cmds.tin 23 KB

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