forked from sh-edraft.de/sh_discord_bot
Added auto-role rule list #54
This commit is contained in:
parent
21c34436b9
commit
97e4f8ec29
@ -6,7 +6,7 @@
|
||||
"bot-core": "src/bot_core/bot-core.json",
|
||||
"bot-data": "src/bot_data/bot-data.json",
|
||||
"admin": "src/modules/admin/admin.json",
|
||||
"auto-role": "src/modules/admin/auto-role.json",
|
||||
"auto-role": "src/modules/auto_role/auto-role.json",
|
||||
"base": "src/modules/base/base.json",
|
||||
"boot-log": "src/modules/boot_log/boot-log.json",
|
||||
"database": "src/modules/database/database.json",
|
||||
|
@ -2,7 +2,7 @@
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "bot.log",
|
||||
"ConsoleLogLevel": "DEBUG",
|
||||
"ConsoleLogLevel": "TRACE",
|
||||
"FileLogLevel": "TRACE"
|
||||
},
|
||||
"BotLoggingSettings": {
|
||||
|
@ -4,7 +4,7 @@ from bot_core.core_extension.core_extension_module import CoreExtensionModule
|
||||
from bot_core.core_module import CoreModule
|
||||
from bot_data.data_module import DataModule
|
||||
from modules.admin.admin_module import AdminModule
|
||||
from modules.autorole.auto_role_module import AutoRoleModule
|
||||
from modules.auto_role.auto_role_module import AutoRoleModule
|
||||
from modules.base.base_module import BaseModule
|
||||
from modules.boot_log.boot_log_module import BootLogModule
|
||||
from modules.database.database_module import DatabaseModule
|
||||
@ -26,6 +26,7 @@ class ModuleList:
|
||||
DatabaseModule,
|
||||
ModeratorModule,
|
||||
PermissionModule,
|
||||
# has to be last!
|
||||
BootLogModule,
|
||||
CoreExtensionModule,
|
||||
BootLogModule # has to be last!
|
||||
])
|
||||
|
@ -6,11 +6,10 @@ 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.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_remove import AutoRoleOnRawReactionRemoveEvent
|
||||
from modules.autorole.helper.reaction_handler import ReactionHandler
|
||||
from modules.auto_role.command.auto_role_group import AutoRoleGroup
|
||||
from modules.auto_role.events.auto_role_on_raw_reaction_add import AutoRoleOnRawReactionAddEvent
|
||||
from modules.auto_role.events.auto_role_on_raw_reaction_remove import AutoRoleOnRawReactionRemoveEvent
|
||||
from modules.auto_role.helper.reaction_handler import ReactionHandler
|
||||
|
||||
|
||||
class AutoRoleModule(ModuleABC):
|
||||
@ -24,8 +23,7 @@ class AutoRoleModule(ModuleABC):
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_transient(ReactionHandler)
|
||||
# commands
|
||||
self._dc.add_command(AutoRoleCommand)
|
||||
self._dc.add_command(AutoRoleRuleCommand)
|
||||
self._dc.add_command(AutoRoleGroup)
|
||||
# events
|
||||
self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_add.value, AutoRoleOnRawReactionAddEvent)
|
||||
self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_remove.value, AutoRoleOnRawReactionRemoveEvent)
|
@ -15,7 +15,7 @@ from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
|
||||
|
||||
class AutoRoleRuleCommand(DiscordCommandABC):
|
||||
class AutoRoleGroup(DiscordCommandABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -39,12 +39,47 @@ class AutoRoleRuleCommand(DiscordCommandABC):
|
||||
|
||||
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||
|
||||
@commands.hybrid_group(name="auto-role-rule")
|
||||
@commands.hybrid_group(name="auto-role")
|
||||
@commands.guild_only()
|
||||
async def auto_role(self, ctx: Context):
|
||||
async def auto_role(self, ctx: Context): pass
|
||||
|
||||
@auto_role.command(alias='auto-roles')
|
||||
@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_roles = self._auto_roles.get_auto_roles()
|
||||
if auto_roles.count() < 1:
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.error.nothing_found'))
|
||||
self._logger.trace(__name__, f'Finished command auto-role list')
|
||||
return
|
||||
|
||||
auto_role_id = ''
|
||||
message_id = ''
|
||||
for auto_role in auto_roles:
|
||||
auto_role_id += f'\n{auto_role.auto_role_id}'
|
||||
message_id += f'\n{auto_role.discord_message_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')
|
||||
pass
|
||||
|
||||
@auto_role.command(alias='auto-role-rules')
|
||||
@auto_role.group()
|
||||
@commands.guild_only()
|
||||
async def rule(self, ctx: Context):
|
||||
pass
|
||||
|
||||
@rule.command(alias='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}')
|
||||
@ -81,17 +116,3 @@ class AutoRoleRuleCommand(DiscordCommandABC):
|
||||
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
|
@ -5,7 +5,7 @@ from discord import RawReactionActionEvent
|
||||
|
||||
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from modules.autorole.helper.reaction_handler import ReactionHandler
|
||||
from modules.auto_role.helper.reaction_handler import ReactionHandler
|
||||
|
||||
|
||||
class AutoRoleOnRawReactionAddEvent(OnRawReactionAddABC):
|
@ -6,7 +6,7 @@ from discord import RawReactionActionEvent
|
||||
|
||||
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from modules.autorole.helper.reaction_handler import ReactionHandler
|
||||
from modules.auto_role.helper.reaction_handler import ReactionHandler
|
||||
|
||||
|
||||
class AutoRoleOnRawReactionRemoveEvent(OnRawReactionRemoveABC):
|
@ -1,86 +0,0 @@
|
||||
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(alias='auto-roles')
|
||||
@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_roles = self._auto_roles.get_auto_roles()
|
||||
if auto_roles.count() < 1:
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.error.nothing_found'))
|
||||
self._logger.trace(__name__, f'Finished command auto-role list')
|
||||
return
|
||||
|
||||
auto_role_id = ''
|
||||
message_id = ''
|
||||
for auto_role in auto_roles:
|
||||
auto_role_id += f'\n{auto_role.auto_role_id}'
|
||||
message_id += f'\n{auto_role.discord_message_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
|
Loading…
Reference in New Issue
Block a user