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:
https://github.com/allthingslinux/tux/blob/9fbb1c7fa64535215f01fc696c6e028866d288cf/tux/cogs/utility/poll.py#L45