Skip to content

Commit

Permalink
Merge pull request #86 from 0xEmma/main
Browse files Browse the repository at this point in the history
Add feedback command
  • Loading branch information
dimoschi authored Apr 2, 2024
2 parents b423e13 + 335728e commit e5f4b90
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .test.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
40 changes: 39 additions & 1 deletion src/cmds/core/other.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand Down Expand Up @@ -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."""
Expand Down
2 changes: 2 additions & 0 deletions src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class Global(BaseSettings):
WEBHOOK_PORT: int = 1337
WEBHOOK_TOKEN: str = ""

SLACK_WEBHOOK: str = ""

ROOT: Path = None

VERSION: str | None = None
Expand Down

0 comments on commit e5f4b90

Please sign in to comment.