mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2014
Posts: 16
R
radmux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: May 2014
Posts: 16
Hello!

Recently, I received help on creating a raffle system I can turn on and off with my Twitch chat bot. Now, I'd like to add a check to my raffle system that checks whether or not the user is a follower of the channel or not. I use this bot on some other channels as well.

This guy has a pretty good follower check script:
https://albinstuff.net/?id=coding
I found it here:
http://discuss.dev.twitch.tv/t/script-check-if-an-user-follows-a-user/767/3
This is what I find useful for what I'm trying to do:
https://albinstuff.net/twitch2.php?id=[USERNAME]&follows=[FOLLOWS]

Objective(s):
- Make a script that replaces [USERNAME] with the channel owner since I use the bot on multiple channels.
- Make a script that replaces [FOLLOWS] with $nick (the user issuing the command) to check if they follow the channel.
- Be able to use the link with [USERNAME] and [FOLLOWS] replaced to return "true" or "false" ; I've checked that guy's script and it works.
- Let the command go through if "true" or halt the command and let the $nick know they need to be a follower if "false" .

Here's my raffle script so far:
Code:
;Raffle System (Beavis)
on *:text:!raffle off:#:{
  if ($nick isop #) {
    set %ticketoff 1
    msg $chan $nick, the raffle/giveaway system is now set to OFF.
  }
  else { msg $chan This command is only available to moderators. }
}
on *:text:!raffle on:#:{
  if ($nick isop #) {
    unset %ticketoff
    msg $chan $nick has started a raffle/giveaway. To enter the raffle/giveaway, you need a ticket. You can purchase a ticket for 200pts by typing the command "!ticket"; only 1 ticket allowed per user. 
  }
  else { msg $chan This command is only available to moderators. }
}
on *:text:!ticket:#:{
  if (%ticketoff) { msg $chan There is currently no raffle/giveaway. | HALT }
  if ((%floodraffle) || ($($+(%,floodraffle.,$nick),2))) { return }
  set -u3 %floodraffle On
  set -u60 %floodraffle. $+ $nick On
  /* Add follower check script here. 
  https://albinstuff.net/twitch2.php?id=[USERNAME]&follows=[FOLLOWS] might have what I need.
  */
  if ($hget($+(tickets.,#),$nick)) { msg # $nick , you already have a ticket! | return }
  var %topic = $+(#,.,$nick)
  ; Check if enough points
  if ($readini(Points.ini,%topic,Points) >= 200) {
    ; Deduct the points
    var %a = $v1 - 200
    writeini Points.ini %topic Points %a
    ; Add the user to tickets.#channel hash table, creating the table if it doesn't exist
    hadd -m $+(tickets.,#) $nick 1
    msg # $nick spent 200 points on a raffle ticket.
  }

else msg #  Sorry $nick , you don't have enough points to join this raffle. You need 200 points to join. }

on *:text:!roll:#:{
  if ($nick isop #) {
    if ($hget($+(tickets.,#))) {
      var %i = $r(1,$hget($+(tickets.,#),0).item)
      msg # The winner is $hget($+(tickets.,#),%i).item
      ; The next line frees the table (all data in it is gone)
      hfree $+(tickets.,#)
    }
    else msg # There are no ticket entries at this time. 
  }
  else msg # $nick, only moderators can use that command.
}


Please help!

Thank you!

~Arden

Joined: May 2014
Posts: 16
R
radmux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: May 2014
Posts: 16
I found this tutorial on sockets: http://forum.swiftirc.net/viewtopic.php?t=4378

Do I need to open a socket to accomplish what I'm trying to do?

Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Yes, you need socket for that. Instead grabbing info from that site, why you dont grab it from twitch api itself?

https://api.twitch.tv/kraken/users/[FOLLOW]/follows/channels/[USERNAME]

Joined: May 2014
Posts: 16
R
radmux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: May 2014
Posts: 16
Originally Posted By: blessing
https://api.twitch.tv/kraken/users/[FOLLOW]/follows/channels/[USERNAME]


To test the response, I tried to plug that information into a browser using: https://api.twitch.tv/kraken/users/radmux/follows/channels/fresherdata

And came up with this:
Code:
{"created_at":"2014-02-21T19:34:46Z","_links":{"self":"https://api.twitch.tv/kraken/users/radmux/follows/channels/fresherdata"},"channel":{"mature":true,"abuse_reported":null,"status":"DayZ SA Experimental Adventures in the wild","display_name":"fresherdata","game":"DayZ","delay":0,"_id":28363157,"name":"fresherdata","created_at":"2012-02-19T21:04:31Z","updated_at":"2014-06-03T06:01:54Z","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/fresherdata-profile_image-c467c541d1d7103d-300x300.jpeg","banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/fresherdata-channel_header_image-a2f576bce4791618-640x125.png","video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/fresherdata-channel_offline_image-2de465272540a574-640x360.png","background":null,"profile_banner":null,"profile_banner_background_color":"null","url":"http://www.twitch.tv/fresherdata","views":124907,"followers":6233,"_links":{"self":"https://api.twitch.tv/kraken/channels/fresherdata","follows":"https://api.twitch.tv/kraken/channels/fresherdata/follows","commercial":"https://api.twitch.tv/kraken/channels/fresherdata/commercial","stream_key":"https://api.twitch.tv/kraken/channels/fresherdata/stream_key","chat":"https://api.twitch.tv/kraken/chat/fresherdata","features":"https://api.twitch.tv/kraken/channels/fresherdata/features","subscriptions":"https://api.twitch.tv/kraken/channels/fresherdata/subscriptions","editors":"https://api.twitch.tv/kraken/channels/fresherdata/editors","teams":"https://api.twitch.tv/kraken/channels/fresherdata/teams","videos":"https://api.twitch.tv/kraken/channels/fresherdata/videos"}}}


From what I've read, this guy's link generates a "true" or "false" response when using his link: https://albinstuff.net/twitch2.php?id=[USERNAME]&follows=[FOLLOWS]

So I tested it with this: https://albinstuff.net/twitch2.php?id=radmux&follows=fresherdata

And came up with:
Code:
true


It would be nice if I could use the Twitch API directly, but I have no idea what I'm doing. For convenience, it might be nice to use the true/false data to somehow simply check if the user is a follower or not and then go from there...

Last edited by radmux; 04/06/14 01:49 AM.
Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
I guess if the response came up with "created_at" it means true, "error" means false.
I'm pretty sure that guy grabs the info from the link i gave you.

Here is the code. You can expand from there.
Note: You need to load $json snippet ( http://www.mircscripts.org/comments.php?cid=4407 ) into your remote.

usage: /followcheck <follow> <username>

Code:
alias followcheck {
  var %follow $1
  var %username $iif($left($2,1) == $chr(35),$right($2,-1),$2)
  var %url $+(https://api.twitch.tv/kraken/users/,%follow,/follows/channels/,%username)

  jsonclearcache
  var %error $json(%url,error) 
  if !%error { 
    echo -tag %follow is follower of %username  
  }
  else { 
    echo -tag %follow is not follower of %username  
  }
}


Last edited by blessing; 04/06/14 03:48 AM.
Joined: May 2014
Posts: 16
R
radmux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: May 2014
Posts: 16
Is there a way to specify that the user issuing the command ($nick) is %follow and the channel owner is %username ?

This is similar to how I would like to use the follow check:
Code:
on *:text:!gimme:#: {
  followcheck
  if !%error { msg $chan $nick , you are not a follower. Hit that follow button to have access to this command! | halt }
else { msg $chan Here is your gold. } 
}

Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Code:
alias followcheck {
  var %follow $1
  var %username $iif($left($2,1) == $chr(35),$right($2,-1),$2)
  var %url $+(https://api.twitch.tv/kraken/users/,%follow,/follows/channels/,%username)

  jsonclearcache
  var %error $json(%url,error) 

  if $isid { return %error }

  if !%error { 
    echo -tag %follow is follower of %username  
  }
  else { 
    echo -tag %follow is not follower of %username  
  }
}

on *:text:!gimme:#: {
  var %error $followcheck($nick,$chan)

  if %error { msg $chan $nick , you are not a follower. Hit that follow button to have access to this command! }
  else { msg $chan Here is your gold. } 
}

Joined: May 2014
Posts: 16
R
radmux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: May 2014
Posts: 16
Thank you so much, blessing! You are a real blessing to this community. I am completely new to scripting and am learning this as I go.

This worked for me!

Thank you so much!

<3

~Arden

Joined: Apr 2014
Posts: 170
Vogon poet
Offline
Vogon poet
Joined: Apr 2014
Posts: 170
After messing with this a bit, I got a nicklist menu set up so I can just right click to check if someone's following and it pops up in chat as well. I'll share that if anyone wants it... Just right click a username and do "Followcheck" obviously.

Code:
menu nicklist {
  Followcheck:/followcheck $1
}


alias followcheck {
  var %follow $1
  var %username $iif($left($2,1) == $chr(35),$right($2,-1),$2)
  var %url $+(https://api.twitch.tv/kraken/users/,%follow,/follows/channels/,%username)

  jsonclearcache
  var %error $json(%url,error) 
  if !%error { 
    msg # %follow is following %username  
  }
  else { 
    msg # %follow is not following %username  
  }
}


Anyway, I have a question that isn't necessarily related to this exact problem. But rather than finding an old thread to bump or creating a new one I figured I'd ask here. Is it possible to use this as a way to welcome a new follower in the chat itself? The script I currently have doesn't seem to work.

Here's what I have that is SUPPOSED to welcome new followers...

Code:
on $*:text:!followers:#: {
  followers.update -s # 
}

alias followers.update {
  if (-* iswm $1) {
    var %switches = $1
    tokenize 32 $2-
  }
  var %chan = #$$1, %limit = $iif($2,$2,25), %offset = $iif($3,$3,0)
  var %sockname = twitch.followers. $+ $ticks
  hfree -w %sockname | hmake %sockname
  hadd %sockname chan %chan
  hadd %sockname limit %limit
  hadd %sockname offset %offset
  hadd %sockname request /kraken/channels/ $+ $mid(%chan,2-) $+ /follows?limit= $+ %limit $+ &offset= $+ %offset
  hadd %sockname method GET
  hadd %sockname signal followers.update
  if (s isin %switches) hadd %sockname show 1
  if (!$hget(followers. $+ %chan)) hadd %sockname init 1
  sockopen -e %sockname api.twitch.tv 443
  return %sockname
}

on *:signal:followers.update:{
  var %err = $1, %sockname = $2, %header = $3, %data = $4
  var %chan = $hget(%sockname,chan), %init = $hget(%sockname,init), %show = $hget(%sockname,show)

  if (* 200 OK iswm $read(%header,n,1)) {
    if (!$hget(followers. $+ %chan)) {
      hmake -s followers. $+ %chan $iif($calc($json(%data,_total) / 10) > 100,$v1,$v2)
      if ($ini(followers.ini,%chan,0) > 0) hload -i followers. $+ %chan followers.ini %chan
    }

    var %i = 0, %n = $json(%data,follows).count, %new.count
    while (%i < %n) {
      var %name = $json(%data,follows,%i,user,name)
      var %display_name = $json(%data,follows,%i,user,display_name)
      if (!$hget(followers. $+ %chan,%name)) {
        hadd followers. $+ %chan %name 1
        if (!%init) && (%show) {
          set -nz %followers. $+ %chan %followers. [ $+ [ %chan ] ] %display_name
          if ($calc($len(%followers. [ $+ [ %chan ] ]) + $len(%display_name)) > 350) {
            var %msg = Welcome to our new follower $+ $iif($numtok(%followers. [ $+ [ %chan ] ],32) > 1,s:,:) $regsubex(%followers. [ $+ [ %chan ] ],/( $+ $chr(32) $+ )/g,$iif(\n == \0,$iif(\0 > 2,$chr(44),$chr(32)) and $chr(32),$chr(44) $+ $chr(32))) $+ !
            .timer 1 $iif(%flood.protection,$v1,0) msg %chan $safe(%msg)
            inc -z %flood.protection 5
            unset %followers. [ $+ [ %chan ] ]
          }
        }
        inc %new.count
      }
      else break
      inc %i
    }

    if (%new.count == $hget(%sockname,limit)) {
      followers.update %chan 100 $calc($hget(%sockname,limit) + $hget(%sockname,offset))
      var %next = $result
      if (%init) hadd %next init 1
      if (%show) hadd %next show 1
    }
    else {
      if (!%init) && (%show) && (%new.count) {
        var %msg = Welcome to our new follower $+ $iif($numtok(%followers. [ $+ [ %chan ] ],32) > 1,s:,:) $regsubex(%followers. [ $+ [ %chan ] ],/( $+ $chr(32) $+ )/g,$iif(\n == \0,$iif(\0 > 2,$chr(44),$chr(32)) and $chr(32),$chr(44) $+ $chr(32))) $+ !
        .timer 1 $iif(%flood.protection,$v1,0) msg %chan $safe(%msg)
        inc -z %flood.protection 5
      }  
      unset %followers. [ $+ [ %chan ] ]
      if ($hget(followers. $+ %chan)) hsave -i followers. $+ %chan followers.ini %chan
    }
  }

  hfree -w %sockname
  if ($isfile(%header)) .remove %header
  if ($isfile(%data)) .remove %data
}



Any help is appreciated (as always) I've been working at getting better with mIRC and reading /help just about every day. But I can't seem to find where something is wrong in this.

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
Can I assume you actually have all the socket related events for that? Does the signal even get hit? Are the header and data files populated?

Joined: Apr 2014
Posts: 170
Vogon poet
Offline
Vogon poet
Joined: Apr 2014
Posts: 170
I got my entire script for the twitch API stuff from Nillen. And, I believe, he said his follower alert stuff wasn't working. Everything else works fine (ie: !commercial, !game, !topic[!status for me, I changed that part])

Nothing happens at all when I try to do the command. Same with if I choose it through the menu in the bot itself. It's not a HUGE deal, because I have a follower alert from NightDev. But every now and then I get a follower that can't hear or something so welcoming and thanking them through my mic isn't an option. I just had a few other things I was looking at getting to work with the "new follow" feature. (a few extra points when they follow mainly)

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
I just tested it and it works fine.

If you can throw in debug statements to find where it's breaking, I can look into it (pm me).

https://gist.github.com/memnochxx/5676bef5707a8019f0ca

Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
confirm not working. It seems $json failed to parse %data.

Here is how i tested it.
/followers.update -s #mark_paintball

Tried to debug using echo between this line
Code:
var %i = 0, %n = $json(%data,follows).count, %new.count
echo -a n value is %n
while (%i < %n) {

It did hmake hashtable, after that it seems %n is $null so while loop never being executed.

Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Here is my version. Not using sockets stuff.
I just wrote it and not enough testing yet.
You can expand from there. Using timer or something else. Just make sure you dont flood twitch api wink

Usage:
/follow #channel
or type !followers (in the channel)

Note:
- need $json snippet.
- !followers is OP command.
Code:
on *:TEXT:!followers:#:if $nick isop # { follow # }

alias follow {
  var %chan $1, %username $iif($left($1,1) == $chr(35),$right($1,-1),$1)
  var %cmd $iif(%chan ischan,msg %chan,echo -agt)
  if !$readini(follower.ini,%username,$chr(44)) {
    %cmd start follower update for %chan $+ ...
    follow@ %chan %username
  }
  else { %cmd follower update for %chan is in progress.. }
}

alias -l follow@ {
  var %chan $1, %username $2, %follow 
  tokenize 32 $readini(follower.ini,%username,$chr(44))
  var %limit 100, %offset $iif($1,$1,0), %ctime $iif($2,$2,$ctime)
  var %lastshow $iif(!$ini(follower.ini,%username),10)
  var %url $+(https://api.twitch.tv/kraken/channels/,%username,/follows?limit=,%limit,&offset=,%offset)

  echo -agt parsing.. %url | ; if you dont want to see update progress, delete this line.

  var %i 0 | while $json(%url,follows,%i,user,display_name) {
    var %f $v1 | inc %i
    if ($numtok(%follow,32) <= %lastshow || (!%lastshow && !$readini(follower.ini,%username,%f))) && %offset == 0 { %follow = %follow %f }
    writeini follower.ini %username %f %ctime
  }
  var %cmd $iif(%chan ischan,msg %chan,echo -agt)
  if %offset == 0 {
    if %follow { %cmd Welcome to our new followers: $replace(%follow,$chr(32),$+($chr(44),$chr(32))) }
    else { %cmd There is no new followers }
  }

  if %i == %limit { 
    inc %offset %limit 
    writeini follower.ini %username $chr(44) %offset %ctime 
    .timerfollow. [ $+ [ %chan ] ] 1 5 follow@ %chan %username
  }
  else { 
    var %tmp $+(%username,.tmp)
    remini follower.ini %username $chr(44)
    hmake %username | hload -i %username follower.ini %username | hsave -i %username %tmp
    window -h @.
    filter -fwx %tmp @. $+(*,%ctime,*) 
    filter -cww @. @. *=*
    var %unfollow, %i 1 
    while $line(@.,%i) {
      %unfollow = %unfollow $v1
      remini follower.ini %username $v1
      inc %i
    }
    window -c @.
    hfree %username | .remove %tmp

    if %unfollow { %cmd Goodbye to our followers: $replace(%unfollow,$chr(32),$+($chr(44),$chr(32))) }
    echo -agt follower update for %chan is completed ( $ini(follower.ini,%username,0) users ) 
  }
}

Last edited by blessing; 05/06/14 08:16 AM.
Joined: Apr 2014
Posts: 191
B
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
EDIT:
It seems %unfollow is not parsed correctly. My bad. Now it is fixed.
Code:
    while $line(@.,%i) {
      var %uf $gettok($v1,1,61)
      %unfollow = %unfollow %uf
      remini follower.ini %username %uf
      inc %i
    }

Joined: Nov 2014
Posts: 1
G
Mostly harmless
Offline
Mostly harmless
G
Joined: Nov 2014
Posts: 1
Originally Posted By: blessing
Code:
alias followcheck {
  var %follow $1
  var %username $iif($left($2,1) == $chr(35),$right($2,-1),$2)
  var %url $+(https://api.twitch.tv/kraken/users/,%follow,/follows/channels/,%username)

  jsonclearcache
  var %error $json(%url,error) 

  if $isid { return %error }

  if !%error { 
    echo -tag %follow is follower of %username  
  }
  else { 
    echo -tag %follow is not follower of %username  
  }
}

on *:text:!gimme:#: {
  var %error $followcheck($nick,$chan)

  if %error { msg $chan $nick , you are not a follower. Hit that follow button to have access to this command! }
  else { msg $chan Here is your gold. } 
}


I was using this script with the !raffle command from the moobot, is there a way to halt the access to the moobot command if the result = error?

When using this the error does pop-up from my user but the moobot keeps adding the person to the raffle.

Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
No.


Link Copied to Clipboard