pull/125/head
stijndcl 2022-08-10 01:12:28 +02:00
parent a614e9a9f1
commit 28cf094ea3
1 changed files with 8 additions and 2 deletions

View File

@ -12,8 +12,8 @@ __all__ = ["AddLink"]
class AddLink(discord.ui.Modal, title="Add Link"): class AddLink(discord.ui.Modal, title="Add Link"):
"""Modal to add a new link""" """Modal to add a new link"""
name = discord.ui.TextInput(label="Name", style=discord.TextStyle.short, placeholder="Source") name: discord.ui.TextInput = discord.ui.TextInput(label="Name", style=discord.TextStyle.short, placeholder="Source")
url = discord.ui.TextInput( url: discord.ui.TextInput = discord.ui.TextInput(
label="URL", style=discord.TextStyle.short, placeholder="https://github.com/stijndcl/didier" label="URL", style=discord.TextStyle.short, placeholder="https://github.com/stijndcl/didier"
) )
@ -25,6 +25,12 @@ class AddLink(discord.ui.Modal, title="Add Link"):
@overrides @overrides
async def on_submit(self, interaction: discord.Interaction): async def on_submit(self, interaction: discord.Interaction):
if self.name.value is None:
return await interaction.response.send_message("Required field `Name` cannot be empty.", ephemeral=True)
if self.url.value is None:
return await interaction.response.send_message("Required field `URL` cannot be empty.", ephemeral=True)
async with self.client.postgres_session as session: async with self.client.postgres_session as session:
await add_link(session, self.name.value, self.url.value) await add_link(session, self.name.value, self.url.value)
await self.client.database_caches.links.invalidate(session) await self.client.database_caches.links.invalidate(session)