Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolate bot channel #36

Merged
merged 3 commits into from
Oct 26, 2023
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
9 changes: 9 additions & 0 deletions src/bot/root_pythia_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@


CHANNEL_ID = getenv("CHANNEL_ID")
if CHANNEL_ID is not None and CHANNEL_ID.isnumeric():
CHANNEL_ID = int(CHANNEL_ID)
else:
logging.warning(
"CHANNEL_ID environment variable is either not set or not an integer: %s", CHANNEL_ID
)


def craft_intents():
Expand Down Expand Up @@ -50,6 +56,9 @@ def craft_intents():


########### Setup bot events response ###############
@BOT.check
def is_my_channel(ctx):
ZynoXelek marked this conversation as resolved.
Show resolved Hide resolved
return ctx.channel.id == CHANNEL_ID


@BOT.event
Expand Down
11 changes: 11 additions & 0 deletions src/bot/root_pythia_cogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import discord
from discord.ext import commands, tasks
from discord.ext.commands.errors import CheckFailure

from pngmaker import NewValidatedChallenge

Expand Down Expand Up @@ -146,6 +147,16 @@ async def verbose_if_idle(self, channel):

@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, CheckFailure):
ZynoXelek marked this conversation as resolved.
Show resolved Hide resolved
self.logger.warning(
"discord.ext.commands.errors.CheckFailure (is_my_channel?)"
" was captured by on_command_error: some global check failed"
" for command: '%s' in channel ID '%s'",
ctx.command,
ctx.channel.id,
)
return

await ctx.send("Command failed, please check logs for more details")
await self.verbose_if_idle(ctx)

Expand Down