Release 2022.10 #112
@ -15,7 +15,7 @@ __title__ = 'cpl_discord'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -55,4 +55,4 @@ def get_discord_collection(services: 'ServiceCollectionABC') -> 'DiscordCollecti
|
||||
# build-ignore-end
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
|
@ -15,7 +15,7 @@ __title__ = 'cpl_discord.application'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -24,4 +24,4 @@ from collections import namedtuple
|
||||
from .discord_bot_application_abc import DiscordBotApplicationABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
|
@ -15,7 +15,7 @@ __title__ = 'cpl_discord.command'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -25,4 +25,4 @@ from .discord_command_abc import DiscordCommandABC
|
||||
from .discord_commands_meta import DiscordCogMeta
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
|
@ -15,7 +15,7 @@ __title__ = 'cpl_discord.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -24,4 +24,4 @@ from collections import namedtuple
|
||||
from .discord_bot_settings import DiscordBotSettings
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
|
26
src/cpl_discord/container/__init__.py
Normal file
26
src/cpl_discord/container/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-discord sh-edraft Common Python library Discord
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library link between discord.py and CPL
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_discord.container'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
21
src/cpl_discord/container/category_channel.py
Normal file
21
src/cpl_discord/container/category_channel.py
Normal file
@ -0,0 +1,21 @@
|
||||
import discord
|
||||
|
||||
from cpl_discord.container.container import Container
|
||||
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
|
||||
|
||||
|
||||
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))
|
31
src/cpl_discord/container/container.py
Normal file
31
src/cpl_discord/container/container.py
Normal file
@ -0,0 +1,31 @@
|
||||
from abc import abstractmethod
|
||||
from typing import Callable
|
||||
|
||||
|
||||
class Container:
|
||||
|
||||
def __init__(self, _o: object, _t: type):
|
||||
self._object = _o
|
||||
self._type = _t
|
||||
|
||||
def __to_type(_f: Callable, _t: type):
|
||||
def wrapper(*args, **kwargs):
|
||||
result = _f(*args, **kwargs)
|
||||
return _t(result)
|
||||
|
||||
return wrapper
|
||||
|
||||
def __getitem__(self, item):
|
||||
result = self._object[item]
|
||||
if isinstance(result, type(self._guild)):
|
||||
result = self._type(result)
|
||||
return result
|
||||
|
||||
def __getattr__(self, item):
|
||||
result = getattr(self._object, item)
|
||||
if callable(result):
|
||||
result = self.__to_type(result, self._type)
|
||||
return result
|
||||
|
||||
def __repr__(self):
|
||||
return repr(self._object)
|
42
src/cpl_discord/container/guild.py
Normal file
42
src/cpl_discord/container/guild.py
Normal file
@ -0,0 +1,42 @@
|
||||
import discord
|
||||
|
||||
from cpl_discord.container.category_channel import CategoryChannel
|
||||
from cpl_discord.container.container import Container
|
||||
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.to_containers_converter import ToContainersConverter
|
||||
from cpl_query.extension import List
|
||||
|
||||
|
||||
class Guild(discord.Guild, Container):
|
||||
|
||||
def __init__(self, _t: discord.Guild):
|
||||
self._object: discord.Guild = _t
|
||||
|
||||
Container.__init__(self, _t, Guild)
|
||||
|
||||
@property
|
||||
def categories(self) -> List[CategoryChannel]:
|
||||
return List(CategoryChannel, ToContainersConverter.convert(self._object.categories, CategoryChannel))
|
||||
|
||||
@property
|
||||
def members(self) -> List[Member]:
|
||||
return List(Member, ToContainersConverter.convert(self._object.members, Member))
|
||||
|
||||
@property
|
||||
def roles(self) -> List[Role]:
|
||||
return List(Role, ToContainersConverter.convert(self._object.roles, Role))
|
||||
|
||||
@property
|
||||
def text_channels(self) -> List[TextChannel]:
|
||||
return List(TextChannel, ToContainersConverter.convert(self._object.text_channels, TextChannel))
|
||||
|
||||
@property
|
||||
def threads(self) -> List[TextChannel]:
|
||||
return List(TextChannel, ToContainersConverter.convert(self._object.threads, TextChannel))
|
||||
|
||||
@property
|
||||
def voice_channels(self) -> List[VoiceChannel]:
|
||||
return List(VoiceChannel, ToContainersConverter.convert(self._object.voice_channels, VoiceChannel))
|
16
src/cpl_discord/container/member.py
Normal file
16
src/cpl_discord/container/member.py
Normal file
@ -0,0 +1,16 @@
|
||||
import discord
|
||||
|
||||
from cpl_discord.container.container import Container
|
||||
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))
|
17
src/cpl_discord/container/role.py
Normal file
17
src/cpl_discord/container/role.py
Normal file
@ -0,0 +1,17 @@
|
||||
import discord
|
||||
|
||||
from cpl_discord.container.container import Container
|
||||
|
||||
from cpl_discord.helper.to_containers_converter import ToContainersConverter
|
||||
from cpl_query.extension.list import List
|
||||
|
||||
|
||||
class Role(discord.Role, Container):
|
||||
|
||||
def __init__(self, _t: discord.Role):
|
||||
Container.__init__(self, _t, Role)
|
||||
|
||||
@property
|
||||
def members(self) -> List['Member']:
|
||||
from cpl_discord.container.member import Member
|
||||
return List(Member, ToContainersConverter.convert(self._object.members, Member))
|
21
src/cpl_discord/container/text_channel.py
Normal file
21
src/cpl_discord/container/text_channel.py
Normal file
@ -0,0 +1,21 @@
|
||||
import discord
|
||||
|
||||
from cpl_discord.container.container import Container
|
||||
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
|
||||
|
||||
|
||||
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))
|
16
src/cpl_discord/container/threads.py
Normal file
16
src/cpl_discord/container/threads.py
Normal 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))
|
16
src/cpl_discord/container/voice_channel.py
Normal file
16
src/cpl_discord/container/voice_channel.py
Normal 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 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))
|
@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "10",
|
||||
"Micro": "1"
|
||||
"Micro": "2"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@ -16,9 +16,9 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.7.0.post2",
|
||||
"cpl-core>=2022.10.1",
|
||||
"discord.py==2.0.1",
|
||||
"cpl-query==2022.7.0"
|
||||
"cpl-query==2022.10.2"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli>=2022.7.0.post2"
|
||||
|
@ -15,7 +15,7 @@ __title__ = 'cpl_discord.events'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -69,4 +69,4 @@ from .on_voice_state_update_abc import OnVoiceStateUpdateABC
|
||||
from .on_webhooks_update_abc import OnWebhooksUpdateABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
|
26
src/cpl_discord/helper/__init__.py
Normal file
26
src/cpl_discord/helper/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-discord sh-edraft Common Python library Discord
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library link between discord.py and CPL
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_discord.helper'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
13
src/cpl_discord/helper/to_containers_converter.py
Normal file
13
src/cpl_discord/helper/to_containers_converter.py
Normal file
@ -0,0 +1,13 @@
|
||||
from typing import Union, Sequence
|
||||
|
||||
from cpl_discord.container.container import Container
|
||||
|
||||
|
||||
class ToContainersConverter:
|
||||
|
||||
@staticmethod
|
||||
def convert(_l: Union[list[object], Sequence[object]], _t: type) -> list[Container]:
|
||||
values = []
|
||||
for e in _l:
|
||||
values.append(_t(e))
|
||||
return values
|
@ -15,7 +15,7 @@ __title__ = 'cpl_discord.service'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -29,4 +29,4 @@ from .discord_service import DiscordService
|
||||
from .discord_service_abc import DiscordServiceABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
|
@ -5,8 +5,11 @@ from cpl_core.console import Console
|
||||
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.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
|
||||
|
||||
|
||||
class DiscordBotService(DiscordBotServiceABC):
|
||||
@ -32,6 +35,7 @@ class DiscordBotService(DiscordBotServiceABC):
|
||||
|
||||
# setup super
|
||||
DiscordBotServiceABC.__init__(self, command_prefix=self._discord_settings.prefix, help_command=None, intents=discord.Intents().all())
|
||||
self._base = super(DiscordBotServiceABC, self)
|
||||
|
||||
@staticmethod
|
||||
def _is_string_invalid(x):
|
||||
@ -77,3 +81,7 @@ class DiscordBotService(DiscordBotServiceABC):
|
||||
self._logger.debug(__name__, f'Finished syncing commands')
|
||||
|
||||
await self._discord_service.on_ready()
|
||||
|
||||
@property
|
||||
def guilds(self) -> List[Guild]:
|
||||
return List(Guild, ToContainersConverter.convert(self._base.guilds, Guild))
|
||||
|
@ -1,8 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from abc import abstractmethod
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
from cpl_discord.container.guild import Guild
|
||||
from cpl_query.extension.list import List
|
||||
|
||||
|
||||
class DiscordBotServiceABC(commands.Bot):
|
||||
|
||||
@ -17,3 +19,7 @@ class DiscordBotServiceABC(commands.Bot):
|
||||
|
||||
@abstractmethod
|
||||
async def on_ready(self): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def guilds(self) -> List[Guild]: pass
|
||||
|
@ -15,7 +15,7 @@ __title__ = 'cpl_query'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
|
@ -15,7 +15,7 @@ __title__ = 'cpl_query._query'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
|
19
src/cpl_query/_query/select.py
Normal file
19
src/cpl_query/_query/select.py
Normal file
@ -0,0 +1,19 @@
|
||||
from typing import Callable
|
||||
|
||||
from cpl_query.extension.iterable_abc import IterableABC
|
||||
|
||||
|
||||
def select_query(_list: IterableABC, _f: Callable) -> any:
|
||||
result = IterableABC()
|
||||
result.extend(_f(_o) for _o in _list)
|
||||
return result
|
||||
|
||||
|
||||
def select_many_query(_list: IterableABC, _f: Callable) -> any:
|
||||
result = IterableABC()
|
||||
# The line below is pain. I don't understand anything of it...
|
||||
# written on 09.11.2022 by Sven Heidemann
|
||||
elements = [_a for _o in _list for _a in _f(_o)]
|
||||
|
||||
result.extend(elements)
|
||||
return result
|
@ -3,8 +3,8 @@
|
||||
"Name": "cpl-query",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "7",
|
||||
"Micro": "0"
|
||||
"Minor": "10",
|
||||
"Micro": "2"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@ -15,7 +15,7 @@ __title__ = 'cpl_query.extension'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0'
|
||||
__version__ = '2022.10.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@ -28,4 +28,4 @@ from .ordered_iterable_abc import OrderedIterableABC
|
||||
from .ordered_iterable import OrderedIterable
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
|
@ -14,6 +14,7 @@ from cpl_query._query.for_each import for_each_query
|
||||
from cpl_query._query.max_min import max_query, min_query
|
||||
from cpl_query._query.order_by import order_by_descending_query, order_by_query
|
||||
from cpl_query._query.reverse import reverse_query
|
||||
from cpl_query._query.select import select_query, select_many_query
|
||||
from cpl_query._query.single import single_or_default_query, single_query
|
||||
from cpl_query._query.skip_take import (skip_last_query, skip_query,
|
||||
take_last_query, take_query)
|
||||
@ -94,6 +95,12 @@ class Iterable(IterableABC):
|
||||
def single_or_default(self) -> Optional[any]:
|
||||
return single_or_default_query(self)
|
||||
|
||||
def select(self, _f: Callable) -> IterableABC:
|
||||
return self.__to_self(select_query(self, _f))
|
||||
|
||||
def select_many(self, _f: Callable) -> IterableABC:
|
||||
return self.__to_self(select_many_query(self, _f))
|
||||
|
||||
def skip(self, index: int) -> IterableABC:
|
||||
return self.__to_self(skip_query(self, index))
|
||||
|
||||
|
@ -158,7 +158,7 @@ class IterableABC(ABC, list):
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend(self, __iterable: Iterable) -> None:
|
||||
def extend(self, __iterable: Iterable) -> 'IterableABC':
|
||||
r"""Adds elements of given list to list
|
||||
|
||||
Parameter
|
||||
@ -169,6 +169,8 @@ class IterableABC(ABC, list):
|
||||
for value in __iterable:
|
||||
self.append(value)
|
||||
|
||||
return self
|
||||
|
||||
@abstractmethod
|
||||
def last(self) -> any:
|
||||
r"""Returns last element
|
||||
@ -290,6 +292,24 @@ class IterableABC(ABC, list):
|
||||
"""
|
||||
pass
|
||||
|
||||
def select(self, _f: Callable) -> 'IterableABC':
|
||||
r"""Formats each element of list to a given format
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `cpl_query.extension.iterable_abc.IterableABC`
|
||||
"""
|
||||
pass
|
||||
|
||||
def select_many(self, _f: Callable) -> 'IterableABC':
|
||||
r"""Flattens resulting lists to one
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `cpl_query.extension.iterable_abc.IterableABC`
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def single(self) -> any:
|
||||
r"""Returns one single element of list
|
||||
|
@ -1,12 +1,37 @@
|
||||
import discord
|
||||
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.events.on_ready_abc import OnReadyABC
|
||||
from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC
|
||||
|
||||
|
||||
class OnReadyEvent(OnReadyABC):
|
||||
|
||||
def __init__(self, logger: LoggerABC):
|
||||
def __init__(self, logger: LoggerABC, bot: DiscordBotServiceABC):
|
||||
OnReadyABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
|
||||
def _log(self, _t: str, _o: object, _type: type = None):
|
||||
self._logger.debug(__name__, f'{_t} {_o} {_type}')
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.info(__name__, 'Hello World')
|
||||
for g in self._bot.guilds:
|
||||
self._log('-Guild', g, type(g))
|
||||
for r in g.roles:
|
||||
self._log('--Role', r, type(r))
|
||||
for rm in r.members:
|
||||
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}')
|
||||
select_many = self._bot.guilds.select_many(lambda guild: guild.roles).where(lambda role: role.name == "Tester").first()
|
||||
self._logger.warn(__name__, f'Does cpl.query select_many work? {select_many}')
|
||||
|
@ -21,7 +21,8 @@ class UpdateTestCase(unittest.TestCase):
|
||||
self._old_package_name = 'discord.py'
|
||||
self._old_package = f'{self._old_package_name}=={self._old_version}'
|
||||
|
||||
self._new_version = '1.7.3'
|
||||
# todo: better way to do shit required
|
||||
self._new_version = '2.0.1'
|
||||
self._new_package_name = 'discord.py'
|
||||
self._new_package = f'{self._new_package_name}=={self._new_version}'
|
||||
|
||||
|
@ -161,9 +161,9 @@ class QueryTestCase(unittest.TestCase):
|
||||
def test_for_each(self):
|
||||
users = []
|
||||
self._tests.for_each(lambda user: (
|
||||
users.append(user)
|
||||
)
|
||||
users.append(user)
|
||||
)
|
||||
)
|
||||
|
||||
self.assertEqual(len(users), len(self._tests))
|
||||
|
||||
@ -239,6 +239,35 @@ class QueryTestCase(unittest.TestCase):
|
||||
|
||||
self.assertEqual(l_res, res)
|
||||
|
||||
def test_select(self):
|
||||
range_list = List(int, range(0, 100))
|
||||
selected_range = range_list.select(lambda x: x + 1)
|
||||
|
||||
modulo_range = []
|
||||
for x in range(0, 100):
|
||||
if x % 2 == 0:
|
||||
modulo_range.append(x)
|
||||
self.assertEqual(selected_range.to_list(), list(range(1, 101)))
|
||||
self.assertEqual(range_list.where(lambda x: x % 2 == 0).to_list(), modulo_range)
|
||||
|
||||
def test_select_many(self):
|
||||
range_list = List(int, range(0, 100))
|
||||
selected_range = range_list.select(lambda x: [x, x])
|
||||
|
||||
self.assertEqual(selected_range, [[x, x] for x in range(0, 100)])
|
||||
self.assertEqual(selected_range.select_many(lambda x: x).to_list(), [_x for _l in [2 * [x] for x in range(0, 100)] for _x in _l])
|
||||
|
||||
class TestClass:
|
||||
def __init__(self, i, is_sub=False):
|
||||
self.i = i
|
||||
if is_sub:
|
||||
return
|
||||
self.elements = [TestClass(x, True) for x in range(0, 10)]
|
||||
|
||||
elements = List(TestClass, [TestClass(i) for i in range(0, 100)])
|
||||
selected_elements = elements.select_many(lambda x: x.elements).select(lambda x: x.i)
|
||||
self.assertEqual(selected_elements.where(lambda x: x == 0).count(), 100)
|
||||
|
||||
def test_single(self):
|
||||
res = self._tests.where(lambda u: u.address.nr == self._t_user.address.nr)
|
||||
s_res = self._tests.where(lambda u: u.address.nr == self._t_user.address.nr).single()
|
||||
|
Loading…
Reference in New Issue
Block a user