From c74a74a3c5d27229f4951fab1ff4bdc7db6230dc Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 15 Jan 2022 16:42:41 +0100 Subject: [PATCH 1/3] Changed version --- src/gismo/__init__.py | 4 ++-- src/gismo/gismo.json | 2 +- src/gismo_core/__init__.py | 4 ++-- src/gismo_core/abc/__init__.py | 4 ++-- src/gismo_core/abc/events/__init__.py | 4 ++-- src/gismo_core/configuration/__init__.py | 4 ++-- src/gismo_core/model/__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 | 4 ++-- src/modules/boot_log/__init__.py | 4 ++-- src/modules/database/__init__.py | 4 ++-- src/modules/permission/__init__.py | 4 ++-- src/modules/permission/abc/__init__.py | 4 ++-- src/modules/permission/configuration/__init__.py | 4 ++-- src/modules/permission/service/__init__.py | 4 ++-- 21 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/gismo/__init__.py b/src/gismo/__init__.py index 12f910a..d0125d3 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo/gismo.json b/src/gismo/gismo.json index 8c10343..abc0fa8 100644 --- a/src/gismo/gismo.json +++ b/src/gismo/gismo.json @@ -4,7 +4,7 @@ "Version": { "Major": "0", "Minor": "4", - "Micro": "9" + "Micro": "2" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/gismo_core/__init__.py b/src/gismo_core/__init__.py index bdc3fd6..ccdab72 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_core/abc/__init__.py b/src/gismo_core/abc/__init__.py index 630422f..a117d2a 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_core/abc/events/__init__.py b/src/gismo_core/abc/events/__init__.py index 8314a42..4b91b99 100644 --- a/src/gismo_core/abc/events/__init__.py +++ b/src/gismo_core/abc/events/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core.abc.events' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_core/configuration/__init__.py b/src/gismo_core/configuration/__init__.py index 556c864..e143593 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_core/model/__init__.py b/src/gismo_core/model/__init__.py index c50db08..5aa5f0e 100644 --- a/src/gismo_core/model/__init__.py +++ b/src/gismo_core/model/__init__.py @@ -15,11 +15,11 @@ __title__ = 'gismo_core.model' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_core/service/__init__.py b/src/gismo_core/service/__init__.py index 139c77a..9bf954e 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_data/__init__.py b/src/gismo_data/__init__.py index 1706107..909b6d8 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_data/abc/__init__.py b/src/gismo_data/abc/__init__.py index 4f60495..f3e8629 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_data/migration/__init__.py b/src/gismo_data/migration/__init__.py index 41ed6ea..21869c8 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_data/model/__init__.py b/src/gismo_data/model/__init__.py index be2f569..f6938ee 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/gismo_data/service/__init__.py b/src/gismo_data/service/__init__.py index c15d42d..2d21c01 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/modules/base/__init__.py b/src/modules/base/__init__.py index 740d0e6..f2da2cd 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/modules/base/service/__init__.py b/src/modules/base/service/__init__.py index 3125c3b..b7e2a3e 100644 --- a/src/modules/base/service/__init__.py +++ b/src/modules/base/service/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules.base.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/modules/boot_log/__init__.py b/src/modules/boot_log/__init__.py index aee4cb6..44d79cf 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/modules/database/__init__.py b/src/modules/database/__init__.py index 9a64572..cbb7dd3 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.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/modules/permission/__init__.py b/src/modules/permission/__init__.py index 9fbddf9..e43b96c 100644 --- a/src/modules/permission/__init__.py +++ b/src/modules/permission/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules.permission' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/modules/permission/abc/__init__.py b/src/modules/permission/abc/__init__.py index 58794dc..9f960ac 100644 --- a/src/modules/permission/abc/__init__.py +++ b/src/modules/permission/abc/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules.permission.abc' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/modules/permission/configuration/__init__.py b/src/modules/permission/configuration/__init__.py index f8c0d96..6da26a1 100644 --- a/src/modules/permission/configuration/__init__.py +++ b/src/modules/permission/configuration/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules.permission.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') diff --git a/src/modules/permission/service/__init__.py b/src/modules/permission/service/__init__.py index 245cd87..70ba12e 100644 --- a/src/modules/permission/service/__init__.py +++ b/src/modules/permission/service/__init__.py @@ -15,11 +15,11 @@ __title__ = 'modules.permission.service' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.4.9' +__version__ = '0.4.2' from collections import namedtuple # imports VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='4', micro='9') +version_info = VersionInfo(major='0', minor='4', micro='2') From 4bbb2b5c451dae65a8dd9412fc1fdd12f33e3606 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 15 Jan 2022 18:59:15 +0100 Subject: [PATCH 2/3] Added user-info command & fixed info command --- src/gismo/startup.py | 12 +- src/gismo_core/abc/message_service_abc.py | 2 +- src/gismo_core/model/embed_description.py | 10 +- src/gismo_core/service/message_service.py | 5 +- src/modules/base/base.py | 39 ++--- src/modules/base/base_settings.py | 6 + .../base/service/help_command_service.py | 2 +- .../base/service/info_command_service.py | 46 ++++-- .../base/service/user_info_command_service.py | 133 ++++++++++++++++++ 9 files changed, 215 insertions(+), 40 deletions(-) create mode 100644 src/modules/base/service/user_info_command_service.py diff --git a/src/gismo/startup.py b/src/gismo/startup.py index 827d3d9..430ba58 100644 --- a/src/gismo/startup.py +++ b/src/gismo/startup.py @@ -42,6 +42,7 @@ from modules.base.service.help_command_service import HelpCommandService from modules.base.service.info_command_service import InfoCommandService from modules.base.service.ping_command_service import PingCommandService from modules.base.service.purge_command_service import PurgeCommandService +from modules.base.service.user_info_command_service import UserInfoCommandService from modules.boot_log.boot_log import BootLog from modules.database.database import Database from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -98,11 +99,12 @@ class Startup(StartupABC): services.add_singleton(PermissionServiceABC, PermissionService) # commands - services.add_singleton(CommandABC, PingCommandService) - services.add_singleton(CommandABC, PurgeCommandService) - services.add_singleton(CommandABC, AFKCommandService) - services.add_singleton(CommandABC, HelpCommandService) - services.add_singleton(CommandABC, InfoCommandService) + services.add_transient(CommandABC, PingCommandService) + services.add_transient(CommandABC, PurgeCommandService) + services.add_transient(CommandABC, AFKCommandService) + services.add_transient(CommandABC, HelpCommandService) + services.add_transient(CommandABC, InfoCommandService) + services.add_transient(CommandABC, UserInfoCommandService) # modules services.add_transient(ModuleABC, Database) diff --git a/src/gismo_core/abc/message_service_abc.py b/src/gismo_core/abc/message_service_abc.py index 61a0211..f19e403 100644 --- a/src/gismo_core/abc/message_service_abc.py +++ b/src/gismo_core/abc/message_service_abc.py @@ -24,4 +24,4 @@ class MessageServiceABC(ABC): async def send_dm_message(self, message: Union[str, discord.Embed], receiver: Union[discord.User, discord.Member]): pass @abstractmethod - async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.Embed], file: discord.File = None, is_persistent: bool = False): pass + async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.Embed], file: discord.File = None, is_persistent: bool = False, wait_before_delete: int = None): pass diff --git a/src/gismo_core/model/embed_description.py b/src/gismo_core/model/embed_description.py index 6684ee9..448783c 100644 --- a/src/gismo_core/model/embed_description.py +++ b/src/gismo_core/model/embed_description.py @@ -11,7 +11,7 @@ class EmbedDescription: description: str = None, url: str = None, color: str = None, - fields: List[EmbedDescriptionField] = None, + fields: list[EmbedDescriptionField] = None, footer: str = None ): self._title = title @@ -25,10 +25,18 @@ class EmbedDescription: def title(self) -> str: return self._title + @title.setter + def title(self, value: str): + self._title = value + @property def description(self) -> str: return self._description + @description.setter + def description(self, value: str): + self._description = value + @property def url(self) -> str: return self._url diff --git a/src/gismo_core/service/message_service.py b/src/gismo_core/service/message_service.py index 32d509c..10a9aed 100644 --- a/src/gismo_core/service/message_service.py +++ b/src/gismo_core/service/message_service.py @@ -76,7 +76,7 @@ class MessageService(MessageServiceABC): self._db.save_changes() self._logger.info(__name__, f'Sent message to user {receiver.id}') - async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.Embed], file: discord.File = None, is_persistent: bool = False): + async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.Embed], file: discord.File = None, is_persistent: bool = False, wait_before_delete: int = None): if ctx is None: self._logger.warn(__name__, 'Message context is empty') self._logger.debug(__name__, f'Message: {message}') @@ -95,6 +95,9 @@ class MessageService(MessageServiceABC): self._logger.info(__name__, f'Sent message to channel {ctx.channel.id}') self._clients.append_sent_message_count(self._bot.user.id, ctx.guild.id, 1) self._db.save_changes() + if wait_before_delete is not None: + await asyncio.sleep(wait_before_delete) + if is_persistent: await self.delete_message(ctx.message) return diff --git a/src/modules/base/base.py b/src/modules/base/base.py index 0612208..346c090 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -26,6 +26,7 @@ from modules.base.service.help_command_service import HelpCommandService from modules.base.service.info_command_service import InfoCommandService from modules.base.service.ping_command_service import PingCommandService from modules.base.service.purge_command_service import PurgeCommandService +from modules.base.service.user_info_command_service import UserInfoCommandService from modules.permission.abc.permission_service_abc import PermissionServiceABC from gismo_core.abc.events.on_member_join_abc import OnMemberJoinABC from gismo_core.abc.events.on_member_remove_abc import OnMemberRemoveABC @@ -38,24 +39,25 @@ from gismo_core.abc.module_abc import ModuleABC class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceStateUpdateABC): def __init__( - self, - config: ConfigurationABC, - logger: LoggerABC, - clients: ClientRepositoryABC, - servers: ServerRepositoryABC, - known_users: KnownUserRepositoryABC, - users: UserRepositoryABC, - user_joins: UserJoinedServerRepositoryABC, - user_joins_vc: UserJoinedVoiceChannelRepositoryABC, - bot: BotServiceABC, - db: DatabaseContextABC, - messenger: MessageServiceABC, - permission_service: PermissionServiceABC, - ping_command: PingCommandService, - purge_command: PurgeCommandService, - afk_command: AFKCommandService, - help_command: HelpCommandService, - info_command: InfoCommandService, + self, + config: ConfigurationABC, + logger: LoggerABC, + clients: ClientRepositoryABC, + servers: ServerRepositoryABC, + known_users: KnownUserRepositoryABC, + users: UserRepositoryABC, + user_joins: UserJoinedServerRepositoryABC, + user_joins_vc: UserJoinedVoiceChannelRepositoryABC, + bot: BotServiceABC, + db: DatabaseContextABC, + messenger: MessageServiceABC, + permission_service: PermissionServiceABC, + ping_command: PingCommandService, + purge_command: PurgeCommandService, + afk_command: AFKCommandService, + help_command: HelpCommandService, + info_command: InfoCommandService, + user_info_command: UserInfoCommandService ): self._config = config self._logger = logger @@ -86,6 +88,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._bot.add_cog(afk_command) self._bot.add_cog(help_command) self._bot.add_cog(info_command) + self._bot.add_cog(user_info_command) self._logger.info(__name__, f'Module {type(self)} loaded') diff --git a/src/modules/base/base_settings.py b/src/modules/base/base_settings.py index 859f458..6c76245 100644 --- a/src/modules/base/base_settings.py +++ b/src/modules/base/base_settings.py @@ -25,6 +25,7 @@ class BaseSettings(ConfigurationModelABC): self._afk_command_move_message: str = '' self._help_command_reference_url: str = '' self._info_command_message: EmbedDescriptionSettings = EmbedDescriptionSettings() + self._user_info_command_message: EmbedDescriptionSettings = EmbedDescriptionSettings() @property def welcome_message(self) -> str: @@ -82,6 +83,10 @@ class BaseSettings(ConfigurationModelABC): def info_command_message(self) -> EmbedDescriptionSettings: return self._info_command_message + @property + def user_info_command_message(self) -> EmbedDescriptionSettings: + return self._user_info_command_message + def from_dict(self, settings: dict): try: self._welcome_message = settings['WelcomeMessage'] @@ -99,6 +104,7 @@ class BaseSettings(ConfigurationModelABC): self._afk_command_move_message = settings['AFKCommandMoveMessage'] self._help_command_reference_url = settings['HelpCommandReferenceUrl'] self._info_command_message.from_dict(settings['InfoCommandMessage']) + self._user_info_command_message.from_dict(settings['UserInfoCommandMessage']) 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/help_command_service.py b/src/modules/base/service/help_command_service.py index bcf6b1c..85a2d92 100644 --- a/src/modules/base/service/help_command_service.py +++ b/src/modules/base/service/help_command_service.py @@ -37,4 +37,4 @@ class HelpCommandService(CommandABC): settings: BaseSettings = self._config.get_configuration(f'Base_{ctx.guild.id}') is_persistent = persistent_flag == '--stay' await self._message_service.send_ctx_msg(ctx, settings.help_command_reference_url, is_persistent=is_persistent) - self._logger.trace(__name__, f'Finished ping command') + self._logger.trace(__name__, f'Finished help command') diff --git a/src/modules/base/service/info_command_service.py b/src/modules/base/service/info_command_service.py index 5803f34..9dd32de 100644 --- a/src/modules/base/service/info_command_service.py +++ b/src/modules/base/service/info_command_service.py @@ -12,6 +12,7 @@ from gismo_core.abc.client_utils_service_abc import ClientUtilsServiceABC from gismo_core.abc.command_abc import CommandABC from gismo_core.abc.message_service_abc import MessageServiceABC from gismo_core.abc.module_abc import ModuleABC +from gismo_core.model.embed_description import EmbedDescription from gismo_core.model.embed_description_field import EmbedDescriptionField from gismo_core.service.embed_service import EmbedService from modules.base.base_settings import BaseSettings @@ -41,35 +42,54 @@ class InfoCommandService(CommandABC): async def info(self, ctx: Context): self._logger.debug(__name__, f'Received command info {ctx}') self._client_utils.received_command(ctx.guild.id) - settings: BaseSettings = self._config.get_configuration(f'Base_{ctx.guild.id}') - embed_description = settings.info_command_message.embed_description client = self._client_utils.get_client(self._bot.user.id, ctx.guild.id) + settings: BaseSettings = self._config.get_configuration(f'Base_{ctx.guild.id}') - for i in range(len(embed_description.fields)): - field = embed_description.fields[i] - if field.value == '$version': + 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 = gismo.__version__ - elif field.value == '$ontime': + + 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 field.value == '$sent_message_count': + + elif settings_field.value == '$sent_message_count': field.value = client.sent_message_count - elif field.value == '$received_message_count': + + elif settings_field.value == '$received_message_count': field.value = client.received_message_count - elif field.value == '$deleted_message_count': + + elif settings_field.value == '$deleted_message_count': field.value = client.deleted_message_count - elif field.value == '$received_command_count': + + elif settings_field.value == '$received_command_count': field.value = client.received_command_count - elif field.value == '$moved_users_count': + + elif settings_field.value == '$moved_users_count': field.value = client.moved_users_count - elif field.value == '$modules': + + 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 ping command') + self._logger.trace(__name__, f'Finished info command') diff --git a/src/modules/base/service/user_info_command_service.py b/src/modules/base/service/user_info_command_service.py new file mode 100644 index 0000000..aa3d0f0 --- /dev/null +++ b/src/modules/base/service/user_info_command_service.py @@ -0,0 +1,133 @@ +from datetime import datetime +from typing import Union, Optional + +import discord +from cpl_core.configuration import ConfigurationABC +from cpl_core.logging import LoggerABC +from cpl_query.extension import List +from discord.ext import commands +from discord.ext.commands import Context + +import gismo +from gismo_core.abc.bot_service_abc import BotServiceABC +from gismo_core.abc.client_utils_service_abc import ClientUtilsServiceABC +from gismo_core.abc.command_abc import CommandABC +from gismo_core.abc.message_service_abc import MessageServiceABC +from gismo_core.abc.module_abc import ModuleABC +from gismo_core.model.embed_description import EmbedDescription +from gismo_core.model.embed_description_field import EmbedDescriptionField +from gismo_core.service.embed_service import EmbedService +from gismo_data.abc.server_repository_abc import ServerRepositoryABC +from gismo_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC +from gismo_data.abc.user_repository_abc import UserRepositoryABC +from modules.base.base_settings import BaseSettings +from modules.permission.abc.permission_service_abc import PermissionServiceABC + + +class UserInfoCommandService(CommandABC): + + def __init__( + self, + config: ConfigurationABC, + logger: LoggerABC, + message_service: MessageServiceABC, + bot: BotServiceABC, + client_utils: ClientUtilsServiceABC, + permissions: PermissionServiceABC, + servers: ServerRepositoryABC, + users: UserRepositoryABC, + user_joined_servers: UserJoinedServerRepositoryABC + ): + CommandABC.__init__(self) + + self._config = config + self._logger = logger + self._message_service = message_service + self._bot = bot + self._client_utils = client_utils + self._permissions = permissions + self._servers = servers + self._users = users + self._user_joined_servers = user_joined_servers + + self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') + + @commands.command(name='user-info') + async def user_info(self, ctx: Context, member: Optional[discord.Member] = None, *, wait: int = None): + self._logger.debug(__name__, f'Received command user-info {ctx}:{member},{wait}') + self._client_utils.received_command(ctx.guild.id) + settings: BaseSettings = self._config.get_configuration(f'Base_{ctx.guild.id}') + + if not self._permissions.is_member_moderator(ctx.author): + await self._message_service.send_ctx_msg(ctx, settings.no_permissions_message) + self._logger.trace(__name__, f'Finished purge command') + return + + if member is None or not isinstance(member, discord.Member): + member = ctx.author + + server = self._servers.find_server_by_discord_id(ctx.guild.id) + user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id) + joins = self._user_joined_servers.get_user_joined_servers_by_user_id(user.user_id) + + embed_description = EmbedDescription( + settings.user_info_command_message.embed_description.title.format(member.name), + settings.user_info_command_message.embed_description.description.format(member.name), + settings.user_info_command_message.embed_description.url, + settings.user_info_command_message.embed_description.color, + List(EmbedDescriptionField), + settings.user_info_command_message.embed_description.footer + ) + + for i in range(len(settings.user_info_command_message.embed_description.fields)): + settings_field = settings.user_info_command_message.embed_description.fields[i] + field = EmbedDescriptionField(settings_field.name, settings_field.value, settings_field.inline) + + if settings_field.value == '$id': + field.value = settings_field.value.replace('$id', str(member.id)) + + elif settings_field.value == '$name': + field.value = settings_field.value.replace('$name', member.name) + + elif settings_field.value == '$discord_join': + field.value = settings_field.value.replace('$discord_join', str(member.created_at)) + + elif settings_field.value == '$last_join': + field.value = settings_field.value.replace('$last_join', str(member.joined_at)) + + elif settings_field.value == '$xp': + field.value = settings_field.value.replace('$xp', str(user.xp)) + + elif settings_field.value == '$roles': + roles = '' + for role in member.roles: + roles += f'{role.name}\n' + field.value = settings_field.value.replace('$roles', roles) + + elif settings_field.value == '$joins': + joins_string = '' + for join in joins: + joins_string += f'{join.joined_on}\n' + field.value = settings_field.value.replace('$joins', joins_string) + + elif settings_field.value == '$leavings': + leavings_string = '' + for join in joins: + if join.leaved_on is None: + if leavings_string == '': + leavings_string = '/' + continue + leavings_string += f'{join.leaved_on}\n' + field.value = settings_field.value.replace('$leavings', leavings_string) + + elif settings_field.value == '$warnings': + field.value = 'Not Implemented yet' + + embed_description.fields.append(field) + + await self._message_service.send_ctx_msg( + ctx, + EmbedService.get_embed(embed_description), + wait_before_delete=wait + ) + self._logger.trace(__name__, f'Finished user-info command') From db175b5b285c97096df415d62a3bef0bc60db735 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 15 Jan 2022 18:59:32 +0100 Subject: [PATCH 3/3] Updated config --- src/gismo/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gismo/config b/src/gismo/config index 83fd51a..2d25643 160000 --- a/src/gismo/config +++ b/src/gismo/config @@ -1 +1 @@ -Subproject commit 83fd51adff8a99af2ef3456542901ec78d4e1946 +Subproject commit 2d25643aa1f0d2ec55f88b7b8f54be77f596dd5f