· 6 years ago · Jul 29, 2019, 06:36 PM
1#####################################################################
2# Author: Graeme Donaldson #
3# IRC: Souperman #eggdrop @ Undernet #
4# Translated by: Horatiu #
5# IRC: Nick:mod - rec - led @ Undernet @ IRC-Hispano #
6# Canales: #Trivias #Radio #Help en la Red IRC-Hispano #
7# WWW: www.help.sufx.net Mail: led@mail-online.dk #
8# Version: EsTrivial 1.0 #
9#####################################################################
10# Sobre el TCL: #
11# Es el primer TCL (Trivial) en Castellano, tiene mas de 68 000 #
12# preguntas todas en Castellano. #
13# El TCL tambien tiene una opción para generar las estatisticas en #
14# tu pagina web :). #
15# Si necesitas algun tipo de ayuda sobre la instalación ya sabes #
16# donde me puedes encontrar. #
17# Actualizada por sedition /server irc.cafechat.org emial: urquizoandrade@gmail.com #
18# me encontraras en chatzona canal #tcl y DALnet canal #tcls #
19#####################################################################
20# Apuntes de instalación: #
21# 1. Crear una carpeta en el directorio donde se encuentra tu egg. #
22# crear la nueva carpeta con el nombre trivial dentro de tu eggdrop #
23# ej: /home/irc/eggdrop/trivial, aqui tienes q meter el archivo #
24# con las preguntas #
25# 2. Mete el tcl EStrivial.tcl en: /home/irc/eggdrop/scripts/ #
26# 3. Añade esta linea:
27# source scripts/EStrivial.tcl en eggdrop.conf #
28# 4. Escribe !Rehash en el canal #
29# 5. Escribe !jugar en el canal donde tienes programado en Trivial #
30# y a jugar ;)
31#####################################################################
32# Known bugs: #
33# The generated stats are still in english. I will translate then #
34# as soon as possible! #
35#####################################################################
36# Commands: #
37# The default channel commands are: #
38# #
39# COMMAND FLAGS DESCRIPTION #
40# !pista -|- gives another hint to the current question. #
41# !saltar -|- skips the question and selects a new one. #
42# !jugar -|- starts the game (if it's not running). #
43# !parar -|- stops the game (if it's running). #
44# !top10 -|- shows the top 10 scores on channel. #
45# si quieres que solo los admin paren el juego dejalo en o|o #
46# The default /msg commands (and flags required for their use) are: #
47# #
48### comandos adicionales ###
49# para ver tu puntuacion #
50# /msg el-nick-de-tu-bot puntuacion #
51# para ver la lista de concursantes #
52# /msg el-nick-de-tu-bot concursante #
53# informar errores
54# /msg el-nick-de-tu-bot errores aqui.especifica.el.numero.de.la.pregunta #
55# para ver las reglas #
56# /msg el-nick-de-tu-bot reglas #
57# COMMAND FLAGS DESCRIPTION #
58# ayuda n/a gives help. #
59# erores n/a report errors in questions/answers. #
60# reset m|m reset score table. #
61# reglas n/a show the channel's rules (customisable). #
62# puntuacion n/a looks up someone's score. #
63# concursante n/a tells you who is ranked one above you. #
64#####################################################################
65#
66# Please SET THE SCRIPT below!
67# WARNING!!!! If you will not set the ENTIRE script your eggdrop will DIE!
68# Thank you!
69#
70# The full path to the file containing the questions and answers.
71# The account the bot runs on must have read access to this file.
72# directorio ejemplo en mi caso y mi loging se llame eggdrop "/home/eggdrop/trivial/preguntas"
73set tgqdb "/home/eggdrop/trivial/preguntas"
74
75# The character that seperates the question and the answer in the
76# question/answer file.
77set tgqdbsep "*"
78
79# What you set here defines how the bot expects the question/answer
80# pairs to be arranged.
81# If set to 1, bot expects lines in the format:
82# question<seperator>answer
83# If set to 0, bot expects lines in the format:
84# answer<seperator>question
85set tgqdbquestionfirst 1
86
87# The full path to the file which tracks the scores. The account
88# the bot runs on must have read & write access to this file. If
89# the file does not exist, it will be created when needed.
90set tgscf "/home/eggdrop/trivial/puntuacion"
91
92# How to send error reports. Set to 1 to send error report to an
93# e-mail address of your choice, or 0 to record errors in a file.
94# Sending via e-mail requires that the bot have access to the "mail"
95# program. If the bot doesn't have access to this program (e.g. if
96# you're running the bot on the Windows platform), then set this to
97# 0 to have errors recorded in a file.
98set tgerrmethod 1
99
100# The full path to the file which records error reports. The
101# account the bot runs on must have read & write access to this
102# file. If the file does not exist, it will be created when needed.
103set tgerrfil "/home/eggdrop/trivial/fallos"
104
105# The e-mail address to send error reports to.
106# email donde se enviaran los errores reportados
107set tgerremail "led@mail-online.dk"
108
109# If error reports are sent via e-mail, where will the bot create
110# a temp file? /tmp is usually a good idea.
111set tgerrmailtmp "/home/eggdrop/tmp"
112
113# The full path to the file which the bot will use to generate
114# an HTML info page. The account the bot runs on must have read
115# & write access to this file. If the file does not exist, it will
116# be created when needed.
117set tghtmlfile "/home/eggdrop/trivial/public_html"
118
119# How often (in seconds) does the html file get updated. Set to 0
120# to disable HTML page.
121set tghtmlrefresh 0
122
123# The font to use on the html page.
124set tghtmlfont "verdana,helvetica,arial"
125
126# The name of the channel where the game will be played. The game
127# can only be played on one channel.
128# canal donde estara activa la trivia
129set tgchan "#mundo"
130
131# How many points to give a person for a correctly answered
132# question.
133set tgpointsperanswer 1
134
135# The maximum number of hints to give before the question 'expires'
136# and the bot goes on to another one. This EXCLUDES the first hint
137# given as the question is asked (i.e. the hint which shows no letters,
138# only placeholders).
139set tgmaxhint 5
140
141# Should the bot show the question on each hint (1) or only on the first (0)?
142set tgalwaysshowq 1
143
144# Show questions in all CAPS (1) or not (0)?
145set tgcapsquestion 0
146
147# Show answers in all CAPS (1) or not (0)?
148set tgcapsanswer 0
149
150# Show hints in all CAPS (1) or not (0)?
151set tgcapshint 0
152
153# The minimum number of correct answers in a row by one person which
154# puts them on a winning streak. Setting this to 0 will disable the
155# winning streak feature.
156set tgstreakmin 3
157
158# The number of missed (i.e. unanswered, not skipped) questions to allow
159# before automatically stopping the game. Setting this to 0 will cause the
160# game to run until somebody uses the stop command, or the bot dies, gets
161# killed, pings out, or whatever.
162set tgmaxmissed 0
163
164# The character to use as a placeholder in hints.
165set tghintchar "*"
166
167# The time in seconds between hints.
168# El tiempo en segundos entre pistas.
169set tgtimehint 20
170
171# The time in seconds between a correct answer, 'expired' or skipped question
172# and the next question being asked.
173# tiempo en segundos cuando la pregunta haya expirado o concluido
174set tgtimenext 10
175
176# Phrases to use at random when someone answers a question correctly. This must
177# be a TCL list. If you don't know what that means, stick to the defaults.
178set tgcongrats [list "Enhorabuena" "Bien.." "Bravo" "Asi se hace...." "Tiene mucha suerte.." "Correcto!" "Enseñalos como se hace" "Madre mia que cerrebro tiene" "BuUUUmMMM q bueno" "...pfff esta jugando bien este" "zzZzZZZzzzzZZZ el Unico q sabe contestar bien es" "eres el mejor" "jejeje, q inteligente" "vamos q los demas no saben nada, sigue asi" "vayaaa..,perfecto" "dale caña" "mmmbien.." "juass q fuerte" "sigue asi"]
179
180# Phrases to use when the question has 'expired'. Must also be a TCL list.
181set tgnobodygotit [list "Nadie ha encontrado la respuesta correcta." "Hello? Hay alguien en Casa?" "Venga q no es tan dificil!" "Las preguntas son Dificiles?" "Estoy hablando solo?" "Asi no se pueden ganar Puntos!" "....ZzzzZZZZ"]
182
183# Phrases to use when the question expired and there's another one coming up.
184# Yep, you guessed it... another TCL list.
185set tgtrythenextone [list "Veamos si saben contestar a la siguente..." "Prepararos para la siguente pregunta..." "Pasamos a la siguente pregunta..." "La siguente pregunta es muy pero q muy facil..." "Paso a la siguente pregunta..." "Algunos de ustedes saben jugar al trivial pero otros..mmbuah"]
186
187# Will the bot calculate the time it took to get the correct
188# answer (1) or not (0)? (requires TCL 8.3 or higher).
189set tgtimeanswer 1
190
191# Will the bot show the correct answer if nobody gets it (1) or not (0)?
192set tgshowanswer 1
193
194# When someone answers a question, will the bot show just that person's score (0)
195# or will it show all players' scores (1) (default). This is useful in channels with
196# a large number (>20) players.
197set tgshowallscores 0
198
199# Use bold codes in messages (1) or not (0)?
200set tgusebold 0
201
202# Send private messages using /msg (1) or not (0)?
203# If set to 0, private messages will be sent using /notice
204set tgpriv2msg 0
205
206# Word to use as /msg command to give help.
207# e.g. set tgcmdhelp "helpme" will make the bot give help when someone
208# does "/msg <botnick> ayuda"
209set tgcmdhelp "ayuda"
210
211# Channel command used to start the game.
212# comando para iniciar el juego
213set tgcmdstart "!jugar"
214
215# Flags required to be able to use the start command.
216set tgflagsstart "-|-"
217
218# Channel command used to stop the game.
219# comando para parar el juego
220set tgcmdstop "!parar"
221
222# Flags required to be able to use the stop command.
223set tgflagsstop "-|-"
224
225# Channel command used to give a hint.
226# comando para dar pistas en el juego
227set tgcmdhint "!pista"
228
229# Flags required to be able to use the hint command.
230set tgflagshint "-|-"
231
232# Disable the !sugestie command x seconds after someone uses it. This
233# prevents accidental double hints if two people use the command in
234# quick succession.
235set tgtempnohint 10
236
237# Channel command used to skip the question.
238# comando para ir a la siguiente pregunta en el juego
239set tgcmdskip "!saltar"
240
241# Flags required to be able to use the skip command.
242set tgflagsskip "-|-"
243
244# Channel command for showing the top 10 scores.
245set tgcmdtop10 "!top10"
246
247# Flags required to use the top 10 command.
248set tgflagstop10 "-|-"
249
250# /msg command used to reset scores.
251set tgcmdreset "reinicio"
252
253# Flags required to be able to use the reset command.
254set tgflagsreset "m|m"
255
256# Require password for resetting scores?
257# If enabled, you must use /msg bot reset <password> to reset scores.
258# The password is the one set by a user using '/msg bot pass'.
259set tgresetreqpw 1
260
261# /msg command for looking up somebody's score. ejemplo /msg el-nick-de-tu-bot puntuacion
262set tgcmdlookup "puntuacion"
263
264# /msg command for looking up your target.
265# (i.e. the person ranked one higher than you).
266set tgcmdtarget "concursante"
267
268# /msg command for reporting errors in questions and/or answers.
269set tgcmderror "errores"
270
271# /msg command to show channel's rules.
272set tgcmdrules "reglas"
273
274# Channel's rules.
275set tgrules "No Spam, No Flood, Sin trampas, Sin Google pinche tramposo, Juega y respeta a tu adversario, Comportate bien con los usuarios que estan jugando. Si no respetas las Reglas seras pateado! :-)"
276
277# Number of minutes between reminders of how to report errors.
278set tgerrremindtime 15
279
280# COLOURS
281# The colour codes used are the same as those used by mIRC:
282# 00:white 01:black 02:dark blue 03:dark green
283# 04:red 05:brown 06:purple 07:orange
284# 08:yellow 09:light green 10:turquoise 11:cyan
285# 12:light blue 13:magenta 14:dark grey 15:light grey
286#
287# Always specify colour codes as two digits, i.e. use "01" for
288# black, not "1".
289# You can specify a background colour using "00,04" (white text
290# on red background).
291# To disable a colour, use "".
292# Note that disabling some colours but not others may yield
293# unexpected results.
294
295set tgcolourstart "03" ;#Game has started.
296set tgcolourstop "04" ;#Game has stopped.
297set tgcolourskip "10" ;#Question has been skipped.
298set tgcolourerr "04" ;#How to report errors.
299set tgcolourmiss "10" ;#Nobody answered the question.
300set tgcolourqhead "04" ;#Question heading.
301set tgcolourqbody "12" ;#Question text
302set tgcolourhint "03" ;#Hint.
303set tgcolourstrk "12" ;#Person is on a winning streak.
304set tgcolourscr1 "04" ;#Score of person in first place.
305set tgcolourscr2 "12" ;#Score of person in second place.
306set tgcolourscr3 "03" ;#Score of person in third place.
307set tgcolourrset "04" ;#Scores have been reset.
308set tgcolourstend "12" ;#Winning streak ended.
309set tgcolourmisc1 "06" ;#Miscellaneous colour #1.
310set tgcolourmisc2 "04" ;#Miscellaneous colour #2.
311
312# DELETE THE FOLOWING LINE! If not, your botwill die!
313#die "You didn't set trivia.tcl"
314
315# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
316# #
317# Any editing done beyond this point is done at your own risk! #
318# #
319# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
320#Misc checks & var initialisations
321set tgver "1.0"
322set tgrel "release"
323if {[info tclversion]<8.2} {
324 putlog "\002[file tail [info script]]\002 failed to load: in order to use this script, eggdrop needs to be compiled to use tcl 8.2 or higher (recommended: latest stable version)."
325 return
326}
327if {$tgtimeanswer==1&&[info tclversion]<8.3} {
328 putlog "\002[file tail [info script]]\002 warning: timing of answers has been automatically disabled. this feature requires tcl 8.3 or higher."
329 set tgtimeanswer 0
330}
331if {![info exists alltools_loaded]||$allt_version<205} {
332 putlog "\002[file tail [info script]]\002 failed to load: please load alltools.tcl v1.14 or higher (available with eggdrop 1.6.13 or higher) before attempting to load this script."
333 return
334}
335if {[utimerexists tghtml]!=""} {killutimer $tghtmlrefreshtimer}
336if {$tghtmlrefresh>0} {
337 set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
338}
339if {![file exists $tgqdb]} {
340 putlog "\002[file tail [info script]]\002 failed to load: $tgqdb does not exist."
341 return
342}
343if {[llength [split $tgchan]]!=1} {
344 putlog "\002[file tail [info script]]\002 failed to load: too many channels specified."
345 return
346}
347if {![info exists tgplaying]} {
348 set ctcp-version "${ctcp-version} (with rotrivia.tcl $tgver ($tgrel) from led@mail-online.dk)"
349 set tgplaying 0
350}
351if {![info exists tghintnum]} {set tghintnum 0}
352if {![info exists tgmissed]} {set tgmissed 0}
353
354#Binds
355bind pubm $tgflagsstart "$tgchan %$tgcmdstart" tgstart
356bind pubm $tgflagsstop "$tgchan %$tgcmdstop" tgstop
357proc tgbindhintcmd {} {
358 global tgflagshint tgcmdhint
359 bind pubm $tgflagshint "$::tgchan %$tgcmdhint" tgforcehint
360}
361proc tgunbindhintcmd {} {
362 global tgflagshint tgcmdhint
363 unbind pubm $tgflagshint "$::tgchan %$tgcmdhint" tgforcehint
364}
365tgbindhintcmd
366bind pubm $tgflagsskip "$tgchan %$tgcmdskip" tgskip
367bind pubm $tgflagstop10 "$tgchan %$tgcmdtop10" tgshowtop10
368bind join -|- "$tgchan *" tgjoinmsg
369bind msg - $tgcmdhelp tggivehelp
370bind msg - $tgcmdlookup tgscorelookup
371bind msg - $tgcmdtarget tgtargetlookup
372bind msg - $tgcmderror tgerror
373bind msg - $tgcmdrules tgrulesmsg
374bind msg $tgflagsreset "$tgcmdreset" tgresetscores
375bind kick - "$tgchan $botnick" tgbotgotkicked
376bind evnt - disconnect-server tgbotgotdisconnected
377
378#starts the game if it isn't running.
379proc tgstart {nick host hand chan text} {
380 global tgplaying tgstreak tgchan tgerrremindtime tgerrremindtimer tgmissed tgmaxhintcurrent
381 if {[strlwr $tgchan]==[strlwr $chan]} {
382 if {$tgplaying==0} {
383 tggamemsg "[tgcolstart]Juego prendido por $nick!"
384 tgnextq
385 set tgplaying 1
386 set tgstreak 0
387 set tgmissed 0
388 set tgerrremindtimer [timer $tgerrremindtime tgerrremind]
389 }
390 }
391}
392
393#stops the game if it's running.
394proc tgstop {nick host hand chan text} {
395 global tghinttimer tgnextqtimer tgplaying tgchan tgcurrentanswer tgstreak tgstreakmin
396 global tgerrremindtimer tgrebindhinttimer
397 if {[strlwr $tgchan]==[strlwr $chan]} {
398 if {$tgplaying==1} {
399 tggamemsg "[tgcolstop]Juego parado por $nick!"
400 if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} { tgstreakend }
401 set tgstreak 0
402 set tgplaying 0
403 catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
404 if {[utimerexists tghint]!=""} {killutimer $tghinttimer}
405 if {[utimerexists tgnextq]!=""} {killutimer $tgnextqtimer}
406 if {[timerexists tgerrremind]!=""} {killtimer $tgerrremindtimer}
407 if {[utimerexists tgrebindhinttimer]!=""} {killtimer $tgrebindhinttimer}
408 }
409 }
410}
411
412#gives a hint if there is currently a question to answer.
413proc tgforcehint {nick host hand chan text} {
414 global tghinttimer tgnextqtimer tgplaying tgchan tgcurrentanswer tgstreak tgstreakmin
415 global tgtempnohint tgmaxhintcurrent tghintnum tgrebindhinttimer tgtempnohint
416 if {[strlwr $tgchan]==[strlwr $chan]} {
417 if {$tgplaying==1&&[utimerexists tghint]!=""} {
418 killutimer $tghinttimer
419 tghint
420 tgunbindhintcmd
421 if {$tghintnum<$tgmaxhintcurrent} {
422 set tgrebindhinttimer [utimer $tgtempnohint tgbindhintcmd]
423 }
424 }
425 }
426}
427
428#skips the current question if one has been asked.
429proc tgskip {nick host hand chan text} {
430 global tghinttimer tgnextqtimer tgplaying tgchan tgcurrentanswer tgstreak
431 global tgstreakmin tgtimenext tgrebindhinttimer
432 if {[strlwr $tgchan]==[strlwr $chan]} {
433 if {$tgplaying==1&&[utimerexists tghint]!=""} {
434 tggamemsg "[tgcolskip]Paso a la siguente pregunta, por q asi me lo ha pedido [tgcolmisc2]$nick[tgcolskip]."
435 if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin&&[strlwr [lindex [split $tgstreak ,] 0]]==[strlwr $nick]} {
436 tgstreakend
437 set tgstreak 0
438 }
439 catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
440 killutimer $tghinttimer
441 if {[utimerexists tgrebindhinttimer]!=""} {killtimer $tgrebindhinttimer}
442 set tgnextqtimer [utimer $tgtimenext tgnextq]
443 }
444 }
445}
446
447#reminds channel how to report errors in questions/answers
448proc tgerrremind {} {
449 global tgerrremindtimer tgerrremindtime botnick tgcmderror
450 tggamemsg "[tgcolerr]Recuerda: para informar los errores de las preguntas y/o respuestas, teclee /msg $botnick $tgcmderror <numero> \[descripción\]"
451 set tgerrremindtimer [timer $tgerrremindtime tgerrremind]
452}
453
454#bot got kicked. stop the game.
455proc tgbotgotkicked {nick host hand chan targ text} {
456 tgquietstop
457}
458
459#bot got disconnected. stop the game.
460proc tgbotgotdisconnected {disconnect-server} {
461 tgquietstop
462}
463
464#stops the game without telling the channel.
465proc tgquietstop {} {
466 global tgplaying tgstreak tgchan tgcurrentanswer tghinttimer tgnextqtimer tgerrremindtimer
467 global tgrebindhinttimer
468 if {$tgplaying==1} {
469 set tgstreak 0
470 set tgplaying 0
471 catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
472 if {[utimerexists tghint]!=""} {killutimer $tghinttimer}
473 if {[utimerexists tgnextq]!=""} {killutimer $tgnextqtimer}
474 if {[timerexists tgerrremind]!=""} {killtimer $tgerrremindtimer}
475 if {[utimerexists tgrebindhinttimer]!=""} {killtimer $tgrebindhinttimer}
476 }
477}
478
479#reads the question database.
480proc tgreadqdb {} {
481 global tgqdb tgquestionstotal tgquestionslist
482 set tgquestionstotal 0
483 set tgquestionslist ""
484 set qfile [open $tgqdb r]
485 set tgquestionslist [split [read -nonewline $qfile] "\n"]
486 set tgquestionstotal [llength $tgquestionslist]
487 close $qfile
488}
489
490#selects the next question.
491proc tgnextq {} {
492 global tgqdb tgcurrentquestion tgcurrentanswer tgquestionnumber
493 global tgquestionstotal tghintnum tgchan tgquestionslist tgqdbsep tgqdbquestionfirst
494 global tgcapsquestion tgcapsanswer
495 tgreadqdb
496 set tgcurrentquestion ""
497 set tgcurrentanswer ""
498 while {$tgcurrentquestion == ""} {
499 set tgquestionnumber [rand [llength $tgquestionslist]]
500 set tgquestionselected [lindex $tgquestionslist $tgquestionnumber]
501 set tgcurrentquestion [lindex [split $tgquestionselected $tgqdbsep] [expr $tgqdbquestionfirst^1]]
502 if {$tgcapsquestion==1} {
503 set tgcurrentquestion [strupr $tgcurrentquestion]
504 }
505 set tgcurrentanswer [string trim [lindex [split $tgquestionselected $tgqdbsep] $tgqdbquestionfirst]]
506 if {$tgcapsanswer==1} {
507 set tgcurrentanswer [strupr $tgcurrentanswer]
508 }
509 }
510 unset tghintnum
511 tghint
512 bind pubm -|- "$tgchan *" tgcheckanswer
513 return
514}
515
516#shows timed hints.
517proc tghint {} {
518 global tgmaxhint tghintnum tgcurrentanswer tghinttimer tgchan
519 global tgtimehint tghintchar tgquestionnumber tgquestionstotal
520 global tgcurrentquestion tghintcharsused tgnextqtimer tgtimenext tgstreak tgstreakmin
521 global tgnobodygotit tgtrythenextone tgmissed tgmaxmissed tgcmdstart tgshowanswer
522 global tgtimestart tgtimeanswer tgalwaysshowq tgmaxhintcurrent tgtempnohint tgcapshint
523 if {![info exists tghintnum]} {
524 set tghintnum 0
525 regsub -all -- "\[^A-Za-z0-9\]" $tgcurrentanswer "" _hintchars
526 set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]
527 catch {tgunbindhintcmd}
528 if {$tgmaxhintcurrent>0} {
529 set tgrebindhinttimer [utimer $tgtempnohint tgbindhintcmd]
530 }
531 } else { incr tghintnum }
532 if {$tghintnum >= [expr $tgmaxhintcurrent+1]} {
533 incr tgmissed
534 set _msg ""
535 append _msg "[tgcolmiss][lindex $tgnobodygotit [rand [llength $tgnobodygotit]]]"
536 if {$tgshowanswer==1} {
537 append _msg " La respuesta correcta era [tgcolmisc2]$tgcurrentanswer[tgcolmiss]."
538 }
539 if {$tgmaxmissed>0&&$tgmissed>=$tgmaxmissed} {
540 append _msg " That's $tgmissed questions gone by unanswered! The game is now automatically disabled. To start the game again, type $tgcmdstart"
541 tgquietstop
542 } else {
543 append _msg " [lindex $tgtrythenextone [rand [llength $tgtrythenextone]]]"
544 }
545 tggamemsg "[tgcolmiss]$_msg"
546 if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} { tgstreakend }
547 set tgstreak 0
548 catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
549 if {$tgmaxmissed==0||$tgmissed<$tgmaxmissed} {
550 set tgnextqtimer [utimer $tgtimenext tgnextq]
551 }
552 return
553 } elseif {$tghintnum == 0} {
554 set i 0
555 set _hint {}
556 set tghintcharsused {}
557 foreach word [split $tgcurrentanswer] {
558 regsub -all -- "\[A-Za-z0-9\]" $word $tghintchar _current
559 lappend _hint $_current
560 }
561 if {$tgtimeanswer==1} {
562 set tgtimestart [clock clicks -milliseconds]
563 }
564 } elseif {$tghintnum == 1} {
565 set i 0
566 set _hint {}
567 while {$i<[llength [split $tgcurrentanswer]]} {
568 set _word [lindex [split $tgcurrentanswer] $i]
569 set j 0
570 set _newword {}
571 while {$j<[strlen $_word]} {
572 if {$j==0} {
573 append _newword [stridx $_word $j]
574 lappend tghintcharsused $i,$j
575 } else {
576 if {[string is alnum [stridx $_word $j]]} {
577 append _newword $tghintchar
578 } else {
579 append _newword [stridx $_word $j]
580 lappend tghintcharsused $i,$j
581 }
582 }
583 incr j
584 }
585 lappend _hint $_newword
586 incr i
587 }
588 } else {
589 set i 0
590 set _hint {}
591 while {$i<[llength [split $tgcurrentanswer]]} {
592 set _word [lindex [split $tgcurrentanswer] $i]
593 set j 0
594 set _newword {}
595 set _selected [rand [strlen $_word]]
596 regsub -all -- "\[^A-Za-z0-9\]" $_word "" _wordalnum
597 if {[strlen $_wordalnum]>=$tghintnum} {
598 while {[lsearch $tghintcharsused $i,$_selected]!=-1||[string is alnum [stridx $_word $_selected]]==0} {
599 set _selected [rand [strlen $_word]]
600 }
601 }
602 lappend tghintcharsused $i,$_selected
603 while {$j<[strlen $_word]} {
604 if {[lsearch $tghintcharsused $i,$j]!=-1||[string is alnum [stridx $_word $j]]==0} {
605 append _newword [stridx $_word $j]
606 } else {
607 if {[string is alnum [stridx $_word $j]]} {
608 append _newword $tghintchar
609 }
610 }
611 incr j
612 }
613 lappend _hint $_newword
614 incr i
615 }
616 }
617 if {$tgcapshint==1} {
618 set _hint [strupr $_hint]
619 }
620 tggamemsg "[tgcolqhead]===== Pregunta Nr. [expr $tgquestionnumber+1]/$tgquestionstotal [expr $tghintnum?"(Pista Nr. $tghintnum/$tgmaxhintcurrent)":""] ====="
621 if {$tgalwaysshowq==1||$tghintnum==0} {
622 tggamemsg "[tgcolqbody]$tgcurrentquestion"
623 }
624 tggamemsg "[tgcolhint]Pista: [join $_hint]"
625 set tghinttimer [utimer $tgtimehint tghint]
626}
627
628#triggered when someone uses !top10 command
629proc tgshowtop10 {nick host hand chan text} {
630 global tgscores tgchan tgscorestotal
631 if {[strlwr $chan]==[strlwr $tgchan]} {
632 tggetscores
633 if {$tgscorestotal>0} {
634 if {$tgscorestotal>9} {
635 set _max 9
636 } else {
637 set _max [expr $tgscorestotal-1]
638 }
639 set i 0
640 while {$i<=$_max} {
641 set _item [lindex $tgscores $i]
642 set _nick [join [lindex [split $_item ,] 2]]
643 set _score [join [lindex [split $_item ,] 0]]
644 if {$i==0} {
645 append _scores "[tgcolscr1]$_nick $_score"
646 } elseif {$i==1} {
647 append _scores ", [tgcolscr2]$_nick $_score"
648 } elseif {$i==2} {
649 append _scores ", [tgcolscr3]$_nick $_score"
650 } else {
651 append _scores ", [tgcolmisc1]$_nick $_score"
652 }
653 incr i
654 }
655 tggamemsg "[tgcolmisc1]Top 10: $_scores"
656 } else {
657 tggamemsg "[tgcolmisc1]La tabla de puntuacion está vacia."
658 }
659 }
660}
661
662#checks if anyone has said the correct answer on channel.
663proc tgcheckanswer {nick host hand chan text} {
664 global tgcurrentanswer
665 if {[strlwr $tgcurrentanswer] == [tgstripcodes [strlwr [string trim $text]]]} {
666 tgcorrectanswer $nick
667 }
668}
669
670#triggered when someone says the correct answer.
671proc tgcorrectanswer {nick} {
672 global tgcurrentanswer tghinttimer tgtimenext tgchan tgnextqtimer tgstreak tgstreakmin
673 global tgscoresbyname tgranksbyname tgranksbynum tgcongrats tgscorestotal tgmissed
674 global tgtimestart tgshowallscores tgrealnames tgscoresbyrank tgtimeanswer
675 tggetscores
676 if {![info exists tgranksbyname([strlwr $nick])]} {
677 set _oldrank 0
678 } else {
679 set _oldrank $tgranksbyname([strlwr $nick])
680 }
681 tgincrscore $nick
682 tggetscores
683 set _newrank $tgranksbyname([strlwr $nick])
684 set _timetoanswer ""
685 if {$tgtimeanswer==1} {
686 set _timetoanswer [expr [expr [clock clicks -milliseconds]-$tgtimestart]/1000.00]
687 }
688 set _msg "[tgcolmisc1][lindex $tgcongrats [rand [llength $tgcongrats]]] [tgcolmisc2]$nick[tgcolmisc1]! La respuesta correcta es [tgcolmisc2]$tgcurrentanswer[tgcolmisc1].[expr $tgtimeanswer==1?" has contestado en [tgcolmisc2]$_timetoanswer[tgcolmisc1] segundos.":""]"
689 if {$_newrank<$_oldrank} {
690 if {$_newrank==1} {
691 append _msg " Estas en el primer puesto!"
692 } else {
693 if {$tgshowallscores==0} {
694 append _msg " Has subido un puesto!"
695 } else {
696 append _msg " Esta en el puesto nr. [tgcolmisc2]$tgranksbyname([strlwr $nick])[tgcolmisc1] en un total de [tgcolmisc2]$tgscorestotal[tgcolmisc1], detras de el [tgcolmisc2]$tgrealnames($tgranksbynum([expr $_newrank-1]))[tgcolmisc1] con [tgcolmisc2]$tgscoresbyrank([expr $_newrank-1])[tgcolmisc1]."
697 }
698 }
699 }
700 tggamemsg "$_msg"
701 if {$tgstreak!=0} {
702 if {[lindex [split $tgstreak ,] 0]==[strlwr $nick]} {
703 set tgstreak [strlwr $nick],[expr [lindex [split $tgstreak ,] 1]+1]
704 if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} {
705 tggamemsg "[tgcolstrk][tgcolmisc2]$nick[tgcolstrk] Ufff, Esta haciendo maravillas! [tgcolmisc2][lindex [split $tgstreak ,] 1] [tgcolstrk]respuestas correctas consecutivas hasta ahora!"
706 }
707 } else {
708 if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} { tgstreakend }
709 set tgstreak [strlwr $nick],1
710 }
711 } else {
712 set tgstreak [strlwr $nick],1
713 }
714 set tgmissed 0
715 tgshowscores $nick
716 catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
717 killutimer $tghinttimer
718 set tgnextqtimer [utimer $tgtimenext tgnextq]
719}
720
721#read current scores from file, sort and store in variable.
722proc tggetscores {} {
723 global tgscf tgscorestotal tgscores tgscoresbyname tgranksbyname tgranksbynum
724 global tgrealnames tgscoresbyrank
725 if {[file exists $tgscf]&&[file size $tgscf]>2} {
726 set _sfile [open $tgscf r]
727 set tgscores [lsort -dict -decreasing [split [gets $_sfile]]]
728 close $_sfile
729 set tgscorestotal [llength $tgscores]
730 } else {
731 set tgscores ""
732 set tgscorestotal 0
733 }
734 if {[info exists tgscoresbyname]} {unset tgscoresbyname}
735 if {[info exists tgranksbyname]} {unset tgranksbyname}
736 if {[info exists tgrealnames]} {unset tgrealnames}
737 if {[info exists tgranksbynum]} {unset tgranksbynum}
738 set i 0
739 while {$i<[llength $tgscores]} {
740 set _item [lindex $tgscores $i]
741 set _nick [lindex [split $_item ,] 2]
742 set _lwrnick [lindex [split $_item ,] 3]
743 set _score [lindex [split $_item ,] 0]
744 set tgscoresbyname($_lwrnick) $_score
745 set tgrealnames($_lwrnick) $_nick
746 set tgranksbyname($_lwrnick) [expr $i+1]
747 set tgranksbynum([expr $i+1]) $_lwrnick
748 set tgscoresbyrank([expr $i+1]) $_score
749 incr i
750 }
751 return
752}
753
754#increment someone's score.
755proc tgincrscore {who} {
756 global tgscores tgscf tgpointsperanswer tgscorestotal tgscoresbyname
757 tggetscores
758 if {$tgscorestotal>0} {
759 set i 0
760 if {![info exists tgscoresbyname([strlwr $who])]} {
761 append _newscores "1,[expr 1000000000000.0/[unixtime]],$who,[strlwr $who] "
762 }
763 while {$i<[llength $tgscores]} {
764 set _item [lindex $tgscores $i]
765 set _nick [lindex [split $_item ,] 2]
766 set _time [lindex [split $_item ,] 1]
767 set _score [lindex [split $_item ,] 0]
768 if {[strlwr $who]==[strlwr $_nick]} {
769 append _newscores "[expr $_score+$tgpointsperanswer],[expr 1000000000000.0/[unixtime]],$who,[strlwr $who][expr [expr [llength $tgscores]-$i]==1?"":"\ "]"
770 } else {
771 append _newscores "$_score,$_time,$_nick,[strlwr $_nick][expr [expr [llength $tgscores]-$i]==1?"":"\ "]"
772 }
773 incr i
774 }
775 } else {
776 append _newscores "1,[expr 1000000000000.0/[unixtime]],$who,[strlwr $who]"
777 }
778 set _sfile [open $tgscf w]
779 puts $_sfile "$_newscores"
780 close $_sfile
781 return
782}
783
784#shows the current scores on channel.
785proc tgshowscores {nick} {
786 global tgscores tgchan tgscorestotal tgshowallscores tgranksbyname tgranksbynum
787 global tgscoresbyname tgrealnames tgscoresbyrank
788 tggetscores
789 set i 0
790 if {$tgshowallscores} {
791 while {$i<[llength $tgscores]} {
792 set _item [lindex $tgscores $i]
793 set _nick [lindex [split $_item ,] 2]
794 set _score [lindex [split $_item ,] 0]
795 if {$i==0} {
796 append _scores "[tgcolscr1]$_nick $_score"
797 } elseif {$i==1} {
798 append _scores ", [tgcolscr2]$_nick $_score"
799 } elseif {$i==2} {
800 append _scores ", [tgcolscr3]$_nick $_score"
801 } elseif {[onchan $_nick $tgchan]} {
802 append _scores ", [tgcolmisc1]$_nick $_score"
803 }
804 incr i
805 }
806 tggamemsg "[tgcolmisc1]The scores: $_scores"
807 } else {
808 if {$tgranksbyname([strlwr $nick])==1} {
809 set _tgt "."
810 } else {
811 set _tgt ", está detras del concursante [tgcolmisc2]$tgrealnames($tgranksbynum([expr $tgranksbyname([strlwr $nick])-1]))[tgcolmisc1] con [tgcolmisc2]$tgscoresbyrank([expr $tgranksbyname([strlwr $nick])-1])[tgcolmisc1]."
812 }
813 tggamemsg "[tgcolmisc2]$nick [tgcolmisc1]tiene ahora [tgcolmisc2]$tgscoresbyname([strlwr $nick]) [tgcolmisc1][expr $tgscoresbyname([strlwr $nick])==1?"punto":"puntos"] y esta en el puesto nr. [tgcolmisc2]$tgranksbyname([strlwr $nick]) [tgcolmisc1]en un total de [tgcolmisc2]$tgscorestotal[tgcolmisc1]$_tgt"
814 }
815}
816
817#reset current scores.
818proc tgresetscores {nick host hand text} {
819 global tgscf tgscorestotal tgscores tgplaying tgresetreqpw
820 if {($tgresetreqpw==1 && [passwdok $hand $text]) || $tgresetreqpw==0} {
821 if {[file exists $tgscf]&&[file size $tgscf]>2} {
822 set _sfile [open $tgscf w]
823 puts $_sfile ""
824 close $_sfile
825 set tgscores ""
826 set tgscorestotal 0
827 }
828 tggamemsg "[tgcolrset]===== Score table reset by $nick! ====="
829 }
830}
831
832#triggered when a winning streak ends.
833proc tgstreakend {} {
834 global tgstreak tgrealnames
835 tggamemsg "[tgcolstend]Ya sta?? [tgcolmisc2]$tgrealnames([lindex [split $tgstreak ,] 0])'s[tgcolstend] ya no sabes las respuestas...?"
836 return
837}
838
839#triggered when someone joins trivia chan.
840proc tgjoinmsg {nick host hand chan} {
841 global botnick tgplaying tgcmdhelp tgcmdstart tgflagsstart tgcmdstop tgflagsstop tgchan
842 if {$nick != $botnick} {
843 set _msg ""
844 append _msg "Bienvenido a $chan. El Juego de Trivia esta"
845 if {$tgplaying==1} {
846 append _msg " \002encendido\002."
847 } else {
848 append _msg " \002apagado\002."
849 }
850 if {[matchattr $hand $tgflagsstart $tgchan]&&$tgplaying==0} {
851 append _msg "Para encender el Juego, escribe el siguente comando \002$tgcmdstart\002."
852 }
853 append _msg " Use \002/MSG $botnick [strupr $tgcmdhelp]\002 si necesitas Ayuda. ¡Disfrute su estancia! :-)"
854 [tgpriv] $nick "$_msg"
855 }
856}
857
858#triggered when someone /msgs the bot with the score lookup command.
859proc tgscorelookup {nick host hand text} {
860 global tgscoresbyname tgranksbyname tgscorestotal tgrealnames
861 if {$text==""} { set text $nick } else { set text [lindex [split $text] 0] }
862 tggetscores
863 if {![info exists tgscoresbyname([strlwr $text])]} {
864 if {[strlwr $text]==[strlwr $nick]} {
865 set _who "[tgcolmisc1]Estas"
866 } else {
867 set _who "[tgcolmisc2]$text [tgcolmisc1]no esta"
868 }
869 [tgpriv] $nick "[tgbold]$_who [tgcolmisc1]en la lista con puntuación."
870 } else {
871 if {[strlwr $text]==[strlwr $nick]} {
872 set _who "[tgcolmisc1]Ai"
873 } else {
874 set _who "[tgcolmisc2]$tgrealnames([strlwr $text]) [tgcolmisc1]are"
875 }
876 [tgpriv] $nick "[tgbold]$_who [tgcolmisc2]$tgscoresbyname([strlwr $text])[tgcolmisc1] puntos, estando en el puesto nr. [tgcolmisc2] $tgranksbyname([strlwr $text]) [tgcolmisc1]en un total de [tgcolmisc2]$tgscorestotal[tgcolmisc1]."
877 }
878}
879
880#triggered when someone /msgs the bot with the target lookup command.
881proc tgtargetlookup {nick host hand text} {
882 global tgscoresbyname tgranksbyname tgscorestotal tgranksbynum tgrealnames
883 tggetscores
884 if {![info exists tgscoresbyname([strlwr $nick])]} {
885 [tgpriv] $nick "[tgbold][tgcolmisc1]Aún no estás en la lista de puntuación.."
886 } elseif {$tgranksbyname([strlwr $nick])==1} {
887 [tgpriv] $nick "[tgbold][tgcolmisc1]Estas en primer lugar!"
888 } else {
889 [tgpriv] $nick "[tgbold][tgcolmisc1]Estas en [tgcolmisc2]$tgscoresbyname([strlwr $nick])[tgcolmisc1]. Tu adversario es [tgcolmisc2]$tgrealnames($tgranksbynum([expr $tgranksbyname([strlwr $nick])-1])) [tgcolmisc1]con [tgcolmisc2]$tgscoresbyname($tgranksbynum([expr $tgranksbyname([strlwr $nick])-1]))[tgcolmisc1], en el Puesto nr. [tgcolmisc2][expr $tgranksbyname([strlwr $nick])-1] [tgcolmisc1]en un total de [tgcolmisc2]$tgscorestotal[tgcolmisc1]."
890 }
891}
892
893#triggered when someone /msgs the bot with the error reporting command.
894proc tgerror {nick host hand text} {
895 global tgquestionstotal tgquestionslist tgerrmethod tgerrfil tgerremail tgerrmailtmp
896 if {$text==""||![string is int [lindex [split $text] 0]]} {
897 [tgpriv] $nick "[tgbold][tgcolmisc1]Tienes que especificar el numero de la pregunta."
898 return
899 }
900 tgreadqdb
901 set _qnum [lindex [split $text] 0]
902 if {$_qnum>$tgquestionstotal} {
903 [tgpriv] $nick "[tgbold][tgcolmisc1]No existe la pregunta."
904 return
905 }
906 set _qques [lindex [split [lindex $tgquestionslist [expr $_qnum-1]] |] 1]
907 set _qans [lindex [split [lindex $tgquestionslist [expr $_qnum-1]] |] 0]
908 set _desc [join [lrange [split $text] 1 end]]
909 if {$_desc==""} { set _desc "No further info given for this error." }
910 if {$tgerrmethod==1} {
911 set _fname $tgerrmailtmp\trivia[rand 100000].tmp
912 set _file [open $_fname w]
913 } else {
914 set _file [open $tgerrfil a]
915 }
916 puts $_file ""
917 puts $_file "Error report generated [strftime %A,\ %d\ %B\ %Y\ @\ %H:%M:%S]"
918 puts $_file "Reported by:\t$nick!$host"
919 puts $_file "Question #:\t$_qnum"
920 puts $_file "Question:\t$_qques"
921 puts $_file "Answer:\t\t$_qans"
922 puts $_file "Comments:\t$_desc"
923 puts $_file "------------------------------"
924 close $_file
925 if {$tgerrmethod==1} {
926 exec mail -s "trivia.tcl error report from $nick" $tgerremail < $_fname
927 file delete $_fname
928 [tgpriv] $nick "[tgbold][tgcolmisc1]Gracias! El error ha sido informado."
929 } else {
930 [tgpriv] $nick "[tgbold][tgcolmisc1]Gracias! El error ha sido informado."
931 }
932}
933
934#triggered when someone /msgs the bot with the rules command.
935proc tgrulesmsg {nick host hand text} {
936 global tgrules
937 [tgpriv] $nick "Las reglas del Canal: $tgrules"
938}
939
940#triggered when someone /msgs the bot with the help command.
941proc tggivehelp {nick host hand {text ""}} {
942 global botnick tgcmdlookup tgcmdhelp tgcmdstart tgcmdstop tgchan tgflagsstop
943 global tgcmdstop tgflagshint tgcmdhint tgflagsskip tgcmdskip tgflagsreset tgcmdreset
944 global tgcmdtarget tgcmderror tgcmdrules tgflagsstart
945 if {$text==""} {
946 [tgpriv] $nick "Tienes acceso a los siguentes comandos (via /MSG):"
947 [tgpriv] $nick "Para poder usar los comandos, use /MSG $botnick <comando>"
948 [tgpriv] $nick " \002[strupr $tgcmdrules]\002"
949 [tgpriv] $nick " -- Lista las reglas del canal."
950 [tgpriv] $nick " \002[strupr $tgcmdlookup]\002 \[nick\]"
951 [tgpriv] $nick " -- Te muestra el puesto y puntaje del [nick], especificó,"
952 [tgpriv] $nick " si no especificas un nick, te mostrara tu puesto y puntaje."
953 [tgpriv] $nick " \002[strupr $tgcmdtarget]\002"
954 [tgpriv] $nick " -- Te muestra el puesto y puntaje de la persona con puntaje más"
955 [tgpriv] $nick " cercano al tuyo"
956 [tgpriv] $nick " \002[strupr $tgcmderror]\002 <numar> \[descriere\]"
957 [tgpriv] $nick " -- Para reportar algun error en alguna pregunta y/o respuesta, para corregirlo"
958 [tgpriv] $nick " La descripción es Opcional, pero sirve de Ayuda"
959 if {[matchattr $hand $tgflagsreset $tgchan]} {
960 [tgpriv] $nick " \002[strupr $tgcmdreset]\002"
961 [tgpriv] $nick " -- Reinicia la Tabla con el puntaje."
962 }
963 [tgpriv] $nick "Para ver una Lista con los comandos del Canal, use /MSG $botnick [strupr $tgcmdhelp] PUBCMDS"
964 }
965 if {[strlwr $text]=="pubcmds"} {
966 [tgpriv] $nick "Tienes acceso a los siguentes comandos en el canal:"
967 if {[matchattr $hand $tgflagsstart $tgchan]} {
968 [tgpriv] $nick " \002$tgcmdstart\002 -- Enciende el Juego."
969 }
970 if {[matchattr $hand $tgflagsstop $tgchan]} {
971 [tgpriv] $nick " \002$tgcmdstop\002 -- para el Juego."
972 }
973 if {[matchattr $hand $tgflagshint $tgchan]} {
974 [tgpriv] $nick " \002$tgcmdhint\002 -- te enseña una Pista."
975 }
976 if {[matchattr $hand $tgflagsskip $tgchan]} {
977 [tgpriv] $nick " \002$tgcmdskip\002 -- cambia de pregunta."
978 }
979 [tgpriv] $nick "Para una Lista de comandos (via /MSG ) use /MSG $botnick [strupr $tgcmdhelp]"
980 }
981}
982
983# Returns text without colour, bold, etc. control codes.
984# This is a stripped down version of the proc in MC_8's mc.moretools.tcl.
985proc tgstripcodes {text} {
986 regsub -all -- "\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?" $text "" text
987 set text "[string map -nocase [list \002 "" \017 "" \026 "" \037 ""] $text]"
988 return $text
989}
990
991proc tggamemsg {what} {
992 global tgchan
993 putquick "PRIVMSG $tgchan :[tgbold]$what"
994}
995
996proc tgbold {} {
997 global tgusebold
998 if {$tgusebold==1} { return "\002" }
999}
1000proc tgcolstart {} {
1001 global tgcolourstart
1002 if {$tgcolourstart!=""} { return "\003$tgcolourstart" }
1003}
1004proc tgcolstop {} {
1005 global tgcolourstop
1006 if {$tgcolourstop!=""} { return "\003$tgcolourstop" }
1007}
1008proc tgcolskip {} {
1009 global tgcolourskip
1010 if {$tgcolourskip!=""} { return "\003$tgcolourskip" }
1011}
1012proc tgcolerr {} {
1013 global tgcolourerr
1014 if {$tgcolourerr!=""} { return "\003$tgcolourerr" }
1015}
1016proc tgcolmiss {} {
1017 global tgcolourmiss
1018 if {$tgcolourmiss!=""} { return "\003$tgcolourmiss" }
1019}
1020proc tgcolqhead {} {
1021 global tgcolourqhead
1022 if {$tgcolourqhead!=""} { return "\003$tgcolourqhead" }
1023}
1024proc tgcolqbody {} {
1025 global tgcolourqbody
1026 if {$tgcolourqbody!=""} { return "\003$tgcolourqbody" }
1027}
1028proc tgcolhint {} {
1029 global tgcolourhint
1030 if {$tgcolourhint!=""} { return "\003$tgcolourhint" }
1031}
1032proc tgcolstrk {} {
1033 global tgcolourstrk
1034 if {$tgcolourstrk!=""} { return "\003$tgcolourstrk" }
1035}
1036proc tgcolscr1 {} {
1037 global tgcolourscr1
1038 if {$tgcolourscr1!=""} { return "\003$tgcolourscr1" }
1039}
1040proc tgcolscr2 {} {
1041 global tgcolourscr2
1042 if {$tgcolourscr2!=""} { return "\003$tgcolourscr2" }
1043}
1044proc tgcolscr3 {} {
1045 global tgcolourscr3
1046 if {$tgcolourscr3!=""} { return "\003$tgcolourscr3" }
1047}
1048proc tgcolrset {} {
1049 global tgcolourrset
1050 if {$tgcolourrset!=""} { return "\003$tgcolourrset" }
1051}
1052proc tgcolstend {} {
1053 global tgcolourstend
1054 if {$tgcolourstend!=""} { return "\003$tgcolourstend" }
1055}
1056proc tgcolmisc1 {} {
1057 global tgcolourmisc1
1058 if {$tgcolourmisc1!=""} { return "\003$tgcolourmisc1" }
1059}
1060proc tgcolmisc2 {} {
1061 global tgcolourmisc2
1062 if {$tgcolourmisc2!=""} { return "\003$tgcolourmisc2" }
1063}
1064proc tgpriv {} {
1065 global tgpriv2msg
1066 if {$tgpriv2msg==1} { return "putmsg" } else { return "putnotc" }
1067}
1068
1069#this generates an html file with all the people on the chan with
1070#their score, as well as a list of all scores, sorted by rank
1071proc tghtml {} {
1072 global tgchan botnick tghtmlfile tghtmlrefresh server tgscoresbyname tgranksbyname
1073 global tgscorestotal tgranksbyname tgrealnames tgscoresbyrank tgranksbynum tgplaying
1074 global tgquestionstotal tghtmlrefreshtimer tghtmlfont
1075 tggetscores
1076 tgreadqdb
1077 set _file [open $tghtmlfile~new w]
1078 puts $_file "<!DOCTYPE HTML PUBLIC \"-/W3C/DTD HTML 4.01 Transitional/EN\">"
1079 puts $_file "<html>"
1080 puts $_file " <head>"
1081 puts $_file " <title>$botnick's trivia channel: $tgchan on [lindex [split $server :] 0]</title>"
1082 puts $_file " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
1083 puts $_file " <meta http-equiv=\"refresh\" content=\"$tghtmlrefresh\">"
1084 puts $_file " <meta name=\"generator\" content=\"Trivial las 24 horas\">"
1085 puts $_file " <style type=\"text/css\">"
1086 puts $_file " <!--"
1087 puts $_file " body,td{font-family:$tghtmlfont;font-size:13px;}"
1088 puts $_file " a{text-decoration:none;color:#09f;}"
1089 puts $_file " -->"
1090 puts $_file " </style>"
1091 puts $_file " </head>"
1092 puts $_file " <body>"
1093 puts $_file " <h1>$tgchan on [lindex [split $server :] 0]</h1>"
1094 puts $_file " <hr size=\"1\" noshade>"
1095 if {![onchan $botnick $tgchan]} {
1096 puts $_file " <p>Hmmm... for some reason I'm not on $tgchan at the moment. Please try again later.</p>"
1097 } else {
1098 puts $_file " <p>Trivia game is currently <b>[expr $tgplaying==1?"on":"off"]</b>. There are <b>$tgquestionstotal</b> questions in the database."
1099 puts $_file " <p>People on $tgchan right now:<br>"
1100 puts $_file " <table width=\"50%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><table width=\"100%\" cellspacing=\"3\" border=\"0\">"
1101 puts $_file " <tr>"
1102 puts $_file " <td><b>Nick</b></td>"
1103 puts $_file " <td><b>Score</b></td>"
1104 puts $_file " <td><b>Rank</b></td>"
1105 puts $_file " <td><b>Idle</b></td>"
1106 puts $_file " </tr>"
1107 foreach nick [lsort [chanlist $tgchan]] {
1108 puts $_file " <tr>"
1109 puts $_file " <td>[expr [isop $nick $tgchan]?"@":""][expr [isvoice $nick $tgchan]?"+":""]$nick[expr [string match $nick $botnick]?" (that's me!)":""]</td>"
1110 if {[info exists tgscoresbyname([strlwr $nick])]} {
1111 puts $_file " <td>$tgscoresbyname([strlwr $nick])</td>"
1112 } else {
1113 puts $_file " <td>-</td>"
1114 }
1115 if {[info exists tgranksbyname([strlwr $nick])]} {
1116 puts $_file " <td>$tgranksbyname([strlwr $nick])</td>"
1117 } else {
1118 puts $_file " <td>-</td>"
1119 }
1120 puts $_file " <td>[expr [getchanidle $nick $tgchan]>10?"[getchanidle $nick $tgchan]m":"-"]</td>"
1121 puts $_file " </tr>"
1122 }
1123 puts $_file " </table></td></tr></table>"
1124 }
1125 if {$tgscorestotal>0} {
1126 puts $_file " <p><small>Existen [expr $tgscorestotal==1?"":""] <b>$tgscorestotal</b> [expr $tgscorestotal==1?"nick":"nick"] en la lista con el puntaje:<br>"
1127 set _rank 1
1128 while {$_rank<=$tgscorestotal} {
1129 puts $_file " <b>$_rank</b>. $tgrealnames($tgranksbynum($_rank)) $tgscoresbyrank($_rank)<br>"
1130 incr _rank
1131 }
1132 } else {
1133 puts $_file " <p><small>Nu exista nici un nick in tabela de scor.<br>"
1134 }
1135 puts $_file " </small></p>"
1136 puts $_file " <hr size=\"1\" noshade>"
1137 puts $_file " <small>Generated on [strftime %A,\ %d\ %B\ %Y\ @\ %H:%M:%S] by <a href=\"http://www.eggdrop.za.net/\">trivia.tcl</a> for <a href=\"http://www.eggheads.org\">eggdrop</a>.<br>"
1138 puts $_file " This page is automatically updated (and refreshed if supported by your browser) every [expr $tghtmlrefresh==1?"second":"$tghtmlrefresh seconds"].</small>"
1139 puts $_file " </body>"
1140 puts $_file "</html>"
1141 close $_file
1142 file rename -force $tghtmlfile~new $tghtmlfile
1143 set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
1144}
1145
1146putlog "================================================================="
1147putlog "* RoTrivia $tgver ($tgrel) by LightAngel & Souperman loaded./Actualizada por sedition /server irc.cafechat.org"
1148putlog "* Visit http://www.helperscript.ro/ for updates."
1149putlog "* $tgquestionstotal questions in $tgqdb ([file size $tgqdb] bytes)"
1150putlog "=================================================================="