cmds.tin 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 本文件属于 PaoTin++ 的一部分。
  4. PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  5. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  6. */
  7. #nop 本文件是 xtintin 的一部分,实现了一些实用命令。;
  8. ///=== {
  9. ///// 实用命令:
  10. //
  11. // ## clear
  12. // 清屏。类似于 DOS/Unix,也可以用 cls,作用相同。
  13. // };
  14. #alias {cls} {clear};
  15. #alias {clear} {
  16. #buffer clear;
  17. #buffer end;
  18. tmux.SetTheme GAME;
  19. prompt.refresh;
  20. };
  21. ///=== {
  22. // ## exit
  23. // 退出客户端,但不退出游戏角色。也可以用 quit,作用相同。
  24. // 一些中文 MUD 服务器在接收到 quit 命令时会让角色从服务器上下线,
  25. // 这往往会导致玩家丢失背包里的物品。新手玩家常常因此懊恼万分。
  26. // 为了避免悲剧发生,这里特别映射一下,改成仅断开连接,而不退出服务器角色。
  27. // 如果玩家真的需要向服务器发送 quit 指令,请输入 #send quit。exit 同理。
  28. // };
  29. #alias {exit} {#end};
  30. #alias {quit} {#end};
  31. ///=== {
  32. // ## xtt.Tick <ID> <代码> <间隔时间> [<触发次数>]
  33. // 跟 #tick 功能类似,但是会立即执行一次代码。对于间隔时间比较长的定时器来说尤其有用。
  34. // 可选的触发次数会导致定时器在次数达到限制后自动销毁。省略此参数时将不限制触发次数。
  35. // 你也可以通过 Tick 别名来使用本别名。
  36. // };
  37. #alias {Tick} {xtt.Tick};
  38. #alias {xtt.Tick} {
  39. #local id {%1};
  40. #local code {%2};
  41. #local interval {%3};
  42. #local times {@defaultNum{%4;0}};
  43. #math times {$times - 1};
  44. #line sub var #untick {$id};
  45. #if { $times > 0 } {
  46. #line sub {var;escapes;functions} #line multishot {$times} #tick {$id} {$code} $interval;
  47. };
  48. #elseif { $times < 0 } {
  49. #line sub var #tick {$id} {$code} $interval;
  50. };
  51. #line sub {var;escapes;functions} $code;
  52. };
  53. ///=== {
  54. // ## xtt.ListTicker
  55. // 列出系统中所有的定时器。因为定时器一般不会很多因此暂时没有做过滤功能。
  56. // 你也可以通过 TICKS 别名来使用本别名。
  57. // };
  58. #alias {TICKS} {xtt.ListTicker};
  59. #alias {xtt.ListTicker} {
  60. #info tickers save;
  61. #echo {<128> %-30s %+20s %+10s %+20s} {所属模块} {定时器名称} {执行周期(s)} {距离下次执行(s)};
  62. #draw Yellow scroll line 1 1 1 90;
  63. #format utime %U;
  64. #local index {};
  65. #loop {1} {&info[TICKERS][]} {index} {
  66. #local uval {};
  67. #math uval $info[TICKERS][+$index][arg3] * 1000000;
  68. #local name {$info[TICKERS][+$index][arg1]};
  69. #echo { %-30s %+20s %+10s %+20m}
  70. {@genModuleLink{$info[TICKERS][+$index][class];MOD}}
  71. {$name @mslp.Exec{{xtt.delTrigger tick $name};<119>✗<269>;false}}
  72. {$info[TICKERS][+$index][arg3]}
  73. {($uval - ($utime - $info[TICKERS][+$index][arg4]) % $uval) / 1000000.00};
  74. };
  75. };
  76. ///=== {
  77. // ## xtt.ListAlias [<正则表达式>]
  78. // 列出系统中符合条件的别名,如果省略条件则列出所有别名。
  79. // 一些不够规整的别名不会被列出。只有符合 PaoTin++ 规范的别名才会被列出。
  80. // 正则表达式会被运用到别名所属模块名称和别名名称上,两者符合其一即可被列出。
  81. // 你也可以通过 ALIS 别名来使用本别名。
  82. // };
  83. #alias {ALIS} {xtt.ListAlias};
  84. #alias {xtt.ListAlias} {
  85. #local pattern {%1};
  86. #info aliases save;
  87. #local aliasTable {};
  88. #local index {};
  89. #loop {1} {&info[ALIASES][]} {index} {
  90. #local name {$info[ALIASES][+$index][arg1]};
  91. #local class {$info[ALIASES][+$index][class]};
  92. #if { "$class" == "" && "$pattern" != "all" } {
  93. #continue;
  94. };
  95. #if { "$class" == "" } {
  96. #local class {未分组};
  97. };
  98. #if { "$name" == "%*{[^a-zA-Z0-9-_.]}%*" } {
  99. #continue;
  100. };
  101. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  102. #continue;
  103. };
  104. #list {aliasTable[$class]} sort {$name};
  105. };
  106. #local format { %-35s %-40s %-10s};
  107. #echo {<128>$format} {class} {别名} {类型};
  108. #draw Yellow scroll line 1 1 1 90;
  109. #local classList {@slist.Sort{*aliasTable[]}};
  110. #local class {};
  111. #foreach {$classList} {class} {
  112. #local name {};
  113. #foreach {${aliasTable[$class][]}} {name} {
  114. #local type {<139>自定义<299>};
  115. #if { "$name" == "%*.{[A-Z][a-zA-Z0-9]+}" } {
  116. #local type {<129>开放API<299>};
  117. };
  118. #if { "$name" == "{[a-z]+}" } {
  119. #local type {<159>伪装的服务器命令<299>};
  120. };
  121. #if { "$class" == "module-loader" } {
  122. #if { "$name" == "{[A-Z]+}" } {
  123. #local type {<169>快捷方式<299>};
  124. };
  125. #else {
  126. #local type {<229>语法增强<299>};
  127. }
  128. };
  129. #if { "${class}.$name" == "main.class.%*" } {
  130. #local type {<229>语法增强<299>};
  131. };
  132. #if { "${class}.$name" == "main.load-{file|config}" } {
  133. #local type {<229>语法增强<299>};
  134. };
  135. #if { "${class}.$name" == "main.%*Log" } {
  136. #local type {<129>日志接口<299>};
  137. };
  138. #if { "$pattern" == "" && "$type" == "%*自定义%*" } {
  139. #continue;
  140. };
  141. #echo {<060>$format}
  142. {@genModuleLink{$class;MOD}<060>}
  143. {@mslp.Exec{{xtt.delTrigger alias $name};<119>✗<269>;false} @linkToHelp{$class;$name}}
  144. {$type};
  145. };
  146. };
  147. };
  148. ///=== {
  149. // ## xtt.ListVar [<正则表达式>]
  150. // 列出系统中符合条件的变量,如果省略条件则列出所有变量。
  151. // 一些不够规整的变量不会被列出。只有符合 PaoTin++ 规范的变量才会被列出。
  152. // 正则表达式会被运用到变量所属模块名称和变量名称上,两者符合其一即可被列出。
  153. // 你也可以通过 VARS 别名来使用本别名。
  154. // };
  155. #alias {VARS} {xtt.ListVar};
  156. #alias {xtt.ListVar} {
  157. #local pattern {%1};
  158. #info variable save;
  159. #local varTable {};
  160. #local index {};
  161. #loop {1} {&info[VARIABLES][]} {index} {
  162. #local name {$info[VARIABLES][+$index][arg1]};
  163. #local class {$info[VARIABLES][+$index][class]};
  164. #local value {$info[VARIABLES][+$index][arg2]};
  165. #local nest {$info[VARIABLES][+$index][nest]};
  166. #if { "$class" == "" && "$pattern" != "all" } {
  167. #continue;
  168. };
  169. #if { "$class" == "" } {
  170. #local class {未分组};
  171. };
  172. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  173. #continue;
  174. };
  175. #local {varTable[$class][$name]} {
  176. {nest}{$nest}
  177. {value}{$value}
  178. };
  179. };
  180. #local format { %-35s %-30s %-10s %s};
  181. #echo {<128>$format} {class} {变量} {类型} {值};
  182. #draw Yellow scroll line 1 1 1 95;
  183. #local classList {@slist.Sort{*varTable[]}};
  184. #local class {};
  185. #foreach {$classList} {class} {
  186. #local name {};
  187. #local nameList {@slist.Sort{*varTable[$class][]}};
  188. #foreach {$nameList} {name} {
  189. #local type {<229>字符串<299>};
  190. #local value {<169>$varTable[$class][$name][value]<299>};
  191. #local nest {$varTable[$class][$name][nest]};
  192. #if { $nest > 0 } {
  193. #local type {<259>表格<299>};
  194. #local value {@mslp.Var{$name;<139>[... 共 $nest 项数据]<299>}};
  195. };
  196. #local showClass {$class};
  197. #replace showClass {^data/} {};
  198. #echo {<060>$format}
  199. {@genModuleLink{$showClass;MOD}<060>}
  200. {@mslp.Exec{{xtt.delTrigger var $name};<119>✗<269>;false} @linkToHelp{$showClass;$name}}
  201. {$type}
  202. {$value};
  203. #if { "$gPaoTinVars[$name]" != "" } {
  204. #echo {$format}
  205. {}
  206. { ╰── $gPaoTinVars[$name][cnName]}
  207. {}
  208. {};
  209. };
  210. };
  211. };
  212. };
  213. #alias {xtt.delTrigger} {
  214. #local type {%1};
  215. #local trigger {%2};
  216. #local cmd {#un$type {$trigger}};
  217. #replace cmd {\\} {};
  218. $cmd;
  219. };
  220. ///=== {
  221. // ## xtt.ListFunc [<正则表达式>]
  222. // 列出系统中符合条件的函数,如果省略条件则列出所有函数。
  223. // 正则表达式会被运用到函数所属模块名称和函数名称上,两者符合其一即可被列出。
  224. // 一些不够规整的函数不会被列出。只有符合 PaoTin++ 规范的函数才会被列出。
  225. // 你也可以通过 FUNCS 别名来使用本别名。
  226. // };
  227. #alias {FUNCS} {xtt.ListFunc};
  228. #alias {xtt.ListFunc} {
  229. #local pattern {%1};
  230. #info functions save;
  231. #local funcsTable {};
  232. #local index {};
  233. #loop {1} {&info[FUNCTIONS][]} {index} {
  234. #local name {$info[FUNCTIONS][+$index][arg1]};
  235. #local class {$info[FUNCTIONS][+$index][class]};
  236. #if { "$class" == "" && "$pattern" != "all" } {
  237. #continue;
  238. };
  239. #if { "$class" == "" } {
  240. #local class {未分组};
  241. };
  242. #if { "$name" == "%*{[^a-zA-Z0-9_./-]}%*" } {
  243. #continue;
  244. };
  245. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  246. #continue;
  247. };
  248. #list {funcsTable[$class]} sort {$name};
  249. };
  250. #local format { %-35s %-40s %-10s};
  251. #echo {<128>$format} {class} {函数} {类型};
  252. #draw Yellow scroll line 1 1 1 90;
  253. #local classList {@slist.Sort{*funcsTable[]}};
  254. #local class {};
  255. #foreach {$classList} {class} {
  256. #local name {};
  257. #foreach {${funcsTable[$class][]}} {name} {
  258. #local type {<139>自定义<299>};
  259. #if { "$name" == "%*.{[A-Z][a-zA-Z0-9]+}" } {
  260. #local type {<129>开放API<299>};
  261. };
  262. #if { "$class" == "{lib/xtintin|main}" } {
  263. #local type {<229>语法增强<299>};
  264. };
  265. #if { "${class}.$name" == "main.%*Log" } {
  266. #local type {<129>日志接口<299>};
  267. };
  268. #if { "$pattern" == "" && "$type" == "%*自定义%*" } {
  269. #continue;
  270. };
  271. #echo {<060>$format}
  272. {@genModuleLink{$class;MOD}<060>}
  273. {@mslp.Exec{{xtt.delTrigger func $name};<119>✗<269>;false} @linkToHelp{$class;$name}}
  274. {$type};
  275. };
  276. };
  277. };
  278. ///=== {
  279. // ## xtt.ListAction [<正则表达式>]
  280. // 列出系统中符合条件的文本触发,如果省略条件则列出所有文本触发。
  281. // 正则表达式会被运用到文本触发所属模块名称和文本触发的条件上,两者符合其一即可被列出。
  282. // 你也可以通过 ACTS 别名来使用本别名。
  283. // };
  284. #alias {ACTS} {xtt.ListAction};
  285. #alias {xtt.ListAction} {
  286. #local pattern {%1};
  287. #info actions save;
  288. #local actionTable {};
  289. #local index {};
  290. #loop {1} {&info[ACTIONS][]} {index} {
  291. #local name {$info[ACTIONS][+$index][arg1]};
  292. #local class {$info[ACTIONS][+$index][class]};
  293. #local priority {$info[ACTIONS][+$index][arg3]};
  294. #if { "$class" == "" && "$pattern" != "all" } {
  295. #continue;
  296. };
  297. #if { "$class" == "" } {
  298. #local class {未分组};
  299. };
  300. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  301. #continue;
  302. };
  303. #list {actionTable[$class]} add {{{name}{$name}{priority}{$priority}}};
  304. };
  305. #local format { %-35s %-5s %-40s %-10s};
  306. #echo {<128>$format} {class} {优先级} {文本触发};
  307. #draw Yellow scroll line 1 1 1 90;
  308. #local classList {@slist.Sort{*actionTable[]}};
  309. #local class {};
  310. #foreach {$classList} {class} {
  311. #list {actionTable[$class]} indexate {name};
  312. #list {actionTable[$class]} sort;
  313. #local act {};
  314. #foreach {${actionTable[$class][]}} {act} {
  315. #local name {$act[name]};
  316. #local priority {$act[priority]};
  317. #echo {<060>$format}
  318. {@genModuleLink{$class;MOD}<060>}
  319. {$priority}
  320. {@mslp.Exec{{xtt.delTrigger action {$name}};<119>✗<269>;false} $name}
  321. };
  322. };
  323. };
  324. ///=== {
  325. // ## xtt.Var <变量中文含义> <变量名> <值>
  326. // 声明并初始化变量。和 #var 不同,如果该变量已存在,则不会修改它的值。
  327. // 另外,如果在模块中使用本方法,则声明的变量会自动存放在 #class data/\$MODULE 中。
  328. // 这意味着即使你重新载入模块代码,也不会破坏该变量的值。
  329. // 因此建议将通过触发抓取到的任务进度信息用本方法存储,可以有效避免机器代码迭代
  330. // 开发过程中,丢失任务信息从而导致任务失败。
  331. //
  332. // 也可以通过短名称 VAR 来使用本命令,效果相同。
  333. // };
  334. #alias {VAR} {xtt.Var};
  335. #alias {xtt.Var} {
  336. #local cnName {%1};
  337. #local name {%2};
  338. #local value {%3};
  339. #if { @existsVar{$name} } {
  340. #return;
  341. };
  342. #if { @existsVar{MODULE} } {
  343. #class data/$MODULE open;
  344. #var {$name} {$value};
  345. #class data/$MODULE close;
  346. };
  347. #else {
  348. #var {$name} {$value};
  349. };
  350. #var gPaoTinVars[$name] {
  351. {name} {$name}
  352. {cnName} {$cnName}
  353. };
  354. };
  355. VAR {用 VAR 关键字定义的 PaoTin++ 变量清单,包含其中文含义} gPaoTinVars {};
  356. load-lib option;
  357. option.Define {DisableOutput} {Bool} {是否禁止向服务器发送命令} {false};
  358. ///=== {
  359. // ## xtt.Send <命令> [<参数> ...]
  360. // 向服务器发送命令。如果命令拦截总开关被打开,则不会真的向服务器发送。
  361. // };
  362. #alias {xtt.Send} {
  363. #if { @option.IsEnable{DisableOutput} } {
  364. #echo {<169>命令已被抑制: <429>%p<299>} {%0};
  365. #return;
  366. };
  367. #send %0;
  368. };
  369. ///=== {
  370. // ## xtt.SendBatch <分号分隔的命令序列>
  371. // 一次性向服务器发送多条命令。
  372. // 有的 MUD 服务器专门为这种方式开辟了通道,本方法可以使用这种通道。
  373. // 如果服务器不支持,则退化为重复调用多次 xtt.Send。
  374. // TODO: 需要区分 MUD,需要支持定制的命令分隔符。
  375. // };
  376. #alias {xtt.SendBatch} {
  377. #local cmds {%1};
  378. #foreach {$cmds} {cmd} {
  379. xtt.Send {$cmd};
  380. };
  381. };
  382. ///=== {
  383. // ## xtt.Answer <问题答复>
  384. // 如果游戏中有需要回答的问题,并且给出了特定的提示符(就是不带换行的文本),
  385. // 那么由于 TinTin++ 的某种机制,导致回答的内容和问题就会有重叠,不能正确显示。
  386. // 此时建议用 xtt.Answer 来回答此类问题。将会留下美观的 buffer 记录。
  387. // };
  388. #alias {xtt.Answer} {
  389. #delay 0 {
  390. #echo {};
  391. #buffer end;
  392. xtt.Send {%1};
  393. };
  394. };
  395. ///=== {
  396. // ## xtt.Stop <命令>
  397. // 暂时阻断某个命令的执行。
  398. // 某些基于触发的机器会周而复始地执行动作。本命令可以用来终止它的运行,并保留状态。
  399. // 例如新手机器人会循环执行 ask job/do/finish 流程,那么只需要输入 xtt.Stop ask,
  400. // 就可以在下一次 ask NPC 时,暂停机器执行,但并不影响机器状态。此时玩家可以手动
  401. // 操作角色,临时去做点别的,比如收个包袱之类的,然后回到房间,手动执行一次 ask 命令,
  402. // 就可以继续机器运行了。
  403. // };
  404. #alias {xtt.Stop} {
  405. #if { "%1" == "" } {
  406. xtt.Usage xtt.Stop;
  407. #return;
  408. };
  409. #line oneshot #alias {%1} {halt; #echo {<119>任务已暂停,请输入 <139>%1 %s <119>继续运行。<299>} {%%0}}
  410. };
  411. option.Define {DisableAllCommands} {Bool} {是否禁用所有的触发器和定时器} {false};
  412. ///=== {
  413. // ## xtt.DisableAllCommands
  414. // 禁止发送任何命令。
  415. // 某些游戏模式下,玩家必须小心地输入,否则一旦输错会造成损失。此时可以用本
  416. // 命令来禁止所有的触发、定时器、事件,防止误发命令。
  417. // 此时玩家只能用 #send {.....} 命令来发送命令。
  418. // 注意快捷键并不会被禁止,所以玩家可以通过快捷键来切换状态。
  419. // };
  420. #alias {xtt.DisableAllCommands} {
  421. #local carefully {@default{%1;true}};
  422. #class disable-all-commands open;
  423. option.Enable DisableAllCommands;
  424. warnLog 所有定时器、触发器和事件句柄已被禁用。;
  425. warnLog 600 秒后自动解除该状态。;
  426. #if { @isTrue{$carefully} } {
  427. #alias {^%*{|ID=paotin/disable-all-commands}$} {
  428. #echo {<119>命令已被抑制,可用 <129>#send<119> 强制发送。撤销请用 <129>xtt.UndoDisableAllCommands<119> : <139>%s<299>} {%%0}
  429. } {1.002};
  430. };
  431. #else {
  432. #alias {^%*{|ID=paotin/disable-all-commands}$} {
  433. #echo {%s} {%%0};
  434. #send %%0;
  435. #line gag;
  436. } {1.002};
  437. };
  438. #gts {#delay 600 {#ats xtt.UndoDisableAllCommands}};
  439. #line quiet #ignore actions on;
  440. #line quiet #ignore tickers on;
  441. #line quiet #ignore events on;
  442. #class disable-all-commands close;
  443. };
  444. ///=== {
  445. // ## xtt.UndoDisableAllCommands
  446. // 取消 xtt.DisableAllCommands 效果,恢复正常状态。
  447. // 参见 HELP xtt.DisableAllCommands
  448. // };
  449. #alias {xtt.UndoDisableAllCommands} {
  450. #class disable-all-commands kill;
  451. #line quiet #ignore actions off;
  452. #line quiet #ignore tickers off;
  453. #line quiet #ignore events off;
  454. okLog 命令已恢复正常。;
  455. option.Disable DisableAllCommands;
  456. } {1.000};
  457. ///=== {
  458. // ## xtt.ToggleDisableCommands
  459. // 在禁止和打开所有的定时器、触发器和事件句柄之间来回切换。
  460. // 本命令可用作绑定快捷键使用。
  461. // };
  462. #alias {xtt.ToggleDisableCommands} {
  463. #if { @option.IsEnable{DisableAllCommands} } {
  464. xtt.UndoDisableAllCommands;
  465. };
  466. #else {
  467. xtt.DisableAllCommands;
  468. };
  469. } {1.000};
  470. ///=== {
  471. // ## xtt.MultiLineEdit
  472. // 进入多行编辑模式。
  473. // };
  474. #alias {xtt.MultiLineEdit} {
  475. xtt.DisableAllCommands false;
  476. #class multi-edit open;
  477. #alias {^x$} {
  478. #class multi-edit kill;
  479. #echo {%s} {%%0};
  480. #send x;
  481. #line gag;
  482. xtt.UndoDisableAllCommands;
  483. } {1.000};
  484. #alias {^c$} {
  485. #class multi-edit kill;
  486. #echo {%s} {%%0};
  487. #send c;
  488. #line gag;
  489. xtt.UndoDisableAllCommands;
  490. } {1.000};
  491. #class multi-edit close;
  492. };
  493. #action {^结束离开用 'x',取消输入用 'c'。$} {xtt.MultiLineEdit};
  494. #func {linkToHelp} {
  495. #local module {%1};
  496. #local keyword {%2};
  497. #local text {$keyword};
  498. #local cmd {HELP $keyword};
  499. #if { "$keyword" == "" } {
  500. #local text {$module};
  501. #local keyword {MODULE};
  502. #local cmd {HELP $module};
  503. };
  504. #if { "$module" == "" } {
  505. #return {$text};
  506. };
  507. #if { &xtt.module-doc[$module][] == 0 } {
  508. #return {$text};
  509. };
  510. #if { &xtt.module-doc[$module][$keyword][] == 0 } {
  511. #return {$text};
  512. };
  513. #return {<149>@mslp.Exec{{$cmd};{$text}}<299>};
  514. };
  515. ///=== {
  516. // ## cli.SmartToggle
  517. // 命令行智能切换。
  518. // 出于方便起见,该命令实际上集成了三个作用,并推荐使用快捷键来调用本命令。
  519. // - 作用1: 当命令行尚未输入内容时,用来切换 PaoTin++ 的调试开关。
  520. // 调试开关开启时,玩家可以看到触发的执行细节,方便调试代码。
  521. // - 作用2: 当命令行输入了 #alias/#action 等 TinTin++ 可被取消的触发时,会
  522. // 自动修改成对应的 #unalias/#unaction 命令,利用这一点可以方便取
  523. // 消已有触发。可被取消的触发列表见下方完整清单。
  524. // - 作用3: 当命令行输入了其它命令时,会自动开启或关闭以调试方式执行该命令。
  525. // 该切换并不会影响全局调试开关。因此不会受到来自其它触发的干扰,
  526. // 内容更精准,方便查看。
  527. //
  528. // 作用2中可被取消的命令清单:
  529. // - 常用 TinTin++ 命令: action alias tick variable delay gag
  530. // - 不常用 TinTin++ 命令: button event function highlight macro pathdir
  531. // prompt substitute tab
  532. // 以上命令的 3 字母以上简写,无论大小写,都会被自动添加或者删除 un,
  533. // 以达到切换的目的。
  534. // - 常用的 PaoTin++ 命令: event.Handle/event.HandleOnce VS event.UnHandle
  535. // };
  536. #alias {cli.SmartToggle} {
  537. #local input {};
  538. #cursor get input;
  539. #line quiet #ignore function on;
  540. #if { {$input} == {} } {
  541. #line quiet #ignore function off;
  542. xtt.ToggleDebug;
  543. #return;
  544. };
  545. #if { {$input} == {#line debug %*} } {
  546. #replace input {^#line debug } {};
  547. };
  548. #else {
  549. #local cmds {act(|i(|o(|n)))|ali(|a(|s))|tic(|k(|e(|r)))
  550. |var(|i(|a(|b(|l(|e)))))
  551. |del(|a(|y))|gag|tab
  552. |but(|t(|o(|n)))|eve(|n(|t))
  553. |fun(|c(|t(|i(|o(|n)))))
  554. |hig(|h(|l(|i(|g(|h(|t))))))
  555. |mac(|r(|o))|pat(|h(|d(|i(|r))))
  556. |pro(|m(|p(|t)))
  557. |sub(|s(|t(|i(|t(|u(|t(|e)))))))};
  558. #replace cmds { } {};
  559. #if { {$input} == {{?i}#un{$cmds} %*} } {
  560. #replace input {{?i}#un} {#};
  561. };
  562. #elseif { {$input} == {{?i}#{$cmds} %*} } {
  563. #replace input {^#} {#un};
  564. };
  565. #elseif { {$input} == {{tt|}event.{Class|}Handle{|Once} %*} } {
  566. #replace input {^{tt|}event.{Class|}Handle{Once|}} {&1event.UnHandle};
  567. };
  568. #elseif { {$input} == {{tt|}event.UnHandle %*} } {
  569. #replace input {^{tt|}event.UnHandle} {&1event.Handle};
  570. };
  571. #else {
  572. #local input {#line debug $input};
  573. };
  574. };
  575. #cursor clear;
  576. #local cmd {
  577. #line quiet #ignore variable on;
  578. #line quiet #line sub escapes #cursor set {$input};
  579. #line quiet #ignore variable off;
  580. };
  581. $cmd;
  582. #line quiet #ignore function off;
  583. };
  584. ///=== {
  585. // ## xtt.Ping [<次数>]
  586. // 计算服务器延迟,输出以毫秒为单位的统计数据;
  587. // };
  588. #alias {PING} {xtt.Ping};
  589. #alias {xtt.Ping} {
  590. #class xtt.Ping open;
  591. #list xtt-ping-samples create {};
  592. #var xtt-ping-send-time {};
  593. #var xtt-ping-times {10};
  594. #alias {xtt.Ping.ping} {
  595. #if { $xtt-ping-times <= 0 } {
  596. xtt.Ping.done;
  597. #return;
  598. };
  599. #var xtt-ping-send-time {@str.Format{%U}};
  600. sync.Wait xtt.Ping.pong;
  601. };
  602. #alias {xtt.Ping.pong} {
  603. #math xtt-ping-times {$xtt-ping-times - 1};
  604. #list xtt-ping-samples add {@math.Eval{ @str.Format{%U} - $xtt-ping-send-time }};
  605. xtt.Ping.ping;
  606. };
  607. #alias {xtt.Ping.done} {
  608. #list xtt-ping-samples order;
  609. #list xtt-ping-samples delete -1;
  610. #list xtt-ping-samples delete 1;
  611. #local min {@math.Eval{ $xtt-ping-samples[1] / 1000 }};
  612. #local max {@math.Eval{ $xtt-ping-samples[-1] / 1000 }};
  613. #local avg {@math.Eval{ @math.Sum{$xtt-ping-samples[]} / &xtt-ping-samples[] / 1000 }};
  614. #class xtt.Ping kill;
  615. okLog 网络测速结果如右:最大值 $max 毫秒,最小值 $min 毫秒,平均值 $avg 毫秒;
  616. };
  617. #class xtt.Ping close;
  618. sync.Wait {xtt.Ping.ping};
  619. };