Fixed a possible uncaught KeyError, and added the ability for a kban to work on the person requesting it (so we can put it in aliases :))

This commit is contained in:
Jeremy Fincher 2003-11-13 19:01:40 +00:00
parent 6004181695
commit 9b20e1dfb6
2 changed files with 13 additions and 4 deletions

View File

@ -113,11 +113,16 @@ class Channel(callbacks.Privmsg):
channel = privmsgs.getChannel(msg, args)
(bannedNick, length) = privmsgs.getArgs(args, optional=1)
length = int(length or 0)
bannedHostmask = irc.state.nickToHostmask(bannedNick)
try:
bannedHostmask = irc.state.nickToHostmask(bannedNick)
except KeyError:
irc.error(msg, 'I haven\'t seen %s.' % bannedNick)
return
capability = ircdb.makeChannelCapability(channel, 'op')
banmask = ircutils.banmask(bannedHostmask)
if ircdb.checkCapability(msg.prefix, capability)\
and not ircdb.checkCapability(bannedHostmask, capability):
if bannedNick == msg.nick or \
(ircdb.checkCapability(msg.prefix, capability) \
and not ircdb.checkCapability(bannedHostmask, capability)):
if irc.nick in irc.state.channels[channel].ops:
irc.queueMsg(ircmsgs.ban(channel, banmask))
irc.queueMsg(ircmsgs.kick(channel, bannedNick, msg.nick))

View File

@ -64,7 +64,11 @@ class ChannelTestCase(ChannelPluginTestCase, PluginDocumentation):
self.irc.feedMsg(ircmsgs.join(self.channel, prefix='foobar!user@host'))
self.assertError('kban foobar')
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
self.assertNotError('kban foobar')
m = self.getMsg('kban foobar')
self.assertEqual(m, ircmsgs.ban(self.channel, '*!*@host'))
m = self.getMsg(' ')
self.assertEqual(m, ircmsgs.kick(self.channel, 'foobar', self.nick))
self.assertNotRegexp('kban adlkfajsdlfkjsd', 'KeyError')
def testLobotomizers(self):
self.assertNotError('lobotomize')