[UNTESTED] Added complaint command #293_complaints

This commit is contained in:
Sven Heidemann 2023-07-17 13:43:27 +02:00
parent 11a4874bfb
commit 9f63a9c6dd
5 changed files with 81 additions and 0 deletions

View File

@ -151,6 +151,11 @@
} }
}, },
"base": { "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_channel_missing_message": "Zu unfähig einem Sprachkanal beizutreten?",
"afk_command_move_message": "Ich verschiebe dich ja schon... (◔_◔)", "afk_command_move_message": "Ich verschiebe dich ja schon... (◔_◔)",
"game_server": { "game_server": {

View File

@ -8,6 +8,7 @@ from bot_core.abc.module_abc import ModuleABC
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from modules.base.abc.base_helper_abc import BaseHelperABC from modules.base.abc.base_helper_abc import BaseHelperABC
from modules.base.command.afk_command import AFKCommand 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.game_server_group import GameServerGroup
from modules.base.command.help_command import HelpCommand from modules.base.command.help_command import HelpCommand
from modules.base.command.info_command import InfoCommand 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 ( from modules.base.events.base_on_voice_state_update_event_scheduled_event_bonus import (
BaseOnVoiceStateUpdateEventScheduledEventBonus, BaseOnVoiceStateUpdateEventScheduledEventBonus,
) )
from modules.base.forms.complaint_form import ComplaintForm
from modules.base.helper.base_reaction_handler import BaseReactionHandler from modules.base.helper.base_reaction_handler import BaseReactionHandler
from modules.base.service.base_helper_service import BaseHelperService from modules.base.service.base_helper_service import BaseHelperService
from modules.base.service.event_service import EventService from modules.base.service.event_service import EventService
@ -55,8 +57,12 @@ class BaseModule(ModuleABC):
services.add_singleton(EventService) services.add_singleton(EventService)
services.add_transient(UserWarningsService) services.add_transient(UserWarningsService)
# forms
services.add_singleton(ComplaintForm)
# commands # commands
self._dc.add_command(AFKCommand) self._dc.add_command(AFKCommand)
self._dc.add_command(ComplaintCommand)
self._dc.add_command(HelpCommand) self._dc.add_command(HelpCommand)
self._dc.add_command(InfoCommand) self._dc.add_command(InfoCommand)
self._dc.add_command(MassMoveCommand) self._dc.add_command(MassMoveCommand)

View File

@ -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}")

View File

@ -0,0 +1 @@
# imports

View File

@ -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")