diff --git a/kdb-bot/src/bot/module_list.py b/kdb-bot/src/bot/module_list.py index 120926ef..700f0c73 100644 --- a/kdb-bot/src/bot/module_list.py +++ b/kdb-bot/src/bot/module_list.py @@ -25,10 +25,10 @@ class ModuleList: DataModule, GraphQLModule, PermissionModule, - LevelModule, DatabaseModule, AutoRoleModule, BaseModule, + LevelModule, ApiModule, TechnicianModule, # has to be last! diff --git a/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py b/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py new file mode 100644 index 00000000..5535b0e7 --- /dev/null +++ b/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py @@ -0,0 +1,34 @@ +from cpl_core.logging import LoggerABC +from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC +from cpl_discord.service import DiscordBotServiceABC +from discord import RawReactionActionEvent + +from bot_core.helper.event_checks import EventChecks +from modules.level.service.level_service import LevelService + + +class LevelOnRawReactionAddEvent(OnRawReactionAddABC): + def __init__( + self, + logger: LoggerABC, + bot: DiscordBotServiceABC, + level: LevelService, + ): + OnRawReactionAddABC.__init__(self) + + self._logger = logger + self._bot = bot + self._level = level + + @EventChecks.check_is_ready() + async def on_raw_reaction_add(self, payload: RawReactionActionEvent): + self._logger.debug(__name__, f"Module {type(self)} started") + try: + self._logger.trace(__name__, f"Handle reaction {payload} for level") + + guild = self._bot.get_guild(payload.guild_id) + member = guild.get_member(payload.user_id) + + await self._level.check_level(member) + except Exception as e: + self._logger.error(__name__, f"Level check by message failed", e) diff --git a/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py b/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py new file mode 100644 index 00000000..3e4c32d7 --- /dev/null +++ b/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py @@ -0,0 +1,34 @@ +from cpl_core.logging import LoggerABC +from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC +from cpl_discord.service import DiscordBotServiceABC +from discord import RawReactionActionEvent + +from bot_core.helper.event_checks import EventChecks +from modules.level.service.level_service import LevelService + + +class LevelOnRawReactionRemoveEvent(OnRawReactionRemoveABC): + def __init__( + self, + logger: LoggerABC, + bot: DiscordBotServiceABC, + level: LevelService, + ): + OnRawReactionRemoveABC.__init__(self) + + self._logger = logger + self._bot = bot + self._level = level + + @EventChecks.check_is_ready() + async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): + self._logger.debug(__name__, f"Module {type(self)} started") + try: + self._logger.trace(__name__, f"Handle reaction {payload} for level") + + guild = self._bot.get_guild(payload.guild_id) + member = guild.get_member(payload.user_id) + + await self._level.check_level(member) + except Exception as e: + self._logger.error(__name__, f"Level check by message failed", e) diff --git a/kdb-bot/src/modules/level/level_module.py b/kdb-bot/src/modules/level/level_module.py index be99518c..018377f9 100644 --- a/kdb-bot/src/modules/level/level_module.py +++ b/kdb-bot/src/modules/level/level_module.py @@ -12,6 +12,8 @@ from bot_data.abc.data_seeder_abc import DataSeederABC from modules.level.command.level_group import LevelGroup from modules.level.events.level_on_member_join_event import LevelOnMemberJoinEvent from modules.level.events.level_on_message_event import LevelOnMessageEvent +from modules.level.events.level_on_raw_reaction_add_event import LevelOnRawReactionAddEvent +from modules.level.events.level_on_raw_reaction_remove_event import LevelOnRawReactionRemoveEvent from modules.level.events.level_on_voice_state_update_event import ( LevelOnVoiceStateUpdateEvent, ) @@ -43,3 +45,5 @@ class LevelModule(ModuleABC): LevelOnVoiceStateUpdateEvent, ) self._dc.add_event(DiscordEventTypesEnum.on_member_join.value, LevelOnMemberJoinEvent) + self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_add.value, LevelOnRawReactionAddEvent) + self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_remove.value, LevelOnRawReactionRemoveEvent)