Skip to content

Commit

Permalink
Inform bot managers about errors if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
TSRBerry committed Sep 12, 2023
1 parent bac8705 commit c0582ed
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions robocop_ng/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from discord.ext import commands
from discord.ext.commands import CommandError, Context

from robocop_ng.helpers.notifications import report_critical_error

if len(sys.argv[1:]) != 1:
sys.stderr.write("usage: <state_dir>")
sys.exit(1)
Expand Down Expand Up @@ -140,6 +142,25 @@ async def on_command(ctx):
async def on_error(event: str, *args, **kwargs):
log.exception(f"Error on {event}:")

exception = sys.exception()
is_report_allowed = any(
[
not isinstance(exception, x)
for x in [
discord.RateLimited,
discord.GatewayNotFound,
discord.InteractionResponded,
discord.LoginFailure,
]
]
)
if exception is not None and is_report_allowed:
await report_critical_error(
bot,
exception,
additional_info={"Event": event, "args": args, "kwargs": kwargs},
)


@bot.event
async def on_command_error(ctx: Context, error: CommandError):
Expand Down

0 comments on commit c0582ed

Please sign in to comment.