1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
alias vote {
if ($hget(countvotes)) { hfree countvotes }
var %i = $hget(Votes,0).item
while (%i > 0) {
hinc -m countvotes $hget(votes,%i).data 1
dec %i
}
var %i = $hget(Countvotes,0).item, %wincount = 0
while (%i > 0) {
var %map = $hget(Countvotes,%i).item
if ($hget(Countvotes,%map) > %wincount) {
if (%votewinner) { var %notwin = %notwin %votewinner }
var %votewinner = %map $+ ( $+ $hget(Countvotes,%map) $+ ) , %wincount = $hget(Countvotes,%map)
}
elseif ($hget(Countvotes,%map) == %wincount) {
var %votewinner = %votewinner %map $+ ( $+ $hget(Countvotes,%map) $+ )
}
else { var %notwin = %notwin %map $+ ( $+ $v1 $+ ) }
dec %i
}
;$reptok(text,token,new,N,C)
echo -s losers: %notwin ** Winners: %votewinner
if ($numtok(%votewinner,32) > 1) {
var %nr = $rand(1,$numtok(%votewinner,32))
var %notwin = %notwin $deltok(%votewinner,%nr,32)
var %votewinner = $gettok(%votewinner,%nr,32)
}
var %x = %votewinner %notwin
if (%x == (0)) || (!%x) { var %x = $hget(maps, $rand(1,$hget(maps,0).item)).item }
return %x
}
|