def testServerTags(self): s = '@aaa=b\\:bb;ccc;example.com/ddd=ee\\\\se ' \ ':[email protected] PRIVMSG me :Hello' m = ircmsgs.IrcMsg(s) self.assertEqual(m.server_tags, { 'aaa': 'b;bb', 'ccc': None, 'example.com/ddd': 'ee\\se' }) self.assertEqual(m.prefix, '[email protected]') self.assertEqual(m.command, 'PRIVMSG') self.assertEqual(m.args, ('me', 'Hello')) self.assertEqual(str(m), s + '\n')
def stab(self, irc, msg, args, channel, user, timer, reason): """<user> [seconds] [reason (ignored)] Stabs a user, putting them on quiet for a random time up to 10 mins.""" hmask = irc.state.nickToHostmask(user) hostmask = ircutils.joinHostmask('*', '*', ircutils.hostFromHostmask(hmask)) irc.queueMsg( ircmsgs.IrcMsg('MODE {0} +q {1}'.format(channel, hostmask))) if timer is not None: t = time.time() r = timer if not timer > 0: r = random.randint(30, 600) expires = t + r len = {} len['m'] = len['s'] = 0 while r > 59: len['m'] += 1 r -= 60 len['s'] = r irc.queueMsg( ircmsgs.IrcMsg( 'NOTICE +{0} :{1} has been quieted for {2}:{3:0>2}'.format( channel, user, len['m'], len['s']))) def f(): irc.queueMsg( ircmsgs.IrcMsg('MODE {0} -q {1}'.format(channel, hostmask))) schedule.addEvent(f, expires) irc.noReply()
def testNick(self): self.irc.reset() self.irc.feedMsg(ircmsgs.IrcMsg(':someuser JOIN #foo')) self.irc.feedMsg(ircmsgs.IrcMsg(':someuser JOIN #bar')) self.irc.feedMsg(ircmsgs.IrcMsg(':someuser2 JOIN #bar2')) class Callback(irclib.IrcCallback): channels_set = None def name(self): return 'testcallback' def doNick(self2, irc, msg): self2.channels_set = msg.tagged('channels') c = Callback() self.irc.addCallback(c) try: self.irc.feedMsg(ircmsgs.IrcMsg(':someuser NICK newuser')) finally: self.irc.removeCallback(c.name()) self.assertEqual(c.channels_set, ircutils.IrcSet(['#foo', '#bar']))
def startCapNegociation(self, caps='sasl'): m = self.irc.takeMsg() self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.failUnless(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m) m = self.irc.takeMsg() self.failUnless(m.command == 'NICK', 'Expected NICK, got %r.' % m) m = self.irc.takeMsg() self.failUnless(m.command == 'USER', 'Expected USER, got %r.' % m) self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP', args=('*', 'LS', caps))) if caps: m = self.irc.takeMsg() self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertEqual(m.args[0], 'REQ', m) self.assertEqual(m.args[1], 'sasl') self.irc.feedMsg( ircmsgs.IrcMsg(command='CAP', args=('*', 'ACK', 'sasl')))
def testReplyInstantBatchPartial(self): """response is shared as a batch + (1 more message)""" self.assertIsNone(self.irc.takeMsg()) conf.supybot.reply.mores.instant.setValue(2) self.irc.feedMsg(ircmsgs.privmsg( self.channel, "@eval 'foo '*300", prefix=self.prefix)) # First message opens the batch m = self.irc.takeMsg() self.assertEqual(m.command, 'BATCH', m) batch_name = m.args[0][1:] self.assertEqual( m, ircmsgs.IrcMsg(command='BATCH', args=('+' + batch_name, 'draft/multiline', self.channel))) # Second message, first PRIVMSG m = self.irc.takeMsg() self.assertEqual( m, ircmsgs.IrcMsg(command='PRIVMSG', args=(self.channel, "test: '" + "foo " * 110), server_tags={'batch': batch_name})) # Third message, last PRIVMSG m = self.irc.takeMsg() self.assertEqual( m, ircmsgs.IrcMsg(command='PRIVMSG', args=(self.channel, "foo " * 111 + "\x02(1 more message)\x02"), server_tags={'batch': batch_name, 'draft/multiline-concat': None})) # Last message, closes the batch m = self.irc.takeMsg() self.assertEqual( m, ircmsgs.IrcMsg(command='BATCH', args=( '-' + batch_name,)))
def setUp(self): self.irc = irclib.Irc('test') #m = self.irc.takeMsg() #self.failUnless(m.command == 'PASS', 'Expected PASS, got %r.' % m) m = self.irc.takeMsg() self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.failUnless(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m) m = self.irc.takeMsg() self.failUnless(m.command == 'NICK', 'Expected NICK, got %r.' % m) m = self.irc.takeMsg() self.failUnless(m.command == 'USER', 'Expected USER, got %r.' % m) # TODO self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP', args=('*', 'LS', '*', 'account-tag multi-prefix'))) self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP', args=('*', 'LS', 'extended-join'))) m = self.irc.takeMsg() self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertEqual(m.args[0], 'REQ', m) # NOTE: Capabilities are requested in alphabetic order, because # sets are unordered, and their "order" is nondeterministic. self.assertEqual(m.args[1], 'account-tag extended-join multi-prefix') self.irc.feedMsg(ircmsgs.IrcMsg(command='CAP', args=('*', 'ACK', 'account-tag multi-prefix extended-join'))) m = self.irc.takeMsg() self.failUnless(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertEqual(m.args, ('END',), m) m = self.irc.takeMsg() self.failUnless(m is None, m)
def doJoin(self, irc, msg): channel = msg.args[0] if channel != '#glob2': return nick = msg.nick if nick.startswith('[YOG]') and \ nick not in self.registryValue('nowelcome').split(' '): irc.queueMsg(ircmsgs.privmsg(nick, 'Hi %s, welcome to the ' 'globulation online game room. Those monitoring this room ' 'via IRC may awaken and challenge you to a game, if you type ' 'their name as given in the room participant window.' % nick)) if nick.startswith('[YOG]'): irc.queueMsg(ircmsgs.IrcMsg(s='WHOIS %s' % nick))
def _assertAutocompleteResponse(self, request, expectedResponse): self._sendRequest(request) m = self.irc.takeMsg() self.assertEqual( m, ircmsgs.IrcMsg( server_tags={ "+draft/reply": "1234", "+draft/autocomplete-response": expectedResponse, }, command="TAGMSG", args=[self.channel], ), )
def do376(self, irc, msg): """Oper up on connect. This listens on numerics 376 (end of MOTD) and 422 (MOTD not found).""" if not self.registryValue('autoOper'): return if irc.network in self.registryValue('operNets'): if self.registryValue("operName") and \ self.registryValue("operPass"): irc.sendMsg(ircmsgs.IrcMsg(command="OPER", args=[self.registryValue("operName"), self.registryValue("operPass")])) else: self.log.warning("OperUp: Bot is set to oper on network %s, but" " operName and/or operPass are not defined!", irc.network)
def verify(self, irc, msg, args, otherIrc, account, code): """[<network>] <account> <code> If the <network> requires a verification code, you need to call this command with the code the server gave you to finish the registration.""" self._checkCanRegister(irc, otherIrc) label = ircutils.makeLabel() self._register[label] = (irc, msg.nick) otherIrc.queueMsg( ircmsgs.IrcMsg(server_tags={"label": label}, command="VERIFY", args=[account, code]))
def testStsInCleartextConnectionInvalidDuration(self): # "Servers MAY send this key to all clients, but insecurely # connected clients MUST ignore it." self.irc.driver.anyCertValidationEnabled.return_value = False self.irc.driver.ssl = True self.irc.driver.currentServer = drivers.Server('irc.test', 6667, None, False) self.irc.feedMsg( ircmsgs.IrcMsg(command='CAP', args=('*', 'LS', 'sts=duration=foo,port=6697'))) self.assertEqual(ircdb.networks.getNetwork('test').stsPolicies, {}) self.irc.driver.reconnect.assert_called_once_with( server=drivers.Server('irc.test', 6697, None, True), wait=True)
def doPrivmsg(self, irc, msg): try: if ircmsgs.isCtcp(msg): self.log.debug('Returning early from doPrivmsg: isCtcp(msg).') return s = callbacks.addressed(irc.nick, msg) payload = self.normalize(s or msg.args[1], irc.nick, msg.nick) if s: msg.tag('addressed', payload) msg = ircmsgs.IrcMsg(args=(msg.args[0], payload), msg=msg) self.__parent.doPrivmsg(irc, msg) finally: self.changed = False self.added = False
def testFirstCommands(self): try: originalNick = conf.supybot.nick() originalUser = conf.supybot.user() originalPassword = conf.supybot.networks.test.password() nick = 'nick' conf.supybot.nick.setValue(nick) user = '******' conf.supybot.user.setValue(user) expected = [ ircmsgs.nick(nick), ircmsgs.IrcMsg(command='CAP', args=('REQ', 'account-notify')), ircmsgs.IrcMsg(command='CAP', args=('REQ', 'extended-join')), ircmsgs.IrcMsg(command='CAP', args=('REQ', 'multi-prefix')), ircmsgs.IrcMsg(command='CAP', args=('END', )), ircmsgs.user('limnoria', user) ] irc = irclib.Irc('test') msgs = [irc.takeMsg()] while msgs[-1] != None: msgs.append(irc.takeMsg()) msgs.pop() self.assertEqual(msgs, expected) password = '******' conf.supybot.networks.test.password.setValue(password) irc = irclib.Irc('test') msgs = [irc.takeMsg()] while msgs[-1] != None: msgs.append(irc.takeMsg()) msgs.pop() expected.insert(0, ircmsgs.password(password)) self.assertEqual(msgs, expected) finally: conf.supybot.nick.setValue(originalNick) conf.supybot.user.setValue(originalUser) conf.supybot.networks.test.password.setValue(originalPassword)
def testReplyInstantSingle(self): self.assertIsNone(self.irc.takeMsg()) # Single message as reply, no batch self.irc.feedMsg( ircmsgs.privmsg(self.channel, "@eval 'foo '*300", prefix=self.prefix)) m = self.irc.takeMsg() self.assertEqual( m, ircmsgs.IrcMsg(command='PRIVMSG', args=(self.channel, "test: '" + "foo " * 110 + " \x02(2 more messages)\x02"))) self.assertIsNone(self.irc.takeMsg())
def social(self, irc, msg, args, channel, user, junk): """[#powder] <user> Sets a redirection ban from #powder to #powder-social, kicks the user (exploiting a users auto-rejoin to force them to #powder-social) then lifts the ban. Also sends the user a notice informing them of what happened.""" if channel not in '#powder': channel = '#powder' irc.queueMsg( ircmsgs.IrcMsg('MODE #powder +b {}$#powder-social'.format( irc.state.nickToHostmask(user)))) irc.queueMsg( ircmsgs.IrcMsg( 'KICK #powder {} :Take it to #powder-social'.format(user))) irc.queueMsg(ircmsgs.invite(user, '#powder-social')) irc.queueMsg( ircmsgs.IrcMsg( 'NOTICE {} :{} has requested you take your current conversation to #powder-social.' .format(user, msg.nick))) expires = time.time() + 300 def f(): irc.queueMsg( ircmsgs.IrcMsg('MODE #powder -b {}$#powder-social'.format( irc.state.nickToHostmask(user)))) schedule.addEvent(f, expires)
def _createPrivmsg(self, irc, channel, payload, event): bold = ircutils.bold format_ = self.plugin.registryValue('format.%s' % event, channel) if not format_.strip(): return repl = flatten_subdicts(payload) for (key, value) in dict(repl).items(): if isinstance(value, basestring) and \ value.startswith(('http://', 'https://')) and \ key + '__tiny' in format_: host = urlparse(value).netloc if host == 'github.com' or host.endswith('.github.com'): url = self._shorten_url(value) if url: repl[key + '__tiny'] = url else: repl[key + '__tiny'] = value else: repl[key + '__tiny'] = value elif isinstance(value, basestring) and \ re.search(r'^[a-f0-9]{40}$', value): # Check if it looks like a commit ID, because there are key # names such as "before" and "after" containing commit IDs. repl[key + '__short'] = value[0:7] elif key == 'commits': repl['__num_commits'] = len(value) elif key.endswith('ref'): try: repl[key + '__branch'] = value.split('/', 2)[2] \ if value else None except IndexError: pass elif isinstance(value, str) or \ (sys.version_info[0] < 3 and isinstance(value, unicode)): repl[key + '__firstline'] = value.split('\n', 1)[0] tokens = callbacks.tokenize(format_) if not tokens: return fake_msg = ircmsgs.IrcMsg(command='PRIVMSG', args=(channel, 'GITHUB'), prefix='github!github@github', reply_env=repl) try: self.plugin.Proxy(irc, fake_msg, tokens) except Exception as e: self.plugin.log.exception( 'Error occured while running triggered command:')
def testClientTagReplyChannel(self): self.irc.addCallback(self.First(self.irc)) try: conf.supybot.protocols.irc.experimentalExtensions.setValue(True) self.irc.state.capabilities_ack.add('message-tags') # Reply in channel to channel message -> +draft/channel-context # is absent self.irc.feedMsg( ircmsgs.IrcMsg(command='PRIVMSG', prefix=self.prefix, args=('#foo', '%s: firstcmd' % self.nick), server_tags={'msgid': 'foobar'})) msg = self.irc.takeMsg() self.assertEqual( msg, ircmsgs.IrcMsg(command='PRIVMSG', args=('#foo', '%s: foo' % self.nick), server_tags={'+draft/reply': 'foobar'})) # Reply in private to channel message -> +draft/channel-context # is present with conf.supybot.reply.inPrivate.context(True): self.irc.feedMsg( ircmsgs.IrcMsg(command='PRIVMSG', prefix=self.prefix, args=('#foo', '%s: firstcmd' % self.nick), server_tags={'msgid': 'foobar'})) msg = self.irc.takeMsg() self.assertEqual( msg, ircmsgs.IrcMsg(command='NOTICE', args=(self.nick, 'foo'), server_tags={ '+draft/reply': 'foobar', '+draft/channel-context': '#foo' })) # Reply in private to private message -> +draft/channel-context # is absent self.irc.feedMsg( ircmsgs.IrcMsg(command='PRIVMSG', prefix=self.prefix, args=(self.nick, 'firstcmd'), server_tags={'msgid': 'foobar'})) msg = self.irc.takeMsg() self.assertEqual( msg, ircmsgs.IrcMsg(command='NOTICE', args=(self.nick, 'foo'), server_tags={'+draft/reply': 'foobar'})) finally: conf.supybot.protocols.irc.experimentalExtensions.setValue(False) self.irc.state.capabilities_ack.remove('message-tags')
def testNoMsgLongerThan512(self): self.irc.queueMsg(ircmsgs.privmsg('whocares', 'x' * 1000)) msg = self.irc.takeMsg() self.assertEqual(len(msg), 512, 'len(msg) was %s (msg=%r)' % (len(msg), msg)) # Server tags don't influence the size limit of the rest of the # message. self.irc.queueMsg( ircmsgs.IrcMsg(command='PRIVMSG', args=['whocares', 'x' * 1000], server_tags={'y': 'z' * 500})) msg2 = self.irc.takeMsg() self.assertEqual(len(msg2), 512 + 504, 'len(msg2) was %s (msg2=%r)' % (len(msg2), msg2)) self.assertEqual(msg.args, msg2.args)
def doJoin(self, irc, msg): channel = msg.args[0] if channel != '#glob2': return nick = msg.nick if nick.startswith('[YOG]') and \ nick not in self.registryValue('nowelcome').split(' '): irc.queueMsg( ircmsgs.privmsg( nick, 'Hi %s, welcome to the ' 'globulation online game. Some people are connected from ' 'IRC if you say there name, they may answer you or start ' 'playing. For more help, type "@g2help" (without the quotes).' % nick)) if nick.startswith('[YOG]'): irc.queueMsg(ircmsgs.IrcMsg(s='WHOIS %s' % nick))
def outFilter(self, irc, msg): if msg.command == 'PRIVMSG': if msg.args[0] in self.outFilters: if ircmsgs.isAction(msg): s = ircmsgs.unAction(msg) else: s = msg.args[1] methods = self.outFilters[msg.args[0]] for filtercommand in methods: myIrc = MyFilterProxy() filtercommand(myIrc, msg, [s]) s = myIrc.s if ircmsgs.isAction(msg): msg = ircmsgs.action(msg.args[0], s, msg=msg) else: msg = ircmsgs.IrcMsg(msg=msg, args=(msg.args[0], s)) return msg
def doTagmsg(self, irc, msg): if REQUEST_TAG not in msg.server_tags: return if "msgid" not in msg.server_tags: return if not self._enabled(irc, msg): return msgid = msg.server_tags["msgid"] text = msg.server_tags[REQUEST_TAG] # using callbacks._addressed instead of callbacks.addressed, as # callbacks.addressed would tag the m payload = callbacks._addressed(irc, msg, payload=text) if not payload: # not addressed return # marks used by '_addressed' are usually prefixes (char, string, # nick), but may also be suffixes (with # supybot.reply.whenAddressedBy.nick.atEnd); but there is no way to # have it in the middle of the message AFAIK. assert payload in text if not text.endswith(payload): # If there is a suffix, it means the end of the text is used to # address the bot, so it can't be a method to be completed. return autocomplete_response = _getAutocompleteResponse(irc, msg, payload) if not autocomplete_response: return target = msg.channel or ircutils.nickFromHostmask(msg.prefix) irc.queueMsg( ircmsgs.IrcMsg( server_tags={ "+draft/reply": msgid, RESPONSE_TAG: autocomplete_response, }, command="TAGMSG", args=[target], ) )
def let(self, irc, msg, args, var_name, _, value, __, command): """<variable> = <value> in <command> Defines <variable> to be equal to <value> in the <command> and runs the <command>. '=' and 'in' can be omitted.""" if msg.reply_env and var_name in msg.reply_env: # For security reason (eg. a Sudo-like plugin), we don't want # to make it possible to override stuff like $nick. irc.error(_('Cannot set a variable that already exists.'), Raise=True) fake_msg = ircmsgs.IrcMsg(msg=msg) if fake_msg.reply_env is None: fake_msg.reply_env = {} fake_msg.reply_env[var_name] = value tokens = callbacks.tokenize(command) self.Proxy(irc, fake_msg, tokens)
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'))
def _createPrivmsg(self, irc, channel, payload, event, hidden=None): bold = ircutils.bold format_ = self.plugin.registryValue('format.%s' % event, channel) if not format_.strip(): return repl = flatten_subdicts(payload) try_gitio = True for (key, value) in dict(repl).items(): if key.endswith('url'): if try_gitio: url = self._shorten_url(value) else: url = None if url: repl[key + '__tiny'] = url else: repl[key + '__tiny'] = value try_gitio = False elif key.endswith('ref'): try: repl[key + '__branch'] = value.split('/', 2)[2] except IndexError: pass elif isinstance(value, str) or \ (sys.version_info[0] < 3 and isinstance(value, unicode)): repl[key + '__firstline'] = value.split('\n', 1)[0] repl.update({'__hidden': hidden or 0}) #if hidden is not None: # s += _(' (+ %i hidden commits)') % hidden #if sys.version_info[0] < 3: # s = s.encode('utf-8') tokens = callbacks.tokenize(format_) if not tokens: return fake_msg = ircmsgs.IrcMsg(command='PRIVMSG', args=(channel, 'GITHUB'), prefix='github!github@github', reply_env=repl) try: self.plugin.Proxy(irc, fake_msg, tokens) except Exception as e: self.plugin.log.exception('Error occured while running triggered command:')
def doNotice(self, irc, msg): if irc.state.supported.get('NETWORK', '') == 'UnderNet': if '[email protected]' in msg.prefix: if 'AUTHENTICATION SUCCESSFUL as' in msg.args[1]: log.info("Successfully authed to X.") modex = self.registryValue('modeXonID') if modex: log.info("Setting +x") irc.sendMsg( ircmsgs.IrcMsg("MODE {} +x".format(irc.nick))) else: log.info("Received a NOTICE from X. msg: {}".format( msg.args[1])) return else: if 'AUTHENTICATION SUCCESSFUL as' in msg.args[1]: log.warning("Someone is impersonating X!") else: log.debug("Notice isn't from UnderNet.. Ignoring")
def getName(self, nick, msg, match): addressed = callbacks.addressed(nick, msg) name = callbacks.addressed( nick, ircmsgs.IrcMsg(prefix='', args=(msg.args[0], match.group(1)), msg=msg)) if not name: name = match.group(1) if not addressed: if not self.registryValue('allowUnaddressedKarma'): return '' if not msg.args[1].startswith(match.group(1)): return '' name = match.group(1) elif addressed: if not addressed.startswith(name): return '' name = name.strip('()') return name
def operup(self, irc, msg, args): """takes no arguments. Makes the bot Oper up using the name and password defined in config. """ if irc.nested: irc.error("This command cannot be nested.", Raise=True) if irc.network in self.registryValue('operNets'): if self.registryValue("operName") and \ self.registryValue("operPass"): irc.sendMsg(ircmsgs.IrcMsg(command="OPER", args=[self.registryValue("operName"), self.registryValue("operPass")])) irc.replySuccess() else: irc.error(_("Either the operName or the operPass " "configuration values were not properly defined. Please " "check to see if these values are correct!")) else: irc.error(_("This network is not configured for opering! (see" " 'config plugins.OperUp.opernets')"))
def testStandardSubstitute(self): # Stub out random msg and irc objects that provide what # standardSubstitute wants irc = getTestIrc() msg = ircmsgs.IrcMsg(':%s PRIVMSG #channel :stuff' % self.hostmask) irc._tagMsg(msg) f = ircutils.standardSubstitute vars = {'foo': 'bar', 'b': 'c', 'i': 100, 'f': lambda: 'called'} self.assertEqual(f(irc, msg, '$foo', vars), 'bar') self.assertEqual(f(irc, None, '$foo', vars), 'bar') self.assertEqual(f(None, None, '$foo', vars), 'bar') self.assertEqual(f(None, msg, '$foo', vars), 'bar') self.assertEqual(f(irc, msg, '${foo}', vars), 'bar') self.assertEqual(f(irc, msg, '$b', vars), 'c') self.assertEqual(f(irc, msg, '${b}', vars), 'c') self.assertEqual(f(irc, msg, '$i', vars), '100') self.assertEqual(f(irc, msg, '${i}', vars), '100') self.assertEqual(f(irc, msg, '$f', vars), 'called') self.assertEqual(f(irc, msg, '${f}', vars), 'called') self.assertEqual(f(irc, msg, '$b:$i', vars), 'c:100')
def testEchomessageLabeledresponseGrouped(self): self.irc = irclib.Irc('test') m = self.irc.takeMsg() self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertTrue(m.args == ('LS', '302'), 'Expected CAP LS 302, got %r.' % m) m = self.irc.takeMsg() self.assertTrue(m.command == 'NICK', 'Expected NICK, got %r.' % m) m = self.irc.takeMsg() self.assertTrue(m.command == 'USER', 'Expected USER, got %r.' % m) self.irc.REQUEST_CAPABILITIES = set( ['account-notify', 'a' * 490, 'echo-message', 'labeled-response']) self.irc.feedMsg( ircmsgs.IrcMsg(command='CAP', args=('*', 'LS', 'account-notify ' + 'a' * 490 + ' echo-message labeled-response'))) m = self.irc.takeMsg() self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertEqual(m.args[0], 'REQ', m) self.assertEqual(m.args[1], 'echo-message labeled-response') m = self.irc.takeMsg() self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertEqual(m.args[0], 'REQ', m) self.assertEqual(m.args[1], 'a' * 490) m = self.irc.takeMsg() self.assertTrue(m.command == 'CAP', 'Expected CAP, got %r.' % m) self.assertEqual(m.args[0], 'REQ', m) self.assertEqual(m.args[1], 'account-notify') m = self.irc.takeMsg() self.assertIsNone(m)
def doNotice(self, irc, msg): if irc.state.supported.get("NETWORK", "") == "UnderNet": if "[email protected]" in msg.prefix: if "AUTHENTICATION SUCCESSFUL as" in msg.args[1]: log.info("Successfully authed to X.") modex = self.registryValue("modeXonID") if modex: log.info("Setting +x") irc.sendMsg( ircmsgs.IrcMsg("MODE {} +x".format(irc.nick))) self.identified = True waitingJoins = self.waitingJoins.pop(irc.network, None) if waitingJoins: for m in waitingJoins: irc.sendMsg(m) else: log.info("Received a NOTICE from X. msg: {}".format( msg.args[1])) return else: if "AUTHENTICATION SUCCESSFUL as" in msg.args[1]: log.warning("Someone is impersonating X!") else: log.debug("Notice isn't from UnderNet.. Ignoring")