Better command logging

This commit is contained in:
Zeva Rose 2022-03-30 10:13:18 -06:00
parent 5e51a9a203
commit 87e3b18a77

View file

@ -73,8 +73,10 @@ class Jarvis(Snake):
if update["domain"] in self.phishing_domains: if update["domain"] in self.phishing_domains:
self.phishing_domains.remove(update["domain"]) self.phishing_domains.remove(update["domain"])
async def _prerun(self, ctx: Context, *args, **kwargs) -> None: async def _prerun(self, ctx: InteractionContext, *args, **kwargs) -> None:
name = ctx.invoked_name name = ctx.invoked_name
if ctx.target:
kwargs["context target"] = ctx.target
args = " ".join(f"{k}:{v}" for k, v in kwargs.items()) args = " ".join(f"{k}:{v}" for k, v in kwargs.items())
self.logger.debug(f"Running command `{name}` with args: {args or 'None'}") self.logger.debug(f"Running command `{name}` with args: {args or 'None'}")
@ -115,6 +117,8 @@ class Jarvis(Snake):
timestamp = int(datetime.now().timestamp()) timestamp = int(datetime.now().timestamp())
timestamp = f"<t:{timestamp}:T>" timestamp = f"<t:{timestamp}:T>"
arg_str = "" arg_str = ""
if ctx.target:
ctx.kwargs["context target"] = ctx.target
for k, v in ctx.kwargs.items(): for k, v in ctx.kwargs.items():
arg_str += f" {k}: " arg_str += f" {k}: "
if isinstance(v, str) and len(v) > 100: if isinstance(v, str) and len(v) > 100:
@ -136,8 +140,8 @@ class Jarvis(Snake):
error_message = "\n ".join(error_message.split("\n")) error_message = "\n ".join(error_message.split("\n"))
full_message += "Exception: |\n " + error_message full_message += "Exception: |\n " + error_message
paste = Paste(content=full_message, site=DEFAULT_SITE) paste = Paste(content=full_message, site=DEFAULT_SITE)
await paste.save() key = await paste.save()
self.logger.debug(f"Large traceback, saved to Pasty {paste.id}") self.logger.debug(f"Large traceback, saved to Pasty {paste.id}, {key=}")
await channel.send( await channel.send(
f"JARVIS encountered an error at {timestamp}. Log too big to send over Discord." f"JARVIS encountered an error at {timestamp}. Log too big to send over Discord."
@ -160,6 +164,8 @@ class Jarvis(Snake):
if modlog: if modlog:
channel = await ctx.guild.fetch_channel(modlog.value) channel = await ctx.guild.fetch_channel(modlog.value)
args = [] args = []
if ctx.target:
args.append(f"{KEY_FMT}context target:{VAL_FMT}{ctx.target}{RESET}")
for k, v in ctx.kwargs.items(): for k, v in ctx.kwargs.items():
if isinstance(v, str): if isinstance(v, str):
v = v.replace("`", "\\`") v = v.replace("`", "\\`")