From 715f926846a80f5667b51ae176e91f7258f60307 Mon Sep 17 00:00:00 2001 From: neersighted Date: Tue, 28 Feb 2012 21:47:11 -0800 Subject: [PATCH] moar PEP8 --- plugins/admin.py | 10 +++-- plugins/choose.py | 3 +- plugins/coin.py | 17 +++++---- plugins/ctcp.py | 9 +++-- plugins/cypher.py | 96 +++++++++++++++++++++++------------------------ 5 files changed, 69 insertions(+), 66 deletions(-) diff --git a/plugins/admin.py b/plugins/admin.py index 79a41cc..8797982 100755 --- a/plugins/admin.py +++ b/plugins/admin.py @@ -116,14 +116,15 @@ def kick(inp, input=None, notice=None): reason = reason[:-1] out = out + " :" + reason - notice("Attempting to kick %s from %s..." % (user, chan)) + notice("Attempting to kick %s from %s..." % (user, chan)) input.conn.send(out) @hook.command def say(inp, input=None, notice=None): ".say [channel] -- Makes the bot say in [channel]. "\ - "If [channel] is blank the bot will say the in the channel the command was used in." + "If [channel] is blank the bot will say the in "\ + "the channel the command was used in." if not input.nick in input.bot.config["admins"]: notice("Only bot admins can use this command!") return @@ -146,8 +147,9 @@ def say(inp, input=None, notice=None): @hook.command("me") @hook.command def act(inp, input=None, notice=None): - ".act [channel] -- Makes the bot act out in [channel]. " - \"If [channel] is blank the bot will act the in the channel the command was used in." + ".act [channel] -- Makes the bot act out in [channel] "\ + "If [channel] is blank the bot will act the in "\ + "the channel the command was used in." if not input.nick in input.bot.config["admins"]: notice("Only bot admins can use this command!") return diff --git a/plugins/choose.py b/plugins/choose.py index dd8ce10..62e87d7 100755 --- a/plugins/choose.py +++ b/plugins/choose.py @@ -6,7 +6,8 @@ from util import hook @hook.command def choose(inp): - ".choose , [choice2], [choice3], [choice4], ... -- Randomly picks one of the given choices." + ".choose , [choice2], [choice3], [choice4], ... -- "\ + "Randomly picks one of the given choices." c = re.findall(r'([^,]+)', inp) if len(c) == 1: diff --git a/plugins/coin.py b/plugins/coin.py index 410b080..ddbd853 100755 --- a/plugins/coin.py +++ b/plugins/coin.py @@ -2,24 +2,25 @@ from util import hook import random + # used for tails: x heads: y def flip_simple(count): heads = 0 tails = 0 for x in range(count): - c = random.randint(0,1) + c = random.randint(0, 1) if c == 0: heads += 1 else: tails += 1 - return [heads,tails] + return [heads, tails] @hook.command(autohelp=False) def coin(inp): ".coin [amount] -- Flips [amount] of coins." - - # checking for valid input. if valid input [count=inp], if invalid [return error], if no input [count=1] + # checking for valid input. if valid input [count=inp], + # if invalid [return error], if no input [count=1] if inp.isdigit(): count = int(inp) else: @@ -32,13 +33,13 @@ def coin(inp): return "Too many coins! Maximum is 200." # depending on the count, we use two different methods to get the output if count == 1: - flip = random.randint(0,1) + flip = random.randint(0, 1) if flip == 1: sidename = "heads" else: sidename = "tails" - return "You flip a coin and get "+sidename+"." + return "You flip a coin and get " + sidename + "." else: flips = flip_simple(count) - return "You flip %s coins and get %s heads and %s tails." % (str(count), str(flips[0]), str(flips[1])) - + return "You flip %s coins and get "\ + "%s heads and %s tails." % (str(count), str(flips[0]), str(flips[1])) diff --git a/plugins/ctcp.py b/plugins/ctcp.py index 7479fe4..083f294 100755 --- a/plugins/ctcp.py +++ b/plugins/ctcp.py @@ -1,19 +1,22 @@ from util import hook + # CTCP responses @hook.regex(r'^\x01VERSION\x01$') def ctcpversion(inp, notice=None): notice('\x01VERSION: CloudBot - http://git.io/cloudbot') - + + @hook.regex(r'^\x01PING\x01$') def ctcpping(inp, notice=None): notice('\x01PING: PONG') - + + @hook.regex(r'^\x01TIME\x01$') def ctcptime(inp, notice=None): notice('\x01TIME: GET A WATCH') + @hook.regex(r'^\x01FINGER\x01$') def ctcpfinger(inp, notice=None): notice('\x01FINGER: WHERE ARE YOU PUTTING THAT') - diff --git a/plugins/cypher.py b/plugins/cypher.py index 930bd81..7e61d74 100755 --- a/plugins/cypher.py +++ b/plugins/cypher.py @@ -1,78 +1,74 @@ ''' Plugin which (de)cyphers a string - Doesn't cypher non-alphanumeric strings yet. - by instanceoftom ''' from util import hook -chars="abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ " +chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ " len_chars = len(chars) + @hook.command def cypher(inp): - ".cypher -- Cyphers with ." + ".cypher -- Cyphers with ." - passwd = inp.split(" ")[0] - len_passwd = len(passwd) - inp = " ".join(inp.split(" ")[1:]) + passwd = inp.split(" ")[0] + len_passwd = len(passwd) + inp = " ".join(inp.split(" ")[1:]) - out ="" - passwd_index=0 - for character in inp: - try: - chr_index = chars.index(character) - passwd_chr_index = chars.index(passwd[passwd_index]) + out = "" + passwd_index = 0 + for character in inp: + try: + chr_index = chars.index(character) + passwd_chr_index = chars.index(passwd[passwd_index]) - out_chr_index = (chr_index + passwd_chr_index) % len_chars - out_chr = chars[out_chr_index] + out_chr_index = (chr_index + passwd_chr_index) % len_chars + out_chr = chars[out_chr_index] - out += out_chr + out += out_chr - passwd_index = ( passwd_index + 1) % len_passwd - except ValueError: - out += character - continue + passwd_index = (passwd_index + 1) % len_passwd + except ValueError: + out += character + continue + return out - return out @hook.command def decypher(inp): - ".decypher -- Decyphers with ." + ".decypher -- Decyphers with ." - passwd = inp.split(" ")[0] - len_passwd = len(passwd) - inp = " ".join(inp.split(" ")[1:]) + passwd = inp.split(" ")[0] + len_passwd = len(passwd) + inp = " ".join(inp.split(" ")[1:]) + passwd_index = 0 + for character in inp: + try: + chr_index = chars.index(character) + passwd_index = (passwd_index + 1) % len_passwd + except ValueError: + continue - passwd_index=0 - #I am lazy and I could do the math to get the passwd_index - #for this inp, but meh thats for a later day so lets loop. - for character in inp: - try: - chr_index = chars.index(character) - passwd_index = ( passwd_index + 1) % len_passwd - except ValueError: - continue + passwd_index = passwd_index - 1 + reversed_message = inp[::-1] - passwd_index = passwd_index-1 - reversed_message = inp[::-1] + out = "" + for character in reversed_message: + try: + chr_index = chars.index(character) + passwd_chr_index = chars.index(passwd[passwd_index]) - out ="" - for character in reversed_message: - try: - chr_index = chars.index(character) - passwd_chr_index = chars.index(passwd[passwd_index]) + out_chr_index = (chr_index - passwd_chr_index) % len_chars + out_chr = chars[out_chr_index] - out_chr_index = (chr_index - passwd_chr_index) % len_chars - out_chr = chars[out_chr_index] + out += out_chr - out += out_chr + passwd_index = (passwd_index - 1) % len_passwd + except ValueError: + out += character + continue - passwd_index = ( passwd_index - 1) % len_passwd - except ValueError: - out += character - continue - - return out[::-1] \ No newline at end of file + return out[::-1]