on *:text:*:#:bet # $nick $1-
on *:nick:bet_ $nick $newnick
alias bet {
noop $regex($3,/^!((?:new|won)?bet)/)
var %r $regml(1)
if $istok(newbet wonbet,%r,32) && $2 !isop $1 { return }
if %r == newbet {
if %bet.q { .notice $2 Bet was already opened | return }
if !$4 || $numtok($4-,58) != 2 { .notice $2 command: !newbet <question> : <option1>,<option2>,<option3>,etc | return }
msg $1 [BET OPENED] $4- - Use: !bet <option> to set your bet.
set -e %bet.q $gettok($4-,1,58)
noop $regex($gettok($4-,2,58),/(\S.+$)/iS)
var %re /((:?\s+)?,(:?\s+)?)/giS
set -e %bet.a $regsubex($regml(1),%re,$chr(44))
}
if %r == bet {
if !%bet.q { return }
if $wildtok(%bet.user,$+($2,*),1,215) {
if !$istok(%bet.twice,$2,32) {
.notice $2 You cant bet twice!
set -e %bet.twice $addtok(%bet.twice,$2,32)
}
return
}
if !$4 {
if !$istok(%bet.warned,$2,32) || $2 isop $1 {
.notice $2 [BET] %bet.q : %bet.a - Use: !bet <option> to set your bet.
set -e %bet.warned $addtok(%bet.warned,$2,32)
}
return
}
if !$istok(%bet.a,$4-,44) {
if !$istok(%bet.invalid,$2,32) {
.notice $2 Valid options are: %bet.a
set -e %bet.invalid $addtok(%bet.invalid,$2,32)
}
return
}
if !$wildtok(%bet.user,$+($2,*),1,215) {
set -e %bet.user $addtok(%bet.user,$2 $4-,215)
msg $1 $+($2,'s) bet is $4-
}
}
if %r == wonbet {
if !%bet.q { .notice $2 There is no BET yet. | return }
if !$4 { .notice $2 command: !wonbet <option> | return }
if !$istok(%bet.a,$4-,44) { .notice $2 Valid options are: %bet.a | return }
var %i 1
while $wildtok(%bet.user,$+(*,$4-),%i,215) {
var %win %win $iif($gettok($v1,1,32) ison $1,$v1)
inc %i
}
msg $1 [BET CLOSED] $+(<,$4-,>) was the winning option! Winners are: %win - good luck for all others on the next bet!
unset %bet.*
}
}
alias bet_ {
if %bet.q {
set -e %bet.twice $reptok(%bet.twice,$1,$2,1,32)
set -e %bet.warned $reptok(%bet.warned,$1,$2,1,32)
set -e %bet.invalid $reptok(%bet.invalid,$1,$2,1,32)
if $wildtok(%bet.user,$+($1,*),1,215) {
set -e %bet.user $reptok(%bet.user,$v1,$2 $gettok($v1,2-,32),215)
}
}
}