forked from sh-edraft.de/sh_discord_bot
[WIP] Added auto-role-rules list #54
This commit is contained in:
parent
9daa0b1c54
commit
b35b023b02
@ -7,6 +7,7 @@ from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
|||||||
from bot_core.abc.module_abc import ModuleABC
|
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.autorole.command.auto_role_command import AutoRoleCommand
|
from modules.autorole.command.auto_role_command import AutoRoleCommand
|
||||||
|
from modules.autorole.command.auto_role_rule_command import AutoRoleRuleCommand
|
||||||
from modules.autorole.events.auto_role_on_raw_reaction_add import AutoRoleOnRawReactionAddEvent
|
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.events.auto_role_on_raw_reaction_remove import AutoRoleOnRawReactionRemoveEvent
|
||||||
from modules.autorole.helper.reaction_handler import ReactionHandler
|
from modules.autorole.helper.reaction_handler import ReactionHandler
|
||||||
@ -24,6 +25,7 @@ class AutoRoleModule(ModuleABC):
|
|||||||
services.add_transient(ReactionHandler)
|
services.add_transient(ReactionHandler)
|
||||||
# commands
|
# commands
|
||||||
self._dc.add_command(AutoRoleCommand)
|
self._dc.add_command(AutoRoleCommand)
|
||||||
|
self._dc.add_command(AutoRoleRuleCommand)
|
||||||
# events
|
# events
|
||||||
self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_add.value, AutoRoleOnRawReactionAddEvent)
|
self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_add.value, AutoRoleOnRawReactionAddEvent)
|
||||||
self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_remove.value, AutoRoleOnRawReactionRemoveEvent)
|
self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_remove.value, AutoRoleOnRawReactionRemoveEvent)
|
||||||
|
@ -41,7 +41,7 @@ class AutoRoleCommand(DiscordCommandABC):
|
|||||||
async def auto_role(self, ctx: Context):
|
async def auto_role(self, ctx: Context):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@auto_role.command()
|
@auto_role.command(alias='auto-roles')
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
async def list(self, ctx: Context, wait: int = None):
|
async def list(self, ctx: Context, wait: int = None):
|
||||||
self._logger.debug(__name__, f'Received command auto-role list {ctx}')
|
self._logger.debug(__name__, f'Received command auto-role list {ctx}')
|
||||||
|
81
src/modules/autorole/command/auto_role_rule_command.py
Normal file
81
src/modules/autorole/command/auto_role_rule_command.py
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from cpl_discord.command import DiscordCommandABC
|
||||||
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
from cpl_translation import TranslatePipe
|
||||||
|
from discord import app_commands
|
||||||
|
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 AutoRoleRuleCommand(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-rule")
|
||||||
|
@commands.guild_only()
|
||||||
|
async def auto_role(self, ctx: Context):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@auto_role.command(alias='auto-role-rules')
|
||||||
|
@commands.guild_only()
|
||||||
|
async def list(self, ctx: Context, auto_role: int, wait: int = None):
|
||||||
|
self._logger.debug(__name__, f'Received command auto-role-rule 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)
|
||||||
|
)
|
||||||
|
|
||||||
|
await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait)
|
||||||
|
self._logger.trace(__name__, f'Finished command auto-role list')
|
||||||
|
|
||||||
|
@list.autocomplete('auto_role')
|
||||||
|
async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
|
||||||
|
auto_roles = self._auto_roles.get_auto_roles().select(lambda x: x.auto_role_id)
|
||||||
|
return [app_commands.Choice(name=key, value=key) for key in auto_roles]
|
||||||
|
|
||||||
|
@auto_role.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
async def add(self, ctx: Context):
|
||||||
|
self._logger.debug(__name__, f'Received command auto-role-rule 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-rule remove {ctx}')
|
||||||
|
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
|
||||||
|
return
|
Loading…
Reference in New Issue
Block a user