;**** Date: 07-18-2001
;**** Programmer: JQ (jq9@hotmail.com)
;**** Purpose: A team trivia bot. This is modified from the Jotrivia bot addon. Converted
;**** to a team trivia bot addon and fixed minor bugs and annoyances.
;**** http://www.geocities.com/teamtriviabot
;******************************************************************************
;**** Events
;******************************************************************************
on *:LOAD: {
if ($version < 5.9) {
echo $colour(info) -ae *** Team Trivia Bot requires mIRC v5.9 or higher. Visit http://www.mirc.com/ for the latest version of mIRC.
unload -rs teamtrivia.mrc
halt
}
else { echo $colour(info) -ae *** Team Trivia Bot loaded. }
}
on *:JOIN:%tt.triv.chan:{
if (%tt.advertise == on) {
if (%tt.trivia == off) { .notice 15$nick Welcome $nick $+ . Team trivia is currently off, to start game type !trivon }
else {
.notice $nick 13Welcome $nick $+ .
.notice $nick 13Type 7!help 13for a list of team trivia commands
}
}
}
on *:START:{
set %tt.triv.status on
set %tt.trivia off
set %tt.in.question no
set %tt.flag.trivoff yes
set %tt.triv.chan
set %tt.advertise off
set %tt.pause.time 20
set %tt.num.corrupt 0
if (%tt.hint.len !isnum) { set %tt.hint.len 3 }
if (%tt.!hint.status != on) {
if (%tt.!hint.status != off) { set %tt.!hint.status on }
}
if (%tt.hint.status != on) {
if (%tt.hint.status != off) { set %tt.hint.status on }
}
if (%tt.question.time !isnum) {
set %tt.question.time 60
set %tt.hint.time 15
}
unset.ttvars
}
on *:TEXT:!helptrivia:%tt.triv.chan:{
if ($me != %tt.botop) || (%tt.triv.status == off) { halt }
showhelp $nick
}
on *:TEXT:!repeat:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if (%tt.in.question == yes) { msg %tt.triv.chan 11Question: 15 %tt.question }
}
on *:TEXT:!hint:%tt.triv.chan: {
if ($me != %tt.botop) { halt }
if (%tt.trivia == on) {
if (%tt.in.question == yes) {
if ($istok(%tt.blue.team,$nick,44)) || ($istok(%tt.red.team,$nick,44)) {
if (%tt.len.ans > %tt.hint.len) {
if (%tt.!hint.status == on) { userhint }
}
}
}
else {
.notice $nick Can't give hint now, question has ended
}
}
}
on *:TEXT:!trivon*:%tt.triv.chan: {
if ($me != %tt.botop) || (%tt.triv.status == off) { halt }
if (%tt.trivia == off) {
if (($2 != $null) && ($2 isnum)) { set %tt.win.score $2 }
else { set %tt.win.score 10 }
%tt.red.team = ""
%tt.blue.team = ""
%tt.red.score = 0
%tt.blue.score = 0
%tt.trivia = on
msg %tt.triv.chan 15Team trivia starts in 1 minute, type 12!join blue 1or 4!join red 1to join a team
msg #orb_bot-data User: $nick - Started Team Trivia game using topic " $+ %tt.topic $+ " at $asctime(yyyy/mm/dd-HH:nn:ss) EST
.timerstart 1 60 trivon
}
}
on *:TEXT:!trivoff:%tt.triv.chan: {
if ($me != %tt.botop) { halt }
if (%tt.trivia == on) {
%tt.flag.trivoff = yes
if (%tt.in.question == yes) { msg %tt.triv.chan 15Trivia will be disabled after question. }
else { trivoff }
}
}
on *:TEXT:!join*:%tt.triv.chan:{
if (%tt.trivia == on) { join.team $nick $1- }
}
on *:TEXT:!teams:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if (%tt.trivia == on) { display.teams }
}
on *:TEXT:!score:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if (%tt.trivia == on) { show.score }
}
on *:TEXT:!timer*:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if (($2 != $null) && ($2 isnum)) {
if ($istok(%tt.blue.team,$nick,44)) || ($istok(%tt.red.team,$nick,44)) {
%tt.pause.time = $2
msg %tt.triv.chan Time between questions has been set to %tt.pause.time seconds
}
}
}
on *:TEXT:!ttbot*:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if ($2 != $null) && ($nick isop %tt.triv.chan) {
if ($2 == on) {
if (%tt.triv.status == off) {
set %tt.triv.status on
init
.msg $nick Trivia bot has been turned on.
}
}
else {
if ($2 == off) && (%tt.triv.status == on) {
set %tt.triv.status off
trivoff
.msg $nick Trivia bot has been turned off.
}
}
}
}
on *:TEXT:!ttad*:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if ($2 != $null) && ($nick isop %tt.triv.chan) {
if ($2 == on) {
set %tt.advertise on
.msg $nick Advertisements have been turned on. }
if ($2 == off) {
set %tt.advertise off
.msg $nick Advertisements have been turned off.
}
}
}
on *:TEXT:!autohint*:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if ($2 != $null) && ($nick isop %tt.triv.chan) {
if ($2 == on) {
set %tt.hint.status on
.msg $nick Auto hints have been turned on.
}
if ($2 == off) {
set %tt.hint.status off
.msg $nick Auto hints have been turned off.
}
}
}
on *:TEXT:!hintlen*:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if ($2 != $null) && ($nick isop %tt.triv.chan) {
if ($2 isnum) {
set %tt.hint.len $2
.msg $nick Hint length has been limited to %tt.hint.len $+ .
}
}
}
on *:TEXT:!hintcmd*:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if ($2 != $null) && ($nick isop %tt.triv.chan) {
if ($2 == on) {
set %tt.!hint.status on
.msg $nick !hint command has been turned on.
}
if ($2 == off) {
set %tt.!hint.status off
.msg $nick !hint command has been turned off.
}
}
}
on *:TEXT:!qtime*:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if ($2 != $null) && ($nick isop %tt.triv.chan) {
if ($2 isnum) {
if (%tt.trivia == off) {
set %tt.question.time $2
set %tt.hint.time $calc(%tt.question.time / 4)
.msg $nick Question time has been set to %tt.question.time seconds.
}
else { .msg $nick Cannot set the question time while the game is running. }
}
}
}
on *:NICK:{
if (%tt.trivia == on) {
if ($istok(%tt.blue.team,$nick,44)) {
%tt.blue.team = $reptok(%tt.blue.team,$nick,$newnick,1,44)
}
if ($istok(%tt.red.team,$nick,44)) {
%tt.red.team = $reptok(%tt.red.team,$nick,$newnick,1,44)
}
}
}
on *:TEXT:*:%tt.triv.chan:{
if ($me != %tt.botop) { halt }
if (%tt.trivia == on) && (%tt.in.question == yes) {
if ($istok(%tt.blue.team,$nick,44)) || ($istok(%tt.red.team,$nick,44)) {
parsetry $nick $1-
}
}
}
;******************************************************************************
;**** Aliases
;******************************************************************************
alias display.teams {
var %tt.b = $numtok(%tt.blue.team,44)
var %tt.r = $numtok(%tt.red.team,44)
var %tt.n = 2
var %tt.blue.names
var %tt.red.names
%tt.blue.names = $gettok(%tt.blue.team,1,44)
while (%tt.n <= %tt.b) {
if (%tt.n == %tt.b) { %tt.blue.names = %tt.blue.names $+ $chr(44) $+ $chr(32) and $gettok(%tt.blue.team,%tt.n,44) }
else { %tt.blue.names = %tt.blue.names $+ $chr(44) $+ $chr(32) $gettok(%tt.blue.team,%tt.n,44) }
inc %tt.n
}
msg %tt.triv.chan 12Blue Team: 1 %tt.blue.names
%tt.n = 2
%tt.red.names = $gettok(%tt.red.team,1,44)
while (%tt.n <= %tt.r) {
if (%tt.n == %tt.r) { %tt.red.names = %tt.red.names $+ $chr(44) $+ $chr(32) and $gettok(%tt.red.team,%tt.n,44) }
else { %tt.red.names = %tt.red.names $+ $chr(44) $+ $chr(32) $gettok(%tt.red.team,%tt.n,44) }
inc %tt.n
}
msg %tt.triv.chan 4Red Team : 1 %tt.red.names
}
alias show.score {
msg %tt.triv.chan 12Blue Team: 1 %tt.blue.score
msg %tt.triv.chan 4Red Team : 1 %tt.red.score
}
alias join.team {
if ($3 == blue) {
if ($istok(%tt.red.team,$1,44)) {
%tt.red.team = $remtok(%tt.red.team,$1,1,44)
.msg $1 1You have been removed from the 4red 1team.
}
%tt.blue.team = $addtok(%tt.blue.team,$1,44)
.msg $1 1You have been added to the 12blue 1team.
}
if ($3 == red) {
if ($istok(%tt.blue.team,$1,44)) {
%tt.blue.team = $remtok(%tt.blue.team,$1,1,44)
.msg $1 1You have been removed from the 12blue 1team.
}
%tt.red.team = $addtok(%tt.red.team,$1,44)
.msg $1 1You have been added to the 4red 1team.
}
}
alias newquestion {
.timerhint off
.timerkill off
.timernextquestion off
unset %tt.question
unset %tt.answer
unset %tt.len.ans
getquestionnum
unset %tt.visible.char
parsequestion
showanswer Answer:
.timerhint 3 %tt.hint.time timehint
.timerkill 1 %tt.question.time killquestion
%tt.time.hint.count = 0
%tt.in.question = yes
}
alias parsequestion {
var %tt.n = 1
var %tt.mystr = $read(" $+ $scriptdir $+ q.txt $+ ", %tt.good.line)
var %tt.lenstr = $len(%tt.mystr)
var %tt.myans = $replace(%tt.mystr,$chr(32),$chr(160))
while ($mid(%tt.mystr,%tt.n,1) != |) && (%tt.n < %tt.lenstr) {
inc %tt.n
}
if (%tt.n == %tt.lenstr) || (%tt.mystr == $null) {
echo -a 2**2*12* 1Question file corrupt. Line = %tt.mystr
write " $+ $scriptdir $+ corrupt.txt $+ " %tt.good.line - %tt.mystr
inc %tt.num.corrupt
if (%tt.num.corrupt < 5) { newquestion }
else {
msg %tt.triv.chan Trivia question file is corrupt. Exiting.
%tt.num.corrupt = 0
trivoff
}
return
}
set %tt.answer $mid(%tt.myans,$calc(%tt.n + 1),$calc(%tt.lenstr - %tt.n))
%tt.len.ans = $len(%tt.answer)
set %tt.question $left(%tt.mystr,$calc(%tt.n - 1))
showquestion
}
alias showquestion msg %tt.triv.chan 11Question: 15 %tt.question
alias showanswer {
var %tt.n = 1
var %tt.l
var %tt.ans
while (%tt.n <= %tt.len.ans) {
%tt.l = $mid(%tt.answer,%tt.n,1)
if (%tt.l isalnum) && ($istok(%tt.visible.char,%tt.n,46) == $false) { %tt.l = * }
%tt.ans = %tt.ans $+ %tt.l
inc %tt.n
}
if (%tt.previous.ans != %tt.ans) { msg %tt.triv.chan 11 $+ $1- 12 %tt.ans }
%tt.previous.ans = %tt.ans
}
alias parsetry {
var %tt.n = 1
var %tt.try = $replace($2-,$chr(32),$chr(160))
var %tt.lentry = $len(%tt.try)
var %tt.toklist
if (%tt.try == %tt.answer) {
msg %tt.triv.chan 1Correct answer by $1 :7 %tt.answer
if ($istok(%tt.blue.team,$1,44)) { %tt.blue.score = %tt.blue.score + 1 }
if ($istok(%tt.red.team,$1,44)) { %tt.red.score = %tt.red.score + 1 }
if (%tt.blue.score == %tt.win.score) {
msg %tt.triv.chan 7Blue team wins %tt.blue.score to %tt.red.score
trivoff
}
if (%tt.red.score == %tt.win.score) {
msg %tt.triv.chan 7Red team wins %tt.red.score to %tt.blue.score
trivoff
}
show.score
%tt.misses = 0
pausenew
return
}
if (%tt.len.ans < %tt.lentry) { %tt.lentry = %tt.len.ans }
while (%tt.n <= %tt.lentry) {
if ($mid(%tt.answer,%tt.n,1) == $mid(%tt.try,%tt.n,1)) {
%tt.visible.char = $addtok(%tt.visible.char,%tt.n,46)
}
inc %tt.n
}
showanswer Answer:
}
alias userhint {
var %tt.threecount = 1
var %tt.n = 1
var %tt.l
if ($count(%tt.previous.ans,*) > %tt.hint.len) {
if ($istok(%tt.visible.char,hint,46) == $false) {
%tt.visible.char = $addtok(%tt.visible.char,hint,46)
while (%tt.n <= %tt.len.ans) && (%tt.threecount <= 3) {
%tt.l = $mid(%tt.answer,%tt.n,1)
if ($istok(%tt.visible.char,%tt.n,46) == $false) && (%tt.l isalnum) {
%tt.visible.char = $addtok(%tt.visible.char,%tt.n,46)
inc %tt.threecount
}
inc %tt.n
}
showanswer Hint:
}
}
}
alias timehint {
var %tt.n
var %tt.l
%tt.time.hint.count = $calc(%tt.time.hint.count + %tt.hint.time)
if (%tt.hint.status == off) || ($count(%tt.previous.ans,*) <= %tt.hint.len) { return }
%tt.n = 1
while (%tt.n <= %tt.len.ans) {
%tt.l = $mid(%tt.answer,%tt.n,1)
if ($istok(%tt.visible.char,%tt.n,46) == $false) && (%tt.l isalnum) {
%tt.visible.char = $addtok(%tt.visible.char,%tt.n,46)
%tt.n = $calc(%tt.len.ans + 1)
}
else { inc %tt.n }
}
showanswer %tt.time.hint.count Second Hint:
}
alias killquestion {
msg %tt.triv.chan 15Time's up! The answer is:7 %tt.answer
show.score
inc %tt.misses
pausenew
}
alias pausenew {
%tt.in.question = no
.timerhint off
.timerkill off
if (%tt.misses > 9) {
%tt.flag.trivoff = yes
msg %tt.triv.chan 15 10 misses in a row. Disabling Trivia
}
if (%tt.flag.trivoff == yes) { trivoff }
else {
.timernextquestion 0 %tt.pause.time newquestion
msg %tt.triv.chan 15Next question in %tt.pause.time seconds
}
}
alias trivoff {
%tt.trivia = off
%tt.in.question = no
unset.ttvars
.timerstart off
.timerhint off
.timerkill off
.timernextquestion off
if (%tt.triv.status == on) { msg %tt.triv.chan 15Trivia disabled. Use !trivon to restart Trivia. }
else { msg %tt.triv.chan 15Team Trivia is shutting down. }
if (%tt.triv.status == on) { halt }
}
alias trivon {
var %tt.questionpath = $scriptdir $+ q.txt
%tt.trivia = on
%tt.flag.trivoff = no
%tt.misses = 0
if ($isfile(%tt.questionpath) == $false) {
msg %tt.triv.chan 2**2*12* 1Cannot run, question file is not present.
%tt.triv.status = off
trivoff
return
}
%tt.total.questions = $read(" $+ $scriptdir $+ q.txt $+ ", 0)
if (%tt.total.questions == 0) {
echo -a 2**2*12* 1Question file format incorrect
return
}
msg %tt.triv.chan Team Trivia Is Starting
newquestion
}
alias getquestionnum {
var %tt.templine = unused
var %tt.usednumsfile = $scriptdir $+ usednums.txt
%tt.good.line = $rand(1,%tt.total.questions)
if ($lines(%tt.usednumsfile) >= %tt.total.questions) || ($isfile(%tt.usednumsfile) == $false) {
%tt.good.line = $rand(1,%tt.total.questions)
echo -a 2**2*12* 1New numsfile
write -c " $+ $scriptdir $+ usednums.txt $+ " %tt.good.line $+ .
}
else {
while (%tt.templine != $null) {
%tt.templine = $read(" $+ $scriptdir $+ usednums.txt $+ ", s, %tt.good.line $+ .)
if (%tt.templine != $null) {
inc %tt.good.line
if (%tt.good.line > %tt.total.questions) { %tt.good.line = 1 }
}
}
write " $+ $scriptdir $+ usednums.txt $+ " %tt.good.line $+ .
}
}
alias checkcorrupt {
var %tt.n = 1
var %tt.nq = $read(" $+ $scriptdir $+ q.txt $+ ", 0)
var %tt.ts
var %tt.i
echo -a 2**2*12* 1Scanning - may take awhile
echo -a 2**2*12* 1Total questions - %tt.nq
while (%tt.nq > %tt.n) {
%tt.ts = $read(" $+ $scriptdir $+ q.txt $+ ", %tt.n)
if (%tt.ts == $null) { echo -a 2**2*12* 1Line %tt.n is empty }
else {
if (| !isin %tt.ts) || ($right(%tt.ts,1) == |) { echo -a 2**2*12* 1Invalid format line %tt.n : %tt.ts }
}
inc %tt.n
%tt.i = $calc(%tt.n / 100)
if (%tt.i == $int(%tt.i)) { echo -a 2**2*12* 1Scanned %tt.n questions }
}
echo -a 2**2*12* 1Scan complete
}
alias showhelp {
.msg $1 5!trivon <# of questions> 1- activates the trivia bot if it is not already running.
.msg $1 1<# of questions> defaults to 10 if not specified.
.msg $1 5!trivoff 1- turns off the trivia bot if it is running.
if (%tt.!hint.status == on) {
.msg $1 5!hint 1- displays a three letter hint to the channel.
}
.msg $1 5!repeat 1- will redisplay the current question.
.msg $1 5!join blue 1- join the blue team.
.msg $1 5!join red 1- join the red team.
.msg $1 5!teams 1- displays the members of each team.
.msg $1 5!score 1- displays the current team scores.
.msg $1 5!timer <# of seconds> 1- sets the number of seconds between questions
.msg $1 12-------------------------2---------------------10------------------14---------------15------------
if ($nick isop %tt.triv.chan) {
.msg $1 5!ttbot <on/off> 1- Turn the bot on or off
.msg $1 5!ttad <on/off> 1- Turn advertisements on or off
.msg $1 5!autohint <on/off> 1- Turn auto hints on or off
.msg $1 5!hintcmd <on/off> 1- Turn the !hint command on or off
.msg $1 5!qtime <# of seconds> 1- Set the length of time to answer a question
.msg $1 5!hintlen <# of chars> 1- Do not allow hint to display last <# of chars> characters
.msg $1 12-------------------------2---------------------10------------------14---------------15------------
}
.msg $1 To answer a question, simply type the answer in the channel window.
.msg $1 You must join a team for the bot to recognize your answers.
.msg $1 Answers are not case sensitive.
}
alias init {
.timerhint off
.timerkill off
.timernextquestion off
set %tt.botop $me
set %tt.trivia off
set %tt.in.question no
set %tt.flag.trivoff no
set %tt.previous.ans ""
}
alias unset.ttvars {
unset %tt.red.team
unset %tt.blue.team
unset %tt.red.score
unset %tt.blue.score
unset %tt.question
unset %tt.answer
unset %tt.len.ans
unset %tt.good.line
unset %tt.visible.char
unset %tt.time.hint.count
unset %tt.misses
unset %tt.win.score
unset %tt.total.questions
unset %tt.previous.ans
}
;******************************************************************************
;**** Menus
;******************************************************************************
menu channel {
Team Trivia
.
.Configure:dialog -m trivia trivia
.-
.Scan question file:checkcorrupt
}
;******************************************************************************
;**** Dialogs
;******************************************************************************
dialog trivia {
title "Team Trivia Setup"
size -1 -1 150 100
option dbu
text "Channel:",1,5 5 40 11,left
edit "",2,38 3 105 11,autohs,result
text "Bot Enabled:",3,5 20 40 11,left
radio "Yes",4,44 19 20 11, group
radio "No",5,70 19 20 11
text "Advertise:",6,5 30 40 11,left
radio "Yes",7,44 29 20 11, group
radio "No",8,70 29 20 11
text "Timed Hints:",9,5 40 40 11,left
radio "Yes",10,44 39 20 11, group
radio "No",11,70 39 20 11
text "!hint Enabled:",14,5 50 40 11,left
radio "Yes",15,44 49 20 11, group
radio "No",16,70 49 20 11
text "Question Time (sec):",12,5 62 50 11,left
edit "",13,60 60 40 11,autohs,result
text "Do not allow hint to display last",17,5 75 80 11,left
edit "",18,80 73 15 10,autohs,result
text "characters",19,97 75 30 11,left
button "Accept",100,48 87 30 11,ok
button "Cancel",101,80 87 30 11,cancel
}
on 1:DIALOG:trivia:init:0: {
if (%tt.triv.status == on) { did -a trivia 2 %tt.triv.chan }
else { did -a trivia 2 $active }
if (%tt.triv.status == on) { did -c trivia 4 }
else { did -c trivia 5 }
if (%tt.advertise == on) { did -c trivia 7 }
else { did -c trivia 8 }
if (%tt.hint.status == on) { did -c trivia 10 }
else { did -c trivia 11 }
did -a trivia 13 %tt.question.time
if (%tt.trivia == on) { did -m trivia 13 }
if (%tt.!hint.status == on) { did -c trivia 15 }
else { did -c trivia 16 }
did -a trivia 18 %tt.hint.len
}
on 1:DIALOG:trivia:sclick:100: {
var %tt.first.char = ""
var %tt.channel.name
%tt.first.char = $mid($did(trivia,2).text,1,1)
if (%tt.first.char != $chr(35)) { %tt.channel.name = $chr(35) $+ $did(trivia,2).text }
else { %tt.channel.name = $did(trivia,2).text }
if (%tt.channel.name ischan) { set %tt.triv.chan %tt.channel.name }
else { echo -a **** %tt.channel.name is not an active channel. Channel not set. }
if ($did(trivia,4).state == 1) {
if (%tt.triv.status == off) {
set %tt.triv.status on
init
}
}
else {
if (%tt.triv.status == on) {
set %tt.triv.status off
trivoff
}
}
if ($did(trivia,7).state == 1) { set %tt.advertise on }
else { set %tt.advertise off }
if ($did(trivia,10).state == 1) { set %tt.hint.status on }
else { set %tt.hint.status off }
if ($did(trivia,13).text isnum) && (%tt.trivia == off) {
set %tt.question.time $did(trivia,13).text
set %tt.hint.time $calc(%tt.question.time / 4)
}
if ($did(trivia,15).state == 1) { set %tt.!hint.status on }
else { set %tt.!hint.status off }
if ($did(trivia,18).text isnum) { set %tt.hint.len $did(trivia,18).text }
}
ctcp 1:version:?:/ctcpreply $nick VERSION TeamTrivia by JQ (jq9@hotmail.com)