From 2c7e5edbd7ca453b0856bb079e4f8c4e61efbad9 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 17 Jul 2023 13:43:27 +0200 Subject: [PATCH 1/3] [UNTESTED] Added complaint command #293_complaints --- kdb-bot/src/bot/translation/de.json | 5 +++ kdb-bot/src/modules/base/base_module.py | 6 +++ .../modules/base/command/complaint_command.py | 25 +++++++++++ kdb-bot/src/modules/base/forms/__init__.py | 1 + .../src/modules/base/forms/complaint_form.py | 44 +++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 kdb-bot/src/modules/base/command/complaint_command.py create mode 100644 kdb-bot/src/modules/base/forms/__init__.py create mode 100644 kdb-bot/src/modules/base/forms/complaint_form.py diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index 27dd9749..d231e3f4 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -151,6 +151,11 @@ } }, "base": { + "complaints": { + "title": "Beschwerde einreichen", + "label": "Beschwerde", + "message": "{} hat eine Beschwerde eingereicht:\n{}" + }, "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 4d8c4f2d..95604372 100644 --- a/kdb-bot/src/modules/base/base_module.py +++ b/kdb-bot/src/modules/base/base_module.py @@ -8,6 +8,7 @@ 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 @@ -36,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.complaint_form import ComplaintForm from modules.base.helper.base_reaction_handler import BaseReactionHandler from modules.base.service.base_helper_service import BaseHelperService from modules.base.service.event_service import EventService @@ -55,8 +57,12 @@ class BaseModule(ModuleABC): services.add_singleton(EventService) services.add_transient(UserWarningsService) + # forms + services.add_singleton(ComplaintForm) + # commands self._dc.add_command(AFKCommand) + self._dc.add_command(ComplaintCommand) 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 new file mode 100644 index 00000000..68b2b1e2 --- /dev/null +++ b/kdb-bot/src/modules/base/command/complaint_command.py @@ -0,0 +1,25 @@ +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/forms/__init__.py b/kdb-bot/src/modules/base/forms/__init__.py new file mode 100644 index 00000000..425ab6c1 --- /dev/null +++ b/kdb-bot/src/modules/base/forms/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/kdb-bot/src/modules/base/forms/complaint_form.py b/kdb-bot/src/modules/base/forms/complaint_form.py new file mode 100644 index 00000000..856b417d --- /dev/null +++ b/kdb-bot/src/modules/base/forms/complaint_form.py @@ -0,0 +1,44 @@ +import discord +from cpl_core.database.context import DatabaseContextABC +from cpl_translation import TranslatePipe +from discord import ui + +from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.logging.command_logger import CommandLogger +from modules.base.configuration.base_server_settings import BaseServerSettings +from modules.base.service.base_helper_service import BaseHelperService + + +class ComplaintForm(ui.Modal): + description = ui.TextInput(label="Complain about something", required=True) + + def __init__( + self, + db: DatabaseContextABC, + logger: CommandLogger, + message_service: MessageServiceABC, + base_helper: BaseHelperService, + t: TranslatePipe, + ): + ui.Modal.__init__(self, title=t.transform("modules.base.complaints.title")) + + 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.complaints.label") + + async def on_submit(self, interaction: discord.Interaction): + self._logger.debug(__name__, f"Started complaint command form") + settings: BaseServerSettings = self._base_helper.get_config(interaction.message.guild.id) + channel = interaction.guild.get_channel(settings.team_channel_id) + await self._message_service.send_channel_message( + channel, + self._t.transform("modules.base.complaints.message").format( + interaction.user.mention, self.description.value + ), + is_persistent=True, + ) + self._logger.trace(__name__, f"Finished complaint command form") From 0f67bf467a4e4146568f6038e2282967390c487b Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 18 Jul 2023 11:30:05 +0200 Subject: [PATCH 2/3] Improved complaint command #293_complaints --- kdb-bot/src/bot/translation/de.json | 3 ++- kdb-bot/src/modules/base/forms/complaint_form.py | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index d231e3f4..61f143e5 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -154,7 +154,8 @@ "complaints": { "title": "Beschwerde einreichen", "label": "Beschwerde", - "message": "{} hat eine Beschwerde eingereicht:\n{}" + "message": "{} hat eine Beschwerde eingereicht:\n{}", + "response": "Danke für deine Beschwerde" }, "afk_command_channel_missing_message": "Zu unfähig einem Sprachkanal beizutreten?", "afk_command_move_message": "Ich verschiebe dich ja schon... (◔_◔)", diff --git a/kdb-bot/src/modules/base/forms/complaint_form.py b/kdb-bot/src/modules/base/forms/complaint_form.py index 856b417d..6ae3b96e 100644 --- a/kdb-bot/src/modules/base/forms/complaint_form.py +++ b/kdb-bot/src/modules/base/forms/complaint_form.py @@ -1,7 +1,7 @@ import discord from cpl_core.database.context import DatabaseContextABC from cpl_translation import TranslatePipe -from discord import ui +from discord import ui, TextStyle from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.logging.command_logger import CommandLogger @@ -10,7 +10,7 @@ from modules.base.service.base_helper_service import BaseHelperService class ComplaintForm(ui.Modal): - description = ui.TextInput(label="Complain about something", required=True) + description = ui.TextInput(label="Complain about something", required=True, style=TextStyle.long) def __init__( self, @@ -32,7 +32,7 @@ class ComplaintForm(ui.Modal): async def on_submit(self, interaction: discord.Interaction): self._logger.debug(__name__, f"Started complaint command form") - settings: BaseServerSettings = self._base_helper.get_config(interaction.message.guild.id) + settings: BaseServerSettings = self._base_helper.get_config(interaction.guild.id) channel = interaction.guild.get_channel(settings.team_channel_id) await self._message_service.send_channel_message( channel, @@ -41,4 +41,7 @@ class ComplaintForm(ui.Modal): ), is_persistent=True, ) + await self._message_service.send_interaction_msg( + interaction, self._t.transform("modules.base.complaints.response") + ) self._logger.trace(__name__, f"Finished complaint command form") From bff435d51ee8138ae6f34909a94189fc8d122447 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 18 Jul 2023 11:43:50 +0200 Subject: [PATCH 3/3] 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")