Skip to content

Instantly share code, notes, and snippets.

@ssg
Created April 13, 2016 18:05
Show Gist options
  • Save ssg/1d24220f907c025eb6ce234e757cf576 to your computer and use it in GitHub Desktop.
Save ssg/1d24220f907c025eb6ce234e757cf576 to your computer and use it in GitHub Desktop.
Quiz bot for XiRCON that used no central DB but relied on people for questions and correct answers (circa 2001)
# gondol.tcl - particularly quiz bot
# idea by teo - code by ssg
set users ""
set question ""
set qowner ""
set answers {}
set qtime 0
set stopping 0
set phase 0
set channel "#gondol"
set cevaps {
"cevabiyla goz doldurdu"
"ile yakla\$tigini saniyor ama yaniliyor"
"deyip alttan aldi"
"cevabi sanki cok yakin?"
"dedi de nereye kadar"
"diyerek radikalligine yeni sinirlar cizdi"
"ile sichti resmen"
"diye gotunden salladi"
"oha oha.. sacmaligin daniskasi"
}
proc reply {who str} {
/msg $who $str
}
proc kus str {
global channel
/msg $channel $str
}
proc stop {} {
global qtime qowner question answers stopping
if {$stopping==0} return
if {$question!=""} {
kus "malesef cevaplamadi eleman o yuzden dogru cevap nedir asla bilemeyecegiz"
kus "yeni sorulariniz icin bana ozelden 'help' yazin"
set question ""
unset answers
set answers {}
set qtime 0
}
}
proc tick {} {
global qtime qowner question answers
incr qtime
if {$qtime==5} {
kus "5 saniye gecti bile"
}
if {$qtime==55} {
kus "hatta son 5 saniye desem yeridir"
}
if {$qtime==60} {
kus "sure bitti.. \$imdi $qowner cevabi sececek"
reply $qowner "baba cevaplar \$unlar:"
reply $qowner "0) hicbiri"
for {set a 0} {$a<[llength $answers]} {incr a} {
reply $qowner "[expr $a+1]) \"[lindex [lindex $answers $a] 1]\""
}
reply $qowner "birini sec artik"
set qtime 0
global stopping
set stopping 1
after 60000 stop
} else {
after 1000 tick
}
}
on privmsg {
set msg [join [lrange [args] 1 end]]
set chan [lindex [args] 0]
global question answers users qowner qtime cevaps
if {![string match "#*" $chan]} {
set chan [nick]
set cmd [string tolower [lindex $msg 0]]
set params [join [lrange $msg 1 end]]
switch $cmd {
"help" {
reply $chan "komutlar q soru, a cevap, c cevap sec modundadir"
}
"q" {
if {$question!=""} {
reply $chan "zaten bi tane soru sorulmu\$ onu cevaplasana soru soracagina"
} elseif {$params==""} {
reply $chan "bir tane soru cumlesi vermeniz lazim q'nun arkasindan"
} else {
set question $params
reply $chan "aldim sorunu baba.."
kus "aha soru sordu biri ($chan)"
kus "soru \$udur: \"$question\""
set qowner $chan
set qtime 1
after 1000 {if [catch tick] {kus "baba sIchtIm ben bot olarak"}}
}
}
"a" {
if {$question==""} {
reply $chan "yarraaam bi soru yok neye cevap veriyon?"
} elseif {$qowner==$chan} {
reply $chan "soruyu soran sensin amcik"
} elseif {$qtime==0} {
reply $chan "malesef sure doldu uzgunuz pek cok"
} elseif {$params==""} {
reply $chan "oyle bo$ cevap veremezsiniz"
} {
set heden 0
for {set x 0} {$x<[llength $answers]} {incr x} {
set tmp [lindex $answers $x]
if {[lindex $tmp 0]==$chan} {
set heden 1
set tmp [lreplace $tmp 1 1 $params]
set answers [lreplace $answers $x $x $tmp]
}
}
if {$heden==0} {
lappend answers [list $chan $params]
reply $chan "aldim baba cevabini ama dilersen degi\$tir bilmiyorum.."
} else {
reply $chan "degi\$tirdim baba cevabini"
}
}
}
"c" {
if {$question==""} {
reply $chan "soru yok? hangi soruya aloo?"
} elseif {$qtime!=0} {
reply $chan "acele etme dur bi sure bitsin"
} else {
global stopping
set stopping 0
kus "\x02 cevaplar secildi.\x02"
kus "ama once dilerseniz yari\$macilarimiz neler demi\$ gorelim.."
kus "sorumuz '$question' idi ve yari\$macilarimiz \$oyle cevapladilar bunu:"
for {set a 0} {$a<[llength $answers]} {incr a} {
set tmp [lindex $answers $a]
kus "[lindex $tmp 0]\ \"\x02[lindex $tmp 1]\x02\" [lindex $cevaps $a]"
}
if {[llength $params] > 1} {
kus "evet elimdeki tablodan goruyorum ki birden fazla dogru cevap veren war"
set str "kendilerini tebrik ediyoruz: \x02"
for {set x 0} {$x < [llength $params]} {incr x} {
set index [lindex $params $x]
if {$index!=0} {
set selected [lindex $answers [expr $index-1]]
set str "$str [lindex $selected 0]"
}
}
set str "$str \x02helall!"
kus $str
} else {
kus "ve dogru cevabi veren..."
if {$params!=0} {
kus "\x02[lindex [lindex $answers [expr $params-1]] 0]\x02 wooooaauv"
} else {
kus "maalesef hickimse :( tuh yaziklar olsun"
}
}
unset answers
set answers {}
set question ""
set qtime 0
}
}
}
}
}
kus "merhaba ben cilgin botunuz gondol yeni resetlendim"
kus "bundan boyle yari\$malarda hep yaninizda olacagim"
kus "bana ozelden `help` yazarak ne zike derman oldugumu ozumseyebilirsiniz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment