Skip to content

Commit 6bfcfbe

Browse files
ajax146dkay0670Copilot
authored
Refactors hello, removes worthless unit tests (#1300)
* Refactors hello, removes worthless unit tests * Add return type None to function * fix typo Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: dkay <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 0f98833 commit 6bfcfbe

File tree

4 files changed

+29
-73
lines changed

4 files changed

+29
-73
lines changed

README.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,21 @@ On startup, the bot will load all extension files in the `techsupport_bot/extens
6868

6969
A (very) simple example:
7070
```python
71-
from core import auxiliary, cogs
72-
from discord.ext import commands
73-
async def setup(bot):
71+
import discord
72+
from core import cogs
73+
from discord import app_commands
74+
75+
async def setup(bot: bot.TechSupportBot) -> None:
7476
await bot.add_cog(Greeter(bot=bot))
77+
7578
class Greeter(cogs.BaseCog):
76-
async def hello_command(self, ctx) -> None:
77-
await auxiliary.add_list_of_reactions(
78-
message=ctx.message, reactions=["🇭", "🇪", "🇾"]
79-
)
80-
@commands.command(
79+
@app_commands.command(
8180
name="hello",
82-
brief="Says hello to the bot",
8381
description="Says hello to the bot (because they are doing such a great job!)",
84-
usage="",
82+
extras={"module": "hello"},
8583
)
86-
async def hello(self, ctx):
87-
await self.hello_command(ctx)
84+
async def hello_app_command(self: Self, interaction: discord.Interaction) -> None:
85+
await interaction.response.send_message("🇭 🇪 🇾")
86+
8887
```
8988
Extensions can be configured per-guild with settings saved on Postgres. There are several extensions included in the main repo, so please reference them for more advanced examples.

techsupport_bot/commands/hello.py

+13-22
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
"""
2-
Module for the hello command on the discord bot.
3-
This module has unit tests
4-
This modules requires no config, no databases, and no APIs
2+
Commands: /hello
3+
Config: None
4+
Databases: None
5+
Unit tests: No need
56
"""
67

78
from __future__ import annotations
89

910
from typing import TYPE_CHECKING, Self
1011

11-
from core import auxiliary, cogs
12-
from discord.ext import commands
12+
import discord
13+
from core import cogs
14+
from discord import app_commands
1315

1416
if TYPE_CHECKING:
1517
import bot
@@ -27,26 +29,15 @@ async def setup(bot: bot.TechSupportBot) -> None:
2729
class Greeter(cogs.BaseCog):
2830
"""Class for the greeter command."""
2931

30-
async def hello_command(self: Self, ctx: commands.Context) -> None:
31-
"""A simple function to add HEY reactions to the command invocation
32-
33-
Args:
34-
ctx (commands.Context): The context in which the command was run in
35-
"""
36-
await auxiliary.add_list_of_reactions(
37-
message=ctx.message, reactions=["🇭", "🇪", "🇾"]
38-
)
39-
40-
@commands.command(
32+
@app_commands.command(
4133
name="hello",
42-
brief="Says hello to the bot",
4334
description="Says hello to the bot (because they are doing such a great job!)",
44-
usage="",
35+
extras={"module": "hello"},
4536
)
46-
async def hello(self: Self, ctx: commands.Context) -> None:
47-
"""Entry point for the .hello command on discord
37+
async def hello_app_command(self: Self, interaction: discord.Interaction) -> None:
38+
"""A simple command to have the bot say HEY to the invoker
4839
4940
Args:
50-
ctx (commands.Context): The context in which the command was run in
41+
interaction (discord.Interaction): The interaction that called this command
5142
"""
52-
await self.hello_command(ctx)
43+
await interaction.response.send_message("🇭 🇪 🇾")

techsupport_bot/core/auxiliary.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ async def add_list_of_reactions(message: discord.Message, reactions: list) -> No
9393
reactions (list): A list of all unicode emojis to add
9494
"""
9595
for emoji in reactions:
96-
await message.add_reaction(emoji)
96+
try:
97+
await message.add_reaction(emoji)
98+
except discord.NotFound:
99+
# Message was deleted, ignore and stop executing
100+
return
97101

98102

99103
def construct_mention_string(targets: list[discord.User]) -> str:

techsupport_bot/tests/commands_tests/test_extensions_hello.py

-38
This file was deleted.

0 commit comments

Comments
 (0)