; =======================================================
; ===== TWITCH IN-CHAT FOLLOWER NOTIFICATION SCRIPT =====
; =======================================================
ON *:LOAD: {
SET -i %streamer your_twitch_name
SET -i %mychan $chr(35) $+ $lower(%streamer)
}
ON *:CONNECT: {
IF ($server == tmi.twitch.tv) {
IF (!$hget(new_follows)) HMAKE new_follows
VAR %x = 0
JSONOpen -u newfollows https://api.twitch.tv/kraken/channels/ $+ $lower(%streamer) $+ /follows?client_id=avm4vi7zv0xpjkpi3d4x0qzk8xbrdw8&limit=100&nocache= $+ $ticks
WHILE (%x <= 100) {
VAR %follower_newest $get_follower_name(%x)
IF ((%follower_newest == %follower_last) || ($istok(%last_100_follows,%follower_newest,32))) {
IF (%x == 0) BREAK
SET %follower_last $get_follower_name(0)
BREAK
}
IF ($numtok(%last_100_follows,32) == 100) SET %last_100_follows $deltok(%last_100_follows, 100, 32)
SET %last_100_follows %follower_newest %last_100_follows
IF (%x == 100) SET %follower_last $get_follower_name(0)
INC %x
}
JSONClose newfollows
.timer.followercheck 0 60 followercheck
}
}
ON *:DISCONNECT: .timer.followercheck off
alias get_follower_name {
IF ($regex($json(newfollows, follows, $1, user, display_name).value,^\w+$)) RETURN $json(newfollows, follows, $1, user, display_name).value
ELSE RETURN $json(newfollows, follows, $1, user, name).value
}
alias followercheck {
VAR %x = 1
WHILE ($hget(new_follows,%x).item) {
VAR %name $v1
IF (%name ison %mychan) {
HDEL new_follows %name
SET %live_follows %live_follows %name $+ $chr(44)
}
INC %x
}
VAR %x = 0 , %new_follows
JSONOpen -u newfollows https://api.twitch.tv/kraken/channels/ $+ $lower(%streamer) $+ /follows?client_id=avm4vi7zv0xpjkpi3d4x0qzk8xbrdw8&limit=25&nocache= $+ $ticks
WHILE (%x <= 25) {
VAR %follower_newest $get_follower_name(%x)
IF (%follower_newest == $null) BREAK
IF ((%follower_newest == %follower_last) || ($istok(%last_100_follows,%follower_newest,32))) {
IF (%x == 0) BREAK
SET %follower_last $get_follower_name(0)
BREAK
}
IF ($numtok(%last_100_follows,32) == 100) SET %last_100_follows $deltok(%last_100_follows, 100, 32)
SET %last_100_follows %follower_newest %last_100_follows
VAR %new_follows %new_follows %follower_newest $+ $chr(44)
IF (%x == 25) SET %follower_last $get_follower_name(0)
INC %x
}
JSONClose newfollows
VAR %x = 1
WHILE ($gettok(%new_follows,%x,44)) {
VAR %name $v1
IF (%name ison %mychan) SET %live_follows %live_follows %name $+ $chr(44)
ELSE HADD -z new_follows %name 600
INC %x
}
IF (%live_follows) {
IF ($numtok(%live_follows,32) == 1) {
MSG %mychan KonCha Thank you for the follow and welcome to the channel, $left(%live_follows,-1) $+ !
;WRITE -l1 new_follows.txt %live_follows thanks for the follow!
}
ELSEIF ($numtok(%live_follows,32) >= 2) {
MSG %mychan KonCha Thank you for the follows and welcome to the channel: $left(%live_follows,-1) $+ !
;WRITE -l1 new_follows.txt %live_follows thanks for the follows!
}
;.timer.new_follows_clear 1 6 WRITE -dl1 new_follows.txt
;IF (%stream_is_live) SPLAY -pq follower_sound.mp3
UNSET %live_follows
}
}
ON *:JOIN:%mychan: {
IF ($hget(new_follows,$nick)) {
HDEL new_follows $nick
SET %live_follows %live_follows $nick $+ $chr(44)
}
}