From da6743b9b7b852701f0324c6c11fe2b642574f40 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 10 Dec 2003 07:29:01 +0000 Subject: [PATCH] Added appropriate error messages for Admin.join when the channel can't be joined. Also added channels command to see what channels the bot is in. --- src/Admin.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++ test/test_Admin.py | 9 +++++++ 2 files changed, 73 insertions(+) diff --git a/src/Admin.py b/src/Admin.py index aa2eb23c5..d21df9af5 100755 --- a/src/Admin.py +++ b/src/Admin.py @@ -55,6 +55,54 @@ import callbacks class Admin(privmsgs.CapabilityCheckingPrivmsg): capability = 'admin' + def __init__(self): + privmsgs.CapabilityCheckingPrivmsg.__init__(self) + self.joins = {} + + def do471(self, irc, msg): + try: + channel = msg.args[1] + (irc, msg) = self.joins[channel] + del self.joins[channel] + irc.error(msg, 'Cannot join %s, it\'s full.' % channel) + except KeyError: + self.log.warning('Got 471 without Admin.join being called.') + + def do473(self, irc, msg): + try: + channel = msg.args[1] + (irc, msg) = self.joins[channel] + del self.joins[channel] + irc.error(msg, 'Cannot join %s, I was not invited.' % channel) + except KeyError: + self.log.warning('Got 473 without Admin.join being called.') + + def do474(self, irc, msg): + try: + channel = msg.args[1] + (irc, msg) = self.joins[channel] + del self.joins[channel] + irc.error(msg, 'Cannot join %s, it\'s banned me.' % channel) + except KeyError: + self.log.warning('Got 474 without Admin.join being called.') + + def do475(self, irc, msg): + try: + channel = msg.args[1] + (irc, msg) = self.joins[channel] + del self.joins[channel] + irc.error(msg, 'Cannot join %s, my keyword was wrong.' % channel) + except KeyError: + self.log.warning('Got 475 without Admin.join being called.') + + def doJoin(self, irc, msg): + if msg.prefix == irc.prefix: + try: + del self.joins[msg.args[0]] + except KeyError: + s = 'Joined a channel without Admin.join being called' + self.log.warning(s) + def join(self, irc, msg, args): """[,] [[,] ...] @@ -74,9 +122,25 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg): channels.append(channel) irc.queueMsg(ircmsgs.joins(channels, keys)) for channel in channels: + self.joins[channel] = (irc, msg) if channel not in irc.state.channels: irc.queueMsg(ircmsgs.who(channel)) + def channels(self, irc, msg, args): + """takes no arguments + + Returns the channels the bot is on. Must be given in private, in order + to protect the secrecy of secret channels. + """ + if ircutils.isChannel(msg.args[0]): + raise callbacks.Error + L = irc.state.channels.keys() + if L: + utils.sortBy(ircutils.toLower, L) + irc.reply(msg, utils.commaAndify(L)) + else: + irc.reply(msg, 'I\'m not currently in any channels.') + def nick(self, irc, msg, args): """ diff --git a/test/test_Admin.py b/test/test_Admin.py index e51a6eada..7046b318a 100644 --- a/test/test_Admin.py +++ b/test/test_Admin.py @@ -35,6 +35,15 @@ import conf class AdminTestCase(PluginTestCase, PluginDocumentation): plugins = ('Admin',) + def testChannels(self): + self.assertRegexp('channels', 'not.*in any') + self.irc.feedMsg(ircmsgs.join('#foo', prefix=self.prefix)) + self.assertRegexp('channels', '#foo') + self.irc.feedMsg(ircmsgs.join('#bar', prefix=self.prefix)) + self.assertRegexp('channels', '#bar and #foo') + self.irc.feedMsg(ircmsgs.join('#Baz', prefix=self.prefix)) + self.assertRegexp('channels', '#bar, #Baz, and #foo') + def testIgnoreUnignore(self): try: self.assertNotError('admin ignore foo!bar@baz')