|
|
|
@@ -17,6 +17,7 @@ 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
|
|
|
|
|
from bot_data.model.auto_role import AutoRole
|
|
|
|
|
from bot_data.model.auto_role_rule import AutoRoleRule
|
|
|
|
|
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -62,7 +63,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
|
|
|
|
|
|
|
|
|
if not self._permissions.is_member_moderator(ctx.author):
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
|
|
|
|
|
self._logger.trace(__name__, f'Finished purge command')
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role list')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
embed = discord.Embed(
|
|
|
|
@@ -96,7 +97,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
|
|
|
|
|
|
|
|
|
if not self._permissions.is_member_moderator(ctx.author):
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
|
|
|
|
|
self._logger.trace(__name__, f'Finished purge command')
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role add')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
message = List(discord.Message, [message async for message in ctx.channel.history(limit=50)]).where(lambda m: m.id == int(message_id)).single_or_default()
|
|
|
|
@@ -134,7 +135,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
|
|
|
|
|
|
|
|
|
if not self._permissions.is_member_moderator(ctx.author):
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
|
|
|
|
|
self._logger.trace(__name__, f'Finished purge command')
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role remove')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
auto_role_from_db = self._auto_roles.find_auto_role_by_id(auto_role)
|
|
|
|
@@ -167,13 +168,13 @@ class AutoRoleGroup(DiscordCommandABC):
|
|
|
|
|
@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}')
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
if not self._permissions.is_member_moderator(ctx.author):
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
|
|
|
|
|
self._logger.trace(__name__, f'Finished purge command')
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role rule list')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
embed = discord.Embed(
|
|
|
|
@@ -184,7 +185,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
|
|
|
|
rules = self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role)
|
|
|
|
|
if rules.count() < 1:
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.error.id_not_found'))
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role-rule list')
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role rule list')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
auto_role_rule_id = ''
|
|
|
|
@@ -199,9 +200,66 @@ class AutoRoleGroup(DiscordCommandABC):
|
|
|
|
|
embed.add_field(name=self._t.transform('modules.auto_role.rule.list.emoji'), value=emoji, inline=True)
|
|
|
|
|
embed.add_field(name=self._t.transform('modules.auto_role.rule.list.role'), value=role, inline=True)
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait)
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role-rule list')
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role rule list')
|
|
|
|
|
|
|
|
|
|
@list.autocomplete('auto_role')
|
|
|
|
|
async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
|
|
|
|
auto_roles = self._auto_roles.get_auto_roles().select(lambda x: x.auto_role_id)
|
|
|
|
|
return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles]
|
|
|
|
|
|
|
|
|
|
@rule.command()
|
|
|
|
|
@commands.guild_only()
|
|
|
|
|
async def add(self, ctx: Context, auto_role: int, emoji_name: str, role_id: str):
|
|
|
|
|
self._logger.debug(__name__, f'Received command auto-role add {ctx} {auto_role}')
|
|
|
|
|
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if not self._permissions.is_member_moderator(ctx.author):
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role rule add')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
emoji = discord.utils.get(self._bot.emojis, name=emoji_name)
|
|
|
|
|
if emoji is None:
|
|
|
|
|
self._logger.debug(__name__, f'auto-role rule add emoji {emoji_name} not found')
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.add.error.emoji_not_found').format(emoji_name, auto_role))
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role add')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
role = ctx.guild.get_role(int(role_id))
|
|
|
|
|
if role is None:
|
|
|
|
|
self._logger.debug(__name__, f'auto-role rule add role {role_id} not found')
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.add.error.role_not_found').format(role_id, auto_role))
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role add')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
auto_role_from_db = self._auto_roles.get_auto_role_by_id(auto_role)
|
|
|
|
|
if auto_role_from_db is None:
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.remove.error.not_found').format(auto_role))
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role rule add')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role).where(lambda r: r.emoji_name == emoji.name and int(role_id) == role.id).count() > 0:
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.error.already_exists').format(auto_role))
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role rule add')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
self._auto_roles.add_auto_role_rule(AutoRoleRule(auto_role, emoji_name, int(role_id)))
|
|
|
|
|
self._db_context.save_changes()
|
|
|
|
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.add.success').format(emoji, role.name, auto_role))
|
|
|
|
|
self._logger.trace(__name__, f'Finished command auto-role rule add')
|
|
|
|
|
|
|
|
|
|
@add.autocomplete('auto_role')
|
|
|
|
|
async def add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
|
|
|
|
auto_roles = self._auto_roles.get_auto_roles().select(lambda x: x.auto_role_id)
|
|
|
|
|
return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles]
|
|
|
|
|
|
|
|
|
|
@add.autocomplete('emoji_name')
|
|
|
|
|
async def add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
|
|
|
|
emojis = interaction.guild.emojis
|
|
|
|
|
return [app_commands.Choice(name=emoji.name, value=emoji.name) for emoji in emojis]
|
|
|
|
|
|
|
|
|
|
@add.autocomplete('role_id')
|
|
|
|
|
async def rule_add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
|
|
|
|
roles = interaction.guild.roles
|
|
|
|
|
return [app_commands.Choice(name=role.name, value=str(role.id)) for role in roles]
|
|
|
|
|