Added logic to log reactions #169

This commit is contained in:
Sven Heidemann 2023-01-11 17:53:21 +01:00
parent 4c577f6a7b
commit d10c33c6c2

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