From 517dd27ba2a97e6f737025b01c84e04f5e2ff95f Mon Sep 17 00:00:00 2001 From: FirePlank <44502537+FirePlank@users.noreply.github.com> Date: Thu, 30 Nov 2023 18:16:25 +0200 Subject: [PATCH] edited views to work like they are supposed to --- bot/extensions/adventofcode/commands.py | 7 +++---- bot/extensions/adventofcode/views.py | 5 ++++- bot/extensions/polls/commands.py | 8 +++----- bot/extensions/polls/views.py | 17 ++++++++++------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/bot/extensions/adventofcode/commands.py b/bot/extensions/adventofcode/commands.py index 927becc6..9e11fd61 100644 --- a/bot/extensions/adventofcode/commands.py +++ b/bot/extensions/adventofcode/commands.py @@ -3,16 +3,15 @@ from bot import core from bot.extensions.adventofcode.utils import home_embed -from bot.extensions.adventofcode.views import CreateAdventOfCodeView +from bot.extensions.adventofcode.views import AdventOfCodeView class AdventOfCode(commands.Cog): def __init__(self, bot): self.bot = bot - self._create_aoc_view = CreateAdventOfCodeView(timeout=None) - self.bot.add_view(self._create_aoc_view) + self.bot.add_view(AdventOfCodeView()) @app_commands.command(name="advent-of-code") async def advent_of_code(self, interaction: core.InteractionType): """Returns information about the Advent of Code""" - await interaction.response.send_message(embed=home_embed(), ephemeral=True, view=self._create_aoc_view) + await interaction.response.send_message(embed=home_embed(), ephemeral=True, view=AdventOfCodeView()) diff --git a/bot/extensions/adventofcode/views.py b/bot/extensions/adventofcode/views.py index 5d92caf9..163b86a0 100644 --- a/bot/extensions/adventofcode/views.py +++ b/bot/extensions/adventofcode/views.py @@ -10,7 +10,10 @@ from bot.extensions.adventofcode.utils import LEADERBOARD_ID, YEAR, Member, fetch_leaderboard, home_embed, ordinal -class CreateAdventOfCodeView(ui.View): +class AdventOfCodeView(ui.View): + def __init__(self): + super().__init__(timeout=None) + HOME_CUSTOM_ID = "extensions:adventofcode:home" LOCAL_LEADERBOARD_CUSTOM_ID = "extensions:adventofcode:local" GLOBAL_LEADERBOARD_CUSTOM_ID = "extensions:adventofcode:global" diff --git a/bot/extensions/polls/commands.py b/bot/extensions/polls/commands.py index edeca6ad..108678f8 100644 --- a/bot/extensions/polls/commands.py +++ b/bot/extensions/polls/commands.py @@ -4,16 +4,14 @@ from bot import core from bot.extensions.polls.utils import emojis, poll_check -from bot.extensions.polls.views import CreatePollView +from bot.extensions.polls.views import PollView from utils.transformers import MessageTransformer class Polls(commands.GroupCog, group_name="poll"): def __init__(self, bot: core.DiscordBot): self.bot = bot - - self._create_poll_view = CreatePollView(timeout=None) - self.bot.add_view(self._create_poll_view) + self.bot.add_view(PollView()) @app_commands.command() @app_commands.describe(question="Your question") @@ -26,7 +24,7 @@ async def new(self, interaction: core.InteractionType, question: str): color=discord.colour.Color.gold(), ) embed.set_footer(text=f"Poll by {interaction.user.display_name}") - await interaction.response.send_message(embed=embed, ephemeral=True, view=self._create_poll_view) + await interaction.response.send_message(embed=embed, ephemeral=True, view=PollView()) @app_commands.command() async def show( diff --git a/bot/extensions/polls/views.py b/bot/extensions/polls/views.py index 52a6b6db..c0041342 100644 --- a/bot/extensions/polls/views.py +++ b/bot/extensions/polls/views.py @@ -26,10 +26,10 @@ async def on_submit(self, interaction: discord.Interaction) -> None: embed.add_field(name=f"{str(emojis[field_count])} {self.name}", value=self.description, inline=False) field_count += 1 - view = CreatePollView() - add_choice_btn = discord.utils.get(view.children, custom_id=CreatePollView.ADD_CUSTOM_ID) - create_poll_btn = discord.utils.get(view.children, custom_id=CreatePollView.CREATE_CUSTOM_ID) + view = PollView() + add_choice_btn = discord.utils.get(view.children, custom_id=PollView.ADD_CUSTOM_ID) + create_poll_btn = discord.utils.get(view.children, custom_id=PollView.CREATE_CUSTOM_ID) delete_select = discord.utils.find(lambda child: isinstance(child, discord.ui.Select), view.children) add_choice_btn.disabled = field_count > 9 @@ -48,7 +48,7 @@ def __init__(self, fields: list["_EmbedFieldProxy"]): row=2, max_values=len(fields), placeholder="➖ Select a choice to remove", - custom_id=CreatePollView.DELETE_CUSTOM_ID, + custom_id=PollView.DELETE_CUSTOM_ID, options=[ discord.SelectOption(emoji=emojis[i], label=field.name.split(maxsplit=1)[1], value=str(i)) for i, field in enumerate(fields) @@ -73,15 +73,18 @@ async def callback(self, interaction: core.InteractionType): field_count = len(embed.fields) # We removed a choice so reset the disabled state of the buttons - add_choice_btn = discord.utils.get(self.view.children, custom_id=CreatePollView.ADD_CUSTOM_ID) - create_poll_btn = discord.utils.get(self.view.children, custom_id=CreatePollView.CREATE_CUSTOM_ID) + add_choice_btn = discord.utils.get(self.view.children, custom_id=PollView.ADD_CUSTOM_ID) + create_poll_btn = discord.utils.get(self.view.children, custom_id=PollView.CREATE_CUSTOM_ID) add_choice_btn.disabled = False create_poll_btn.disabled = field_count < 2 await interaction.response.edit_message(embed=embed, view=self.view) -class CreatePollView(ui.View): +class PollView(ui.View): + def __init__(self): + super().__init__(timeout=None) + ADD_CUSTOM_ID = "extensions:polls:add" DELETE_CUSTOM_ID = "extensions:polls:delete" CREATE_CUSTOM_ID = "extensions:polls:create"