Added logic to save bot data
This commit is contained in:
parent
853c1262e7
commit
0662be7b79
@ -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')
|
||||
|
Reference in New Issue
Block a user