From 5ed354a65b568040d450b2f37e3b0c9063b8abd6 Mon Sep 17 00:00:00 2001 From: FirePlank <44502537+FirePlank@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:40:44 +0200 Subject: [PATCH 1/7] Made example.env unified and added error handling to aoc extension. --- bot/config.py | 6 --- bot/extensions/adventofcode/utils.py | 14 ++++-- bot/extensions/adventofcode/views.py | 18 +++++--- bot/extensions/challenges/commands.py | 6 +-- example.env | 62 ++++++++++++--------------- 5 files changed, 52 insertions(+), 54 deletions(-) diff --git a/bot/config.py b/bot/config.py index 8af5d29e..89e36eda 100644 --- a/bot/config.py +++ b/bot/config.py @@ -78,11 +78,6 @@ class Tags(BaseModel): required_role_id: int # [lvl 30] Engineer -class Timathon(BaseModel): - channel_id: int - participant_role_id: int - - class Hastebin(BaseModel): base_url: str @@ -112,7 +107,6 @@ class Settings(BaseSettings): moderation: Moderation reaction_roles: ReactionRoles tags: Tags - timathon: Timathon hastebin: Hastebin errors: ErrorHandling custom_roles: CustomRoles diff --git a/bot/extensions/adventofcode/utils.py b/bot/extensions/adventofcode/utils.py index ef3921ea..49f449de 100644 --- a/bot/extensions/adventofcode/utils.py +++ b/bot/extensions/adventofcode/utils.py @@ -2,6 +2,7 @@ from typing import Optional, Union from zoneinfo import ZoneInfo +import aiohttp import discord from async_lru import alru_cache from pydantic import BaseModel, validator @@ -76,7 +77,7 @@ class Member(BaseModel): local_score: int @validator("name", pre=True) - def set_name_to_anonymous(cls, val: Optional[str]) -> str: + def check_username(cls, val: Optional[str]) -> str: if val is None: return "Anonymous User" return val @@ -88,11 +89,18 @@ async def fetch_leaderboard(local: bool = False) -> Union[str, dict]: if local: url += f"/private/view/{LEADERBOARD_ID}.json" - async with http.session.get(url, headers=AOC_REQUEST_HEADERS, raise_for_status=True) as resp: + async with http.session.get(url, headers=AOC_REQUEST_HEADERS) as resp: if resp.status == 200: if local: - response = await resp.json() + try: + response = await resp.json() + except aiohttp.ContentTypeError: + response = "Failed to get leaderboard data. Please check that the leaderboard code is correct." else: response = await resp.text() + elif resp.status == 500: + response = "Failed to get leaderboard data. Please check that the session cookie is correct." + else: + response = "Failed to get leaderboard data. Please check that all the env values are correct." return response diff --git a/bot/extensions/adventofcode/views.py b/bot/extensions/adventofcode/views.py index 13e7da4d..5d92caf9 100644 --- a/bot/extensions/adventofcode/views.py +++ b/bot/extensions/adventofcode/views.py @@ -22,17 +22,21 @@ async def home(self, interaction: core.InteractionType, _button: ui.Button): @discord.ui.button( label="Local Leaderboard", style=discord.ButtonStyle.gray, emoji="👥", custom_id=LOCAL_LEADERBOARD_CUSTOM_ID ) - async def local_leaderboard(self, interaction: core.InteractionType, button: ui.Button): + async def local_leaderboard(self, interaction: core.InteractionType, _button: ui.Button): leaderboard = await fetch_leaderboard(local=True) - members = [Member(**member_data) for member_data in leaderboard["members"].values()] - embed = discord.Embed( title=f"{interaction.guild.name} Advent of Code Leaderboard", colour=0x68C290, url=f"https://adventofcode.com/{YEAR}/leaderboard/private/view/{LEADERBOARD_ID}", ) + if isinstance(leaderboard, str): + embed.description = leaderboard + return await interaction.response.edit_message(embed=embed, view=self) + + members = [Member(**member_data) for member_data in leaderboard["members"].values()] + leaderboard = { "owner_id": leaderboard["owner_id"], "event": leaderboard["event"], @@ -53,9 +57,8 @@ async def local_leaderboard(self, interaction: core.InteractionType, button: ui. @discord.ui.button( label="Global Leaderboard", style=discord.ButtonStyle.gray, emoji="🌎", custom_id=GLOBAL_LEADERBOARD_CUSTOM_ID ) - async def global_leaderboard(self, interaction: core.InteractionType, button: ui.Button): + async def global_leaderboard(self, interaction: core.InteractionType, _button: ui.Button): raw_html = await fetch_leaderboard(local=False) - soup = BeautifulSoup(raw_html, "html.parser") embed = discord.Embed( title="Advent of Code Global Leaderboard", @@ -63,6 +66,11 @@ async def global_leaderboard(self, interaction: core.InteractionType, button: ui url=f"https://adventofcode.com/{YEAR}/leaderboard", ) + if raw_html.startswith("Failed to get leaderboard data."): + embed.description = raw_html + return await interaction.response.edit_message(embed=embed, view=self) + + soup = BeautifulSoup(raw_html, "html.parser") if soup.find("p").text == "Nothing to show on the leaderboard... yet.": embed.description = "The global leaderboard is not available yet. Please try again later." return await interaction.response.edit_message(embed=embed, view=self) diff --git a/bot/extensions/challenges/commands.py b/bot/extensions/challenges/commands.py index fdd05ba7..707a3242 100644 --- a/bot/extensions/challenges/commands.py +++ b/bot/extensions/challenges/commands.py @@ -75,10 +75,6 @@ def submit_channel(self) -> discord.TextChannel | None: def submissions_channel(self) -> discord.TextChannel | None: return self.bot.guild.get_channel(settings.challenges.submissions_channel_id) - @property - def games_channel(self) -> discord.TextChannel | None: - return self.bot.guild.get_channel(settings.bot.games_channel_id) - @app_commands.command() async def clear_winners(self, interaction: core.InteractionType): """Clears the winner role from all members that have it.""" @@ -150,7 +146,7 @@ async def announce(self, interaction: core.InteractionType): """Send an announcement in the info channel mentioning the winners.""" text = ( - f"{self.winner_role.mention} 🥞 have been given out, go deposit them in {self.games_channel.mention}." + f"{self.winner_role.mention} 🥞 have been given out, go deposit them in <#{settings.bot.games_channel_id}>." f"\nAnalysis for the challenge will be available shortly in {self.info_channel.mention}." ) await self.info_channel.send(text, allowed_mentions=discord.AllowedMentions(roles=[self.winner_role])) diff --git a/example.env b/example.env index 5c9adeb0..b165b9f5 100644 --- a/example.env +++ b/example.env @@ -1,34 +1,30 @@ # -------- Config # --- AoC -AOC__CHANNEL_ID=0 -AOC__ROLE_ID=0 -AOC__LEADERBOARD_CODE = 975452-d90a48b0 -AOC__SESSION_COOKIE=... +AOC__CHANNEL_ID= +AOC__ROLE_ID= +AOC__LEADERBOARD_CODE=975452-d90a48b0 +AOC__SESSION_COOKIE= # --- Bots - -# List[int] # [#bot-commands, #commands] (main bot-commands channel at index 0) -# Leave no sapce or use double quotes `"` e.g: "[0, 0]" -BOT__COMMANDS_CHANNELS_IDS=[0,0] -BOT__GAMES_CHANNEL_ID=0 +BOT__GAMES_CHANNEL_ID= BOT__TOKEN= # --- CHALLENGES -CHALLENGES__CHANNEL_ID=0 -CHALLENGES__DISCUSSION_CHANNEL_ID=0 -CHALLENGES__HOST_HELPER_ROLE_ID=0 -CHALLENGES__HOST_ROLE_ID=0 -CHALLENGES__INFO_CHANNEL_ID=0 -CHALLENGES__PARTICIPANT_ROLE_ID=0 -CHALLENGES__SUBMISSIONS_CHANNEL_ID=0 -CHALLENGES__SUBMITTED_ROLE_ID=0 -CHALLENGES__SUBMIT_CHANNEL_ID=0 -CHALLENGES__WINNER_ROLE_ID=0 +CHALLENGES__CHANNEL_ID= +CHALLENGES__DISCUSSION_CHANNEL_ID= +CHALLENGES__HOST_HELPER_ROLE_ID= +CHALLENGES__HOST_ROLE_ID= +CHALLENGES__INFO_CHANNEL_ID= +CHALLENGES__PARTICIPANT_ROLE_ID= +CHALLENGES__SUBMISSIONS_CHANNEL_ID= +CHALLENGES__SUBMITTED_ROLE_ID= +CHALLENGES__SUBMIT_CHANNEL_ID= +CHALLENGES__WINNER_ROLE_ID= # --- COC -COC__CHANNEL_ID=0 -COC__MESSAGE_ID=0 -COC__ROLE_ID=0 +COC__CHANNEL_ID= +COC__MESSAGE_ID= +COC__ROLE_ID= # --- Postgres POSTGRES__MAX_POOL_CONNECTIONS=10 @@ -37,7 +33,7 @@ POSTGRES__URI= # --- Guild GUILD__ID= -GUILD__WELCOMES_CHANNEL_ID=0 +GUILD__WELCOMES_CHANNEL_ID= # --- Moderation # List[int], # Leave no sapce or use double quotes `"` e.g: "[0, 0]" @@ -45,8 +41,8 @@ MODERATION__ADMIN_ROLES_IDS= MODERATION__STAFF_ROLE_ID= # --- Notification -NOTIFICATION__CHANNEL_ID=0 -NOTIFICATION__ROLE_ID=0 +NOTIFICATION__CHANNEL_ID= +NOTIFICATION__ROLE_ID= # --- Reaction Roles # Access to reaction roles @@ -57,19 +53,15 @@ REACTION_ROLES__ROLES={"0":0} REACTION_ROLES__MESSAGE_ID=0 # --- Tags -TAGS__LOG_CHANNEL_ID=0 +TAGS__LOG_CHANNEL_ID= # Access to tag commands -TAGS__REQUIRED_ROLE_ID=0 - -# --- Timathon -TIMATHON__CHANNEL_ID=0 -TIMATHON__PARTICIPANT_ROLE_ID=0 +TAGS__REQUIRED_ROLE_ID= # --- Custom Roles -CUSTOM_ROLES__LOG_CHANNEL_ID=0 -CUSTOM_ROLES__DIVIDER_ROLE_ID=0 +CUSTOM_ROLES__LOG_CHANNEL_ID= +CUSTOM_ROLES__DIVIDER_ROLE_ID= # --- Youtube YOUTUBE__CHANNEL_ID=UC4JX40jDee_tINbkjycV4Sg -YOUTUBE__TEXT_CHANNEL_ID=0 -YOUTUBE__ROLE_ID=0 +YOUTUBE__TEXT_CHANNEL_ID= +YOUTUBE__ROLE_ID= From 9e0e4947a1d2b49aeca2f67fda1efbf753c87c61 Mon Sep 17 00:00:00 2001 From: FirePlank <44502537+FirePlank@users.noreply.github.com> Date: Thu, 30 Nov 2023 16:24:09 +0200 Subject: [PATCH 2/7] return instead of saving response --- bot/extensions/adventofcode/utils.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bot/extensions/adventofcode/utils.py b/bot/extensions/adventofcode/utils.py index 49f449de..5e26fabd 100644 --- a/bot/extensions/adventofcode/utils.py +++ b/bot/extensions/adventofcode/utils.py @@ -93,14 +93,12 @@ async def fetch_leaderboard(local: bool = False) -> Union[str, dict]: if resp.status == 200: if local: try: - response = await resp.json() + return await resp.json() except aiohttp.ContentTypeError: - response = "Failed to get leaderboard data. Please check that the leaderboard code is correct." + return "Failed to get leaderboard data. Please check that the leaderboard code is correct." else: - response = await resp.text() + return await resp.text() elif resp.status == 500: - response = "Failed to get leaderboard data. Please check that the session cookie is correct." + return "Failed to get leaderboard data. Please check that the session cookie is correct." else: - response = "Failed to get leaderboard data. Please check that all the env values are correct." - - return response + return "Failed to get leaderboard data. Please check that all the env values are correct." 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 3/7] 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" From b92ce5315cc7cd29f2be4164d3d037130458614f Mon Sep 17 00:00:00 2001 From: FirePlank <44502537+FirePlank@users.noreply.github.com> Date: Thu, 30 Nov 2023 19:42:42 +0200 Subject: [PATCH 4/7] added error handling to views --- bot/extensions/adventofcode/views.py | 7 ++++++- bot/extensions/polls/views.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bot/extensions/adventofcode/views.py b/bot/extensions/adventofcode/views.py index 163b86a0..71e84e2e 100644 --- a/bot/extensions/adventofcode/views.py +++ b/bot/extensions/adventofcode/views.py @@ -1,10 +1,12 @@ import re from datetime import datetime +from typing import Any from zoneinfo import ZoneInfo import discord from bs4 import BeautifulSoup -from discord import ui +from discord import Interaction, ui +from discord.ui import Item from bot import core from bot.extensions.adventofcode.utils import LEADERBOARD_ID, YEAR, Member, fetch_leaderboard, home_embed, ordinal @@ -109,3 +111,6 @@ async def global_leaderboard(self, interaction: core.InteractionType, _button: u embed.description = s_desc await interaction.response.edit_message(embed=embed, view=self) + + async def on_error(self, interaction: Interaction, _error: Exception, _item: Item[Any], /) -> None: + await interaction.client.on_error("adventofcode_view") diff --git a/bot/extensions/polls/views.py b/bot/extensions/polls/views.py index c0041342..00008238 100644 --- a/bot/extensions/polls/views.py +++ b/bot/extensions/polls/views.py @@ -1,7 +1,7 @@ import typing as t import discord -from discord import ui +from discord import Interaction, ui from bot import core from bot.extensions.polls.utils import emojis @@ -118,3 +118,6 @@ async def create_poll(self, interaction: core.InteractionType, _button: ui.Butto for i in range(0, len(embed.fields)): await message.add_reaction(emojis[i]) + + async def on_error(self, interaction: Interaction, _error: Exception, _item: ui.Item[t.Any], /) -> None: + await interaction.client.on_error("poll_view") From fc55d5702358ec17f44796b31c6a95ae320a32cb Mon Sep 17 00:00:00 2001 From: FirePlank <44502537+FirePlank@users.noreply.github.com> Date: Thu, 30 Nov 2023 20:01:50 +0200 Subject: [PATCH 5/7] Did the suggested changes --- bot/extensions/adventofcode/views.py | 4 ++-- bot/extensions/polls/commands.py | 6 +++--- bot/extensions/polls/views.py | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bot/extensions/adventofcode/views.py b/bot/extensions/adventofcode/views.py index 71e84e2e..10cc8e66 100644 --- a/bot/extensions/adventofcode/views.py +++ b/bot/extensions/adventofcode/views.py @@ -1,6 +1,6 @@ import re +import typing as t from datetime import datetime -from typing import Any from zoneinfo import ZoneInfo import discord @@ -112,5 +112,5 @@ async def global_leaderboard(self, interaction: core.InteractionType, _button: u await interaction.response.edit_message(embed=embed, view=self) - async def on_error(self, interaction: Interaction, _error: Exception, _item: Item[Any], /) -> None: + async def on_error(self, interaction: Interaction, _error: Exception, _item: Item[t.Any], /) -> None: await interaction.client.on_error("adventofcode_view") diff --git a/bot/extensions/polls/commands.py b/bot/extensions/polls/commands.py index 108678f8..e22c4354 100644 --- a/bot/extensions/polls/commands.py +++ b/bot/extensions/polls/commands.py @@ -4,14 +4,14 @@ from bot import core from bot.extensions.polls.utils import emojis, poll_check -from bot.extensions.polls.views import PollView +from bot.extensions.polls.views import CreatePollView from utils.transformers import MessageTransformer class Polls(commands.GroupCog, group_name="poll"): def __init__(self, bot: core.DiscordBot): self.bot = bot - self.bot.add_view(PollView()) + self.bot.add_view(CreatePollView()) @app_commands.command() @app_commands.describe(question="Your question") @@ -24,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=PollView()) + await interaction.response.send_message(embed=embed, ephemeral=True, view=CreatePollView()) @app_commands.command() async def show( diff --git a/bot/extensions/polls/views.py b/bot/extensions/polls/views.py index 00008238..6712d377 100644 --- a/bot/extensions/polls/views.py +++ b/bot/extensions/polls/views.py @@ -27,9 +27,9 @@ 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 = 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) + 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) 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=PollView.DELETE_CUSTOM_ID, + custom_id=CreatePollView.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,15 @@ 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=PollView.ADD_CUSTOM_ID) - create_poll_btn = discord.utils.get(self.view.children, custom_id=PollView.CREATE_CUSTOM_ID) + 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.disabled = False create_poll_btn.disabled = field_count < 2 await interaction.response.edit_message(embed=embed, view=self.view) -class PollView(ui.View): +class CreatePollView(ui.View): def __init__(self): super().__init__(timeout=None) From 771d59001b0f3ec9c7b49bb4d4487471c064de21 Mon Sep 17 00:00:00 2001 From: FirePlank <44502537+FirePlank@users.noreply.github.com> Date: Thu, 30 Nov 2023 20:07:52 +0200 Subject: [PATCH 6/7] grudgingly did the suggested changes --- bot/extensions/polls/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/extensions/polls/views.py b/bot/extensions/polls/views.py index 6712d377..0c729aa3 100644 --- a/bot/extensions/polls/views.py +++ b/bot/extensions/polls/views.py @@ -1,7 +1,7 @@ import typing as t import discord -from discord import Interaction, ui +from discord import ui from bot import core from bot.extensions.polls.utils import emojis @@ -119,5 +119,5 @@ async def create_poll(self, interaction: core.InteractionType, _button: ui.Butto for i in range(0, len(embed.fields)): await message.add_reaction(emojis[i]) - async def on_error(self, interaction: Interaction, _error: Exception, _item: ui.Item[t.Any], /) -> None: + async def on_error(self, interaction: core.InteractionType, _error: Exception, _item: ui.Item[t.Any], /) -> None: await interaction.client.on_error("poll_view") From d8e594f53cdcc2965880d4e5bc18f2f312d42f36 Mon Sep 17 00:00:00 2001 From: FirePlank <44502537+FirePlank@users.noreply.github.com> Date: Thu, 30 Nov 2023 20:13:57 +0200 Subject: [PATCH 7/7] used interactiontype --- bot/extensions/adventofcode/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/extensions/adventofcode/views.py b/bot/extensions/adventofcode/views.py index 10cc8e66..39ab430b 100644 --- a/bot/extensions/adventofcode/views.py +++ b/bot/extensions/adventofcode/views.py @@ -5,7 +5,7 @@ import discord from bs4 import BeautifulSoup -from discord import Interaction, ui +from discord import ui from discord.ui import Item from bot import core @@ -112,5 +112,5 @@ async def global_leaderboard(self, interaction: core.InteractionType, _button: u await interaction.response.edit_message(embed=embed, view=self) - async def on_error(self, interaction: Interaction, _error: Exception, _item: Item[t.Any], /) -> None: + async def on_error(self, interaction: core.InteractionType, _error: Exception, _item: Item[t.Any], /) -> None: await interaction.client.on_error("adventofcode_view")