diff --git a/.test.env b/.test.env index def9d16..fa57de7 100644 --- a/.test.env +++ b/.test.env @@ -90,5 +90,6 @@ HTB_API_KEY=CHANGE_ME #Feedback Webhook SLACK_FEEDBACK_WEBHOOK="https://hook.slack.com/sdfsdfsf" -#Feedback Webhook +# Webhook JIRA_WEBHOOK="https://automation.atlassian.com/sdfsdfsf" +JIRA_WEBHOOK_SECRET=xxxxxxxxxxxxx \ No newline at end of file diff --git a/src/cmds/core/other.py b/src/cmds/core/other.py index 2dcd280..346f14e 100644 --- a/src/cmds/core/other.py +++ b/src/cmds/core/other.py @@ -97,7 +97,11 @@ async def callback(self, interaction: discord.Interaction) -> None: "type": "spoiler" } - await webhook.webhook_call(webhook_url, data) + headers = { + "X-Automation-Webhook-Token": settings.JIRA_WEBHOOK_SECRET, + } + + await webhook.webhook_call(webhook_url, data, headers) class SpoilerConfirmationView(View): @@ -133,7 +137,7 @@ async def no_hints(self, ctx: ApplicationContext) -> Message: ) @slash_command(guild_ids=settings.guild_ids, - description="A simple reply proving a link to the support desk article on how to get support") + description="A simple reply providing 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, @@ -153,7 +157,8 @@ 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.", + "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 ) @@ -180,8 +185,11 @@ async def cheater( "description": description, "type": "cheater" } + headers = { + "X-Automation-Webhook-Token": settings.JIRA_WEBHOOK_SECRET, + } - await webhook.webhook_call(settings.JIRA_WEBHOOK, data) + await webhook.webhook_call(settings.JIRA_WEBHOOK, data, headers) await ctx.respond("Thank you for your report.", ephemeral=True) diff --git a/src/core/config.py b/src/core/config.py index 6b3025e..f1e8aef 100644 --- a/src/core/config.py +++ b/src/core/config.py @@ -189,6 +189,7 @@ class Global(BaseSettings): SLACK_FEEDBACK_WEBHOOK: str = "" JIRA_WEBHOOK: str = "" + JIRA_WEBHOOK_SECRET: str = "" ROOT: Path = None diff --git a/src/helpers/webhook.py b/src/helpers/webhook.py index 04d0a16..619a92d 100644 --- a/src/helpers/webhook.py +++ b/src/helpers/webhook.py @@ -6,11 +6,11 @@ logger = logging.getLogger(__name__) -async def webhook_call(url: str, data: dict) -> None: - """Send a POST request to the webhook URL with the given data.""" +async def webhook_call(url: str, data: dict, headers: dict = None) -> None: + """Send a POST request to the webhook URL with the given data and optional headers.""" async with aiohttp.ClientSession() as session: try: - async with session.post(url, json=data) as response: + async with session.post(url, json=data, headers=headers) as response: if response.status != 200: logger.error(f"Failed to send to webhook: {response.status} - {await response.text()}") except Exception as e: diff --git a/tests/src/cmds/core/test_other.py b/tests/src/cmds/core/test_other.py index aeab30b..4593c3a 100644 --- a/tests/src/cmds/core/test_other.py +++ b/tests/src/cmds/core/test_other.py @@ -144,7 +144,8 @@ async def test_spoiler_modal_callback_with_url(self): "url": "http://example.com/spoiler", "desc": "Test description", "type": "spoiler" - } + }, + settings.JIRA_WEBHOOK_SECRET ) @pytest.mark.asyncio @@ -168,7 +169,8 @@ async def test_cheater_command(self, bot, ctx): "cheater": test_username, "description": test_description, "type": "cheater" - } + }, + settings.JIRA_WEBHOOK_SECRET ) # Verify the response was sent