Added auto-role rule add command #54
This commit is contained in:
parent
b75777a339
commit
eb3bdac162
@ -73,6 +73,9 @@
|
||||
"not_found": "auto-role {} nicht gefunden!"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"nothing_found": "Keine auto-role Einträge gefunden."
|
||||
},
|
||||
"rule": {
|
||||
"list": {
|
||||
"title": "auto-role Regeln:",
|
||||
@ -81,12 +84,24 @@
|
||||
"emoji": "Emoji",
|
||||
"role": "Rolle"
|
||||
},
|
||||
"add": {
|
||||
"success": "Regel {} -> {} für auto-role {} wurde hinzugefügt :D",
|
||||
"error": {
|
||||
"id_not_found": "Kein auto-role Eintrag mit der Id gefunden!"
|
||||
"not_found": "Regel für auto-role {} nicht gefunden!",
|
||||
"emoji_not_found": "Eomji {} für auto-role Regel {} nicht gefunden!",
|
||||
"rule_not_found": "Rolle {} für auto-role Regel {} nicht gefunden!",
|
||||
"already_exists": "Regel für auto-role {} existiert bereits!"
|
||||
}
|
||||
},
|
||||
"remove": {
|
||||
"success": "Regel für auto-role {} wurde entfernt :D",
|
||||
"error": {
|
||||
"not_found": "Regel für auto-role {} nicht gefunden!"
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"nothing_found": "Keine auto-role Einträge gefunden."
|
||||
"id_not_found": "Kein auto-role Eintrag mit der Id gefunden!"
|
||||
}
|
||||
}
|
||||
},
|
||||
"moderator": {
|
||||
|
@ -59,7 +59,7 @@ class AutoRoleRule(TableABC):
|
||||
`AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._auto_role_id},
|
||||
{self._discord_emoji_name},
|
||||
'{self._discord_emoji_name}',
|
||||
{self._discord_role_id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
@ -74,12 +74,12 @@ class AutoRoleRule(TableABC):
|
||||
SET `DiscordEmojiName` = {self._discord_emoji_name},
|
||||
SET `DiscordRoleId` = {self._discord_role_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_id};
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_rule_id};
|
||||
""")
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
DELETE FROM `AutoRoleRules`
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_id};
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_rule_id};
|
||||
""")
|
||||
|
@ -170,12 +170,12 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC):
|
||||
return auto_role_rules
|
||||
|
||||
def add_auto_role_rule(self, auto_role_rule: AutoRoleRule):
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role_rule.delete_string}')
|
||||
self._context.cursor.execute(auto_role_rule.delete_string)
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role_rule.insert_string}')
|
||||
self._context.cursor.execute(auto_role_rule.insert_string)
|
||||
|
||||
def update_auto_role_rule(self, auto_role_rule: AutoRoleRule):
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role_rule.delete_string}')
|
||||
self._context.cursor.execute(auto_role_rule.delete_string)
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role_rule.udpate_string}')
|
||||
self._context.cursor.execute(auto_role_rule.udpate_string)
|
||||
|
||||
def delete_auto_role_rule(self, auto_role_rule: AutoRoleRule):
|
||||
self._logger.trace(__name__, f'Send SQL command: {auto_role_rule.delete_string}')
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user