From afa49be4561c1fc4cc2c8fc8d5ec699ff85b4f59 Mon Sep 17 00:00:00 2001 From: James Vega Date: Mon, 25 May 2009 10:02:11 -0400 Subject: [PATCH] Channel: Chunk mass mode changes according to supported['MODES'] Signed-off-by: James Vega --- plugins/Channel/plugin.py | 36 ++++++++++++++++++++++++++---------- plugins/Channel/test.py | 22 +++++++++++++++++++--- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index 088dd7bf7..4b7758f8d 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -56,6 +56,12 @@ class Channel(callbacks.Plugin): irc.queueMsg(msg) irc.noReply() + def _sendMsgs(self, irc, nicks, f): + numModes = irc.state.supported.get('modes', 1) + for i in range(0, len(nicks), numModes): + irc.queueMsg(f(nicks[i:i + numModes])) + irc.noReply() + def mode(self, irc, msg, args, channel, modes): """[] [ ...] @@ -126,7 +132,9 @@ class Channel(callbacks.Plugin): """ if not nicks: nicks = [msg.nick] - self._sendMsg(irc, ircmsgs.ops(channel, nicks)) + def f(L): + return ircmsgs.ops(channel, L) + self._sendMsgs(irc, nicks, f) op = wrap(op, ['op', ('haveOp', 'op someone'), any('nickInChannel')]) def halfop(self, irc, msg, args, channel, nicks): @@ -139,7 +147,9 @@ class Channel(callbacks.Plugin): """ if not nicks: nicks = [msg.nick] - self._sendMsg(irc, ircmsgs.halfops(channel, nicks)) + def f(L): + return ircmsgs.halfops(channel, L) + self._sendMsgs(irc, nicks, f) halfop = wrap(halfop, ['halfop', ('haveOp', 'halfop someone'), any('nickInChannel')]) @@ -161,7 +171,9 @@ class Channel(callbacks.Plugin): capability = 'voice' capability = ircdb.makeChannelCapability(channel, capability) if ircdb.checkCapability(msg.prefix, capability): - self._sendMsg(irc, ircmsgs.voices(channel, nicks)) + def f(L): + return ircmsgs.voices(channel, L) + self._sendMsgs(irc, nicks, f) else: irc.errorNoCapability(capability) voice = wrap(voice, ['channel', ('haveOp', 'voice someone'), @@ -180,7 +192,9 @@ class Channel(callbacks.Plugin): 'yourself.', Raise=True) if not nicks: nicks = [msg.nick] - self._sendMsg(irc, ircmsgs.deops(channel, nicks)) + def f(L): + return ircmsgs.deops(channel, L) + self._sendMsgs(irc, nicks, f) deop = wrap(deop, ['op', ('haveOp', 'deop someone'), any('nickInChannel')]) @@ -197,12 +211,12 @@ class Channel(callbacks.Plugin): 'dehalfop me yourself.', Raise=True) if not nicks: nicks = [msg.nick] - self._sendMsg(irc, ircmsgs.dehalfops(channel, nicks)) + def f(L): + return ircmsgs.dehalfops(channel, L) + self._sendMsgs(irc, nicks, f) dehalfop = wrap(dehalfop, ['halfop', ('haveOp', 'dehalfop someone'), any('nickInChannel')]) - # XXX We should respect the MODES part of an 005 here. Helper function - # material. def devoice(self, irc, msg, args, channel, nicks): """[] [ ...] @@ -216,7 +230,9 @@ class Channel(callbacks.Plugin): 'me yourself.', Raise=True) if not nicks: nicks = [msg.nick] - self._sendMsg(irc, ircmsgs.devoices(channel, nicks)) + def f(L): + return ircmsgs.devoices(channel, L) + self._sendMsgs(irc, nicks, f) devoice = wrap(devoice, ['voice', ('haveOp', 'devoice someone'), any('nickInChannel')]) @@ -247,8 +263,8 @@ class Channel(callbacks.Plugin): kicklen = irc.state.supported.get('kicklen', sys.maxint) if len(reason) > kicklen: irc.error('The reason you gave is longer than the allowed ' - 'length for a KICK reason on this server.') - return + 'length for a KICK reason on this server.', + Raise=True) self._sendMsg(irc, ircmsgs.kick(channel, nick, reason)) kick = wrap(kick, ['op', ('haveOp', 'kick someone'), 'nickInChannel', additional('text')]) diff --git a/plugins/Channel/test.py b/plugins/Channel/test.py index 3026dab52..67ba108a3 100644 --- a/plugins/Channel/test.py +++ b/plugins/Channel/test.py @@ -116,7 +116,17 @@ class ChannelTestCase(ChannelPluginTestCase): m.args == (self.channel, '+o', 'foo')) m = self.getMsg('op foo bar') self.failUnless(m.command == 'MODE' and - m.args == (self.channel, '+oo', 'foo', 'bar')) + m.args == (self.channel, '+o', 'foo')) + m = self.irc.takeMsg() + self.failUnless(m.command == 'MODE' and + m.args == (self.channel, '+o', 'bar')) + self.irc.state.supported['MODES'] = 2 + m = self.getMsg('op foo bar') + try: + self.failUnless(m.command == 'MODE' and + m.args == (self.channel, '+oo', 'foo', 'bar')) + finally: + self.irc.state.supported['MODES'] = 1 def testHalfOp(self): self.assertError('halfop') @@ -127,7 +137,10 @@ class ChannelTestCase(ChannelPluginTestCase): m.args == (self.channel, '+h', 'foo')) m = self.getMsg('halfop foo bar') self.failUnless(m.command == 'MODE' and - m.args == (self.channel, '+hh', 'foo', 'bar')) + m.args == (self.channel, '+h', 'foo')) + m = self.irc.takeMsg() + self.failUnless(m.command == 'MODE' and + m.args == (self.channel, '+h', 'bar')) def testVoice(self): self.assertError('voice') @@ -138,7 +151,10 @@ class ChannelTestCase(ChannelPluginTestCase): m.args == (self.channel, '+v', 'foo')) m = self.getMsg('voice foo bar') self.failUnless(m.command == 'MODE' and - m.args == (self.channel, '+vv', 'foo', 'bar')) + m.args == (self.channel, '+v', 'foo')) + m = self.irc.takeMsg() + self.failUnless(m.command == 'MODE' and + m.args == (self.channel, '+v', 'bar')) def assertBan(self, query, hostmask, **kwargs): m = self.getMsg(query, **kwargs)