def test_from_twitch_privmsg_bits(self): IrcMessage.fromMessage('''\ @badges=staff/1,bits/1000;bits=100;color=;display-name=TWITCH_UserNaME;\ emotes=;id=b34ccfc7-4977-403a-8a94-33c6bac34fb8;mod=0;room-id=1337;\ subscriber=0;turbo=1;user-id=1337;user-type=staff \ :twitch_username!twitch_username@twitch_username.tmi.twitch.tv \ PRIVMSG #channel :cheer100''')
def test_log_irc_part(self): self.channel.ircUsers.add('botgotsthis') message = IrcMessage.fromMessage( ':[email protected] PART ' '#botgotsthis') ircmessage.irc_part(self.connection, message, self.now) self.assertEqual(self.channel.ircUsers, set())
def test_log_irc_notice(self, mock_parse): message = IrcMessage.fromMessage( '@msg-id=bad_timeout_broadcaster :tmi.twitch.tv NOTICE ' '#botgotsthis :You cannot timeout the broadcaster.') ircmessage.irc_notice(self.connection, message, self.now) self.assertTrue(mock_parse.called) self.assertTrue(self.mock_log.called)
def test_from_twitch_privmsg(self): self.assertEqual( IrcMessage.fromMessage( '@badges=broadcaster/1;color=#DAA520;display-name=BotGotsThis;' 'emotes=25:6-10;mod=1;room-id=42553092;subscriber=0;turbo=0;' 'user-id=55612319;user-type=mod ' ':[email protected] ' 'PRIVMSG #botgotsthis :Hello Kappa'), IrcMessage( tags=IrcMessageTagsReadOnly({ 'badges': 'broadcaster/1', 'color': '#DAA520', 'display-name': 'BotGotsThis', 'emotes': '25:6-10', 'mod': '1', 'room-id': '42553092', 'subscriber': '0', 'turbo': '0', 'user-id': '55612319', 'user-type': 'mod' }), prefix=IrcMessagePrefix(nick='botgotsthis', user='******', host='botgotsthis.tmi.twitch.tv'), command='PRIVMSG', params=IrcMessageParams(middle='#botgotsthis', trailing='Hello Kappa')))
def test_log_irc_353(self): message = IrcMessage.fromMessage( ':botgotsthis.tmi.twitch.tv 353 botgotsthis = #botgotsthis ' ':botgotsthis') ircmessage.irc_353(self.connection, message, self.now) self.assertEqual(self.channel.ircUsers, {'botgotsthis'}) self.assertTrue(self.mock_log.called)
def test_log_irc_privmsg_no_channel(self, mock_parse, mock_config): mock_config.botnick = 'botgotsthis' message = IrcMessage.fromMessage( ':[email protected] PRIVMSG ' '#megotsthis :Hello Kappa') ircmessage.irc_privmsg(self.connection, message, self.now) self.assertFalse(mock_parse.called) self.assertTrue(self.mock_log.called)
def test_from_twitch_001(self): self.assertEqual( IrcMessage.fromMessage( ':tmi.twitch.tv 001 botgotsthis :Welcome, GLHF!'), IrcMessage(prefix=IrcMessagePrefix(servername='tmi.twitch.tv'), command=1, params=IrcMessageParams(middle='botgotsthis', trailing='Welcome, GLHF!')))
def test_log_irc_privmsg_mention(self, mock_parse, mock_config): mock_config.botnick = 'botgotsthis' message = IrcMessage.fromMessage( ':[email protected] PRIVMSG ' '#botgotsthis :botgotsthis') ircmessage.irc_privmsg(self.connection, message, self.now) self.assertTrue(mock_parse.called) self.assertGreaterEqual(self.mock_log.call_count, 2)
def test_log_irc_whisper(self, mock_parse, mock_config): mock_config.botnick = 'botgotsthis' message = IrcMessage.fromMessage( ':[email protected] WHISPER ' 'botgotsthis :Kappa') ircmessage.irc_whisper(self.connection, message, self.now) self.assertTrue(mock_parse.called) self.assertGreaterEqual(self.mock_log.call_count, 3)
def test_from_prefix_command_param_middle(self): self.assertEqual( IrcMessage.fromMessage('''\ :[email protected] JOIN #botgotsthis'''), IrcMessage( prefix=IrcMessagePrefix(nick='botgotsthis', user='******', host='botgotsthis.tmi.twitch.tv'), command='JOIN', params=IrcMessageParams(middle='#botgotsthis')))
def parseMessage(connection: 'connectionM.ConnectionHandler', ircmsg: str, timestamp: datetime) -> None: message: IrcMessage = IrcMessage.fromMessage(ircmsg) if message.command in ircHandlers: ircHandlers[message.command](connection, message, timestamp) log_channel_message(message, timestamp) pkg: str for pkg in bot.globals.pkgs: ircmessage: Any ircmessage = importlib.import_module('pkg.' + pkg + '.ircmessage') ircmessage.parseMessage(connection, ircmsg, timestamp)
def test_from_command_param_middle(self): self.assertEqual(IrcMessage.fromMessage('PART #botgotsthis'), IrcMessage(command='PART', params=IrcMessageParams( middle='#botgotsthis')))
def test_log_irc_join(self): message = IrcMessage.fromMessage( ':[email protected] JOIN ' '#botgotsthis') ircmessage.irc_join(self.connection, message, self.now) self.assertEqual(self.channel.ircUsers, {'botgotsthis'})
def test_log_irc_reconnect(self): message = IrcMessage.fromMessage(':tmi.twitch.tv RECONNECT') with self.assertRaises(ConnectionReset): ircmessage.irc_reconnect(self.connection, message, self.now)
def test_log_irc_hosttarget(self): message = IrcMessage.fromMessage( ':tmi.twitch.tv ROOMSTATE #megotsthis') ircmessage.irc_clearchat(self.connection, message, self.now) self.assertTrue(self.mock_log.called)
def test_log_irc_pong(self, mock_config): mock_config.botnick = 'botgotsthis' message = IrcMessage.fromMessage( ':tmi.twitch.tv PONG tmi.twitch.tv :botgotsthis') ircmessage.irc_pong(self.connection, message, self.now) self.assertEqual(self.connection.lastPing, self.now)
def test_log_irc_userstate(self, mock_parse): message = IrcMessage.fromMessage( ':tmi.twitch.tv CLEARCHAT #botgotsthis') ircmessage.irc_userstate(self.connection, message, self.now) self.assertTrue(mock_parse.called) self.assertTrue(self.mock_log.called)
def test_log_irc_ping(self): message = IrcMessage.fromMessage('PING :tmi.twitch.tv') ircmessage.irc_ping(self.connection, message, self.now) self.assertTrue(self.connection.ping.called)
def test_log_irc_mode_plus_o_duplicating(self): self.channel.ircOps = {'botgotsthis'} message = IrcMessage.fromMessage( ':jtv MODE #botgotsthis +o botgotsthis') ircmessage.irc_mode(self.connection, message, self.now) self.assertEqual(self.channel.ircOps, {'botgotsthis'})
def test_log_irc_366(self): message = IrcMessage.fromMessage( ':botgotsthis.tmi.twitch.tv 366 botgotsthis #botgotsthis ' ':End of /NAMES list') ircmessage.irc_353(self.connection, message, self.now) self.assertTrue(self.mock_log.called)
def test_log_irc_mode_minus_o_empty(self): message = IrcMessage.fromMessage( ':jtv MODE #botgotsthis -o botgotsthis') ircmessage.irc_mode(self.connection, message, self.now) self.assertEqual(self.channel.ircOps, set())
def test_from_command(self): self.assertEqual(IrcMessage.fromMessage('RECONNECT'), IrcMessage(command='RECONNECT'))