Improved info commands

This commit is contained in:
Sven Heidemann 2022-07-17 14:40:11 +02:00
parent aa929de8d7
commit 6739b9744e
7 changed files with 30 additions and 45 deletions

View File

@ -10,6 +10,7 @@ from cpl_core.environment import ApplicationEnvironment
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
from bot_core.service.client_utils_service import ClientUtilsService
from bot_core.service.message_service import MessageService
from bot_data.abc.client_repository_abc import ClientRepositoryABC
@ -64,6 +65,9 @@ class Startup(StartupABC):
services.add_transient(MessageServiceABC, MessageService)
services.add_transient(ClientUtilsServiceABC, ClientUtilsService)
# pipes
services.add_transient(DateTimeOffsetPipe)
# module services
services.add_singleton(PermissionServiceABC, PermissionService)

View File

@ -2,7 +2,8 @@
"common": {
"hello_world": "Hallo Welt",
"bot_has_no_permission_message": "Ey!!!\nWas soll das?\nIch habe keine Berechtigungen :(\nScheiß System...",
"no_permission_message": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯"
"no_permission_message": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯",
"not_implemented_yet": "Ey Alter, das kann ich noch nicht..."
},
"modules": {
"base": {

View File

@ -1,26 +1 @@
# -*- coding: utf-8 -*-
"""
bot Keksdose bot
~~~~~~~~~~~~~~~~~~~
Discord bot for the Keksdose discord Server
:copyright: (c) 2022 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = 'bot_core'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
__version__ = '1.0.0.dev1'
from collections import namedtuple
# imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='1', minor='0', micro='0.dev1')
# imports

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,11 @@
from datetime import datetime
from cpl_core.pipes.pipe_abc import PipeABC
class DateTimeOffsetPipe(PipeABC):
def __init__(self): pass
def transform(self, value: datetime, *args):
return value.strftime('%Y-%m-%d %H:%M')

View File

@ -5,7 +5,6 @@ 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
@ -13,10 +12,6 @@ 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):

View File

@ -5,20 +5,16 @@ 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
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 bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC
from modules.base.configuration.base_server_settings import BaseServerSettings
from modules.permission.abc.permission_service_abc import PermissionServiceABC
@ -35,7 +31,8 @@ class UserInfoCommand(DiscordCommandABC):
servers: ServerRepositoryABC,
users: UserRepositoryABC,
user_joined_servers: UserJoinedServerRepositoryABC,
translate: TranslatePipe
translate: TranslatePipe,
date: DateTimeOffsetPipe
):
DiscordCommandABC.__init__(self)
@ -49,6 +46,7 @@ class UserInfoCommand(DiscordCommandABC):
self._users = users
self._user_joined_servers = user_joined_servers
self._t = translate
self._date = date
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
@ -70,15 +68,15 @@ class UserInfoCommand(DiscordCommandABC):
joins = self._user_joined_servers.get_user_joined_servers_by_user_id(user.user_id)
embed = discord.Embed(
title=self._t.transform('modules.base.user_info.title'),
description=self._t.transform('modules.base.user_info.description'),
title=member.name,
description=member.name,
color=int('ef9d0d', 16)
)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.id'), value=member.id)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.name'), value=member.name)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.discord_join'), value=member.created_at, inline=False)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.last_join'), value=member.joined_at, inline=False)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.discord_join'), value=self._date.transform(member.created_at), inline=False)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.last_join'), value=self._date.transform(member.joined_at), inline=False)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.xp'), value=str(user.xp))
roles = ''
@ -88,7 +86,7 @@ class UserInfoCommand(DiscordCommandABC):
joins_string = ''
for join in joins:
joins_string += f'{join.joined_on}\n'
joins_string += f'{self._date.transform(join.joined_on)}\n'
embed.add_field(name=self._t.transform('modules.base.user_info.fields.joins'), value=joins_string)
lefts_string = ''
@ -97,9 +95,9 @@ class UserInfoCommand(DiscordCommandABC):
if lefts_string == '':
lefts_string = '/'
continue
lefts_string += f'{join.leaved_on}\n'
lefts_string += f'{self._date.transform(join.leaved_on)}\n'
embed.add_field(name=self._t.transform('modules.base.user_info.fields.lefts'), value=lefts_string)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.warnings'), value='Not Implemented yet', inline=False)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.warnings'), value=self._t.transform('common.not_implemented_yet'), inline=False)
await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait)
self._logger.trace(__name__, f'Finished user-info command')