Esempio n. 1
0
    def test_no_moves(self):
        bot = MockBot()
        battle_bot = BattleBot(POKEDEX, bot)

        self.assertEqual(BattleState.idle, battle_bot.state)

        battle_bot._parse_text(
            'You have been challenged to a Pokemon Battle by TestUser! '
            'To accept, go to the Battle Dungeon and type !accept. '
            'You have one minute.')
        battle_bot._parse_text(
            'BotUsername sends out Farfetch\'d (Level 97)! TestUser sends '
            'out Gastly (Level 97)!')
        self.assertEqual(
            92, battle_bot.session.opponent_pokemon.dex_info.species_id)

        move_counter = collections.Counter()

        for dummy in range(100):
            battle_bot._parse_text(
                'What will Farfetch\'d do? '
                '(!move1)Slash, (!move2)Feint, (!move3)Fury Attack, '
                '(!move4)Leer (!help)Additional Commands '
                '(reply in Battle Dungeon)')
            self.assertIn(bot.last_whisper[1],
                          ('!move1', '!move2', '!move3', '!move4'))
            move_counter[bot.last_whisper[1]] += 1

        self.assertTrue(move_counter['!move1'])
        self.assertTrue(move_counter['!move2'])
        self.assertTrue(move_counter['!move3'])
        self.assertTrue(move_counter['!move4'])
Esempio n. 2
0
    def test_no_moves(self):
        bot = MockBot()
        battle_bot = BattleBot(POKEDEX, bot)

        self.assertEqual(BattleState.idle, battle_bot.state)

        battle_bot._parse_text(
            'You have been challenged to a Pokemon Battle by TestUser! '
            'To accept, go to the Battle Dungeon and type !accept. '
            'You have one minute.'
        )
        battle_bot._parse_text(
            'BotUsername sends out Farfetch\'d (Level 97)! TestUser sends '
            'out Gastly (Level 97)!'
        )
        self.assertEqual(
            92,
            battle_bot.session.opponent_pokemon.dex_info.species_id
        )

        move_counter = collections.Counter()

        for dummy in range(100):
            battle_bot._parse_text(
                'What will Farfetch\'d do? '
                '(!move1)Slash, (!move2)Feint, (!move3)Fury Attack, '
                '(!move4)Leer (!help)Additional Commands '
                '(reply in Battle Dungeon)'
            )
            self.assertIn(
                bot.last_whisper[1],
                ('!move1', '!move2', '!move3', '!move4')
            )
            move_counter[bot.last_whisper[1]] += 1

        self.assertTrue(move_counter['!move1'])
        self.assertTrue(move_counter['!move2'])
        self.assertTrue(move_counter['!move3'])
        self.assertTrue(move_counter['!move4'])
Esempio n. 3
0
    def __init__(self, bot: Bot, help_text: str, database: Database,
                 config: dict):
        self._bot = bot
        self._help_text = help_text
        self._database = database
        self._config = config
        self._recent_messages_for_regex = collections.defaultdict(
            lambda: collections.deque(maxlen=100))
        self._last_message = {}
        self._spam_limiter = Limiter(min_interval=10)
        self._password_api_limiter = Limiter(min_interval=2)
        self._user_list = collections.defaultdict(set)
        self._regex_server = RegexServer()
        self._token_notifier = TokenNotifier(
            config.get('token_notify_filename'),
            config.get('token_notify_channels'),
            config.get('token_notify_interval', 60))
        self._tellnext_generator = None

        if os.path.isfile(config.get('tellnext_database', '')):
            self._tellnext_generator = TellnextGenerator(
                config['tellnext_database'])

        self._match_generator = None

        if os.path.isfile(config.get('veekun_pokedex_database', '')):
            self._match_generator = MatchGenerator(
                config['veekun_pokedex_database'])
            self._battlebot = BattleBot(config['veekun_pokedex_database'],
                                        self._bot)

            bot.register_message_handler('pubmsg',
                                         self._battlebot.message_callback)
            bot.register_message_handler('whisper',
                                         self._battlebot.message_callback)

        self._mail_disabled_channels = config.get('mail_disabled_channels')
        self._avoid_pikalaxbot = config.get('avoid_pikalaxbot')

        bot.register_message_handler('pubmsg', self._collect_recent_message)
        bot.register_message_handler('action', self._collect_recent_message)
        bot.register_command(r'!?s/(.+/.*)', self._regex_command)
        bot.register_command(r'(?i)!caw($|\s.*)', self._caw_command)
        bot.register_command(r'(?i)!countdown($|\s.*)',
                             self._countdown_command)
        bot.register_command(r'(?i)!debugecho\s+(.*)',
                             self._debug_echo_command)
        bot.register_command(r'(?i)!double(team)?($|\s.*)',
                             self._double_command)
        bot.register_command(r'(?i)!(set)?greet(ing)?($|\s.*)$',
                             self._greeting_command)
        bot.register_command(r'(?i)!(groudonger)?(help|commands)($|\s.*)',
                             self._help_command)
        bot.register_command(r'(?i)!groudon(ger)?($|\s.*)', self._roar_command)
        bot.register_command(r'(?i)!huffle($|\s.*)', self._huffle_command)
        bot.register_command(r'(?i)!hypestats($|\s.*)',
                             self._hype_stats_command)
        bot.register_command(r'(?i)!klappa($|\s.*)', self._klappa_command)
        bot.register_command(r'(?i)!(mail|post)($|\s.*)$', self._mail_command)
        bot.register_command(r'(?i)!(mail|post)status($|\s.*)',
                             self._mail_status_command)
        bot.register_command(r'(?i)!mute($|\s.*)',
                             self._mute_command,
                             ignore_rate_limit=True)
        bot.register_command(r'(?i)!normalize($|\s.*)',
                             self._normalize_command)
        bot.register_command(r'(?i)!password\s+(.*)', self._password_command)
        bot.register_command(r'(?i)!pick\s+(.*)', self._pick_command)
        bot.register_command(r'(?i)!praise($|\s.{,100})$',
                             self._praise_command)
        bot.register_command(r'(?i)!schedule($|\s.*)', self._schedule_command)
        bot.register_command(r'(?i)!(word)?(?:shuffle|scramble)($|\s.*)',
                             self._shuffle_command)
        bot.register_command(r'(?i)!song($|\s.{,50})$', self._song_command)
        bot.register_command(r'(?i)!sort($|\s.*)', self._sort_command)
        bot.register_command(r'(?i)!spellchat(?:ot)?($|\s.*)',
                             self._spell_chatot_command)
        bot.register_command(r'(?i)!racc(?:attack)?($|\s\S*)',
                             self._raccattack_command)
        bot.register_command(r'(?i)!rand(?:om)?case($|\s.*)',
                             self._rand_case_command)
        bot.register_command(r'(?i)!release($|\s.{,100})$',
                             self._release_command)
        bot.register_command(r'(?i)!reverse($|\s.*)', self._reverse_command)
        bot.register_command(r'(?i)!riot($|\s.{,100})$', self._riot_command)
        bot.register_command(r'(?i)!rip($|\s.{,100})$', self._rip_command)
        bot.register_command(r'(?i)!roomsize?($|\s.*)',
                             self._room_size_command)
        bot.register_command(r'(?i)!gen(?:erate)?match($|\s.*)$',
                             self._generate_match_command)
        bot.register_command(r'(?i)!(xd|minglee)($|\s.*)', self._xd_command)
        # bot.register_command(r'(?i)!(set)?{}($|\s.*)'.format(username), self._username_command)
        # Temporary disabled. interferes with rate limit
        # bot.register_command(r'.*\b[xX][dD] +MingLee\b.*', self._xd_rand_command)
        bot.register_command(r'(?i)!(wow)($|\s.*)', self._wow_command)
        bot.register_command(
            r'(?i)(?:has )?(?:just )?donate(?:d|s)? [^0-9]{0,5}([0-9][0-9,.]*)',
            self._donation_trigger)

        bot.register_message_handler('join', self._join_callback)
        bot.register_message_handler('part', self._part_callback)

        self._reseed_rng_sched()
        self._token_notify_sched()
        self._discord_presence_sched()
Esempio n. 4
0
    def test_battle(self):
        bot = MockBot()
        battle_bot = BattleBot(POKEDEX, bot, 'BotUsername')

        self.assertEqual(BattleState.idle, battle_bot.state)

        battle_bot._parse_text(
            'You have been challenged to a Pokemon Battle by TestUser! '
            'To accept, go to the Battle Dungeon and type !accept. '
            'You have one minute.'
        )
        self.assertTrue(bot.last_text[1].startswith('G'))
        self.assertEqual('!accept', bot.last_whisper[1])
        self.assertEqual(BattleState.in_battle, battle_bot.state)

        bot.last_text = None

        battle_bot._parse_text(
            'BotUsername sends out Tentacool (Level 97)! TestUser sends '
            'out Nidorina (Level 97)!'
        )
        self.assertEqual(
            30,
            battle_bot.session.opponent_pokemon.dex_info.species_id
        )

        move_counter = collections.Counter()

        for dummy in range(100):
            battle_bot._parse_text(
                'What will Tentacool do? '
                '(!move1)Icy-wind, (!move2)Water-gun, (!move3)Acid, '
                '(!move4)Knock-off (!help)Additional Commands '
                '(reply in Battle Dungeon)'
            )
            self.assertIn(
                bot.last_whisper[1],
                ('!move1', '!move2', '!move3', '!move4')
            )
            move_counter[bot.last_whisper[1]] += 1

        self.assertTrue('!move2', move_counter.most_common()[0][0])

        battle_bot._parse_text(
            'Type !list to get a list of your Pokemon. Type !switch<number> '
            'to switch to that Pokemon (for example, the if you want to '
            'switch to the first Pokemon, type !switch0'
        )
        self.assertEqual('!switch0', bot.last_whisper[1])

        battle_bot._parse_text(
            'TestUser calls back Nidorina and sent out Basculin!'
        )
        self.assertEqual(
            550,
            battle_bot.session.opponent_pokemon.dex_info.species_id
        )

        battle_bot._parse_text(
            'TestUser is out of usable Pokemon! Trainer Class '
            'BotUsername wins! PogChamp'
        )

        self.assertTrue(bot.last_text[1].startswith('G'))
        self.assertEqual(BattleState.idle, battle_bot.state)
Esempio n. 5
0
    def _pwt_iteration(self, iteration: str):
        bot = MockBot()
        battle_bot = BattleBot(POKEDEX, bot)

        self.assertEqual(BattleState.idle, battle_bot.state)

        battle_bot._parse_text(
            'BlahUserName has started a new Random Pokemon World Tournament!'
            ' Type !join to join. The PWT will start in 60 seconds.'
        )

        self.assertIsNone(bot.last_text)
        self.assertIsNone(bot.last_whisper)

        battle_bot._parse_text(
            'TestUser has been added to the PWT! Type !join to join.'
        )

        self.assertIsNone(bot.last_text)
        self.assertIsNone(bot.last_whisper)

        def not_us():
            battle_bot._parse_text(
                'This is a First Round match of the Random tournament! '
                'This match is between Pro Memer TestUser and Gambler Spencer!'
            )

            self.assertIsNone(bot.last_text)
            self.assertIsNone(bot.last_whisper)

            battle_bot._parse_text('Blah blah copypasta')

            self.assertIsNone(bot.last_text)
            self.assertIsNone(bot.last_whisper)

            battle_bot._parse_text('TestUser forfeits! Gambler Spencer wins!')

            self.assertIsNone(bot.last_text)
            self.assertIsNone(bot.last_whisper)

        not_us()

        if iteration == 'loser':
            battle_bot._parse_text(
                'This is a First Round match of the Random tournament! '
                'This match is between TestUser and Groudonger!'
            )
        else:
            battle_bot._parse_text(
                'This is a First Round match of the Random tournament! '
                'This match is between Pro Memer TestUser and Gym Leader Groudonger!'
            )

        self.assertEqual(BattleState.in_pwt_battle, battle_bot.state)
        self.assertTrue(bot.last_text[1].startswith('G'))

        bot.last_text = None

        battle_bot._parse_text(
            'Gym Leader Groudonger sends out Tentacool (Level 97)! '
            'TestUser sends out Nidorina (Level 97)!'
        )
        self.assertEqual(
            30,
            battle_bot.session.opponent_pokemon.dex_info.species_id
        )

        battle_bot._parse_text(
            'What will Tentacool do? '
            '(!move1)Icy-wind, (!move2)Water-gun, (!move3)Acid, '
            '(!move4)Knock-off (!help)Additional Commands '
            '(reply in Battle Dungeon)'
        )
        self.assertIn(
            bot.last_whisper[1],
            ('!move1', '!move2', '!move3', '!move4')
        )

        battle_bot._parse_text(
            'Type !list to get a list of your Pokemon. Type !switch<number> '
            'to switch to that Pokemon (for example, the if you want to '
            'switch to the first Pokemon, type !switch0'
        )
        self.assertEqual('!switch0', bot.last_whisper[1])

        battle_bot._parse_text(
            'TestUser calls back Nidorina and sent out Basculin!'
        )
        self.assertEqual(
            550,
            battle_bot.session.opponent_pokemon.dex_info.species_id
        )

        if iteration == 'loser':
            battle_bot._parse_text(
                'Gym Leader Groudonger is out of usable Pokemon! '
                'TestUser wins! PogChamp'
            )
        else:
            battle_bot._parse_text(
                'TestUser is out of usable Pokemon! '
                'Gym Leader Groudonger wins! PogChamp'
            )

        self.assertEqual(BattleState.in_pwt_standby, battle_bot.state)
        self.assertTrue(bot.last_text[1].startswith('G'))

        bot.last_text = None
        bot.last_whisper = None

        not_us()

        if iteration == 'loser':
            battle_bot._parse_text(
                'Scientist Tim has won the Random Pokemon World Tournament! PagChomp'
            )

            self.assertIsNone(bot.last_text)
        else:
            battle_bot._parse_text(
                'Gym Leader Groudonger has won the Random Pokemon World Tournament! PagChomp'
            )
            self.assertTrue(bot.last_text[1].startswith('G'))

            bot.last_text = None

        self.assertEqual(BattleState.idle, battle_bot.state)
Esempio n. 6
0
    def test_battle(self):
        bot = MockBot()
        battle_bot = BattleBot(POKEDEX, bot, 'BotUsername')

        self.assertEqual(BattleState.idle, battle_bot.state)

        battle_bot._parse_text(
            'You have been challenged to a Pokemon Battle by TestUser! '
            'To accept, go to the Battle Dungeon and type !accept. '
            'You have one minute.')
        self.assertTrue(bot.last_text[1].startswith('G'))
        self.assertEqual('!accept', bot.last_whisper[1])
        self.assertEqual(BattleState.in_battle, battle_bot.state)

        bot.last_text = None

        battle_bot._parse_text(
            'BotUsername sends out Tentacool (Level 97)! TestUser sends '
            'out Nidorina (Level 97)!')
        self.assertEqual(
            30, battle_bot.session.opponent_pokemon.dex_info.species_id)

        move_counter = collections.Counter()

        for dummy in range(100):
            battle_bot._parse_text(
                'What will Tentacool do? '
                '(!move1)Icy-wind, (!move2)Water-gun, (!move3)Acid, '
                '(!move4)Knock-off (!help)Additional Commands '
                '(reply in Battle Dungeon)')
            self.assertIn(bot.last_whisper[1],
                          ('!move1', '!move2', '!move3', '!move4'))
            move_counter[bot.last_whisper[1]] += 1

        self.assertTrue('!move2', move_counter.most_common()[0][0])

        battle_bot._parse_text(
            'Type !list to get a list of your Pokemon. Type !switch<number> '
            'to switch to that Pokemon (for example, the if you want to '
            'switch to the first Pokemon, type !switch0')
        self.assertEqual('!switch0', bot.last_whisper[1])

        battle_bot._parse_text(
            'TestUser calls back Nidorina and sent out Basculin!')
        self.assertEqual(
            550, battle_bot.session.opponent_pokemon.dex_info.species_id)

        battle_bot._parse_text(
            'TestUser is out of usable Pokemon! Trainer Class '
            'BotUsername wins! PogChamp')

        self.assertTrue(bot.last_text[1].startswith('G'))
        self.assertEqual(BattleState.idle, battle_bot.state)
Esempio n. 7
0
 def test_slugify_accents(self):
     self.assertEqual('flabebe', BattleBot.slugify('Flabébé'))
Esempio n. 8
0
    def _pwt_iteration(self, iteration: str):
        bot = MockBot()
        battle_bot = BattleBot(POKEDEX, bot)

        self.assertEqual(BattleState.idle, battle_bot.state)

        battle_bot._parse_text(
            'BlahUserName has started a new Random Pokemon World Tournament!'
            ' Type !join to join. The PWT will start in 60 seconds.')

        self.assertIsNone(bot.last_text)
        self.assertIsNone(bot.last_whisper)

        battle_bot._parse_text(
            'TestUser has been added to the PWT! Type !join to join.')

        self.assertIsNone(bot.last_text)
        self.assertIsNone(bot.last_whisper)

        def not_us():
            battle_bot._parse_text(
                'This is a First Round match of the Random tournament! '
                'This match is between Pro Memer TestUser and Gambler Spencer!'
            )

            self.assertIsNone(bot.last_text)
            self.assertIsNone(bot.last_whisper)

            battle_bot._parse_text('Blah blah copypasta')

            self.assertIsNone(bot.last_text)
            self.assertIsNone(bot.last_whisper)

            battle_bot._parse_text('TestUser forfeits! Gambler Spencer wins!')

            self.assertIsNone(bot.last_text)
            self.assertIsNone(bot.last_whisper)

        not_us()

        if iteration == 'loser':
            battle_bot._parse_text(
                'This is a First Round match of the Random tournament! '
                'This match is between TestUser and Groudonger!')
        else:
            battle_bot._parse_text(
                'This is a First Round match of the Random tournament! '
                'This match is between Pro Memer TestUser and Gym Leader Groudonger!'
            )

        self.assertEqual(BattleState.in_pwt_battle, battle_bot.state)
        self.assertTrue(bot.last_text[1].startswith('G'))

        bot.last_text = None

        battle_bot._parse_text(
            'Gym Leader Groudonger sends out Tentacool (Level 97)! '
            'TestUser sends out Nidorina (Level 97)!')
        self.assertEqual(
            30, battle_bot.session.opponent_pokemon.dex_info.species_id)

        battle_bot._parse_text(
            'What will Tentacool do? '
            '(!move1)Icy-wind, (!move2)Water-gun, (!move3)Acid, '
            '(!move4)Knock-off (!help)Additional Commands '
            '(reply in Battle Dungeon)')
        self.assertIn(bot.last_whisper[1],
                      ('!move1', '!move2', '!move3', '!move4'))

        battle_bot._parse_text(
            'Type !list to get a list of your Pokemon. Type !switch<number> '
            'to switch to that Pokemon (for example, the if you want to '
            'switch to the first Pokemon, type !switch0')
        self.assertEqual('!switch0', bot.last_whisper[1])

        battle_bot._parse_text(
            'TestUser calls back Nidorina and sent out Basculin!')
        self.assertEqual(
            550, battle_bot.session.opponent_pokemon.dex_info.species_id)

        if iteration == 'loser':
            battle_bot._parse_text(
                'Gym Leader Groudonger is out of usable Pokemon! '
                'TestUser wins! PogChamp')
        else:
            battle_bot._parse_text('TestUser is out of usable Pokemon! '
                                   'Gym Leader Groudonger wins! PogChamp')

        self.assertEqual(BattleState.in_pwt_standby, battle_bot.state)
        self.assertTrue(bot.last_text[1].startswith('G'))

        bot.last_text = None
        bot.last_whisper = None

        not_us()

        if iteration == 'loser':
            battle_bot._parse_text(
                'Scientist Tim has won the Random Pokemon World Tournament! PagChomp'
            )

            self.assertIsNone(bot.last_text)
        else:
            battle_bot._parse_text(
                'Gym Leader Groudonger has won the Random Pokemon World Tournament! PagChomp'
            )
            self.assertTrue(bot.last_text[1].startswith('G'))

            bot.last_text = None

        self.assertEqual(BattleState.idle, battle_bot.state)