From f170743837ec4da5981767f96648bb1807986b57 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 25 Jul 2010 07:54:11 -0500 Subject: [PATCH] genericify existing admin functions, move standard variable declaration to on_privmsg and use them as arguments, use nm_to_n/nm_to_uh irclib functions for getting nick/userhost --- dr.botzo.py | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/dr.botzo.py b/dr.botzo.py index 1557e4d..4ff7697 100755 --- a/dr.botzo.py +++ b/dr.botzo.py @@ -12,15 +12,11 @@ import irclib # interface assumptions: privmsg ##### -def sub_join_channel(connection, event, admin_unlocked): - nick = event.source().split('!')[0] - userhost = event.source().split('!')[1] - what = event.arguments()[0] - +def sub_join_channel(connection, event, nick, userhost, replypath, what, admin_unlocked): if what.split(' ')[0] == 'join' and admin_unlocked: channel = what.split(' ')[1] connection.join(channel) - connection.privmsg(nick, 'joined ' + channel + '.') + connection.privmsg(replypath, 'joined ' + channel + '.') ##### # sub_part_channel @@ -28,15 +24,11 @@ def sub_join_channel(connection, event, admin_unlocked): # interface assumptions: privmsg ##### -def sub_part_channel(connection, event, admin_unlocked): - nick = event.source().split('!')[0] - userhost = event.source().split('!')[1] - what = event.arguments()[0] - +def sub_part_channel(connection, event, nick, userhost, replypath, what, admin_unlocked): if what.split(' ')[0] == 'part' and admin_unlocked: channel = what.split(' ')[1] connection.part(channel, ' '.join(what.split(' ')[2:])) - connection.privmsg(nick, 'parted ' + channel + '.') + connection.privmsg(replypath, 'parted ' + channel + '.') ##### # sub_quit_channel @@ -44,13 +36,9 @@ def sub_part_channel(connection, event, admin_unlocked): # interface assumptions: privmsg ##### -def sub_quit_channel(connection, event, admin_unlocked): - nick = event.source().split('!')[0] - userhost = event.source().split('!')[1] - what = event.arguments()[0] - +def sub_quit_channel(connection, event, nick, userhost, replypath, what, admin_unlocked): if what.split(' ')[0] == 'quit' and admin_unlocked: - connection.privmsg(nick, 'quitting') + connection.privmsg(replypath, 'quitting') connection.quit(' '.join(what.split(' ')[1:])) with open('dr.botzo.cfg', 'w') as cfg: config.write(cfg) @@ -61,11 +49,7 @@ def sub_quit_channel(connection, event, admin_unlocked): # interface assumptions: privmsg ##### -def sub_autojoin_manipulate(connection, event, admin_unlocked): - nick = event.source().split('!')[0] - userhost = event.source().split('!')[1] - what = event.arguments()[0] - +def sub_autojoin_manipulate(connection, event, nick, userhost, replypath, what, admin_unlocked): if what.split(' ')[0] == 'autojoin' and admin_unlocked: if what.split(' ')[1] == 'add': try: @@ -74,7 +58,7 @@ def sub_autojoin_manipulate(connection, event, admin_unlocked): channelset = set(config.get('channels', 'autojoin').split(',')) channelset.add(channel) config.set('channels', 'autojoin', ','.join(channelset)) - connection.privmsg(nick, 'added ' + channel + ' to autojoin') + connection.privmsg(replypath, 'added ' + channel + ' to autojoin') except NoOptionError: pass elif what.split(' ')[1] == 'remove': try: @@ -83,7 +67,7 @@ def sub_autojoin_manipulate(connection, event, admin_unlocked): channelset = set(config.get('channels', 'autojoin').split(',')) channelset.discard(channel) config.set('channels', 'autojoin', ','.join(channelset)) - connection.privmsg(nick, 'removed ' + channel + ' from autojoin') + connection.privmsg(replypath, 'removed ' + channel + ' from autojoin') except NoOptionError: pass ##### @@ -112,9 +96,11 @@ def on_connect(connection, event): ##### def on_privmsg(connection, event): - nick = event.source().split('!')[0] - userhost = event.source().split('!')[1] + nick = irclib.nm_to_n(event.source()) + userhost = irclib.nm_to_uh(event.source()) + replypath = nick what = event.arguments()[0] + admin_unlocked = False try: @@ -123,10 +109,10 @@ def on_privmsg(connection, event): except NoOptionError: pass # admin commands - sub_join_channel(connection, event, admin_unlocked) - sub_part_channel(connection, event, admin_unlocked) - sub_quit_channel(connection, event, admin_unlocked) - sub_autojoin_manipulate(connection, event, admin_unlocked) + sub_join_channel(connection, event, nick, userhost, replypath, what, admin_unlocked) + sub_part_channel(connection, event, nick, userhost, replypath, what, admin_unlocked) + sub_quit_channel(connection, event, nick, userhost, replypath, what, admin_unlocked) + sub_autojoin_manipulate(connection, event, nick, userhost, replypath, what, admin_unlocked) ##### # init