Module graia.application.event

Expand source code
from graia.broadcast.entities.dispatcher import BaseDispatcher
from pydantic import BaseModel, validator
from graia.broadcast import BaseEvent
from graia.application.context import application
from graia.application.exceptions import InvalidEventTypeDefinition


class MiraiEvent(BaseEvent):
    __base_event__ = True
    type: str

    @validator("type", allow_reuse=True)
    def type_limit(cls, v):
        if cls.type != v:
            raise InvalidEventTypeDefinition(
                "{0}'s type must be '{1}', not '{2}'".format(cls.__name__, cls.type, v)
            )
        return v

    class Config:
        extra = "ignore"

    class Dispatcher:
        pass


class ApplicationDispatcher(BaseDispatcher):
    @staticmethod
    async def catch(interface):
        if getattr(interface.annotation, "__name__", None) == "GraiaMiraiApplication":
            return application.get()


class EmptyDispatcher(BaseDispatcher):
    mixin = [ApplicationDispatcher]

    @staticmethod
    async def catch(interface):
        pass

Sub-modules

graia.application.event.dispatcher
graia.application.event.lifecycle
graia.application.event.messages
graia.application.event.mirai
graia.application.event.network

Classes

class ApplicationDispatcher

所有非单函数型 Dispatcher 的基类, 用于为参数解析提供可扩展的支持.

Expand source code
class ApplicationDispatcher(BaseDispatcher):
    @staticmethod
    async def catch(interface):
        if getattr(interface.annotation, "__name__", None) == "GraiaMiraiApplication":
            return application.get()

Ancestors

Inherited members

class EmptyDispatcher

所有非单函数型 Dispatcher 的基类, 用于为参数解析提供可扩展的支持.

Expand source code
class EmptyDispatcher(BaseDispatcher):
    mixin = [ApplicationDispatcher]

    @staticmethod
    async def catch(interface):
        pass

Ancestors

Inherited members

class MiraiEvent (**data: Any)

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Expand source code
class MiraiEvent(BaseEvent):
    __base_event__ = True
    type: str

    @validator("type", allow_reuse=True)
    def type_limit(cls, v):
        if cls.type != v:
            raise InvalidEventTypeDefinition(
                "{0}'s type must be '{1}', not '{2}'".format(cls.__name__, cls.type, v)
            )
        return v

    class Config:
        extra = "ignore"

    class Dispatcher:
        pass

Ancestors

  • BaseEvent
  • pydantic.main.BaseModel
  • pydantic.utils.Representation

Subclasses

Class variables

var Config
var Dispatcher
var type : str

Static methods

def type_limit(v)
Expand source code
@validator("type", allow_reuse=True)
def type_limit(cls, v):
    if cls.type != v:
        raise InvalidEventTypeDefinition(
            "{0}'s type must be '{1}', not '{2}'".format(cls.__name__, cls.type, v)
        )
    return v