Skip to content

Commit

Permalink
SNIPPET: Add basic snippet-releated views.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamievlin committed Jul 13, 2024
1 parent ae250ef commit d633fbc
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions bot/libs/snippets/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from libs.utils import RoboView, GuildContext
import discord.ui

from rodhaj import Rodhaj


class SnippetCreationModal(discord.ui.Modal, title="Editing Snippet"):
content = discord.ui.TextInput(
label="Snippet message",
placeholder="Call me Ishmael. Some years ago—never mind "
+ "how long precisely...",
style=discord.TextStyle.paragraph,
)

def __init__(self, bot: Rodhaj, context: GuildContext, name: str):
super().__init__(timeout=12 * 3600)
self._bot = bot
self._ctx = context
self._snippet_name = name
self.title = f"Creating Snippet {name}"

async def on_submit(self, interaction: discord.Interaction):
await interaction.response.defer()
self._bot.dispatch(
"snippet_create",
self._ctx.guild,
self._ctx.author,
self._snippet_name,
self.content.value,
self._ctx,
)
self.stop()


class SnippetPreCreationConfirmationView(discord.ui.View):
def __init__(self, bot: Rodhaj, ctx: GuildContext, snippet_name: str, timeout=15):
super().__init__(timeout=timeout)
self._bot = bot
self._ctx = ctx
self._snippet_name = snippet_name

@discord.ui.button(label="Create Snippet", style=discord.ButtonStyle.green)
async def create_snippet(
self, interaction: discord.Interaction, button: discord.ui.Button
):
if interaction.user.id != self._ctx.author.id:
return
button.disabled = True
modal = SnippetCreationModal(self._bot, self._ctx, self._snippet_name)
await interaction.response.send_modal(modal)
await interaction.edit_original_response(
content="Creating Snippet...", view=None
)
await modal.wait()
await interaction.delete_original_response()
self.stop()

async def on_timeout(self):
self.clear_items()
self.stop()


class SnippetInfoView(RoboView):
pass

0 comments on commit d633fbc

Please sign in to comment.