mirror of
https://github.com/allthingslinux/tux.git
synced 2024-10-02 16:43:12 +00:00
integrate poll banning into poll code, gonna see if this code is working
This commit is contained in:
parent
65466b5b25
commit
7fe7b85f18
1 changed files with 25 additions and 2 deletions
|
@ -3,7 +3,9 @@ from discord import app_commands
|
|||
from discord.ext import commands
|
||||
from loguru import logger
|
||||
|
||||
from prisma.enums import CaseType
|
||||
from tux.bot import Tux
|
||||
from tux.database.controllers import CaseController
|
||||
from tux.ui.embeds import EmbedCreator
|
||||
|
||||
# TODO: Create option inputs for the poll command instead of using a comma separated string
|
||||
|
@ -12,6 +14,16 @@ from tux.ui.embeds import EmbedCreator
|
|||
class Poll(commands.Cog):
|
||||
def __init__(self, bot: Tux) -> None:
|
||||
self.bot = bot
|
||||
self.case_controller = CaseController()
|
||||
|
||||
async def is_pollbanned(self, guild_id: int, user_id: int) -> bool:
|
||||
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
|
||||
|
||||
@commands.Cog.listener() # listen for messages
|
||||
async def on_message(self, message: discord.Message) -> None:
|
||||
|
@ -40,7 +52,8 @@ class Poll(commands.Cog):
|
|||
@commands.Cog.listener()
|
||||
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User) -> None:
|
||||
# Block any reactions that are not numbers for the poll
|
||||
|
||||
# NOTE: Today we observed in amazing detail that the pure will of 1 too many dedicated discord members can make
|
||||
# the bot freak out whenever trying to remove reactions. Is there a better solution for this?
|
||||
if reaction.message.embeds:
|
||||
embed = reaction.message.embeds[0]
|
||||
if (
|
||||
|
@ -52,7 +65,13 @@ class Poll(commands.Cog):
|
|||
|
||||
@app_commands.command(name="poll", description="Creates a poll.")
|
||||
@app_commands.describe(title="Title of the poll", options="Poll options, comma separated")
|
||||
async def poll(self, interaction: discord.Interaction, title: str, options: str) -> None:
|
||||
async def poll(
|
||||
self,
|
||||
interaction: discord.Interaction,
|
||||
title: str,
|
||||
options: str,
|
||||
ctx: commands.Context[Tux],
|
||||
) -> None:
|
||||
"""
|
||||
Create a poll with a title and options.
|
||||
|
||||
|
@ -65,6 +84,7 @@ class Poll(commands.Cog):
|
|||
options : str
|
||||
The options for the poll, separated by commas.
|
||||
"""
|
||||
assert ctx.guild
|
||||
|
||||
# Split the options by comma
|
||||
options_list = options.split(",")
|
||||
|
@ -72,6 +92,9 @@ class Poll(commands.Cog):
|
|||
# Remove any leading or trailing whitespaces from the options
|
||||
options_list = [option.strip() for option in options_list]
|
||||
|
||||
if await self.is_pollbanned(ctx.guild.id, ctx.author.id):
|
||||
await ctx.send("You are banned from making polls.")
|
||||
return
|
||||
# Check if the options count is between 2-9
|
||||
if len(options_list) < 2 or len(options_list) > 9:
|
||||
embed = EmbedCreator.create_embed(
|
||||
|
|
Loading…
Reference in a new issue