iamai.event module

iamai event.

Base class for event classes. Adapter developers should implement a subclass of this event class base class.

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

Bases: ABC, BaseModel, Generic[AdapterT]

The base class of event classes.

adapter

The adapter object that generated the current event.

Type:

Any

type

event type.

Type:

str | None

__handled__

Indicates whether the event has been handled, used for adapter processing. Warning: Do not change the value of this property manually.

Type:

bool

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

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

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

Bases: Event, Generic[AdapterT]

Base class for general message event classes.

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

Ask for news.

Indicates getting the user’s reply after replying to a message. Equivalent to executing get() after reply().

Parameters:
  • 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.

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

Get the user’s reply message.

Equivalent to get() of Bot, the condition is that the adapter, event type and sender are the same.

Parameters:
  • max_try_times – Maximum number of events.

  • timeout – timeout period.

Returns:

Message event that the user replies to.

Raises:

GetEventTimeout – Maximum number of events exceeded or timeout.

abstract get_plain_text() str[source]

Get the plain text content of the message.

Returns:

The plain text content of the message.

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

Determine whether itself and another event are the same sender.

Parameters:

other – another event.

Returns:

Is it the same sender?

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

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

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

Reply message.

Parameters:

message – The content of the reply message.

Returns:

The response to the reply message action.

type: str | None