From 53fe43710029f01bc4c54279a713ea2481a6b010 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 12 Sep 2022 22:18:49 +0200 Subject: [PATCH] Added more data containers --- src/cpl_discord/container/category_channel.py | 12 +++++++++++- src/cpl_discord/container/container.py | 1 + src/cpl_discord/container/guild.py | 2 +- src/cpl_discord/container/member.py | 9 +++++++-- src/cpl_discord/container/role.py | 11 ++++++----- src/cpl_discord/container/text_channel.py | 12 +++++++++++- src/cpl_discord/container/threads.py | 16 ++++++++++++++++ src/cpl_discord/container/voice_channel.py | 7 ++++++- ...rsConverter.py => to_containers_converter.py} | 0 src/cpl_discord/service/discord_bot_service.py | 2 +- .../src/modules/hello_world/on_ready_event.py | 6 +++++- 11 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 src/cpl_discord/container/threads.py rename src/cpl_discord/helper/{ToContainersConverter.py => to_containers_converter.py} (100%) diff --git a/src/cpl_discord/container/category_channel.py b/src/cpl_discord/container/category_channel.py index 3c9ad3cf..52e93ac9 100644 --- a/src/cpl_discord/container/category_channel.py +++ b/src/cpl_discord/container/category_channel.py @@ -1,7 +1,9 @@ import discord from cpl_discord.container.container import Container -from cpl_discord.helper.ToContainersConverter import ToContainersConverter +from cpl_discord.container.text_channel import TextChannel +from cpl_discord.container.voice_channel import VoiceChannel +from cpl_discord.helper.to_containers_converter import ToContainersConverter from cpl_query.extension import List @@ -9,3 +11,11 @@ class CategoryChannel(discord.CategoryChannel, Container): def __init__(self, _t: discord.CategoryChannel): Container.__init__(self, _t, CategoryChannel) + + @property + def text_channels(self) -> List[TextChannel]: + return List(TextChannel, ToContainersConverter.convert(self._object.text_channels, TextChannel)) + + @property + def voice_channels(self) -> List[VoiceChannel]: + return List(VoiceChannel, ToContainersConverter.convert(self._object.voice_channels, VoiceChannel)) diff --git a/src/cpl_discord/container/container.py b/src/cpl_discord/container/container.py index a32479d6..b55e1d0d 100644 --- a/src/cpl_discord/container/container.py +++ b/src/cpl_discord/container/container.py @@ -1,3 +1,4 @@ +from abc import abstractmethod from typing import Callable diff --git a/src/cpl_discord/container/guild.py b/src/cpl_discord/container/guild.py index b69af4ed..83055d44 100644 --- a/src/cpl_discord/container/guild.py +++ b/src/cpl_discord/container/guild.py @@ -6,7 +6,7 @@ from cpl_discord.container.member import Member from cpl_discord.container.role import Role from cpl_discord.container.text_channel import TextChannel from cpl_discord.container.voice_channel import VoiceChannel -from cpl_discord.helper.ToContainersConverter import ToContainersConverter +from cpl_discord.helper.to_containers_converter import ToContainersConverter from cpl_query.extension import List diff --git a/src/cpl_discord/container/member.py b/src/cpl_discord/container/member.py index 0fe775f3..9f785422 100644 --- a/src/cpl_discord/container/member.py +++ b/src/cpl_discord/container/member.py @@ -1,11 +1,16 @@ import discord from cpl_discord.container.container import Container -from cpl_discord.helper.ToContainersConverter import ToContainersConverter -from cpl_query.extension import List +from cpl_discord.helper.to_containers_converter import ToContainersConverter +from cpl_query.extension.list import List class Member(discord.Member, Container): def __init__(self, _t: discord.Member): Container.__init__(self, _t, Member) + + @property + def roles(self) -> List['Role']: + from cpl_discord.container.role import Role + return List(Role, ToContainersConverter.convert(self._object.roles, Role)) diff --git a/src/cpl_discord/container/role.py b/src/cpl_discord/container/role.py index 27251ef0..74f8c874 100644 --- a/src/cpl_discord/container/role.py +++ b/src/cpl_discord/container/role.py @@ -1,9 +1,9 @@ import discord from cpl_discord.container.container import Container -from cpl_discord.container.member import Member -from cpl_discord.helper.ToContainersConverter import ToContainersConverter -from cpl_query.extension import List + +from cpl_discord.helper.to_containers_converter import ToContainersConverter +from cpl_query.extension.list import List class Role(discord.Role, Container): @@ -12,5 +12,6 @@ class Role(discord.Role, Container): Container.__init__(self, _t, Role) @property - def members(self) -> List[discord.Member]: - return List(discord.Member, ToContainersConverter.convert(self._object.members, Member)) + def members(self) -> List['Member']: + from cpl_discord.container.member import Member + return List(Member, ToContainersConverter.convert(self._object.members, Member)) diff --git a/src/cpl_discord/container/text_channel.py b/src/cpl_discord/container/text_channel.py index 1051a3a5..62347bbf 100644 --- a/src/cpl_discord/container/text_channel.py +++ b/src/cpl_discord/container/text_channel.py @@ -1,7 +1,9 @@ import discord from cpl_discord.container.container import Container -from cpl_discord.helper.ToContainersConverter import ToContainersConverter +from cpl_discord.container.member import Member +from cpl_discord.container.threads import Thread +from cpl_discord.helper.to_containers_converter import ToContainersConverter from cpl_query.extension import List @@ -9,3 +11,11 @@ class TextChannel(discord.TextChannel, Container): def __init__(self, _t: discord.TextChannel): Container.__init__(self, _t, TextChannel) + + @property + def members(self) -> List[discord.Member]: + return List(discord.Member, ToContainersConverter.convert(self._object.members, Member)) + + @property + def threads(self) -> List[Thread]: + return List(Thread, ToContainersConverter.convert(self._object.threads, Thread)) diff --git a/src/cpl_discord/container/threads.py b/src/cpl_discord/container/threads.py new file mode 100644 index 00000000..03b11ac4 --- /dev/null +++ b/src/cpl_discord/container/threads.py @@ -0,0 +1,16 @@ +import discord + +from cpl_discord.container.container import Container +from cpl_discord.container.member import Member +from cpl_discord.helper.to_containers_converter import ToContainersConverter +from cpl_query.extension import List + + +class Thread(discord.Thread, Container): + + def __init__(self, _t: discord.Thread): + Container.__init__(self, _t, Thread) + + @property + def members(self) -> List[Member]: + return List(Member, ToContainersConverter.convert(self._object.members, Member)) diff --git a/src/cpl_discord/container/voice_channel.py b/src/cpl_discord/container/voice_channel.py index ccc5ac4f..805ea4bb 100644 --- a/src/cpl_discord/container/voice_channel.py +++ b/src/cpl_discord/container/voice_channel.py @@ -1,7 +1,8 @@ import discord from cpl_discord.container.container import Container -from cpl_discord.helper.ToContainersConverter import ToContainersConverter +from cpl_discord.container.member import Member +from cpl_discord.helper.to_containers_converter import ToContainersConverter from cpl_query.extension import List @@ -9,3 +10,7 @@ class VoiceChannel(discord.VoiceChannel, Container): def __init__(self, _t: discord.VoiceChannel): Container.__init__(self, _t, VoiceChannel) + + @property + def members(self) -> List[Member]: + return List(Member, ToContainersConverter.convert(self._object.members, Member)) diff --git a/src/cpl_discord/helper/ToContainersConverter.py b/src/cpl_discord/helper/to_containers_converter.py similarity index 100% rename from src/cpl_discord/helper/ToContainersConverter.py rename to src/cpl_discord/helper/to_containers_converter.py diff --git a/src/cpl_discord/service/discord_bot_service.py b/src/cpl_discord/service/discord_bot_service.py index e2928c5e..6b8466d1 100644 --- a/src/cpl_discord/service/discord_bot_service.py +++ b/src/cpl_discord/service/discord_bot_service.py @@ -6,7 +6,7 @@ from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.logging import LoggerABC, LoggingSettings, LoggingLevelEnum from cpl_discord.configuration.discord_bot_settings import DiscordBotSettings from cpl_discord.container.guild import Guild -from cpl_discord.helper.ToContainersConverter import ToContainersConverter +from cpl_discord.helper.to_containers_converter import ToContainersConverter from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC from cpl_discord.service.discord_service_abc import DiscordServiceABC from cpl_query.extension.list import List diff --git a/src/tests/custom/discord/src/modules/hello_world/on_ready_event.py b/src/tests/custom/discord/src/modules/hello_world/on_ready_event.py index 10d3453c..d9a2fd5d 100644 --- a/src/tests/custom/discord/src/modules/hello_world/on_ready_event.py +++ b/src/tests/custom/discord/src/modules/hello_world/on_ready_event.py @@ -22,10 +22,14 @@ class OnReadyEvent(OnReadyABC): for r in g.roles: self._log('--Role', r, type(r)) for rm in r.members: - self._log('---Rolemembers', rm, type(rm)) + self._log('---Rolemember', rm, type(rm)) for m in g.members: self._log('--Member', m, type(m)) + for mr in m.roles: + self._log('--Memberole', mr, type(mr)) + for rm in mr.members: + self._log('---Rolemember', rm, type(rm)) select = self._bot.guilds.select(lambda guild: (guild.name, guild.id)) self._logger.warn(__name__, f'Does cpl.query select work? {select}')