From 32308e96a72f8f7dbfb16e9bf7e543c4b71ba0ae Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Fri, 5 Jun 2026 12:31:39 -0700 Subject: [PATCH 1/3] Moves XKCD to app commands --- techsupport_bot/commands/xkcd.py | 124 +++++++++++++++++-------------- 1 file changed, 68 insertions(+), 56 deletions(-) diff --git a/techsupport_bot/commands/xkcd.py b/techsupport_bot/commands/xkcd.py index e68018f7b..1a048f7d1 100644 --- a/techsupport_bot/commands/xkcd.py +++ b/techsupport_bot/commands/xkcd.py @@ -8,6 +8,7 @@ import discord import munch from core import auxiliary, cogs +from discord import app_commands from discord.ext import commands if TYPE_CHECKING: @@ -29,115 +30,126 @@ class XKCD(cogs.BaseCog): Attributes: MOST_RECENT_API_URL (str): The URL for the most recent comic SPECIFIC_API_URL (str): The URL for a given number comic + xkcd (app_commands.Group): The group for the /xkcd commands """ + xkcd: app_commands.Group = app_commands.Group( + name="xkcd", description="Command Group for the XKCD Extension" + ) + MOST_RECENT_API_URL: str = "https://xkcd.com/info.0.json" SPECIFIC_API_URL: str = "https://xkcd.com/%s/info.0.json" - @commands.group( - brief="xkcd extension parent", - description="Group for xkcd subcommands and retrieves numbered comics.", - invoke_without_subcommand=True, + @xkcd.command( + name="latest", + description="Gets the latest XKCD comic.", + extras={ + "module": "xkcd", + }, ) - async def xkcd( - self: Self, ctx: commands.Context, number: int | None = None - ) -> None: - """Entry point for the xkcd command. This either shows extension help - Or will display a comic if a number is entered + async def xkcd_latest(self: Self, interaction: discord.Interaction) -> None: + """This calls the XKCD API and gets the latest comic Args: - ctx (commands.Context): The context genereated by this command - number (int | None, optional): The comic number to lookup and display. - Defaults to None. + interaction (discord.Interaction): The interaction that called this command """ - if number: - await self.numbered_comic(ctx, number) + await interaction.response.defer() + latest_comic_data = await self.api_call() + if latest_comic_data.status_code != 200: + embed = auxiliary.prepare_deny_embed( + message="I had trouble looking up XKCD's comics" + ) + await interaction.followup.send(embed=embed) + return + + embed = self.generate_embed(latest_comic_data) + if not embed: + embed = auxiliary.prepare_deny_embed( + message="I had trouble calling getting the correct XKCD info", + ) + + await interaction.followup.send(embed=embed) @xkcd.command( name="random", - brief="Gets a random XKCD comic", - description="Gets a random XKCD comic", + description="Gets a random XKCD comic.", + extras={ + "module": "xkcd", + }, ) - async def random_comic(self: Self, ctx: commands.Context) -> None: - """Gets a completely random comic after looking up the latest comic and displays it + async def xkcd_random(self: Self, interaction: discord.Interaction) -> None: + """This calls the XKCD API and gets a random comic Args: - ctx (commands.Context): The context generated by running this command + interaction (discord.Interaction): The interaction that called this command """ - most_recent_comic_data = await self.api_call() - if most_recent_comic_data.status_code != 200: - await auxiliary.send_deny_embed( - message="I had trouble looking up XKCD's comics", channel=ctx.channel + await interaction.response.defer() + latest_comic_data = await self.api_call() + if latest_comic_data.status_code != 200: + embed = auxiliary.prepare_deny_embed( + message="I had trouble looking up XKCD's comics" ) + await interaction.followup.send(embed=embed) return - max_number = most_recent_comic_data.get("num") + max_number = latest_comic_data.get("num") if not max_number: - await auxiliary.send_deny_embed( - message="I could not determine the max XKCD number", channel=ctx.channel + embed = auxiliary.prepare_deny_embed( + message="I could not determine the max XKCD number" ) + await interaction.followup.send(embed=embed) return comic_number = random.randint(1, max_number) random_comic_data = await self.api_call(number=comic_number) if random_comic_data.status_code != 200: - await auxiliary.send_deny_embed( + embed = auxiliary.prepare_deny_embed( message=f"I had trouble calling a random comic (#{comic_number})", - channel=ctx.channel, ) + await interaction.followup.send(embed=embed) return embed = self.generate_embed(random_comic_data) if not embed: - await auxiliary.send_deny_embed( + embed = auxiliary.prepare_deny_embed( message="I had trouble calling getting the correct XKCD info", - channel=ctx.channel, ) - return - await ctx.send(embed=embed) + await interaction.followup.send(embed=embed) @xkcd.command( - name="[number]", - brief="Gets a XKCD comic", - description="Gets a XKCD comic by number", + name="specific", + description="Gets an XKCD comic by number.", + extras={"module": "xkcd", "usage": "[comic_number]"}, ) - async def shadow_number(self: Self, ctx: commands.Context, *, _: int) -> None: - """Method to generate the help entry for the group parent and - prevent direct invocation. - This exists due to an oversight in the help menu generation. - This command should never be called + async def xkcd_specific( + self: Self, interaction: discord.Interaction, comic_number: int + ) -> None: + """This calls the XKCD API and gets a specific comic Args: - ctx (commands.Context): The context generate by this command + interaction (discord.Interaction): The interaction that called this command + comic_number (int): The number of the comic to fetch from XKCD """ - return + await interaction.response.defer() - async def numbered_comic(self: Self, ctx: commands.Context, number: int) -> None: - """Gets the comic from XKCD by number - - Args: - ctx (commands.Context): The context that called an XKCD command - number (int): The comic number to get - """ - comic_data = await self.api_call(number=number) + comic_data = await self.api_call(number=comic_number) if comic_data.status_code != 200: - await auxiliary.send_deny_embed( - message="I had trouble looking up XKCD's comics", channel=ctx.channel + embed = auxiliary.prepare_deny_embed( + message=f"I had trouble calling the comic (#{comic_number})", ) + await interaction.followup.send(embed=embed) return embed = self.generate_embed(comic_data) if not embed: - await auxiliary.send_deny_embed( + embed = auxiliary.prepare_deny_embed( message="I had trouble calling getting the correct XKCD info", - channel=ctx.channel, ) - return - await ctx.send(embed=embed) + await interaction.followup.send(embed=embed) async def api_call(self: Self, number: int = None) -> munch.Munch: """Makes an API call to xkcd to get the json for a given comic From 003652596602a56e25bf1ad6bcf92de8c7fa202a Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Fri, 5 Jun 2026 12:32:59 -0700 Subject: [PATCH 2/3] Formatting --- techsupport_bot/commands/xkcd.py | 1 - 1 file changed, 1 deletion(-) diff --git a/techsupport_bot/commands/xkcd.py b/techsupport_bot/commands/xkcd.py index 1a048f7d1..e09782cda 100644 --- a/techsupport_bot/commands/xkcd.py +++ b/techsupport_bot/commands/xkcd.py @@ -9,7 +9,6 @@ import munch from core import auxiliary, cogs from discord import app_commands -from discord.ext import commands if TYPE_CHECKING: import bot From 6f3cc7cbecdfeac3104497c9121cb07305b1fe84 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Fri, 5 Jun 2026 12:34:19 -0700 Subject: [PATCH 3/3] Formatting 2 --- techsupport_bot/commands/xkcd.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/techsupport_bot/commands/xkcd.py b/techsupport_bot/commands/xkcd.py index e09782cda..4ed666438 100644 --- a/techsupport_bot/commands/xkcd.py +++ b/techsupport_bot/commands/xkcd.py @@ -33,13 +33,13 @@ class XKCD(cogs.BaseCog): """ + MOST_RECENT_API_URL: str = "https://xkcd.com/info.0.json" + SPECIFIC_API_URL: str = "https://xkcd.com/%s/info.0.json" + xkcd: app_commands.Group = app_commands.Group( name="xkcd", description="Command Group for the XKCD Extension" ) - MOST_RECENT_API_URL: str = "https://xkcd.com/info.0.json" - SPECIFIC_API_URL: str = "https://xkcd.com/%s/info.0.json" - @xkcd.command( name="latest", description="Gets the latest XKCD comic.",