mirror of https://github.com/stijndcl/didier
Fix mypy & tests
parent
3debd18d82
commit
8227190a8d
|
@ -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:
|
async def get_random_dad_joke(session: AsyncSession) -> DadJoke:
|
||||||
"""Return a random database entry"""
|
"""Return a random database entry"""
|
||||||
statement = select(DadJoke).order_by(func.random())
|
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]
|
||||||
|
|
|
@ -20,8 +20,8 @@ class Fun(commands.Cog):
|
||||||
async def dad_joke(self, ctx: commands.Context):
|
async def dad_joke(self, ctx: commands.Context):
|
||||||
"""Get a random dad joke"""
|
"""Get a random dad joke"""
|
||||||
async with self.client.db_session as session:
|
async with self.client.db_session as session:
|
||||||
row = await get_random_dad_joke(session)
|
joke = await get_random_dad_joke(session)
|
||||||
return await ctx.reply(row[0].joke, mention_author=False)
|
return await ctx.reply(joke.joke, mention_author=False)
|
||||||
|
|
||||||
|
|
||||||
async def setup(client: Didier):
|
async def setup(client: Didier):
|
||||||
|
|
|
@ -27,7 +27,7 @@ class AddDadJoke(discord.ui.Modal, title="Add Dad Joke"):
|
||||||
@overrides
|
@overrides
|
||||||
async def on_submit(self, interaction: discord.Interaction):
|
async def on_submit(self, interaction: discord.Interaction):
|
||||||
async with self.client.db_session as session:
|
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)
|
await interaction.response.send_message(f"Successfully added joke #{joke.dad_joke_id}", ephemeral=True)
|
||||||
|
|
||||||
|
|
|
@ -39,5 +39,5 @@ env = [
|
||||||
"DB_PASSWORD = pytest",
|
"DB_PASSWORD = pytest",
|
||||||
"DB_HOST = localhost",
|
"DB_HOST = localhost",
|
||||||
"DB_PORT = 5433",
|
"DB_PORT = 5433",
|
||||||
"DISC_TOKEN = token"
|
"DISCORD_TOKEN = token"
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue