diff --git a/src/modules/base/base.py b/src/modules/base/base.py index 09a8ac4..1d851bc 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Union +from typing import Union, Optional import discord from cpl_core.configuration import ConfigurationABC @@ -78,19 +78,19 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS def _get_config(self, g_id: int) -> BaseSettings: return self._config.get_configuration(f'{type(self).__name__}_{g_id}') - def _apppend_received_message_count(self, g_id: int): + def _append_received_message_count(self, g_id: int): try: - self._clients.apppend_received_message_count(self._bot.user.id, g_id, 1) + self._clients.append_received_message_count(self._bot.user.id, g_id, 1) self._db.save_changes() except Exception as e: - self._logger.error(__name__, f'Cannot edit client {self._bot.user.id}@{g_id}') + self._logger.error(__name__, f'Cannot edit client {self._bot.user.id}@{g_id}', e) - def _apppend_deleted_message_count(self, g_id: int): + def _append_deleted_message_count(self, g_id: int): try: - self._clients.apppend_received_message_count(self._bot.user.id, g_id, 1) + self._clients.append_received_message_count(self._bot.user.id, g_id, 1) self._db.save_changes() except Exception as e: - self._logger.error(__name__, f'Cannot edit client {self._bot.user.id}@{g_id}') + self._logger.error(__name__, f'Cannot edit client {self._bot.user.id}@{g_id}', e) def _check_for_known_user(self, member: Union[discord.User, discord.Member]): self._logger.debug(__name__, f'Check if user is already known {member}') @@ -154,7 +154,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._logger.error(__name__, f'Cannot get user {member.id}', e) def _update_voice_state(self, joined: bool, dc_user_id: int, dc_channel_id: int, server: Server): - user: User = None + user: Optional[User] = None try: user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.server_id) except Exception as e: @@ -198,7 +198,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._logger.error(__name__, f'Cannot get server {message.guild.id}', e) return - user: User = None + user: Optional[User] = None try: user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.server_id) except Exception as e: @@ -211,7 +211,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS settings: BaseSettings = self._get_config(message.guild.id) old_xp = user.xp - user.xp += settings._xp_per_message + user.xp += settings.xp_per_message self._users.update_user(user) self._db.save_changes() @@ -230,7 +230,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._logger.debug(__name__, f'Module {type(self)} started') if message is None or message.guild is None: return - self._apppend_received_message_count(message.guild.id) + self._append_received_message_count(message.guild.id) if not message.author.bot: self._handle_message_for_xp(message) @@ -238,34 +238,33 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): self._logger.debug(__name__, f'Module {type(self)} started') self._logger.trace(__name__, f'Detected on_voice_state_update {member.id} from {before} to {after}') - u: discord.User = member settings: BaseSettings = self._get_config(member.guild.id) server = self._servers.get_server_by_discord_id(member.guild.id) try: # join if before.channel is None and after.channel is not None and after.channel.id not in settings.afk_channel_ids: - self._logger.trace(__name__, f'User {u.id} joined {after.channel}') + self._logger.trace(__name__, f'User {member.id} joined {after.channel}') self._update_voice_state(True, member.id, after.channel.id, server) # leave elif before.channel is not None and after.channel is None and before.channel.id not in settings.afk_channel_ids: - self._logger.trace(__name__, f'User {u.id} left {before.channel}') + self._logger.trace(__name__, f'User {member.id} left {before.channel}') self._update_voice_state(False, member.id, before.channel.id, server) # channel to channel elif before.channel is not None and after.channel is not None: # joined if before.channel.id in settings.afk_channel_ids and after.channel.id not in settings.afk_channel_ids: - self._logger.trace(__name__, f'User {u.id} joined {after.channel}') + self._logger.trace(__name__, f'User {member.id} joined {after.channel}') self._update_voice_state(True, member.id, after.channel.id, server) # left elif after.channel.id in settings.afk_channel_ids and before.channel.id not in settings.afk_channel_ids: - self._logger.trace(__name__, f'User {u.id} left {before.channel}') + self._logger.trace(__name__, f'User {member.id} left {before.channel}') self._update_voice_state(False, member.id, before.channel.id, server) else: - self._logger.trace(__name__, f'User {u.id} switched to {after.channel}') + self._logger.trace(__name__, f'User {member.id} switched to {after.channel}') except Exception as e: - self._logger.error(__name__, f'Cannot handle voice state for user {u.id}', e) + self._logger.error(__name__, f'Cannot handle voice state for user {member.id}', e) diff --git a/src/modules/base/base_settings.py b/src/modules/base/base_settings.py index 87e2843..300af49 100644 --- a/src/modules/base/base_settings.py +++ b/src/modules/base/base_settings.py @@ -78,8 +78,8 @@ class BaseSettings(ConfigurationModelABC): self._max_voice_state_hours = int(settings['MaxVoiceStateHours']) self._xp_per_message = int(settings['XpPerMessage']) self._xp_per_ontime_hour = int(settings['XpPerOntimeHour']) - for id in settings['AFKChannelIds']: - self._afk_channel_ids.append(int(id)) + for index in settings['AFKChannelIds']: + self._afk_channel_ids.append(int(index)) self._purge_message = settings['PurgeMessage'] self._no_permissions_message = settings['NoPermissionsMessage'] self._afk_command_channel_id = settings['AFKCommandChannelId'] diff --git a/src/modules/base/service/base_command_service.py b/src/modules/base/service/base_command_service.py index e88bb60..5c2d7ff 100644 --- a/src/modules/base/service/base_command_service.py +++ b/src/modules/base/service/base_command_service.py @@ -53,7 +53,7 @@ class BaseCommandService(CommandABC): settings: BaseSettings = self._config.get_configuration(f'Base_{ctx.guild.id}') server_settings: ServerSettings = self._config.get_configuration(f'DSERVER_{ctx.guild.id}') - if (not self._permissions.is_member_moderator(ctx.author)): + if not self._permissions.is_member_moderator(ctx.author): await self._message_service.send_ctx_msg(ctx, settings.no_permissions_message) self._logger.trace(__name__, f'Finished purge command') return diff --git a/src/modules/permission/abc/permission_service_abc.py b/src/modules/permission/abc/permission_service_abc.py index cbfde25..6265cca 100644 --- a/src/modules/permission/abc/permission_service_abc.py +++ b/src/modules/permission/abc/permission_service_abc.py @@ -32,7 +32,7 @@ class PermissionServiceABC(ABC): def get_moderators(self, g_id: int) -> list[discord.Member]: pass @abstractmethod - def is_member_admin(member: discord.Member) -> bool: pass + def is_member_admin(self, member: discord.Member) -> bool: pass @abstractmethod - def is_member_moderator(member: discord.Member) -> bool: pass + def is_member_moderator(self, member: discord.Member) -> bool: pass