Merge pull request 'Reaktion ins message.log #169' (#174) from #169 into 0.3.1

Reviewed-on: sh-edraft.de/kd_discord_bot#174
Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com>
Closes #169
This commit is contained in:
Sven Heidemann 2023-01-12 07:05:50 +01:00
commit 242ffd1550

View File

@ -3,6 +3,7 @@ from cpl_core.logging import LoggerABC
from cpl_discord.service import DiscordBotServiceABC
from discord import RawReactionActionEvent
from bot_core.helper.log_message_helper import LogMessageHelper
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC
from modules.base.abc.base_helper_abc import BaseHelperABC
@ -36,6 +37,20 @@ class BaseReactionHandler:
self._logger.warn(__name__, f'User {payload.user_id} in {guild.name} not found - skipping')
return
try:
log_msg = f'{member.name} reacted'
if payload.emoji.name is not None:
log_msg += f' with {payload.emoji.name}'
try:
channel = guild.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
self._logger.info(__name__, f'{log_msg} to message {LogMessageHelper.get_log_string(message)}')
except Exception as e:
self._logger.error(__name__, f'Getting message for reaction logging failed', e)
self._logger.info(__name__, f'{log_msg} to message {payload.message_id}')
except Exception as e:
self._logger.error(__name__, f'Reaction logging failed', e)
if member.bot:
return