diff --git a/koala/cogs/react_for_role/cog.py b/koala/cogs/react_for_role/cog.py index 2d0f797e..d20db794 100644 --- a/koala/cogs/react_for_role/cog.py +++ b/koala/cogs/react_for_role/cog.py @@ -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 @@ -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) diff --git a/koala/cogs/verification/cog.py b/koala/cogs/verification/cog.py index ae66fa55..c1c9387c 100644 --- a/koala/cogs/verification/cog.py +++ b/koala/cogs/verification/cog.py @@ -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) diff --git a/koala/env.py b/koala/env.py index 3dd612f7..183b2244 100644 --- a/koala/env.py +++ b/koala/env.py @@ -1,22 +1,22 @@ -import os -from dotenv import load_dotenv - -load_dotenv() - -BOT_TOKEN = os.environ['DISCORD_TOKEN'] -BOT_OWNER_ENV = os.environ.get('BOT_OWNER') -BOT_OWNER_STR = BOT_OWNER_ENV.split(',') -BOT_OWNER = [int(item) for item in BOT_OWNER_STR] - -API_PORT = os.environ.get("API_PORT", 8080) - -DB_KEY = os.environ.get('SQLITE_KEY', "2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99") -ENCRYPTED_DB = (not os.name == 'nt') and eval(os.environ.get('ENCRYPTED', "True")) - -CONFIG_PATH = os.environ.get("CONFIG_PATH") -if not CONFIG_PATH: - CONFIG_PATH = "/config" - if os.name == 'nt': - CONFIG_PATH = '.'+CONFIG_PATH - -LOGGING_FILE = eval(os.environ.get("LOGGING_FILE", "True")) \ No newline at end of file +import os +from dotenv import load_dotenv + +load_dotenv() + +BOT_TOKEN = os.environ['DISCORD_TOKEN'] +BOT_OWNER_ENV = os.environ.get('BOT_OWNER') +BOT_OWNER_STR = BOT_OWNER_ENV.split(',') +BOT_OWNER = [int(item) for item in BOT_OWNER_STR] + +API_PORT = os.environ.get("API_PORT", 8080) + +DB_KEY = os.environ.get('SQLITE_KEY', "2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99") +ENCRYPTED_DB = (not os.name == 'nt') and eval(os.environ.get('ENCRYPTED', "True")) + +CONFIG_PATH = os.environ.get("CONFIG_PATH") +if not CONFIG_PATH: + CONFIG_PATH = "/config" + if os.name == 'nt': + CONFIG_PATH = '.'+CONFIG_PATH + +LOGGING_FILE = eval(os.environ.get("LOGGING_FILE", "True")) diff --git a/tests/test_koalabot.py b/tests/test_koalabot.py index bb92a1cc..9953f0db 100644 --- a/tests/test_koalabot.py +++ b/tests/test_koalabot.py @@ -97,6 +97,10 @@ def test_not_admin_is_admin(test_ctx): assert not koalabot.is_admin(test_ctx) koalabot.is_dpytest = True +@pytest.mark.asyncio +async def test_command_not_found(): + with pytest.raises(discord.ext.commands.errors.CommandNotFound): + await dpytest.message(koalabot.COMMAND_PREFIX + 'fakecommand') @mock.patch("koalabot.COGS_PACKAGE", "tests.tests_utils.fake_load_all_cogs") @mock.patch("koalabot.ENABLED_COGS", ['greetings_cog'])