Skip to content

Commit

Permalink
Added warning before submitting a spoiler with ephermal message
Browse files Browse the repository at this point in the history
  • Loading branch information
janssensjelle committed Feb 11, 2025
1 parent 50a9853 commit a232dbb
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions src/cmds/core/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import discord
from discord import ApplicationContext, Interaction, Message, Option, slash_command
from discord.ext import commands
from discord.ui import InputText, Modal
from discord.ui import Button, InputText, Modal, View
from slack_sdk.webhook import WebhookClient

from src.bot import Bot
Expand Down Expand Up @@ -60,8 +60,22 @@ class SpoilerModal(Modal):
def __init__(self, *args, **kwargs) -> None:
"""Initialize the Spoiler Modal with input fields."""
super().__init__(*args, **kwargs)
self.add_item(InputText(label="Description", placeholder="Description", required=False, style=discord.InputTextStyle.long))
self.add_item(InputText(label="URL", placeholder="Enter URL. Submitting malicious or fake links will result in consequences.", required=True, style=discord.InputTextStyle.paragraph))
self.add_item(
InputText(
label="Description",
placeholder="Description",
required=False,
style=discord.InputTextStyle.long
)
)
self.add_item(
InputText(
label="URL",
placeholder="Enter URL. Submitting malicious or fake links will result in consequences.",
required=True,
style=discord.InputTextStyle.paragraph
)
)

async def callback(self, interaction: discord.Interaction) -> None:
"""Handle the modal submission by sending the spoiler report to JIRA."""
Expand All @@ -86,6 +100,25 @@ async def callback(self, interaction: discord.Interaction) -> None:
await webhook.webhook_call(webhook_url, data)


class SpoilerConfirmationView(View):
"""A confirmation view before opening the SpoilerModal."""

def __init__(self, user: discord.Member):
super().__init__(timeout=60)
self.user = user

@discord.ui.button(label="Proceed", style=discord.ButtonStyle.danger)
async def proceed(self, button: Button, interaction: discord.Interaction) -> None:
"""Opens the spoiler modal after confirmation."""
if interaction.user.id != self.user.id:
await interaction.response.send_message("This confirmation is not for you.", ephemeral=True)
return

modal = SpoilerModal(title="Report Spoiler")
await interaction.response.send_modal(modal)
self.stop()


class OtherCog(commands.Cog):
"""Other commands related to the bot."""

Expand Down Expand Up @@ -116,10 +149,14 @@ async def support(
)

@slash_command(guild_ids=settings.guild_ids, description="Add a URL which contains a spoiler.")
async def spoiler(self, ctx: ApplicationContext) -> Interaction:
"""Report a URL that contains a spoiler."""
modal = SpoilerModal(title="Report Spoiler")
return await ctx.send_modal(modal)
async def spoiler(self, ctx: ApplicationContext) -> None:
"""Ask for confirmation before reporting a spoiler."""
view = SpoilerConfirmationView(ctx.user)
await ctx.respond(
"Thank you for taking the time to report a spoiler. \n ⚠️ **Warning:** Submitting malicious or fake links will result in consequences.",
view=view,
ephemeral=True
)

@slash_command(guild_ids=settings.guild_ids, description="Provide feedback to HTB.")
@commands.cooldown(1, 60, commands.BucketType.user)
Expand Down

0 comments on commit a232dbb

Please sign in to comment.