diff options
| author | 2023-12-15 10:33:39 +0800 | |
|---|---|---|
| committer | 2023-12-15 10:33:39 +0800 | |
| commit | 7a5f8667cacc589e069d82e1b8db5469e28ae3bc (patch) | |
| tree | 64920b936000247bb02c03db77a278fc72e736f6 | |
| parent | e24473243f7eba9f686573078bd134ef1535547a (diff) | |
| download | infini-7a5f8667cacc589e069d82e1b8db5469e28ae3bc.tar.gz infini-7a5f8667cacc589e069d82e1b8db5469e28ae3bc.zip | |
:bug: 修订异常Merge的问题
| -rw-r--r-- | src/infini/__init__.py | 8 | ||||
| -rw-r--r-- | src/infini/cli.py | 45 | ||||
| -rw-r--r-- | src/infini/event.py | 2 | ||||
| -rw-r--r-- | src/infini/exceptions.py | 2 | ||||
| -rw-r--r-- | src/infini/logging.py | 6 | ||||
| -rw-r--r-- | src/infini/manager.py | 18 | ||||
| -rw-r--r-- | src/infini/rule.py | 75 |
7 files changed, 7 insertions, 149 deletions
diff --git a/src/infini/__init__.py b/src/infini/__init__.py index 9c88b4f9..5f6d1105 100644 --- a/src/infini/__init__.py +++ b/src/infini/__init__.py @@ -1,6 +1,4 @@ -from infini.cli import Cli -from infini.rule import Rule, Result, Dice -from infini.typing import Config as ConfigTyping -from infini.event import Event +from infini.handler import Handler, Result +from infini.event import MessageEvent -__all__ = ["Rule", "Cli", "Result", "Dice", "Event", "ConfigTyping"] +__all__ = ["Handler", "Result", "MessageEvent"] diff --git a/src/infini/cli.py b/src/infini/cli.py deleted file mode 100644 index e372b4b4..00000000 --- a/src/infini/cli.py +++ /dev/null @@ -1,45 +0,0 @@ -from pathlib import Path -from .consts import templates -from .logging import logger - -import argparse -import os -import sys -import importlib - - -class Cli: - def parse_args(self, argv: list[str] | None = None): - parser = argparse.ArgumentParser(description="HydroRoll 命令行工具") - - parser.add_argument("--new", action="store_true", help="创建一个 HydroRoll 规则包模板") - parser.add_argument("--run", action="store_true", help="运行 HydroRoll 规则包") - parser.add_argument("--gui", action="store_true", help="显示弹窗") - parser.add_argument("--path", help="指定路径") - - args = parser.parse_args(argv if argv else sys.argv[1:]) - - if args.gui: - logger.critical("选项[--gui]尚未被支持!") - sys.exit(1) - - path = Path(args.path).resolve() if args.path else Path(os.getcwd()).resolve() - if args.new and args.run: - logger.error("无法确定的指令要求: 你同时指定了new与run指令。") - sys.exit(1) - - if args.new: - if path.exists(): - logger.error("指定的文件夹已经存在!") - sys.exit(1) - - path.mkdir(parents=True, exist_ok=True) - (path / "rule.py").write_text(templates.RULE, encoding="utf-8") - (path / "event.py").write_text(templates.EVENT, encoding="utf-8") - (path / "dice.py").write_text(templates.DICE, encoding="utf-8") - - logger.success("HydroRoll 规则包模板已创建!") - - if args.run: - sys.path.append(str(path)) - importlib.import_module("event") diff --git a/src/infini/event.py b/src/infini/event.py index 0363ac96..a83c4042 100644 --- a/src/infini/event.py +++ b/src/infini/event.py @@ -56,4 +56,4 @@ class MatcherEvent: return f"<MatcherEvent [{self.name}]>" -events = Events()
\ No newline at end of file +events = Events() diff --git a/src/infini/exceptions.py b/src/infini/exceptions.py index e7c87b36..2c181b48 100644 --- a/src/infini/exceptions.py +++ b/src/infini/exceptions.py @@ -15,4 +15,4 @@ class UnknownMatcherEvent(EventError): class UnknownMessageEvent(EventError): - """未知的给出实现"""
\ No newline at end of file + """未知的给出实现""" diff --git a/src/infini/logging.py b/src/infini/logging.py index 3c3d2b02..3882f828 100644 --- a/src/infini/logging.py +++ b/src/infini/logging.py @@ -11,9 +11,7 @@ from .settings import DEBUG __all__ = ["logger", "error_or_exception"] -logger = multilogger( - name="Infini", payload="Core", level="DEBUG" if DEBUG else "INFO" -) +logger = multilogger(name="Infini", payload="Core", level="DEBUG" if DEBUG else "INFO") current_path = Path(__file__).resolve().parent LOG_PATH = current_path / "logs" if not LOG_PATH.exists(): @@ -30,4 +28,4 @@ def error_or_exception(message: str, exception: Exception, verbose: bool = True) logger.exception(exception) logger.critical(message) else: - logger.critical(f"{message} {exception!r}")
\ No newline at end of file + logger.critical(f"{message} {exception!r}") diff --git a/src/infini/manager.py b/src/infini/manager.py deleted file mode 100644 index 42e79563..00000000 --- a/src/infini/manager.py +++ /dev/null @@ -1,18 +0,0 @@ -from .event import Events, events -from .logging import logger -from .typing import Dict - - -class Manager: - """事件处理单元""" - - events: Events - - def __init__(self, _events: Events = None) -> None: - self.events = _events if _events else events - - def roll(self): - ... - - -manager = Manager() diff --git a/src/infini/rule.py b/src/infini/rule.py deleted file mode 100644 index a1f04151..00000000 --- a/src/infini/rule.py +++ /dev/null @@ -1,75 +0,0 @@ -from abc import ABCMeta, abstractmethod -from enum import Enum -from .exceptions import HydroError -from .typing import Dict - -__all__ = ["RuleLoadType", "Result", "Dice", "Rule"] - - -class RuleLoadType(Enum): - """The Type Of Rules To Be Loaded""" - - DIR = "dir" - NAME = "name" - FILE = "file" - CLASS = "class" - - -class Result(metaclass=ABCMeta): - """规则检定结果基类""" - - event: str - status: bool - exception: HydroError | None = None - - def __init__(self, event: str, status: bool, exception: HydroError | None) -> None: - self.event = event - self.status = status - self.exception = exception - - def ok(self): - """规则执行期间是否产生异常""" - return isinstance(self.exception, HydroError) - - -class Dice(metaclass=ABCMeta): - """掷骰基类""" - - roll_string: str - db: str - outcome: int - - def __repr__(self) -> str: - return f'<HydroDice "{self.db.upper()}">' - - def __str__(self) -> str: - return self.db.upper() - - def __int__(self) -> int: - return self.outcome - - @abstractmethod - def parse(self) -> "Dice": - """解析传入的掷骰字符串`roll_string`,返回一个`Dice`对象""" - raise NotImplementedError - - @abstractmethod - def roll(self) -> int: - """掷骰方法,返回掷骰结果""" - raise NotImplementedError - - -class Rule(metaclass=ABCMeta): - """规则基类""" - - name: str - dices: Dict[str, str] = {} - priority: int = 0 - - @abstractmethod - def __init__(self) -> None: - raise NotImplementedError - - @abstractmethod - def check(self, dice: Dice) -> Result: - raise NotImplementedError |
