コード例 #1
0
 def flush_writes(self) -> None:
     self.messaging.cleanOldTimestamps()
     whisperMessage: WhisperMessage
     for whisperMessage in iter(self.messaging.popWhisper, None):
         ircMsg: str = f'.w {whisperMessage.nick} {whisperMessage.message}'
         ircMsg = ircMsg[:bot.config.messageLimit]
         try:
             self.queue_write(IrcMessage(
                 None, None, 'PRIVMSG',
                 IrcMessageParams(bot.globals.groupChannel.ircChannel,
                                  ircMsg)),
                              whisper=whisperMessage)
         except ValueError:
             utils.logException()
     nessage: ChatMessage
     for message in iter(self.messaging.popChat, None):
         try:
             self.queue_write(IrcMessage(
                 None, None, 'PRIVMSG',
                 IrcMessageParams(
                     message.channel.ircChannel,
                     message.message[:bot.config.messageLimit])),
                              channel=message.channel)
         except ValueError:
             utils.logException()
コード例 #2
0
 def test_command_params_middle(self):
     message = IrcMessage(command='JOIN',
                          params=IrcMessageParams(middle='#botgotsthis'))
     self.assertIsNone(message.tags)
     self.assertIsNone(message.prefix)
     self.assertEqual(message.command, 'JOIN')
     self.assertIs(message.params.middle, '#botgotsthis')
     self.assertIs(message.params.trailing, None)
     self.assertEqual(message,
                      IrcMessage(command='JOIN',
                                 params=IrcMessageParams('#botgotsthis')))
コード例 #3
0
 def test_command_params_middle_trailing(self):
     message = IrcMessage(command='PRIVMSG',
                          params=IrcMessageParams(middle='#botgotsthis',
                                                  trailing='Hello World'))
     self.assertIsNone(message.tags)
     self.assertIsNone(message.prefix)
     self.assertEqual(message.command, 'PRIVMSG')
     self.assertIs(message.params.middle, '#botgotsthis')
     self.assertIs(message.params.trailing, 'Hello World')
     self.assertEqual(
         message,
         IrcMessage(command='PRIVMSG',
                    params=IrcMessageParams('#botgotsthis', 'Hello World')))
コード例 #4
0
 def test_parse_prefix_servername_command_params_middle_trailing(self):
     self.assertEqual(
         IrcMessage.parse(':tmi.twitch.tv PONG tmi.twitch.tv :botgotsthis'),
         ParsedMessage(None,
                       IrcMessagePrefix(servername='tmi.twitch.tv'),
                       'PONG',
                       IrcMessageParams('tmi.twitch.tv', 'botgotsthis')))
コード例 #5
0
 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')))
コード例 #6
0
    def test_parse_multiple_spaces(self):
        self.assertEqual(
            IrcMessage.parse('''\
@multiple=spaces  :will!be@used  HERE  to  test :if  this  passes'''),
            ParsedMessage(
                IrcMessageTagsReadOnly({'multiple': 'spaces'}),
                IrcMessagePrefix(nick='will', user='******', host='used'),
                'HERE', IrcMessageParams('to test', 'if  this  passes')))
コード例 #7
0
 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!')))
コード例 #8
0
    def test_str_magic_prefix_command_params(self):
        self.assertEqual(
            str(IrcMessage(
                prefix=IrcMessagePrefix(nick='botgotsthis',
                                        user='******',
                                        host='botgotsthis.tmi.twitch.tv'),
                command='PART',
                params=IrcMessageParams('#botgotsthis'))),
            '''\
:[email protected] PART #botgotsthis''')
コード例 #9
0
    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')))
コード例 #10
0
    def part_channel(self, channel: 'data.Channel') -> None:
        if channel.channel not in self._channels:
            return
        self.queue_write(
            IrcMessage(None, None, 'PART',
                       IrcMessageParams(channel.ircChannel)))
        del self._channels[channel.channel]

        join.on_part(channel.channel)
        print(f'{utils.now()} Parted {channel.channel}')
コード例 #11
0
    def test_parse_prefix_command_params_middle(self):
        self.assertEqual(
            IrcMessage.parse('''\
:[email protected] JOIN #botgotsthis'''),
            ParsedMessage(None,
                          IrcMessagePrefix(nick='bot_gots_this',
                                           user='******',
                                           host='botgotsthis.tmi.twitch.tv'),
                          'JOIN',
                          IrcMessageParams('#botgotsthis')))
コード例 #12
0
 def send_ping(self) -> None:
     now = utils.now()
     sinceLastSend: timedelta = now - self.lastSentPing
     sinceLast: timedelta = now - self.lastPing
     if sinceLastSend >= timedelta(minutes=1):
         self.queue_write(IrcMessage(None, None, 'PING',
                                     IrcMessageParams(bot.config.botnick)),
                          prepend=True)
         self.lastSentPing = now
     elif sinceLast >= timedelta(minutes=1, seconds=15):
         raise ConnectionError()
コード例 #13
0
 async def login(self, writer: asyncio.StreamWriter) -> None:
     if not isinstance(writer, asyncio.StreamWriter):
         raise TypeError()
     commands: List[IrcMessage] = [
         IrcMessage(None, None, 'PASS',
                    IrcMessageParams(bot.config.password or None)),
         IrcMessage(None, None, 'NICK',
                    IrcMessageParams(bot.config.botnick)),
         IrcMessage(
             None, None, 'USER',
             IrcMessageParams(bot.config.botnick + ' 0 *',
                              bot.config.botnick)),
         IrcMessage(None, None, 'CAP',
                    IrcMessageParams('REQ', 'twitch.tv/membership')),
         IrcMessage(None, None, 'CAP',
                    IrcMessageParams('REQ', 'twitch.tv/commands')),
         IrcMessage(None, None, 'CAP',
                    IrcMessageParams('REQ', 'twitch.tv/tags')),
     ]
     command: IrcMessage
     for command in commands:
         message: bytes = (str(command) + '\r\n').encode('utf-8')
         writer.write(message)
         self._log_write(command)
         await writer.drain()
コード例 #14
0
 def test_str_tags_magic_prefix_command_params(self):
     message = IrcMessage(
             tags=IrcMessageTagsReadOnly({
                 'broadcaster-lang': '',
                 'emote-only': '0',
                 'r9k': '0',
                 'slow': '0',
                 'subs-only': '0'
                 }),
             prefix=IrcMessagePrefix(servername='tmi.twitch.tv'),
             command='ROOMSTATE', params=IrcMessageParams('#botgotsthis'))
     self.assertEqual(
         str(message),
         '@' + str(message.tags) + ' :tmi.twitch.tv ROOMSTATE #botgotsthis')
コード例 #15
0
 def test_tags_prefix_command_params(self):
     message = IrcMessage(
         tags=IrcMessageTagsReadOnly({
             'broadcaster-lang': '',
             'emote-only': '0',
             'r9k': '0',
             'slow': '0',
             'subs-only': '0'
             }),
         prefix=IrcMessagePrefix(servername='tmi.twitch.tv'),
         command='ROOMSTATE', params=IrcMessageParams('#botgotsthis'))
     self.assertEqual(len(message.tags), 5)
     self.assertEqual(message.tags['broadcaster-lang'], '')
     self.assertEqual(message.tags['emote-only'], '0')
     self.assertEqual(message.tags['r9k'], '0')
     self.assertEqual(message.tags['slow'], '0')
     self.assertEqual(message.tags['subs-only'], '0')
     self.assertEqual(message.prefix.servername, 'tmi.twitch.tv')
     self.assertIsNone(message.prefix.nick)
     self.assertIsNone(message.prefix.user)
     self.assertIsNone(message.prefix.host)
     self.assertEqual(message.command, 'ROOMSTATE')
     self.assertIs(message.params.middle, '#botgotsthis')
     self.assertIs(message.params.trailing, None)
     self.assertEqual(
         message,
         IrcMessage(
             tags=IrcMessageTagsReadOnly({
                 'broadcaster-lang': '',
                 'emote-only': '0',
                 'r9k': '0',
                 'slow': '0',
                 'subs-only': '0'
                 }),
             prefix=IrcMessagePrefix(servername='tmi.twitch.tv'),
             command='ROOMSTATE',
             params=IrcMessageParams('#botgotsthis')))
コード例 #16
0
 def test_prefix_command_params(self):
     message = IrcMessage(
         prefix=IrcMessagePrefix(
             nick='botgotsthis',
             user='******',
             host='botgotsthis.tmi.twitch.tv'),
         command='PART',
         params=IrcMessageParams('#botgotsthis'))
     self.assertIsNone(message.prefix.servername)
     self.assertEqual(message.prefix.nick, 'botgotsthis')
     self.assertEqual(message.prefix.user, 'botgotsthis')
     self.assertEqual(message.prefix.host, 'botgotsthis.tmi.twitch.tv')
     self.assertEqual(message.command, 'PART')
     self.assertIs(message.params.middle, '#botgotsthis')
     self.assertIs(message.params.trailing, None)
     self.assertEqual(
         message,
         IrcMessage(
             prefix=IrcMessagePrefix(
                 nick='botgotsthis',
                 user='******',
                 host='botgotsthis.tmi.twitch.tv'),
             command='PART',
             params=IrcMessageParams('#botgotsthis')))
コード例 #17
0
ファイル: join.py プロジェクト: PikalaxALT/BotGotsThis
def join_a_channel() -> None:
    if not _can_process():
        return

    channels: Dict[str, data.Channel] = _connected_channels()
    notJoined: Set[str] = set(channels.keys()) - _channelJoined
    if not notJoined:
        return

    broadcaster: Optional[str]
    broadcaster = _get_join_with_lowest_priority(channels, notJoined)
    if broadcaster is None:
        return
    chat: data.Channel = channels[broadcaster]
    if chat.connection is None:
        return
    ircCommand: IrcMessage = IrcMessage(None, None, 'JOIN',
                                        IrcMessageParams(chat.ircChannel))
    chat.connection.queue_write(ircCommand, channel=chat)
    _channelJoined.add(chat.channel)
コード例 #18
0
 def test_trailing_empty(self):
     params = IrcMessageParams(trailing='')
     self.assertIsNone(params.middle)
     self.assertEqual(params.trailing, '')
     self.assertEqual(params, IrcMessageParams(None, ''))
     self.assertIs(params.isEmpty, False)
コード例 #19
0
 def test_command_set_params(self):
     message = IrcMessage(command=0)
     with self.assertRaises(AttributeError):
         message.params = IrcMessageParams()
コード例 #20
0
 def test_trailing_starting_colon(self):
     params = IrcMessageParams(trailing=':Kappa')
     self.assertEqual(params.trailing, ':Kappa')
コード例 #21
0
 def test_trailing(self):
     params = IrcMessageParams(trailing='Kappa')
     self.assertEqual(params.trailing, 'Kappa')
     self.assertEqual(params, IrcMessageParams(None, 'Kappa'))
コード例 #22
0
 def test_str_magic_command_params_middle(self):
     self.assertEqual(
         str(IrcMessage(command='JOIN',
                        params=IrcMessageParams(middle='#botgotsthis'))),
         'JOIN #botgotsthis')
コード例 #23
0
 def test_from_command_param_middle(self):
     self.assertEqual(IrcMessage.fromMessage('PART #botgotsthis'),
                      IrcMessage(command='PART',
                                 params=IrcMessageParams(
                                     middle='#botgotsthis')))
コード例 #24
0
 def test_parse_empty_middle(self):
     self.assertEqual(IrcMessage.parse('TEST :empty middle'),
                      ParsedMessage(None, None, 'TEST',
                                    IrcMessageParams(None, 'empty middle')))
コード例 #25
0
 def test_parse_empty_trailing(self):
     self.assertEqual(
         IrcMessage.parse('TEST middle empty trail :'),
         ParsedMessage(None, None, 'TEST',
                       IrcMessageParams('middle empty trail', '')))
コード例 #26
0
 def test_str_magic_command_params_middle_trailing(self):
     self.assertEqual(
         str(IrcMessage(command='PRIVMSG',
                        params=IrcMessageParams(middle='#botgotsthis',
                                                trailing='Hello World'))),
         'PRIVMSG #botgotsthis :Hello World')
コード例 #27
0
 def test_parse_command_int(self):
     self.assertEqual(IrcMessage.parse('001'),
                      ParsedMessage(None, None, 1, IrcMessageParams()))
コード例 #28
0
 def test_parse_command_params_middle(self):
     self.assertEqual(IrcMessage.parse('PART #botgotsthis'),
                      ParsedMessage(None, None, 'PART',
                                    IrcMessageParams('#botgotsthis')))
コード例 #29
0
 def test_log_channel_message(self):
     message = IrcMessage(command='PRIVMSG',
                          params=IrcMessageParams(middle='#botgotsthis',
                                                  trailing=''))
     ircmessage.log_channel_message(message, self.now)
     self.assertTrue(self.mock_log.called)
コード例 #30
0
 def test_parse_command(self):
     self.assertEqual(IrcMessage.parse('RECONNECT'),
                      ParsedMessage(None, None, 'RECONNECT',
                                    IrcMessageParams()))