mIRC Home    About    Download    Register    News    Help

Print Thread
#263527 15/08/18 01:52 AM
Joined: Jul 2016
Posts: 10
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Jul 2016
Posts: 10
To sum it up, i have the following Code in a channel:

on *:LOGON:*:{
raw CAP REQ :twitch.tv/membership
raw CAP REQ :twitch.tv/tags
raw CAP REQ :twitch.tv/commands
/debug @raw
}

raw USERNOTICE:*:{
if (($msgtags(msg-id).key == subgift) && ($1 == #couragejd)) {
var %nick_from $iif($msgtags(display-name).key, $v1, $msgtags(login).key) , %nick_to $iif($msgtags(msg-param-recipient-display-name).key, $v1, $msgtags(msg-param-recipient-user-name).key)
describe $1 keviskAww NEW SUB!! courageHEART Thank you %nick_to for subscribing with a gifted sub from %nick_from courageLOGO ausHype courageLOGO
}

raw USERNOTICE:*:{
if (($msgtags(msg-id).key == sub) && ($1 == #couragejd)) {
var %nick $iif($msgtags(display-name).key, $v1, $msgtags(login).key)
msg $1 keviskAww NEW SUB!! courageHEART %nick welcome to the Courageous!! courageLOGO ausHype courageLOGO
}
elseif (($msgtags(msg-id).key == resub) && ($1 == #couragejd)) {
var %nick $iif($msgtags(display-name).key, $v1, $msgtags(login).key)
if ($0 == 1) {
msg $1 courageLOGO courageHEART RESUB!! %nick welcome back to the courageous for $msgtags(msg-param-months).key months in a row! courageHEART courageLOGO
}
else {
msg $1 courageLOGO courageHEART RESUB!! %nick welcome back to the courageous for $msgtags(msg-param-months).key months in a row! courageHEART courageLOGO Left a note: $qt($2-)
}
}
}

This works perfectly at announcing subs. However when there tends to be a larger amount of subs at one time as seen in this gyazo --> https://gyazo.com/f1d6c2bb0b25ee75bd90fc1598efa4d0 the messages send to chat delayed. Slowly announcing one at a time in chat instead of instant, this slows down my bot across all channels until its finished announcing all the subs in said chat. Is this just an issue with my script or a delay issue im unaware of with the twitch server? And how can i improve this response time.

Joined: Jul 2006
Posts: 4,141
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,141
It's an issue with twitch (IRC servers in general though) when you send too many commands too quickly, the server simply processes your requests slower in order not to get laggy.

You have to make a queue/antiflood system for your bot.

Whenever you are sending a message, instead of sending it (/msg), add the message to a queue.

Run a timer that periodically (every two seconds in my code below) check the queue, pop a message from it, and send it.
This way, across all channels, your bot is always ever sending a new message each 2 seconds (of course this can be improved by changing the frequency based on the activity of channels, or you can make a queue for each channel possibly and change the frequency of that channel's queue based on the channel activity (easier?))

Code:
alias queue_push {
  if (!$window(@queue)) window -h @queue
  aline @queue $1
}
alias queue_pop {
  var %tok = $line(@queue, 1)
  if (!$line(@queue,0)) window -c @queue
  else dline @queue 1
  return %tok
}

on *:LOGON:*:{
raw CAP REQ :twitch.tv/membership
raw CAP REQ :twitch.tv/tags
raw CAP REQ :twitch.tv/commands
/debug @raw

;you can get millisecond support, here 1500 ms aka 1 second and a half
;.timerqueuechecking -m 0 1500 if ($queue_pop != $!null) $!v1
.timerqueuechecking 0 2 if ($queue_pop != $!null) $!v1
}

raw USERNOTICE:*:{
if (($msgtags(msg-id).key == subgift) && ($1 == #couragejd)) {
var %nick_from $iif($msgtags(display-name).key, $v1, $msgtags(login).key) , %nick_to $iif($msgtags(msg-param-recipient-display-name).key, $v1, $msgtags(msg-param-recipient-user-name).key)
queue_push describe $1 keviskAww NEW SUB!! courageHEART Thank you %nick_to for subscribing with a gifted sub from %nick_from courageLOGO ausHype courageLOGO 
}

raw USERNOTICE:*:{
if (($msgtags(msg-id).key == sub) && ($1 == #couragejd)) {
var %nick $iif($msgtags(display-name).key, $v1, $msgtags(login).key)
queue_push msg $1 keviskAww NEW SUB!! courageHEART %nick welcome to the Courageous!! courageLOGO ausHype courageLOGO 
}
elseif (($msgtags(msg-id).key == resub) && ($1 == #couragejd)) {
var %nick $iif($msgtags(display-name).key, $v1, $msgtags(login).key)
if ($0 == 1) {
queue_push msg $1 courageLOGO courageHEART RESUB!! %nick welcome back to the courageous for $msgtags(msg-param-months).key months in a row! courageHEART courageLOGO 
}
else {
queue_push msg $1 courageLOGO courageHEART RESUB!! %nick welcome back to the courageous for $msgtags(msg-param-months).key months in a row! courageHEART courageLOGO Left a note: $qt($2-) 
}
}
}
the queue is first in, first out (fifo), this is untested but should work, if not it should give you an idea wink


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2016
Posts: 10
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Jul 2016
Posts: 10
So far so good, your script is working perfectly laugh i'll stress test it a bit more when the chat is a bit more wild but it looks like it will hold up. Oh and checking the @raw window it appears like this when a sub occurs --> https://gyazo.com/5ba04860d00443c7cf1eda1c5abedfa2 is that normal to have so many usernotice events or is that to do with how many different sub scrips i have for channels?

Joined: Jul 2006
Posts: 4,141
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,141
No, and you don't have them, these are caused by your script.

The line starting with ->, it's what mIRC is sending to the server and the server answer back with the raw 421 indicating that you sent an unknown command to the server. I'm sure you recognize that command, it's your raw event definition.
This means that your script has a { } mismatch, it's missing a closing } at some points so it continues to execute the new line.
/raw is a valid command which sends the data to the server as a command.

And indeed, your first raw event is missing a } at the end wink


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2016
Posts: 10
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Jul 2016
Posts: 10
I might be pulling my hair out right now, you dont even want to know how long i spent scanning my code and it was something that simple the whole time :x thanks so much for the help wims <3

Joined: Aug 2003
Posts: 318
P
Pan-dimensional mouse
Offline
Pan-dimensional mouse
P
Joined: Aug 2003
Posts: 318
1. mIRC has anti-flooding settings which should queue the messages for you.

2. The mIRC script editor has a "check brackets" button in the top right hand corner which can easily find these sorts of errors.


Link Copied to Clipboard