def testSeparateModes(self): self.assertEqual(ircutils.separateModes(["+ooo", "x", "y", "z"]), [("+o", "x"), ("+o", "y"), ("+o", "z")]) self.assertEqual(ircutils.separateModes(["+o-o", "x", "y"]), [("+o", "x"), ("-o", "y")]) self.assertEqual(ircutils.separateModes(["+s-o", "x"]), [("+s", None), ("-o", "x")]) self.assertEqual( ircutils.separateModes(["+sntl", "100"]), [("+s", None), ("+n", None), ("+t", None), ("+l", 100)] )
def testSeparateModes(self): self.assertEqual(ircutils.separateModes(['+ooo', 'x', 'y', 'z']), [('+o', 'x'), ('+o', 'y'), ('+o', 'z')]) self.assertEqual(ircutils.separateModes(['+o-o', 'x', 'y']), [('+o', 'x'), ('-o', 'y')]) self.assertEqual(ircutils.separateModes(['+s-o', 'x']), [('+s', None), ('-o', 'x')]) self.assertEqual(ircutils.separateModes(['+sntl', '100']), [('+s', None),('+n', None),('+t', None),('+l', 100)])
def testBan(self): channel = '#osu' ban = '*!*@*.edu' exception = '*!*@*ohio-state.edu' noException = ircmsgs.ban(channel, ban) self.assertEqual(ircutils.separateModes(noException.args[1:]), [('+b', ban)]) withException = ircmsgs.ban(channel, ban, exception) self.assertEqual(ircutils.separateModes(withException.args[1:]), [('+b', ban), ('+e', exception)])
def testBans(self): channel = '#osu' bans = ['*!*@*', 'jemfinch!*@*'] exceptions = ['*!*@*ohio-state.edu'] noException = ircmsgs.bans(channel, bans) self.assertEqual(ircutils.separateModes(noException.args[1:]), [('+b', bans[0]), ('+b', bans[1])]) withExceptions = ircmsgs.bans(channel, bans, exceptions) self.assertEqual(ircutils.separateModes(withExceptions.args[1:]), [('+b', bans[0]), ('+b', bans[1]), ('+e', exceptions[0])])
def doMode(self, irc, msg): channel = msg.args[0] chanOp = ircdb.makeChannelCapability(channel, 'op') chanVoice = ircdb.makeChannelCapability(channel, 'voice') chanHalfOp = ircdb.makeChannelCapability(channel, 'halfop') if not ircdb.checkCapability(msg.prefix, chanOp): irc.sendMsg(ircmsgs.deop(channel, msg.nick)) for (mode, value) in ircutils.separateModes(msg.args[1:]): if not value: continue if ircutils.strEqual(value, msg.nick): # We allow someone to mode themselves to oblivion. continue if irc.isNick(value): hostmask = irc.state.nickToHostmask(value) if mode == '+o': if not self.isOp(irc, channel, hostmask): irc.queueMsg(ircmsgs.deop(channel, value)) elif mode == '+h': if not ircdb.checkCapability(hostmask, chanHalfOp): irc.queueMsg(ircmsgs.dehalfop(channel, value)) elif mode == '+v': if not ircdb.checkCapability(hostmask, chanVoice): irc.queueMsg(ircmsgs.devoice(channel, value)) elif mode == '-o': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.op(channel, value)) elif mode == '-h': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.halfop(channel, value)) elif mode == '-v': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.voice(channel, value)) else: assert ircutils.isUserHostmask(value)
def doMode(self, irc, msg): channel = msg.channel chanOp = ircdb.makeChannelCapability(channel, 'op') chanVoice = ircdb.makeChannelCapability(channel, 'voice') chanHalfOp = ircdb.makeChannelCapability(channel, 'halfop') if not ircdb.checkCapability(msg.prefix, chanOp): irc.sendMsg(ircmsgs.deop(channel, msg.nick)) for (mode, value) in ircutils.separateModes(msg.args[1:]): if not value: continue if ircutils.strEqual(value, msg.nick): # We allow someone to mode themselves to oblivion. continue if irc.isNick(value): hostmask = irc.state.nickToHostmask(value) if mode == '+o': if not self.isOp(irc, channel, hostmask): irc.queueMsg(ircmsgs.deop(channel, value)) elif mode == '+h': if not ircdb.checkCapability(hostmask, chanHalfOp): irc.queueMsg(ircmsgs.dehalfop(channel, value)) elif mode == '+v': if not ircdb.checkCapability(hostmask, chanVoice): irc.queueMsg(ircmsgs.devoice(channel, value)) elif mode == '-o': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.op(channel, value)) elif mode == '-h': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.halfop(channel, value)) elif mode == '-v': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.voice(channel, value)) else: assert ircutils.isUserHostmask(value)
def doMode(self, irc, msg): channel = msg.args[0] if irc.isChannel(channel) and msg.args[1:]: self.doLog(irc, channel, '*** %s sets mode: %s %s\n' % (msg.nick or msg.prefix, msg.args[1], ' '.join(msg.args[2:]))) modes = ircutils.separateModes(msg.args[1:]) for param in modes: realname = '' mode = param[0] mask = '' comment=None if param[0] not in ("+b", "-b", "+q", "-q"): continue mask = param[1] if mask.startswith("$r:"): mask = mask[3:] realname = ' (realname)' if param[0][1] == 'q': mask = '%' + mask if param[0] in ('+b', '+q'): comment = self.getHostFromBan(irc, msg, mask) self.doKickban(irc, channel, msg.prefix, mask + realname, extra_comment=comment) elif param[0] in ('-b', '-q'): self.doUnban(irc,channel, msg.nick, mask + realname)
def doMode(self, irc, msg): t = time.time() #self._log.info(repr(msg)) channel = msg.args[0] chan = self.__getChannel(channel) modeLists = {'b':chan.bans, 'e':chan.excepts, 'I':chan.invites} for (mode, value) in ircutils.separateModes(msg.args[1:]): (action, modeChar) = mode if modeChar in 'beI': md = modeLists[modeChar] if action == '-' and value in md: del md[value] elif action == '+': md[value] = (msg.prefix, t)
def doMode(self, irc, msg): channel = msg.args[0] mainchan = channel.replace('-unregged', '') if (channel.endswith('-unregged') and mainchan in self.registryValue('channels')) and channel in irc.state.channels: modes = ircutils.separateModes(msg.args[1:]) for (mode, value) in modes: if mode == '+i': kicks = [] for user in irc.state.channels[channel].users: if not (user in irc.state.channels[channel].ops or user in irc.state.channels[channel].voices): kicks.append(user) if 'r' in irc.state.channels[channel].modes: for user in kicks: irc.queueMsg(ircmsgs.IrcMsg('REMOVE %s %s :%s' % (channel, user, self.registryValue('kickMessage') % (mainchan, mainchan)))) irc.queueMsg(ircmsgs.mode(channel, '-ir')) else: for user in kicks: irc.queueMsg(ircmsgs.kick(channel, user, self.registryValue('kickMessage') % (mainchan, mainchan))) irc.queueMsg(ircmsgs.mode(channel, '-i'))