iamai.event module#

iamai 事件。

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

class iamai.event.Event(*, adapter: Any, type: str | None, **extra_data: Any)[source]#

Bases: ABC, BaseModel, Generic[AdapterT]

事件类的基类。

adapter#

产生当前事件的适配器对象。

Type:

Any

type#

事件类型。

Type:

str | None

__handled__#

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

Type:

bool

adapter: Any#
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'adapter': FieldInfo(annotation=Any, required=True), 'type': FieldInfo(annotation=Union[str, NoneType], required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

type: str | None#
class iamai.event.MessageEvent(*, adapter: Any, type: str | None, **extra_data: Any)[source]#

Bases: Event, Generic[AdapterT]

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

adapter: Any#
async ask(message: str, max_try_times: int | None = None, timeout: int | float | None = None) Self[source]#

询问消息。

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

Parameters:
  • message – 回复消息的内容。

  • max_try_times – 最大事件数。

  • timeout – 超时时间。

Returns:

用户回复的消息事件。

async get(*, max_try_times: int | None = None, timeout: int | float | None = None) Self[source]#

获取用户回复消息。

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

Parameters:
  • max_try_times – 最大事件数。

  • timeout – 超时时间。

Returns:

用户回复的消息事件。

Raises:

GetEventTimeout – 超过最大事件数或超时。

abstract get_plain_text() str[source]#

获取消息的纯文本内容。

Returns:

消息的纯文本内容。

abstract async is_same_sender(other: Self) bool[source]#

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

Parameters:

other – 另一个事件。

Returns:

是否是同一个发送者。

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'allow'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'adapter': FieldInfo(annotation=Any, required=True), 'type': FieldInfo(annotation=Union[str, NoneType], required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

abstract async reply(message: str) Any[source]#

回复消息。

Parameters:

message – 回复消息的内容。

Returns:

回复消息动作的响应。

type: str | None#