Merge pull request 'Added level checks #304' (#305) from #304 into support

Reviewed-on: sh-edraft.de/kd_discord_bot#305
Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com>
Closes #304
This commit is contained in:
Sven Heidemann 2023-04-12 21:20:52 +02:00
commit ebdf375283
4 changed files with 73 additions and 1 deletions

View File

@ -25,10 +25,10 @@ class ModuleList:
DataModule, DataModule,
GraphQLModule, GraphQLModule,
PermissionModule, PermissionModule,
LevelModule,
DatabaseModule, DatabaseModule,
AutoRoleModule, AutoRoleModule,
BaseModule, BaseModule,
LevelModule,
ApiModule, ApiModule,
TechnicianModule, TechnicianModule,
# has to be last! # has to be last!

View File

@ -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)

View File

@ -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)

View File

@ -12,6 +12,8 @@ from bot_data.abc.data_seeder_abc import DataSeederABC
from modules.level.command.level_group import LevelGroup 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_member_join_event import LevelOnMemberJoinEvent
from modules.level.events.level_on_message_event import LevelOnMessageEvent 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 ( from modules.level.events.level_on_voice_state_update_event import (
LevelOnVoiceStateUpdateEvent, LevelOnVoiceStateUpdateEvent,
) )
@ -43,3 +45,5 @@ class LevelModule(ModuleABC):
LevelOnVoiceStateUpdateEvent, LevelOnVoiceStateUpdateEvent,
) )
self._dc.add_event(DiscordEventTypesEnum.on_member_join.value, LevelOnMemberJoinEvent) 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)