Skip to content

Commit

Permalink
feat: 将 HydroRoll.Dice 类修改为一个泛型类,更好的IDE支持
Browse files Browse the repository at this point in the history
  • Loading branch information
HsiangNianian committed Nov 15, 2023
1 parent a904949 commit 21d7c37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
32 changes: 24 additions & 8 deletions example/plugins/HydroRoll/__init__.py
Original file line number Diff line number Diff line change
@@ -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__))
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions example/plugins/HydroRoll/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 21d7c37

Please sign in to comment.