diff --git a/core/bot.py b/core/bot.py index 454083e..45ac674 100644 --- a/core/bot.py +++ b/core/bot.py @@ -86,7 +86,11 @@ async def on_command_error(self, ctx: commands.Context, error) -> None: await ctx.send("A required argument is missing.") ERRORS_CHANNEL_ID = 1219407043186659479 - embed = discord.Embed(title="Error", description=f"```{error}```", color=discord.Color.red()) + if ctx.guild: + error_msg = f"Error in {ctx.guild.name} ({ctx.guild.id}) by {ctx.author} -> {ctx.command.qualified_name}" + else: + error_msg = f"Error in DMs by {ctx.author} -> {ctx.command.qualified_name}" + embed = discord.Embed(title=error_msg, description=f"```{error}```", color=discord.Color.red()) await self.get_channel(ERRORS_CHANNEL_ID).send(embed=embed) try: diff --git a/extensions/karma.py b/extensions/karma.py index 6c6af4f..acbec45 100644 --- a/extensions/karma.py +++ b/extensions/karma.py @@ -1,5 +1,6 @@ import logging import os +import io import re from datetime import datetime @@ -165,7 +166,7 @@ async def karma_donate(self, ctx: commands.Context, *args): """ if len(args) != 2: msg = f"Got {len(args)} arguments, expected 2." - raise commands.MissingRequiredArgument(msg) + raise NotEnoughArguments(msg) user = None amount = None @@ -238,14 +239,16 @@ def pred(m: discord.Member) -> bool: @karma_donate.error async def karma_donate_error(self, ctx: commands.Context, error): embed = discord.Embed(color=0xF66045) - if isinstance(error, commands.MissingRequiredArgument): - embed.description = "You didn't specify a user to donate to!" + print(type(error)) + if isinstance(error, NotEnoughArguments): + embed.description = "You didn't specify an `amount` or a `user` to donate to!" elif isinstance(error, commands.BadArgument): embed.description = f"Wrong command usage! Command usage is `{ctx.prefix}karma donate `" else: embed.description = f"An unknown error occured. Please contact <@{self.bot.owner_id}> for help." logger.error(f"An unknown error occured in karma_donate: {error}") await ctx.send(embed=embed) + error.is_handled = True @karma.group(name="emotes", aliases=["emote"], usage="emotes", invoke_without_command=True) async def karma_emotes(self, ctx: commands.Context): @@ -460,10 +463,10 @@ async def karma_stats_graph(self, ctx: commands.Context): fig = go.Figure(data=go.Bar(x=x, y=y)) fig.update_layout(title="Karma Graph", xaxis_title="Percentile of users", yaxis_title="Total karma") fig.update_layout(template="plotly_dark") - fig.write_image(filename) + image_bytes = fig.to_image(format="png") + image_file = io.BytesIO(image_bytes) - await ctx.send(file=discord.File(filename)) - os.remove(filename) + await ctx.send(file=discord.File(image_file, filename=f"{filename}.png")) @commands.hybrid_group(name="post", aliases=["po"], invoke_without_command=True) async def post(self, ctx: commands.Context): @@ -1098,6 +1101,10 @@ async def on_submit(self, interaction: discord.Interaction) -> None: await _update_kasino_msg(bot, kasino_id) +class NotEnoughArguments(commands.UserInputError): + pass + + async def setup(bot: core.Substiify): query = await bot.db.fetch("SELECT * FROM discord_channel WHERE upvote = True") upvote_channels = [channel["discord_channel_id"] for channel in query] or []