From 3405845303063ad89ec01c509138bc978cf2b3c9 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 9 Aug 2011 18:41:04 -0400 Subject: [PATCH] minor fixes, cleanup, and general improvements --- bot/commands/afc_report.py | 4 ++-- bot/commands/chanops.py | 7 ++++++- bot/commands/crypt.py | 10 ++++++++-- bot/commands/git.py | 21 +++++++++------------ bot/commands/help.py | 5 ++--- bot/commands/threads.py | 2 +- bot/frontend.py | 3 ++- bot/main.py | 2 +- earwigbot.py | 2 +- 9 files changed, 32 insertions(+), 24 deletions(-) diff --git a/bot/commands/afc_report.py b/bot/commands/afc_report.py index 7f4abf7..5375ce5 100644 --- a/bot/commands/afc_report.py +++ b/bot/commands/afc_report.py @@ -46,8 +46,8 @@ class Command(BaseCommand): return url = page.url().replace("en.wikipedia.org/wiki", "enwp.org") - short = re.sub(r"wikipedia( talk)?:articles for creation/", "", title, - re.IGNORECASE) + short = re.sub("wikipedia( talk)?\:articles for creation\/", "", title, + flags=re.IGNORECASE) status = self.get_status(page) user = self.site.get_user(page.creator()) user_name = user.name() diff --git a/bot/commands/chanops.py b/bot/commands/chanops.py index 727ebbf..fd8f009 100644 --- a/bot/commands/chanops.py +++ b/bot/commands/chanops.py @@ -8,12 +8,17 @@ class Command(BaseCommand): name = "chanops" def check(self, data): - commands = ["voice", "devoice", "op", "deop"] + commands = ["chanops", "voice", "devoice", "op", "deop"] if data.is_command and data.command in commands: return True return False def process(self, data): + if data.command == "chanops": + msg = "available commands are !voice, !devoice, !op, and !deop." + self.connection.reply(data, msg) + return + if data.host not in config.irc["permissions"]["admins"]: msg = "you must be a bot admin to use this command." self.connection.reply(data, msg) diff --git a/bot/commands/crypt.py b/bot/commands/crypt.py index 8727c6d..2261112 100644 --- a/bot/commands/crypt.py +++ b/bot/commands/crypt.py @@ -8,14 +8,20 @@ import blowfish class Command(BaseCommand): """Provides hash functions with !hash (!hash list for supported algorithms) and blowfish encryption with !encrypt and !decrypt.""" - name = "cryptography" + name = "crypt" def check(self, data): - if data.is_command and data.command in ["hash", "encrypt", "decrypt"]: + commands = ["crypt", "hash", "encrypt", "decrypt"] + if data.is_command and data.command in commands: return True return False def process(self, data): + if data.command == "crypt": + msg = "available commands are !hash, !encrypt, and !decrypt." + self.connection.reply(data, msg) + return + if not data.args: msg = "what do you want me to {0}?".format(data.command) self.connection.reply(data, msg) diff --git a/bot/commands/git.py b/bot/commands/git.py index 90d7bdc..0d3a92d 100644 --- a/bot/commands/git.py +++ b/bot/commands/git.py @@ -8,8 +8,8 @@ from classes import BaseCommand import config class Command(BaseCommand): - """Commands to interface with the bot's git repository; use '!git help' for - a sub-command list.""" + """Commands to interface with the bot's git repository; use '!git' for a + sub-command list.""" name = "git" def process(self, data): @@ -20,8 +20,7 @@ class Command(BaseCommand): return if not data.args: - msg = "no arguments provided. Maybe you wanted '!git help'?" - self.connection.reply(data, msg) + self.do_help() return if data.args[0] == "help": @@ -59,7 +58,7 @@ class Command(BaseCommand): def do_help(self): """Display all commands.""" - help_dict = { + help = { "branch": "get current branch", "branches": "get all branches", "checkout": "switch branches", @@ -67,13 +66,11 @@ class Command(BaseCommand): "pull": "update everything from the remote server", "status": "check if we are up-to-date", } - keys = help_dict.keys() - keys.sort() - help = "" - for key in keys: - help += "\x0303%s\x0301 (%s), " % (key, help_dict[key]) - help = help[:-2] # trim last comma and space - self.connection.reply(self.data, "sub-commands are: %s." % help) + msg = "" + for key in sorted(help.keys()): + msg += "\x0303{0}\x0301 ({1}), ".format(key, help[key]) + msg = msg[:-2] # Trim last comma and space + self.connection.reply(self.data, "sub-commands are: {0}.".format(msg)) def do_branch(self): """Get our current branch.""" diff --git a/bot/commands/help.py b/bot/commands/help.py index 484dcb4..10bad4f 100644 --- a/bot/commands/help.py +++ b/bot/commands/help.py @@ -18,9 +18,8 @@ class Command(BaseCommand): def do_main_help(self, data): """Give the user a general help message with a list of all commands.""" - msg = "I am a bot! I have {0} commands loaded: {1}. You can get help for any command with '!help '." - cmnds = self.cmnds.keys() - cmnds.sort() + msg = "Hi, I'm a bot! I have {0} commands loaded: {1}. You can get help for any command with '!help '." + cmnds = sorted(self.cmnds.keys()) msg = msg.format(len(cmnds), ', '.join(cmnds)) self.connection.reply(data, msg) diff --git a/bot/commands/threads.py b/bot/commands/threads.py index 263dd6d..f3f6a4f 100644 --- a/bot/commands/threads.py +++ b/bot/commands/threads.py @@ -20,7 +20,7 @@ class Command(BaseCommand): def process(self, data): self.data = data if data.host not in config.irc["permissions"]["owners"]: - msg = "at this time, you must be a bot owner to use this command." + msg = "you must be a bot owner to use this command." self.connection.reply(data, msg) return diff --git a/bot/frontend.py b/bot/frontend.py index b3a6307..8566f44 100644 --- a/bot/frontend.py +++ b/bot/frontend.py @@ -93,7 +93,8 @@ def _process_message(line): # If we are pinged, pong back to the server: if line[0] == "PING": - connection.send("PONG %s" % line[1]) + msg = " ".join(("PONG", line[1])) + connection.send(msg) # On successful connection to the server: if line[1] == "376": diff --git a/bot/main.py b/bot/main.py index eb892de..f0ae18b 100644 --- a/bot/main.py +++ b/bot/main.py @@ -1,4 +1,4 @@ -#! /usr/bin/python +#! /usr/bin/env python # -*- coding: utf-8 -*- """ diff --git a/earwigbot.py b/earwigbot.py index a98f961..bf6d9aa 100755 --- a/earwigbot.py +++ b/earwigbot.py @@ -1,4 +1,4 @@ -#! /usr/bin/python +#! /usr/bin/env python # -*- coding: utf-8 -*- """