Fix mypy & tests

pull/119/head
stijndcl 2022-07-16 00:19:05 +02:00
parent 3debd18d82
commit 8227190a8d
4 changed files with 9 additions and 5 deletions

View File

@ -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]

View File

@ -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):

View File

@ -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)

View File

@ -39,5 +39,5 @@ env = [
"DB_PASSWORD = pytest",
"DB_HOST = localhost",
"DB_PORT = 5433",
"DISC_TOKEN = token"
"DISCORD_TOKEN = token"
]