properly call admin functions within do.

before this, recursion type stuff wasn't responded to properly because
do wasn't returning the methods' text
This commit is contained in:
Brian S. Stephan 2010-09-04 12:26:50 -05:00
parent 8c1c10a4bc
commit 053c3f0ae6
1 changed files with 63 additions and 66 deletions

View File

@ -59,85 +59,82 @@ class IrcAdmin(Module):
except NoOptionError: pass except NoOptionError: pass
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
# this could be more sophisticated, but i'm too lazy to do a real port """Try all the admin methods."""
# right now.
# TODO: sophisticate. also, document all of these # TODO: sophisticate. also, document all of these
self.sub_join_channel(connection, event, nick, userhost, replypath, what, admin_unlocked)
self.sub_part_channel(connection, event, nick, userhost, replypath, what, admin_unlocked) whats = what.split(' ')
self.sub_quit_irc(connection, event, nick, userhost, replypath, what, admin_unlocked)
self.sub_autojoin_manipulate(connection, event, nick, userhost, replypath, what, admin_unlocked) if whats[0] == 'join' and admin_unlocked and len(whats) >= 2:
self.sub_save_config(connection, event, nick, userhost, replypath, what, admin_unlocked) return self.sub_join_channel(connection, event, nick, userhost, replypath, what, admin_unlocked)
self.sub_change_nick(connection, event, nick, userhost, replypath, what, admin_unlocked) elif whats[0] == 'part' and admin_unlocked and len(whats) >= 2:
return self.sub_part_channel(connection, event, nick, userhost, replypath, what, admin_unlocked)
elif whats[0] == 'quit' and admin_unlocked:
return self.sub_quit_irc(connection, event, nick, userhost, replypath, what, admin_unlocked)
elif whats[0] == 'autojoin' and admin_unlocked and len(whats) >= 3:
return self.sub_autojoin_manipulate(connection, event, nick, userhost, replypath, what, admin_unlocked)
elif whats[0] == 'config' and whats[1] == 'save' and admin_unlocked:
return self.sub_save_config(connection, event, nick, userhost, replypath, what, admin_unlocked)
elif whats[0] == 'nick' and admin_unlocked and len(whats) >= 2:
return self.sub_change_nick(connection, event, nick, userhost, replypath, what, admin_unlocked)
def sub_join_channel(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def sub_join_channel(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ') channel = whats[1]
if whats[0] == 'join' and admin_unlocked and len(whats) >= 2: if irclib.is_channel(channel):
channel = whats[1] connection.join(channel)
if irclib.is_channel(channel): replystr = 'joined ' + channel
connection.join(channel) return self.reply(connection, replypath, replystr)
replystr = 'joined ' + channel
return self.reply(connection, replypath, replystr)
def sub_part_channel(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def sub_part_channel(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ') channel = whats[1]
if whats[0] == 'part' and admin_unlocked and len(whats) >= 2: if irclib.is_channel(channel):
channel = whats[1] connection.part(channel, ' '.join(whats[2:]))
if irclib.is_channel(channel): replystr = 'parted ' + channel
connection.part(channel, ' '.join(whats[2:])) return self.reply(connection, replypath, replystr)
replystr = 'parted ' + channel
return self.reply(connection, replypath, replystr)
def sub_quit_irc(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def sub_quit_irc(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ') if replypath is not None:
if whats[0] == 'quit' and admin_unlocked: connection.privmsg(replypath, 'quitting')
if replypath is not None: connection.quit(' '.join(whats[1:]))
connection.privmsg(replypath, 'quitting') self.save_config()
connection.quit(' '.join(whats[1:])) sys.exit()
self.save_config()
sys.exit()
def sub_autojoin_manipulate(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def sub_autojoin_manipulate(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ') if whats[1] == 'add':
if whats[0] == 'autojoin' and admin_unlocked and len(whats) >= 3: try:
if whats[1] == 'add': # get existing list
try: channel = whats[2]
# get existing list if irclib.is_channel(channel):
channel = whats[2] channelset = set(self.config.get(self.__class__.__name__, 'autojoin').split(','))
if irclib.is_channel(channel): channelset.add(channel)
channelset = set(self.config.get(self.__class__.__name__, 'autojoin').split(',')) self.config.set(self.__class__.__name__, 'autojoin', ','.join(channelset))
channelset.add(channel) replystr = 'added ' + channel + ' to autojoin'
self.config.set(self.__class__.__name__, 'autojoin', ','.join(channelset)) return self.reply(connection, replypath, replystr)
replystr = 'added ' + channel + ' to autojoin' except NoOptionError: pass
return self.reply(connection, replypath, replystr) elif whats[1] == 'remove':
except NoOptionError: pass try:
elif whats[1] == 'remove': # get existing list
try: channel = whats[2]
# get existing list if irclib.is_channel(channel):
channel = whats[2] channelset = set(self.config.get(self.__class__.__name__, 'autojoin').split(','))
if irclib.is_channel(channel): channelset.discard(channel)
channelset = set(self.config.get(self.__class__.__name__, 'autojoin').split(',')) self.config.set(self.__class__.__name__, 'autojoin', ','.join(channelset))
channelset.discard(channel) replystr = 'removed ' + channel + ' from autojoin'
self.config.set(self.__class__.__name__, 'autojoin', ','.join(channelset)) return self.reply(connection, replypath, replystr)
replystr = 'removed ' + channel + ' from autojoin' except NoOptionError: pass
return self.reply(connection, replypath, replystr)
except NoOptionError: pass
def sub_save_config(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def sub_save_config(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ') with open('dr.botzo.cfg', 'w') as cfg:
if whats[0] == 'config' and whats[1] == 'save' and admin_unlocked: self.config.write(cfg)
with open('dr.botzo.cfg', 'w') as cfg: replystr = 'saved config file'
self.config.write(cfg) return self.reply(connection, replypath, replystr)
replystr = 'saved config file'
return self.reply(connection, replypath, replystr)
def sub_change_nick(self, connection, event, nick, userhost, replypath, what, admin_unlocked): def sub_change_nick(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
whats = what.split(' ') newnick = whats[1]
if whats[0] == 'nick' and admin_unlocked and len(whats) >= 2: connection.nick(newnick)
newnick = whats[1] self.config.set('dr.botzo', 'nick', newnick)
connection.nick(newnick) replystr = 'changed nickname'
self.config.set('dr.botzo', 'nick', newnick) return self.reply(connection, replypath, replystr)
replystr = 'changed nickname'
return self.reply(connection, replypath, replystr)
# Save the config file. # Save the config file.
def save_config(self): def save_config(self):