Guarded IrcState.doMode to work only with channels.

This commit is contained in:
Jeremy Fincher 2003-09-29 07:44:27 +00:00
parent 1410d1af43
commit 6169822349
2 changed files with 20 additions and 14 deletions

View File

@ -268,20 +268,22 @@ class IrcState(IrcCommandDispatcher):
self.channels[channel] = chan self.channels[channel] = chan
def doMode(self, irc, msg): def doMode(self, irc, msg):
chan = self.channels[msg.args[0]] channel = msg.args[0]
for (mode, nick) in ircutils.separateModes(msg.args[1:]): if ircutils.isChannel(channel):
if mode == '-o': chan = self.channels[channel]
chan.ops.discard(nick) for (mode, nick) in ircutils.separateModes(msg.args[1:]):
elif mode == '+o': if mode == '-o':
chan.ops.add(nick) chan.ops.discard(nick)
if mode == '-h': elif mode == '+o':
chan.halfops.discard(nick) chan.ops.add(nick)
elif mode == '+h': if mode == '-h':
chan.halfops.add(nick) chan.halfops.discard(nick)
if mode == '-v': elif mode == '+h':
chan.voices.discard(nick) chan.halfops.add(nick)
elif mode == '+v': if mode == '-v':
chan.voices.add(nick) chan.voices.discard(nick)
elif mode == '+v':
chan.voices.add(nick)
def do353(self, irc, msg): def do353(self, irc, msg):
(_, _, channel, users) = msg.args (_, _, channel, users) = msg.args

View File

@ -212,6 +212,10 @@ class IrcStateTestCase(unittest.TestCase):
st.addMsg(self.irc, ircmsgs.dehalfop('#foo', 'bar')) st.addMsg(self.irc, ircmsgs.dehalfop('#foo', 'bar'))
self.failIf('bar' in st.channels['#foo'].halfops) self.failIf('bar' in st.channels['#foo'].halfops)
def testDoModeOnlyChannels(self):
st = irclib.IrcState()
self.assert_(st.addMsg(self.irc, ircmsgs.IrcMsg('MODE foo +i')) or 1)
""" """
def testChannels(self): def testChannels(self):
channel = channel =