mIRC Home    About    Download    Register    News    Help

Print Thread
T
TUSK3N
TUSK3N
T
Hello I need help with some code,

I would like my script to only send a message per 2 seconds no matter what script has been executed.

I am using this on twitch so if the script/bot says 2 messages at the same time it wont show up so I would like to have a queue system where the text messages queue up and sends per 2 seconds instead of sending at the same time.

if someone does !command it shows up the response
but if you say it again in 2 seconds it will queue and wait 2 seconds and say the message.

Its hard to explain, need help! smile

Joined: Dec 2015
Posts: 147
D
Vogon poet
Offline
Vogon poet
D
Joined: Dec 2015
Posts: 147
Code:
on *:connect:clear @mywindow | unset %staph*

on *:text:!mycommand:#: {
  if (!%staph) {
    set -eu18 %staph 1
    if (!$window(@mywindow)) window -h @mywindow
    aline @mywindow .msg # Hello world! This a random message #1
    aline @mywindow .msg # Hello world! This a random message #2
    aline @mywindow .msg # Hello world! This a random message #3
    aline @mywindow .msg # Hello world! This a random message #4
    aline @mywindow .msg # Hello world! This a random message #5
    aline @mywindow .msg # Hello world! This a random message #6
    aline @mywindow .msg # Hello world! This a random message #7
    aline @mywindow .msg # Hello world! This a random message #8
    aline @mywindow .msg # Hello world! This a random message #9
    if (!$timer(mytimer)) sendmymessage
  }
}

on *:text:!mycommand2:#: {
  if (!%staph2) {
    set -eu8 %staph2 1
    if (!$window(@mywindow)) window -h @mywindow
    aline @mywindow .msg # Ohai #1
    aline @mywindow .msg # Ohai #2
    aline @mywindow .msg # Ohai #3
    aline @mywindow .msg # Ohai #4
    if (!$timer(mytimer)) sendmymessage
  }
}

alias -l sendmymessage {
  if ($line(@mywindow,1)) {
    dline @mywindow 1
    $v1
    if ($line(@mywindow,1)) .timermytimer 1 2 sendmymessage
  }
}



EDIT:
Just to explain a bit more: you just add lines to the "@mywindow" window, then use the "sendmymessage" command and it'll spam all the lines from the window one by one with a two second delay.

"%staph" is currently preventing people from spamming the command, so it won't repeat the same lines over and over again if you spam it while it's already spamming the lines.

You can add lines to the window from anywhere at any time and it'll just spam them one by one in the order they were entered.


EDIT #2:
You can also create the "@mywindow" window on start/connect so that you don't need to if it exists on every command.

Last edited by Dazuz; 14/03/16 04:09 PM.
Joined: Apr 2010
Posts: 964
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 964
Code:
;; Use the following command to throttle their
;; counterparts. More can be added using the same
;; format.
alias tmsg      throttle msg $1-
alias tdescribe throttle describe $1-
alias tnotice   throttle notice $1-

;; Workhorse; handles queueing and execution
;; throttled commanded
alias -l throttle {

  ;; Throttle id - used for connection-specified
  ;; window and timer names
  var %TID = $+(@Throttle, $cid)
  
  ;; If not connected close the throttle buffer
  ;; window
  if ($status !== connected) {
    close -@ %TID
  }
  
  ;; If the input is not meant as a throttle
  ;; execution iteration
  elseif ($1- !== -r) {
  
    ;; if the throttle buffer window is not open,
    ;; create it as a hidden & minimized list
    ;; window
    if (!$window(%TID)) {
      window -lnh0 %TID
    }
    
    ;; If the throttle-read timer is running,
    ;; simply add the input command to the
    ;; throttle buffer
    if ($timer(%TID)) {
      aline %TID $-
    }
    
    ;; Otherwise, its been longer than 2 seconds
    ;; since a command has executed so execute
    ;; the input command and start the timer to
    ;; read the throttle buffer in 2 seconds
    else {
      $1-
      $+(.timer,%TID) 1 2 throttle -r
    }
  }
  
  ;; if the input is meant as a throttle read and
  ;; there is a throttled command to be executed,
  ;; execute the command, remove it from the
  ;; throttle buffer and start a timer to read
  ;; from the buffer again in 2 seconds
  elseif ($line(%TID, 1)) {
    $v1
    dline %TID 1
    $+(.timer, %TID) 1 2 throttle -r
  }
}

Last edited by FroggieDaFrog; 14/03/16 06:19 PM.

Link Copied to Clipboard