aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/hrc/event.py
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2025-01-04 22:38:23 +0800
committerHsiangNianian <i@jyunko.cn>2025-01-04 22:38:23 +0800
commitc990518cb533a793399e44edbb4bc036342c7175 (patch)
tree8e2bd0f833b803a73dea7d88e7c294cf3d078d4d /hrc/event.py
parentbc57c1410c08323ba37114082d0fe609fafc2c5d (diff)
downloadHydroRollCore-main.tar.gz
HydroRollCore-main.zip
feat(core): Initialize core components and configuration modelsHEADmain
Diffstat (limited to 'hrc/event.py')
-rw-r--r--hrc/event.py94
1 files changed, 0 insertions, 94 deletions
diff --git a/hrc/event.py b/hrc/event.py
deleted file mode 100644
index 961a356..0000000
--- a/hrc/event.py
+++ /dev/null
@@ -1,94 +0,0 @@
-from abc import ABC, abstractmethod
-from typing import TYPE_CHECKING, Any, Generic, Optional, Union
-from typing_extensions import Self
-
-from pydantic import BaseModel, ConfigDict
-from hrc.typing import RuleT
-
-
-class Event(ABC, BaseModel, Generic[RuleT]):
- model_config = ConfigDict(extra="allow")
-
- if TYPE_CHECKING:
- rule: RuleT
- else:
- rule: Any
- type: Optional[str]
- __handled__: bool = False
-
- def __str__(self) -> str:
- return f"Event<{self.type}>"
-
- def __repr__(self) -> str:
- return self.__str__()
-
-
-class MessageEvent(Event[RuleT], Generic[RuleT]):
- """Base class for general message event classes."""
-
- @abstractmethod
- def get_plain_text(self) -> str:
- """Get the plain text content of the message.
-
- Returns:
- The plain text content of the message.
- """
-
- @abstractmethod
- async def reply(self, message: str) -> Any:
- """Reply message.
-
- Args:
- message: The content of the reply message.
-
- Returns:
- The response to the reply message action.
- """
-
- @abstractmethod
- async def is_same_sender(self, other: Self) -> bool:
- """Determine whether itself and another event are the same sender.
-
- Args:
- other: another event.
-
- Returns:
- Is it the same sender?
- """
-
- async def get(
- self,
- *,
- max_try_times: Optional[int] = None,
- timeout: Optional[Union[int, float]] = None,
- ) -> Self:
-
- return await self.rule.get(
- self.is_same_sender,
- event_type=type(self),
- max_try_times=max_try_times,
- timeout=timeout,
- )
-
- async def ask(
- self,
- message: str,
- max_try_times: Optional[int] = None,
- timeout: Optional[Union[int, float]] = None,
- ) -> Self:
- """Ask for news.
-
- Indicates getting the user's reply after replying to a message.
- Equivalent to executing ``get()`` after ``reply()``.
-
- Args:
- message: The content of the reply message.
- max_try_times: Maximum number of events.
- timeout: timeout period.
-
- Returns:
- Message event that the user replies to.
- """
-
- await self.reply(message)
- return await self.get(max_try_times=max_try_times, timeout=timeout)