diff --git a/example/plugins/HydroRoll/__init__.py b/example/plugins/HydroRoll/__init__.py index 5e48546..6800e96 100644 --- a/example/plugins/HydroRoll/__init__.py +++ b/example/plugins/HydroRoll/__init__.py @@ -1,18 +1,37 @@ """中间件""" +import re import json import joblib import os import shutil -from ast import literal_eval -from os.path import dirname, join, abspath + from iamai import ConfigModel, Plugin from iamai.log import logger +from iamai.exceptions import GetEventTimeout +from iamai.event import MessageEvent, Event +from iamai.typing import StateT + from .config import Directory, GlobalConfig, Models from .utils import * from .models.Transformer import query from .command import Set, Get -from iamai.exceptions import GetEventTimeout -from iamai.event import MessageEvent +from .config import ( + BasePluginConfig, + CommandPluginConfig, + RegexPluginConfig, + GlobalConfig, +) + +from ast import literal_eval +from os.path import dirname, join, abspath +from abc import ABC, abstractmethod +from typing import Any, Generic, TypeVar +from typing_extensions import Annotated + +ConfigT = TypeVar("ConfigT", bound=BasePluginConfig) +RegexPluginConfigT = TypeVar("RegexPluginConfigT", bound=RegexPluginConfig) +CommandPluginConfigT = TypeVar("CommandPluginConfigT", bound=CommandPluginConfig) + BASE_DIR = dirname(abspath("__file__")) HYDRO_DIR = dirname(abspath(__file__)) @@ -21,12 +40,9 @@ # logger.info(GlobalConfig._copyright) -class HydroRoll(Plugin): +class Dice(Plugin[MessageEvent, Annotated[dict, {}], RegexPluginConfig]): """中间件""" - class Config(ConfigModel): - __config_name__ = "HydroRoll" - priority = 0 # TODO: HydroRollCore should be able to handle all signals and tokens from Psi. diff --git a/example/plugins/HydroRoll/config.py b/example/plugins/HydroRoll/config.py index 97591fe..f90ebc0 100644 --- a/example/plugins/HydroRoll/config.py +++ b/example/plugins/HydroRoll/config.py @@ -25,6 +25,7 @@ class RegexPluginConfig(BasePluginConfig): class CommandPluginConfig(RegexPluginConfig): + __config_name__ = "HydroRoll" command_prefix: Set[str] = Field(default_factory=lambda: {".", "。"}) """命令前缀。""" command: Set[str] = Field(default_factory=set)