mirc

How to make script increment value every 1.5 seconds when triggered


I have been working on adding a 1.5 second delay to the "inc %x_note_id" portion but instead of it just doing it with one message at a time until the last one, it delays and then sends them all at once. How do I make it where it delays each increment of %x_note_id in this porton of the script?

the full code is 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 ] ]
   }
  }
 }
}

Solution

  • Fixing your existing code, will require more work and will force me to work under your code restrictions.

    I've decided to construct new message queuing, which will be more explicit and detailed. Which will result in easier time when you will need to extend it.

    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 $2-
      msg # $nick $+ , Your message has been left for $2 $+ .
    }
    
    ON !*:JOIN:#: playmessages $server # $nick
    ON *:TEXT:*:#: playmessages $server # $nick
    
    alias -l findServerConnectionIdx {
      if (!$1) return
    
      var %i = 1, %length = $scon(0)
      while (%i <= %length) {
        var %server = $scon(%i).server
        if (%server == $1) {
          return %i
        }
        inc %i
      }
      return
    }
    
    alias -l userMessages {
      ; $1 = server, $2 = channel, $3 = nick
      if (!$3) return
    
      if ($prop == sent) {
        var %i = 1, %length = $var($+(notemsg.,$1,.,$2,.*), 0)
        var %numOfSentMsgs = 0
        while (%i <= %length) {
          var %messages = $var($+(notemsg.,$1,.,$2,.*), %i).value
          inc %numOfSentMsgs $wildtok(%messages, $3 *, 0, 9)
    
          inc %i
        }
        return %numOfSentMsgs
      }
      else if ($prop == recv) {
        var %messages = $var($+(notemsg.,$1,.,$2,.,$3), 1).value
        return $numtok(%messages, 9)
      }
    }
    
    alias -l saveMessage {
      ; $1 = server, $2 = channel, $3 = dest-nick, $4 = src-nick, $5- = message
      if (!$5) return
    
      set % [ $+ [ $+(notemsg.,$1,.,$2,.,$3) ] ] $addtok(% [ $+ [ $+(notemsg.,$1,.,$2,.,$3) ] ], $4-, 9)
    }
    
    alias -l clearRecvMessages {
      ; $1 = server, $2 = channel, $3 = nick
      if (!$3) return
    
      unset % [ $+ [ $+(notemsg., $1,.,$2,.,$3) ] ]
    }
    
    alias -l playMessages {
      ; $1 = server, $2 = channel, $3 = nick, $4 = delay
      if (!$3) return
    
      var %messages = % [ $+ [ $+(notemsg., $1,.,$2,.,$3) ] ]
      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($1)
        $+(.timernotes.,notemsg.,$1,.,$2,.,$3,.,%i) 1 $calc((%i - 1) * 1.5) scid -t1 %sconServer msg $2 From: %sourceNick Message: %message
        inc %i
      }
      clearRecvMessages $1-3
    }