on *:text:!raffle*:#: {
if ($2 == start) && ($nick == $remove(#,$chr(35))) {
if (%raffle. [ $+ [ $chan ] ]) { msg # A raffle is already underway! | return }
set -u120 %raffle. [ $+ [ $chan ] ] On
msg # Raffle started! Type !raffle to participate, and make sure you are following the stream, or you won't be able to win! The winner will be chosen in 2 minutes
.timer 1 60 msg # 60 seconds left until raffle ends! Type !raffle to join.
.timer 1 90 msg # 30 seconds until raffle ends! Type !raffle to join
.timer 1 120 endofraffle #
}
if (!$2) && ($1 == !raffle) {
if (!%raffle. [ $+ [ $chan ] ]) return
if (!%raffle.string. [ $+ [ $chan ] ]) set %raffle.string. [ $+ [ $chan ] ] $nick
set %raffle.string. [ $+ [ $chan ] ] $addtok(%raffle.string. [ $+ [ $chan ] ] $+ ,$nick,32)
;echo -a %raffle.string. [ $+ [ $chan ] ]
}
}
alias endofraffle {
;echo -a %raffle.string. [ $+ [ $1 ] ]
var %i 1 | var %temp = $numtok(%raffle.string. [ $+ [ $1 ] ] $+ ,32)
msg $1 Raffle has ended! %temp people participated in the raffle. Selecting a winner at random..
:selection
var %winnernumber = $rand(1,%temp) | var %user = $gettok(%raffle.string. [ $+ [ $1 ] ] $+ ,%winnernumber,32) | var %streamer = $remove($1,$chr(35))
jsonopen -du raffle https://api.twitch.tv/kraken/users/ $+ %user $+ /follows/channels/ $+ %streamer
if (%i > 50) { msg $1 No winner could be selected. | unset %raffle.string. [ $+ [ $1 ] ] | return }
if ($json(raffle,channel,views) == $null) { inc %i | goto selection }
msg $1 %user follows the stream and is the winner of the raffle, congrats!! | unset %raffle.string. [ $+ [ $1 ] ]
}