def test_player_data_with_just_red_players():
        connected_players(fake_player(1, "Player1", "red"),
                          fake_player(4, "Player4", "red"))

        player_data = mydiscordbot.player_data()

        assert_that(player_data, is_("\n**R:** **Player1**(0) **Player4**(0) "))
Пример #2
0
    def test_cmd_mapsoulz_for_another_nonexisting_disconnected_player(self):
        player = fake_player(123, "Issuing Player", team="red")
        fragging_player = fake_player(456, "Fragging Player", team="red")

        killed1 = fake_player(4, "Killed1", team="blue")
        killed2 = fake_player(5, "Killed2", team="blue")
        killed3 = fake_player(6, "Killed3", team="blue")
        killed4 = fake_player(7, "Killed4", team="blue")
        connected_players(player, killed1, killed2, killed3, killed4)

        self.plugin.frag_log = [(player.steam_id, killed1.steam_id),
                                (fragging_player.steam_id, killed2.steam_id),
                                (fragging_player.steam_id, killed2.steam_id),
                                (fragging_player.steam_id, killed3.steam_id)]

        when(self.db).exists(
            f"minqlx:players:{fragging_player.steam_id}:last_used_name"
        ).thenReturn(False)

        self.plugin.cmd_mapsoulz(player,
                                 ["!mapsoulz", f"{fragging_player.steam_id}"],
                                 self.reply_channel)

        assert_channel_was_replied(self.reply_channel, any_,
                                   times=0)  # type: ignore
Пример #3
0
    def test_cmd_reaperz_returns_top10(self):
        player = fake_player(123, "Issuing Player", team="red")

        killer1 = fake_player(4, "Killer1", team="blue")
        killer2 = fake_player(5, "Killer2", team="blue")
        killer3 = fake_player(6, "Killer3", team="blue")
        killer4 = fake_player(7, "Killer4", team="blue")
        connected_players(player, killer1, killer2, killer3, killer4)

        when(self.db).zrevrangebyscore(f"minqlx:players:{player.steam_id}:reaperz",
                                       "+INF", "-INF", start=0, num=10, withscores=True)\
            .thenReturn([
                (killer1.steam_id, 2),
                (killer2.steam_id, 3),
                (killer3.steam_id, 5),
                (killer4.steam_id, 7),
            ])

        self.plugin.cmd_reaperz(player, ["!reaperz"], self.reply_channel)

        assert_channel_was_replied(
            self.reply_channel,
            matches(
                r"Top 10 reaperz of Issuing Player.*'s soul: "
                r"Killer4.* \(7\), Killer3.* \(5\), Killer2.* \(3\), Killer1.* \(2\)"
            ))
    def test_shuffle_double_blink_when_diff_one_player(self):
        spy2(time.sleep)
        when2(time.sleep, any_(float)).thenReturn(None)
        spy2(Plugin.shuffle)
        when2(Plugin.shuffle).thenReturn(None)

        connected_players(fake_player(1, "Red Player1", team="red"),
                          fake_player(2, "Red Player2", team="red"),
                          fake_player(3, "Red Player3", team="red"),
                          fake_player(4, "Red Player4", team="red"),
                          fake_player(5, "Blue Player1", team="blue"),
                          fake_player(6, "Blue Player2", team="blue"),
                          fake_player(7, "Blue Player3", team="blue"),
                          fake_player(8, "Blue Player4", team="blue"),
                          fake_player(9, "Blue Player5", team="blue"))

        autoready.shuffle_double_blink(10)

        verify(time, times=2).sleep(0.2)
        verify(time).sleep(0.3)
        verify(Plugin, times=0).shuffle()
        assert_plugin_center_printed(
            "Match will ^2auto-start^7 in\n^1 ^7:^1  ", times=2)
        assert_plugin_center_printed(
            "Match will ^2auto-start^7 in\n^10^7:^110", times=2)
Пример #5
0
    def test_handle_round_end_winning_streak_triggers_teams_callback_already_called_multiple_times(
            self):
        mocked_balance_plugin = mock()
        mocked_balance_plugin.callback_teams = lambda: None
        Plugin._loaded_plugins["balance"] = mocked_balance_plugin  # pylint: disable=protected-access
        setup_game_in_progress(game_type="ca",
                               roundlimit=8,
                               red_score=4,
                               blue_score=3)

        red_player1 = fake_player(123, "Red Player1", "red")
        red_player2 = fake_player(456, "Red Player2", "red")
        blue_player1 = fake_player(246, "Blue Player1", "blue")
        blue_player2 = fake_player(975, "Blue Player2", "blue")
        connected_players(red_player1, red_player2,
                          fake_player(42, "Spec Player", "spectator"),
                          blue_player1, blue_player2)
        self.plugin.winning_teams = [
            "blue", "blue", "blue", "red", "red", "red", "red"
        ]

        undecorated(self.plugin.handle_round_end)(self.plugin, {
            "TEAM_WON": "RED"
        })

        players = {
            p.steam_id: "ca"
            for p in [red_player1, red_player2, blue_player1, blue_player2]
        }
        verify(mocked_balance_plugin,
               times=0).add_request(players,
                                    mocked_balance_plugin.callback_teams,
                                    minqlx.CHAT_CHANNEL)
    def test_handle_client_command_allows_readyup_when_configured_with_too_few_players(
            self):
        setup_cvars({
            "zmq_stats_enable": "1",
            "qlx_autoready_min_players": "10",
            "qlx_autoready_autostart_delay": "180",
            "qlx_autoready_min_seconds": "30",
            "qlx_autoready_timer_visible": "60",
            "qlx_autoready_disable_manual_readyup": "1"
        })

        self.plugin = autoready.autoready()

        player = fake_player(1, "Readying Player", team="red")
        connected_players(player, fake_player(2, "Other Player", team="blue"),
                          fake_player(3, "Other Player", team="red"),
                          fake_player(4, "Other Player", team="blue"),
                          fake_player(5, "Other Player", team="red"),
                          fake_player(6, "Other Player", team="blue"),
                          fake_player(7, "Other Player", team="red"),
                          fake_player(8, "Other Player", team="blue"))

        return_val = self.plugin.handle_client_command(player, "readyup")

        assert_that(return_val, is_(True))
Пример #7
0
    def test_cmd_soulz_returns_top10(self):
        player = fake_player(123, "Issuing Player", team="red")

        killed1 = fake_player(4, "Killed1", team="blue")
        killed2 = fake_player(5, "Killed2", team="blue")
        killed3 = fake_player(6, "Killed3", team="blue")
        killed4 = fake_player(7, "Killed4", team="blue")
        connected_players(player, killed1, killed2, killed3, killed4)

        when(self.db).zrevrangebyscore(f"minqlx:players:{player.steam_id}:soulz",
                                       "+INF", "-INF", start=0, num=10, withscores=True)\
            .thenReturn([
                (killed1.steam_id, 2),
                (killed2.steam_id, 3),
                (killed3.steam_id, 5),
                (killed4.steam_id, 8)
            ])

        self.plugin.cmd_soulz(player, ["!soulz"], self.reply_channel)

        assert_channel_was_replied(
            self.reply_channel,
            matches(
                r"Top 10 reaped soulz for Issuing Player.*: "
                r"Killed4.* \(8\), Killed3.* \(5\), Killed2.* \(3\), Killed1.* \(2\)"
            ))
Пример #8
0
    def test_cmd_soulz_for_another_disconnected_player(self):
        player = fake_player(123, "Issuing Player", team="red")
        fragging_player = fake_player(456, "Fragging Player", team="red")

        killed1 = fake_player(4, "Killed1", team="blue")
        killed2 = fake_player(5, "Killed2", team="blue")
        killed3 = fake_player(6, "Killed3", team="blue")
        killed4 = fake_player(7, "Killed4", team="blue")
        connected_players(player, killed1, killed2, killed3, killed4)

        when(self.db).zrevrangebyscore(f"minqlx:players:{fragging_player.steam_id}:soulz",
                                       "+INF", "-INF", start=0, num=10, withscores=True)\
            .thenReturn([
                (killed2.steam_id, 2),
                (killed3.steam_id, 1)
            ])
        when(self.db).exists(
            f"minqlx:players:{fragging_player.steam_id}:last_used_name"
        ).thenReturn(True)
        when(self.db).get(f"minqlx:players:{fragging_player.steam_id}:last_used_name") \
            .thenReturn(fragging_player.name)

        self.plugin.cmd_soulz(player,
                              ["!soulz", f"{fragging_player.steam_id}"],
                              self.reply_channel)

        assert_channel_was_replied(
            self.reply_channel,
            matches(r"Top 10 reaped soulz for Fragging Player.*: "
                    r"Killed2.* \(2\), Killed3.* \(1\)"))
Пример #9
0
    def test_cmd_soulz_with_a_disconnected_player(self):
        player = fake_player(123, "Issuing Player", team="red")

        killed1 = fake_player(4, "Killed1", team="blue")
        disconnected_killed2 = fake_player(5,
                                           "Disconnected Killed2",
                                           team="blue")
        connected_players(player, killed1)

        when(self.db).zrevrangebyscore(f"minqlx:players:{player.steam_id}:soulz",
                                       "+INF", "-INF", start=0, num=10, withscores=True)\
            .thenReturn([
                (killed1.steam_id, 1),
                (disconnected_killed2.steam_id, 2)
            ])
        when(self.db).exists(
            f"minqlx:players:{disconnected_killed2.steam_id}:last_used_name"
        ).thenReturn(True)
        when(self.db).get(f"minqlx:players:{disconnected_killed2.steam_id}:last_used_name") \
            .thenReturn(disconnected_killed2.name)

        self.plugin.cmd_soulz(player, ["!soulz"], self.reply_channel)

        assert_channel_was_replied(
            self.reply_channel,
            matches(r"Top 10 reaped soulz for Issuing Player.*: "
                    r"Disconnected Killed2.* \(2\), Killed1.* \(1\)"))
Пример #10
0
    def test_cmd_mapreaperz_with_a_disconnected_player(self):
        player = fake_player(123, "Issuing Player", team="red")

        killed1 = fake_player(4, "Killed1", team="blue")
        disconnected_killed2 = fake_player(5,
                                           "Disconnected Killed2",
                                           team="blue")
        connected_players(player, killed1)

        self.plugin.frag_log = [
            (killed1.steam_id, player.steam_id),
            (disconnected_killed2.steam_id, player.steam_id),
            (disconnected_killed2.steam_id, player.steam_id)
        ]
        when(self.db).exists(
            f"minqlx:players:{disconnected_killed2.steam_id}:last_used_name"
        ).thenReturn(True)
        when(self.db).get(f"minqlx:players:{disconnected_killed2.steam_id}:last_used_name") \
            .thenReturn(disconnected_killed2.name)

        self.plugin.cmd_mapreaperz(player, ["!mapreaperz"], self.reply_channel)

        assert_channel_was_replied(
            self.reply_channel,
            matches(r"Top 10 reaperz of Issuing Player.*'s soul: "
                    r"Disconnected Killed2.* \(2\), Killed1.* \(1\)"))
Пример #11
0
    def test_cmd_mapreaperz_returns_top10(self):
        player = fake_player(123, "Issuing Player", team="red")

        killer1 = fake_player(4, "Killer1", team="blue")
        killer2 = fake_player(5, "Killer2", team="blue")
        killer3 = fake_player(6, "Killer3", team="blue")
        killer4 = fake_player(7, "Killer4", team="blue")
        connected_players(player, killer1, killer2, killer3, killer4)

        self.plugin.frag_log = [(killer1.steam_id, player.steam_id),
                                (killer2.steam_id, player.steam_id),
                                (killer3.steam_id, player.steam_id),
                                (killer4.steam_id, player.steam_id),
                                (killer4.steam_id, player.steam_id),
                                (killer3.steam_id, player.steam_id),
                                (killer4.steam_id, player.steam_id),
                                (killer2.steam_id, player.steam_id),
                                (killer4.steam_id, player.steam_id),
                                (killer3.steam_id, player.steam_id),
                                (killer4.steam_id, player.steam_id),
                                (killer4.steam_id, player.steam_id),
                                (killer2.steam_id, player.steam_id),
                                (killer1.steam_id, player.steam_id),
                                (killer3.steam_id, player.steam_id),
                                (killer4.steam_id, player.steam_id),
                                (killer3.steam_id, player.steam_id)]

        self.plugin.cmd_mapreaperz(player, ["!mapreaperz"], self.reply_channel)

        assert_channel_was_replied(
            self.reply_channel,
            matches(
                r"Top 10 reaperz of Issuing Player.*'s soul: "
                r"Killer4.* \(7\), Killer3.* \(5\), Killer2.* \(3\), Killer1.* \(2\)"
            ))
    def test_player_data_with_just_blue_players():
        connected_players(fake_player(2, "Player2", "blue"),
                          fake_player(3, "Player3", "blue"))

        player_data = mydiscordbot.player_data()

        assert_that(player_data, is_("\n**B:** **Player2**(0) **Player3**(0) "))
Пример #13
0
    def test_cmd_mapsoulz_for_another_disconnected_player(self):
        player = fake_player(123, "Issuing Player", team="red")
        fragging_player = fake_player(456, "Fragging Player", team="red")

        killed1 = fake_player(4, "Killed1", team="blue")
        killed2 = fake_player(5, "Killed2", team="blue")
        killed3 = fake_player(6, "Killed3", team="blue")
        killed4 = fake_player(7, "Killed4", team="blue")
        connected_players(player, killed1, killed2, killed3, killed4)

        self.plugin.frag_log = [(player.steam_id, killed1.steam_id),
                                (fragging_player.steam_id, killed2.steam_id),
                                (fragging_player.steam_id, killed2.steam_id),
                                (fragging_player.steam_id, killed3.steam_id)]

        when(self.db).exists(
            f"minqlx:players:{fragging_player.steam_id}:last_used_name"
        ).thenReturn(True)
        when(self.db).get(f"minqlx:players:{fragging_player.steam_id}:last_used_name") \
            .thenReturn(fragging_player.name)

        self.plugin.cmd_mapsoulz(player,
                                 ["!mapsoulz", f"{fragging_player.steam_id}"],
                                 self.reply_channel)

        assert_channel_was_replied(
            self.reply_channel,
            matches(r"Top 10 reaped soulz for Fragging Player.*: "
                    r"Killed2.* \(2\), Killed3.* \(1\)"))
Пример #14
0
 def setUp(self):
     setup_plugin()
     setup_cvars({
         "qlx_balanceUseLocal": "0",
     })
     setup_game_in_progress()
     connected_players()
     self.plugin = balance()
Пример #15
0
    def test_handle_team_switch_attempt_to_spectator(self):
        player = fake_player(42, "Fake Player")
        connected_players(player)

        return_code = self.plugin.handle_team_switch_attempt(
            player, "blue", "spectator")

        assert_that(return_code, is_(minqlx.RET_NONE))
Пример #16
0
    def test_handle_team_switch_attempt_plugin_disabled(self):
        self.plugin.plugin_enabled = False
        switching_player = fake_player(123, "Joining Player")
        connected_players(switching_player)

        return_code = self.plugin.handle_team_switch_attempt(
            switching_player, "spectator", "any")

        assert_that(return_code, is_(minqlx.RET_NONE))
Пример #17
0
    def test_handle_team_switch_attempt_rebalance_not_set_for_teamswitch_events(
            self):
        player = fake_player(42, "Fake Player")
        connected_players(player)

        return_code = self.plugin.handle_team_switch_attempt(
            player, "spectator", "red")

        assert_that(return_code, is_(minqlx.RET_NONE))
Пример #18
0
    def test_cmd_soulz_for_another_non_existent_player(self):
        player = fake_player(123, "Issuing Player", team="red")

        connected_players(player)

        self.plugin.cmd_soulz(player, ["!soulz", "Non-existent"],
                              self.reply_channel)

        assert_player_was_told(player, matches(".*no players matched.*"))
Пример #19
0
    def test_handle_team_switch_attempt_game_in_warmup(self):
        setup_game_in_warmup()
        player = fake_player(42, "Fake Player")
        connected_players(player)

        return_code = self.plugin.handle_team_switch_attempt(
            player, "spectator", "any")

        assert_that(return_code, is_(minqlx.RET_NONE))
    def test_player_data_with_players_on_both_teams():
        connected_players(fake_player(1, "Player1", "red", score=1),
                          fake_player(2, "Player2", "blue", score=3),
                          fake_player(3, "Player3", "blue", score=2),
                          fake_player(4, "Player4", "red", score=5))

        player_data = mydiscordbot.player_data()

        assert_that(player_data, is_("\n**R:** **Player4**(5) **Player1**(1) \n**B:** **Player2**(3) **Player3**(2) "))
Пример #21
0
    def test_handle_death_on_own_death_does_nothing(self):
        victim = fake_player(123, "Fragged Player", team="red")

        connected_players(victim)

        self.plugin.handle_death(victim, victim, {"MOD": "ROCKET"})

        assert_that(self.plugin.frag_log,
                    not_(contains_exactly(victim.steam_id)))  # type: ignore
    def test_handle_player_disconnect_with_no_game(self):
        setup_no_game()
        self.plugin.current_timer = 42
        disconnecting_player = fake_player(1, "Disconnecting Player")
        connected_players(disconnecting_player)

        self.plugin.handle_player_disconnect(disconnecting_player, "ragequit")

        assert_that(self.plugin.current_timer, is_(42))
    def test_handle_player_disconnect_while_game_not_in_warmup(self):
        setup_game_in_progress()
        self.plugin.current_timer = 42
        disconnecting_player = fake_player(1, "Disconnecting Player")
        connected_players(disconnecting_player)

        self.plugin.handle_player_disconnect(disconnecting_player, "ragequit")

        assert_that(self.plugin.current_timer, is_(42))
Пример #24
0
    def test_cmd_policy_exception_for_no_matching_player(self):
        admin_player = fake_player(123, "Admin Player")
        connected_players(admin_player)

        self.plugin.cmd_policy_exception(admin_player, ["!except", "except"],
                                         minqlx.CHAT_CHANNEL)

        assert_player_was_told(admin_player,
                               matches(".*Could not find player.*"))
Пример #25
0
    def test_cmd_switch_plugin_with_no_balance_plugin(self):
        minqlx.Plugin._loaded_plugins.pop("balance")  # pylint: disable=protected-access
        self.plugin.plugin_enabled = False
        reply_channel = mocked_channel()
        connected_players()

        self.plugin.cmd_switch_plugin(None, ["!policy"], reply_channel)

        assert_that(self.plugin.plugin_enabled, is_(False))
Пример #26
0
    def test_cmd_policy_exception_for_connected_player(self):
        admin_player = fake_player(123, "Admin Player")
        exception_player = fake_player(456, "Excepted Player")
        connected_players(admin_player, exception_player)

        self.plugin.cmd_policy_exception(admin_player, ["!except", "except"],
                                         minqlx.CHAT_CHANNEL)

        assert_that(self.plugin.exceptions, is_({exception_player.steam_id}))
Пример #27
0
    def test_cmd_policy_exception_for_player_too_short(self):
        admin_player = fake_player(123, "Admin Player")
        connected_players(admin_player)

        return_code = self.plugin.cmd_policy_exception(admin_player,
                                                       ["!except"],
                                                       minqlx.CHAT_CHANNEL)

        assert_that(return_code, is_(minqlx.RET_USAGE))
Пример #28
0
    def test_handle_team_switch_attempt_player_has_exception_to_join(self):
        switching_player = fake_player(123, "Joining Player")
        connected_players(switching_player)
        self.plugin.exceptions.add(switching_player.steam_id)

        return_code = self.plugin.handle_team_switch_attempt(
            switching_player, "spectator", "any")

        assert_that(return_code, is_(minqlx.RET_NONE))
 def setUp(self):
     setup_plugin()
     setup_game_in_warmup("ca")
     connected_players()
     self.discord = mock(spec=SimpleAsyncDiscord, strict=False)
     setup_cvars({
         "qlx_discordQuakeRelayMessageFilters": r"^\!s$, ^\!p$"
     })
     self.plugin = mydiscordbot(discord_client=self.discord)
Пример #30
0
    def test_handle_team_switch_attempt_no_balance_plugin(self):
        minqlx.Plugin._loaded_plugins.pop("balance")  # pylint: disable=protected-access
        switching_player = fake_player(123, "Joining Player")
        connected_players(switching_player)

        self.plugin.handle_team_switch_attempt(switching_player, "spectator",
                                               "any")

        assert_that(self.plugin.plugin_enabled, is_(False))