forked from sh-edraft.de/sh_discord_bot
Added auto-role rule remove command #54
This commit is contained in:
parent
eb3bdac162
commit
17befd9f05
@ -80,7 +80,7 @@
|
|||||||
"list": {
|
"list": {
|
||||||
"title": "auto-role Regeln:",
|
"title": "auto-role Regeln:",
|
||||||
"description": "Von auto-role angewendete Regeln:",
|
"description": "Von auto-role angewendete Regeln:",
|
||||||
"auto_role_id": "auto-role Id",
|
"auto_role_rule_id": "auto-role Regel Id",
|
||||||
"emoji": "Emoji",
|
"emoji": "Emoji",
|
||||||
"role": "Rolle"
|
"role": "Rolle"
|
||||||
},
|
},
|
||||||
|
@ -108,7 +108,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self._auto_roles.find_auto_roles_by_message_id(int(message_id)) is not None:
|
if self._auto_roles.find_auto_roles_by_message_id(int(message_id)) is not None:
|
||||||
self._logger.debug(__name__, f'AutoRole for message {message_id} already exists')
|
self._logger.debug(__name__, f'auto-role for message {message_id} already exists')
|
||||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.error.already_exists').format(message_id))
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.error.already_exists').format(message_id))
|
||||||
self._logger.trace(__name__, f'Finished command auto-role add')
|
self._logger.trace(__name__, f'Finished command auto-role add')
|
||||||
return
|
return
|
||||||
@ -116,7 +116,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
server_id = self._servers.get_server_by_discord_id(ctx.guild.id).server_id
|
server_id = self._servers.get_server_by_discord_id(ctx.guild.id).server_id
|
||||||
self._auto_roles.add_auto_role(AutoRole(server_id, int(message_id)))
|
self._auto_roles.add_auto_role(AutoRole(server_id, int(message_id)))
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
self._logger.info(__name__, f'Saved AutoRole for message {message_id} at server {server_id}')
|
self._logger.info(__name__, f'Saved auto-role for message {message_id} at server {server_id}')
|
||||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.success').format(message_id))
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.success').format(message_id))
|
||||||
self._logger.trace(__name__, f'Finished command auto-role add')
|
self._logger.trace(__name__, f'Finished command auto-role add')
|
||||||
|
|
||||||
@ -140,18 +140,18 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
|
|
||||||
auto_role_from_db = self._auto_roles.find_auto_role_by_id(auto_role)
|
auto_role_from_db = self._auto_roles.find_auto_role_by_id(auto_role)
|
||||||
if auto_role_from_db is None:
|
if auto_role_from_db is None:
|
||||||
self._logger.debug(__name__, f'AutoRole {auto_role} not found')
|
self._logger.debug(__name__, f'auto-role {auto_role} not found')
|
||||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.remove.error.not_found').format(auto_role))
|
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 remove')
|
self._logger.trace(__name__, f'Finished command auto-role remove')
|
||||||
return
|
return
|
||||||
|
|
||||||
for rule in self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_from_db.auto_role_id):
|
for rule in self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_from_db.auto_role_id):
|
||||||
self._auto_roles.delete_auto_role_rule(rule)
|
self._auto_roles.delete_auto_role_rule(rule)
|
||||||
self._logger.info(__name__, f'Removed AutoRole rule {rule.role_id}')
|
self._logger.info(__name__, f'Removed auto-role rule {rule.role_id}')
|
||||||
|
|
||||||
self._auto_roles.delete_auto_role(auto_role_from_db)
|
self._auto_roles.delete_auto_role(auto_role_from_db)
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
self._logger.info(__name__, f'Removed AutoRole {auto_role}')
|
self._logger.info(__name__, f'Removed auto-role {auto_role}')
|
||||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.remove.success').format(auto_role))
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.remove.success').format(auto_role))
|
||||||
self._logger.trace(__name__, f'Finished command auto-role remove')
|
self._logger.trace(__name__, f'Finished command auto-role remove')
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
emoji += f'\n{rule.emoji_name}'
|
emoji += f'\n{rule.emoji_name}'
|
||||||
role += f'\n{ctx.guild.get_role(rule.role_id)}'
|
role += f'\n{ctx.guild.get_role(rule.role_id)}'
|
||||||
|
|
||||||
embed.add_field(name=self._t.transform('modules.auto_role.rule.list.auto_role_id'), value=auto_role_rule_id, inline=True)
|
embed.add_field(name=self._t.transform('modules.auto_role.rule.list.auto_role_rule_id'), value=auto_role_rule_id, inline=True)
|
||||||
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.emoji'), value=emoji, inline=True)
|
||||||
embed.add_field(name=self._t.transform('modules.auto_role.rule.list.role'), value=role, 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)
|
await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait)
|
||||||
@ -263,3 +263,33 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
async def rule_add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
async def rule_add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
roles = interaction.guild.roles
|
roles = interaction.guild.roles
|
||||||
return [app_commands.Choice(name=role.name, value=str(role.id)) for role in roles]
|
return [app_commands.Choice(name=role.name, value=str(role.id)) for role in roles]
|
||||||
|
|
||||||
|
@rule.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
async def remove(self, ctx: Context, auto_role_rule: int):
|
||||||
|
self._logger.debug(__name__, f'Received command auto-role remove {ctx} {auto_role_rule}')
|
||||||
|
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 remove')
|
||||||
|
return
|
||||||
|
|
||||||
|
auto_role_from_db = self._auto_roles.get_auto_role_rule_by_id(auto_role_rule)
|
||||||
|
if auto_role_from_db is None:
|
||||||
|
self._logger.debug(__name__, f'auto-role rule {auto_role_rule} not found')
|
||||||
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.remove.error.not_found').format(auto_role_rule))
|
||||||
|
self._logger.trace(__name__, f'Finished command auto-role rule remove')
|
||||||
|
return
|
||||||
|
|
||||||
|
self._auto_roles.delete_auto_role_rule(auto_role_from_db)
|
||||||
|
self._db_context.save_changes()
|
||||||
|
self._logger.info(__name__, f'Removed auto-role rule {auto_role_rule}')
|
||||||
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.remove.success').format(auto_role_rule))
|
||||||
|
self._logger.trace(__name__, f'Finished command auto-role remove')
|
||||||
|
|
||||||
|
@remove.autocomplete('auto_role_rule')
|
||||||
|
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
|
rules = self._auto_roles.get_auto_role_rules()
|
||||||
|
return [app_commands.Choice(name=f'{rule.auto_role_rule_id} {rule.emoji_name} {interaction.guild.get_role(int(rule.role_id))}', value=rule.auto_role_rule_id) for rule in rules]
|
||||||
|
Loading…
Reference in New Issue
Block a user