Cooldown handling, formatting

This commit is contained in:
Zeva Rose 2022-03-25 12:45:41 -06:00
parent 3b12ffa7f0
commit dffd5f780f
2 changed files with 22 additions and 4 deletions

View file

@ -11,5 +11,6 @@ extend-ignore =
D101, # Missing docstring in public class D101, # Missing docstring in public class
# Plugins we don't currently include: flake8-return # Plugins we don't currently include: flake8-return
R502, # do not implicitly return None in function able to return non-None value.
R503, # missing explicit return at the end of function ableto return non-None value. R503, # missing explicit return at the end of function ableto return non-None value.
max-line-length=100 max-line-length=100

View file

@ -7,6 +7,7 @@ from datetime import datetime
from aiohttp import ClientSession from aiohttp import ClientSession
from dis_snek import Snake, listen from dis_snek import Snake, listen
from dis_snek.api.events.discord import MessageCreate, MessageDelete, MessageUpdate from dis_snek.api.events.discord import MessageCreate, MessageDelete, MessageUpdate
from dis_snek.client.errors import CommandCheckFailure, CommandOnCooldown
from dis_snek.client.utils.misc_utils import find_all from dis_snek.client.utils.misc_utils import find_all
from dis_snek.models.discord.channel import DMChannel from dis_snek.models.discord.channel import DMChannel
from dis_snek.models.discord.embed import EmbedField from dis_snek.models.discord.embed import EmbedField
@ -95,14 +96,23 @@ class Jarvis(Snake):
self, ctx: Context, error: Exception, *args: list, **kwargs: dict self, ctx: Context, error: Exception, *args: list, **kwargs: dict
) -> None: ) -> None:
"""Lepton on_command_error override.""" """Lepton on_command_error override."""
if isinstance(error, CommandOnCooldown):
await ctx.send(str(error), ephemeral=True)
return
elif isinstance(error, CommandCheckFailure):
await ctx.send("I'm afraid I can't let you do that", ephemeral=True)
return
guild = await self.fetch_guild(DEFAULT_GUILD) guild = await self.fetch_guild(DEFAULT_GUILD)
channel = await guild.fetch_channel(DEFAULT_ERROR_CHANNEL) channel = await guild.fetch_channel(DEFAULT_ERROR_CHANNEL)
error_time = datetime.utcnow().strftime("%d-%m-%Y %H:%M-%S.%f UTC") error_time = datetime.utcnow().strftime("%d-%m-%Y %H:%M-%S.%f UTC")
timestamp = int(datetime.now().timestamp()) timestamp = int(datetime.now().timestamp())
timestamp = f"<t:{timestamp}:T>" timestamp = f"<t:{timestamp}:T>"
arg_str = ( arg_str = ""
"\n".join(f" {k}: {v}" for k, v in ctx.kwargs.items()) if ctx.kwargs else " None" for k, v in ctx.kwargs.items():
) arg_str += f" {k}: "
if isinstance(v, str) and len(v) > 100:
v = v[97] + "..."
arg_str += f"{v}\n"
callback_args = "\n".join(f" - {i}" for i in args) if args else " None" callback_args = "\n".join(f" - {i}" for i in args) if args else " None"
callback_kwargs = ( callback_kwargs = (
"\n".join(f" {k}: {v}" for k, v in kwargs.items()) if kwargs else " None" "\n".join(f" {k}: {v}" for k, v in kwargs.items()) if kwargs else " None"
@ -141,7 +151,14 @@ class Jarvis(Snake):
modlog = await Setting.find_one(q(guild=ctx.guild.id, setting="modlog")) modlog = await Setting.find_one(q(guild=ctx.guild.id, setting="modlog"))
if modlog: if modlog:
channel = await ctx.guild.fetch_channel(modlog.value) channel = await ctx.guild.fetch_channel(modlog.value)
args = " ".join(f"{KEY_FMT}{k}:{VAL_FMT}{v}{RESET}" for k, v in ctx.kwargs.items()) args = []
for k, v in ctx.kwargs.items():
if isinstance(v, str):
v = v.replace("`", "\\`")
if len(v) > 100:
v = v[:97] + "..."
args.append(f"{KEY_FMT}{k}:{VAL_FMT}{v}{RESET}")
args = " ".join(args)
fields = [ fields = [
EmbedField( EmbedField(
name="Command", name="Command",