diff --git a/.test.env b/.test.env index fe783be..b4ab351 100644 --- a/.test.env +++ b/.test.env @@ -85,3 +85,7 @@ CURRENT_SEASON_ID=1 #V4 Bearer Token HTB_API_KEY=CHANGE_ME + +#Feedback Webhook + +FEEDBACK_WEBHOOK="https://hook.slack.com/sdfsdfsf" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 793d5b9..3e8f255 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ alembic = "^1.10.3" pymysql = "^1.0.3" prometheus-client = "^0.16.0" toml = "^0.10.2" +slack-sdk = "^3.27.1" [tool.poetry.group.dev.dependencies] colorlog = "^6.5.0" diff --git a/src/cmds/core/other.py b/src/cmds/core/other.py index e40408f..e681ff7 100644 --- a/src/cmds/core/other.py +++ b/src/cmds/core/other.py @@ -1,14 +1,44 @@ import logging -from discord import ApplicationContext, Embed, Interaction, Message, WebhookMessage, slash_command +from discord import ApplicationContext, Embed, Interaction, Message, WebhookMessage, slash_command, InputTextStyle +from discord.ui import InputText, Modal from discord.ext import commands from src.bot import Bot from src.core import settings +from slack_sdk.webhook import WebhookClient + logger = logging.getLogger(__name__) +class FeedbackModal(Modal): + def __init__(self, *args, **kwargs) -> None: + 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): + + await interaction.response.send_message("Thank you, your feedback has been recorded.") + + webhook = WebhookClient(settings.slack_webhook) + + response = webhook.send( + text=f"{self.children[0].value} - {self.children[1].value}", + blocks=[ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": f"{self.children[0].value}:\n {self.children[0].value}" + } + } + ] + ) + assert response.status_code == 200 + assert response.body == "ok"` + class OtherCog(commands.Cog): """Ban related commands.""" @@ -46,7 +76,15 @@ async def spoiler(self, ctx: ApplicationContext, url: str) -> Interaction | Webh 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!") + @commands.cooldown(1, 60, commands.BucketType.user) + async def feedback(self, ctx: ApplicationContext) -> Message: + """ Provide Feedback to HTB """ + modal = FeedbackModal(title="Feedback") # Send the Modal defined above in Feedback Modal, which handles the callback + await ctx.send_modal(modal) + def setup(bot: Bot) -> None: """Load the `ChannelManageCog` cog.""" diff --git a/src/core/config.py b/src/core/config.py index 8c0bb26..d926fa2 100644 --- a/src/core/config.py +++ b/src/core/config.py @@ -189,6 +189,8 @@ class Global(BaseSettings): WEBHOOK_PORT: int = 1337 WEBHOOK_TOKEN: str = "" + SLACK_WEBHOOK: str = "" + ROOT: Path = None VERSION: str | None = None