Skip to content

Commit

Permalink
Improve error messages in error channel, improve error message for ka…
Browse files Browse the repository at this point in the history
…rma donate
  • Loading branch information
jackra1n committed Mar 19, 2024
1 parent 68b735a commit 563bcd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 5 additions & 1 deletion core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 12 additions & 6 deletions extensions/karma.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import io
import re
from datetime import datetime

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -238,8 +239,9 @@ 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 a `amount` or `user` to donate to!"
elif isinstance(error, commands.BadArgument):
embed.description = f"Wrong command usage! Command usage is `{ctx.prefix}karma donate <user> <amount>`"
else:
Expand Down Expand Up @@ -460,10 +462,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):
Expand Down Expand Up @@ -1098,6 +1100,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 []
Expand Down

0 comments on commit 563bcd4

Please sign in to comment.