0

我想向我的机器人添加一个命令,该命令将接受用户定义的触发器时间。触发器的默认值为 60 秒。但我希望用户能够通过命令手动设置它。

例子:

[昵称] @cmd 5s

[bot] 命令在 5 秒内启动

或者

[昵称] @cmd 2m

[bot] 命令在 2 分钟内启动

proc weed:pack {nick uhost hand chan text} {
if {[utimerexists delay] == ""} {
    putserv "PRIVMSG $chan \00303Pack your \00309bowls\00303! Chan-wide \00304Toke\00311-\00304out\00303 in\00308 1 \00303Minute!\003"
    global wchan
    set wchan $chan
    utimer 60 weed:pack:go
    utimer 60 delay
    }
}

proc weed:pack:go {} {
global wchan
putserv "PRIVMSG $wchan :\00303::\003045\00303:";
putserv "PRIVMSG $wchan :\00303::\003044\00303:";
putserv "PRIVMSG $wchan :\00303::\003043\00303:";
putserv "PRIVMSG $wchan :\00303::\003042\00303:";
putserv "PRIVMSG $wchan :\00303::\003041\00303:";
putserv "PRIVMSG $wchan :\00303::\00311\002SYNCRONIZED!\002 \00304FIRE THEM BOWLS UP!!!"; return
}
4

1 回答 1

0

嗯,主要是关于理解utimer。该命令有两个参数,一个等待秒数的计数,以及一个在计时器触发时执行的命令(包括相关参数)。

您需要做的就是弄清楚如何解析用户提供的时间。我们可以使用scan它。

scan $text "%d%1s" count type

最好检查一下结果,看看你是否成功;成功时,将返回 2(用于两个字段)。现在你已经把东西分开了,你必须把它转换成秒数:

if {[scan $text "%d%1s" count type] != 2} {
    # Do an error message; don't just silently fail! Don't know eggdrop enough to do that properly
    return
}
switch -- $type {
    "s" { set delay $count }
    "m" { set delay [expr {$count * 60}] }
    "h" { set delay [expr {$count * 60 * 60}] }
    default {
        # Again, you ought to send a complaining message to the user here
        return
    }
}
utimer $delay weed:pack:go

将所有内容与您需要的任何其他部分一起粘贴在您的内部proc,您应该一切顺利。如果您有多个需要解析的地方,您甚至可以将该代码转换为它自己的过程;这就是我真正想要的,因为“解析持续时间描述”是这类事情的一个很好的候选者。

于 2016-07-02T15:22:17.067 回答