pymud 0.21.0a4__tar.gz → 0.21.0a5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {pymud-0.21.0a4 → pymud-0.21.0a5}/PKG-INFO +33 -4
  2. {pymud-0.21.0a4 → pymud-0.21.0a5}/README.md +32 -3
  3. {pymud-0.21.0a4 → pymud-0.21.0a5}/pyproject.toml +1 -1
  4. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/__init__.py +5 -5
  5. pymud-0.21.0a5/src/pymud/decorators.py +234 -0
  6. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/extras.py +1 -1
  7. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/lang/i18n_chs.py +6 -2
  8. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/lang/i18n_eng.py +13 -6
  9. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/main.py +17 -4
  10. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/modules.py +33 -180
  11. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/objects.py +77 -70
  12. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/protocol.py +7 -7
  13. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/pymud.py +3 -3
  14. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/session.py +182 -154
  15. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/settings.py +2 -2
  16. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud.egg-info/PKG-INFO +33 -4
  17. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud.egg-info/SOURCES.txt +1 -0
  18. {pymud-0.21.0a4 → pymud-0.21.0a5}/LICENSE.txt +0 -0
  19. {pymud-0.21.0a4 → pymud-0.21.0a5}/setup.cfg +0 -0
  20. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/__main__.py +0 -0
  21. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/dialogs.py +0 -0
  22. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/i18n.py +0 -0
  23. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/logger.py +0 -0
  24. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud/pkuxkx.py +0 -0
  25. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud.egg-info/dependency_links.txt +0 -0
  26. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud.egg-info/entry_points.txt +0 -0
  27. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud.egg-info/requires.txt +0 -0
  28. {pymud-0.21.0a4 → pymud-0.21.0a5}/src/pymud.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pymud
3
- Version: 0.21.0a4
3
+ Version: 0.21.0a5
4
4
  Summary: a MUD Client written in Python
5
5
  Author-email: "newstart@pkuxkx" <crapex@hotmail.com>
6
6
  Maintainer-email: "newstart@pkuxkx" <crapex@hotmail.com>
@@ -37,12 +37,15 @@ Dynamic: license-file
37
37
  ### 源代码地址: https://github.com/crapex/pymud
38
38
  ### 帮助文档地址: https://pymud.readthedocs.org
39
39
  ### PyPi项目地址: https://pypi.org/project/pymud
40
- ### 使用交流QQ群:554672580
40
+ ### 由deepwiki自动生成的项目理解文档地址: https://deepwiki.com/crapex/pymud
41
+ ### PyMUD用户shanghua写的入门教程文档:https://www.pkuxkx.net/forum/forum.php?mod=viewthread&tid=49999&forumuid=12067
42
+ ### 交流QQ群:554672580
41
43
 
42
44
 
43
45
  ### 北大侠客行Mud (www.pkuxkx.net),最好的中文Mud游戏!
44
46
  ### PyMUD是我为了更好的玩北大侠客行,特意自行开发的MUD客户端。PyMUD具有以下特点:
45
47
  + 原生Python开发,除prompt-toolkit及其依赖库(wcwidth, pygment, pyperclip)外,不需要其他第三方库支持
48
+ + 原生Python的asyncio实现的通信协议处理,支持async/await语法在脚本中直接应用,脚本实现的同步异步两种模式由你自己选择
46
49
  + 基于控制台的全屏UI界面设计,支持鼠标操作(Android上支持触摸屏操作)
47
50
  + 支持分屏显示,在数据快速滚动的时候,上半屏保持不动,以确保不错过信息
48
51
  + 解决了99%情况下,北大侠客行中文对不齐,也就是看不清字符画的问题(因为我没有走遍所有地方,不敢保证100%)
@@ -64,11 +67,36 @@ Dynamic: license-file
64
67
  ## 版本更新信息
65
68
 
66
69
  ### 0.21.0 开发中,最新更新2025-05-18
70
+ + 功能新增: #load / #unload 现在支持当前会话对插件的临时启用和禁用,实现方式为调用插件里的PLUGIN_SESSION_CREATE和PLUGIN_SESSION_DESTROYE函数。群文件的moving.py插件写法可以支持。
71
+ + 功能调整: 各会话变量保存的.mud文件,统一移到save子目录下。原来当前目录下的.mud文件,在对应会话重新加载时会自动移动,无需人工处理。
72
+ + 功能新增: 调整了enableGroup处理,可以通过组名支持子组操作,也可以指定有效类型范围。例如下面代码:
73
+ ``` Python
74
+ class MyTestConfig(IConfig):
75
+ def __init__(self, session, *args, **kwargs):
76
+ self._objs = [
77
+ Trigger(session, "tri1", group = "group1"),
78
+ Trigger(session, "tri2", group = "group1.subgroup1"),
79
+ Trigger(session, "tri3", group = "group1.subgroup2"),
80
+ Alias(session, "alias1", group = "group1"),
81
+ Alias(session, "alias2", group = "group1.subgroup1"),
82
+ Timer(session, 5, group = "group1.subgroup1")
83
+ ]
84
+
85
+ #以下调用可以同时禁用上述6个对象,因为 group1.subgroup1 和 group1.subgroup2 都属于 group1 的子组
86
+ session.enableGroup("group1", False)
87
+ #以下调用可以同时仅启用触发器tri1和别名alias1,因为通过subgroup参数限定了不传递到子组
88
+ session.enableGroup("group1", True, subgroup = False)
89
+ # 以下调用可以同时禁用对应发器和别名,但不禁用定时器,因为通过types参数指定了有效范围:
90
+ session.enableGroup("group1.subgroup1", False, types = [Trigger, Alias])
91
+
92
+ ```
93
+ + 功能新增: 增加了多处异常追踪提示。在模块或插件的脚本中发生错误时,均会打印错误追踪信息,方便定位错误。
94
+ + 功能新增: 新增 #echo 命令,类似于 #test 命令,但该命令只会模拟收到服务器数据,直接激发各匹配触发器,但不显示触发测试结果。
67
95
  + 功能新增: 增加了国际化(i18n)支持,原生开发语言为中文简体,目前使用AI翻译生成了英文。应用语言通过Settings中新增的language配置来控制,默认为"chs",可以在pymud.cfg中覆盖该配置。其值目前可以为"chs"、"eng"。自行翻译的语言可以在pymud/lang目录下下新增语言文件,文件名为i18n_加语言代码,例如"i18n_chs.py"表示可以使用"chs"语言,其中使用Python字典方式定义了所有需动态显示的文本内容。
68
96
  + 功能新增: 新增了使用元类型及装饰器来管理Pymud对象,包括Alias, Trigger, Timer, GMCPTrigger四种可以使用对应的装饰器,@alias, @trigger, @timer, @gmcp来直接在标记函数上创建。可以参考本版本中的pkuxkx.py文件写法和注意事项。
69
97
  + 功能新增: 新增了两个装饰器,@exception和@async_exception,用于捕获异常并调用session.error进行显示。@exception用于捕获同步异常,@async_exception用于捕获异步异常。参考如下:
70
98
  ``` Python
71
- from pymud import Command, Trigger, IConfig
99
+ from pymud import Command, Trigger, IConfig, exception, async_exception
72
100
 
73
101
  class MyCustomCommand(Command, IConfig):
74
102
  @exception
@@ -97,6 +125,7 @@ Dynamic: license-file
97
125
  ```
98
126
  + 问题修复: 修复了Alias和Command执行时的优先级判断。之前未进行优先级判断,因此遇到能同时匹配的多个时,不一定优先级高的被触发。现在对Alias和Command进行了优先级判断,优先级高的先触发。
99
127
  + 问题修复: 修复Alias中的keepEval参数和oneShot参数。keepEval参数支持多个匹配成功的别名同时生效,oneShot参数支持一个匹配成功的别名生效后,后续的匹配不再生效。
128
+ + 问题修复: 修复Command中的keepEval参数。以往同时匹配生效的Command会覆盖后续Command和Alias,当前会持续匹配。
100
129
  + 功能增强: 对几乎所有函数的参数进行了类型标注,增加了类型检查,提高了代码的可读性和可维护性,也便于自行编写脚本时的提示。
101
130
  + 功能增强: 为Session类型增加了commandHistory属性,用于查询发送到服务器的命令历史。保存的命令历史的数量由pymud.cfg中的client["history_records"]控制,默认为500。当该值为0时,不会保存命令历史。为-1时,会保存所有命令历史。
102
131
  + 功能调整: #help命令时,增加了上下两行分隔符显示,以便明显区分帮助输出和游戏输出。
@@ -105,7 +134,7 @@ Dynamic: license-file
105
134
  + 问题修复: 删除了extras.py中多余的MenuItem类型定义,该定义与prompt_toolkit中的MenuItem定义冲突。
106
135
  + 问题修复: 调整了众多代码中未检查对象是否为None即调用、使用的局部变量可能未经过初始化和赋值路径等的情况,保证程序运行的健壮性。
107
136
  + 问题修复: 修复了#test命令的帮助内容错误。实际#show命令不触发脚本,仅测试;而#test会触发脚本。
108
- + 已知问题: 在进行类型标注是,发现了协议中处理MSDP协议的代码有问题,由于北大侠客行不适用MSDP传输数据,所以关闭了默认配置中的MSDP支持,此问题先遗留,后续再解决。之前某些MUD游戏报解码错误可能与MSDP协议有关。
137
+ + 问题修复: 修复了协议处理中MSDP编码解码处理错误的问题;修复了协议处理中默认encoding不传递导致某些情况下报解码错误的问题。
109
138
  + 示例更新: 更新了包中自带的pkuxkx.py,增加了@alias, @trigger, @timer, @gmcp的示例以及状态窗口的示例。
110
139
 
111
140
  ### 0.20.4 (2025-03-30)
@@ -5,12 +5,15 @@
5
5
  ### 源代码地址: https://github.com/crapex/pymud
6
6
  ### 帮助文档地址: https://pymud.readthedocs.org
7
7
  ### PyPi项目地址: https://pypi.org/project/pymud
8
- ### 使用交流QQ群:554672580
8
+ ### 由deepwiki自动生成的项目理解文档地址: https://deepwiki.com/crapex/pymud
9
+ ### PyMUD用户shanghua写的入门教程文档:https://www.pkuxkx.net/forum/forum.php?mod=viewthread&tid=49999&forumuid=12067
10
+ ### 交流QQ群:554672580
9
11
 
10
12
 
11
13
  ### 北大侠客行Mud (www.pkuxkx.net),最好的中文Mud游戏!
12
14
  ### PyMUD是我为了更好的玩北大侠客行,特意自行开发的MUD客户端。PyMUD具有以下特点:
13
15
  + 原生Python开发,除prompt-toolkit及其依赖库(wcwidth, pygment, pyperclip)外,不需要其他第三方库支持
16
+ + 原生Python的asyncio实现的通信协议处理,支持async/await语法在脚本中直接应用,脚本实现的同步异步两种模式由你自己选择
14
17
  + 基于控制台的全屏UI界面设计,支持鼠标操作(Android上支持触摸屏操作)
15
18
  + 支持分屏显示,在数据快速滚动的时候,上半屏保持不动,以确保不错过信息
16
19
  + 解决了99%情况下,北大侠客行中文对不齐,也就是看不清字符画的问题(因为我没有走遍所有地方,不敢保证100%)
@@ -32,11 +35,36 @@
32
35
  ## 版本更新信息
33
36
 
34
37
  ### 0.21.0 开发中,最新更新2025-05-18
38
+ + 功能新增: #load / #unload 现在支持当前会话对插件的临时启用和禁用,实现方式为调用插件里的PLUGIN_SESSION_CREATE和PLUGIN_SESSION_DESTROYE函数。群文件的moving.py插件写法可以支持。
39
+ + 功能调整: 各会话变量保存的.mud文件,统一移到save子目录下。原来当前目录下的.mud文件,在对应会话重新加载时会自动移动,无需人工处理。
40
+ + 功能新增: 调整了enableGroup处理,可以通过组名支持子组操作,也可以指定有效类型范围。例如下面代码:
41
+ ``` Python
42
+ class MyTestConfig(IConfig):
43
+ def __init__(self, session, *args, **kwargs):
44
+ self._objs = [
45
+ Trigger(session, "tri1", group = "group1"),
46
+ Trigger(session, "tri2", group = "group1.subgroup1"),
47
+ Trigger(session, "tri3", group = "group1.subgroup2"),
48
+ Alias(session, "alias1", group = "group1"),
49
+ Alias(session, "alias2", group = "group1.subgroup1"),
50
+ Timer(session, 5, group = "group1.subgroup1")
51
+ ]
52
+
53
+ #以下调用可以同时禁用上述6个对象,因为 group1.subgroup1 和 group1.subgroup2 都属于 group1 的子组
54
+ session.enableGroup("group1", False)
55
+ #以下调用可以同时仅启用触发器tri1和别名alias1,因为通过subgroup参数限定了不传递到子组
56
+ session.enableGroup("group1", True, subgroup = False)
57
+ # 以下调用可以同时禁用对应发器和别名,但不禁用定时器,因为通过types参数指定了有效范围:
58
+ session.enableGroup("group1.subgroup1", False, types = [Trigger, Alias])
59
+
60
+ ```
61
+ + 功能新增: 增加了多处异常追踪提示。在模块或插件的脚本中发生错误时,均会打印错误追踪信息,方便定位错误。
62
+ + 功能新增: 新增 #echo 命令,类似于 #test 命令,但该命令只会模拟收到服务器数据,直接激发各匹配触发器,但不显示触发测试结果。
35
63
  + 功能新增: 增加了国际化(i18n)支持,原生开发语言为中文简体,目前使用AI翻译生成了英文。应用语言通过Settings中新增的language配置来控制,默认为"chs",可以在pymud.cfg中覆盖该配置。其值目前可以为"chs"、"eng"。自行翻译的语言可以在pymud/lang目录下下新增语言文件,文件名为i18n_加语言代码,例如"i18n_chs.py"表示可以使用"chs"语言,其中使用Python字典方式定义了所有需动态显示的文本内容。
36
64
  + 功能新增: 新增了使用元类型及装饰器来管理Pymud对象,包括Alias, Trigger, Timer, GMCPTrigger四种可以使用对应的装饰器,@alias, @trigger, @timer, @gmcp来直接在标记函数上创建。可以参考本版本中的pkuxkx.py文件写法和注意事项。
37
65
  + 功能新增: 新增了两个装饰器,@exception和@async_exception,用于捕获异常并调用session.error进行显示。@exception用于捕获同步异常,@async_exception用于捕获异步异常。参考如下:
38
66
  ``` Python
39
- from pymud import Command, Trigger, IConfig
67
+ from pymud import Command, Trigger, IConfig, exception, async_exception
40
68
 
41
69
  class MyCustomCommand(Command, IConfig):
42
70
  @exception
@@ -65,6 +93,7 @@
65
93
  ```
66
94
  + 问题修复: 修复了Alias和Command执行时的优先级判断。之前未进行优先级判断,因此遇到能同时匹配的多个时,不一定优先级高的被触发。现在对Alias和Command进行了优先级判断,优先级高的先触发。
67
95
  + 问题修复: 修复Alias中的keepEval参数和oneShot参数。keepEval参数支持多个匹配成功的别名同时生效,oneShot参数支持一个匹配成功的别名生效后,后续的匹配不再生效。
96
+ + 问题修复: 修复Command中的keepEval参数。以往同时匹配生效的Command会覆盖后续Command和Alias,当前会持续匹配。
68
97
  + 功能增强: 对几乎所有函数的参数进行了类型标注,增加了类型检查,提高了代码的可读性和可维护性,也便于自行编写脚本时的提示。
69
98
  + 功能增强: 为Session类型增加了commandHistory属性,用于查询发送到服务器的命令历史。保存的命令历史的数量由pymud.cfg中的client["history_records"]控制,默认为500。当该值为0时,不会保存命令历史。为-1时,会保存所有命令历史。
70
99
  + 功能调整: #help命令时,增加了上下两行分隔符显示,以便明显区分帮助输出和游戏输出。
@@ -73,7 +102,7 @@
73
102
  + 问题修复: 删除了extras.py中多余的MenuItem类型定义,该定义与prompt_toolkit中的MenuItem定义冲突。
74
103
  + 问题修复: 调整了众多代码中未检查对象是否为None即调用、使用的局部变量可能未经过初始化和赋值路径等的情况,保证程序运行的健壮性。
75
104
  + 问题修复: 修复了#test命令的帮助内容错误。实际#show命令不触发脚本,仅测试;而#test会触发脚本。
76
- + 已知问题: 在进行类型标注是,发现了协议中处理MSDP协议的代码有问题,由于北大侠客行不适用MSDP传输数据,所以关闭了默认配置中的MSDP支持,此问题先遗留,后续再解决。之前某些MUD游戏报解码错误可能与MSDP协议有关。
105
+ + 问题修复: 修复了协议处理中MSDP编码解码处理错误的问题;修复了协议处理中默认encoding不传递导致某些情况下报解码错误的问题。
77
106
  + 示例更新: 更新了包中自带的pkuxkx.py,增加了@alias, @trigger, @timer, @gmcp的示例以及状态窗口的示例。
78
107
 
79
108
  ### 0.20.4 (2025-03-30)
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
 
3
3
  name = "pymud" # Required
4
- version = "0.21.0a4" # Required
4
+ version = "0.21.0a5" # Required
5
5
  description = "a MUD Client written in Python" # Optional
6
6
  readme = "README.md" # Optional
7
7
  requires-python = ">=3.7"
@@ -1,17 +1,17 @@
1
1
  from .settings import Settings
2
2
  from .pymud import PyMudApp
3
- from .modules import IConfig, PymudDecorator, PymudMeta, alias, trigger, timer, gmcp
3
+ from .modules import IConfigBase, IConfig, PymudMeta
4
4
  from .objects import CodeBlock, Alias, SimpleAlias, Trigger, SimpleTrigger, Command, SimpleCommand, Timer, SimpleTimer, GMCPTrigger
5
5
  from .extras import DotDict
6
- from .session import Session, exception, async_exception
6
+ from .session import Session
7
7
  from .logger import Logger
8
8
  from .main import main
9
+ from .decorators import exception, async_exception, PymudDecorator, alias, trigger, timer, gmcp
9
10
 
10
11
  __all__ = [
11
- "PymudDecorator", "PymudMeta", "alias", "trigger", "timer", "gmcp",
12
- "IConfig", "PyMudApp", "Settings", "CodeBlock",
12
+ "PymudMeta", "IConfigBase", "IConfig", "PyMudApp", "Settings", "CodeBlock",
13
13
  "Alias", "SimpleAlias", "Trigger", "SimpleTrigger",
14
14
  "Command", "SimpleCommand", "Timer", "SimpleTimer",
15
15
  "GMCPTrigger", "Session", "DotDict", "Logger", "main",
16
- "exception", "async_exception"
16
+ "exception", "async_exception", "PymudDecorator", "alias", "trigger", "timer", "gmcp",
17
17
  ]
@@ -0,0 +1,234 @@
1
+ import sys, functools, traceback
2
+ from typing import Union, Optional, List
3
+
4
+ def print_exception(session, e: Exception):
5
+ """打印异常信息"""
6
+ from .settings import Settings
7
+ from .session import Session
8
+ if isinstance(session, Session):
9
+ # tb = sys.exc_info()[2]
10
+ # frames = traceback.extract_tb(tb)
11
+ # frame = frames[-1]
12
+ # session.error(Settings.gettext("exception_traceback", frame.filename, frame.lineno, frame.name), Settings.gettext("script_error"))
13
+ # if frame.line:
14
+ # session.error(f" {frame.line}", Settings.gettext("script_error"))
15
+
16
+ # session.error(Settings.gettext("exception_message", type(e).__name__, e), Settings.gettext("script_error"))
17
+ # session.error("===========================", Settings.gettext("script_error"))
18
+ session.error(traceback.format_exc(), Settings.gettext("script_error"))
19
+
20
+ def exception(func):
21
+ """方法异常处理装饰器,捕获异常后通过会话的session.error打印相关信息"""
22
+ @functools.wraps(func)
23
+ def wrapper(self, *args, **kwargs):
24
+ from .objects import BaseObject
25
+ from .modules import ModuleInfo, IConfig
26
+ from .session import Session
27
+ from .settings import Settings
28
+ try:
29
+ return func(self, *args, **kwargs)
30
+ except Exception as e:
31
+ # 调用类的错误处理方法
32
+ if isinstance(self, Session):
33
+ session = self
34
+ elif isinstance(self, (BaseObject, IConfig, ModuleInfo)):
35
+ session = self.session
36
+ else:
37
+ session = None
38
+
39
+ if isinstance(session, Session):
40
+ print_exception(session, e)
41
+ #session.error(Settings.gettext("exception_message", e, type(e)))
42
+ #session.error(Settings.gettext("exception_traceback", traceback.format_exc()))
43
+ else:
44
+ raise # 当没有会话时,选择重新抛出异常
45
+ return wrapper
46
+
47
+ def async_exception(func):
48
+ """异步方法异常处理装饰器,捕获异常后通过会话的session.error打印相关信息"""
49
+ @functools.wraps(func)
50
+ async def wrapper(self, *args, **kwargs):
51
+ from .objects import BaseObject
52
+ from .modules import ModuleInfo, IConfig
53
+ from .session import Session
54
+ from .settings import Settings
55
+ try:
56
+ return await func(self, *args, **kwargs)
57
+ except Exception as e:
58
+ if isinstance(self, Session):
59
+ session = self
60
+ elif isinstance(self, (BaseObject, IConfig, ModuleInfo)):
61
+ session = self.session
62
+ else:
63
+ session = None
64
+
65
+ if isinstance(session, Session):
66
+ print_exception(session, e)
67
+
68
+ else:
69
+ raise # 当没有会话时,选择重新抛出异常
70
+ return wrapper
71
+
72
+
73
+ class PymudDecorator:
74
+ """
75
+ 装饰器基类。使用装饰器可以快捷创建各类Pymud基础对象。
76
+
77
+ :param type: 装饰器的类型,用于区分不同的装饰器,为字符串类型。
78
+ :param args: 可变位置参数,用于传递额外的参数。
79
+ :param kwargs: 可变关键字参数,用于传递额外的键值对参数。
80
+ """
81
+ def __init__(self, type: str, *args, **kwargs):
82
+ self.type = type
83
+ self.args = args
84
+ self.kwargs = kwargs
85
+
86
+ def __call__(self, func):
87
+ decos = getattr(func, "__pymud_decorators__", [])
88
+ decos.append(self)
89
+ func.__pymud_decorators__ = decos
90
+
91
+ return func
92
+
93
+ def __repr__(self):
94
+ return f"<{self.__class__.__name__} type = {self.type} args = {self.args} kwargs = {self.kwargs}>"
95
+
96
+
97
+ def alias(
98
+ patterns: Union[List[str], str],
99
+ id: Optional[str] = None,
100
+ group: str = "",
101
+ enabled: bool = True,
102
+ ignoreCase: bool = False,
103
+ isRegExp: bool = True,
104
+ keepEval: bool = False,
105
+ expandVar: bool = True,
106
+ priority: int = 100,
107
+ oneShot: bool = False,
108
+ *args, **kwargs):
109
+ """
110
+ 使用装饰器创建一个别名(Alias)对象。被装饰的函数将在别名成功匹配时调用。
111
+ 被装饰的函数,除第一个参数为类实例本身self之外,另外包括id, line, wildcards三个参数。
112
+ 其中id为别名对象的唯一标识符,line为匹配的文本行,wildcards为匹配的通配符列表。
113
+
114
+ :param patterns: 别名匹配的模式。
115
+ :param id: 别名对象的唯一标识符,不指定时将自动生成唯一标识符。
116
+ :param group: 别名所属的组名,默认为空字符串。
117
+ :param enabled: 别名是否启用,默认为 True。
118
+ :param ignoreCase: 匹配时是否忽略大小写,默认为 False。
119
+ :param isRegExp: 模式是否为正则表达式,默认为 True。
120
+ :param keepEval: 若存在多个可匹配的别名时,是否持续匹配,默认为 False。
121
+ :param expandVar: 是否展开变量,默认为 True。
122
+ :param priority: 别名的优先级,值越小优先级越高,默认为 100。
123
+ :param oneShot: 别名是否只触发一次后自动失效,默认为 False。
124
+ :param args: 可变位置参数,用于传递额外的参数。
125
+ :param kwargs: 可变关键字参数,用于传递额外的键值对参数。
126
+ :return: PymudDecorator 实例,类型为 "alias"。
127
+ """
128
+ # 将传入的参数更新到 kwargs 字典中
129
+ kwargs.update({
130
+ "patterns": patterns,
131
+ "id": id,
132
+ "group": group,
133
+ "enabled": enabled,
134
+ "ignoreCase": ignoreCase,
135
+ "isRegExp": isRegExp,
136
+ "keepEval": keepEval,
137
+ "expandVar": expandVar,
138
+ "priority": priority,
139
+ "oneShot": oneShot})
140
+
141
+ # 如果 id 为 None,则从 kwargs 中移除 "id" 键
142
+ if not id:
143
+ kwargs.pop("id")
144
+
145
+ return PymudDecorator("alias", *args, **kwargs)
146
+
147
+ def trigger(
148
+ patterns: Union[List[str], str],
149
+ id: Optional[str] = None,
150
+ group: str = "",
151
+ enabled: bool = True,
152
+ ignoreCase: bool = False,
153
+ isRegExp: bool = True,
154
+ keepEval: bool = False,
155
+ expandVar: bool = True,
156
+ raw: bool = False,
157
+ priority: int = 100,
158
+ oneShot: bool = False,
159
+ *args, **kwargs):
160
+ """
161
+ 使用装饰器创建一个触发器(Trigger)对象。
162
+
163
+ :param patterns: 触发器匹配的模式。单行模式可以是字符串或正则表达式,多行模式必须是元组或列表,其中每个元素都是字符串或正则表达式。
164
+ :param id: 触发器对象的唯一标识符,不指定时将自动生成唯一标识符。
165
+ :param group: 触发器所属的组名,默认为空字符串。
166
+ :param enabled: 触发器是否启用,默认为 True。
167
+ :param ignoreCase: 匹配时是否忽略大小写,默认为 False。
168
+ :param isRegExp: 模式是否为正则表达式,默认为 True。
169
+ :param keepEval: 若存在多个可匹配的触发器时,是否持续匹配,默认为 False。
170
+ :param expandVar: 是否展开变量,默认为 True。
171
+ :param raw: 是否使用原始匹配方式,默认为 False。原始匹配方式下,不对 VT100 下的 ANSI 颜色进行解码,因此可以匹配颜色;正常匹配仅匹配文本。
172
+ :param priority: 触发器的优先级,值越小优先级越高,默认为 100。
173
+ :param oneShot: 触发器是否只触发一次后自动失效,默认为 False。
174
+ :param args: 可变位置参数,用于传递额外的参数。
175
+ :param kwargs: 可变关键字参数,用于传递额外的键值对参数。
176
+ :return: PymudDecorator 实例,类型为 "trigger"。
177
+ """
178
+ # 将传入的参数更新到 kwargs 字典中
179
+ kwargs.update({
180
+ "patterns": patterns,
181
+ "id": id,
182
+ "group": group,
183
+ "enabled": enabled,
184
+ "ignoreCase": ignoreCase,
185
+ "isRegExp": isRegExp,
186
+ "keepEval": keepEval,
187
+ "expandVar": expandVar,
188
+ "raw": raw,
189
+ "priority": priority,
190
+ "oneShot": oneShot})
191
+ if not id:
192
+ kwargs.pop("id")
193
+ return PymudDecorator("trigger", *args, **kwargs)
194
+
195
+ def timer(timeout: float, id: Optional[str] = None, group: str = "", enabled: bool = True, *args, **kwargs):
196
+ """
197
+ 使用装饰器创建一个定时器(Timer)对象。
198
+
199
+ :param timeout: 定时器超时时间,单位为秒。
200
+ :param id: 定时器对象的唯一标识符,不指定时将自动生成唯一标识符。
201
+ :param group: 定时器所属的组名,默认为空字符串。
202
+ :param enabled: 定时器是否启用,默认为 True。
203
+ :param args: 可变位置参数,用于传递额外的参数。
204
+ :param kwargs: 可变关键字参数,用于传递额外的键值对参数。
205
+ :return: PymudDecorator 实例,类型为 "timer"。
206
+ """
207
+ kwargs.update({
208
+ "timeout": timeout,
209
+ "id": id,
210
+ "group": group,
211
+ "enabled": enabled
212
+ })
213
+ if not id:
214
+ kwargs.pop("id")
215
+ return PymudDecorator("timer", *args, **kwargs)
216
+
217
+ def gmcp(name: str, group: str = "", enabled: bool = True, *args, **kwargs):
218
+ """
219
+ 使用装饰器创建一个GMCP触发器(GMCPTrigger)对象。
220
+
221
+ :param name: GMCP触发器的名称。
222
+ :param group: GMCP触发器所属的组名,默认为空字符串。
223
+ :param enabled: GMCP触发器是否启用,默认为 True。
224
+ :param args: 可变位置参数,用于传递额外的参数。
225
+ :param kwargs: 可变关键字参数,用于传递额外的键值对参数。
226
+ :return: PymudDecorator 实例,类型为 "gmcp"。
227
+ """
228
+ kwargs.update({
229
+ "id": name,
230
+ "group": group,
231
+ "enabled": enabled
232
+ })
233
+
234
+ return PymudDecorator("gmcp", *args, **kwargs)
@@ -310,7 +310,7 @@ class SessionBufferControl(BufferControl):
310
310
  # Focus buffer when clicked.
311
311
  cur_control = get_app().layout.current_control
312
312
  cur_buffer = get_app().layout.current_buffer
313
- # 这里时修改的内容
313
+ # 这里是修改的内容
314
314
  if (cur_control == self) or (cur_buffer and cur_buffer.name == "input"):
315
315
  if self._last_get_processed_line:
316
316
  processed_line = self._last_get_processed_line(position.y)
@@ -86,13 +86,17 @@ TRANSLATION = {
86
86
  "load_fail" : "加载失败",
87
87
  "unload_ok" : "卸载完成",
88
88
  "reload_ok" : "重新加载完成",
89
+ "msg_plugin_unloaded" : "本会话中插件 {0} 已停用。",
90
+ "msg_plugin_loaded" : "本会话中插件 {0} 已启用。",
89
91
 
90
92
  # text in objects.py
91
93
  "excpetion_brace_not_matched" : "错误的代码块,大括号数量不匹配",
92
94
  "exception_quote_not_matched" : "引号的数量不匹配",
93
95
  "exception_forced_async" : "该命令中同时存在强制同步命令和强制异步命令,将使用异步执行,同步命令将失效。",
94
96
  "exception_session_type_fail" : "session 必须是 Session 类型对象的实例!",
95
- "exception_in_async" : "异步执行中遇到异常, {}",
97
+ "exception_message" : "异常信息: <{}> {}",
98
+ "exception_traceback" : '脚本执行异常, 异常位于文件"{}"中的第{}行的"{}"函数中。',
99
+ "script_error" : "脚本错误",
96
100
 
97
101
 
98
102
  # text display in session.py
@@ -173,7 +177,7 @@ TRANSLATION = {
173
177
 
174
178
  "msg_no_plugins" : "PYMUD当前并未加载任何插件。",
175
179
  "msg_plugins_list" : "PYMUD当前已加载 {0} 个插件,分别为:",
176
- "msg_plugins_info" : "{0}, 版本 {1} 作者 {2} 发布日期 {3}",
180
+ "msg_plugins_info" : "作者 {2} 版本 {1} 发布日期 {3}\n 简介: {0}",
177
181
 
178
182
  "msg_py_exception" : "Python执行错误:{0}",
179
183
 
@@ -86,13 +86,17 @@ TRANSLATION = {
86
86
  "load_fail" : "Load failed",
87
87
  "unload_ok" : "Unload completed",
88
88
  "reload_ok" : "Reload completed",
89
+ "msg_plugin_unloaded" : "Plugin {0} has been disabled for this session.",
90
+ "msg_plugin_loaded" : "Plugin {0} has been enabled for this session.",
89
91
 
90
92
  # text in objects.py
91
93
  "excpetion_brace_not_matched" : "Invalid code block, number of braces does not match",
92
94
  "exception_quote_not_matched" : "Number of quotes does not match",
93
95
  "exception_forced_async" : "This command contains both forced synchronous and asynchronous commands, will use asynchronous execution, synchronous commands will be invalid.",
94
96
  "exception_session_type_fail" : "session must be an instance of Session type object!",
95
- "exception_in_async" : "Exception occurred during asynchronous execution, {}",
97
+ "exception_message" : "Exception information: <{}> {}",
98
+ "exception_traceback" : "Exception occurred at line number {1} in file '{0}', and function name is '{2}'",
99
+ "script_error" : "Script Error",
96
100
 
97
101
  # text display in session.py
98
102
  "msg_var_autoload_success" : "Variables automatically loaded from {0} successfully.",
@@ -172,7 +176,7 @@ TRANSLATION = {
172
176
 
173
177
  "msg_no_plugins" : "PYMUD currently has no plugins loaded.",
174
178
  "msg_plugins_list" : "PYMUD currently has {0} plugins loaded, respectively:",
175
- "msg_plugins_info" : "{0}, version {1} author {2} release date {3}",
179
+ "msg_plugins_info" : "Author {2} Version {1} Release Date {3}\n Description: {0}",
176
180
 
177
181
  "msg_py_exception" : "Python execution error: {0}",
178
182
 
@@ -363,21 +367,24 @@ TRANSLATION = {
363
367
 
364
368
  "handle_test" :
365
369
  '''
366
- The execution function of the embedded command #test/#show, trigger testing command. Similar to zmud's #show command.
370
+ The execution function of the embedded command #test/#show/#echo, trigger testing command. Similar to zmud's #show command.
367
371
  This function should not be called directly in the code.
368
372
 
369
373
  Usage:
370
- - #show {some_text}: Test trigger response when server receives {some_text}. Triggers won't actually execute.
371
- - #test {some_test}: Difference from #show is that matched triggers will execute regardless of enabled status.
374
+ - #show {some_text}: Test trigger response when receives {some_text}. Triggers won't actually execute.
375
+ - #test {some_text}: Difference from #show is that matched triggers will execute regardless of enabled status.
376
+ - #echo {some_text}: Simulate receiving {some_text} from server, triggers will execute normally but won't display test results.
372
377
 
373
378
  Examples:
374
379
  - ``#show You take a deep breath and stand up.``: Simulate trigger testing when server receives "You take a deep breath and stand up." (display test results only)
375
380
  - ``#test %copy``: Copy a sentence and simulate trigger testing when server receives the copied content again
376
381
  - ``#test You take a deep breath and stand up.``: Actual trigger execution will occur even if disabled
382
+ - ``#echo You take a deep breath and stand up.``: Simulate trigger testing when server receives "You take a deep breath and stand up." (won't display test results)
377
383
 
378
384
  Notes:
379
385
  - #show command only displays test results without actual trigger execution
380
- - #ttest command forces actual trigger execution regardless of enabled status
386
+ - #test command forces actual trigger execution regardless of enabled status
387
+ - #echo command can be used to manually trigger triggers
381
388
  ''',
382
389
 
383
390
  "handle_timer" :
@@ -5,23 +5,28 @@ from .settings import Settings
5
5
 
6
6
  CFG_TEMPLATE = {
7
7
  "language" : "chs", # 语言设置,默认为简体中文
8
+
8
9
  "client": {
9
10
  "buffer_lines" : 5000, # 保留缓冲行数
10
11
 
11
12
  "interval" : 10, # 在自动执行中,两次命令输入中的间隔时间(ms)
12
13
  "auto_connect" : True, # 创建会话后,是否自动连接
13
14
  "auto_reconnect" : False, # 在会话异常断开之后,是否自动重连
15
+ "reconnect_wait" : 15, # 自动重连等待的时间(秒数)
14
16
  "var_autosave" : True, # 断开时自动保存会话变量
15
17
  "var_autoload" : True, # 初始化时自动加载会话变量
16
18
 
17
- "echo_input" : False,
18
19
  "beautify" : True, # 专门为解决控制台下PKUXKX字符画对不齐的问题
20
+ "history_records" : 500,
19
21
 
22
+ "status_divider" : False, # 是否显示状态栏的分隔线
20
23
  "status_display" : 1, # 状态窗口显示情况设置,0-不显示,1-显示在下方,2-显示在右侧
21
24
  "status_height" : 4, # 下侧状态栏的高度
22
25
  "status_width" : 30, # 右侧状态栏的宽度
26
+
23
27
 
24
28
  },
29
+
25
30
  "sessions" : {
26
31
  "pkuxkx" : {
27
32
  "host" : "mud.pkuxkx.net",
@@ -68,7 +73,11 @@ def init_pymud_env(args):
68
73
 
69
74
  dir = args.dir
70
75
  if dir:
71
- print(f"你已经指定了创建脚本的目录为 {args.dir}")
76
+ if dir == ".":
77
+ dir_msg = "当前目录"
78
+ else:
79
+ dir_msg = f": {dir}"
80
+ print(f"你已经指定了创建脚本的目录为{dir_msg}")
72
81
  dir = Path(dir)
73
82
  else:
74
83
  dir = Path.home().joinpath('pkuxkx')
@@ -112,7 +121,11 @@ def init_pymud_env(args):
112
121
  print("Starting to initialize the environment for the first time...")
113
122
  dir = args.dir
114
123
  if dir:
115
- print(f"You have specified the directory to create the script as {args.dir}")
124
+ if dir == ".":
125
+ dir_msg = "current directory"
126
+ else:
127
+ dir_msg = f": {dir}"
128
+ print(f"You have specified the directory to create the script as {dir_msg}")
116
129
  dir = Path(dir)
117
130
  else:
118
131
  dir = Path.home().joinpath('pkuxkx')
@@ -189,7 +202,7 @@ def main():
189
202
  subparsers = parser.add_subparsers(help = 'init用于初始化运行环境')
190
203
 
191
204
  par_init = subparsers.add_parser('init', description = '初始化pymud运行环境, 包括建立脚本目录, 创建默认配置文件, 创建样例脚本等.')
192
- par_init.add_argument('-d', '--dir', dest = 'dir', metavar = 'dir', type = str, default = '', help = '指定构建脚本目录的名称, 不指定时会根据操作系统选择不同默认值')
205
+ par_init.add_argument('-d', '--dir', dest = 'dir', metavar = 'dir', type = str, default = '.', help = '指定构建脚本目录的名称, 不指定时会根据操作系统选择不同默认值')
193
206
  par_init.set_defaults(func = init_pymud_env)
194
207
 
195
208
  parser.add_argument('-d', '--debug', dest = 'debug', action = 'store_true', default = False, help = '指定以调试模式进入PyMUD。此时,系统log等级将设置为logging.NOTSET, 所有log数据均会被记录。默认不启用。')