xecho -b Poll script loaded! xecho -b Written by gircobain 31/03/2002 assign POLLFILE ~/poll assign POLL_ON 0 assign SURVEY If you would like to suggest a name for our network please type: assign POLL_CHAN #alternative alias startpoll { if (POLL_ON) { xecho -b Poll is already on! }{ assign POLL_ON 1 xecho -b Poll is now on! if (!match($POLL_CHAN $onchannels())) join $POLL_CHAN @delarray(poll) @:fd = open($POLLFILE r) while (!eof($fd)) { @:vote = read($fd) if (vote) @setitem(poll $numitems(poll) $vote) } @close($fd) } } on #-join 9012 '$POLL_CHAN *' { if (matchitem(poll $1 *) < 0 && POLL_ON) spampoll $1 } on #-msg 3748 "% !poll" if (POLL_ON) spampoll $0 on #-msg 8725 "% !vote %" if (POLL_ON) { @:pos = matchitem(poll $0 *) if (pos < 0) { @setitem(poll $numitems(poll) $0 $2) msg $0 You have voted for: $2 }{ @setitem(poll $pos $0 $2) msg $0 You have switched your vote over to: $2 } } on #-msg 2587 "% !vote" if (POLL_ON) { @:pos = matchitem(poll $0 *) if (pos < 0) { msg $0 You have not voted yet. }{ msg $0 You have currently voted for: $word(1 $getitem(poll $pos)) } } on #-msg 2859 "% !results" if (POLL_ON) { count_votes @:sorted = revw($numsort($listarray(votes))) if (numwords($sorted) > 5) @sorted = leftw(5 $sorted) @delarray(most_voted) @:names_list = listarray(names) @:votes_list = listarray(votes) fe ($sorted) votes { @:pos = findw($votes $votes_list) @setitem(most_voted $numitems(most_voted) $word($pos $names_list) $votes) @names_list = remw($word($pos $names_list) $names_list) @votes_list = remw($votes $votes_list) } msg $0 5 most voted names are: for (@:count = 0,count < 5,@count++) { msg $0 $getitem(most_voted $count) } @delarray(most_voted) } alias endpoll { if (POLL_ON) { assign POLL_ON 0 count_votes @:votes = rightw(1 $numsort($listarray(votes))) @:most_voted = [] fe ($getmatches(votes $votes)) nitem { @most_voted #= getitem(names $nitem) ## [ ] } timer -del POLL savepoll msg $POLL_CHAN $cparse(%cPoll is over!) msg $POLL_CHAN $cparse(%cAnd the winner is/are...) msg $POLL_CHAN $cparse(%Y$most_voted%c, with%Y $votes %cvotes!) }{ xecho -b Poll is already off! } } alias spampoll { msg $0 $SURVEY msg $0 /msg $N !vote msg $0 Remember that must be one word and only your last vote counts msg $0 Also you can type /msg $N !results to see poll results } alias count_votes { @delarray(names) @delarray(votes) for (@:count = 0,count < numitems(poll),@:count++) { @:name = word(1 $getitem(poll $count)) @:pos = matchitem(names $name) if (pos < 0) { @setitem(names $numitems(names) $name) @setitem(votes $numitems(votes) 1) }{ @setitem(votes $pos ${getitem(votes $pos) + 1}) } } } alias savepoll { @unlink($POLLFILE) @:fd = open($POLLFILE w) for (@:count = 0,count < numitems(poll),@:count++) { @write($fd $getitem(poll $count)) } @close($fd) } timer -ref POLL -rep -1 900 savepoll