From acb816bbabde1eaaf389d3dd7f935b2495a03d9e Mon Sep 17 00:00:00 2001 From: dkay Date: Wed, 30 Apr 2025 21:28:20 -0700 Subject: [PATCH 1/6] Add friendly message when trying to echo into a forum channel --- techsupport_bot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/techsupport_bot/bot.py b/techsupport_bot/bot.py index 133ffbf1..15055aa9 100644 --- a/techsupport_bot/bot.py +++ b/techsupport_bot/bot.py @@ -47,7 +47,7 @@ class TechSupportBot(commands.Bot): FUNCTIONS_DIR (str):The list of all files in the FUNCTIONS_DIR_NAME folder """ - CONFIG_PATH: str = "./config.yml" + CONFIG_PATH: str = "../config.yml" EXTENSIONS_DIR_NAME: str = "commands" EXTENSIONS_DIR: str = ( f"{os.path.join(os.path.dirname(__file__))}/{EXTENSIONS_DIR_NAME}" From 280f192c67f68e77601c71206026c16577ee41e1 Mon Sep 17 00:00:00 2001 From: dkay Date: Wed, 30 Apr 2025 22:50:40 -0700 Subject: [PATCH 2/6] Revert "Add friendly message when trying to echo into a forum channel" This reverts commit acb816bbabde1eaaf389d3dd7f935b2495a03d9e. --- techsupport_bot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/techsupport_bot/bot.py b/techsupport_bot/bot.py index 15055aa9..133ffbf1 100644 --- a/techsupport_bot/bot.py +++ b/techsupport_bot/bot.py @@ -47,7 +47,7 @@ class TechSupportBot(commands.Bot): FUNCTIONS_DIR (str):The list of all files in the FUNCTIONS_DIR_NAME folder """ - CONFIG_PATH: str = "../config.yml" + CONFIG_PATH: str = "./config.yml" EXTENSIONS_DIR_NAME: str = "commands" EXTENSIONS_DIR: str = ( f"{os.path.join(os.path.dirname(__file__))}/{EXTENSIONS_DIR_NAME}" From a72a9c01742740ed6a4ca3ab38e2c0b939098b8e Mon Sep 17 00:00:00 2001 From: dkay Date: Wed, 30 Apr 2025 22:54:31 -0700 Subject: [PATCH 3/6] Update echo to use slash command and fix #922 --- techsupport_bot/commands/echo.py | 71 ++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/techsupport_bot/commands/echo.py b/techsupport_bot/commands/echo.py index c212542d..641ea696 100644 --- a/techsupport_bot/commands/echo.py +++ b/techsupport_bot/commands/echo.py @@ -12,6 +12,9 @@ from typing import TYPE_CHECKING, Self +import discord.abc +from discord import app_commands + from core import auxiliary, cogs from discord.ext import commands @@ -25,7 +28,7 @@ async def setup(bot: bot.TechSupportBot) -> None: Args: bot (bot.TechSupportBot): The bot object to register the cogs to """ - await bot.add_cog(MessageEcho(bot=bot)) + await bot.add_cog(MessageEcho(bot=bot, extension_name="echo")) class MessageEcho(cogs.BaseCog): @@ -33,28 +36,22 @@ class MessageEcho(cogs.BaseCog): The class that holds the echo commands """ - @commands.check(auxiliary.bot_admin_check_context) - @commands.group( - brief="Executes an echo bot command", description="Executes an echo bot command" + echo: app_commands.Group = app_commands.Group( + name="echo", description="...", extras={"module": "echo"} ) - async def echo(self: Self, ctx: commands.Context) -> None: - """The bare .echo command. This does nothing but generate the help message - - Args: - ctx (commands.Context): The context in which the command was run in - """ - - # Executed if there are no/invalid args supplied - await auxiliary.extension_help(self, ctx, self.__module__[9:]) - @auxiliary.with_typing + @commands.check(auxiliary.bot_admin_check_context) @echo.command( name="channel", description="Echos a message to a channel", - usage="[channel-id] [message]", + extras={"module": "echo"}, ) async def echo_channel( - self: Self, ctx: commands.Context, channel_id: int, *, message: str + self: Self, + interaction: discord.Interaction, + channel: discord.Thread | discord.TextChannel | discord.VoiceChannel, + *, + message: str, ) -> None: """Sends a message to a specified channel. @@ -65,25 +62,27 @@ async def echo_channel( channel_id (int): the ID of the channel to send the echoed message message (str): the message to echo """ - channel = self.bot.get_channel(channel_id) - if not channel: - await auxiliary.send_deny_embed( - message="I couldn't find that channel", channel=ctx.channel + try: + await channel.send(content=message) + except discord.Forbidden: + embed = auxiliary.prepare_deny_embed( + message="Unable to send message" ) + await interaction.response.send_message(embed=embed) return - await channel.send(content=message) - await auxiliary.send_confirm_embed(message="Message sent", channel=ctx.channel) + embed = auxiliary.prepare_confirm_embed(message="Message sent!") + await interaction.response.send_message(embed=embed, ephemeral=True) - @auxiliary.with_typing + @commands.check(auxiliary.bot_admin_check_context) @echo.command( name="user", description="Echos a message to a user", - usage="[user-id] [message]", + extras={"module": "echo"}, ) async def echo_user( - self: Self, ctx: commands.Context, user_id: int, *, message: str + self: Self, interaction: discord.Interaction, user: discord.User, message: str ) -> None: """Sends a message to a specified user. @@ -91,16 +90,24 @@ async def echo_user( Args: ctx (commands.Context): the context object for the calling message - user_id (int): the ID of the user to send the echoed message + user (discord.User): the the user to send the echoed message message (str): the message to echo """ - user = await self.bot.fetch_user(int(user_id)) - if not user: - await auxiliary.send_deny_embed( - message="I couldn't find that user", channel=ctx.channel + + if user.bot: + await interaction.response.send_message( + embed=auxiliary.prepare_deny_embed(message="You cannot message a bot") ) return - await user.send(content=message) + try: + await user.send(content=message) + except discord.Forbidden: + embed = auxiliary.prepare_deny_embed( + message="Unable to send message to this user" + ) + await interaction.response.send_message(embed=embed) + return - await auxiliary.send_confirm_embed(message="Message sent", channel=ctx.channel) + embed = auxiliary.prepare_confirm_embed(message="Message sent!") + await interaction.response.send_message(embed=embed, ephemeral=True) From 9369709c1cd605ce18845bacd54f9d6a509ac111 Mon Sep 17 00:00:00 2001 From: dkay Date: Wed, 30 Apr 2025 22:58:03 -0700 Subject: [PATCH 4/6] update docstrings and format file --- techsupport_bot/commands/echo.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/techsupport_bot/commands/echo.py b/techsupport_bot/commands/echo.py index 641ea696..1d63d5a4 100644 --- a/techsupport_bot/commands/echo.py +++ b/techsupport_bot/commands/echo.py @@ -58,20 +58,17 @@ async def echo_channel( This is a command and should be accessed via Discord. Args: - ctx (commands.Context): the context object for the calling message - channel_id (int): the ID of the channel to send the echoed message + interaction (discord.Interaction): the associated interaction + channel (discord.Thread|discord.TextChannel|discord.VoiceChannel): the ID of the channel to send the echoed message message (str): the message to echo """ try: await channel.send(content=message) except discord.Forbidden: - embed = auxiliary.prepare_deny_embed( - message="Unable to send message" - ) + embed = auxiliary.prepare_deny_embed(message="Unable to send message") await interaction.response.send_message(embed=embed) return - embed = auxiliary.prepare_confirm_embed(message="Message sent!") await interaction.response.send_message(embed=embed, ephemeral=True) @@ -89,7 +86,7 @@ async def echo_user( This is a command and should be accessed via Discord. Args: - ctx (commands.Context): the context object for the calling message + interaction (discord.Interaction): the associated interaction user (discord.User): the the user to send the echoed message message (str): the message to echo """ From a9e4aee126c340579149122b1d1587bc90f15eb7 Mon Sep 17 00:00:00 2001 From: dkay Date: Wed, 30 Apr 2025 23:06:36 -0700 Subject: [PATCH 5/6] sort imports, fix docstrings more, format file --- techsupport_bot/commands/echo.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/techsupport_bot/commands/echo.py b/techsupport_bot/commands/echo.py index 1d63d5a4..e667bbf8 100644 --- a/techsupport_bot/commands/echo.py +++ b/techsupport_bot/commands/echo.py @@ -4,8 +4,8 @@ MessageEcho This file contains 2 commands: - .echo user - .echo channel + /echo user + /echo channel """ from __future__ import annotations @@ -14,9 +14,9 @@ import discord.abc from discord import app_commands +from discord.ext import commands from core import auxiliary, cogs -from discord.ext import commands if TYPE_CHECKING: import bot @@ -59,7 +59,7 @@ async def echo_channel( Args: interaction (discord.Interaction): the associated interaction - channel (discord.Thread|discord.TextChannel|discord.VoiceChannel): the ID of the channel to send the echoed message + channel (discord.Thread|discord.TextChannel|discord.VoiceChannel): channel to send the message to message (str): the message to echo """ try: @@ -92,9 +92,8 @@ async def echo_user( """ if user.bot: - await interaction.response.send_message( - embed=auxiliary.prepare_deny_embed(message="You cannot message a bot") - ) + embed = auxiliary.prepare_deny_embed(message="You cannot message a bot") + await interaction.response.send_message(embed=embed) return try: From 1bcde18b4a43086121c1b376cd2ed1b945fe25de Mon Sep 17 00:00:00 2001 From: dkay Date: Thu, 1 May 2025 13:22:55 -0700 Subject: [PATCH 6/6] Sort imports better --- techsupport_bot/commands/echo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/techsupport_bot/commands/echo.py b/techsupport_bot/commands/echo.py index e667bbf8..3bcca7c8 100644 --- a/techsupport_bot/commands/echo.py +++ b/techsupport_bot/commands/echo.py @@ -10,12 +10,12 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Self - import discord.abc from discord import app_commands from discord.ext import commands +from typing import TYPE_CHECKING, Self + from core import auxiliary, cogs if TYPE_CHECKING: