Added more data containers

This commit is contained in:
Sven Heidemann 2022-09-12 22:18:49 +02:00
parent fc63f3616e
commit 53fe437100
11 changed files with 65 additions and 13 deletions

View File

@ -1,7 +1,9 @@
import discord import discord
from cpl_discord.container.container import Container 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 from cpl_query.extension import List
@ -9,3 +11,11 @@ class CategoryChannel(discord.CategoryChannel, Container):
def __init__(self, _t: discord.CategoryChannel): def __init__(self, _t: discord.CategoryChannel):
Container.__init__(self, _t, 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))

View File

@ -1,3 +1,4 @@
from abc import abstractmethod
from typing import Callable from typing import Callable

View File

@ -6,7 +6,7 @@ from cpl_discord.container.member import Member
from cpl_discord.container.role import Role from cpl_discord.container.role import Role
from cpl_discord.container.text_channel import TextChannel from cpl_discord.container.text_channel import TextChannel
from cpl_discord.container.voice_channel import VoiceChannel 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 from cpl_query.extension import List

View File

@ -1,11 +1,16 @@
import discord import discord
from cpl_discord.container.container import Container from cpl_discord.container.container import Container
from cpl_discord.helper.ToContainersConverter import ToContainersConverter from cpl_discord.helper.to_containers_converter import ToContainersConverter
from cpl_query.extension import List from cpl_query.extension.list import List
class Member(discord.Member, Container): class Member(discord.Member, Container):
def __init__(self, _t: discord.Member): def __init__(self, _t: discord.Member):
Container.__init__(self, _t, 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))

View File

@ -1,9 +1,9 @@
import discord import discord
from cpl_discord.container.container import Container from cpl_discord.container.container import Container
from cpl_discord.container.member import Member
from cpl_discord.helper.ToContainersConverter import ToContainersConverter from cpl_discord.helper.to_containers_converter import ToContainersConverter
from cpl_query.extension import List from cpl_query.extension.list import List
class Role(discord.Role, Container): class Role(discord.Role, Container):
@ -12,5 +12,6 @@ class Role(discord.Role, Container):
Container.__init__(self, _t, Role) Container.__init__(self, _t, Role)
@property @property
def members(self) -> List[discord.Member]: def members(self) -> List['Member']:
return List(discord.Member, ToContainersConverter.convert(self._object.members, Member)) from cpl_discord.container.member import Member
return List(Member, ToContainersConverter.convert(self._object.members, Member))

View File

@ -1,7 +1,9 @@
import discord import discord
from cpl_discord.container.container import Container 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 from cpl_query.extension import List
@ -9,3 +11,11 @@ class TextChannel(discord.TextChannel, Container):
def __init__(self, _t: discord.TextChannel): def __init__(self, _t: discord.TextChannel):
Container.__init__(self, _t, 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))

View File

@ -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))

View File

@ -1,7 +1,8 @@
import discord import discord
from cpl_discord.container.container import Container 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 from cpl_query.extension import List
@ -9,3 +10,7 @@ class VoiceChannel(discord.VoiceChannel, Container):
def __init__(self, _t: discord.VoiceChannel): def __init__(self, _t: discord.VoiceChannel):
Container.__init__(self, _t, VoiceChannel) Container.__init__(self, _t, VoiceChannel)
@property
def members(self) -> List[Member]:
return List(Member, ToContainersConverter.convert(self._object.members, Member))

View File

@ -6,7 +6,7 @@ from cpl_core.environment import ApplicationEnvironmentABC
from cpl_core.logging import LoggerABC, LoggingSettings, LoggingLevelEnum from cpl_core.logging import LoggerABC, LoggingSettings, LoggingLevelEnum
from cpl_discord.configuration.discord_bot_settings import DiscordBotSettings from cpl_discord.configuration.discord_bot_settings import DiscordBotSettings
from cpl_discord.container.guild import Guild 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_bot_service_abc import DiscordBotServiceABC
from cpl_discord.service.discord_service_abc import DiscordServiceABC from cpl_discord.service.discord_service_abc import DiscordServiceABC
from cpl_query.extension.list import List from cpl_query.extension.list import List

View File

@ -22,10 +22,14 @@ class OnReadyEvent(OnReadyABC):
for r in g.roles: for r in g.roles:
self._log('--Role', r, type(r)) self._log('--Role', r, type(r))
for rm in r.members: for rm in r.members:
self._log('---Rolemembers', rm, type(rm)) self._log('---Rolemember', rm, type(rm))
for m in g.members: for m in g.members:
self._log('--Member', m, type(m)) 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)) select = self._bot.guilds.select(lambda guild: (guild.name, guild.id))
self._logger.warn(__name__, f'Does cpl.query select work? {select}') self._logger.warn(__name__, f'Does cpl.query select work? {select}')