Skip to content

alicebot.event

AliceBot 事件。

事件类的基类。适配器开发者应实现此事件类基类的子类。

class Event

Bases: abc.ABC, pydantic.main.BaseModel, typing.Generic

事件类的基类。

  • Attributes

    • adapter (Any) - 产生当前事件的适配器对象。

    • type (Optional[str]) - 事件类型。

    • __handled__ - 表示事件是否被处理过了,用于适配器处理。警告:请勿手动更改此属性的值。

abstract class MessageEvent

Bases: alicebot.event.Event, typing.Generic

通用的消息事件类的基类。

async method ask(self, message, max_try_times = None, timeout = None)

询问消息。

表示回复一个消息后获取用户的回复。 相当于 reply() 后执行 get()

  • Arguments

    • message (str) - 回复消息的内容。

    • max_try_times (Optional[int]) - 最大事件数。

    • timeout (Union[int, float, NoneType]) - 超时时间。

  • Returns

    Type: Self

    用户回复的消息事件。

async method get(self, *, max_try_times = None, timeout = None)

获取用户回复消息。

相当于 Botget(),条件为适配器、事件类型、发送人相同。

  • Arguments

    • max_try_times (Optional[int]) - 最大事件数。

    • timeout (Union[int, float, NoneType]) - 超时时间。

  • Returns

    Type: Self

    用户回复的消息事件。

  • Raises

    • GetEventTimeout - 超过最大事件数或超时。

method get_plain_text(self)

获取消息的纯文本内容。

  • Returns

    Type: str

    消息的纯文本内容。

method get_sender_id(self)

获取消息的发送者的唯一标识符。

  • Returns

    Type: Union[NoneType, int, str]

    消息的发送者的唯一标识符。

async method is_same_sender(self, other)

判断自身和另一个事件是否是同一个发送者。

  • Arguments

    • other (Self) - 另一个事件。
  • Returns

    Type: bool

    是否是同一个发送者。

async method reply(self, message)

回复消息。

  • Arguments

    • message (str) - 回复消息的内容。
  • Returns

    Type: Any

    回复消息动作的响应。

Released under the MIT License.