From 5b9abeb1cca4568dafbf3e7ff35960d562ec3a0e Mon Sep 17 00:00:00 2001 From: endercheif Date: Mon, 13 Sep 2021 16:05:04 -0700 Subject: [PATCH 01/22] =?UTF-8?q?=F0=9F=93=9D=20Changed=20code=20theme=20t?= =?UTF-8?q?o=20monokai?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/conf.py b/docs/conf.py index 75c94fc4..c687d93e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -65,6 +65,7 @@ # a list of builtin themes. # html_theme = 'sphinx_rtd_theme' +pygments_style = 'monokai' default_dark_mode = False # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, From ee160ba9def0d88b93e1cca0ac8aa8393c98224a Mon Sep 17 00:00:00 2001 From: endercheif Date: Mon, 13 Sep 2021 16:05:36 -0700 Subject: [PATCH 02/22] =?UTF-8?q?=F0=9F=93=9D=20Added=20quickstart=20for?= =?UTF-8?q?=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/quickstart.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 73bcddf2..357539f5 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -45,3 +45,22 @@ Inheriting from :class:`~.client.Client` allows more flexibility and enables adv bot.run() +Implementing Slash Commands +--------------------------- + +Using slash commands is as easy as adding the :func:`~.pincer.commands.command` decorator on a function and using Python annotations to specify the argument types. + +.. code-block:: python + + from pincer import Client, command + + class Bot(Client): + def __init__(self, token): + super(Bot, self).__init__(token) + + @command(description="Add two numbers!") + async def add(self, first: int, second: int): + return f"The addition of `{first}` and `{second}` is `{first + second}`" + + bot = Bot("TOKEN") + bot.run() \ No newline at end of file From 0497072c928947a59e3ba7199e3853e35045cc1f Mon Sep 17 00:00:00 2001 From: endercheif Date: Mon, 13 Sep 2021 16:28:39 -0700 Subject: [PATCH 03/22] =?UTF-8?q?=F0=9F=93=9D=20Added=20quickstart=20for?= =?UTF-8?q?=20Message=20and=20Embeds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/quickstart.rst | 56 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 357539f5..456e40d0 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -55,12 +55,58 @@ Using slash commands is as easy as adding the :func:`~.pincer.commands.command` from pincer import Client, command class Bot(Client): - def __init__(self, token): - super(Bot, self).__init__(token) - + ... @command(description="Add two numbers!") async def add(self, first: int, second: int): return f"The addition of `{first}` and `{second}` is `{first + second}`" - bot = Bot("TOKEN") - bot.run() \ No newline at end of file + +Sending private messages +------------------------ + +See :class:`~.pincer.objects.message.Message` for more. + +.. code-block:: python + + from pincer import Client, command, Message + + class Bot(Client): + ... + @command(description="Sends a DM to the user.") + async def private_say(self, message: str): + return Message(message, flags=InteractionFlags.EPHEMERAL) + + +Sending Embeds +-------------- + +See :class:`pincer.objects.embed.Embed` for more + +.. code-block:: python + + from pincer import Client, command, Embed + + class Bot(Client): + ... + @command(description="Pincer Informational Embed") + async def an_embed(self, message: str): + return Embed( + title="Pincer", + description=( + "🚀 An asynchronous python API wrapper meant to replace" + " discord.py\n> Snappy discord api wrapper written " + "with aiohttp & websockets" + ) + ).add_field( + name="**Github Repository**", + value="> https://github.com/Pincer-org/Pincer" + ).set_thumbnail( + url="https://pincer.dev/img/icon.png" + ).set_image( + url=( + "https://repository-images.githubusercontent.com" + "/400871418/045ebf39-7c6e-4c3a-b744-0c3122374203" + ) + ) + + From 8be5095c3a87fbc9a9f407449770f3c004eafc4e Mon Sep 17 00:00:00 2001 From: Arthurdw Date: Tue, 14 Sep 2021 10:22:03 +0200 Subject: [PATCH 04/22] :bookmark: Prep for next release + config fixes --- pincer/__init__.py | 2 +- setup.cfg | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pincer/__init__.py b/pincer/__init__.py index 33af938a..b5c733d2 100644 --- a/pincer/__init__.py +++ b/pincer/__init__.py @@ -11,7 +11,7 @@ __package__ = "pincer" __author__ = "Sigmanificient, Arthurdw" __license__ = "MIT" -__version__ = "0.6.7-dev" +__version__ = "0.7.0-dev" __description__ = "Discord API wrapper rebuild from scratch." from pincer.client import Client, Bot diff --git a/setup.cfg b/setup.cfg index 59a6ae5f..7b6ae241 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pincer -version = 0.6.6 +version = 0.7.0 description = Discord API wrapper rebuild from scratch. long_description = file: docs/PYPI.md long_description_content_type = text/markdown @@ -35,8 +35,10 @@ include_package_data = True packages = pincer pincer.core - pincer.objects pincer.utils + pincer.middleware + pincer.objects + pincer.objects.events install_requires = websockets aiohttp From 207edf024f5c4be3192835a869ce896abe519e36 Mon Sep 17 00:00:00 2001 From: Arthurdw Date: Tue, 14 Sep 2021 10:23:32 +0200 Subject: [PATCH 05/22] :sparkles: Implemented the new way how library middleware will be implemented + preps for all event middleware --- pincer/middleware/__init__.py | 64 +++++++++---------- pincer/middleware/activity_join.py | 27 ++++++++ pincer/middleware/activity_join_request.py | 25 ++++++++ pincer/middleware/activity_spectate.py | 28 ++++++++ pincer/middleware/channel_create.py | 25 ++++++++ pincer/middleware/error.py | 46 +++++++++++++ pincer/middleware/guild_create.py | 25 ++++++++ pincer/middleware/guild_status.py | 25 ++++++++ pincer/middleware/interaction_create.py | 6 +- pincer/middleware/message_create.py | 25 ++++++++ pincer/middleware/message_delete.py | 25 ++++++++ pincer/middleware/message_update.py | 25 ++++++++ pincer/middleware/notification_create.py | 28 ++++++++ pincer/middleware/ready.py | 4 ++ pincer/middleware/speaking_start.py | 25 ++++++++ pincer/middleware/speaking_stop.py | 25 ++++++++ pincer/middleware/voice_channel_select.py | 25 ++++++++ pincer/middleware/voice_connection_status.py | 25 ++++++++ pincer/middleware/voice_settings_update.py | 25 ++++++++ pincer/middleware/voice_state_create.py | 25 ++++++++ pincer/middleware/voice_state_delete.py | 25 ++++++++ pincer/middleware/voice_state_update.py | 28 ++++++++ pincer/objects/events/__init__.py | 0 pincer/{ => objects}/events/channel.py | 8 +-- pincer/objects/events/error.py | 42 ++++++++++++ .../{ => objects}/events/gateway_commands.py | 8 +-- pincer/{ => objects}/events/guild.py | 18 +++--- pincer/{ => objects}/events/hello_ready.py | 10 +-- pincer/{ => objects}/events/integration.py | 6 +- pincer/{ => objects}/events/invite.py | 12 ++-- pincer/{ => objects}/events/message.py | 10 +-- pincer/{ => objects}/events/presence.py | 8 +-- pincer/{ => objects}/events/thread.py | 6 +- pincer/{ => objects}/events/typing_start.py | 8 +-- pincer/{ => objects}/events/voice.py | 4 +- pincer/{ => objects}/events/webhook.py | 4 +- pincer/objects/guild.py | 2 +- 37 files changed, 641 insertions(+), 86 deletions(-) create mode 100644 pincer/middleware/activity_join.py create mode 100644 pincer/middleware/activity_join_request.py create mode 100644 pincer/middleware/activity_spectate.py create mode 100644 pincer/middleware/channel_create.py create mode 100644 pincer/middleware/error.py create mode 100644 pincer/middleware/guild_create.py create mode 100644 pincer/middleware/guild_status.py create mode 100644 pincer/middleware/message_create.py create mode 100644 pincer/middleware/message_delete.py create mode 100644 pincer/middleware/message_update.py create mode 100644 pincer/middleware/notification_create.py create mode 100644 pincer/middleware/speaking_start.py create mode 100644 pincer/middleware/speaking_stop.py create mode 100644 pincer/middleware/voice_channel_select.py create mode 100644 pincer/middleware/voice_connection_status.py create mode 100644 pincer/middleware/voice_settings_update.py create mode 100644 pincer/middleware/voice_state_create.py create mode 100644 pincer/middleware/voice_state_delete.py create mode 100644 pincer/middleware/voice_state_update.py create mode 100644 pincer/objects/events/__init__.py rename pincer/{ => objects}/events/channel.py (89%) create mode 100644 pincer/objects/events/error.py rename pincer/{ => objects}/events/gateway_commands.py (96%) rename pincer/{ => objects}/events/guild.py (93%) rename pincer/{ => objects}/events/hello_ready.py (90%) rename pincer/{ => objects}/events/integration.py (91%) rename pincer/{ => objects}/events/invite.py (91%) rename pincer/{ => objects}/events/message.py (94%) rename pincer/{ => objects}/events/presence.py (97%) rename pincer/{ => objects}/events/thread.py (94%) rename pincer/{ => objects}/events/typing_start.py (89%) rename pincer/{ => objects}/events/voice.py (94%) rename pincer/{ => objects}/events/webhook.py (94%) diff --git a/pincer/middleware/__init__.py b/pincer/middleware/__init__.py index e3014613..17586a4c 100644 --- a/pincer/middleware/__init__.py +++ b/pincer/middleware/__init__.py @@ -22,40 +22,38 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +from glob import glob +from importlib import import_module +from os import chdir +from pathlib import Path from typing import Dict +from pincer.exceptions import NoExportMethod from pincer.utils import Coro -from .interaction_create import interaction_create_middleware -from .ready import on_ready_middleware - -# TODO: Make imports dynamic. -# from glob import glob -# from importlib import import_module -# from os import path -# from pathlib import Path -# from pincer.exceptions import NoExportMethod - -# def get_middleware() -> Dict[str, Coro]: -# middleware_list: Dict[str, Coro] = {} -# -# for middleware_path in glob(path.join( -# Path(__file__).parent.resolve(), -# "[!__init__]*.py") -# ): -# event = middleware_path[:-3] -# -# try: -# middleware_list[event] = getattr(import_module(f"event"), "export") -# except AttributeError: -# raise NoExportMethod( -# f"Middleware module `{middleware_path}` expected an " -# "`export` method but none was found!" -# ) -# -# return middleware_list -# middleware: Dict[str, Coro] = get_middleware() -middleware: Dict[str, Coro] = { - "ready": on_ready_middleware, - "interaction_create": interaction_create_middleware -} + +def get_middleware() -> Dict[str, Coro]: + middleware_list: Dict[str, Coro] = {} + chdir(Path(__file__).parent.resolve()) + + for middleware_path in glob("*.py"): + if middleware_path.startswith("__"): + continue + + event = middleware_path[:-3] + + try: + middleware_list[event] = getattr( + import_module(f".{event}", package=__name__), + "export" + )() + except AttributeError: + raise NoExportMethod( + f"Middleware module `{middleware_path}` expected an " + "`export` method but none was found!" + ) + + return middleware_list + + +middleware: Dict[str, Coro] = get_middleware() diff --git a/pincer/middleware/activity_join.py b/pincer/middleware/activity_join.py new file mode 100644 index 00000000..1834628b --- /dev/null +++ b/pincer/middleware/activity_join.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" +sent when the user clicks a Rich Presence join invite in chat to join a game +""" diff --git a/pincer/middleware/activity_join_request.py b/pincer/middleware/activity_join_request.py new file mode 100644 index 00000000..9a9b460c --- /dev/null +++ b/pincer/middleware/activity_join_request.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when the user receives a Rich Presence Ask to Join request""" diff --git a/pincer/middleware/activity_spectate.py b/pincer/middleware/activity_spectate.py new file mode 100644 index 00000000..736f7a0b --- /dev/null +++ b/pincer/middleware/activity_spectate.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" +sent when the user clicks a Rich Presence spectate invite in chat to +spectate a game +""" diff --git a/pincer/middleware/channel_create.py b/pincer/middleware/channel_create.py new file mode 100644 index 00000000..992a339c --- /dev/null +++ b/pincer/middleware/channel_create.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when a channel is created/joined on the client""" diff --git a/pincer/middleware/error.py b/pincer/middleware/error.py new file mode 100644 index 00000000..c79ebd54 --- /dev/null +++ b/pincer/middleware/error.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +""" +non-subscription event sent when there is an error, +including command responses +""" +from pincer.core.dispatch import GatewayDispatch +from pincer.objects.events.error import DiscordError + + +def error_middleware(_, payload: GatewayDispatch): + """ + Middleware for ``on_error`` event. + + :param _: + Filler param for client. + + :param payload: + The data received from the ready event. + """ + return "on_error", [DiscordError.from_dict(payload.data)] + + +def export(): + return error_middleware diff --git a/pincer/middleware/guild_create.py b/pincer/middleware/guild_create.py new file mode 100644 index 00000000..6a680bc2 --- /dev/null +++ b/pincer/middleware/guild_create.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when a guild is created/joined on the client""" diff --git a/pincer/middleware/guild_status.py b/pincer/middleware/guild_status.py new file mode 100644 index 00000000..357d5064 --- /dev/null +++ b/pincer/middleware/guild_status.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""Event sent when a subscribed server's state changes""" diff --git a/pincer/middleware/interaction_create.py b/pincer/middleware/interaction_create.py index cca1092d..89a8f6fa 100644 --- a/pincer/middleware/interaction_create.py +++ b/pincer/middleware/interaction_create.py @@ -24,7 +24,7 @@ from pincer.commands import ChatCommandHandler from pincer.core.dispatch import GatewayDispatch from pincer.objects import Interaction, Embed, Message, InteractionFlags -from pincer.utils import MISSING, should_pass_cls +from pincer.utils import MISSING, should_pass_cls, Coro from pincer.utils.extraction import get_params @@ -72,3 +72,7 @@ async def interaction_create_middleware(self, payload: GatewayDispatch): ) return "on_interaction_create", [interaction] + + +def export() -> Coro: + return interaction_create_middleware diff --git a/pincer/middleware/message_create.py b/pincer/middleware/message_create.py new file mode 100644 index 00000000..4dadacca --- /dev/null +++ b/pincer/middleware/message_create.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when a message is created in a subscribed text channel""" diff --git a/pincer/middleware/message_delete.py b/pincer/middleware/message_delete.py new file mode 100644 index 00000000..7e2ba626 --- /dev/null +++ b/pincer/middleware/message_delete.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when a message is deleted in a subscribed text channel""" diff --git a/pincer/middleware/message_update.py b/pincer/middleware/message_update.py new file mode 100644 index 00000000..d07d36bb --- /dev/null +++ b/pincer/middleware/message_update.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when a message is updated in a subscribed text channel""" diff --git a/pincer/middleware/notification_create.py b/pincer/middleware/notification_create.py new file mode 100644 index 00000000..da67b1c3 --- /dev/null +++ b/pincer/middleware/notification_create.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" +sent when the client receives a notification +(mention or new message in eligible channels) +""" diff --git a/pincer/middleware/ready.py b/pincer/middleware/ready.py index 596627e3..a4a30a81 100644 --- a/pincer/middleware/ready.py +++ b/pincer/middleware/ready.py @@ -21,6 +21,10 @@ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +""" +non-subscription event sent immediately after connecting, +contains server information +""" from pincer.commands import ChatCommandHandler from pincer.core.dispatch import GatewayDispatch from pincer.objects import User diff --git a/pincer/middleware/speaking_start.py b/pincer/middleware/speaking_start.py new file mode 100644 index 00000000..66baf381 --- /dev/null +++ b/pincer/middleware/speaking_start.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when a user in a subscribed voice channel speaks""" diff --git a/pincer/middleware/speaking_stop.py b/pincer/middleware/speaking_stop.py new file mode 100644 index 00000000..c477d3c4 --- /dev/null +++ b/pincer/middleware/speaking_stop.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when a user in a subscribed voice channel stops speaking""" diff --git a/pincer/middleware/voice_channel_select.py b/pincer/middleware/voice_channel_select.py new file mode 100644 index 00000000..1f539555 --- /dev/null +++ b/pincer/middleware/voice_channel_select.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when the client joins a voice channel""" diff --git a/pincer/middleware/voice_connection_status.py b/pincer/middleware/voice_connection_status.py new file mode 100644 index 00000000..7c851c77 --- /dev/null +++ b/pincer/middleware/voice_connection_status.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when the client's voice connection status changes""" diff --git a/pincer/middleware/voice_settings_update.py b/pincer/middleware/voice_settings_update.py new file mode 100644 index 00000000..7772b89d --- /dev/null +++ b/pincer/middleware/voice_settings_update.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when the client's voice settings update""" diff --git a/pincer/middleware/voice_state_create.py b/pincer/middleware/voice_state_create.py new file mode 100644 index 00000000..ca98b0ba --- /dev/null +++ b/pincer/middleware/voice_state_create.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +"""sent when a user joins a subscribed voice channel""" diff --git a/pincer/middleware/voice_state_delete.py b/pincer/middleware/voice_state_delete.py new file mode 100644 index 00000000..6559414e --- /dev/null +++ b/pincer/middleware/voice_state_delete.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" sent when a user parts a subscribed voice channel""" diff --git a/pincer/middleware/voice_state_update.py b/pincer/middleware/voice_state_update.py new file mode 100644 index 00000000..7c82bc7f --- /dev/null +++ b/pincer/middleware/voice_state_update.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +""" +sent when a user's voice state changes in a subscribed voice channel +(mute, volume, etc.) +""" diff --git a/pincer/objects/events/__init__.py b/pincer/objects/events/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pincer/events/channel.py b/pincer/objects/events/channel.py similarity index 89% rename from pincer/events/channel.py rename to pincer/objects/events/channel.py index ecca9523..38da86b7 100644 --- a/pincer/events/channel.py +++ b/pincer/objects/events/channel.py @@ -24,10 +24,10 @@ from dataclasses import dataclass -from ..utils.api_object import APIObject -from ..utils.snowflake import Snowflake -from ..utils.timestamp import Timestamp -from ..utils.types import MISSING, APINullable +from pincer.utils.api_object import APIObject +from pincer.utils.snowflake import Snowflake +from pincer.utils.timestamp import Timestamp +from pincer.utils.types import MISSING, APINullable @dataclass diff --git a/pincer/objects/events/error.py b/pincer/objects/events/error.py new file mode 100644 index 00000000..1558c7f8 --- /dev/null +++ b/pincer/objects/events/error.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# MIT License +# +# Copyright (c) 2021 Pincer +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +from dataclasses import dataclass + +from pincer.exceptions import PincerError +from pincer.utils import APIObject + + +@dataclass +class DiscordError(PincerError, APIObject): + """ + Represents an error event in the Discord Gateway. + + :param code: + The RPC error code. + + :param message: + The error description.. + """ + code: int + message: str diff --git a/pincer/events/gateway_commands.py b/pincer/objects/events/gateway_commands.py similarity index 96% rename from pincer/events/gateway_commands.py rename to pincer/objects/events/gateway_commands.py index b4fa4e21..1dc6d09b 100644 --- a/pincer/events/gateway_commands.py +++ b/pincer/objects/events/gateway_commands.py @@ -27,10 +27,10 @@ from typing import List, Optional, Tuple, Union from .presence import Activity -from ..objects.intents import Intents -from ..utils.api_object import APIObject -from ..utils.types import APINullable, MISSING -from ..utils.snowflake import Snowflake +from pincer.objects.intents import Intents +from pincer.utils.api_object import APIObject +from pincer.utils.types import APINullable, MISSING +from pincer.utils.snowflake import Snowflake @dataclass diff --git a/pincer/events/guild.py b/pincer/objects/events/guild.py similarity index 93% rename from pincer/events/guild.py rename to pincer/objects/events/guild.py index 6f365524..2f4585f3 100644 --- a/pincer/events/guild.py +++ b/pincer/objects/events/guild.py @@ -26,15 +26,15 @@ from typing import Any, List, Optional from .presence import PresenceUpdateEvent -from ..objects.guild_member import GuildMember -from ..objects.emoji import Emoji -from ..objects.role import Role -from ..objects.sticker import Sticker -from ..objects.user import User -from ..utils.api_object import APIObject -from ..utils.snowflake import Snowflake -from ..utils.timestamp import Timestamp -from ..utils.types import MISSING, APINullable +from pincer.objects.guild_member import GuildMember +from pincer.objects.emoji import Emoji +from pincer.objects.role import Role +from pincer.objects.sticker import Sticker +from pincer.objects.user import User +from pincer.utils.api_object import APIObject +from pincer.utils.snowflake import Snowflake +from pincer.utils.timestamp import Timestamp +from pincer.utils.types import MISSING, APINullable @dataclass diff --git a/pincer/events/hello_ready.py b/pincer/objects/events/hello_ready.py similarity index 90% rename from pincer/events/hello_ready.py rename to pincer/objects/events/hello_ready.py index 8163edc3..ad448ae4 100644 --- a/pincer/events/hello_ready.py +++ b/pincer/objects/events/hello_ready.py @@ -25,11 +25,11 @@ from dataclasses import dataclass from typing import List, Tuple -from ..objects.application import Application -from ..objects.guild import Guild -from ..objects.user import User -from ..utils.api_object import APIObject -from ..utils.types import MISSING, APINullable +from pincer.objects.application import Application +from pincer.objects.guild import Guild +from pincer.objects.user import User +from pincer.utils.api_object import APIObject +from pincer.utils.types import MISSING, APINullable @dataclass diff --git a/pincer/events/integration.py b/pincer/objects/events/integration.py similarity index 91% rename from pincer/events/integration.py rename to pincer/objects/events/integration.py index 5451c856..1097959e 100644 --- a/pincer/events/integration.py +++ b/pincer/objects/events/integration.py @@ -24,9 +24,9 @@ from dataclasses import dataclass -from ..utils.api_object import APIObject -from ..utils.snowflake import Snowflake -from ..utils.types import MISSING, APINullable +from pincer.utils.api_object import APIObject +from pincer.utils.snowflake import Snowflake +from pincer.utils.types import MISSING, APINullable @dataclass diff --git a/pincer/events/invite.py b/pincer/objects/events/invite.py similarity index 91% rename from pincer/events/invite.py rename to pincer/objects/events/invite.py index 1d5e625a..132ca0fa 100644 --- a/pincer/events/invite.py +++ b/pincer/objects/events/invite.py @@ -24,12 +24,12 @@ from dataclasses import dataclass -from ..objects.invite import InviteTargetType -from ..objects.user import User -from ..utils.api_object import APIObject -from ..utils.snowflake import Snowflake -from ..utils.timestamp import Timestamp -from ..utils.types import APINullable, MISSING +from pincer.objects.invite import InviteTargetType +from pincer.objects.user import User +from pincer.utils.api_object import APIObject +from pincer.utils.snowflake import Snowflake +from pincer.utils.timestamp import Timestamp +from pincer.utils.types import APINullable, MISSING @dataclass diff --git a/pincer/events/message.py b/pincer/objects/events/message.py similarity index 94% rename from pincer/events/message.py rename to pincer/objects/events/message.py index 27a58d8d..d0eec366 100644 --- a/pincer/events/message.py +++ b/pincer/objects/events/message.py @@ -25,11 +25,11 @@ from dataclasses import dataclass from typing import List -from ..objects.emoji import Emoji -from ..objects.guild_member import GuildMember -from ..utils.api_object import APIObject -from ..utils.snowflake import Snowflake -from ..utils.types import APINullable, MISSING +from pincer.objects.emoji import Emoji +from pincer.objects.guild_member import GuildMember +from pincer.utils.api_object import APIObject +from pincer.utils.snowflake import Snowflake +from pincer.utils.types import APINullable, MISSING @dataclass diff --git a/pincer/events/presence.py b/pincer/objects/events/presence.py similarity index 97% rename from pincer/events/presence.py rename to pincer/objects/events/presence.py index e72c0663..7e49fbd8 100644 --- a/pincer/events/presence.py +++ b/pincer/objects/events/presence.py @@ -26,10 +26,10 @@ from enum import IntEnum from typing import List, Optional, Tuple -from ..objects.user import User -from ..utils.api_object import APIObject -from ..utils.snowflake import Snowflake -from ..utils.types import MISSING, APINullable +from pincer.objects.user import User +from pincer.utils.api_object import APIObject +from pincer.utils.snowflake import Snowflake +from pincer.utils.types import MISSING, APINullable class ActivityType(IntEnum): diff --git a/pincer/events/thread.py b/pincer/objects/events/thread.py similarity index 94% rename from pincer/events/thread.py rename to pincer/objects/events/thread.py index 363e0678..823a5fb5 100644 --- a/pincer/events/thread.py +++ b/pincer/objects/events/thread.py @@ -25,9 +25,9 @@ from dataclasses import dataclass from typing import List -from ..objects.channel import Channel -from ..objects.thread import ThreadMember -from ..utils import APIObject, APINullable, MISSING, Snowflake +from pincer.objects.channel import Channel +from pincer.objects.thread import ThreadMember +from pincer.utils import APIObject, APINullable, MISSING, Snowflake @dataclass diff --git a/pincer/events/typing_start.py b/pincer/objects/events/typing_start.py similarity index 89% rename from pincer/events/typing_start.py rename to pincer/objects/events/typing_start.py index 1972b521..2a586c19 100644 --- a/pincer/events/typing_start.py +++ b/pincer/objects/events/typing_start.py @@ -24,10 +24,10 @@ from dataclasses import dataclass -from ..objects.guild_member import GuildMember -from ..utils.api_object import APIObject -from ..utils.types import APINullable, MISSING -from ..utils.snowflake import Snowflake +from pincer.objects.guild_member import GuildMember +from pincer.utils.api_object import APIObject +from pincer.utils.types import APINullable, MISSING +from pincer.utils.snowflake import Snowflake @dataclass diff --git a/pincer/events/voice.py b/pincer/objects/events/voice.py similarity index 94% rename from pincer/events/voice.py rename to pincer/objects/events/voice.py index 9f8de1f7..4fb79311 100644 --- a/pincer/events/voice.py +++ b/pincer/objects/events/voice.py @@ -25,8 +25,8 @@ from dataclasses import dataclass from typing import Optional -from ..utils.api_object import APIObject -from ..utils.snowflake import Snowflake +from pincer.utils.api_object import APIObject +from pincer.utils.snowflake import Snowflake @dataclass diff --git a/pincer/events/webhook.py b/pincer/objects/events/webhook.py similarity index 94% rename from pincer/events/webhook.py rename to pincer/objects/events/webhook.py index 86d6f23e..b91288b1 100644 --- a/pincer/events/webhook.py +++ b/pincer/objects/events/webhook.py @@ -24,8 +24,8 @@ from dataclasses import dataclass -from ..utils.api_object import APIObject -from ..utils.snowflake import Snowflake +from pincer.utils.api_object import APIObject +from pincer.utils.snowflake import Snowflake @dataclass diff --git a/pincer/objects/guild.py b/pincer/objects/guild.py index 7413d97b..e852a616 100644 --- a/pincer/objects/guild.py +++ b/pincer/objects/guild.py @@ -27,7 +27,7 @@ from enum import Enum, auto, IntEnum from typing import Optional, List -from ..events.presence import PresenceUpdateEvent +from pincer.objects.events.presence import PresenceUpdateEvent from ..exceptions import UnavailableGuildError from .channel import Channel from .emoji import Emoji From 515ac28b9f4f68f5842cddc869f373b234b02cea Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 14 Sep 2021 08:24:08 +0000 Subject: [PATCH 06/22] =?UTF-8?q?=F0=9F=93=9D=20Autogenerated=20Update=20t?= =?UTF-8?q?o=20Docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/pincer.middleware.rst | 152 +++++++++++++++++++++++++++++++++ docs/pincer.objects.events.rst | 117 +++++++++++++++++++++++++ docs/pincer.objects.rst | 8 ++ 3 files changed, 277 insertions(+) create mode 100644 docs/pincer.objects.events.rst diff --git a/docs/pincer.middleware.rst b/docs/pincer.middleware.rst index d2219528..2201046d 100644 --- a/docs/pincer.middleware.rst +++ b/docs/pincer.middleware.rst @@ -4,6 +4,62 @@ pincer.middleware package Submodules ---------- +pincer.middleware.activity\_join module +--------------------------------------- + +.. automodule:: pincer.middleware.activity_join + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.activity\_join\_request module +------------------------------------------------ + +.. automodule:: pincer.middleware.activity_join_request + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.activity\_spectate module +------------------------------------------- + +.. automodule:: pincer.middleware.activity_spectate + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.channel\_create module +---------------------------------------- + +.. automodule:: pincer.middleware.channel_create + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.error module +------------------------------ + +.. automodule:: pincer.middleware.error + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.guild\_create module +-------------------------------------- + +.. automodule:: pincer.middleware.guild_create + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.guild\_status module +-------------------------------------- + +.. automodule:: pincer.middleware.guild_status + :members: + :undoc-members: + :show-inheritance: + pincer.middleware.interaction\_create module -------------------------------------------- @@ -12,6 +68,38 @@ pincer.middleware.interaction\_create module :undoc-members: :show-inheritance: +pincer.middleware.message\_create module +---------------------------------------- + +.. automodule:: pincer.middleware.message_create + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.message\_delete module +---------------------------------------- + +.. automodule:: pincer.middleware.message_delete + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.message\_update module +---------------------------------------- + +.. automodule:: pincer.middleware.message_update + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.notification\_create module +--------------------------------------------- + +.. automodule:: pincer.middleware.notification_create + :members: + :undoc-members: + :show-inheritance: + pincer.middleware.ready module ------------------------------ @@ -20,6 +108,70 @@ pincer.middleware.ready module :undoc-members: :show-inheritance: +pincer.middleware.speaking\_start module +---------------------------------------- + +.. automodule:: pincer.middleware.speaking_start + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.speaking\_stop module +--------------------------------------- + +.. automodule:: pincer.middleware.speaking_stop + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.voice\_channel\_select module +----------------------------------------------- + +.. automodule:: pincer.middleware.voice_channel_select + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.voice\_connection\_status module +-------------------------------------------------- + +.. automodule:: pincer.middleware.voice_connection_status + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.voice\_settings\_update module +------------------------------------------------ + +.. automodule:: pincer.middleware.voice_settings_update + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.voice\_state\_create module +--------------------------------------------- + +.. automodule:: pincer.middleware.voice_state_create + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.voice\_state\_delete module +--------------------------------------------- + +.. automodule:: pincer.middleware.voice_state_delete + :members: + :undoc-members: + :show-inheritance: + +pincer.middleware.voice\_state\_update module +--------------------------------------------- + +.. automodule:: pincer.middleware.voice_state_update + :members: + :undoc-members: + :show-inheritance: + Module contents --------------- diff --git a/docs/pincer.objects.events.rst b/docs/pincer.objects.events.rst new file mode 100644 index 00000000..cb2da3c0 --- /dev/null +++ b/docs/pincer.objects.events.rst @@ -0,0 +1,117 @@ +pincer.objects.events package +============================= + +Submodules +---------- + +pincer.objects.events.channel module +------------------------------------ + +.. automodule:: pincer.objects.events.channel + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.error module +---------------------------------- + +.. automodule:: pincer.objects.events.error + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.gateway\_commands module +---------------------------------------------- + +.. automodule:: pincer.objects.events.gateway_commands + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.guild module +---------------------------------- + +.. automodule:: pincer.objects.events.guild + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.hello\_ready module +----------------------------------------- + +.. automodule:: pincer.objects.events.hello_ready + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.integration module +---------------------------------------- + +.. automodule:: pincer.objects.events.integration + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.invite module +----------------------------------- + +.. automodule:: pincer.objects.events.invite + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.message module +------------------------------------ + +.. automodule:: pincer.objects.events.message + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.presence module +------------------------------------- + +.. automodule:: pincer.objects.events.presence + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.thread module +----------------------------------- + +.. automodule:: pincer.objects.events.thread + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.typing\_start module +------------------------------------------ + +.. automodule:: pincer.objects.events.typing_start + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.voice module +---------------------------------- + +.. automodule:: pincer.objects.events.voice + :members: + :undoc-members: + :show-inheritance: + +pincer.objects.events.webhook module +------------------------------------ + +.. automodule:: pincer.objects.events.webhook + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: pincer.objects.events + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/pincer.objects.rst b/docs/pincer.objects.rst index 4eb713b9..50e67dfc 100644 --- a/docs/pincer.objects.rst +++ b/docs/pincer.objects.rst @@ -1,6 +1,14 @@ pincer.objects package ====================== +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + pincer.objects.events + Submodules ---------- From 5218ddb09ada9c5c35f87a892563b651c28acd90 Mon Sep 17 00:00:00 2001 From: Arthurdw Date: Tue, 14 Sep 2021 10:58:46 +0200 Subject: [PATCH 07/22] :sparkles: Implemented message create event --- pincer/__init__.py | 3 +- pincer/middleware/__init__.py | 1 + pincer/middleware/error.py | 4 +-- pincer/middleware/message_create.py | 11 +++++++ pincer/objects/guild_member.py | 1 + pincer/objects/user.py | 4 +++ pincer/objects/user_message.py | 47 +++++++++++++++++++++++++++-- 7 files changed, 66 insertions(+), 5 deletions(-) diff --git a/pincer/__init__.py b/pincer/__init__.py index b5c733d2..f4657b9e 100644 --- a/pincer/__init__.py +++ b/pincer/__init__.py @@ -16,5 +16,6 @@ from pincer.client import Client, Bot from pincer.commands import command +from pincer.objects import Intents -__all__ = ("Client", "Bot", "command") +__all__ = ("Client", "Bot", "command", "Intents") diff --git a/pincer/middleware/__init__.py b/pincer/middleware/__init__.py index 17586a4c..cdcab328 100644 --- a/pincer/middleware/__init__.py +++ b/pincer/middleware/__init__.py @@ -29,6 +29,7 @@ from typing import Dict from pincer.exceptions import NoExportMethod +from pincer.middleware.message_create import message_create_middleware from pincer.utils import Coro diff --git a/pincer/middleware/error.py b/pincer/middleware/error.py index c79ebd54..8d57ca3d 100644 --- a/pincer/middleware/error.py +++ b/pincer/middleware/error.py @@ -29,11 +29,11 @@ from pincer.objects.events.error import DiscordError -def error_middleware(_, payload: GatewayDispatch): +def error_middleware(self, payload: GatewayDispatch): """ Middleware for ``on_error`` event. - :param _: + :param self: Filler param for client. :param payload: diff --git a/pincer/middleware/message_create.py b/pincer/middleware/message_create.py index 4dadacca..7964ada5 100644 --- a/pincer/middleware/message_create.py +++ b/pincer/middleware/message_create.py @@ -23,3 +23,14 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when a message is created in a subscribed text channel""" + +from pincer.core.dispatch import GatewayDispatch +from pincer.objects import UserMessage + + +async def message_create_middleware(self, payload: GatewayDispatch): + return "on_message", [UserMessage.from_dict(payload.data)] + + +def export(): + return message_create_middleware diff --git a/pincer/objects/guild_member.py b/pincer/objects/guild_member.py index 2d11742f..714b1167 100644 --- a/pincer/objects/guild_member.py +++ b/pincer/objects/guild_member.py @@ -74,6 +74,7 @@ class GuildMember(APIObject): mute: bool roles: List[Snowflake] + hoisted_role: APINullable[Snowflake] = MISSING nick: APINullable[Optional[str]] = MISSING pending: APINullable[bool] = MISSING is_pending: APINullable[bool] = MISSING diff --git a/pincer/objects/user.py b/pincer/objects/user.py index 83b6f226..8e1c00bd 100644 --- a/pincer/objects/user.py +++ b/pincer/objects/user.py @@ -129,6 +129,10 @@ def premium(self) -> APINullable[PremiumTypes]: else PremiumTypes(self.premium_type) ) + @property + def mention(self) -> str: + return f"<@!{self.id}>" + def __str__(self): """Return the discord tag when object gets used as a string.""" return self.username + '#' + self.discriminator diff --git a/pincer/objects/user_message.py b/pincer/objects/user_message.py index 6b12be21..dd1204c8 100644 --- a/pincer/objects/user_message.py +++ b/pincer/objects/user_message.py @@ -41,7 +41,8 @@ from .sticker import StickerItem from .user import User from .._config import GatewayConfig -from ..utils import APIObject, APINullable, MISSING, Snowflake, Timestamp +from ..utils import APIObject, APINullable, MISSING, Snowflake, Timestamp, \ + convert class MessageActivityType(IntEnum): @@ -278,12 +279,12 @@ class UserMessage(APIObject): mention_everyone: bool mentions: List[User] mention_roles: List[Role] - mention_channels: List[ChannelMention] attachments: List[Attachment] embeds: List[Embed] pinned: bool type: MessageType + mention_channels: APINullable[List[ChannelMention]] = MISSING guild_id: APINullable[Snowflake] = MISSING member: APINullable[GuildMember] = MISSING reactions: APINullable[List[Reaction]] = MISSING @@ -299,3 +300,45 @@ class UserMessage(APIObject): thread: APINullable[Channel] = MISSING components: APINullable[List[MessageComponent]] = MISSING sticker_items: APINullable[List[StickerItem]] = MISSING + + def __post_init__(self): + self.id = convert(self.id, Snowflake.from_string) + self.channel_id = convert(self.channel_id, Snowflake.from_string) + self.author = convert(self.author, User.from_dict) + self.timestamp = convert(self.timestamp, Timestamp) + self.edited_timestamp = convert(self.edited_timestamp, Timestamp) + self.mentions = convert(self.mentions, User.from_dict) + self.mention_roles = convert(self.mention_roles, Role.from_dict) + self.attachments = convert(self.attachments, Attachment.from_dict) + self.embeds = convert(self.embeds, Embed.from_dict) + self.mention_channels = convert( + self.mention_channels, + ChannelMention.from_dict + ) + self.guild_id = convert(self.guild_id, Snowflake.from_string) + self.member = convert(self.member, GuildMember.from_dict) + self.reactions = convert(self.reactions, Reaction.from_dict) + self.webhook_id = convert(self.webhook_id, Snowflake.from_string) + self.activity = convert(self.activity, MessageActivity.from_dict) + self.application = convert(self.application, Application.from_dict) + self.application_id = convert( + self.application_id, + Snowflake.from_string + ) + self.message_reference = convert( + self.message_reference, + MessageReference.from_dict + ) + # self.flags = convert(self.flags, MessageFlags.from_bytes) + # self.referenced_message = convert( + # self.referenced_message, + # Message.from_dict + # ) + self.interaction = convert( + self.interaction, + MessageInteraction.from_dict + ) + self.thread = convert(self.thread, Channel.from_dict) + self.components = convert(self.components, MessageComponent.from_dict) + self.sticker_items = convert(self.sticker_items, StickerItem.from_dict) + From a2b0a1f63a55c0c3d840e12b2cc97eec9e15f051 Mon Sep 17 00:00:00 2001 From: Arthurdw Date: Tue, 14 Sep 2021 11:01:02 +0200 Subject: [PATCH 08/22] :memo: Added todo notes --- pincer/middleware/activity_join.py | 3 +++ pincer/middleware/activity_join_request.py | 2 ++ pincer/middleware/activity_spectate.py | 3 +++ pincer/middleware/channel_create.py | 2 ++ pincer/middleware/guild_create.py | 2 ++ pincer/middleware/guild_status.py | 2 ++ pincer/middleware/message_delete.py | 2 ++ pincer/middleware/message_update.py | 2 ++ pincer/middleware/notification_create.py | 2 ++ pincer/middleware/speaking_start.py | 2 ++ pincer/middleware/speaking_stop.py | 2 ++ pincer/middleware/voice_channel_select.py | 2 ++ pincer/middleware/voice_connection_status.py | 2 ++ pincer/middleware/voice_settings_update.py | 2 ++ pincer/middleware/voice_state_create.py | 2 ++ pincer/middleware/voice_state_delete.py | 2 ++ pincer/middleware/voice_state_update.py | 2 ++ 17 files changed, 36 insertions(+) diff --git a/pincer/middleware/activity_join.py b/pincer/middleware/activity_join.py index 1834628b..4281fe56 100644 --- a/pincer/middleware/activity_join.py +++ b/pincer/middleware/activity_join.py @@ -25,3 +25,6 @@ """ sent when the user clicks a Rich Presence join invite in chat to join a game """ + +# TODO: Implement event + diff --git a/pincer/middleware/activity_join_request.py b/pincer/middleware/activity_join_request.py index 9a9b460c..f3d60507 100644 --- a/pincer/middleware/activity_join_request.py +++ b/pincer/middleware/activity_join_request.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when the user receives a Rich Presence Ask to Join request""" + +# TODO: Implement event diff --git a/pincer/middleware/activity_spectate.py b/pincer/middleware/activity_spectate.py index 736f7a0b..9935b940 100644 --- a/pincer/middleware/activity_spectate.py +++ b/pincer/middleware/activity_spectate.py @@ -26,3 +26,6 @@ sent when the user clicks a Rich Presence spectate invite in chat to spectate a game """ + +# TODO: Implement event + diff --git a/pincer/middleware/channel_create.py b/pincer/middleware/channel_create.py index 992a339c..6f3c4fbe 100644 --- a/pincer/middleware/channel_create.py +++ b/pincer/middleware/channel_create.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when a channel is created/joined on the client""" + +# TODO: Implement event diff --git a/pincer/middleware/guild_create.py b/pincer/middleware/guild_create.py index 6a680bc2..e2533866 100644 --- a/pincer/middleware/guild_create.py +++ b/pincer/middleware/guild_create.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when a guild is created/joined on the client""" + +# TODO: Implement event diff --git a/pincer/middleware/guild_status.py b/pincer/middleware/guild_status.py index 357d5064..f6cfa69f 100644 --- a/pincer/middleware/guild_status.py +++ b/pincer/middleware/guild_status.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """Event sent when a subscribed server's state changes""" + +# TODO: Implement event diff --git a/pincer/middleware/message_delete.py b/pincer/middleware/message_delete.py index 7e2ba626..d1baa7d8 100644 --- a/pincer/middleware/message_delete.py +++ b/pincer/middleware/message_delete.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when a message is deleted in a subscribed text channel""" + +# TODO: Implement event diff --git a/pincer/middleware/message_update.py b/pincer/middleware/message_update.py index d07d36bb..4f2bf7a0 100644 --- a/pincer/middleware/message_update.py +++ b/pincer/middleware/message_update.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when a message is updated in a subscribed text channel""" + +# TODO: Implement event diff --git a/pincer/middleware/notification_create.py b/pincer/middleware/notification_create.py index da67b1c3..f5fb8a85 100644 --- a/pincer/middleware/notification_create.py +++ b/pincer/middleware/notification_create.py @@ -26,3 +26,5 @@ sent when the client receives a notification (mention or new message in eligible channels) """ + +# TODO: Implement event diff --git a/pincer/middleware/speaking_start.py b/pincer/middleware/speaking_start.py index 66baf381..22e8678e 100644 --- a/pincer/middleware/speaking_start.py +++ b/pincer/middleware/speaking_start.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when a user in a subscribed voice channel speaks""" + +# TODO: Implement event diff --git a/pincer/middleware/speaking_stop.py b/pincer/middleware/speaking_stop.py index c477d3c4..dbf36644 100644 --- a/pincer/middleware/speaking_stop.py +++ b/pincer/middleware/speaking_stop.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when a user in a subscribed voice channel stops speaking""" + +# TODO: Implement event diff --git a/pincer/middleware/voice_channel_select.py b/pincer/middleware/voice_channel_select.py index 1f539555..628b475e 100644 --- a/pincer/middleware/voice_channel_select.py +++ b/pincer/middleware/voice_channel_select.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when the client joins a voice channel""" + +# TODO: Implement event diff --git a/pincer/middleware/voice_connection_status.py b/pincer/middleware/voice_connection_status.py index 7c851c77..ff8811d5 100644 --- a/pincer/middleware/voice_connection_status.py +++ b/pincer/middleware/voice_connection_status.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when the client's voice connection status changes""" + +# TODO: Implement event diff --git a/pincer/middleware/voice_settings_update.py b/pincer/middleware/voice_settings_update.py index 7772b89d..1008e533 100644 --- a/pincer/middleware/voice_settings_update.py +++ b/pincer/middleware/voice_settings_update.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when the client's voice settings update""" + +# TODO: Implement event diff --git a/pincer/middleware/voice_state_create.py b/pincer/middleware/voice_state_create.py index ca98b0ba..91e964bc 100644 --- a/pincer/middleware/voice_state_create.py +++ b/pincer/middleware/voice_state_create.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """sent when a user joins a subscribed voice channel""" + +# TODO: Implement event diff --git a/pincer/middleware/voice_state_delete.py b/pincer/middleware/voice_state_delete.py index 6559414e..3f62b7c7 100644 --- a/pincer/middleware/voice_state_delete.py +++ b/pincer/middleware/voice_state_delete.py @@ -23,3 +23,5 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ sent when a user parts a subscribed voice channel""" + +# TODO: Implement event diff --git a/pincer/middleware/voice_state_update.py b/pincer/middleware/voice_state_update.py index 7c82bc7f..08aec159 100644 --- a/pincer/middleware/voice_state_update.py +++ b/pincer/middleware/voice_state_update.py @@ -26,3 +26,5 @@ sent when a user's voice state changes in a subscribed voice channel (mute, volume, etc.) """ + +# TODO: Implement event From a2405bcb85aaa62c90cb464a0aaf668fb66b875c Mon Sep 17 00:00:00 2001 From: Arthurdw Date: Tue, 14 Sep 2021 11:25:52 +0200 Subject: [PATCH 09/22] :bug: Bugfix + refactoring --- pincer/client.py | 4 +++- pincer/middleware/__init__.py | 1 - pincer/middleware/error.py | 5 +---- pincer/middleware/message_create.py | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pincer/client.py b/pincer/client.py index 8df85c40..94959a00 100644 --- a/pincer/client.py +++ b/pincer/client.py @@ -135,10 +135,12 @@ def decorator(func: Coro): async def wrapper(cls, payload: GatewayDispatch): _log.debug("`%s` middleware has been invoked", call) + print(func, should_pass_cls(func)) + return await ( func(cls, payload) if should_pass_cls(func) - else await func(payload) + else func(payload) ) _events[call] = wrapper diff --git a/pincer/middleware/__init__.py b/pincer/middleware/__init__.py index cdcab328..17586a4c 100644 --- a/pincer/middleware/__init__.py +++ b/pincer/middleware/__init__.py @@ -29,7 +29,6 @@ from typing import Dict from pincer.exceptions import NoExportMethod -from pincer.middleware.message_create import message_create_middleware from pincer.utils import Coro diff --git a/pincer/middleware/error.py b/pincer/middleware/error.py index 8d57ca3d..92e96753 100644 --- a/pincer/middleware/error.py +++ b/pincer/middleware/error.py @@ -29,13 +29,10 @@ from pincer.objects.events.error import DiscordError -def error_middleware(self, payload: GatewayDispatch): +def error_middleware(payload: GatewayDispatch): """ Middleware for ``on_error`` event. - :param self: - Filler param for client. - :param payload: The data received from the ready event. """ diff --git a/pincer/middleware/message_create.py b/pincer/middleware/message_create.py index 7964ada5..51d4d2bb 100644 --- a/pincer/middleware/message_create.py +++ b/pincer/middleware/message_create.py @@ -28,7 +28,7 @@ from pincer.objects import UserMessage -async def message_create_middleware(self, payload: GatewayDispatch): +async def message_create_middleware(payload: GatewayDispatch): return "on_message", [UserMessage.from_dict(payload.data)] From 1014a81d4cfe89d4c5373a3f6a0bc8bcd5a48cc8 Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Wed, 15 Sep 2021 23:46:10 +0200 Subject: [PATCH 10/22] :sparkles: message delete middleware --- pincer/middleware/message_delete.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pincer/middleware/message_delete.py b/pincer/middleware/message_delete.py index d1baa7d8..671b93d7 100644 --- a/pincer/middleware/message_delete.py +++ b/pincer/middleware/message_delete.py @@ -24,4 +24,19 @@ """sent when a message is deleted in a subscribed text channel""" -# TODO: Implement event + +async def on_message_delete_middleware(payload: GatewayDispatch): + """ + Middleware for ``on_message_delete`` event. + + :param self: + The current client. + + :param payload: + The data received from the delete message event. + """ + return "on_message_delete", [MessageDeleteEvent.from_dict(payload.data)] + + +def export(): + return on_message_delete_middleware From f4415d006437af661ab5a84980fbda840109f046 Mon Sep 17 00:00:00 2001 From: Endercheif <45527309+Endercheif@users.noreply.github.com> Date: Wed, 15 Sep 2021 17:19:32 -0700 Subject: [PATCH 11/22] =?UTF-8?q?=F0=9F=90=9B=20Changed=20`Client.=5F=5Fre?= =?UTF-8?q?ceived`=20to=20`Client.received=5Fmessage`=20because=20it=20was?= =?UTF-8?q?=20causing=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pincer/client.py | 2 +- pincer/middleware/interaction_create.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pincer/client.py b/pincer/client.py index 94959a00..e922317d 100644 --- a/pincer/client.py +++ b/pincer/client.py @@ -187,7 +187,7 @@ def __init__( ) self.bot: Optional[User] = None - self.__received = received or "Command arrived successfully!" + self.received_message = received or "Command arrived successfully!" self.http = HTTPClient(token) @property diff --git a/pincer/middleware/interaction_create.py b/pincer/middleware/interaction_create.py index 89a8f6fa..47a67e79 100644 --- a/pincer/middleware/interaction_create.py +++ b/pincer/middleware/interaction_create.py @@ -62,7 +62,7 @@ async def interaction_create_middleware(self, payload: GatewayDispatch): message = Message(embeds=[message]) elif not isinstance(message, Message): message = Message(message) if message else Message( - self.__received, + self.received_message, flags=InteractionFlags.EPHEMERAL ) From 1d7fa4826fb0242b8cb7100798ad3b00349b8315 Mon Sep 17 00:00:00 2001 From: Endercheif <45527309+Endercheif@users.noreply.github.com> Date: Wed, 15 Sep 2021 19:27:47 -0700 Subject: [PATCH 12/22] =?UTF-8?q?=F0=9F=90=9B=20Added=20missing=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pincer/middleware/message_delete.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pincer/middleware/message_delete.py b/pincer/middleware/message_delete.py index 671b93d7..b1e1c8d2 100644 --- a/pincer/middleware/message_delete.py +++ b/pincer/middleware/message_delete.py @@ -24,6 +24,8 @@ """sent when a message is deleted in a subscribed text channel""" +from pincer.core.dispatch import GatewayDispatch +from pincer.events.message import MessageDeleteEvent async def on_message_delete_middleware(payload: GatewayDispatch): """ From 4240e6a48cec77e13d262159aa1d510eb6480a11 Mon Sep 17 00:00:00 2001 From: Endercheif <45527309+Endercheif@users.noreply.github.com> Date: Wed, 15 Sep 2021 19:31:28 -0700 Subject: [PATCH 13/22] =?UTF-8?q?=F0=9F=90=9B=20Import=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pincer/middleware/message_delete.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pincer/middleware/message_delete.py b/pincer/middleware/message_delete.py index b1e1c8d2..02f598fc 100644 --- a/pincer/middleware/message_delete.py +++ b/pincer/middleware/message_delete.py @@ -25,7 +25,7 @@ """sent when a message is deleted in a subscribed text channel""" from pincer.core.dispatch import GatewayDispatch -from pincer.events.message import MessageDeleteEvent +from pincer.objects.events.message import MessageDeleteEvent async def on_message_delete_middleware(payload: GatewayDispatch): """ From 6ab94eb4dbb7d8d5d3edf20ce53fea4d20cff60a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Sep 2021 13:25:27 +0000 Subject: [PATCH 14/22] :arrow_up: Bump tox from 3.24.3 to 3.24.4 Bumps [tox](https://github.com/tox-dev/tox) from 3.24.3 to 3.24.4. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/master/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/3.24.3...3.24.4) --- updated-dependencies: - dependency-name: tox dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index cc008eb1..59fa0368 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,5 +1,5 @@ flake8==3.9.2 -tox==3.24.3 +tox==3.24.4 pytest==6.2.5 pytest-cov==2.12.1 mypy==0.910 From 34d7f7a5671a8aeb5b323444bb719a7742ad4615 Mon Sep 17 00:00:00 2001 From: endercheif Date: Thu, 16 Sep 2021 19:55:46 -0700 Subject: [PATCH 15/22] =?UTF-8?q?=E2=9C=A8Guild=20Object=20with=20Client.g?= =?UTF-8?q?et=5Fguild?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pincer/client.py | 5 ++++ pincer/middleware/__init__.py | 1 + pincer/objects/channel.py | 53 +++++++++++++++++++++++++++++++++-- pincer/objects/guild.py | 33 ++++++++++++++++++---- 4 files changed, 85 insertions(+), 7 deletions(-) diff --git a/pincer/client.py b/pincer/client.py index e922317d..01eeda64 100644 --- a/pincer/client.py +++ b/pincer/client.py @@ -26,6 +26,8 @@ import logging from asyncio import iscoroutinefunction, run +from pincer.objects.channel import Channel +from pincer.objects.guild import Guild from typing import Optional, Any, Union, Dict, Tuple, List from . import __package__ @@ -357,5 +359,8 @@ async def event_handler(self, _, payload: GatewayDispatch): else: await call(*args, **kwargs) + async def get_guild(self, id: int) -> Guild: + # TODO: docs + return await Guild.from_id(self, id) Bot = Client diff --git a/pincer/middleware/__init__.py b/pincer/middleware/__init__.py index 17586a4c..095a4690 100644 --- a/pincer/middleware/__init__.py +++ b/pincer/middleware/__init__.py @@ -48,6 +48,7 @@ def get_middleware() -> Dict[str, Coro]: "export" )() except AttributeError: + continue # TODO: Fix this. Always raises error because some modules are empty raise NoExportMethod( f"Middleware module `{middleware_path}` expected an " "`export` method but none was found!" diff --git a/pincer/objects/channel.py b/pincer/objects/channel.py index 01e80694..f0336543 100644 --- a/pincer/objects/channel.py +++ b/pincer/objects/channel.py @@ -22,10 +22,10 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from __future__ import annotations - +from json import dump from dataclasses import dataclass from enum import IntEnum -from typing import Optional, List +from typing import Dict, Optional, List, TYPE_CHECKING from .._config import GatewayConfig from .guild_member import GuildMember @@ -34,6 +34,12 @@ from .overwrite import Overwrite from ..utils import APIObject, APINullable, MISSING, Snowflake, Timestamp +if TYPE_CHECKING: + from pincer import Client + from ..core.http import HTTPClient + + + class ChannelType(IntEnum): """Represents a channel its type.""" @@ -148,6 +154,9 @@ class Channel(APIObject): the camera video quality mode of the voice channel, 1 when not present """ + _client: Client + _http: HTTPClient + id: Snowflake type: ChannelType @@ -156,11 +165,15 @@ class Channel(APIObject): default_auto_archive_duration: APINullable[int] = MISSING guild_id: APINullable[Snowflake] = MISSING icon: APINullable[Optional[str]] = MISSING + last_message_id: APINullable[Optional[Snowflake]] = MISSING last_pin_timestamp: APINullable[Optional[Timestamp]] = MISSING member: APINullable[GuildMember] = MISSING + member_count: APINullable[int] = MISSING + message_count: APINullable[int] = MISSING + name: APINullable[str] = MISSING nsfw: APINullable[bool] = MISSING owner_id: APINullable[Snowflake] = MISSING @@ -176,12 +189,40 @@ class Channel(APIObject): user_limit: APINullable[int] = MISSING video_quality_mode: APINullable[int] = MISSING + @classmethod + async def from_id(cls, client: Client, id: int) -> Channel: + data = (await client.http.get(f"/guilds/{id}")) or {} + data.update({"_client": client, "_http": client.http, "type": ChannelType(data.pop("type"))}) + channel_cls = _channel_type_map.get(data["type"], Channel) + return channel_cls.from_dict(data) + def __str__(self): """return the discord tag when object gets used as a string.""" return self.name or str(self.id) +@dataclass +class TextChannel(Channel): + pass + + +@dataclass +class VoiceChannel(Channel): + pass + + +@dataclass +class CategoryChannel(Channel): + pass + + +@dataclass +class NewsChannel(Channel): + pass + + + @dataclass class ChannelMention(APIObject): """ @@ -203,3 +244,11 @@ class ChannelMention(APIObject): guild_id: Snowflake type: ChannelType name: str + + +_channel_type_map: Dict[ChannelType, Channel] = { + ChannelType.GUILD_TEXT: TextChannel, + ChannelType.GUILD_VOICE: VoiceChannel, + ChannelType.GUILD_CATEGORY: CategoryChannel, + ChannelType.GUILD_NEWS: NewsChannel +} \ No newline at end of file diff --git a/pincer/objects/guild.py b/pincer/objects/guild.py index e852a616..8f0833a1 100644 --- a/pincer/objects/guild.py +++ b/pincer/objects/guild.py @@ -23,9 +23,9 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from __future__ import annotations -from dataclasses import dataclass +from dataclasses import dataclass, InitVar, field from enum import Enum, auto, IntEnum -from typing import Optional, List +from typing import Optional, List, TYPE_CHECKING from pincer.objects.events.presence import PresenceUpdateEvent from ..exceptions import UnavailableGuildError @@ -39,6 +39,9 @@ from .welcome_screen import WelcomeScreen from ..utils import APIObject, APINullable, MISSING, Snowflake, Timestamp +if TYPE_CHECKING: + from pincer import Client + from pincer.core.http import HTTPClient class PremiumTier(IntEnum): """ @@ -366,6 +369,9 @@ class Guild(APIObject): :param member_count: total number of members in this guild + :param nsfw: + boolean if the server is NSFW + :param owner: true if the user is the owner of the guild @@ -413,6 +419,9 @@ class Guild(APIObject): returned in an Invite's guild object """ + _client: Client + _http: HTTPClient + afk_channel_id: Optional[Snowflake] afk_timeout: int application_id: Optional[Snowflake] @@ -430,7 +439,7 @@ class Guild(APIObject): nsfw_level: GuildNSFWLevel owner_id: Snowflake preferred_locale: str - premium_tier: PremiumTier + premium_tier: InitVar[PremiumTier] public_updates_channel_id: Optional[Snowflake] roles: List[Role] rules_channel_id: Optional[Snowflake] @@ -442,7 +451,7 @@ class Guild(APIObject): approximate_member_count: APINullable[int] = MISSING approximate_presence_count: APINullable[int] = MISSING - channels: APINullable[List[Channel]] = MISSING + channels: APINullable[List[Channel]] = field(default_factory=list) icon_hash: APINullable[Optional[str]] = MISSING joined_at: APINullable[Timestamp] = MISSING large: APINullable[bool] = MISSING @@ -451,6 +460,7 @@ class Guild(APIObject): max_video_channel_users: APINullable[int] = MISSING members: APINullable[List[GuildMember]] = MISSING member_count: APINullable[bool] = MISSING + nsfw: APINullable[bool] = MISSING # Note: This is missing from discord's docs but in the api owner: APINullable[bool] = MISSING permissions: APINullable[str] = MISSING premium_subscription_count: APINullable[int] = MISSING @@ -466,6 +476,19 @@ class Guild(APIObject): widget_channel_id: APINullable[Optional[Snowflake]] = MISSING welcome_screen: APINullable[WelcomeScreen] = MISSING + + @classmethod + async def from_id(cls, client: Client, id: int) -> Guild: + data = await client.http.get(f"/guilds/{id}") + channel_data = await client.http.get(f"/guilds/{id}/channels") + + channels: List[Channel] = [Channel.from_dict(i | {"_client": client, "_http": client.http}) for i in (channel_data or [])] + + data.update({"_client": client, "_http": client.http, "channels": channels}) + + return Guild(**data) # Once below is fixed. Change this to Guild.from_dict + + # TODO: Fix this function. It causes a RecursionError because ot keeps calling itself @classmethod def from_dict(cls, data) -> Guild: """ @@ -482,4 +505,4 @@ def from_dict(cls, data) -> Guild: " to a discord outage." ) - return cls.from_dict(data) + return cls.from_dict(data) From f6fdf0af17afb927c0670924a46e49999eec73f2 Mon Sep 17 00:00:00 2001 From: Endercheif <45527309+Endercheif@users.noreply.github.com> Date: Thu, 16 Sep 2021 20:11:01 -0700 Subject: [PATCH 16/22] =?UTF-8?q?=F0=9F=8E=A8=20Made=20Codacy=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pincer/client.py | 1 - pincer/middleware/__init__.py | 2 +- pincer/objects/channel.py | 3 +-- pincer/objects/guild.py | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pincer/client.py b/pincer/client.py index 01eeda64..b7b619a7 100644 --- a/pincer/client.py +++ b/pincer/client.py @@ -26,7 +26,6 @@ import logging from asyncio import iscoroutinefunction, run -from pincer.objects.channel import Channel from pincer.objects.guild import Guild from typing import Optional, Any, Union, Dict, Tuple, List diff --git a/pincer/middleware/__init__.py b/pincer/middleware/__init__.py index 095a4690..1d3c93bf 100644 --- a/pincer/middleware/__init__.py +++ b/pincer/middleware/__init__.py @@ -48,7 +48,7 @@ def get_middleware() -> Dict[str, Coro]: "export" )() except AttributeError: - continue # TODO: Fix this. Always raises error because some modules are empty + continue # TODO: Fix this. Always raises error because some modules are empty raise NoExportMethod( f"Middleware module `{middleware_path}` expected an " "`export` method but none was found!" diff --git a/pincer/objects/channel.py b/pincer/objects/channel.py index f0336543..2fab609e 100644 --- a/pincer/objects/channel.py +++ b/pincer/objects/channel.py @@ -22,7 +22,6 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from __future__ import annotations -from json import dump from dataclasses import dataclass from enum import IntEnum from typing import Dict, Optional, List, TYPE_CHECKING @@ -165,7 +164,7 @@ class Channel(APIObject): default_auto_archive_duration: APINullable[int] = MISSING guild_id: APINullable[Snowflake] = MISSING icon: APINullable[Optional[str]] = MISSING - + last_message_id: APINullable[Optional[Snowflake]] = MISSING last_pin_timestamp: APINullable[Optional[Timestamp]] = MISSING member: APINullable[GuildMember] = MISSING diff --git a/pincer/objects/guild.py b/pincer/objects/guild.py index 8f0833a1..04356091 100644 --- a/pincer/objects/guild.py +++ b/pincer/objects/guild.py @@ -487,7 +487,7 @@ async def from_id(cls, client: Client, id: int) -> Guild: data.update({"_client": client, "_http": client.http, "channels": channels}) return Guild(**data) # Once below is fixed. Change this to Guild.from_dict - + # TODO: Fix this function. It causes a RecursionError because ot keeps calling itself @classmethod def from_dict(cls, data) -> Guild: @@ -505,4 +505,4 @@ def from_dict(cls, data) -> Guild: " to a discord outage." ) - return cls.from_dict(data) + return cls.from_dict(data) From f54ca8e6ab752aefcc6d64b608ce3ee444c17e4b Mon Sep 17 00:00:00 2001 From: Endercheif <45527309+Endercheif@users.noreply.github.com> Date: Thu, 16 Sep 2021 20:13:52 -0700 Subject: [PATCH 17/22] =?UTF-8?q?=F0=9F=8E=A8=20Removed=20Whitespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pincer/objects/channel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pincer/objects/channel.py b/pincer/objects/channel.py index 2fab609e..58ec030b 100644 --- a/pincer/objects/channel.py +++ b/pincer/objects/channel.py @@ -170,7 +170,7 @@ class Channel(APIObject): member: APINullable[GuildMember] = MISSING member_count: APINullable[int] = MISSING - + message_count: APINullable[int] = MISSING name: APINullable[str] = MISSING From d6f3f5165bb41baa0e2d7ccd15a99fc675bb884e Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Fri, 17 Sep 2021 07:32:04 +0200 Subject: [PATCH 18/22] =?UTF-8?q?=F0=9F=8E=A8=20Trailing=20space?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pincer/objects/channel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pincer/objects/channel.py b/pincer/objects/channel.py index 58ec030b..22a6e68d 100644 --- a/pincer/objects/channel.py +++ b/pincer/objects/channel.py @@ -194,7 +194,7 @@ async def from_id(cls, client: Client, id: int) -> Channel: data.update({"_client": client, "_http": client.http, "type": ChannelType(data.pop("type"))}) channel_cls = _channel_type_map.get(data["type"], Channel) return channel_cls.from_dict(data) - + def __str__(self): """return the discord tag when object gets used as a string.""" @@ -250,4 +250,4 @@ class ChannelMention(APIObject): ChannelType.GUILD_VOICE: VoiceChannel, ChannelType.GUILD_CATEGORY: CategoryChannel, ChannelType.GUILD_NEWS: NewsChannel -} \ No newline at end of file +} From 20b8c6bc28efc4719d32b621727991eff0940da5 Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Fri, 17 Sep 2021 07:44:21 +0200 Subject: [PATCH 19/22] =?UTF-8?q?=F0=9F=8E=A8=20Applying=20pep8=20&=20501?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pincer/objects/guild.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pincer/objects/guild.py b/pincer/objects/guild.py index 04356091..624b794a 100644 --- a/pincer/objects/guild.py +++ b/pincer/objects/guild.py @@ -460,7 +460,8 @@ class Guild(APIObject): max_video_channel_users: APINullable[int] = MISSING members: APINullable[List[GuildMember]] = MISSING member_count: APINullable[bool] = MISSING - nsfw: APINullable[bool] = MISSING # Note: This is missing from discord's docs but in the api + nsfw: APINullable[bool] = MISSING + # Note: This is missing from discord's docs but in the api owner: APINullable[bool] = MISSING permissions: APINullable[str] = MISSING premium_subscription_count: APINullable[int] = MISSING @@ -482,13 +483,24 @@ async def from_id(cls, client: Client, id: int) -> Guild: data = await client.http.get(f"/guilds/{id}") channel_data = await client.http.get(f"/guilds/{id}/channels") - channels: List[Channel] = [Channel.from_dict(i | {"_client": client, "_http": client.http}) for i in (channel_data or [])] + channels: List[Channel] = [ + Channel.from_dict(i | {"_client": client, "_http": client.http}) + for i in (channel_data or []) + ] - data.update({"_client": client, "_http": client.http, "channels": channels}) + data.update( + { + "_client": client, + "_http": client.http, + "channels": channels + } + ) - return Guild(**data) # Once below is fixed. Change this to Guild.from_dict + # Once below is fixed. Change this to Guild.from_dict + return Guild(**data) - # TODO: Fix this function. It causes a RecursionError because ot keeps calling itself + # TODO: Fix this function. + # It causes a RecursionError because ot keeps calling itself @classmethod def from_dict(cls, data) -> Guild: """ From 0834ff8a6bb45a7da692ac055045fb02f52511f0 Mon Sep 17 00:00:00 2001 From: Endercheif <45527309+Endercheif@users.noreply.github.com> Date: Thu, 16 Sep 2021 22:52:07 -0700 Subject: [PATCH 20/22] =?UTF-8?q?=F0=9F=94=8A=20Logging=20for=20get=5Fmidd?= =?UTF-8?q?leware?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pincer/middleware/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pincer/middleware/__init__.py b/pincer/middleware/__init__.py index 1d3c93bf..1d99aa7a 100644 --- a/pincer/middleware/__init__.py +++ b/pincer/middleware/__init__.py @@ -22,6 +22,7 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +import logging from glob import glob from importlib import import_module from os import chdir @@ -31,6 +32,8 @@ from pincer.exceptions import NoExportMethod from pincer.utils import Coro +_log = logging.getLogger(__package__) + def get_middleware() -> Dict[str, Coro]: middleware_list: Dict[str, Coro] = {} @@ -48,6 +51,7 @@ def get_middleware() -> Dict[str, Coro]: "export" )() except AttributeError: + _log.warning(f"Middleware {middleware_path} excpected an `export` method.") continue # TODO: Fix this. Always raises error because some modules are empty raise NoExportMethod( f"Middleware module `{middleware_path}` expected an " From df10c475ea9b14fcc322cd0c3db9312e03dec413 Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Fri, 17 Sep 2021 20:51:30 +0200 Subject: [PATCH 21/22] :ambulance: Adding events to 3.7 --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 59a6ae5f..0cbf4c52 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,6 +35,7 @@ include_package_data = True packages = pincer pincer.core + pincer.events pincer.objects pincer.utils install_requires = From 1bc510ac0eaf2eb5286deb303b9ec2d52845b7fc Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Fri, 17 Sep 2021 20:54:56 +0200 Subject: [PATCH 22/22] :ambulance: Adding events to 3.7 --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 7b6ae241..bee2ce83 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pincer -version = 0.7.0 +version = 0.6.7 description = Discord API wrapper rebuild from scratch. long_description = file: docs/PYPI.md long_description_content_type = text/markdown