Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVEMENT] - add warning before submitting spoiler #140

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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", required=True, style=discord.InputTextStyle.long))
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 @@
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

Check warning on line 108 in src/cmds/core/other.py

View check run for this annotation

Codecov / codecov/patch

src/cmds/core/other.py#L107-L108

Added lines #L107 - L108 were not covered by tests

@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

Check warning on line 115 in src/cmds/core/other.py

View check run for this annotation

Codecov / codecov/patch

src/cmds/core/other.py#L113-L115

Added lines #L113 - L115 were not covered by tests

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

Check warning on line 119 in src/cmds/core/other.py

View check run for this annotation

Codecov / codecov/patch

src/cmds/core/other.py#L117-L119

Added lines #L117 - L119 were not covered by tests


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

Expand Down Expand Up @@ -116,10 +149,14 @@
)

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

Check warning on line 155 in src/cmds/core/other.py

View check run for this annotation

Codecov / codecov/patch

src/cmds/core/other.py#L154-L155

Added lines #L154 - L155 were not covered by tests
"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
Loading