cmds.tin 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. // ## xtt.Tick <ID> <代码> <间隔时间>
  12. // 跟 #tick 功能类似,但是会立即执行一次代码。对于间隔时间比较长的定时器来说尤其有用。
  13. // 你也可以通过 Tick 别名来使用本别名。
  14. // };
  15. #alias {Tick} {xtt.Tick};
  16. #alias {xtt.Tick} {
  17. #local id {%1};
  18. #local code {%2};
  19. #local interval {%3};
  20. #line sub var #untick {$id};
  21. #line sub var #tick {$id} {$code} $interval;
  22. $code;
  23. };
  24. ///=== {
  25. // ## xtt.ListTicker
  26. // 列出系统中所有的定时器。因为定时器一般不会很多因此暂时没有做过滤功能。
  27. // 你也可以通过 TICKS 别名来使用本别名。
  28. // };
  29. #alias {TICKS} {xtt.ListTicker};
  30. #alias {xtt.ListTicker} {
  31. #info tickers save;
  32. #echo {<128> %-30s %+20s %+10s %+20s} {所属模块} {定时器名称} {执行周期} {距离下次执行(s)};
  33. #draw Yellow scroll line 1 1 1 90;
  34. #format utime %U;
  35. #local index {};
  36. #loop {1} {&info[TICKERS][]} {index} {
  37. #local uval {};
  38. #math uval $info[TICKERS][+$index][arg3] * 1000000;
  39. #echo { %-30s %+20s %+10s %+20m}
  40. {@genModuleLink{$info[TICKERS][+$index][class];MOD}}
  41. {$info[TICKERS][+$index][arg1]}
  42. {$info[TICKERS][+$index][arg3]}
  43. {($uval - ($utime - $info[TICKERS][+$index][arg4]) % $uval) / 1000000.00};
  44. };
  45. };
  46. ///=== {
  47. // ## xtt.ListAlias [<正则表达式>]
  48. // 列出系统中符合条件的别名,如果省略条件则列出所有别名。
  49. // 一些不够规整的别名不会被列出。只有符合 PaoTin++ 规范的别名才会被列出。
  50. // 正则表达式会被运用到别名所属模块名称和别名名称上,两者符合其一即可被列出。
  51. // 你也可以通过 ALIASES 别名来使用本别名。
  52. // };
  53. #alias {ALIASES} {xtt.ListAlias};
  54. #alias {xtt.ListAlias} {
  55. #local pattern {%1};
  56. #info aliases save;
  57. #local aliasTable {};
  58. #local index {};
  59. #loop {1} {&info[ALIASES][]} {index} {
  60. #local name {$info[ALIASES][+$index][arg1]};
  61. #local class {$info[ALIASES][+$index][class]};
  62. #if { "$class" == "" && "$pattern" != "all" } {
  63. #continue;
  64. };
  65. #if { "$class" == "" } {
  66. #local class {未分组};
  67. };
  68. #if { "$name" == "%*{[^a-zA-Z0-9-_.]}%*" } {
  69. #continue;
  70. };
  71. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  72. #continue;
  73. };
  74. #list {aliasTable[$class]} sort {$name};
  75. };
  76. #local format { %-30s %-30s %-10s};
  77. #echo {<128>$format} {class} {别名} {类型};
  78. #draw Yellow scroll line 1 1 1 80;
  79. #local classList {@list.Sort{*aliasTable[]}};
  80. #local class {};
  81. #foreach {$classList} {class} {
  82. #local name {};
  83. #foreach {${aliasTable[$class][]}} {name} {
  84. #local type {<130>自定义<070>};
  85. #if { "$name" == "%*.{[A-Z][a-zA-Z0-9]+}" } {
  86. #local type {<120>开放API<070>};
  87. };
  88. #if { "$class" == "module-loader" } {
  89. #if { "$name" == "{[A-Z]+}" } {
  90. #local type {<160>快捷方式<070>};
  91. };
  92. #else {
  93. #local type {<020>语法增强<070>};
  94. }
  95. };
  96. #if { "${class}.$name" == "main.class.%*" } {
  97. #local type {<020>语法增强<070>};
  98. };
  99. #if { "${class}.$name" == "main.load-file" } {
  100. #local type {<020>语法增强<070>};
  101. };
  102. #if { "${class}.$name" == "main.%*Log" } {
  103. #local type {<120>日志接口<070>};
  104. };
  105. #if { "$pattern" == "" && "$type" == "%*自定义%*" } {
  106. #continue;
  107. };
  108. #echo {<060>$format}
  109. {@genModuleLink{$class;MOD}<060>}
  110. {@linkToHelp{$class;$name}}
  111. {$type};
  112. };
  113. };
  114. };
  115. ///=== {
  116. // ## xtt.ListVar [<正则表达式>]
  117. // 列出系统中符合条件的变量,如果省略条件则列出所有变量。
  118. // 一些不够规整的变量不会被列出。只有符合 PaoTin++ 规范的变量才会被列出。
  119. // 正则表达式会被运用到变量所属模块名称和变量名称上,两者符合其一即可被列出。
  120. // 你也可以通过 VARS 别名来使用本别名。
  121. // };
  122. #alias {VARS} {xtt.ListVar};
  123. #alias {xtt.ListVar} {
  124. #local pattern {%1};
  125. #info variable save;
  126. #local varTable {};
  127. #local index {};
  128. #loop {1} {&info[VARIABLES][]} {index} {
  129. #local name {$info[VARIABLES][+$index][arg1]};
  130. #local class {$info[VARIABLES][+$index][class]};
  131. #local value {$info[VARIABLES][+$index][arg2]};
  132. #local nest {$info[VARIABLES][+$index][nest]};
  133. #if { "$class" == "" && "$pattern" != "all" } {
  134. #continue;
  135. };
  136. #if { "$class" == "" } {
  137. #local class {未分组};
  138. };
  139. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  140. #continue;
  141. };
  142. #local {varTable[$class][$name]} {
  143. {nest}{$nest}
  144. {value}{$value}
  145. };
  146. };
  147. #local format { %-30s %-30s %-10s %s};
  148. #echo {<128>$format} {class} {变量} {类型} {值};
  149. #draw Yellow scroll line 1 1 1 80;
  150. #local classList {@slist.Sort{*varTable[]}};
  151. #local class {};
  152. #foreach {$classList} {class} {
  153. #local name {};
  154. #local nameList {@slist.Sort{*varTable[$class][]}};
  155. #foreach {$nameList} {name} {
  156. #local type {<020>字符串<070>};
  157. #local value {<160>$varTable[$class][$name][value]<070>};
  158. #local nest {$varTable[$class][$name][nest]};
  159. #if { $nest > 0 } {
  160. #local type {<050>表格<070>};
  161. #local value {@mslp.Var{$name;<130>[... 共 $nest 项数据]<070>}};
  162. };
  163. #echo {<060>$format}
  164. {@genModuleLink{$class;MOD}<060>}
  165. {@linkToHelp{$class;$name}}
  166. {$type}
  167. {$value};
  168. };
  169. };
  170. };
  171. ///=== {
  172. // ## xtt.ListFunc [<正则表达式>]
  173. // 列出系统中符合条件的函数,如果省略条件则列出所有函数。
  174. // 正则表达式会被运用到函数所属模块名称和函数名称上,两者符合其一即可被列出。
  175. // 一些不够规整的函数不会被列出。只有符合 PaoTin++ 规范的函数才会被列出。
  176. // 你也可以通过 FUNCS 别名来使用本别名。
  177. // };
  178. #alias {FUNCS} {xtt.ListFunc};
  179. #alias {xtt.ListFunc} {
  180. #local pattern {%1};
  181. #info functions save;
  182. #local funcsTable {};
  183. #local index {};
  184. #loop {1} {&info[FUNCTIONS][]} {index} {
  185. #local name {$info[FUNCTIONS][+$index][arg1]};
  186. #local class {$info[FUNCTIONS][+$index][class]};
  187. #if { "$class" == "" && "$pattern" != "all" } {
  188. #continue;
  189. };
  190. #if { "$class" == "" } {
  191. #local class {未分组};
  192. };
  193. #if { "$name" == "%*{[^a-zA-Z0-9_./-]}%*" } {
  194. #continue;
  195. };
  196. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  197. #continue;
  198. };
  199. #list {funcsTable[$class]} sort {$name};
  200. };
  201. #local format { %-30s %-30s %-10s};
  202. #echo {<128>$format} {class} {函数} {类型};
  203. #draw Yellow scroll line 1 1 1 80;
  204. #local classList {@list.Sort{*funcsTable[]}};
  205. #local class {};
  206. #foreach {$classList} {class} {
  207. #local name {};
  208. #foreach {${funcsTable[$class][]}} {name} {
  209. #local type {<130>自定义<070>};
  210. #if { "$name" == "%*.{[A-Z][a-zA-Z0-9]+}" } {
  211. #local type {<120>开放API<070>};
  212. };
  213. #if { "$class" == "{lib/xtintin|main}" } {
  214. #local type {<020>语法增强<070>};
  215. };
  216. #if { "${class}.$name" == "main.%*Log" } {
  217. #local type {<120>日志接口<070>};
  218. };
  219. #if { "$pattern" == "" && "$type" == "%*自定义%*" } {
  220. #continue;
  221. };
  222. #echo {<060>$format}
  223. {@genModuleLink{$class;MOD}<060>}
  224. {@linkToHelp{$class;$name}}
  225. {$type};
  226. };
  227. };
  228. };
  229. ///=== {
  230. // ## xtt.Send <命令> [<参数> ...]
  231. // 向服务器发送命令。如果命令拦截总开关被打开,则不会真的向服务器发送。
  232. // };
  233. #alias {xtt.Send} {
  234. #if { "$xttOptions[DisableOutput]" == "true" } {
  235. #echo {<160>命令已被抑制: <420>%p<070>} {%0};
  236. #return;
  237. };
  238. #send %0;
  239. };
  240. ///=== {
  241. // ## xtt.SendAtOnce <分号分隔的命令序列>
  242. // 一次性向服务器发送多条命令。
  243. // 有的 MUD 服务器专门为这种方式开辟了通道,本方法可以使用这种通道。
  244. // TODO: 需要区分 MUD,需要支持定制的命令分隔符。
  245. // };
  246. #alias {xtt.SendAtOnce} {
  247. #local cmds {%1};
  248. #send {#$cmds#};
  249. };
  250. ///=== {
  251. // ## xtt.Answer <问题答复>
  252. // 如果游戏中有需要回答的问题,并且给出了特定的提示符(就是不带换行的文本),
  253. // 那么由于 TinTin++ 的某种机制,导致回答的内容和问题就会有重叠,不能正确显示。
  254. // 此时建议用 xtt.Answer 来回答此类问题。将会留下美观的 buffer 记录。
  255. // };
  256. #alias {xtt.Answer} {
  257. #delay 0 {
  258. #echo {};
  259. #buffer end;
  260. #send {%1};
  261. };
  262. };
  263. #func {linkToHelp} {
  264. #local module {%1};
  265. #local keyword {%2};
  266. #local text {$keyword};
  267. #local cmd {HELP $keyword};
  268. #if { "$keyword" == "" } {
  269. #local text {$module};
  270. #local keyword {MODULE};
  271. #local cmd {HELP $module};
  272. };
  273. #if { "$module" == "" } {
  274. #return {$text};
  275. };
  276. #if { &xtt.module-doc[$module][] == 0 } {
  277. #return {$text};
  278. };
  279. #if { &xtt.module-doc[$module][$keyword][] == 0 } {
  280. #return {$text};
  281. };
  282. #return {<140>@mslp.Exec{{$cmd};{$text}}<270>};
  283. };