From 09a3f6afd69ee005ebd6a737d16f0246faa29905 Mon Sep 17 00:00:00 2001 From: 苏向夜 Date: Mon, 11 Dec 2023 00:37:00 +0800 Subject: :memo: 更新文档 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 0dc52238..dbc5b727 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,22 @@ 2. 创建规则包实例 + 创建`cli.py`并写入以下内容: + + ```python + import HydroRollCore + + client = HydroRollCore.Cli() + client.parse_args() + ``` + + 打开终端并执行: + ``` shell - mkdir myrules && cd myrules && mkdir rule1 - echo.> config.toml - echo.> __init__.py + python cli.py --new --path MyRule ``` - 在 `__init__.py` 创建一个 `rule` 实例并继承 `Rule` 基类, 通过编写合适的相关方法与类注册规则包实现规则的自定义。 + 你可以在生成的 `MyRule\rule.py` 创建一个或者多个 `rule` 实例并继承 `Rule` 基类, 通过编写合适的相关方法与类注册规则包实现规则的自定义。 ``` python from HydroRollCore import Rule, Result, Dice @@ -63,9 +72,11 @@ def check(self, dice: Dice) -> Result: """声明规则包检定方式""" - return Result("myevent.event1", True) + return Result("event1", True) ``` + `check`函数应当返回一个`Result`对象,它应当包含一个消息事件名(例如示例中的`event1`),该消息事件名应当在 `MyRule\event.py` 中被注册。消息事件的动态内容通过`{name}`的方式声明并通过`name="内容"`的方式实现。 + 3. 合理修改你的 `config.toml` 配置文件,完成注册! ### 🎍Sites -- cgit v1.2.3-70-g09d2