cmds.tin 24 KB

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