mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2018
Posts: 23
R
Ryntovy Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jan 2018
Posts: 23
Hello,

I have the following code for a !uptime command in my Twitch channel:

Code:
[script]
n0=on *:TEXT:!uptime*:#: {
n1=  var %json = streamuptime, %stream = $iif(#* iswm $iif($2,$2,#), $mid($v2, 2-), $v2), %time
n2=  jsonopen -ud %json https://api.twitch.tv/kraken/streams?channel= $+ $lower(%stream)
n3=  if ($JSONError) {
n4=  
n5=    msg # Unable to retrieve the state of %stream
n6=  }
n7=  elseif ($regex($JSON(%json, streams, 0, created_at), /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/)) {
n8=    %time = $calc($ctime($+($gettok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec, $regml(2), 32) $ord($base($regml(3), 10, 10)), $chr(44) $regml(1) $regml(4), :, $regml(5), :, $regml(6))) + ( $time(z) * 3600))
n9=    msg # %stream has been online for $duration(%time)
n10=  }
n11=  else {
n12=    msg # %stream is currently not live.
n13=  }
n14=}


But I want to add code that prevents people from spamming !uptime. And I tried this:

Code:
[script]
n0=on *:TEXT:!uptime*:#: {
n1=  if ((%floodsocial) || ($($+(%,floodsocial.,$nick),2))) { return }
n2=  set -u10 %floodsocial On
n3=  set -u30 %floodsocial. $+ $nick On
n4=  var %json = streamuptime, %stream = $iif(#* iswm $iif($2,$2,#), $mid($v2, 2-), $v2), %time
n5=  jsonopen -ud %json https://api.twitch.tv/kraken/streams?channel= $+ $lower(%stream)
n6=  if ($JSONError) {
n7=  
n8=    msg # Unable to retrieve the state of %stream
n9=  }
n10=  elseif ($regex($JSON(%json, streams, 0, created_at), /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/)) {
n11=    %time = $calc($ctime($+($gettok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec, $regml(2), 32) $ord($base($regml(3), 10, 10)), $chr(44) $regml(1) $regml(4), :, $regml(5), :, $regml(6))) + ( $time(z) * 3600))
n12=    msg # %stream has been online for $duration(%time)
n13=  }
n14=  else {
n15=    msg # %stream is currently not live.
n16=  }
n17=}


However, it doesn't work. Any suggestions on what I should change? Maybe I placed
Code:
n1=  if ((%floodsocial) || ($($+(%,floodsocial.,$nick),2))) { return }
n2=  set -u10 %floodsocial On
n3=  set -u30 %floodsocial. $+ $nick On
in the wrong place? Or is it just not the right code to use for this?

Thank you for taking the time to read this,

With kind regards,
Ry

Last edited by Ryntovy; 05/02/18 09:37 PM.
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
1. it's a log easier to read code that's pasted without the n1= stuff. Either paste from the REMOTE tab of alt-R window or if you name your script with filetype .mrc instead of .ini it won't add those n1= stuff.

2. Not sure what you're not seeing work. When a script doesn't do what you want it to do, or vice-versa, it helps to have debug messages to see why things are the way they are. Take this line and put into your script in 2 places. First insert it as a line above the code where you're returning if someone is spamming, and the other place below both of the set -u30's.

Code:
echo 4 -g # $time $scriptline values floodsocial= $+ %floodsocial remain= $+ $var(%floodsocial,1).secs  floodsocial. $+ $nick $+ = $+ %floodsocial. [ $+ [ $nick ] ] remain= $+ $var(%floodsocial. [ $+ [ $nick ] ] ,1).secs



This tells you if either variable is set prior to the event, and if so it tells how long until it clears. Any failed attempt to use the trigger does not reset the countdown.


Link Copied to Clipboard