diff --git a/src/Channel.py b/src/Channel.py index 78f840dae..284ab080b 100755 --- a/src/Channel.py +++ b/src/Channel.py @@ -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)) diff --git a/test/test_Channel.py b/test/test_Channel.py index b8948c823..31404adbb 100644 --- a/test/test_Channel.py +++ b/test/test_Channel.py @@ -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')