Skip to content

Commit

Permalink
Make it so it stops logging every autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKrol committed Aug 21, 2024
1 parent fde405e commit a21597d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
2 changes: 2 additions & 0 deletions techsupport_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,8 @@ async def slash_command_log(self: Self, interaction: discord.Interaction) -> Non
Args:
interaction (discord.Interaction): The interaction the slash command generated
"""
if interaction.type != discord.InteractionType.application_command:
return
embed = discord.Embed()
embed.add_field(name="User", value=interaction.user)
embed.add_field(
Expand Down
37 changes: 19 additions & 18 deletions techsupport_bot/commands/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,34 +204,21 @@ async def wait(self: Self, config: munch.Munch, _: discord.Guild) -> None:
"""
await aiocron.crontab(config.extensions.news.cron_config.value).next()

@commands.group(
brief="Executes a news command",
description="Executes a news command",
)
async def news(self: Self, ctx: commands.Context) -> None:
"""The bare .news 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:])

@news.command(
name="random",
brief="Gets a random news article",
@app_commands.command(
name="news",
description="Gets a random news headline",
extras={"module": "news"},
)
async def news_command(self, interaction: discord.Interaction, category: str = ""):
"""Discord command entry point for getting a news article
Args:
ctx (commands.Context): The context in which the command was run
interaction (discord.Interaction): The interaction in which the command was run
category (str, optional): The category to get news headlines from. Defaults to None.
"""

# Debug statement
print("Executing news command")
if category is None or category.lower() not in self.valid_category:
category = random.choice(list(Category)).value
else:
Expand All @@ -254,6 +241,18 @@ async def news_command(self, interaction: discord.Interaction, category: str = "

await interaction.response.send_message(content=url)

# Log the command execution
log_channel = config.get("logging_channel")
if log_channel:
await self.bot.logger.send_log(
message=f"News command executed: Sent a news headline to {interaction.channel.name}",

Check notice on line 248 in techsupport_bot/commands/news.py

View check run for this annotation

codefactor.io / CodeFactor

techsupport_bot/commands/news.py#L248

Line too long (101/100) (line-too-long)
level=LogLevel.INFO,
context=LogContext(
guild=interaction.guild, channel=interaction.channel
),
channel=log_channel,
)

@news_command.autocomplete("category")
async def news_autocompletion(
self, interaction: discord.Interaction, current: str
Expand All @@ -267,6 +266,8 @@ async def news_autocompletion(
Returns:
The list of autocomplete for the news command.
"""
# Debug statement
print("Autocomplete interaction")
news_category = []
for category in Category:
if current.lower() in category.value.lower():
Expand Down

0 comments on commit a21597d

Please sign in to comment.