Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message improvements #321

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions koala/cogs/react_for_role/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Own modules
import koalabot
from koala.colours import KOALA_GREEN
from koala.utils import wait_for_message
from koala.utils import wait_for_message, is_int
from koala.db import insert_extension
from .db import ReactForRoleDBManager
from .log import logger
Expand Down Expand Up @@ -783,7 +783,12 @@ async def get_rfr_message_from_prompts(self, ctx: commands.Context) -> Tuple[dis
if not channel:
raise commands.CommandError("Invalid channel given.")
msg_id_raw = await self.prompt_for_input(ctx, "react for role message ID")
msg_id = None if (msg_id_raw == "") else int(msg_id_raw)
if (msg_id_raw == ""):
msg_id = None
elif not is_int(msg_id_raw):
msg_id = None
else:
msg_id = int(msg_id_raw)
if not msg_id:
raise commands.CommandError("Invalid Message ID given.")
msg = await channel.fetch_message(msg_id)
Expand Down
5 changes: 4 additions & 1 deletion koala/cogs/verification/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ async def verify(self, ctx, email):
session.add(NonVerifiedEmails(u_id=ctx.author.id, email=email, token=verification_code))
session.commit()

self.send_email(email, verification_code)
try:
self.send_email(email, verification_code)
except smtplib.SMTPRecipentsRefused:
raise Exception("KoalaBot was unable to send an email to the given address.")
await ctx.send("Please verify yourself using the command you have been emailed")

@commands.check(koalabot.is_dm_channel)
Expand Down
22 changes: 15 additions & 7 deletions koalabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@

def is_owner(ctx):
"""
A command used to check if the user of a command is the owner, or the testing bot
A command used to check if the user of a command is the owner, or the testing bot.
The command also allows Senior Devs of KoalaBot to use owner only commands (as given by Admin role in the dev portal)
e.g. @commands.check(koalabot.is_owner)
:param ctx: The context of the message
:return: True if owner or test, False otherwise
Expand Down Expand Up @@ -149,25 +150,32 @@ async def on_command_error(ctx, error: Exception):
else:
guild_id = ctx.guild.id

if error.__class__ in [commands.MissingRequiredArgument,
commands.CommandNotFound]:
if error.__class__ in [commands.MissingRequiredArgument]:
await ctx.send(embed=error_embed(error_type=str(type(error).__name__),
description=str(error)+"\nAn argument is missing from this command. "
"Use k!help <command> for more information.")) #TODO: Make <command> actually change to the command inputted
if error.__class__ in [commands.CommandNotFound]:
await ctx.send(embed=error_embed(description=error))
if error.__class__ in [commands.CheckFailure]:
await ctx.send(embed=error_embed(error_type=str(type(error).__name__),
description=str(error)+"\nPlease ensure you have administrator permissions, "
"and have enabled this extension."))
description=str(error)+"\nThe command could not be executed with the given "
"parameter."))
DatGuyChucky marked this conversation as resolved.
Show resolved Hide resolved
elif isinstance(error, commands.CommandOnCooldown):
await ctx.send(embed=error_embed(description=f"{ctx.author.mention}, this command is still on cooldown for "
f"{str(error.retry_after)}s."))
elif isinstance(error, commands.errors.ChannelNotFound):
await ctx.send(embed=error_embed(description=f"The channel ID provided is either invalid, or not in this server."))
elif isinstance(error, commands.errors.Forbidden):
await ctx.send(embed=error.embed(description=f"The bot lacks necessary guild permissions, re-add the bot to "
f"this server "
f"with the correct permissions from the README.md"))
DatGuyChucky marked this conversation as resolved.
Show resolved Hide resolved
elif isinstance(error, commands.CommandInvokeError):
logger.error("CommandInvokeError(%s), guild_id: %s, message: %s", error.original, guild_id, ctx.message, exc_info=error)
await ctx.send(embed=error_embed(description=error.original))
else:
logger.error(f"Unexpected Error in guild %s : %s", guild_id, error, exc_info=error)
await ctx.send(embed=error_embed(
description=f"An unexpected error occurred, please contact an administrator Timestamp: {time.time()}")) # FIXME: better timestamp
description=f"An unexpected error occurred, please contact an administrator Timestamp: {time.asctime(time.gmtime(time.time()))}"))
raise error


Expand All @@ -194,4 +202,4 @@ async def run_bot():

if __name__ == '__main__': # pragma: no cover
loop = asyncio.get_event_loop()
loop.run_until_complete(run_bot())
loop.run_until_complete(run_bot())