async def on_message(self, prot: IRCProtocol, msg: Message): self.network.feed_message(msg) if msg.isnumeric('001'): prot.sendline('JOIN #botted') prot.loop.call_later( 15, prot.sendline, 'PRIVMSG #botted :waited for ' '15 seconds to say something! o/') if isinstance(msg, Privmsg): if msg.message == '+test': prot.sendline('QUIT :quitting you bastard!' .format(msg.sender)) elif msg.message == '+cycle': if is_channel(msg.target): prot.sendline('PART {} :Cycling! Because I can!' .format(msg.target)) prot.sendline('JOIN {}'.format(msg.target)) elif msg.message.startswith('+'): return if is_channel(msg.target) and \ ('http://' in msg.message or 'https://' in msg.message)\ and not msg.message.startswith('+'): def replace_url(match): the_url, = match.groups('url') return '\x0304\x02{}\x0F'.format(the_url) text = utils.url_pattern.sub(replace_url, msg.message) prot.sendline('PRIVMSG {} :Matched: {}' .format(msg.target, text)) if isinstance(msg, CtcpRequest): if msg.ctcp_command == 'VERSION': prot.sendline('NOTICE {} :\x01VERSION {}\x01' .format(msg.sender, 'Shanghai Doll 0.1dev'))
def test_rfc(self): # https://tools.ietf.org/html/rfc2812#section-2.2 a = parse.rfc_lower('ABCabc{}|^0123') self.assertEqual(a, 'abcabc[]\\~0123') a = parse.rfc_lower('ABCabc[]\\~0123') self.assertEqual(a, 'abcabc[]\\~0123') a = parse.rfc_upper('ABCabc{}|^0123') self.assertEqual(a, 'ABCABC{}|^0123') a = parse.rfc_upper('ABCabc[]\\~0123') self.assertEqual(a, 'ABCABC{}|^0123') self.assertTrue(parse.is_channel('#foobar')) self.assertTrue(parse.is_channel('&foobar')) self.assertTrue(parse.is_channel('+foobar')) self.assertTrue(parse.is_channel('!foobar')) self.assertFalse(parse.is_channel('#')) self.assertFalse(parse.is_channel('&')) self.assertFalse(parse.is_channel('+')) self.assertFalse(parse.is_channel('!')) self.assertFalse(parse.is_channel('foobar')) self.assertFalse(parse.is_channel('#foo\0bar')) self.assertFalse(parse.is_channel('#foo\nbar')) self.assertFalse(parse.is_channel('#foo\rbar')) self.assertFalse(parse.is_channel('#foo\abar')) self.assertFalse(parse.is_channel('#foo bar')) self.assertFalse(parse.is_channel('#foo,bar')) self.assertFalse(parse.is_channel('#foo:bar'))