-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e73809a
commit c63efb3
Showing
14 changed files
with
211 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .protocol import MessageCreatedEvent as MessageCreatedEvent | ||
from .protocol import MessageEvent as MessageEvent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Callable, TypeVar | ||
|
||
from ..plugin import dispatch | ||
|
||
TE = TypeVar("TE", bound="BasedEvent") | ||
|
||
|
||
class BasedEvent: | ||
@classmethod | ||
def dispatch(cls: type[TE], predicate: Callable[[TE], bool] | None = None, name: str | None = None): | ||
name = name or getattr(cls, "__disp_name__", None) | ||
return dispatch(cls, predicate=predicate, name=name) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dataclasses import dataclass | ||
from typing import Union | ||
|
||
from arclet.letoderea import Contexts, Provider, es | ||
|
||
from ..message import MessageChain | ||
from .base import BasedEvent | ||
|
||
|
||
@dataclass | ||
class CommandExecute(BasedEvent): | ||
command: Union[str, MessageChain] | ||
|
||
async def gather(self, context: Contexts): | ||
if isinstance(self.command, str): | ||
context["command"] = MessageChain(self.command) | ||
else: | ||
context["command"] = self.command | ||
|
||
class CommandProvider(Provider[MessageChain]): | ||
async def __call__(self, context: Contexts): | ||
return context.get("command") | ||
|
||
__disp_name__ = "entari.event/command_execute" | ||
|
||
|
||
pub = es.define("entari.event/command_execute", CommandExecute, lambda x: {"command": x.command, "message": x.command}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING | ||
|
||
from arclet.letoderea import deref, es, provide | ||
from arclet.letoderea.ref import generate | ||
|
||
from ..message import MessageChain | ||
from .base import BasedEvent | ||
|
||
if TYPE_CHECKING: | ||
from ..session import Session | ||
|
||
|
||
@dataclass | ||
class SendRequest(BasedEvent): | ||
session: "Session" | ||
message: "MessageChain" | ||
|
||
__disp_name__ = "entari.event/before_send" | ||
|
||
|
||
pub = es.define("entari.event/before_send", SendRequest, lambda x: {"session": x.session, "message": x.message}) | ||
pub.bind(provide(MessageChain, call=generate(deref(SendRequest).message))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.