Skip to content

Commit

Permalink
feat(pkuxkx): ask 机器人
Browse files Browse the repository at this point in the history
  • Loading branch information
dzpao committed Dec 12, 2023
1 parent 1ff67b0 commit 6073198
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions mud/pkuxkx/plugins/basic/cmds/ask.tin
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#nop vim: set filetype=tt:;

/*
本文件属于 PaoTin++ 的一部分
===========
PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <[email protected]>) 享有并保留一切法律权利
你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
===========
*/

load-lib event;

#var basic_cmds_ask[META] {
{NAME} {ask 队列管理}
{DESC} {北侠要求,ask 必须间隔一定的时间,这对玩家编写脚本带来了困难。}
{AUTHOR} {担子炮}
{NOTE} {}
{CONFIG} {}
};

VAR {ask 最小间隔时间} {ask.CD} {2};
VAR {ask 队列,所有的 ask 命令都通过这个队列来排队询问} ask.askQueue {};

#alias {^ask %* about %*$} {
#local who {%1};
#local what {%2};

ask.About {%1} {%2};
};

#alias {ask.About} {
#local who {%1};
#local what {%2};

queue.Push ask.askQueue {
{who} {$who}
{what} {$what}
};

ask.loop;
};

VAR {ask 循环是否正在工作} ask.loop.working {false};
VAR {上次 ask 的时间} ask.lastTime {0};

#alias {ask.loop} {
#if { @isTrue{$ask.loop.working} } {
#return;
};

#if { @queue.Size{ask.askQueue} == 0 } {
#var ask.loop.working {false};
#return;
};

#var ask.loop.working {true};

#alias {ask.loop.do} {
#local req {@queue.First{ask.askQueue}};

#local ID {|ID=ask/loop};

#class ask.loop.do open;

#line sub var #action {^你说话太快,对方听不懂,慢点说吧。{$ID}$} {
#class ask.loop.do kill;
#alias {ask.loop.done} {#0};
#undelay ask.loop.retry;
#delay ask.loop.retry {ask.loop.do} {@math.Eval{$ask.CD * 2}};
};

#alias {ask.loop.done} {
#class ask.loop.do kill;
queue.Shift ask.askQueue;
#undelay ask.loop.retry;
#var ask.loop.working {false};
#delay ask.loop.next {ask.loop} $ask.CD;
};

#class ask.loop.do close;

#var ask.lastTime {@time.Now{}};
xtt.Send ask $req[who] about $req[what];
sync.Wait {ask.loop.done};
#delay ask.loop.retry {ask.loop.do} {@math.Eval{$ask.CD * 4}};
};

#local delay {@math.Min{0; @math.Eval{$ask.lastTime + $ask.CD - @time.Now{}}}};
#delay ask.loop.next {sync.Wait ask.loop.do} $delay;
};

0 comments on commit 6073198

Please sign in to comment.