Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,21 @@ On startup, the bot will load all extension files in the `techsupport_bot/extens

A (very) simple example:
```python
from core import auxiliary, cogs
from discord.ext import commands
async def setup(bot):
import discord
from core import cogs
from discord import app_commands

async def setup(bot: bot.TechSupportBot) -> None:
await bot.add_cog(Greeter(bot=bot))

class Greeter(cogs.BaseCog):
async def hello_command(self, ctx) -> None:
await auxiliary.add_list_of_reactions(
message=ctx.message, reactions=["🇭", "🇪", "🇾"]
)
@commands.command(
@app_commands.command(
name="hello",
brief="Says hello to the bot",
description="Says hello to the bot (because they are doing such a great job!)",
usage="",
extras={"module": "hello"},
)
async def hello(self, ctx):
await self.hello_command(ctx)
async def hello_app_command(self: Self, interaction: discord.Interaction) -> None:
await interaction.response.send_message("🇭 🇪 🇾")

```
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.
35 changes: 13 additions & 22 deletions techsupport_bot/commands/hello.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""
Module for the hello command on the discord bot.
This module has unit tests
This modules requires no config, no databases, and no APIs
Commands: /hello
Config: None
Databases: None
Unit tests: No need
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Self

from core import auxiliary, cogs
from discord.ext import commands
import discord
from core import cogs
from discord import app_commands

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

async def hello_command(self: Self, ctx: commands.Context) -> None:
"""A simple function to add HEY reactions to the command invocation

Args:
ctx (commands.Context): The context in which the command was run in
"""
await auxiliary.add_list_of_reactions(
message=ctx.message, reactions=["🇭", "🇪", "🇾"]
)

@commands.command(
@app_commands.command(
name="hello",
brief="Says hello to the bot",
description="Says hello to the bot (because they are doing such a great job!)",
usage="",
extras={"module": "hello"},
)
async def hello(self: Self, ctx: commands.Context) -> None:
"""Entry point for the .hello command on discord
async def hello_app_command(self: Self, interaction: discord.Interaction) -> None:
"""A simple command to have the bot say HEY to the invoker

Args:
ctx (commands.Context): The context in which the command was run in
interaction (discord.Interaction): The interaction that called this command
"""
await self.hello_command(ctx)
await interaction.response.send_message("🇭 🇪 🇾")
6 changes: 5 additions & 1 deletion techsupport_bot/core/auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ async def add_list_of_reactions(message: discord.Message, reactions: list) -> No
reactions (list): A list of all unicode emojis to add
"""
for emoji in reactions:
await message.add_reaction(emoji)
try:
await message.add_reaction(emoji)
except discord.NotFound:
# Message was deleted, ignore and stop executing
return


def construct_mention_string(targets: list[discord.User]) -> str:
Expand Down
38 changes: 0 additions & 38 deletions techsupport_bot/tests/commands_tests/test_extensions_hello.py

This file was deleted.

Loading