触发时如何使脚本每 1.5 秒递增一次值

How to make script increment value every 1.5 seconds when triggered

我一直在努力为 "inc %x_note_id" 部分添加 1.5 秒的延迟,但它不是一次只处理一条消息直到最后一条消息,而是延迟然后一次发送所有消息.我如何让它在脚本的这个部分延迟 %x_note_id 的每个增量?

完整代码是here

alias postmessage {
if ( $nick == $me ) { return }

 var %x_note_id 1
while ( %noteidnick. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] > 0 ) {

msg $chan %notemsg. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] [ $+ [ . ] ] [ $+ [ %x_note_id ] ]
unset %notenick. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] [ $+ [ . ] ] [ $+ [ %x_note_id ] ]
unset %notemsg. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ] [ $+ [ . ] ] [ $+ [ %x_note_id ] ]
var %note_delay 10000
while ( %note_delay ) {
  dec %note_delay
  if ( %note_delay == 0 ) {

    inc %x_note_id
    dec %noteidnick. [ $+ [ $server ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] [ $+ [ . ] ] [ $+ [ $nick ] ]
   }
  }
 }
}

修复您现有的代码,需要更多的工作,并且会迫使我在您的代码限制下工作。

我决定构建新的消息队列,它将更加明确和详细。这将使您在需要扩展它时更容易。

ON $*:TEXT:/^!note\s\w+\s/iS:#: {

  if ($nick isin %twitchbots) return

  ; Bot command flood protection, 3 messages per 10 seconds.
  inc -u10 % [ $+ [ $+(bpf.,$server,.,#,.,$wildsite) ]
  var %bpf = % [ $+ [ $+(bpf.,$server,.,#,.,$wildsite) ]
  if (%bpf >= 4) return

  ; Verify the sender doesn't reach his max quota
  if ($userMessages($server, #, $nick).sent == 5) {
    msg # $nick $+ , Limit reached. Only 5 messages per user is allowed.
    return
  }

  saveMessage $server # $nick -
  msg # $nick $+ , Your message has been left for  $+ .
}

ON !*:JOIN:#: playmessages $server # $nick
ON *:TEXT:*:#: playmessages $server # $nick

alias -l findServerConnectionIdx {
  if (!) return

  var %i = 1, %length = $scon(0)
  while (%i <= %length) {
    var %server = $scon(%i).server
    if (%server == ) {
      return %i
    }
    inc %i
  }
  return
}

alias -l userMessages {
  ;  = server,  = channel,  = nick
  if (!) return

  if ($prop == sent) {
    var %i = 1, %length = $var($+(notemsg.,,.,,.*), 0)
    var %numOfSentMsgs = 0
    while (%i <= %length) {
      var %messages = $var($+(notemsg.,,.,,.*), %i).value
      inc %numOfSentMsgs $wildtok(%messages,  *, 0, 9)

      inc %i
    }
    return %numOfSentMsgs
  }
  else if ($prop == recv) {
    var %messages = $var($+(notemsg.,,.,,.,), 1).value
    return $numtok(%messages, 9)
  }
}

alias -l saveMessage {
  ;  = server,  = channel,  = dest-nick,  = src-nick, - = message
  if (!) return

  set % [ $+ [ $+(notemsg.,,.,,.,) ] ] $addtok(% [ $+ [ $+(notemsg.,,.,,.,) ] ], -, 9)
}

alias -l clearRecvMessages {
  ;  = server,  = channel,  = nick
  if (!) return

  unset % [ $+ [ $+(notemsg., ,.,,.,) ] ]
}

alias -l playMessages {
  ;  = server,  = channel,  = nick,  = delay
  if (!) return

  var %messages = % [ $+ [ $+(notemsg., ,.,,.,) ] ]
  var %i = 1, %length = $numtok(%messages, 9)
  while (%i <= %length) {
    var %fullMessage = $gettok(%messages, %i, 9)
    var %sourceNick = $gettok(%fullMessage, 1, 32)
    var %message = $gettok(%fullMessage, 2-, 32)

    var %sconServer = $findServerConnectionIdx()
    $+(.timernotes.,notemsg.,,.,,.,,.,%i) 1 $calc((%i - 1) * 1.5) scid -t1 %sconServer msg  From: %sourceNick Message: %message
    inc %i
  }
  clearRecvMessages -3
}