;************************************************
;********************** POLL ********************
;************************************************
on *:TEXT:!poll *:#: {
if (($nick !isop $chan) && ($$2 != results)) {
msg $chan Only mods may use this feature.
}
else {
; *********
; OPEN POLL
; *********
if ($$2 == open) {
unset $($+(%,polloptions,$chan),1)
unset $($+(%,pollvotes,$chan),1)
unset $($+(%,hasvoted,$chan),1)
set $($+(%,polloptions,$chan),1) $3-
var %numberofoptions $numtok($3-,124)
while ( %numberofoptions > 0 ) {
dec %numberofoptions
set $($+(%,pollvotes,$chan),1) $($+(%,pollvotes,$chan),2) 0
}
var %number $numtok($($+(%,polloptions,$chan),2),124)
while (%number > 0) {
if (%number == $numtok($($+(%,polloptions,$chan),2),124)) {
var %finalresults %number - $gettok($($+(%,polloptions,$chan),2),%number,124) %finalresults
}
else {
var %finalresults %number - $gettok($($+(%,polloptions,$chan),2),%number,124) || %finalresults
}
dec %number
}
msg $chan A new poll has been opened: %finalresults
}
; ************
; POLL RESULTS
; ************
elseif ($$2 == results) {
if ($($+(%,polloptions,$chan),2) != $null) {
msg $chan Current Results are: $pollresults
}
else {
msg $chan Results for previous poll are: $($+(%,oldresults,$chan),2)
}
}
; **********
; POLL CLOSE
; **********
elseif ($$2 == close) {
msg $chan $nick has closed the poll! Results are: $pollresults
set $($+(%,oldresults,$chan),1) $pollresults
unset $($+(%,polloptions,$chan),1)
unset $($+(%,pollvotes,$chan),1)
unset $($+(%,hasvoted,$chan),1)
}
}
}
alias pollresults {
var %number $numtok($($+(%,polloptions,$chan),2),124)
while (%number > 0) {
if (%number == $numtok($($+(%,polloptions,$chan),2),124)) {
var %finalresults $gettok($($+(%,polloptions,$chan),2),%number,124) : $gettok($($+(%,pollvotes,$chan),2),%number,32) votes %finalresults
}
else {
var %finalresults $gettok($($+(%,polloptions,$chan),2),%number,124) $+ : $gettok($($+(%,pollvotes,$chan),2),%number,32) votes || %finalresults
}
dec %number
}
return %finalresults
}
on *:TEXT:!vote *:#: {
if ( $($+(%,polloptions,$chan),2) == $null) {
msg $chan There is no open poll to vote on!
}
elseif ($nick isin $($+(%,hasvoted,$chan),2)) {
msg $chan $nick $+ , you have already voted in this poll!
}
elseif ($$2 !isnum 1 - $numtok($($+(%,pollvotes,$chan),2),32)) {
msg $chan $$2- is not a valid poll option!
}
else {
set $($+(%,hasvoted,$chan),1) $($+(%,hasvoted,$chan),2) $nick
var %voteupdate $gettok($($+(%,pollvotes,$chan),2),$$2,32)
inc %voteupdate
set $($+(%,pollvotes,$chan),1) $puttok($($+(%,pollvotes,$chan),2),%voteupdate,$$2,32)
msg $chan $nick has voted for option $$2 $+ : $gettok($($+(%,polloptions,$chan),2),$$2,124)
}
}