Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

✨ Rewrote command registration and added cogs #389

Merged
merged 82 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
2bf1451
:page_facing_up: Automatic license generator
Jan 15, 2022
4430544
:sparkles: updated cogs to not suck
Lunarmagpie Jan 15, 2022
3181649
:art: Automatic sorting
Jan 15, 2022
4ccd971
:sparkles: SelectMenu and Button support
Lunarmagpie Jan 15, 2022
072463f
:twisted_rightwards_arrows: Merge branch 'cogs' of https://github.com…
Lunarmagpie Jan 15, 2022
ed59d3c
:art: Automatic sorting
Jan 16, 2022
702afb9
:sparkles: fixed cog example and error handling
Lunarmagpie Jan 16, 2022
c6f58b6
:twisted_rightwards_arrows: Merge branch 'cogs' of https://github.com…
Lunarmagpie Jan 16, 2022
824469d
:art: remove glob
Lunarmagpie Jan 16, 2022
e19c3f9
:twisted_rightwards_arrows: Merge branch 'cogs' of https://github.com…
Lunarmagpie Jan 16, 2022
87b7cbd
:art: remove print
Lunarmagpie Jan 16, 2022
9febfe9
:memo: updated docs
Lunarmagpie Jan 16, 2022
6319114
:art: Automatic sorting
Jan 16, 2022
6f1ee8a
:bug: fixed some cog bugs
Lunarmagpie Jan 16, 2022
6e2fa2c
:art: cleaner impl
Lunarmagpie Jan 16, 2022
c1bcd5e
:memo: added Cog module to docs
Lunarmagpie Jan 16, 2022
6147ecd
:art: change stuff I didn't like from diff
Lunarmagpie Jan 16, 2022
3e4ce89
:art: remove unused imports
Lunarmagpie Jan 16, 2022
6483be1
:art: Update pincer/cog.py
Lunarmagpie Jan 16, 2022
14c5001
:art: Update pincer/commands/chat_command_handler.py
Lunarmagpie Jan 16, 2022
09b9a93
:bug: get cog returns cogs
Lunarmagpie Jan 16, 2022
8421250
:art: Automatic sorting
Jan 16, 2022
f5fec97
:twisted_rightwards_arrows: merge with upstream
Lunarmagpie Jan 16, 2022
7fa7d96
:art: fix merge error
Lunarmagpie Jan 16, 2022
edd40b4
:twisted_rightwards_arrows: Merge branch 'cogs' of https://github.com…
Lunarmagpie Jan 16, 2022
dc054b9
:art: better wording in cog description
Lunarmagpie Jan 16, 2022
5c31f44
:memo: documented cog
Lunarmagpie Jan 16, 2022
7994506
:fire: remove print
Lunarmagpie Jan 16, 2022
c1c4171
:recycle: started suggested changes
Lunarmagpie Jan 16, 2022
191ecfa
:art: Update pincer/commands/interactable.py
Lunarmagpie Jan 17, 2022
4b829cb
:recycle: Update pincer/middleware/interaction_create.py
Lunarmagpie Jan 17, 2022
3417c40
:art: Update pincer/middleware/interaction_create.py
Lunarmagpie Jan 17, 2022
974c0f0
:art: defaultdict for ThrottleInterface
Lunarmagpie Jan 17, 2022
8d6746f
:twisted_rightwards_arrows: Merge branch 'cogs' of https://github.com…
Lunarmagpie Jan 17, 2022
8035888
:art: Update pincer/commands/chat_command_handler.py
Lunarmagpie Jan 17, 2022
672b6bf
:art: Update pincer/commands/chat_command_handler.py
Lunarmagpie Jan 17, 2022
1e8024c
:art: Update pincer/commands/chat_command_handler.py
Lunarmagpie Jan 17, 2022
a939cd9
:recycle: change on_command_error to use *args and **kwargs
Lunarmagpie Jan 17, 2022
55ceb9e
:twisted_rightwards_arrows: Merge branch 'cogs' of https://github.com…
Lunarmagpie Jan 17, 2022
abf0f1c
:art: fix codacity problems
Lunarmagpie Jan 17, 2022
dd85f31
:art: fix bug where cogs could not be reloaded if you had a command g…
Lunarmagpie Jan 17, 2022
8b50fb2
:art: simplied cogs and added load_cogs method
Lunarmagpie Jan 17, 2022
7950819
:recycle: improved readability of how `changed_commands` is generated
Lunarmagpie Jan 17, 2022
a7e2adf
:recycle: some crazy refactoring
Lunarmagpie Jan 17, 2022
12007be
:recycle: improve readability
Lunarmagpie Jan 17, 2022
bdcd58c
:memo: Update pincer/cog.py
Lunarmagpie Jan 17, 2022
d7b5de5
:art: Update pincer/commands/interactable.py
Lunarmagpie Jan 17, 2022
3f67959
:recycle: Apply suggestions from code review
Lunarmagpie Jan 17, 2022
9586dd7
:art: made more code better
Lunarmagpie Jan 17, 2022
82250d9
:art: Update pincer/commands/chat_command_handler.py
Lunarmagpie Jan 17, 2022
962a1ed
:art: Update pincer/commands/chat_command_handler.py
Lunarmagpie Jan 17, 2022
b7dd938
:art: make execute event staticmethod
Lunarmagpie Jan 17, 2022
bcb4812
:twisted_rightwards_arrows: Merge branch 'cogs' of https://github.com…
Lunarmagpie Jan 17, 2022
52b58f1
:art: add client to ChatCommandHandler()
Lunarmagpie Jan 17, 2022
740fc3d
:art: remove unused imports
Lunarmagpie Jan 17, 2022
11e834f
:memo: docstring for partial event
Lunarmagpie Jan 17, 2022
09095e2
:art: replace __dict__ with vars
Lunarmagpie Jan 18, 2022
5d746b2
:memo: try adding info to Interactable
Lunarmagpie Jan 18, 2022
e6b77d3
:art: Automatic sorting
Jan 18, 2022
b4fa007
:sparkles: functional rewrite
Lunarmagpie Jan 18, 2022
88e9a88
:sparkles: reloading cogs
Lunarmagpie Jan 19, 2022
33b3cd9
:twisted_rightwards_arrows: Merge branch 'cogs-rewrite' of https://gi…
Lunarmagpie Jan 19, 2022
7513b34
:art: use _hash_interactable_structure
Lunarmagpie Jan 19, 2022
f3cfee2
:bug: don't reload cogs that were never loaded
Lunarmagpie Jan 19, 2022
48239d1
:bug: pop events correctly
Lunarmagpie Jan 19, 2022
6c077d7
:memo: fix type docs
Lunarmagpie Jan 19, 2022
d5a06ef
:memo: update more docs
Lunarmagpie Jan 19, 2022
c0f40d7
:bug: fix doc building
Lunarmagpie Jan 19, 2022
2b3a5bd
:memo: add docs to unassign
Lunarmagpie Jan 19, 2022
35cbfea
:art: fix import
Lunarmagpie Jan 19, 2022
d3600a3
:art: make cog loading cleaner
Lunarmagpie Jan 19, 2022
ff70303
:memo: fix typehint
Lunarmagpie Jan 19, 2022
259858e
:bug: make metadata Optional[T]
Lunarmagpie Jan 19, 2022
363d89b
:art: Update pincer/commands/interactable.py
Lunarmagpie Jan 20, 2022
632955b
:art: remove unused imports
Lunarmagpie Jan 20, 2022
eed00fe
:art: Update pincer/commands/interactable.py
Lunarmagpie Jan 20, 2022
b60d9b3
:art: remove unused imports
Lunarmagpie Jan 20, 2022
28c6bac
:bug: fix call
Lunarmagpie Jan 20, 2022
9b60e03
Update pincer/commands/chat_command_handler.py
Sigmanificient Jan 29, 2022
ac49e3c
Update pincer/client.py
Sigmanificient Jan 29, 2022
f4e302e
Update pincer/commands/chat_command_handler.py
Lunarmagpie Feb 19, 2022
9fe7bab
Update pincer/commands/interactable.py
Lunarmagpie Feb 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/api/cog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

.. currentmodule:: pincer.cog
Lunarmagpie marked this conversation as resolved.
Show resolved Hide resolved

Pincer Cog Module
=================

cog
---
.. attributetable:: Cog
.. autoclass:: Cog()

.. autofunction:: load_cog
.. autofunction:: load_module
.. autofunction:: reload_cog
9 changes: 8 additions & 1 deletion docs/api/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@ Command Groups
.. currentmodule:: pincer.commands.groups

.. autoclass:: Group()
.. autoclass:: Subgroup()
.. autoclass:: Subgroup()

Interactable Objects
~~~~~~~~~~~~~~~~~~~~
.. currentmodule:: pincer.commands.interactable

.. attributetable:: Interactable
.. autoclass:: Interactable()
1 change: 1 addition & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The Full Pincer API Referance

pincer
core
cog
commands
middleware
objects/index
Expand Down
6 changes: 3 additions & 3 deletions docs/api/objects/app.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ AppCommand

.. autoclass:: AppCommand()

ClientCommandStructure
InteractableStructure
~~~~~~~~~~~~~~~~~~~~~~

.. attributetable:: ClientCommandStructure
.. attributetable:: InteractableStructure

.. autoclass:: ClientCommandStructure()
.. autoclass:: InteractableStructure()

Intents
-------
Expand Down
1 change: 1 addition & 0 deletions docs/api/pincer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Client

.. autoclass:: Client
:exclude-members: event
:inherited-members:

.. automethod:: Client.event()
:decorator:
Expand Down
38 changes: 38 additions & 0 deletions examples/basic_cogs/cogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import Any, Dict, List
from pincer import Client, Cog, command
from pincer.objects import MessageContext, Embed


class ErrorHandler(Cog):
@Client.event
async def on_command_error(
self,
ctx: MessageContext,
error: Exception,
args: List[Any],
kwargs: Dict[str, Any]
Lunarmagpie marked this conversation as resolved.
Show resolved Hide resolved
):
return Embed(
Lunarmagpie marked this conversation as resolved.
Show resolved Hide resolved
"Oops...",
"An error occurred while trying to execute the "
f"`{ctx.interaction.data.name}` command! Please retry later!",
color=0xff0000
).add_field(
"Exception:",
f"```\n{type(error).__name__}:\n{error}\n```"
)


class OnReadyCog(Cog):
@Client.event
async def on_ready(self):
print(
f"Started client on {self.client.bot}\n"
"Registered commands: " + ", ".join(self.client.chat_commands)
)


class SayCog(Cog):
@command(description="Say something as the bot!")
async def say(self, ctx: MessageContext, message: str):
return Embed(description=f"{ctx.author.mention} said:\n{message}")
19 changes: 0 additions & 19 deletions examples/basic_cogs/cogs/error_handler.py

This file was deleted.

16 changes: 0 additions & 16 deletions examples/basic_cogs/cogs/on_ready.py

This file was deleted.

11 changes: 0 additions & 11 deletions examples/basic_cogs/cogs/say.py

This file was deleted.

11 changes: 3 additions & 8 deletions examples/basic_cogs/run.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
from glob import glob

from pincer import Client

from cogs import OnReadyCog, SayCog, ErrorHandler


class Bot(Client):
def __init__(self, *args, **kwargs):
self.load_cogs()
super().load_cogs(OnReadyCog, SayCog, ErrorHandler)
super().__init__(*args, **kwargs)

def load_cogs(self):
"""Load all cogs from the `cogs` directory."""
for cog in glob("cogs/*.py"):
self.load_cog(cog.replace("/", ".").replace("\\", ".")[:-3])


if __name__ == "__main__":
Bot("XXXYOURBOTTOKENHEREXXX").run()
3 changes: 2 additions & 1 deletion pincer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from ._config import GatewayConfig
from .client import event_middleware, Client, Bot
from .cog import Cog
from .commands import command, ChatCommandHandler
from .exceptions import (
PincerError, InvalidPayload, UnhandledException, NoExportMethod,
Expand Down Expand Up @@ -59,7 +60,7 @@ def __repr__(self) -> str:
__version__ = repr(version_info)

__all__ = (
"BadRequestError", "Bot", "ChatCommandHandler", "Client",
"BadRequestError", "Bot", "ChatCommandHandler", "Client", "Cog",
"CogAlreadyExists", "CogError", "CogNotFound", "CommandAlreadyRegistered",
"CommandCooldownError", "CommandDescriptionTooLong", "CommandError",
"CommandIsNotCoroutine", "CommandReturnIsEmpty", "DisallowedIntentsError",
Expand Down
Loading