A-0.3 - Basismodul #36

Merged
edraft merged 48 commits from 0.3 into Alpha 2021-12-27 18:17:42 +01:00
Showing only changes of commit f417eca644 - Show all commits

View File

@ -1,10 +1,14 @@
from typing import Union
import discord
from cpl_core.database.context import DatabaseContextABC
from cpl_core.logging.logger_abc import LoggerABC
from gismo_core.abc.bot_service_abc import BotServiceABC
from gismo_data.abc.client_repository_abc import ClientRepositoryABC
from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC
from gismo_data.abc.server_repository_abc import ServerRepositoryABC
from gismo_data.model.known_user import KnownUser
from modules_core.abc.events.on_member_join_abc import OnMemberJoinABC
from modules_core.abc.events.on_message_abc import OnMessageABC
from modules_core.abc.events.on_voice_state_update_abc import \
@ -19,6 +23,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMessageABC, OnVoiceStateUpdateABC):
logger: LoggerABC,
clients: ClientRepositoryABC,
servers: ServerRepositoryABC,
known_users: KnownUserRepositoryABC,
bot: BotServiceABC,
db: DatabaseContextABC
):
@ -26,6 +31,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMessageABC, OnVoiceStateUpdateABC):
self._logger = logger
self._clients = clients
self._servers = servers
self._known_users = known_users
self._bot = bot
self._db = db
@ -49,7 +55,22 @@ class Base(ModuleABC, OnMemberJoinABC, OnMessageABC, OnVoiceStateUpdateABC):
except Exception as e:
self._logger.error(__name__, f'Cannot edit client {self._bot.user.id}@{g_id}')
async def on_member_join(self, member: discord.Member):
def _check_for_known_user(self, member: Union[discord.User, discord.Member]):
self._logger.debug(__name__, f'Check if user is already known {member}')
try:
user = self._known_users.find_user_by_discord_id(member.id)
if user is not None:
return
self._logger.debug(__name__, f'Add user: {member.id}')
self._known_users.add_user(KnownUser(member.id))
self._db.save_changes()
except Exception as e:
self._logger.error(__name__, f'Cannot get user {member.id}')
async def on_member_join(self, member: Union[discord.User, discord.Member]):
self._check_for_known_user(member)
# self._check_for_user(member)
self._logger.debug(__name__, f'Module {type(self)} started')
async def on_message(self, message: discord.Message):
@ -57,4 +78,6 @@ class Base(ModuleABC, OnMemberJoinABC, OnMessageABC, OnVoiceStateUpdateABC):
self._logger.debug(__name__, f'Module {type(self)} started')
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
# todo: save ontime
# todo: add xp to user when he goes offline
self._logger.debug(__name__, f'Module {type(self)} started')