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