Added auto-role list #54

This commit is contained in:
Sven Heidemann 2022-10-03 19:26:48 +02:00
parent d0ed413150
commit 9daa0b1c54
5 changed files with 93 additions and 1 deletions

View File

@ -53,6 +53,14 @@
"shutdown_message": "Trauert nicht um mich, es war eine logische Entscheidung. Das Wohl von Vielen, es wiegt schwerer als das Wohl von Wenigen oder eines Einzelnen. Ich war es und ich werde es immer sein, Euer Freund. Lebt lange und in Frieden :)",
"deploy_message": "Der neue Stand wurde hochgeladen."
},
"auto_role": {
"list": {
"title": "beobachtete Nachrichten:",
"description": "Von auto-role beobachtete Nachrichten:",
"auto_role_id": "auto-role Id",
"message_id": "Nachricht-Id"
}
},
"moderator": {
"purge_message": "Na gut..., ich lösche alle Nachrichten wenns sein muss."
},

View File

@ -6,6 +6,7 @@ from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
from bot_core.abc.module_abc import ModuleABC
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from modules.autorole.command.auto_role_command import AutoRoleCommand
from modules.autorole.events.auto_role_on_raw_reaction_add import AutoRoleOnRawReactionAddEvent
from modules.autorole.events.auto_role_on_raw_reaction_remove import AutoRoleOnRawReactionRemoveEvent
from modules.autorole.helper.reaction_handler import ReactionHandler
@ -22,6 +23,7 @@ class AutoRoleModule(ModuleABC):
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
services.add_transient(ReactionHandler)
# commands
self._dc.add_command(AutoRoleCommand)
# events
self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_add.value, AutoRoleOnRawReactionAddEvent)
self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_remove.value, AutoRoleOnRawReactionRemoveEvent)

View File

View File

@ -0,0 +1,82 @@
import discord
from cpl_discord.command import DiscordCommandABC
from cpl_discord.service import DiscordBotServiceABC
from cpl_translation import TranslatePipe
from discord.ext import commands
from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.logging.command_logger import CommandLogger
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC
class AutoRoleCommand(DiscordCommandABC):
def __init__(
self,
logger: CommandLogger,
message_service: MessageServiceABC,
bot: DiscordBotServiceABC,
client_utils: ClientUtilsServiceABC,
translate: TranslatePipe,
servers: ServerRepositoryABC,
auto_roles: AutoRoleRepositoryABC
):
DiscordCommandABC.__init__(self)
self._logger = logger
self._message_service = message_service
self._bot = bot
self._client_utils = client_utils
self._t = translate
self._servers = servers
self._auto_roles = auto_roles
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
@commands.hybrid_group(name="auto-role")
@commands.guild_only()
async def auto_role(self, ctx: Context):
pass
@auto_role.command()
@commands.guild_only()
async def list(self, ctx: Context, wait: int = None):
self._logger.debug(__name__, f'Received command auto-role list {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
embed = discord.Embed(
title=self._t.transform('modules.auto_role.list.title'),
description=self._t.transform('modules.auto_role.list.description'),
color=int('ef9d0d', 16)
)
auto_role_id = ''
for id in self._auto_roles.get_auto_roles().select(lambda x: x.auto_role_id):
auto_role_id += f'\n{id}'
message_id = ''
for id in self._auto_roles.get_auto_roles().select(lambda x: x.discord_message_id):
message_id += f'\n{id}'
embed.add_field(name=self._t.transform('modules.auto_role.list.auto_role_id'), value=auto_role_id, inline=True)
embed.add_field(name=self._t.transform('modules.auto_role.list.message_id'), value=message_id, inline=True)
await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait)
self._logger.trace(__name__, f'Finished command auto-role list')
@auto_role.command()
@commands.guild_only()
async def add(self, ctx: Context):
self._logger.debug(__name__, f'Received command auto-role add {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
@auto_role.command()
@commands.guild_only()
async def remove(self, ctx: Context):
self._logger.debug(__name__, f'Received command auto-role remove {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return

View File

@ -62,7 +62,7 @@ class InfoCommand(DiscordCommandABC):
embed.add_field(name=self._t.transform('modules.base.info.fields.moved_users_count'), value=client.moved_users_count)
from bot.module_list import ModuleList
modules = ModuleList.get_modules()
modules = modules.select(lambda x: x.replace('Module', ''))
modules = modules.select(lambda x: x.__name__.replace('Module', ''))
embed.add_field(name=self._t.transform('modules.base.info.fields.modules'), value='\n'.join(modules), inline=False)
await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait)