From c9a5a64c7b8125120c2e0c895982addc551cbe34 Mon Sep 17 00:00:00 2001 From: Cora Cordes Date: Thu, 6 Jan 2022 21:14:20 +0100 Subject: [PATCH 1/4] Changed version --- cpl-workspace.json | 12 ++++++++---- src/gismo/__init__.py | 4 ++-- src/gismo/gismo.json | 4 ++-- src/gismo_core/__init__.py | 4 ++-- src/gismo_core/abc/__init__.py | 4 ++-- src/gismo_core/configuration/__init__.py | 4 ++-- src/gismo_core/service/__init__.py | 4 ++-- src/gismo_data/__init__.py | 4 ++-- src/gismo_data/abc/__init__.py | 4 ++-- src/gismo_data/migration/__init__.py | 4 ++-- src/gismo_data/model/__init__.py | 4 ++-- src/gismo_data/service/__init__.py | 4 ++-- src/modules/base/__init__.py | 4 ++-- src/modules/base/service/__init__.py | 24 ++++++++++++++++++++++++ src/modules/boot_log/__init__.py | 4 ++-- src/modules/database/__init__.py | 4 ++-- 16 files changed, 60 insertions(+), 32 deletions(-) diff --git a/cpl-workspace.json b/cpl-workspace.json index 2684182..81d4750 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -14,15 +14,19 @@ "permission": "src/modules/permission/permission.json" }, "Scripts": { - "build-start": "cd src/gismo_cli; echo 'gismo-cli:'; cpl build; cd ../gismo; echo 'gismo:'; cpl build; cd ../../dist/gismo/build/gismo; bash gismo", + "build-gismo": "cd src/gismo; echo 'gismo:'; cpl build; cd ../../;", + "build-gismo-cli": "cd src/gismo_cli; echo 'gismo-cli:'; cpl build; cd ../../;", + "build-start": "cpl build-gismo-cli; cpl build-gismo; cd dist/gismo/build/gismo; bash gismo", "bs": "cpl build-start", + "build-all": "cpl build-gismo-cli; cpl build-gismo;", + "ba": "cpl build-all", "pre-build": "cd ../gismo_cli; echo 'gismo-cli:'; cpl build; echo 'gismo:'", "pre-start": "if [ -z $GISMO_ENVIRONMENT ]; then echo '!WARNING! You should start with the right environment!\nRun cpl start-ENV\nSee workspace for more details.'; sleep 2; fi", - "pre-dev": "echo 'development:'; ", + "pre-dev": "echo 'development:';", "dev": "export GISMO_ENVIRONMENT=development; export GISMO_NAME=Gismo-dev; cpl start", - "pre-test": "echo 'staging:'; ", + "pre-test": "echo 'staging:';", "test": "export GISMO_ENVIRONMENT=staging; export GISMO_NAME=Gismo-test; cpl start", - "pre-prod": "echo 'production:'; ", + "pre-prod": "echo 'production:';", "prod": "export GISMO_ENVIRONMENT=production; export GISMO_NAME=Gismo-prod; cpl start" } } diff --git a/src/gismo/__init__.py b/src/gismo/__init__.py index e2d1c61..a9bad85 100644 --- a/src/gismo/__init__.py +++ b/src/gismo/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/gismo/gismo.json b/src/gismo/gismo.json index 37f5aaa..d613dc5 100644 --- a/src/gismo/gismo.json +++ b/src/gismo/gismo.json @@ -3,8 +3,8 @@ "Name": "gismo", "Version": { "Major": "0", - "Minor": "3", - "Micro": "0" + "Minor": "4", + "Micro": "3" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/gismo_core/__init__.py b/src/gismo_core/__init__.py index 98c9727..dd03aac 100644 --- a/src/gismo_core/__init__.py +++ b/src/gismo_core/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/gismo_core/abc/__init__.py b/src/gismo_core/abc/__init__.py index 2ef29e0..f919836 100644 --- a/src/gismo_core/abc/__init__.py +++ b/src/gismo_core/abc/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/gismo_core/configuration/__init__.py b/src/gismo_core/configuration/__init__.py index 256c23c..7e7c53e 100644 --- a/src/gismo_core/configuration/__init__.py +++ b/src/gismo_core/configuration/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/gismo_core/service/__init__.py b/src/gismo_core/service/__init__.py index 016bce9..ce98b94 100644 --- a/src/gismo_core/service/__init__.py +++ b/src/gismo_core/service/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/gismo_data/__init__.py b/src/gismo_data/__init__.py index f8cc746..473f4b1 100644 --- a/src/gismo_data/__init__.py +++ b/src/gismo_data/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_data' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/gismo_data/abc/__init__.py b/src/gismo_data/abc/__init__.py index 1845f2d..2f3dd20 100644 --- a/src/gismo_data/abc/__init__.py +++ b/src/gismo_data/abc/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_data.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/gismo_data/migration/__init__.py b/src/gismo_data/migration/__init__.py index ff6ccc6..5c6766b 100644 --- a/src/gismo_data/migration/__init__.py +++ b/src/gismo_data/migration/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_data.migration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/gismo_data/model/__init__.py b/src/gismo_data/model/__init__.py index 7009a86..204bee2 100644 --- a/src/gismo_data/model/__init__.py +++ b/src/gismo_data/model/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_data.model' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/gismo_data/service/__init__.py b/src/gismo_data/service/__init__.py index 76e0775..d2d0536 100644 --- a/src/gismo_data/service/__init__.py +++ b/src/gismo_data/service/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_data.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/modules/base/__init__.py b/src/modules/base/__init__.py index 307aa80..ea3ab60 100644 --- a/src/modules/base/__init__.py +++ b/src/modules/base/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules.base' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/modules/base/service/__init__.py b/src/modules/base/service/__init__.py index 425ab6c..0644214 100644 --- a/src/modules/base/service/__init__.py +++ b/src/modules/base/service/__init__.py @@ -1 +1,25 @@ +# -*- coding: utf-8 -*- + +""" +gismo sh-edraft Gismo +~~~~~~~~~~~~~~~~~~~ + +sh-edraft Dicord bot Gismo + +:copyright: (c) 2021 - 2022 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'modules.base.service' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' +__version__ = '0.4.3' + +from collections import namedtuple + # imports + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/modules/boot_log/__init__.py b/src/modules/boot_log/__init__.py index d6b52d8..9a8fe2b 100644 --- a/src/modules/boot_log/__init__.py +++ b/src/modules/boot_log/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules.boot_log' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') diff --git a/src/modules/database/__init__.py b/src/modules/database/__init__.py index 3e9733f..10dc994 100644 --- a/src/modules/database/__init__.py +++ b/src/modules/database/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules.database' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' +__version__ = '0.4.3' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') +version_info = VersionInfo(major='0', minor='4', micro='3') From dc025170e133cb1e030b0af7f73ae2166a380711 Mon Sep 17 00:00:00 2001 From: Cora Cordes Date: Fri, 7 Jan 2022 13:17:00 +0100 Subject: [PATCH 2/4] Added settings --- src/gismo/config/base.json | 3 ++- src/modules/base/base_settings.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gismo/config/base.json b/src/gismo/config/base.json index 631149a..29066cc 100644 --- a/src/gismo/config/base.json +++ b/src/gismo/config/base.json @@ -11,6 +11,7 @@ 910199452915093594 ], "PurgeMessage": "Ja mein Herr, ich lösche alle Nachrichten!", - "NoPermissionsMessage": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯" + "NoPermissionsMessage": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯", + "AFKCommandChannelId": 910199452915093594 } } \ No newline at end of file diff --git a/src/modules/base/base_settings.py b/src/modules/base/base_settings.py index fbd7eaf..c2346d4 100644 --- a/src/modules/base/base_settings.py +++ b/src/modules/base/base_settings.py @@ -18,6 +18,7 @@ class BaseSettings(ConfigurationModelABC): self._afk_channel_ids: list[int] = [] self._purge_message: str = '' self._no_permissions_message: str = '' + self._afk_command_channel_id: int = 0 @property def welcome_message(self) -> str: @@ -55,6 +56,10 @@ class BaseSettings(ConfigurationModelABC): def no_permissions_message(self) -> str: return self._no_permissions_message + @property + def afk_command_channel_ids(self) -> int: + return self._afk_command_channel_id + def from_dict(self, settings: dict): try: self._welcome_message = settings['WelcomeMessage'] @@ -67,6 +72,7 @@ class BaseSettings(ConfigurationModelABC): self._afk_channel_ids.append(int(id)) self._purge_message = settings['PurgeMessage'] self._no_permissions_message = settings['NoPermissionsMessage'] + self._afk_command_channel_id = settings['AFKCommandChannelId'] except Exception as e: Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') From 853c1262e7ffbce820997b82d0947419033597e4 Mon Sep 17 00:00:00 2001 From: Cora Cordes Date: Fri, 7 Jan 2022 14:35:27 +0100 Subject: [PATCH 3/4] Added logic to move user to afk channel --- src/gismo/config/base.json | 4 ++- .../configuration/server_settings.py | 8 ++++- src/modules/base/base.py | 8 ++--- src/modules/base/base_settings.py | 14 ++++++++- .../base/service/base_command_service.py | 29 ++++++++++++++++++- 5 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/gismo/config/base.json b/src/gismo/config/base.json index 29066cc..eba4860 100644 --- a/src/gismo/config/base.json +++ b/src/gismo/config/base.json @@ -12,6 +12,8 @@ ], "PurgeMessage": "Ja mein Herr, ich lösche alle Nachrichten!", "NoPermissionsMessage": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯", - "AFKCommandChannelId": 910199452915093594 + "AFKCommandChannelId": 910199452915093594, + "AFKCommandChannelMissingMessage": "Zu unfähig einem Sprachkanal beizutreten?", + "AFKCommandMoveMessage": "Ich verschiebe dich ja schon... (◔_◔)" } } \ No newline at end of file diff --git a/src/gismo_core/configuration/server_settings.py b/src/gismo_core/configuration/server_settings.py index f4dffc4..ccda195 100644 --- a/src/gismo_core/configuration/server_settings.py +++ b/src/gismo_core/configuration/server_settings.py @@ -11,6 +11,7 @@ class ServerSettings(ConfigurationModelABC): self._id: int = 0 self._message_delete_timer: int = 0 + self._bot_has_no_permission_message: str = '' @property def id(self) -> str: @@ -20,10 +21,15 @@ class ServerSettings(ConfigurationModelABC): def message_delete_timer(self) -> int: return self._message_delete_timer + @property + def bot_has_no_permission_message(self) -> str: + return self._bot_has_no_permission_message + def from_dict(self, settings: dict): try: self._id = int(settings['Id']) - self._message_delete_timer = int(settings['MessageDeleteTimer']) + self._message_delete_timer = int(settings['MessageDeleteTimer']) + self._bot_has_no_permission_message = settings['BotHasNoPermissionMessage'] except Exception as e: Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in settings') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/src/modules/base/base.py b/src/modules/base/base.py index 9666eb9..09a8ac4 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -246,24 +246,24 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS # 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._update_voice_state(True, member.id, after.channel.id, server.server_id) + 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._update_voice_state(False, member.id, before.channel.id, server.server_id) + 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._update_voice_state(True, member.id, after.channel.id, server.server_id) + 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._update_voice_state(False, member.id, before.channel.id, server.server_id) + self._update_voice_state(False, member.id, before.channel.id, server) else: self._logger.trace(__name__, f'User {u.id} switched to {after.channel}') diff --git a/src/modules/base/base_settings.py b/src/modules/base/base_settings.py index c2346d4..87e2843 100644 --- a/src/modules/base/base_settings.py +++ b/src/modules/base/base_settings.py @@ -19,6 +19,8 @@ class BaseSettings(ConfigurationModelABC): self._purge_message: str = '' self._no_permissions_message: str = '' self._afk_command_channel_id: int = 0 + self._afk_command_channel_missing_message: str = '' + self._afk_command_move_message: str = '' @property def welcome_message(self) -> str: @@ -57,9 +59,17 @@ class BaseSettings(ConfigurationModelABC): return self._no_permissions_message @property - def afk_command_channel_ids(self) -> int: + def afk_command_channel_id(self) -> int: return self._afk_command_channel_id + @property + def afk_command_channel_missing_message(self) -> str: + return self._afk_command_channel_missing_message + + @property + def afk_command_move_message(self) -> str: + return self._afk_command_move_message + def from_dict(self, settings: dict): try: self._welcome_message = settings['WelcomeMessage'] @@ -73,6 +83,8 @@ class BaseSettings(ConfigurationModelABC): self._purge_message = settings['PurgeMessage'] self._no_permissions_message = settings['NoPermissionsMessage'] self._afk_command_channel_id = settings['AFKCommandChannelId'] + self._afk_command_channel_missing_message = settings['AFKCommandChannelMissingMessage'] + self._afk_command_move_message = settings['AFKCommandMoveMessage'] except Exception as e: Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/src/modules/base/service/base_command_service.py b/src/modules/base/service/base_command_service.py index 4f41507..93e12c4 100644 --- a/src/modules/base/service/base_command_service.py +++ b/src/modules/base/service/base_command_service.py @@ -1,5 +1,6 @@ import asyncio import discord +from discord.channel import VoiceChannel from discord.ext import commands from discord.ext.commands import Context @@ -50,5 +51,31 @@ class BaseCommandService(CommandABC): await self._message_service.send_ctx_msg(ctx, settings.purge_message) await asyncio.sleep(server_settings.message_delete_timer) - await ctx.channel.purge() + try: + await ctx.channel.purge() + except Exception as e: + self._logger.error(__name__, f'Cannot purge channel {ctx.channel.id}', e) + await self._message_service.send_ctx_msg(ctx, server_settings.bot_has_no_permission_message) + self._logger.trace(__name__, f'Finished purge command') + + @commands.command() + async def afk(self, ctx: Context): + self._logger.debug(__name__, f'Received command afk {ctx}') + settings: BaseSettings = self._config.get_configuration(f'Base_{ctx.guild.id}') + server_settings: ServerSettings = self._config.get_configuration(f'DSERVER_{ctx.guild.id}') + + if ctx.author.voice is None or ctx.author.voice.channel is None: + await self._message_service.send_ctx_msg(ctx, settings.afk_command_channel_missing_message) + self._logger.trace(__name__, f'Finished afk command') + return + + await self._message_service.send_ctx_msg(ctx, settings.afk_command_move_message) + channel: VoiceChannel = ctx.guild.get_channel(settings.afk_command_channel_id) + try: + await ctx.author.move_to(channel) + except Exception as e: + self._logger.error(__name__, f'Cannot purge channel {ctx.channel.id}', e) + await self._message_service.send_ctx_msg(ctx, server_settings.bot_has_no_permission_message) + + self._logger.trace(__name__, f'Finished afk command') From 0662be7b7972cc858864d03f9bb29f613e14dd88 Mon Sep 17 00:00:00 2001 From: Cora Cordes Date: Fri, 7 Jan 2022 14:50:32 +0100 Subject: [PATCH 4/4] Added logic to save bot data --- .../base/service/base_command_service.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/modules/base/service/base_command_service.py b/src/modules/base/service/base_command_service.py index 93e12c4..e88bb60 100644 --- a/src/modules/base/service/base_command_service.py +++ b/src/modules/base/service/base_command_service.py @@ -1,4 +1,5 @@ import asyncio +from cpl_core.database.context.database_context import DatabaseContext import discord from discord.channel import VoiceChannel from discord.ext import commands @@ -6,10 +7,12 @@ from discord.ext.commands import Context from cpl_core.logging import LoggerABC from cpl_core.configuration import ConfigurationABC +from gismo_core.abc.bot_service_abc import BotServiceABC from gismo_core.abc.command_abc import CommandABC from gismo_core.abc.message_service_abc import MessageServiceABC from gismo_core.configuration.server_settings import ServerSettings +from gismo_data.abc.client_repository_abc import ClientRepositoryABC from modules.base.base_settings import BaseSettings from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -21,7 +24,10 @@ class BaseCommandService(CommandABC): logger: LoggerABC, config: ConfigurationABC, message_service: MessageServiceABC, - permissions: PermissionServiceABC + permissions: PermissionServiceABC, + clients: ClientRepositoryABC, + db: DatabaseContext, + bot: BotServiceABC ): CommandABC.__init__(self) @@ -29,6 +35,9 @@ class BaseCommandService(CommandABC): self._config = config self._message_service = message_service self._permissions = permissions + self._clients = clients + self._db = db + self._bot = bot self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') @@ -74,8 +83,13 @@ class BaseCommandService(CommandABC): channel: VoiceChannel = ctx.guild.get_channel(settings.afk_command_channel_id) try: await ctx.author.move_to(channel) + + client = self._clients.get_client_by_discord_id(self._bot.user.id) + client.moved_users_count += 1 + self._clients.update_client(client) + self._db.save_changes() except Exception as e: - self._logger.error(__name__, f'Cannot purge channel {ctx.channel.id}', e) + self._logger.error(__name__, f'Cannot move user {ctx.author.id} to channel {ctx.channel.id}', e) await self._message_service.send_ctx_msg(ctx, server_settings.bot_has_no_permission_message) self._logger.trace(__name__, f'Finished afk command')