From bff435d51ee8138ae6f34909a94189fc8d122447 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 18 Jul 2023 11:43:50 +0200 Subject: [PATCH] Added bug report #293_complaints --- kdb-bot/src/bot/translation/de.json | 6 +++ kdb-bot/src/modules/base/base_module.py | 6 ++- .../modules/base/command/complaint_command.py | 25 ---------- .../src/modules/base/command/submit_group.py | 43 ++++++++++++++++ .../src/modules/base/forms/bug_report_form.py | 50 +++++++++++++++++++ 5 files changed, 103 insertions(+), 27 deletions(-) delete mode 100644 kdb-bot/src/modules/base/command/complaint_command.py create mode 100644 kdb-bot/src/modules/base/command/submit_group.py create mode 100644 kdb-bot/src/modules/base/forms/bug_report_form.py diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index 61f143e5..c4939ad7 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -157,6 +157,12 @@ "message": "{} hat eine Beschwerde eingereicht:\n{}", "response": "Danke für deine Beschwerde" }, + "bug": { + "title": "Bug melden", + "label": "Bug", + "message": "{} meldet einen Bug:\n{}", + "response": "Danke für dein Feedback :D" + }, "afk_command_channel_missing_message": "Zu unfähig einem Sprachkanal beizutreten?", "afk_command_move_message": "Ich verschiebe dich ja schon... (◔_◔)", "game_server": { diff --git a/kdb-bot/src/modules/base/base_module.py b/kdb-bot/src/modules/base/base_module.py index 95604372..aad5292d 100644 --- a/kdb-bot/src/modules/base/base_module.py +++ b/kdb-bot/src/modules/base/base_module.py @@ -8,7 +8,6 @@ from bot_core.abc.module_abc import ModuleABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from modules.base.abc.base_helper_abc import BaseHelperABC from modules.base.command.afk_command import AFKCommand -from modules.base.command.complaint_command import ComplaintCommand from modules.base.command.game_server_group import GameServerGroup from modules.base.command.help_command import HelpCommand from modules.base.command.info_command import InfoCommand @@ -17,6 +16,7 @@ from modules.base.command.ping_command import PingCommand from modules.base.command.presence_command import PresenceCommand from modules.base.command.purge_command import PurgeCommand from modules.base.command.register_group import RegisterGroup +from modules.base.command.submit_group import SubmitGroup from modules.base.command.unregister_group import UnregisterGroup from modules.base.command.user_group import UserGroup from modules.base.events.base_on_command_error_event import BaseOnCommandErrorEvent @@ -37,6 +37,7 @@ from modules.base.events.base_on_voice_state_update_event_help_channel import ( from modules.base.events.base_on_voice_state_update_event_scheduled_event_bonus import ( BaseOnVoiceStateUpdateEventScheduledEventBonus, ) +from modules.base.forms.bug_report_form import BugReportForm from modules.base.forms.complaint_form import ComplaintForm from modules.base.helper.base_reaction_handler import BaseReactionHandler from modules.base.service.base_helper_service import BaseHelperService @@ -58,11 +59,12 @@ class BaseModule(ModuleABC): services.add_transient(UserWarningsService) # forms + services.add_singleton(BugReportForm) services.add_singleton(ComplaintForm) # commands self._dc.add_command(AFKCommand) - self._dc.add_command(ComplaintCommand) + self._dc.add_command(SubmitGroup) self._dc.add_command(HelpCommand) self._dc.add_command(InfoCommand) self._dc.add_command(MassMoveCommand) diff --git a/kdb-bot/src/modules/base/command/complaint_command.py b/kdb-bot/src/modules/base/command/complaint_command.py deleted file mode 100644 index 68b2b1e2..00000000 --- a/kdb-bot/src/modules/base/command/complaint_command.py +++ /dev/null @@ -1,25 +0,0 @@ -from cpl_core.logging import LoggerABC -from cpl_discord.command import DiscordCommandABC -from cpl_discord.service import DiscordBotServiceABC -from discord.ext import commands -from discord.ext.commands import Context - -from bot_core.helper.command_checks import CommandChecks -from modules.base.forms.complaint_form import ComplaintForm - - -class ComplaintCommand(DiscordCommandABC): - def __init__(self, logger: LoggerABC, bot: DiscordBotServiceABC, form: ComplaintForm): - DiscordCommandABC.__init__(self) - - self._logger = logger - self._bot = bot - self._form = form - - @commands.hybrid_command() - @commands.guild_only() - @CommandChecks.check_is_ready() - async def complaint(self, ctx: Context): - self._logger.debug(__name__, f"Received command complaint {ctx}") - await ctx.interaction.response.send_modal(self._form) - self._logger.trace(__name__, f"Finished command complaint {ctx}") diff --git a/kdb-bot/src/modules/base/command/submit_group.py b/kdb-bot/src/modules/base/command/submit_group.py new file mode 100644 index 00000000..56812e14 --- /dev/null +++ b/kdb-bot/src/modules/base/command/submit_group.py @@ -0,0 +1,43 @@ +from cpl_core.logging import LoggerABC +from cpl_discord.command import DiscordCommandABC +from cpl_discord.service import DiscordBotServiceABC +from discord.ext import commands +from discord.ext.commands import Context + +from bot_core.helper.command_checks import CommandChecks +from modules.base.forms.bug_report_form import BugReportForm +from modules.base.forms.complaint_form import ComplaintForm + + +class SubmitGroup(DiscordCommandABC): + def __init__( + self, logger: LoggerABC, bot: DiscordBotServiceABC, complaint_form: ComplaintForm, bug_form: BugReportForm + ): + DiscordCommandABC.__init__(self) + + self._logger = logger + self._bot = bot + self._complaint_form = complaint_form + self._bug_form = bug_form + + @commands.hybrid_group() + @commands.guild_only() + async def submit(self, ctx: Context): + pass + + @submit.command() + @commands.guild_only() + @CommandChecks.check_is_ready() + async def complaint(self, ctx: Context): + self._logger.debug(__name__, f"Received command complaint {ctx}") + await ctx.interaction.response.send_modal(self._complaint_form) + self._logger.trace(__name__, f"Finished command complaint {ctx}") + pass + + @submit.command() + @commands.guild_only() + @CommandChecks.check_is_ready() + async def bug_report(self, ctx: Context): + self._logger.debug(__name__, f"Received command complaint {ctx}") + await ctx.interaction.response.send_modal(self._bug_form) + self._logger.trace(__name__, f"Finished command complaint {ctx}") diff --git a/kdb-bot/src/modules/base/forms/bug_report_form.py b/kdb-bot/src/modules/base/forms/bug_report_form.py new file mode 100644 index 00000000..85d24bce --- /dev/null +++ b/kdb-bot/src/modules/base/forms/bug_report_form.py @@ -0,0 +1,50 @@ +import discord +from cpl_core.database.context import DatabaseContextABC +from cpl_discord.service import DiscordBotServiceABC +from cpl_translation import TranslatePipe +from discord import ui, TextStyle + +from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.configuration.bot_settings import BotSettings +from bot_core.logging.command_logger import CommandLogger +from modules.base.service.base_helper_service import BaseHelperService + + +class BugReportForm(ui.Modal): + description = ui.TextInput(label="Report a bug", required=True, style=TextStyle.long) + + def __init__( + self, + bot_settings: BotSettings, + bot: DiscordBotServiceABC, + db: DatabaseContextABC, + logger: CommandLogger, + message_service: MessageServiceABC, + base_helper: BaseHelperService, + t: TranslatePipe, + ): + ui.Modal.__init__(self, title=t.transform("modules.base.bug.title")) + + self._bot_settings = bot_settings + self._bot = bot + self._db = db + self._message_service = message_service + self._logger = logger + self._base_helper = base_helper + self._t = t + + self.description.label = t.transform("modules.base.bug.label") + + async def on_submit(self, interaction: discord.Interaction): + self._logger.debug(__name__, f"Started bug report form") + + for t in self._bot_settings.technicians: + member = self._bot.get_user(t) + await self._message_service.send_dm_message( + self._t.transform("modules.base.bug.message").format(interaction.user.mention, self.description.value), + member, + without_tracking=True, + ) + + await self._message_service.send_interaction_msg(interaction, self._t.transform("modules.base.bug.response")) + self._logger.trace(__name__, f"Finished bug report form")