-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from hwsuk/feat/feedback-command
Add feedback slash command
- Loading branch information
Showing
15 changed files
with
378 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import json | ||
import typing | ||
import discord | ||
|
||
import harmony_services.db | ||
import harmony_ui.feedback | ||
|
||
from loguru import logger | ||
from discord import app_commands | ||
from discord.ext import commands | ||
|
||
|
||
with open("config.json", "r") as f: | ||
config = json.load(f) | ||
|
||
feedback_channel_id = int(config["feedback"]["feedback_channel_id"]) | ||
discord_guild_id = int(config["discord"]["guild_id"]) | ||
|
||
|
||
class Feedback(commands.Cog): | ||
def __init__(self, bot: commands.Bot): | ||
self.bot = bot | ||
|
||
self.feedback_channel = bot.get_guild(discord_guild_id).get_channel(feedback_channel_id) | ||
if not self.feedback_channel: | ||
logger.error(f"Feedback channel with ID {feedback_channel_id} doesn't exist.") | ||
raise RuntimeError() | ||
|
||
@app_commands.command( | ||
name='feedback', | ||
description='Create feedback items for the community to vote on.' | ||
) | ||
@app_commands.guild_only | ||
@app_commands.guilds(discord.Object(int(config["discord"]["guild_id"]))) | ||
async def feedback(self, interaction: discord.Interaction) -> typing.NoReturn: | ||
""" | ||
Method invoked when the user performs the feedback slash command. | ||
:param interaction: The interaction to use to respond to the user. | ||
:return: Nothing. | ||
""" | ||
await interaction.response.send_modal(harmony_ui.feedback.CreateFeedbackItemModal(self.feedback_channel)) | ||
|
||
@commands.Cog.listener() | ||
async def on_raw_message_delete(self, payload: discord.RawMessageDeleteEvent) -> typing.NoReturn: | ||
""" | ||
Delete feedback data when the message containing its voting view is deleted. | ||
:param payload: The data about which message was deleted. | ||
:return: Nothing. | ||
""" | ||
logger.info(f"Deleting feedback data because message with ID {payload.message_id} " | ||
f"was deleted from #{self.feedback_channel.name}") | ||
|
||
if payload.channel_id == self.feedback_channel.id: | ||
harmony_services.db.delete_feedback_data(payload.message_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import datetime | ||
import mongoengine | ||
|
||
|
||
class FeedbackVote(mongoengine.EmbeddedDocument): | ||
discord_username = mongoengine.StringField(required=True) | ||
vote_timestamp = mongoengine.DateTimeField(default=datetime.datetime.utcnow) | ||
vote_weight = mongoengine.IntField(required=True, max_value=1, min_value=-1) | ||
|
||
|
||
class FeedbackItem(mongoengine.Document): | ||
author_username = mongoengine.StringField(required=True) | ||
creation_timestamp = mongoengine.DateTimeField(default=datetime.datetime.utcnow) | ||
feedback_title = mongoengine.StringField(required=True, max_length=200) | ||
feedback_description = mongoengine.StringField(required=True, max_length=1500) | ||
discord_message_id = mongoengine.LongField(required=True, unique=True) | ||
votes = mongoengine.EmbeddedDocumentListField(FeedbackVote, default=[]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.