Merge pull request '0.3 - AutoRole Emoji zu nachricht nach Anlegen einer Regel hinzufügen (#63)' (#110) from #63 into 0.3
Reviewed-on: sh-edraft.de/kd_discord_bot#110 Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com> Closes #63
This commit is contained in:
commit
be96644e5c
@ -7,7 +7,7 @@ from cpl_discord.container import TextChannel
|
|||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
from cpl_query.extension import List
|
from cpl_query.extension import List
|
||||||
from cpl_translation import TranslatePipe
|
from cpl_translation import TranslatePipe
|
||||||
from discord import app_commands
|
from discord import app_commands, Guild
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import Context
|
from discord.ext.commands import Context
|
||||||
|
|
||||||
@ -258,13 +258,27 @@ class AutoRoleGroup(DiscordCommandABC):
|
|||||||
self._logger.trace(__name__, f'Finished command auto-role rule add')
|
self._logger.trace(__name__, f'Finished command auto-role rule add')
|
||||||
return
|
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:
|
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).first_or_default() is not None:
|
||||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.error.already_exists').format(auto_role))
|
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')
|
self._logger.trace(__name__, f'Finished command auto-role rule add')
|
||||||
return
|
return
|
||||||
|
|
||||||
self._auto_roles.add_auto_role_rule(AutoRoleRule(auto_role, emoji_name, int(role_id)))
|
self._auto_roles.add_auto_role_rule(AutoRoleRule(auto_role, emoji_name, int(role_id)))
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
|
rule = 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).single()
|
||||||
|
try:
|
||||||
|
message = await ctx.fetch_message(auto_role_from_db.discord_message_id)
|
||||||
|
guild: Guild = self._bot.guilds.where(lambda g: g == ctx.guild).single()
|
||||||
|
emoji = List(discord.Emoji, guild.emojis).where(lambda x: x.name == rule.emoji_name).single()
|
||||||
|
|
||||||
|
if emoji is None:
|
||||||
|
self._logger.debug(__name__, f'Emoji {rule.emoji_name} not found')
|
||||||
|
return
|
||||||
|
await message.add_reaction(emoji)
|
||||||
|
self._logger.debug(__name__, f'Added reaction {rule.emoji_name} to message: {auto_role_from_db.discord_message_id}')
|
||||||
|
except Exception as e:
|
||||||
|
self._logger.error(__name__, f'Cannot add reaction {rule.emoji_name} to message: {auto_role_from_db.discord_message_id}', e)
|
||||||
|
|
||||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.add.success').format(emoji, role.name, auto_role))
|
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')
|
self._logger.trace(__name__, f'Finished command auto-role rule add')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user