allthingslinux / tux

Tux is an all in one bot for the All Things Linux discord server.
https://discord.gg/linux
GNU General Public License v3.0
85 stars 25 forks source link

this implementation is flawed, if someone bans and unbans the same user multiple times, this will not work as expected... #580

Closed github-actions[bot] closed 1 month ago

github-actions[bot] commented 1 month ago

https://github.com/allthingslinux/tux/blob/e2b4fc835d959947dee28577fd1c479c3d78dd55/tux/cogs/utility/poll.py#L45


class Poll(commands.Cog):
    def __init__(self, bot: Tux) -> None:
        self.bot = bot
        self.case_controller = CaseController()

    # TODO: for the moment this is duplicated code from ModerationCogBase in a attempt to get the code out sooner
    async def is_pollbanned(self, guild_id: int, user_id: int) -> bool:
        """
        Check if a user is poll banned.

        Parameters
        ----------
        guild_id : int
            The ID of the guild to check in.
        user_id : int
            The ID of the user to check.

        Returns
        -------
        bool
            True if the user is poll banned, False otherwise.
        """

        ban_cases = await self.case_controller.get_all_cases_by_type(guild_id, CaseType.POLLBAN)
        unban_cases = await self.case_controller.get_all_cases_by_type(guild_id, CaseType.POLLUNBAN)

        ban_count = sum(case.case_user_id == user_id for case in ban_cases)
        unban_count = sum(case.case_user_id == user_id for case in unban_cases)

        return (
            ban_count > unban_count
        )  # TODO: this implementation is flawed, if someone bans and unbans the same user multiple times, this will not work as expected

    @commands.Cog.listener()  # listen for messages
    async def on_message(self, message: discord.Message) -> None: