Added info command
This commit is contained in:
91
src/modules/base/command/info_command.py
Normal file
91
src/modules/base/command/info_command.py
Normal file
@@ -0,0 +1,91 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.command import DiscordCommandABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
from cpl_translation import TranslatePipe
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
import bot
|
||||
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.model.embed_description import EmbedDescription
|
||||
from bot_core.model.embed_description_field import EmbedDescriptionField
|
||||
from bot_core.service.embed_service import EmbedService
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class InfoCommand(DiscordCommandABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: LoggerABC,
|
||||
message_service: MessageServiceABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
client_utils: ClientUtilsServiceABC,
|
||||
translate: TranslatePipe
|
||||
):
|
||||
DiscordCommandABC.__init__(self)
|
||||
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._message_service = message_service
|
||||
self._bot = bot
|
||||
self._client_utils = client_utils
|
||||
self._t = translate
|
||||
|
||||
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||
|
||||
@commands.command()
|
||||
async def info(self, ctx: Context):
|
||||
self._logger.debug(__name__, f'Received command info {ctx}')
|
||||
self._client_utils.received_command(ctx.guild.id)
|
||||
client = self._client_utils.get_client(self._bot.user.id, ctx.guild.id)
|
||||
settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{ctx.guild.id}')
|
||||
|
||||
embed_description = EmbedDescription(
|
||||
self._t.transform('modules.base.user_info.title'),
|
||||
self._t.transform('modules.base.user_info.description'),
|
||||
'',
|
||||
'ef9d0d',
|
||||
List(EmbedDescriptionField),
|
||||
self._t.transform('modules.base.user_info.footer'),
|
||||
)
|
||||
|
||||
embed_description.fields.append(
|
||||
EmbedDescriptionField(self._t.transform('modules.base.user_info.fields.version'), bot.__version__, True)
|
||||
)
|
||||
start_time = self._config.get_configuration('Bot_StartTime')
|
||||
ontime = round((datetime.now() - datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S.%f')).total_seconds() / 3600, 2)
|
||||
embed_description.fields.append(
|
||||
EmbedDescriptionField(self._t.transform('modules.base.user_info.fields.ontime'), f'{ontime}h', True)
|
||||
)
|
||||
embed_description.fields.append(
|
||||
EmbedDescriptionField(self._t.transform('modules.base.user_info.fields.sent_message_count'), client.sent_message_count, True)
|
||||
)
|
||||
embed_description.fields.append(
|
||||
EmbedDescriptionField(self._t.transform('modules.base.user_info.fields.received_message_count'), client.received_message_count, True)
|
||||
)
|
||||
embed_description.fields.append(
|
||||
EmbedDescriptionField(self._t.transform('modules.base.user_info.fields.deleted_message_count'), client.deleted_message_count, True)
|
||||
)
|
||||
embed_description.fields.append(
|
||||
EmbedDescriptionField(self._t.transform('modules.base.user_info.fields.received_command_count'), client.received_command_count, True)
|
||||
)
|
||||
embed_description.fields.append(
|
||||
EmbedDescriptionField(self._t.transform('modules.base.user_info.fields.moved_users_count'), client.moved_users_count, False)
|
||||
)
|
||||
modules = ['Base', 'BootLog', 'Database', 'Permission']
|
||||
embed_description.fields.append(
|
||||
EmbedDescriptionField(self._t.transform('modules.base.user_info.fields.modules'), '\n'.join(modules), False)
|
||||
)
|
||||
|
||||
await self._message_service.send_ctx_msg(
|
||||
ctx,
|
||||
EmbedService.get_embed(embed_description)
|
||||
)
|
||||
self._logger.trace(__name__, f'Finished info command')
|
@@ -1,94 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.command import DiscordCommandABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
import bot
|
||||
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class InfoCommandService(DiscordCommandABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: LoggerABC,
|
||||
message_service: MessageServiceABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
client_utils: ClientUtilsServiceABC
|
||||
):
|
||||
DiscordCommandABC.__init__(self)
|
||||
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._message_service = message_service
|
||||
self._bot = bot
|
||||
self._client_utils = client_utils
|
||||
|
||||
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||
|
||||
@commands.command()
|
||||
async def info(self, ctx: Context):
|
||||
#
|
||||
# Todo: Use native embeds!!!
|
||||
#
|
||||
self._logger.debug(__name__, f'Received command info {ctx}')
|
||||
self._client_utils.received_command(ctx.guild.id)
|
||||
client = self._client_utils.get_client(self._bot.user.id, ctx.guild.id)
|
||||
settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{ctx.guild.id}')
|
||||
|
||||
embed_description = EmbedDescription(
|
||||
settings.info_command_message.embed_description.title,
|
||||
settings.info_command_message.embed_description.description,
|
||||
settings.info_command_message.embed_description.url,
|
||||
settings.info_command_message.embed_description.color,
|
||||
List(EmbedDescriptionField),
|
||||
settings.info_command_message.embed_description.footer
|
||||
)
|
||||
|
||||
for i in range(len(settings.info_command_message.embed_description.fields)):
|
||||
settings_field = settings.info_command_message.embed_description.fields[i]
|
||||
field = EmbedDescriptionField(settings_field.name, settings_field.value, settings_field.inline)
|
||||
|
||||
if settings_field.value == '$version':
|
||||
field.value = bot.__version__
|
||||
|
||||
elif settings_field.value == '$ontime':
|
||||
start_time = self._config.get_configuration('Bot_StartTime')
|
||||
ontime = round((datetime.now() - datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S.%f')).total_seconds()/3600, 2)
|
||||
field.value = f'{ontime}h'
|
||||
|
||||
elif settings_field.value == '$sent_message_count':
|
||||
field.value = client.sent_message_count
|
||||
|
||||
elif settings_field.value == '$received_message_count':
|
||||
field.value = client.received_message_count
|
||||
|
||||
elif settings_field.value == '$deleted_message_count':
|
||||
field.value = client.deleted_message_count
|
||||
|
||||
elif settings_field.value == '$received_command_count':
|
||||
field.value = client.received_command_count
|
||||
|
||||
elif settings_field.value == '$moved_users_count':
|
||||
field.value = client.moved_users_count
|
||||
|
||||
elif settings_field.value == '$modules':
|
||||
field.value = ''
|
||||
for module in ModuleABC.__subclasses__():
|
||||
field.value += f'{module.__name__}\n'
|
||||
|
||||
embed_description.fields.append(field)
|
||||
|
||||
await self._message_service.send_ctx_msg(
|
||||
ctx,
|
||||
EmbedService.get_embed(embed_description)
|
||||
)
|
||||
self._logger.trace(__name__, f'Finished info command')
|
Reference in New Issue
Block a user