Skip to content

Commit

Permalink
More descriptive skullboard error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
CrageJ committed Aug 17, 2024
1 parent 4fc4bb8 commit 8609153
Showing 1 changed file with 28 additions and 38 deletions.
66 changes: 28 additions & 38 deletions src/commands/skullboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,7 @@ async def rank(self, interaction: Interaction):
try:
rankings = await self.db.get_user_rankings()
if not rankings:
await interaction.response.send_message(
"Database error or empty user rankings - check the logs.",
ephemeral=True,
)
return
raise Exception("Database Error")

# Warning: description in embed cannot be longer than 2048 characters
msg = ["### Top Users of All-Time:\n"]
Expand All @@ -238,21 +234,18 @@ async def rank(self, interaction: Interaction):
)

except Exception as e:
logging.exception("Rank")
logging.exception(f"User {interaction.message.author.name} called Rank()")
await interaction.response.send_message(
f"An error occurred: {str(e)}", ephemeral=True
f"Error:\n Either no data was available for this command, or a serious error occurred.\n{str(e)}",
ephemeral=True,
)

@app_commands.command(name="hof", description="Get top posts (all-time)")
async def hof(self, interaction: Interaction):
try:
hof_entries = await self.db.get_HOF()
if not hof_entries:
await interaction.response.send_message(
"Database error or empty Hall of Fame - check the logs.",
ephemeral=True,
)
return
raise Exception("Database Error")

# Warning: description in embed cannot be longer than 2048 characters
msg = ["### Top Posts of All-Time:"]
Expand All @@ -275,9 +268,10 @@ async def hof(self, interaction: Interaction):
)

except Exception as e:
logging.exception("Hof")
logging.exception(f"User {interaction.message.author.name} called Hof()")
await interaction.response.send_message(
f"An error occurred: {str(e)}", ephemeral=True
f"Error:\n Either no data was available for this command, or a serious error occurred.\n{str(e)}",
ephemeral=True,
)

@app_commands.command(name="week", description="Get top posts (this week)")
Expand All @@ -290,11 +284,7 @@ async def week(self, interaction: Interaction):
if frequency > 0
]
if not hof_entries:
await interaction.response.send_message(
"Database error or no posts saved - check the logs.",
ephemeral=True,
)
return
raise Exception("Database Error")

# Warning: description in embed cannot be longer than 2048 characters
msg = ["### Top Posts This Week:"]
Expand All @@ -317,9 +307,10 @@ async def week(self, interaction: Interaction):
)

except Exception as e:
logging.exception("Week")
logging.exception(f"User {interaction.message.author.name} called Week()")
await interaction.response.send_message(
f"An error occurred: {str(e)}", ephemeral=True
f"Error:\n Either no data was available for this command, or a serious error occurred.\n{str(e)}",
ephemeral=True,
)

@app_commands.command(name="stats", description="Get skullboard stats")
Expand Down Expand Up @@ -359,11 +350,8 @@ async def stats(
] # only including post/counts for more than 0 reactions and 0 posts

if not data:
await interaction.response.send_message(
"Database error or no posts saved - check the logs.",
ephemeral=True,
)
return
raise Exception("Database Error")

title += "Post Distribution"

# Collecting stats
Expand Down Expand Up @@ -403,26 +391,25 @@ async def stats(
)

except Exception as e:
logging.exception("Stats")
logging.exception(
f"User {interaction.message.author.name} called Stats(timeframe={timeframe.value})"
)
await interaction.response.send_message(
f"An error occurred: {str(e)}", ephemeral=True
f"Error:\n Either no data was available for this command, or a serious error occurred.\n{str(e)}",
ephemeral=True,
)

@app_commands.command(name="user", description="Get user stats")
async def user(self, interaction: Interaction, user: Member):
async def user(self, interaction: Interaction, member: Member):
try:
user_id = user.id
user_name = user.name
user_id = member.id
user_name = member.name

data = await self.db.get_user_rankings(999999) # get all
data = [(id, freq) for id, freq in data if freq > 0]

if not data:
await interaction.response.send_message(
"Database error or no posts saved - check the logs.",
ephemeral=True,
)
return
raise Exception("Database Error")

user = [(id, freq) for id, freq in data if id == user_id]
if not user:
Expand Down Expand Up @@ -470,9 +457,12 @@ async def user(self, interaction: Interaction, user: Member):
)

except Exception as e:
logging.exception("User")
logging.exception(
f"User {interaction.message.author.name} called user(member={member.name})"
)
await interaction.response.send_message(
f"An error occurred: {str(e)}", ephemeral=True
f"Error:\n Either no data was available for this command, or a serious error occurred.\n{str(e)}",
ephemeral=True,
)


Expand Down

0 comments on commit 8609153

Please sign in to comment.