0

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 ] ]
   }
  }
 }
}
  • Can you tell us what you expect the postmessage alias to preform in detail ? because the current algorithm is not the best way to go. – Orel Eraki Jul 13 '17 at 21:47
  • What I expect the script to do is to have it like this: The corresponding user either joins the channel or speaks then the bot posts the first message found for that user and 1.5 seconds after that it then sends the next one found for that user and so on. – Technodevster Jul 19 '17 at 11:49
  • If i understand it correctly, you want some kind of queuing system ? And if it's correct, you want it to dequeue messages every 1.5 seconds, per user, or for the entire users. UserX and UserY are talking at the same time, should it post every 1.5 1 message or 2 messages ? – Orel Eraki Jul 19 '17 at 15:35
  • Yes and I want it to be per user and a 1.5 second dequeue rate. If 2 or more users join or type at the same time the first result found for both users that spoke or joined gets posted immediately afterwards and then 1.5 seconds after those messages it sends their next result if there are any. – Technodevster Jul 20 '17 at 06:51
  • Can i know the incentive of repeating the user message in the same channel he wrote ? (bot publishing the same message as the user wrote on the same channel) – Orel Eraki Jul 20 '17 at 07:25
  • It's a note leaving script that queues notes for users who join the channel or speak in it if they are already in it. The syntax is !note username message and when they trigger the postmessage alias in the code it returns each message left for them. The idea is to have every message be sent at a 1.5 second rate to avoid flood filters on some servers. – Technodevster Jul 20 '17 at 08:48
  • Is setting `!note username message` to user that is already on channel is allowed ? A bot can work and queue messages to each channel separately? – Orel Eraki Jul 20 '17 at 09:10
  • Yes. I have it like that because on servers like the Twitch IRC server the user/viewers list doesn't get updated immediately. – Technodevster Jul 21 '17 at 00:48
  • Still need help with this problem ? – Orel Eraki Sep 09 '17 at 08:59
  • Yes. I still can't seem to figure it out. – Technodevster Sep 17 '17 at 10:14
  • I've answer you few days ago.. Did it helped ? – Orel Eraki Oct 02 '17 at 19:16
  • Yeah that's what I needed help on. Thanks. – Technodevster Oct 12 '17 at 04:06

1 Answers1

0

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
}
Orel Eraki
  • 11,940
  • 3
  • 28
  • 36