diff --git a/database/crud/dad_jokes.py b/database/crud/dad_jokes.py index a7f1ac9..30aa010 100644 --- a/database/crud/dad_jokes.py +++ b/database/crud/dad_jokes.py @@ -35,4 +35,8 @@ async def edit_dad_joke(session: AsyncSession, joke_id: int, new_joke: str) -> D async def get_random_dad_joke(session: AsyncSession) -> DadJoke: """Return a random database entry""" statement = select(DadJoke).order_by(func.random()) - return (await session.execute(statement)).first() + row = (await session.execute(statement)).first() + if row is None: + raise NoResultFoundException + + return row[0] diff --git a/didier/cogs/fun.py b/didier/cogs/fun.py index 7aa7da7..ddc119b 100644 --- a/didier/cogs/fun.py +++ b/didier/cogs/fun.py @@ -20,8 +20,8 @@ class Fun(commands.Cog): async def dad_joke(self, ctx: commands.Context): """Get a random dad joke""" async with self.client.db_session as session: - row = await get_random_dad_joke(session) - return await ctx.reply(row[0].joke, mention_author=False) + joke = await get_random_dad_joke(session) + return await ctx.reply(joke.joke, mention_author=False) async def setup(client: Didier): diff --git a/didier/views/modals/dad_jokes.py b/didier/views/modals/dad_jokes.py index 699a15f..9632197 100644 --- a/didier/views/modals/dad_jokes.py +++ b/didier/views/modals/dad_jokes.py @@ -27,7 +27,7 @@ class AddDadJoke(discord.ui.Modal, title="Add Dad Joke"): @overrides async def on_submit(self, interaction: discord.Interaction): async with self.client.db_session as session: - joke = await add_dad_joke(session, self.name.value) + joke = await add_dad_joke(session, str(self.name.value)) await interaction.response.send_message(f"Successfully added joke #{joke.dad_joke_id}", ephemeral=True) diff --git a/pyproject.toml b/pyproject.toml index 7d77992..75d3054 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,5 +39,5 @@ env = [ "DB_PASSWORD = pytest", "DB_HOST = localhost", "DB_PORT = 5433", - "DISC_TOKEN = token" + "DISCORD_TOKEN = token" ]