From 73aef2e9ae305e7111f3cf35be62e801913efabd Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Thu, 5 Sep 2013 07:28:47 +0800 Subject: [PATCH 1/6] Added option to authenticate as another nickserv user. --- config.default | 1 + plugins/core_misc.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config.default b/config.default index 43fb526..824cfd1 100644 --- a/config.default +++ b/config.default @@ -8,6 +8,7 @@ "user": "cloudbot", "realname": "CloudBot - http://git.io/cloudbotirc", "nickserv_password": "", + "nickserv_user": "", "channels": ["#cloudbot", "#cloudbot2"], "invite_join": true, "auto_rejoin": false, diff --git a/plugins/core_misc.py b/plugins/core_misc.py index 4fb082f..5e075a9 100755 --- a/plugins/core_misc.py +++ b/plugins/core_misc.py @@ -22,11 +22,19 @@ def invite(paraml, conn=None): def onjoin(paraml, conn=None, bot=None): nickserv_password = conn.conf.get('nickserv_password', '') nickserv_name = conn.conf.get('nickserv_name', 'nickserv') - nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY %s') + nickserv_account_name = conn.conf.get('nickserv_user', '') + nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY') if nickserv_password: + print "Found a password..." if nickserv_password in bot.config['censored_strings']: bot.config['censored_strings'].remove(nickserv_password) - conn.msg(nickserv_name, nickserv_command % nickserv_password) + if nickserv_account_name: + print "Found an account name..." + print "Sending"," ".join([nickserv_command, nickserv_account_name, nickserv_password]),"to",nickserv_name + conn.msg(nickserv_name, " ".join([nickserv_command, nickserv_account_name, nickserv_password])) + else: + print "Sending"," ".join([nickserv_command, nickserv_password]),"to",nickserv_name + conn.msg(nickserv_name, " ".join([nickserv_command, nickserv_password])) bot.config['censored_strings'].append(nickserv_password) time.sleep(1) From b3c08a33dabc9eba0f8fea76eaa8d342fd5c0c04 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Thu, 5 Sep 2013 07:44:29 +0800 Subject: [PATCH 2/6] Added mode function for channel modes. Added mute/unmute. --- plugins/op.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/plugins/op.py b/plugins/op.py index bab1979..251e4be 100755 --- a/plugins/op.py +++ b/plugins/op.py @@ -16,6 +16,19 @@ def mode_cmd(mode, text, inp, chan, conn, notice): conn.send("MODE {} {} {}".format(channel, mode, target)) +def mode_cmd_no_target(mode, text, inp, chan, conn, notice): + """ generic mode setting function without a target""" + split = inp.split(" ") + if split[0].startswith("#"): + channel = split[0] + notice("Attempting to {} {}...".format(text, channel)) + conn.send("MODE {} {}".format(channel, mode)) + else: + channel = chan + notice("Attempting to {} {}...".format(text, channel)) + conn.send("MODE {} {}".format(channel, mode)) + + @hook.command(permissions=["op_ban", "op"]) def ban(inp, conn=None, chan=None, notice=None): """ban [channel] -- Makes the bot ban in [channel]. @@ -134,3 +147,19 @@ def remove(inp, chan=None, conn=None): message = " ".join(split) out = "REMOVE {} :{}".format(chan, message) conn.send(out) + + +@hook.command(permissions=["op_mute", "op"], autohelp=False) +def mute(inp, conn=None, chan=None, notice=None): + """mute [channel] -- Makes the bot mute a channel.. + If [channel] is blank the bot will mute + the channel the command was used in.""" + mode_cmd_no_target("+m", "mute", inp, chan, conn, notice) + + +@hook.command(permissions=["op_mute", "op"], autohelp=False) +def unmute(inp, conn=None, chan=None, notice=None): + """mute [channel] -- Makes the bot mute a channel.. + If [channel] is blank the bot will mute + the channel the command was used in.""" + mode_cmd_no_target("-m", "mute", inp, chan, conn, notice) From 5a8b2c282583eb758bea1c96471670a82597a4e9 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Thu, 5 Sep 2013 07:45:34 +0800 Subject: [PATCH 3/6] Corrected typo in unmute, added lock/unlock. --- plugins/op.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/op.py b/plugins/op.py index 251e4be..7380e68 100755 --- a/plugins/op.py +++ b/plugins/op.py @@ -162,4 +162,20 @@ def unmute(inp, conn=None, chan=None, notice=None): """mute [channel] -- Makes the bot mute a channel.. If [channel] is blank the bot will mute the channel the command was used in.""" - mode_cmd_no_target("-m", "mute", inp, chan, conn, notice) + mode_cmd_no_target("-m", "unmute", inp, chan, conn, notice) + + +@hook.command(permissions=["op_mute", "op"], autohelp=False) +def mute(inp, conn=None, chan=None, notice=None): + """mute [channel] -- Makes the bot mute a channel.. + If [channel] is blank the bot will mute + the channel the command was used in.""" + mode_cmd_no_target("+i", "lock", inp, chan, conn, notice) + + +@hook.command(permissions=["op_mute", "op"], autohelp=False) +def unmute(inp, conn=None, chan=None, notice=None): + """mute [channel] -- Makes the bot mute a channel.. + If [channel] is blank the bot will mute + the channel the command was used in.""" + mode_cmd_no_target("-i", "unlock", inp, chan, conn, notice) \ No newline at end of file From bc1062e8d6d2d0b15ee8f54ada1253a9c8c894d7 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Thu, 5 Sep 2013 07:51:42 +0800 Subject: [PATCH 4/6] Fixing typos. --- plugins/op.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/op.py b/plugins/op.py index 7380e68..ed51f3f 100755 --- a/plugins/op.py +++ b/plugins/op.py @@ -165,17 +165,17 @@ def unmute(inp, conn=None, chan=None, notice=None): mode_cmd_no_target("-m", "unmute", inp, chan, conn, notice) -@hook.command(permissions=["op_mute", "op"], autohelp=False) -def mute(inp, conn=None, chan=None, notice=None): - """mute [channel] -- Makes the bot mute a channel.. +@hook.command(permissions=["op_lock", "op"], autohelp=False) +def lock(inp, conn=None, chan=None, notice=None): + """lock [channel] -- Makes the bot lock a channel. If [channel] is blank the bot will mute the channel the command was used in.""" mode_cmd_no_target("+i", "lock", inp, chan, conn, notice) -@hook.command(permissions=["op_mute", "op"], autohelp=False) -def unmute(inp, conn=None, chan=None, notice=None): - """mute [channel] -- Makes the bot mute a channel.. +@hook.command(permissions=["op_lock", "op"], autohelp=False) +def unlock(inp, conn=None, chan=None, notice=None): + """unlock [channel] -- Makes the bot unlock a channel.. If [channel] is blank the bot will mute the channel the command was used in.""" mode_cmd_no_target("-i", "unlock", inp, chan, conn, notice) \ No newline at end of file From 8c60a923baf9e8433722c7fc6c057f12d62a6be5 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Thu, 5 Sep 2013 08:42:40 +0800 Subject: [PATCH 5/6] Rewrite --- plugins/cypher.py | 75 ++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 49 deletions(-) diff --git a/plugins/cypher.py b/plugins/cypher.py index 1c4d7d6..1faad4c 100755 --- a/plugins/cypher.py +++ b/plugins/cypher.py @@ -1,65 +1,42 @@ -""" -Plugin which (de)cyphers a string -Doesn't cypher non-alphanumeric strings yet. -by instanceoftom -All character cyphering added - TheNoodle -""" - +import base64 from util import hook +def encode(key, clear): + enc = [] + for i in range(len(clear)): + key_c = key[i % len(key)] + enc_c = chr((ord(clear[i]) + ord(key_c)) % 256) + enc.append(enc_c) + print "[debug]" + return base64.urlsafe_b64encode("".join(enc)) + +def decode(key, enc): + dec = [] + print " [debug] " + print "key: "+key + print "string: "+enc + enc = base64.urlsafe_b64decode(enc.encode('ascii','ignore')) + print "de64: "+enc + for i in range(len(enc)): + key_c = key[i % len(key)] + dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256) + dec.append(dec_c) + return "".join(dec) + + @hook.command def cypher(inp): """cypher -- Cyphers with .""" passwd = inp.split(" ")[0] - len_passwd = len(passwd) inp = " ".join(inp.split(" ")[1:]) - - out = "" - passwd_index = 0 - for character in inp: - chr_index = ord(character) - passwd_chr_index = ord(passwd[passwd_index]) - - out_chr_index = (chr_index + passwd_chr_index) % 255 - out_chr = chr[out_chr_index] - - out += out_chr - - passwd_index = (passwd_index + 1) % len_passwd - return out + return encode(passwd,inp) @hook.command def decypher(inp): """decypher -- Decyphers with .""" - passwd = inp.split(" ")[0] - len_passwd = len(passwd) inp = " ".join(inp.split(" ")[1:]) - - passwd_index = 0 - for character in inp: - passwd_index = (passwd_index + 1) % len_passwd - - passwd_index -= 1 - reversed_message = inp[::-1] - - out = "" - for character in reversed_message: - try: - chr_index = ord(character) - passwd_chr_index = ord(passwd[passwd_index]) - - out_chr_index = (chr_index - passwd_chr_index) % 255 - out_chr = chars[out_chr_index] - - out += out_chr - - passwd_index = (passwd_index - 1) % len_passwd - except ValueError: - out += character - continue - - return out[::-1] + return decode(passwd,inp) From 6c4d7db9762af226efcb328563772803c256c106 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 5 Sep 2013 13:16:08 +1200 Subject: [PATCH 6/6] Removed debug code --- plugins/cypher.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/cypher.py b/plugins/cypher.py index 1faad4c..1527778 100755 --- a/plugins/cypher.py +++ b/plugins/cypher.py @@ -8,16 +8,11 @@ def encode(key, clear): key_c = key[i % len(key)] enc_c = chr((ord(clear[i]) + ord(key_c)) % 256) enc.append(enc_c) - print "[debug]" return base64.urlsafe_b64encode("".join(enc)) def decode(key, enc): dec = [] - print " [debug] " - print "key: "+key - print "string: "+enc enc = base64.urlsafe_b64decode(enc.encode('ascii','ignore')) - print "de64: "+enc for i in range(len(enc)): key_c = key[i % len(key)] dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256)