mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +01:00
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.
This commit is contained in:
parent
9678560c98
commit
da6743b9b7
64
src/Admin.py
64
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):
|
||||
"""<channel>[,<key>] [<channel>[,<key>] ...]
|
||||
|
||||
@ -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):
|
||||
"""<nick>
|
||||
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user