pymud 0.20.0__py3-none-any.whl → 0.20.0a1__py3-none-any.whl
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.
- pymud/__init__.py +1 -3
- pymud/__main__.py +138 -2
- pymud/dialogs.py +6 -11
- pymud/extras.py +73 -1
- pymud/logger.py +4 -10
- pymud/objects.py +14 -45
- pymud/pkuxkx.py +7 -4
- pymud/pymud.py +54 -92
- pymud/session.py +141 -376
- pymud/settings.py +1 -1
- {pymud-0.20.0.dist-info → pymud-0.20.0a1.dist-info}/METADATA +194 -225
- pymud-0.20.0a1.dist-info/RECORD +17 -0
- {pymud-0.20.0.dist-info → pymud-0.20.0a1.dist-info}/WHEEL +1 -1
- pymud/main.py +0 -142
- pymud/modules.py +0 -188
- pymud-0.20.0.dist-info/RECORD +0 -19
- {pymud-0.20.0.dist-info → pymud-0.20.0a1.dist-info}/LICENSE.txt +0 -0
- {pymud-0.20.0.dist-info → pymud-0.20.0a1.dist-info}/entry_points.txt +0 -0
- {pymud-0.20.0.dist-info → pymud-0.20.0a1.dist-info}/top_level.txt +0 -0
pymud/__init__.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
from .settings import Settings
|
2
2
|
from .pymud import PyMudApp
|
3
|
-
from .modules import IConfig
|
4
3
|
from .objects import CodeBlock, Alias, SimpleAlias, Trigger, SimpleTrigger, Command, SimpleCommand, Timer, SimpleTimer, GMCPTrigger
|
5
4
|
from .extras import DotDict
|
6
5
|
from .session import Session
|
7
6
|
from .logger import Logger
|
8
|
-
from .main import main
|
9
7
|
|
10
8
|
__all__ = [
|
11
|
-
"
|
9
|
+
"PyMudApp", "Settings", "CodeBlock", "Alias", "SimpleAlias", "Trigger", "SimpleTrigger", "Command", "SimpleCommand", "Timer", "SimpleTimer", "GMCPTrigger", "Session", "PyMudApp", "DotDict", "Logger"
|
12
10
|
]
|
pymud/__main__.py
CHANGED
@@ -1,4 +1,140 @@
|
|
1
|
-
|
1
|
+
import sys, os, json, platform, shutil, logging, argparse
|
2
|
+
from .pymud import main
|
3
|
+
from .settings import Settings
|
4
|
+
|
5
|
+
CFG_TEMPLATE = {
|
6
|
+
"client": {
|
7
|
+
"buffer_lines" : 5000, # 保留缓冲行数
|
8
|
+
|
9
|
+
"interval" : 10, # 在自动执行中,两次命令输入中的间隔时间(ms)
|
10
|
+
"auto_connect" : True, # 创建会话后,是否自动连接
|
11
|
+
"auto_reconnect" : False, # 在会话异常断开之后,是否自动重连
|
12
|
+
"var_autosave" : True, # 断开时自动保存会话变量
|
13
|
+
"var_autoload" : True, # 初始化时自动加载会话变量
|
14
|
+
|
15
|
+
"echo_input" : False,
|
16
|
+
"beautify" : True, # 专门为解决控制台下PKUXKX字符画对不齐的问题
|
17
|
+
|
18
|
+
"status_display" : 1, # 状态窗口显示情况设置,0-不显示,1-显示在下方,2-显示在右侧
|
19
|
+
"status_height" : 4, # 下侧状态栏的高度
|
20
|
+
"status_width" : 30, # 右侧状态栏的宽度
|
21
|
+
|
22
|
+
},
|
23
|
+
"sessions" : {
|
24
|
+
"pkuxkx" : {
|
25
|
+
"host" : "mud.pkuxkx.net",
|
26
|
+
"port" : "8081",
|
27
|
+
"encoding" : "utf8",
|
28
|
+
"autologin" : "{0};{1}",
|
29
|
+
"default_script": "examples",
|
30
|
+
"chars" : {
|
31
|
+
"display_title" : ["yourid", "yourpassword", ""],
|
32
|
+
}
|
33
|
+
}
|
34
|
+
},
|
35
|
+
"keys" : {
|
36
|
+
"f3" : "#ig",
|
37
|
+
"f4" : "#clear",
|
38
|
+
"f11" : "#close",
|
39
|
+
"f12" : "#exit",
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
def init_pymud_env(args):
|
44
|
+
print(f"欢迎使用PyMUD, 版本{Settings.__version__}. 使用PyMUD时, 建议建立一个新目录(任意位置),并将自己的脚本以及配置文件放到该目录下.")
|
45
|
+
print("即将开始为首次运行初始化环境...")
|
46
|
+
system = platform.system().lower()
|
47
|
+
|
48
|
+
dir = args.dir
|
49
|
+
if dir:
|
50
|
+
print(f"你已经指定了创建脚本的目录为 {args.dir}, 将不再检测操作系统")
|
51
|
+
|
52
|
+
else:
|
53
|
+
if system == "windows":
|
54
|
+
dir = input("检测到当前系统为Windows, 请指定游戏脚本的目录(若目录不存在会自动创建),直接回车表示使用默认值[d:\pkuxkx]:")
|
55
|
+
if not dir: dir = "d:\\pkuxkx"
|
56
|
+
|
57
|
+
elif system == "linux":
|
58
|
+
dir = input("检测到当前系统为Linux, 请指定游戏脚本的目录(若目录不存在会自动创建),直接回车表示使用默认值[~/pkuxkx]:")
|
59
|
+
if not dir: dir = "~/pkuxkx"
|
60
|
+
|
61
|
+
elif system == "darwin":
|
62
|
+
dir = input("检测到当前系统为MacOS, 请指定游戏脚本的目录(若目录不存在会自动创建),直接回车表示使用默认值[~/pkuxkx]:")
|
63
|
+
if not dir: dir = "~/pkuxkx"
|
64
|
+
|
65
|
+
else:
|
66
|
+
print(f"当前系统不是Windows、Linux或MacOS, 无法通过init来进行配置, 请手动配置. 默认配置即将推出")
|
67
|
+
|
68
|
+
|
69
|
+
if not os.path.exists(dir):
|
70
|
+
print(f'检测到给定目录 {dir} 不存在,正在创建目录...', end = "")
|
71
|
+
os.mkdir(dir)
|
72
|
+
os.chdir(dir)
|
73
|
+
print(f'完成!')
|
74
|
+
|
75
|
+
if os.path.exists('pymud.cfg'):
|
76
|
+
print(f'检测到脚本目录下已存在pymud.cfg文件,将直接使用此文件进入PyMUD...')
|
77
|
+
else:
|
78
|
+
print(f'检测到脚本目录下不存在pymud.cfg文件,将使用默认内容创建该配置文件...')
|
79
|
+
with open('pymud.cfg', mode = 'x') as fp:
|
80
|
+
fp.writelines(json.dumps(CFG_TEMPLATE, indent = 4))
|
81
|
+
|
82
|
+
if not os.path.exists('examples.py'):
|
83
|
+
from pymud import pkuxkx
|
84
|
+
module_dir = pkuxkx.__file__
|
85
|
+
shutil.copyfile(module_dir, 'examples.py')
|
86
|
+
print(f'已将样例脚本拷贝至脚本目录,并加入默认配置文件')
|
87
|
+
|
88
|
+
print(f"后续可自行修改 {dir} 目录下的 pymud.cfg 文件以进行配置。")
|
89
|
+
if system == "windows":
|
90
|
+
print(f"后续运行PyMUD, 请在 {dir} 目录下键入命令: python -m pymud")
|
91
|
+
else:
|
92
|
+
print(f"后续运行PyMUD, 请在 {dir} 目录下键入命令: python3 -m pymud")
|
93
|
+
|
94
|
+
input('所有内容已初始化完毕, 请按回车进入PyMUD.')
|
95
|
+
|
96
|
+
module_entry(args)
|
97
|
+
|
98
|
+
def module_entry(args):
|
99
|
+
if args.debug:
|
100
|
+
logging.basicConfig(level = logging.NOTSET,
|
101
|
+
format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
|
102
|
+
datefmt = '%m-%d %H:%M',
|
103
|
+
filename = args.logfile,
|
104
|
+
filemode = 'a' if args.filemode else 'w',
|
105
|
+
encoding = "utf-8"
|
106
|
+
)
|
107
|
+
|
108
|
+
else:
|
109
|
+
logging.basicConfig(level = logging.NOTSET,
|
110
|
+
format = '%(asctime)s %(name)-12s: %(message)s',
|
111
|
+
datefmt = '%m-%d %H:%M',
|
112
|
+
handlers = [logging.NullHandler()],
|
113
|
+
)
|
114
|
+
|
115
|
+
cfg = "pymud.cfg"
|
116
|
+
if os.path.exists(cfg):
|
117
|
+
with open(cfg, "r", encoding="utf8", errors="ignore") as fp:
|
118
|
+
cfg_data = json.load(fp)
|
119
|
+
main(cfg_data)
|
120
|
+
else:
|
121
|
+
main()
|
122
|
+
|
2
123
|
|
3
124
|
if __name__ == "__main__":
|
4
|
-
|
125
|
+
parser = argparse.ArgumentParser(prog = "pymud", usage = "python -m pymud [-h] [-d] [-l logfile] [-a] {init} ...", description = "PyMUD命令行参数帮助")
|
126
|
+
subparsers = parser.add_subparsers(help = 'init用于初始化运行环境')
|
127
|
+
|
128
|
+
par_init = subparsers.add_parser('init', usage = "python -m pymud init [-h] [-d dir]", description = '初始化pymud运行环境, 包括建立脚本目录, 创建默认配置文件, 创建样例脚本等.')
|
129
|
+
par_init.add_argument('-d', '--dir', dest = 'dir', metavar = 'dir', type = str, default = '', help = '指定构建脚本目录的名称, 不指定时会根据操作系统选择不同默认值')
|
130
|
+
par_init.set_defaults(func = init_pymud_env)
|
131
|
+
|
132
|
+
parser.add_argument('-d', '--debug', dest = 'debug', action = 'store_true', default = False, help = '指定以调试模式进入PyMUD。此时,系统log等级将设置为logging.NOTSET, 所有log数据均会被记录。默认不启用。')
|
133
|
+
parser.add_argument('-l', '--logfile', dest = 'logfile', metavar = 'logfile', default = 'pymud.log', help = '指定调试模式下记录文件名,不指定时,默认为当前目录下的pymud.log')
|
134
|
+
parser.add_argument('-a', '--appendmode', dest = 'filemode', action = 'store_true', default = True, help = '指定log文件的访问模式是否为append尾部添加模式,默认为True。当为False时,使用w模式,即每次运行清空之前记录')
|
135
|
+
|
136
|
+
args=parser.parse_args()
|
137
|
+
if hasattr(args, 'func'):
|
138
|
+
args.func(args)
|
139
|
+
else:
|
140
|
+
module_entry(args)
|
pymud/dialogs.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import asyncio, webbrowser
|
2
2
|
|
3
3
|
from prompt_toolkit.layout import AnyContainer, ConditionalContainer, Float, VSplit, HSplit, Window, WindowAlign, ScrollablePane, ScrollOffsets
|
4
|
-
from prompt_toolkit.widgets import Button, Dialog, Label, MenuContainer, MenuItem, TextArea, SystemToolbar, Frame, RadioList
|
4
|
+
from prompt_toolkit.widgets import Button, Dialog, Label, MenuContainer, MenuItem, TextArea, SystemToolbar, Frame, RadioList
|
5
5
|
from prompt_toolkit.layout.dimension import Dimension, D
|
6
6
|
from prompt_toolkit import ANSI, HTML
|
7
7
|
from prompt_toolkit.mouse_events import MouseEvent, MouseEventType
|
@@ -133,14 +133,12 @@ class LogSelectionDialog(BasicDialog):
|
|
133
133
|
def __init__(self, text, values, modal=True):
|
134
134
|
self._header_text = text
|
135
135
|
self._selection_values = values
|
136
|
-
self.
|
137
|
-
if len(values) > 0:
|
138
|
-
self._radio_list = RadioList(values = self._selection_values)
|
139
|
-
else:
|
140
|
-
self._radio_list = Label('无记录'.center(13))
|
136
|
+
self._radio_list = RadioList(values = self._selection_values)
|
141
137
|
super().__init__('选择查看的记录', modal)
|
142
138
|
|
143
139
|
def create_body(self) -> AnyContainer:
|
140
|
+
|
141
|
+
|
144
142
|
body=HSplit([
|
145
143
|
Label(text = self._header_text, dont_extend_height=True),
|
146
144
|
self._radio_list
|
@@ -153,9 +151,6 @@ class LogSelectionDialog(BasicDialog):
|
|
153
151
|
return [ok_button, cancel_button]
|
154
152
|
|
155
153
|
def btn_ok_clicked(self):
|
156
|
-
|
157
|
-
|
158
|
-
self.set_done(result)
|
159
|
-
else:
|
160
|
-
self.set_done(False)
|
154
|
+
result = self._radio_list.current_value
|
155
|
+
self.set_done(result)
|
161
156
|
|
pymud/extras.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# External Libraries
|
2
2
|
from unicodedata import east_asian_width
|
3
3
|
from wcwidth import wcwidth
|
4
|
-
import
|
4
|
+
from typing import Any
|
5
|
+
import time, datetime
|
5
6
|
|
6
7
|
from typing import Iterable
|
7
8
|
from prompt_toolkit import ANSI
|
@@ -1007,5 +1008,76 @@ class DotDict(dict):
|
|
1007
1008
|
def __setstate__(self, state):
|
1008
1009
|
self.update(state)
|
1009
1010
|
|
1011
|
+
import importlib
|
1012
|
+
import importlib.util
|
1010
1013
|
|
1014
|
+
class Plugin:
|
1015
|
+
"""
|
1016
|
+
插件管理类。对加载的插件文件进行管理。该类型由PyMudApp进行管理,无需人工创建。
|
1017
|
+
|
1018
|
+
有关插件的详细信息,请参见 `插件 <plugins.html>`_
|
1019
|
+
|
1020
|
+
:param name: 插件的文件名, 如'myplugin.py'
|
1021
|
+
:param location: 插件所在的目录。自动加载的插件包括PyMUD包目录下的plugins目录以及当前目录下的plugins目录
|
1022
|
+
|
1023
|
+
"""
|
1024
|
+
def __init__(self, name, location):
|
1025
|
+
self._plugin_file = name
|
1026
|
+
self._plugin_loc = location
|
1027
|
+
|
1028
|
+
self.reload()
|
1029
|
+
|
1030
|
+
def reload(self):
|
1031
|
+
"加载/重新加载插件对象"
|
1032
|
+
#del self.modspec, self.mod
|
1033
|
+
self.modspec = importlib.util.spec_from_file_location(self._plugin_file[:-3], self._plugin_loc)
|
1034
|
+
self.mod = importlib.util.module_from_spec(self.modspec)
|
1035
|
+
self.modspec.loader.exec_module(self.mod)
|
1036
|
+
|
1037
|
+
self._app_init = self.mod.__dict__["PLUGIN_PYMUD_START"]
|
1038
|
+
self._session_create = self.mod.__dict__["PLUGIN_SESSION_CREATE"]
|
1039
|
+
self._session_destroy = self.mod.__dict__["PLUGIN_SESSION_DESTROY"]
|
1040
|
+
|
1041
|
+
@property
|
1042
|
+
def name(self):
|
1043
|
+
"插件名称,由插件文件中的 PLUGIN_NAME 常量定义"
|
1044
|
+
return self.mod.__dict__["PLUGIN_NAME"]
|
1045
|
+
|
1046
|
+
@property
|
1047
|
+
def desc(self):
|
1048
|
+
"插件描述,由插件文件中的 PLUGIN_DESC 常量定义"
|
1049
|
+
return self.mod.__dict__["PLUGIN_DESC"]
|
1050
|
+
|
1051
|
+
@property
|
1052
|
+
def help(self):
|
1053
|
+
"插件帮助,由插件文件中的文档字符串定义"
|
1054
|
+
return self.mod.__doc__
|
1055
|
+
|
1056
|
+
def onAppInit(self, app):
|
1057
|
+
"""
|
1058
|
+
PyMUD应用启动时对插件执行的操作,由插件文件中的 PLUGIN_PYMUD_START 函数定义
|
1059
|
+
|
1060
|
+
:param app: 启动的 PyMudApp 对象实例
|
1061
|
+
"""
|
1062
|
+
self._app_init(app)
|
1063
|
+
|
1064
|
+
def onSessionCreate(self, session):
|
1065
|
+
"""
|
1066
|
+
新会话创建时对插件执行的操作,由插件文件中的 PLUGIN_SESSION_CREATE 函数定义
|
1067
|
+
|
1068
|
+
:param session: 新创建的会话对象实例
|
1069
|
+
"""
|
1070
|
+
self._session_create(session)
|
1071
|
+
|
1072
|
+
def onSessionDestroy(self, session):
|
1073
|
+
"""
|
1074
|
+
会话关闭时(注意不是断开)对插件执行的操作,由插件文件中的 PLUGIN_SESSION_DESTROY 函数定义
|
1075
|
+
|
1076
|
+
:param session: 所关闭的会话对象实例
|
1077
|
+
"""
|
1078
|
+
self._session_destroy(session)
|
1079
|
+
|
1080
|
+
def __getattr__(self, __name: str) -> Any:
|
1081
|
+
if hasattr(self.mod, __name):
|
1082
|
+
return self.mod.__getattribute__(__name)
|
1011
1083
|
|
pymud/logger.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
import os, re, datetime, threading
|
1
|
+
import os, re, datetime, threading
|
2
2
|
from queue import SimpleQueue, Empty
|
3
|
-
from pathlib import Path
|
4
3
|
|
5
4
|
class Logger:
|
6
5
|
"""
|
7
|
-
PyMUD
|
6
|
+
PyMUD 的记录器类型,可用于会话中向文件记录数据
|
8
7
|
|
9
8
|
:param name: 记录器名称,各记录器名称应保持唯一。记录器名称会作为记录文件名称的主要参数
|
10
9
|
:param mode: 记录模式。可选模式包括 a, w, n 三种。
|
@@ -16,7 +15,7 @@ class Logger:
|
|
16
15
|
:param raw: 记录带ANSI标记的原始内容,还是记录纯文本内容,默认为True,即记录带ANSI标记的原始内容。
|
17
16
|
"""
|
18
17
|
|
19
|
-
_esc_regx = re.compile(
|
18
|
+
_esc_regx = re.compile("\x1b\\[[\d;]+[abcdmz]", flags = re.IGNORECASE)
|
20
19
|
|
21
20
|
def __init__(self, name, mode = 'a', encoding = "utf-8", errors = "ignore", raw = False):
|
22
21
|
self._name = name
|
@@ -57,12 +56,7 @@ class Logger:
|
|
57
56
|
now = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
|
58
57
|
filename = f"{self.name}.{now}.log"
|
59
58
|
|
60
|
-
|
61
|
-
if not logdir.exists() or not logdir.is_dir():
|
62
|
-
logdir.mkdir()
|
63
|
-
|
64
|
-
filename = logdir.joinpath(filename)
|
65
|
-
#filename = os.path.abspath(filename)
|
59
|
+
filename = os.path.abspath(filename)
|
66
60
|
self._stream = open(filename, mode = mode, encoding = self._encoding, errors = self._errors)
|
67
61
|
self._thread = t = threading.Thread(target=self._monitor)
|
68
62
|
t.daemon = True
|
pymud/objects.py
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
MUD会话(session)中, 支持的对象列表
|
3
3
|
"""
|
4
4
|
|
5
|
-
import asyncio, logging, re
|
6
|
-
from abc import ABC, ABCMeta, abstractmethod
|
5
|
+
import asyncio, logging, re
|
7
6
|
from collections.abc import Iterable
|
8
7
|
from collections import namedtuple
|
9
8
|
from typing import Any
|
@@ -148,7 +147,7 @@ class CodeLine:
|
|
148
147
|
return new_code_str, new_code
|
149
148
|
|
150
149
|
async def async_execute(self, session, *args, **kwargs):
|
151
|
-
|
150
|
+
await session.exec_code_async(self, *args, **kwargs)
|
152
151
|
|
153
152
|
class CodeBlock:
|
154
153
|
"""
|
@@ -278,16 +277,14 @@ class CodeBlock:
|
|
278
277
|
"""
|
279
278
|
以异步方式执行该 CodeBlock。参数与 execute 相同。
|
280
279
|
"""
|
281
|
-
result = None
|
282
280
|
for code in self.codes:
|
283
281
|
if isinstance(code, CodeLine):
|
284
|
-
|
282
|
+
await code.async_execute(session, *args, **kwargs)
|
285
283
|
|
286
284
|
if Settings.client["interval"] > 0:
|
287
285
|
await asyncio.sleep(Settings.client["interval"] / 1000.0)
|
288
286
|
|
289
287
|
session.clean_finished_tasks()
|
290
|
-
return result
|
291
288
|
|
292
289
|
class BaseObject:
|
293
290
|
"""
|
@@ -322,12 +319,7 @@ class BaseObject:
|
|
322
319
|
"内部缩写代码前缀"
|
323
320
|
|
324
321
|
def __init__(self, session, *args, **kwargs):
|
325
|
-
|
326
|
-
if isinstance(session, Session):
|
327
|
-
self.session = session
|
328
|
-
else:
|
329
|
-
assert("session must be an instance of class Session!")
|
330
|
-
|
322
|
+
self.session = session
|
331
323
|
self._enabled = True # give a default value
|
332
324
|
self.log = logging.getLogger(f"pymud.{self.__class__.__name__}")
|
333
325
|
self.id = kwargs.get("id", session.getUniqueID(self.__class__.__abbr__))
|
@@ -348,8 +340,6 @@ class BaseObject:
|
|
348
340
|
|
349
341
|
self.log.debug(f"对象实例 {self} 创建成功.")
|
350
342
|
|
351
|
-
self.session.addObject(self)
|
352
|
-
|
353
343
|
@property
|
354
344
|
def enabled(self):
|
355
345
|
"可读写属性,使能或取消使能本对象"
|
@@ -400,8 +390,7 @@ class BaseObject:
|
|
400
390
|
return self.__detailed__()
|
401
391
|
|
402
392
|
def __detailed__(self) -> str:
|
403
|
-
|
404
|
-
return f'<{self.__class__.__name__}> id = "{self.id}" {group}enabled = {self.enabled}'
|
393
|
+
return f'<{self.__class__.__name__}> id = "{self.id}" group = "{self.group}" enabled = {self.enabled}'
|
405
394
|
|
406
395
|
class GMCPTrigger(BaseObject):
|
407
396
|
"""
|
@@ -451,8 +440,7 @@ class GMCPTrigger(BaseObject):
|
|
451
440
|
self._onSuccess(self.id, value, value_exp)
|
452
441
|
|
453
442
|
def __detailed__(self) -> str:
|
454
|
-
|
455
|
-
return f'<{self.__class__.__name__}> name = "{self.id}" value = "{self.value}" {group}enabled = {self.enabled} '
|
443
|
+
return f'<{self.__class__.__name__}> name = "{self.id}" value = "{self.value}" group = "{self.group}" enabled = {self.enabled} '
|
456
444
|
|
457
445
|
class MatchObject(BaseObject):
|
458
446
|
"""
|
@@ -487,7 +475,7 @@ class MatchObject(BaseObject):
|
|
487
475
|
super().__init__(session, patterns = patterns, *args, **kwargs)
|
488
476
|
|
489
477
|
def __del__(self):
|
490
|
-
|
478
|
+
self.reset()
|
491
479
|
|
492
480
|
@property
|
493
481
|
def patterns(self):
|
@@ -526,11 +514,11 @@ class MatchObject(BaseObject):
|
|
526
514
|
self._mline = 0
|
527
515
|
|
528
516
|
def reset(self):
|
529
|
-
"复位事件,用于async
|
517
|
+
"复位事件,用于async执行未等待结果时,对事件的复位"
|
530
518
|
self.event.clear()
|
531
519
|
|
532
520
|
def set(self):
|
533
|
-
"
|
521
|
+
"设置事件标记,用于人工强制触发"
|
534
522
|
self.event.set()
|
535
523
|
|
536
524
|
def match(self, line: str, docallback = True) -> BaseObject.State:
|
@@ -626,8 +614,7 @@ class MatchObject(BaseObject):
|
|
626
614
|
return self.state
|
627
615
|
|
628
616
|
def __detailed__(self) -> str:
|
629
|
-
|
630
|
-
return f'<{self.__class__.__name__}> id = "{self.id}" {group}enabled = {self.enabled} patterns = "{self.patterns}"'
|
617
|
+
return f'<{self.__class__.__name__}> id = "{self.id}" group = "{self.group}" enabled = {self.enabled} patterns = "{self.patterns}"'
|
631
618
|
|
632
619
|
class Alias(MatchObject):
|
633
620
|
"""
|
@@ -657,8 +644,7 @@ class SimpleAlias(Alias):
|
|
657
644
|
self._codeblock.execute(self.session, id = id, line = line, wildcards = wildcards)
|
658
645
|
|
659
646
|
def __detailed__(self) -> str:
|
660
|
-
|
661
|
-
return f'<{self.__class__.__name__}> id = "{self.id}" {group}enabled = {self.enabled} patterns = "{self.patterns}" code = "{self._code}"'
|
647
|
+
return f'<{self.__class__.__name__}> id = "{self.id}" group = "{self.group}" enabled = {self.enabled} patterns = "{self.patterns}" code = "{self._code}"'
|
662
648
|
|
663
649
|
def __repr__(self) -> str:
|
664
650
|
return self.__detailed__()
|
@@ -709,8 +695,7 @@ class SimpleTrigger(Trigger):
|
|
709
695
|
self._codeblock.execute(self.session, id = id, line = line, raw = raw, wildcards = wildcards)
|
710
696
|
|
711
697
|
def __detailed__(self) -> str:
|
712
|
-
|
713
|
-
return f'<{self.__class__.__name__}> id = "{self.id}" {group}enabled = {self.enabled} patterns = "{self.patterns}" code = "{self._code}"'
|
698
|
+
return f'<{self.__class__.__name__}> id = "{self.id}" group = "{self.group}" enabled = {self.enabled} patterns = "{self.patterns}" code = "{self._code}"'
|
714
699
|
|
715
700
|
def __repr__(self) -> str:
|
716
701
|
return self.__detailed__()
|
@@ -731,20 +716,6 @@ class Command(MatchObject):
|
|
731
716
|
super().__init__(session, patterns, sync = False, *args, **kwargs)
|
732
717
|
self._tasks = set()
|
733
718
|
|
734
|
-
def __unload__(self):
|
735
|
-
"""
|
736
|
-
当从会话中移除任务时,会自动调用该函数。
|
737
|
-
可以将命令管理的各子类对象在此处清除。
|
738
|
-
该函数需要在子类中覆盖重写。
|
739
|
-
"""
|
740
|
-
pass
|
741
|
-
|
742
|
-
def unload(self):
|
743
|
-
"""
|
744
|
-
与__unload__方法相同,子类仅需覆盖一种方法就可以
|
745
|
-
"""
|
746
|
-
pass
|
747
|
-
|
748
719
|
def create_task(self, coro, *args, name = None):
|
749
720
|
"""
|
750
721
|
创建并管理任务。由 Command 创建的任务,同时也被 Session 所管理。
|
@@ -996,8 +967,7 @@ class Timer(BaseObject):
|
|
996
967
|
self.startTimer()
|
997
968
|
|
998
969
|
def __detailed__(self) -> str:
|
999
|
-
|
1000
|
-
return f'<{self.__class__.__name__}> id = "{self.id}" {group}enabled = {self.enabled} timeout = {self.timeout}'
|
970
|
+
return f'<{self.__class__.__name__}> id = "{self.id}" group = "{self.group}" enabled = {self.enabled} timeout = {self.timeout}'
|
1001
971
|
|
1002
972
|
def __repr__(self) -> str:
|
1003
973
|
return self.__detailed__()
|
@@ -1019,6 +989,5 @@ class SimpleTimer(Timer):
|
|
1019
989
|
self._codeblock.execute(self.session, id = id)
|
1020
990
|
|
1021
991
|
def __detailed__(self) -> str:
|
1022
|
-
|
1023
|
-
return f'<{self.__class__.__name__}> id = "{self.id}" {group}enabled = {self.enabled} timeout = {self.timeout} code = "{self._code}"'
|
992
|
+
return f'<{self.__class__.__name__}> id = "{self.id}" group = "{self.group}" enabled = {self.enabled} timeout = {self.timeout} code = "{self._code}"'
|
1024
993
|
|
pymud/pkuxkx.py
CHANGED
@@ -17,9 +17,9 @@ class Configuration:
|
|
17
17
|
|
18
18
|
# hpbrief long情况下的含义
|
19
19
|
HP_KEYS = (
|
20
|
-
"
|
21
|
-
"
|
22
|
-
"
|
20
|
+
"exp", "pot", "maxneili", "neili", "maxjingli", "jingli",
|
21
|
+
"maxqi", "effqi", "qi", "maxjing", "effjing", "jing",
|
22
|
+
"zhenqi", "zhenyuan", "food", "water", "fighting", "busy"
|
23
23
|
)
|
24
24
|
|
25
25
|
# 类的构造函数,传递参数session,是会话本身
|
@@ -54,7 +54,7 @@ class Configuration:
|
|
54
54
|
|
55
55
|
# 1. fullme的链接对应的触发器,匹配URL
|
56
56
|
# 当匹配成功后,调用ontri_webpage
|
57
|
-
self._triggers["tri_webpage"] = self.tri_webpage = Trigger(self.session, id = 'tri_webpage', patterns = r'^http://fullme.pkuxkx.net/robot.php.+$', group = "sys", onSuccess =
|
57
|
+
self._triggers["tri_webpage"] = self.tri_webpage = Trigger(self.session, id = 'tri_webpage', patterns = r'^http://fullme.pkuxkx.net/robot.php.+$', group = "sys", onSuccess = self.ontri_webpage)
|
58
58
|
# 2. fullme的链接对应的触发器,因为要进行多行匹配(3行),因此匹配模式pattern为3个正则表达式模式构成的元组(所有列表类型均可识别),无需像MushClient一样要指定multiline标识和linesToMatch数量
|
59
59
|
# 当匹配成功后,调用ontri_hpbrief
|
60
60
|
# 特别说明:此处的hpbrief触发匹配,需要set hpbrief long后才可以支持
|
@@ -130,6 +130,9 @@ class Configuration:
|
|
130
130
|
def onTimer(self, name, *args, **kwargs):
|
131
131
|
self.session.info("每2秒都会打印本信息", "定时器测试")
|
132
132
|
|
133
|
+
def ontri_webpage(self, name, line, wildcards):
|
134
|
+
webbrowser.open(line)
|
135
|
+
|
133
136
|
def ontri_hpbrief(self, name, line, wildcards):
|
134
137
|
self.session.setVariables(self.HP_KEYS, wildcards)
|
135
138
|
|