Skip to content

Commit

Permalink
Merge pull request #119 from hackthebox/revert-112-main
Browse files Browse the repository at this point in the history
Revert "Send Leaks report to Jira & Fix Lint"
  • Loading branch information
dimoschi authored Nov 21, 2024
2 parents d9f6d5c + 96ba3a7 commit 5e3e326
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 71 deletions.
6 changes: 1 addition & 5 deletions .test.env
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,4 @@ HTB_API_KEY=CHANGE_ME

#Feedback Webhook

SLACK_FEEDBACK_WEBHOOK="https://hook.slack.com/sdfsdfsf"

#Spoilers Webhook

JIRA_SPOILER_WEBHOOK="https://automation.atlassian.com/sdfsdfsf"
SLACK_WEBHOOK="https://hook.slack.com/sdfsdfsf"
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 47 additions & 63 deletions src/cmds/core/other.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import logging

import aiohttp
import discord
from discord import ApplicationContext, Interaction, Message, slash_command
from discord import ApplicationContext, Embed, Interaction, Message, WebhookMessage, slash_command
from discord.ext import commands
from discord.ui import InputText, Modal
from slack_sdk.webhook import WebhookClient
Expand All @@ -14,29 +13,28 @@


class FeedbackModal(Modal):
"""Modal for collecting user feedback."""

def __init__(self, *args, **kwargs) -> None:
"""Initialize the Feedback Modal with input fields."""
super().__init__(*args, **kwargs)

self.add_item(InputText(label="Title"))
self.add_item(InputText(label="Feedback", style=discord.InputTextStyle.long))

async def callback(self, interaction: discord.Interaction) -> None:
"""Handle the modal submission by sending feedback to Slack."""
async def callback(self, interaction: discord.Interaction):

await interaction.response.send_message("Thank you, your feedback has been recorded.", ephemeral=True)

webhook = WebhookClient(settings.SLACK_FEEDBACK_WEBHOOK)

if interaction.user:
webhook = WebhookClient(settings.SLACK_WEBHOOK) # Establish Slack Webhook
if interaction.user: # Protects against some weird edge-cases
title = f"{self.children[0].value} - {interaction.user.name}"
else:
title = self.children[0].value

title = f"{self.children[0].value}"
message_body = self.children[1].value
title = title.replace("@", "[at]").replace("<", "[bracket]")
message_body = message_body.replace("@", "[at]").replace("<", "[bracket]")

# Slack has no way to disallow @(@everyone calls), so we strip it out and replace it with a safe version
title = title.replace("@", "[at]").replace("<", "[bracket]")
message_body = message_body.replace("@", "[at]").replace("<", "[bracket]")

response = webhook.send(
text=f"{title} - {message_body}",
blocks=[
Expand All @@ -53,70 +51,56 @@ async def callback(self, interaction: discord.Interaction) -> None:
assert response.body == "ok"


class SpoilerModal(Modal):
"""Modal for reporting a spoiler."""

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))

async def callback(self, interaction: discord.Interaction) -> None:
"""Handle the modal submission by sending the spoiler report to JIRA."""
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_SPOILER_WEBHOOK

payload = {
"user": user_name,
"url": url,
}

async with aiohttp.ClientSession() as session:
try:
async with session.post(webhook_url, json=payload) as response:
if response.status != 200:
logger.error(f"Failed to send to JIRA: {response.status} - {await response.text()}")
except Exception as e:
logger.error(f"Error sending to JIRA: {e}")


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

def __init__(self, bot: Bot):
self.bot = bot

@slash_command(guild_ids=settings.guild_ids, description="A simple reply stating hints are not allowed.")
async def no_hints(self, ctx: ApplicationContext) -> Message:
"""Reply stating that hints are not allowed."""
async def no_hints(
self, ctx: ApplicationContext
) -> Message:
"""A simple reply stating hints are not allowed."""
return await ctx.respond(
"No hints are allowed for the duration of the event. Once the event is over, feel free to share solutions."
"No hints are allowed for the duration the event is going on. This is a competitive event with prizes. "
"Once the event is over you are more then welcome to share solutions/write-ups/etc and try them in the "
"After Party event."
)

@slash_command(guild_ids=settings.guild_ids, description="Link to the support desk article.")
@slash_command(guild_ids=settings.guild_ids,
description="A simple reply proving a link to the support desk article on how to get support")
@commands.cooldown(1, 60, commands.BucketType.user)
async def support(self, ctx: ApplicationContext) -> Message:
"""Provide a link to the support desk article."""
return await ctx.respond("https://help.hackthebox.com/en/articles/5986762-contacting-htb-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 support(
self, ctx: ApplicationContext
) -> Message:
"""A simple reply proving a link to the support desk article on how to get support"""
return await ctx.respond(
"https://help.hackthebox.com/en/articles/5986762-contacting-htb-support"
)

@slash_command(guild_ids=settings.guild_ids, description="Add the URL which has spoiler link.")
async def spoiler(self, ctx: ApplicationContext, url: str) -> Interaction | WebhookMessage:
"""Add the URL which has spoiler link."""
if len(url) == 0:
return await ctx.respond("Please provide the spoiler URL.")

embed = Embed(title="Spoiler Report", color=0xB98700)
embed.add_field(name=f"{ctx.user} has submitted a spoiler.", value=f"URL: <{url}>", inline=False)

channel = self.bot.get_channel(settings.channels.SPOILER)
await channel.send(embed=embed)
return await ctx.respond("Thanks for the reporting the spoiler.", ephemeral=True, delete_after=15)

@slash_command(guild_ids=settings.guild_ids, description="Provide feedback to HTB.")
@slash_command(guild_ids=settings.guild_ids, description="Provide feedback to HTB!")
@commands.cooldown(1, 60, commands.BucketType.user)
async def feedback(self, ctx: ApplicationContext) -> Interaction:
"""Provide feedback to HTB."""
""" Provide Feedback to HTB """
# Send the Modal defined above in Feedback Modal, which handles the callback
modal = FeedbackModal(title="Feedback")
return await ctx.send_modal(modal)


def setup(bot: Bot) -> None:
"""Load the OtherCog cog."""
"""Load the `ChannelManageCog` cog."""
bot.add_cog(OtherCog(bot))
3 changes: 1 addition & 2 deletions src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ class Global(BaseSettings):
WEBHOOK_PORT: int = 1337
WEBHOOK_TOKEN: str = ""

SLACK_FEEDBACK_WEBHOOK: str = ""
JIRA_SPOILER_WEBHOOK: str = ""
SLACK_WEBHOOK: str = ""

ROOT: Path = None

Expand Down

0 comments on commit 5e3e326

Please sign in to comment.