Skip to content

Commit

Permalink
Merged the code from hackthebox#134 to prevent merge conflics
Browse files Browse the repository at this point in the history
  • Loading branch information
janssensjelle committed Jan 19, 2025
1 parent e5f78ea commit 3f228f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/cmds/core/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,26 @@ 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="URL", placeholder="Enter the spoiler URL", 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", required=True, style=discord.InputTextStyle.long))

async def callback(self, interaction: discord.Interaction) -> None:
"""Handle the modal submission by sending the spoiler report to JIRA."""
url = self.children[0].value.strip() # Trim any whitespace
desc = self.children[0].value.strip() # Trim any whitespace
url = self.children[1].value.strip() # Trim any whitespace

if not url: # Check if the URL is empty
await interaction.response.send_message("Please provide the spoiler URL.", ephemeral=True)
return
await interaction.response.send_message("Thank you, the spoiler has been reported.", ephemeral=True)

user_name = interaction.user.display_name
url = self.children[0].value

webhook_url = settings.JIRA_WEBHOOK

data = {
"user": user_name,
"url": url,
"desc": desc,
"type": "spoiler"
}

Expand Down
17 changes: 3 additions & 14 deletions tests/src/cmds/core/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ async def test_spoiler_modal_callback_with_url(self):
modal = SpoilerModal(title="Report Spoiler")
interaction = AsyncMock()
interaction.user.display_name = "TestUser"
modal.children[0].value = "http://example.com/spoiler"
modal.children[0].value = "Test description"
modal.children[1].value = "http://example.com/spoiler"

with patch('src.helpers.webhook.webhook_call', new_callable=AsyncMock) as mock_webhook:
await modal.callback(interaction)
Expand All @@ -141,23 +142,11 @@ async def test_spoiler_modal_callback_with_url(self):
{
"user": "TestUser",
"url": "http://example.com/spoiler",
"desc": "Test description",
"type": "spoiler"
}
)

@pytest.mark.asyncio
async def test_spoiler_modal_callback_without_url(self):
"""Test the spoiler modal callback without a URL."""
modal = SpoilerModal(title="Report Spoiler")
interaction = AsyncMock()
interaction.user.display_name = "TestUser"
modal.children[0].value = ""

await modal.callback(interaction)
interaction.response.send_message.assert_called_once_with(
"Please provide the spoiler URL.", ephemeral=True
)

@pytest.mark.asyncio
async def test_cheater_command(self, bot, ctx):
"""Test the cheater command with valid inputs."""
Expand Down

0 comments on commit 3f228f9

Please sign in to comment.