All pastes #15355 Raw Edit

Someone

public text v1 · immutable
#15355 ·published 2005-06-21 17:22 UTC
rendered paste body
######################################################################
#PLEASE customise the settings before rehashing your bot!            #
######################################################################

#  The full path to the file containing the questions and answers.
#  The account the bot runs on must have read access to this file.
set tgqdb "scripts/trivia.questions"

#  The character that seperates the question and the answer in the
#  question/answer file.
set tgqdbsep "="

#  What you set here defines how the bot expects the question/answer
#  pairs to be arranged.
#  If set to 1, bot expects lines in the format:
#    question<seperator>answer
#  If set to 0, bot expects lines in the format:
#    answer<seperator>question
set tgqdbquestionfirst 1

#  The full path to the file which tracks the scores. The account
#  the bot runs on must have read & write access to this file. If
#  the file does not exist, it will be created when needed.
set tgscf "scripts/trivia.scores"

#  How to send error reports. Set to 1 to send error report to an
#  e-mail address of your choice, or 0 to record errors in a file.
#  Sending via e-mail requires that the bot have access to the "mail"
#  program. If the bot doesn't have access to this program (e.g. if
#  you're running the bot on the Windows platform), then set this to
#  0 to have errors recorded in a file.
set tgerrmethod 1

#  The full path to the file which records error reports. The
#  account the bot runs on must have read & write access to this
#  file. If the file does not exist, it will be created when needed.
set tgerrfil "scripts/trivia.errors"

#  The e-mail address to send error reports to.
set tgerremail "rosofter@yahoo.co.uk"

#  If error reports are sent via e-mail, where will the bot create
#  a temp file? /tmp/ is a good idea.
set tgerrmailtmp "/home/design-s/CNN/eggdrop/scripts/"

#  The full path to the file which the bot will use to generate
#  an HTML info page. The account the bot runs on must have read
#  & write access to this file. If the file does not exist, it will
#  be created when needed.
set tghtmlfile "/home/design-s/CNN/eggdrop/scripts/radio.html"

#  How often (in seconds) does the html file get updated. Set to 0
#  to disable HTML page.
set tghtmlrefresh 30

#  The font to use on the html page.
set tghtmlfont "verdana,helvetica,arial"

#  The name of the channel where the game will be played. The game
#  can only be played on one channel.
set tgchan "#RadioFM"

#  How many points to give a person for a correctly answered
#  question.
set tgpointsperanswer 0

#  The maximum number of hints to give before the question 'expires'
#  and the bot goes on to another one. This EXCLUDES the first hint
#  given as the question is asked (i.e. the hint which shows no letters,
#  only placeholders).
set tgmaxhint 3

#  Should the bot show the question on each hint (1) or only on the first (0)?
set tgalwaysshowq 0

#  Show questions in all CAPS (1) or not (0)?
set tgcapsquestion 0

#  Show answers in all CAPS (1) or not (0)?
set tgcapsanswer 0

#  Show hints in all CAPS (1) or not (0)?
set tgcapshint 0

#  The minimum number of correct answers in a row by one person which
#  puts them on a winning streak. Setting this to 0 will disable the
#  winning streak feature.
set tgstreakmin 0

#  The number of missed (i.e. unanswered, not skipped) questions to allow
#  before automatically stopping the game. Setting this to 0 will cause the
#  game to run until somebody uses the stop command, or the bot dies, gets
#  killed, pings out, or whatever.
set tgmaxmissed 0

#  The character to use as a placeholder in hints.
set tghintchar "*"

#  The time in seconds between hints.
set tgtimehint 15

#  The time in seconds between a correct answer, 'expired' or skipped question
#  and the next question being asked.
set tgtimenext 10

#  Phrases to use at random when someone answers a question correctly. This must
#  be a TCL list. If you don't know what that means, stick to the defaults.
set tgcongrats [list "Felicitari" "Bravo" "Bine facut! " "Nu te mai uita la vecinul." "Ai tastatura automata?" "De ce copiezi?!" "Nani,nani... te-am trezit?" "Ai sunat un prieten?" "Mama... ce rapid." "To Fast and Furious." "Asa creier mai rar."  "Buna treaba." "Ai prins-o tine-o bine." "Cam asa se joacã trivia." "Arata-le cum se joaca trivia." "Fiti atenti ce cap mare are!"]

#  Phrases to use when the question has 'expired'. Must also be a TCL list.
set tgnobodygotit [list "Nimeni nu a ghicit." "Allo? Cineva acasa?" "Va trebui sa va chinuiti mai mult!" "A fost prea grea intrebarea?" "Sunt singur aici sau ce?" "Nu o sa primiti nici un punct daca jucati asa!"]


#  Phrases to use when the question expired and there's another one coming up.
#  Yep, you guessed it... another TCL list.
set tgtrythenextone [list "Sa vedem daca o ghiciti pe urmatoarea..." "Pregatiti-va pentru urmatoarea intrebare..." "Poate o sa ai noroc data viitoare..." "Incearc-o si pe urmatoarea..." "Acum vine urmatoarea intrebare..."]

#  Will the bot calculate the time it took to get the correct
#  answer (1) or not (0)? (requires TCL 8.3 or higher).
set tgtimeanswer 1

#  Will the bot show the correct answer if nobody gets it (1) or not (0)?
set tgshowanswer 1

#  When someone answers a question, will the bot show just that person's score (0)
#  or will it show all players' scores (1) (default). This is useful in channels with
#  a large number (>20) players.
set tgshowallscores 0

#  Use bold codes in messages (1) or not (0)?
set tgusebold 0

#  Send private messages using /msg (1) or not (0)?
#  If set to 0, private messages will be sent using /notice
set tgpriv2msg 0

#  Word to use as /msg command to give help.
#  e.g. set tgcmdhelp "helpme" will make the bot give help when someone
#  does "/msg <botnick> helpme"
set tgcmdhelp "help"

#  Channel command used to start the game.
set tgcmdstart "!go"

#  Flags required to be able to use the start command.
set tgflagsstart "-|-"

#  Channel command used to stop the game.
set tgcmdstop "!stop"

#  Flags required to be able to use the stop command.
set tgflagsstop "m|m"

#  Channel command used to give a hint.
set tgcmdhint "!hint"

#  Flags required to be able to use the hint command.
set tgflagshint "-|-"

#  Disable the !hint command x seconds after someone uses it. This
#  prevents accidental double hints if two people use the command in
#  quick succession.
set tgtempnohint 10

#  Channel command used to skip the question.
set tgcmdskip "!next"

#  Flags required to be able to use the skip command.
set tgflagsskip "o|o"

#  Channel command for showing the top 10 scores.
set tgcmdtop10 "!top10"

#  Flags required to use the top 10 command.
set tgflagstop10 "-|-"

#  /msg command used to reset scores.
set tgcmdreset "reset"

#  Flags required to be able to use the reset command.
set tgflagsreset "m|m"

#  /msg command for looking up somebody's score.
set tgcmdlookup "scor"

#  /msg command for looking up your target.
#  (i.e. the person ranked one higher than you).
set tgcmdtarget "locul"

#  /msg command for reporting errors in questions and/or answers.
set tgcmderror "eroare"

#  /msg command to show channel's rules.
set tgcmdrules "reguli"

#  Channel's rules.
set tgrules "Fara reclame, fara profanatism, fara hartuire a userilor, fara scripturi active si fara flood. Daca incalci regulile asteapta-te sa fii banat. Distractie Placuta. :-)"

#  Number of minutes between reminders of how to report errors.
set tgerrremindtime 15

#  COLOURS
#  The colour codes used are the same as those used by mIRC:
#  00:white        01:black        02:dark blue    03:dark green
#  04:red          05:brown        06:purple       07:orange
#  08:yellow       09:light green  10:turquoise    11:cyan
#  12:light blue   13:magenta      14:dark grey    15:light grey
#
#  Always specify colour codes as two digits, i.e. use "01" for
#  black, not "1".
#  You can specify a background colour using "00,04" (white text
#  on red background).
#  To disable a colour, use "".
#  Note that disabling some colours but not others may yield
#  unexpected results.

set tgcolourstart "08,05"               ;#Game has started.
set tgcolourstop "13,01"                ;#Game has stopped.
set tgcolourskip "00,10"                ;#Question has been skipped.
set tgcolourerr "07"                    ;#How to report errors.
set tgcolourmiss "14"                ;#Nobody answered the question.
set tgcolourqhead "07"               ;#Question heading.
set tgcolourqbody "11,04"               ;#Question text
set tgcolourhint "02"                   ;#Hint.
set tgcolourstrk "04,11"                ;#Person is on a winning streak.
set tgcolourscr1 "04,01"                ;#Score of person in first place.
set tgcolourscr2 "04,02"                ;#Score of person in second place.
set tgcolourscr3 "01,08"                ;#Score of person in third place.
set tgcolourrset "05"                   ;#Scores have been reset.
set tgcolourstend "12"          ;#Winning streak ended.
set tgcolourmisc1 "06"          ;#Miscellaneous colour #1.
set tgcolourmisc2 "07"          ;#Miscellaneous colour #2.

##### Rand ######

set randline {
    Da bule
 }


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#                                                                   #
#    Any editing done beyond this point is done at your own risk!   #
#                                                                   #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#Misc checks & var initialisations
set tgver "1.3.1"
set tgrel "release"
set qval 0
if {[info tclversion]<8.2} {
 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)."
 return
}
if {$tgtimeanswer==1&&[info tclversion]<8.3} {
 putlog "\002[file tail [info script]]\002 warning: timing of answers has been automatically disabled. this feature requires tcl 8.3 or higher."
 set tgtimeanswer 0
}
if {![info exists alltools_loaded]||$allt_version<204} {
 putlog "\002[file tail [info script]]\002 failed to load: please load alltools.tcl v1.6 or higher before attempting to load this script."
 return
}
if {[utimerexists tghtml]!=""} {killutimer $tghtmlrefreshtimer}
if {$tghtmlrefresh>0} {
 set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
}
if {![file exists $tgqdb]} {
 putlog "\002[file tail [info script]]\002 failed to load: $tgqdb does not exist."
 return
}
if {[llength [split $tgchan]]!=1} {
 putlog "\002[file tail [info script]]\002 failed to load: too many channels specified."
 return
}
if {![info exists tgplaying]} {
 set ctcp-version "${ctcp-version} (with trivia.tcl $tgver ($tgrel) from www.geocities.com/triviatcl/)"
 set tgplaying 0
}
if {![info exists tghintnum]} {set tghintnum 0}
if {![info exists tgmissed]} {set tgmissed 0}

#Binds

bind pubm $tgflagsstart "$tgchan %$tgcmdstart" tgstart
bind pubm $tgflagsstop "$tgchan %$tgcmdstop" tgstop
proc tgbindhintcmd {} {
        global tgflagshint tgcmdhint
        bind pubm $tgflagshint "$::tgchan %$tgcmdhint" tgforcehint
}
proc tgunbindhintcmd {} {
        global tgflagshint tgcmdhint
        unbind pubm $tgflagshint "$::tgchan %$tgcmdhint" tgforcehint
}
tgbindhintcmd
bind pubm $tgflagsskip "$tgchan %$tgcmdskip" tgskip
bind pubm $tgflagstop10 "$tgchan %$tgcmdtop10" tgshowtop10
bind join -|- "$tgchan *" tgjoinmsg
bind msg - $tgcmdhelp tggivehelp
bind msg - $tgcmdlookup tgscorelookup
bind msg - $tgcmdtarget tgtargetlookup
bind msg - $tgcmderror tgerror
bind msg - $tgcmdrules tgrulesmsg
bind msg $tgflagsreset "$tgcmdreset" tgresetscores
bind kick - "$tgchan $botnick" tgbotgotkicked
bind evnt - disconnect-server tgbotgotdisconnected



#starts the game if it isn't running.
proc tgstart {nick host hand chan text} {
 global tgplaying tgstreak tgchan tgerrremindtime tgerrremindtimer tgmissed
 if {[strlwr $tgchan]==[strlwr $chan]} {
  if {$tgplaying==0} {
   tggamemsg "[tgcolstart]Jocul de Trivia a fost pornit de catre $nick!"
   tgnextq
   set tgplaying 1
   set tgstreak 0
   set tgmissed 0
   set tgerrremindtimer [timer $tgerrremindtime tgerrremind]
  }
 }
}

#stops the game if it's running.
proc tgstop {nick host hand chan text} {
 global tghinttimer tgnextqtimer tgplaying tgchan tgcurrentanswer tgstreak tgstreakmin
 global tgerrremindtimer tgrebindhinttimer
 if {[strlwr $tgchan]==[strlwr $chan]} {
  if {$tgplaying==1} {
   tggamemsg "[tgcolstop]Jocul de Trivia a fost oprit de catre $nick!"
   if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} { tgstreakend }
   set tgstreak 0
   set tgplaying 0
   catch {unbind pubm -|- "$tgchan $tgcurrentanswer" tgcorrectanswer}
   if {[utimerexists tghint]!=""} {killutimer $tghinttimer}
   if {[utimerexists tgnextq]!=""} {killutimer $tgnextqtimer}
   if {[timerexists tgerrremind]!=""} {killtimer $tgerrremindtimer}
   if {[utimerexists tgrebindhinttimer]!=""} {killtimer $tgrebindhinttimer}
  }
 }
}

#gives a hint if there is currently a question to answer.

proc tgforcehint {nick host hand chan text} {
        global tghinttimer tgnextqtimer tgplaying tgchan tgcurrentanswer tgstreak tgstreakmin
        global tgtempnohint tgmaxhintcurrent tghintnum tgrebindhinttimer tgtempnohint
        if {[strlwr $tgchan]==[strlwr $chan]} {
                if {$tgplaying==1&&[utimerexists tghint]!=""} {
                        killutimer $tghinttimer
                        tghint
                        tgunbindhintcmd
                        if {$tghintnum<$tgmaxhintcurrent} {
                                set tgrebindhinttimer [utimer $tgtempnohint tgbindhintcmd]
                        }
                }
        }
}



#skips the current question if one has been asked.
proc tgskip {nick host hand chan text} {
 global tghinttimer tgnextqtimer tgplaying tgchan tgcurrentanswer tgstreak
 global tgstreakmin tgtimenext tgrebindhinttimer
 if {[strlwr $tgchan]==[strlwr $chan]} {
  if {$tgplaying==1&&[utimerexists tghint]!=""} {
   tggamemsg "[tgcolskip]Skipping to next question by [tgcolmisc2]$nick's[tgcolskip] request..."
   if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin&&[strlwr [lindex [split $tgstreak ,] 0]]==[strlwr $nick]} {
    tgstreakend
    set tgstreak 0
   }
   unbind pubm -|- "$tgchan $tgcurrentanswer" tgcorrectanswer
   killutimer $tghinttimer
   if {[utimerexists tgrebindhinttimer]!=""} {killtimer $tgrebindhinttimer}
   set tgnextqtimer [utimer $tgtimenext tgnextq]
  }
 }
}

#reminds channel how to report errors in questions/answers
proc tgerrremind {} {
 global tgerrremindtimer tgerrremindtime botnick tgcmderror
 tggamemsg "[tgcolerr]Tineti minte: pentru a raporta erori in intrebari/raspunsuri, scrieti /msg $botnick $tgcmderror <numar> \[descriere\]"
 set tgerrremindtimer [timer $tgerrremindtime tgerrremind]
}

#bot got kicked. stop the game.
proc tgbotgotkicked {nick host hand chan targ text} {
 tgquietstop
}

#bot got disconnected. stop the game.
proc tgbotgotdisconnected {disconnect-server} {
 tgquietstop
}

#stops the game without telling the channel.
proc tgquietstop {} {
 global tgplaying tgstreak tgchan tgcurrentanswer tghinttimer tgnextqtimer tgerrremindtimer
 global tgrebindhinttimer
 if {$tgplaying==1} {
  set tgstreak 0
  set tgplaying 0
  catch {unbind pubm -|- "$tgchan $tgcurrentanswer" tgcorrectanswer}
  if {[utimerexists tghint]!=""} {killutimer $tghinttimer}
  if {[utimerexists tgnextq]!=""} {killutimer $tgnextqtimer}
  if {[timerexists tgerrremind]!=""} {killtimer $tgerrremindtimer}
  if {[utimerexists tgrebindhinttimer]!=""} {killtimer $tgrebindhinttimer}
 }
}

#reads the question database.
proc tgreadqdb {} {
 global tgqdb tgquestionstotal tgquestionslist
 set tgquestionstotal 0
 set tgquestionslist ""	
 set qfile [open $tgqdb r]
 while {![eof $qfile]} {
  lappend tgquestionslist [gets $qfile]
  incr tgquestionstotal
 }
 close $qfile
}
proc get_rand_value {} {
  set rnd [rand 79]
  set rnd [expr $rnd+30]
  if {$rnd < 101} {
      set val [expr [expr $rnd/10]+1]
      } else {
      switch $rnd {
        101 {set val 25}
        102 {set val 25}
        103 {set val 25}
        104 {set val 25}
        105 {set val 50}
        106 {set val 50}
        107 {set val 50}
        108 {set val 100}
        default {set val 0}
        }
      }
  unset rnd
  return $val
}
#selects the next question.
proc tgnextq {} {
 global tgqdb tgcurrentquestion tgcurrentanswer tgquestionnumber tgquestionstotal
 global tghintnum tgchan tgquestionslist tgqdbsep tgqdbquestionfirst qval
 tgreadqdb
 set tgquestionnumber [rand [llength $tgquestionslist]]			
 set tgquestionselected [lindex $tgquestionslist $tgquestionnumber]
 set tgcurrentquestion [lindex [split $tgquestionselected $tgqdbsep] [expr $tgqdbquestionfirst^1]]
 set tgcurrentanswer [strlwr [lindex [split $tgquestionselected $tgqdbsep] $tgqdbquestionfirst]]
 set qval [get_rand_value]
 unset tghintnum
 tghint
 bind pubm -|- "$tgchan $tgcurrentanswer" tgcorrectanswer
 return
}

#shows timed hints.
proc tghint {} {
 global tgmaxhint tghintnum tgcurrentanswer tghinttimer tgchan
 global tgtimehint tghintchar tgquestionnumber tgquestionstotal
 global tgcurrentquestion tghintcharsused tgnextqtimer tgtimenext tgstreak tgstreakmin
 global tgnobodygotit tgtrythenextone tgmissed tgmaxmissed tgcmdstart tgshowanswer
 global tgtimestart tgtimeanswer tgalwaysshowq tgmaxhintcurrent tgtempnohint
 global tgcapsanswer tgcapsquestion tgcapshint qval
 if {[catch {incr tghintnum}]!=0} {
  set tghintnum 0
  regsub -all -- "\[^A-Za-z0-9\]" [string trim $tgcurrentanswer] "" _hintchars
  set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]
  catch {tgunbindhintcmd}
  if {$tgmaxhintcurrent>0} {
   set tgrebindhinttimer [utimer $tgtempnohint tgbindhintcmd]
  }
 }
 if {$tghintnum >= [expr $tgmaxhintcurrent+1]} {
  incr tgmissed
  set _msg ""
  append _msg "[tgcolmiss][lindex $tgnobodygotit [rand [llength $tgnobodygotit]]]"
  if {$tgshowanswer==1} {
   append _msg " Raspunsul corect a fost [tgcolmisc2][expr $tgcapsanswer?"[strupr $tgcurrentanswer]":"$tgcurrentanswer"][tgcolmiss]."
  }
  if {$tgmaxmissed>0&&$tgmissed>=$tgmaxmissed} {
   append _msg " Au trecut $tgmissed intrebari care nu au fost raspunse! Jocul s-a intrerupt automat. Pentru a reincepe jocul, scrie $tgcmdstart"
   tgquietstop
  } else {
   append _msg " [lindex $tgtrythenextone [rand [llength $tgtrythenextone]]]"
  }
  tggamemsg "[tgcolmiss]$_msg"
  if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} { tgstreakend }
  set tgstreak 0
  catch {unbind pubm -|- "$tgchan $tgcurrentanswer" tgcorrectanswer}
  if {$tgmaxmissed==0||$tgmissed<$tgmaxmissed} {
   set tgnextqtimer [utimer $tgtimenext tgnextq]
  }
  return
 } elseif {$tghintnum == 0} {
  set i 0
  set _hint {}
  set tghintcharsused {}
  foreach word [split $tgcurrentanswer] {
   regsub -all -- "\[A-Za-z0-9\]" $word $tghintchar _current
   lappend _hint $_current
  }
  if {$tgtimeanswer==1} {
   set tgtimestart [clock clicks -milliseconds]
  }
 } elseif {$tghintnum == 1} {
  set i 0
  set _hint {}
  while {$i<[llength [split $tgcurrentanswer]]} {
   set _word [lindex [split $tgcurrentanswer] $i]
   set j 0
   set _newword {}
   while {$j<[strlen $_word]} {
    if {$j==0} {
     append _newword [stridx $_word $j]
     lappend tghintcharsused $i,$j
    } else {
     if {[string is alnum [stridx $_word $j]]} {
      append _newword $tghintchar
     } else {
      append _newword [stridx $_word $j]
      lappend tghintcharsused $i,$j
     }
    }
    incr j
   }
   lappend _hint $_newword
   incr i
  }
  } else {
   set i 0
   set _hint {}
   while {$i<[llength [split $tgcurrentanswer]]} {
    set _word [lindex [split $tgcurrentanswer] $i]
    set j 0
    set _newword {}
    set _selected [rand [strlen $_word]]
    regsub -all -- "\[^A-Za-z0-9\]" $_word "" _wordalnum
    if {[strlen $_wordalnum]>=$tghintnum} {
     while {[lsearch $tghintcharsused $i,$_selected]!=-1||[string is alnum [stridx $_word $_selected]]==0} {
      set _selected [rand [strlen $_word]]
     }
    }
    lappend tghintcharsused $i,$_selected
    while {$j<[strlen $_word]} {
     if {[lsearch $tghintcharsused $i,$j]!=-1||[string is alnum [stridx $_word $j]]==0} {
      append _newword [stridx $_word $j]
     } else {
      if {[string is alnum [stridx $_word $j]]} {
       append _newword $tghintchar
      }
    }
    incr j
   }
   lappend _hint $_newword
   incr i
  }
 }
##### Shows Questions and Hints ####

          if {$tgalwaysshowq==1||$tghintnum==0} {
          tggamemsg "\00311,4Într.[expr $tgquestionnumber+1]: \003[tgcolqbody]$tgcurrentquestion\003"   
           }
          tggamemsg "[tgcolhint]\002\0038,2[expr $tghintnum?"Hint$tghintnum/$tgmaxhintcurrent":""]\002\003 [tgcolhint][expr $tgcapshint?"[strupr [join $_hint]]":"[join $_hint]"]\003               \00313[join $qval]\00313 puncte"
         set tghinttimer [utimer $tgtimehint tghint]
    }

#triggered when someone uses !top10 command
proc tgshowtop10 {nick host hand chan text} {
 global tgscores tgchan tgscorestotal
 if {[strlwr $chan]==[strlwr $tgchan]} {
  tggetscores
  if {$tgscorestotal>0} {
   if {$tgscorestotal>9} {
    set _max 9
   } else {
    set _max [expr $tgscorestotal-1]
   }
   set i 0
   while {$i<=$_max} {
    set _item [lindex $tgscores $i]
    set _nick [join [lindex [split $_item ,] 2]]
    set _score [join [lindex [split $_item ,] 0]]
    if {$i==0} {
     append _scores "[tgcolscr1]$_nick $_score"
    } elseif {$i==1} {
     append _scores ", [tgcolscr2]$_nick $_score"
    } elseif {$i==2} {
     append _scores ", [tgcolscr3]$_nick $_score"
    } else {
     append _scores ", [tgcolmisc1]$_nick $_score"
    }
    incr i
   }
   tggamemsg "[tgcolmisc1]Top 10: $_scores"
  } else {
   tggamemsg "[tgcolmisc1]Tabelul cu scoruri este gol."
  }
 }
}

#triggered when someone says the correct answer.
proc tgcorrectanswer {nick host hand chan text} {
 global tgcurrentanswer tghinttimer tgtimenext tgchan tgnextqtimer tgstreak tgstreakmin
 global tgscoresbyname tgranksbyname tgranksbynum tgcongrats tgscorestotal tgmissed
 global tgtimestart tgshowallscores tgrealnames tgscoresbyrank tgtimeanswer tgcapsanswer
 tggetscores
 if {![info exists tgranksbyname([strlwr $nick])]} {
  set _oldrank 0
 } else {
  set _oldrank $tgranksbyname([strlwr $nick])
 }
 tgincrscore $nick
 tggetscores
 set _newrank $tgranksbyname([strlwr $nick])
 set _timetoanswer ""
 if {$tgtimeanswer==1} {
  set _timetoanswer [expr [expr [clock clicks -milliseconds]-$tgtimestart]/1000.00]
 }
 set _msg "[tgcolmisc1][lindex $tgcongrats [rand [llength $tgcongrats]]] [tgcolmisc2]$nick[tgcolmisc1]! Raspunsul a fost [tgcolmisc2][expr $tgcapsanswer?"[strupr $tgcurrentanswer]":"$tgcurrentanswer"][tgcolmisc1].[expr $tgtimeanswer==1?" Ai raspuns in [tgcolmisc2]$_timetoanswer[tgcolmisc1] secunde.":""]"
 if {$_newrank<$_oldrank} {
  if {$_newrank==1} {
   append _msg " Acum esti pe primul loc!"
  } else {
   if {$tgshowallscores==0} {
    append _msg " Ai avansat in top!"
   } else {
    append _msg " Acum esti pe locul [tgcolmisc2][tgordnum $tgranksbyname([strlwr $nick])][tgcolmisc1] din [tgcolmisc2]$tgscorestotal[tgcolmisc1], in urma lui [tgcolmisc2]$tgrealnames($tgranksbynum([expr $_newrank-1]))[tgcolmisc1] cu [tgcolmisc2]$tgscoresbyrank([expr $_newrank-1])[tgcolmisc1] puncte."
   }
  }
 }
 tggamemsg "$_msg"
 if {$tgstreak!=0} {
  if {[lindex [split $tgstreak ,] 0]==[strlwr $nick]} {
   set tgstreak [strlwr $nick],[expr [lindex [split $tgstreak ,] 1]+1]
   if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} {
    tggamemsg "[tgcolstrk][tgcolmisc2]$nick[tgcolstrk] is on a winning streak! [tgcolmisc2][lindex [split $tgstreak ,] 1] [tgcolstrk]in a row so far!"
   }
  } else {
   if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} { tgstreakend }
   set tgstreak [strlwr $nick],1
  }
 } else {
  set tgstreak [strlwr $nick],1
 }
 set tgmissed 0
 tgshowscores $nick
 unbind pubm -|- "$tgchan $tgcurrentanswer" tgcorrectanswer
 killutimer $tghinttimer
 set tgnextqtimer [utimer $tgtimenext tgnextq]
}


#read current scores from file, sort and store in variable.
proc tggetscores {} {
 global tgscf tgscorestotal tgscores tgscoresbyname tgranksbyname tgranksbynum
 global tgrealnames tgscoresbyrank
 if {[file exists $tgscf]&&[file size $tgscf]>2} {
  set _sfile [open $tgscf r]
  set tgscores [lsort -dict -decreasing [split [gets $_sfile]]]
  close $_sfile
  set tgscorestotal [llength $tgscores]
 } else {
  set tgscores ""
  set tgscorestotal 0
 }
 if {[info exists tgscoresbyname]} {unset tgscoresbyname}
 if {[info exists tgranksbyname]} {unset tgranksbyname}
 if {[info exists tgrealnames]} {unset tgrealnames}
 if {[info exists tgranksbynum]} {unset tgranksbynum}
 set i 0
 while {$i<[llength $tgscores]} {
  set _item [lindex $tgscores $i]
  set _nick [lindex [split $_item ,] 2]
  set _lwrnick [lindex [split $_item ,] 3]
  set _score [lindex [split $_item ,] 0]
  set tgscoresbyname($_lwrnick) $_score
  set tgrealnames($_lwrnick) $_nick
  set tgranksbyname($_lwrnick) [expr $i+1]
  set tgranksbynum([expr $i+1]) $_lwrnick
  set tgscoresbyrank([expr $i+1]) $_score
  incr i
 }
 return
}

#increment someone's score.
proc tgincrscore {who} {
 global tgscores tgscf tgpointsperanswer tgscorestotal tgscoresbyname qval
 tggetscores
 if {$tgscorestotal>0} {
  set i 0
  if {![info exists tgscoresbyname([strlwr $who])]} {
   append _newscores "1,[expr 1000000000000.0/[unixtime]],$who,[strlwr $who] "
  }
  while {$i<[llength $tgscores]} {
   set _item [lindex $tgscores $i]
   set _nick [lindex [split $_item ,] 2]
   set _time [lindex [split $_item ,] 1]
   set _score [lindex [split $_item ,] 0]
   if {[strlwr $who]==[strlwr $_nick]} {
    append _newscores "[expr $_score+$qval],[expr 1000000000000.0/[unixtime]],$who,[strlwr $who][expr [expr [llength $tgscores]-$i]==1?"":"\ "]"
   } else {
    append _newscores "$_score,$_time,$_nick,[strlwr $_nick][expr [expr [llength $tgscores]-$i]==1?"":"\ "]"
   }
   incr i
  }
 } else {
  append _newscores "1,[expr 1000000000000.0/[unixtime]],$who,[strlwr $who]"
 }
 set _sfile [open $tgscf w]
 puts $_sfile "$_newscores"
 close $_sfile
 return
}

#shows the current scores on channel.
proc tgshowscores {nick} {
 global tgscores tgchan tgscorestotal tgshowallscores tgranksbyname tgranksbynum
 global tgscoresbyname tgrealnames tgscoresbyrank
 tggetscores
 set i 0
 if {$tgshowallscores} {
  while {$i<[llength $tgscores]} {
   set _item [lindex $tgscores $i]
   set _nick [lindex [split $_item ,] 2]
   set _score [lindex [split $_item ,] 0]
   if {$i==0} {
    append _scores "[tgcolscr1]$_nick $_score"
   } elseif {$i==1} {
    append _scores ", [tgcolscr2]$_nick $_score"
   } elseif {$i==2} {
    append _scores ", [tgcolscr3]$_nick $_score"
   } elseif {[onchan $_nick $tgchan]} {
    append _scores ", [tgcolmisc1]$_nick $_score"
   }
   incr i
  }
  tggamemsg "[tgcolmisc1]Scorurile: $_scores"
 } else {
  if {$tgranksbyname([strlwr $nick])==1} {
   set _tgt "."
  } else {
   set _tgt ", in urma lui [tgcolmisc2]$tgrealnames($tgranksbynum([expr $tgranksbyname([strlwr $nick])-1]))[tgcolmisc1] cu [tgcolmisc2]$tgscoresbyrank([expr $tgranksbyname([strlwr $nick])-1])[tgcolmisc1] puncte."
  }
  tggamemsg "[tgcolmisc2]$nick [tgcolmisc1]acum are [tgcolmisc2]$tgscoresbyname([strlwr $nick]) [tgcolmisc1][expr $tgscoresbyname([strlwr $nick])==1?"punct":"puncte"] si este pe locul [tgcolmisc2][tgordnum $tgranksbyname([strlwr $nick])] [tgcolmisc1]din [tgcolmisc2]$tgscorestotal[tgcolmisc1]$_tgt"
 }
}

#reset current scores.
proc tgresetscores {nick host hand text} {
 global tgscf tgscorestotal tgscores tgplaying
 if {[file exists $tgscf]&&[file size $tgscf]>2} {
  set _sfile [open $tgscf w]
  puts $_sfile ""
  close $_sfile
  set tgscores ""
  set tgscorestotal 0
 }
 tggamemsg "[tgcolrset]===== Tabelul cu scoruri a fost resetat de catre $nick! ====="
}

#triggered when a winning streak ends.
proc tgstreakend {} {
  global tgstreak tgrealnames
  tggamemsg "[tgcolstend]So much for [tgcolmisc2]$tgrealnames([lindex [split $tgstreak ,] 0])'s[tgcolstend] winning streak."
  return
}

####### Pentru autovoice #####

#triggered when someone joins trivia chan.
proc tgjoinmsg {nick host hand chan} {
global botnick tgplaying tgcmdhelp tgcmdstart tgflagsstart tgcmdstop tgflagsstop tgchan
global tgscorelookupjoin tgscoresbyname tgranksbyname tgscorestotal tgranksbynum tgrealnames
global tgscoresbyrank tgscores
tggetscores
if {$nick != $botnick} {
set _msg ""
if {[string match *users.undernet.org* $host ]} {return 0}
append _msg "Bine ati venit pe #radiofm unde $botnick va fi gazda voastrã. Jocul de trivia este"
if {$tgplaying==1} {
append _msg " \002pornit\002."
} else {
append _msg " \002oprit\002."
}
if {[matchattr $hand $tgflagsstart $tgchan]&&$tgplaying==0} {
append _msg " Pentru a incepe jocul scrie \002$tgcmdstart\002 pe $tgchan."
}
append _msg " Pentru ajutor scrie \002/MSG $botnick [strupr $tgcmdhelp]\002. Felicitari castigatorilor de luna trecuta.\002 Noua comanda la trivia: /msg $botnick rose <nick destinatar> <Mesaj atasat la trandafir> "
[tgpriv] $nick "$_msg"

if {![info exists tgscoresbyname([strlwr $nick])]} {
} elseif {$tgranksbyname([strlwr $nick])==1} {
tggamemsg "[tgcolmisc1]Salut [tgcolmisc2]$nick ![tgcolmisc1] Ai -> [tgcolmisc2]$tgscoresbyname([strlwr $nick]) [tgcolmisc1]<- [expr $tgscoresbyname([strlwr $nick])==1?"punct":"puncte"] ! Esti pe locul [tgcolmisc2][ordnumber $tgranksbyname([strlwr $nick])] [tgcolmisc1]din [tgcolmisc2]$tgscorestotal[tgcolmisc1]."
} else {
}
set i 0

while {$i<[llength $tgscores]} {
set _item [lindex $tgscores $i]
set _nick [lindex [split $_item ,] 2]
set _score [lindex [split $_item ,] 0]
if {$i<=9&&$nick==$_nick&&[botisop $tgchan]} {
putserv "MODE $tgchan +v $nick"
putserv "PRIVMSG $tgchan :[tgcolmisc1] Wowwwww, misto [tgcolmisc2]$nick [tgcolmisc1]! Te afli in primele 10 locuri si meriti sa primesti voice). Hai sa-i intrecem pe toti!!!"
}
incr i
}
}
}


#triggered when someone /msgs the bot with the score lookup command.
proc tgscorelookup {nick host hand text} {
 global tgscoresbyname tgranksbyname tgscorestotal tgrealnames
 if {$text==""} { set text $nick } else { set text [lindex [split $text] 0] }
 tggetscores
 if {![info exists tgscoresbyname([strlwr $text])]} {
  if {[strlwr $text]==[strlwr $nick]} {
   set _who "[tgcolmisc1]Tu esti"
  } else {
   set _who "[tgcolmisc2]$text [tgcolmisc1]is"
  }
  [tgpriv] $nick "[tgbold]$_who [tgcolmisc1]not pe lista cu scoruri."
 } else {
  if {[strlwr $text]==[strlwr $nick]} {
   set _who "[tgcolmisc1]Tu ai"
  } else {
   set _who "[tgcolmisc2]$tgrealnames([strlwr $text]) [tgcolmisc1]are"
  }
  [tgpriv] $nick "[tgbold]$_who [tgcolmisc2]$tgscoresbyname([strlwr $text])[tgcolmisc1] puncte, si este pe locul [tgcolmisc2][tgordnum $tgranksbyname([strlwr $text])] [tgcolmisc1]din [tgcolmisc2]$tgscorestotal[tgcolmisc1]."
 }
}

#triggered when someone /msgs the bot with the target lookup command.
proc tgtargetlookup {nick host hand text} {
 global tgscoresbyname tgranksbyname tgscorestotal tgranksbynum tgrealnames
 tggetscores
 if {![info exists tgscoresbyname([strlwr $nick])]} {
  [tgpriv] $nick "[tgbold][tgcolmisc1]Nu esti pe lista cu scoruri inca."
 } elseif {$tgranksbyname([strlwr $nick])==1} {
  [tgpriv] $nick "[tgbold][tgcolmisc1]Tu esti pe locul intai!"
 } else {
  [tgpriv] $nick "[tgbold][tgcolmisc1]Tu esti pe locul [tgcolmisc2]$tgscoresbyname([strlwr $nick])[tgcolmisc1]. Urmatoarea ta tinta este [tgcolmisc2]$tgrealnames($tgranksbynum([expr $tgranksbyname([strlwr $nick])-1])) [tgcolmisc1]cu [tgcolmisc2]$tgscoresbyname($tgranksbynum([expr $tgranksbyname([strlwr $nick])-1]))[tgcolmisc1], de pe locul [tgcolmisc2][tgordnum [expr $tgranksbyname([strlwr $nick])-1]] [tgcolmisc1]din [tgcolmisc2]$tgscorestotal[tgcolmisc1]."
 }
}

#triggered when someone /msgs the bot with the error reporting command.
proc tgerror {nick host hand text} {
 global tgquestionstotal tgquestionslist tgerrmethod tgerrfil tgerremail tgerrmailtmp
 if {$text==""||![string is int [lindex [split $text] 0]]} {
  [tgpriv] $nick "[tgbold][tgcolmisc1]Trebuie sa specifici numarul intrebarii."
  return
 }
 tgreadqdb
 set _qnum [lindex [split $text] 0]
 if {$_qnum>$tgquestionstotal} {
  [tgpriv] $nick "[tgbold][tgcolmisc1]Nu exista aceasta intrebare."
  return
 }
 set _qques [lindex [split [lindex $tgquestionslist [expr $_qnum-1]] |] 1]
 set _qans [lindex [split [lindex $tgquestionslist [expr $_qnum-1]] |] 0]
 set _desc [join [lrange [split $text] 1 end]]
 if {$_desc==""} { set _desc "Nici o alta informatie asupra acestei erori." }
 if {$tgerrmethod==1} {
  set _fname $tgerrmailtmp\trivia[rand 100000].tmp
  set _file [open $_fname w]
 } else {
  set _file [open $tgerrfil a]
 }
 puts $_file ""
 puts $_file "Error report generated [strftime %A,\ %d\ %B\ %Y\ @\ %H:%M:%S]"
 puts $_file "Reported by:\t$nick!$host"
 puts $_file "Question #:\t$_qnum"
 puts $_file "Question:\t$_qques"
 puts $_file "Answer:\t\t$_qans"
 puts $_file "Comments:\t$_desc"
 puts $_file "------------------------------"
 close $_file
 if {$tgerrmethod==1} {
  exec mail -s "trivia.tcl error report from $nick" $tgerremail < $_fname
  file delete $_fname
  [tgpriv] $nick "[tgbold][tgcolmisc1]Multumesc! Raportul tau asupra erorii a fost trimisa pe e-mail lui Jay-Cr."
 } else {
  [tgpriv] $nick "[tgbold][tgcolmisc1]Multumesc! Raportul tau asupra erorii a fost inregistrat si va fi verificat in cel mai scurt timp posibil."
 }
}

#triggered when someone /msgs the bot with the rules command.
proc tgrulesmsg {nick host hand text} {
 global tgrules
 [tgpriv] $nick "Regulile canalului sunt urmatoarele: $tgrules"
}

#triggered when someone /msgs the bot with the help command.
proc tggivehelp {nick host hand {text ""}} {
 global botnick tgcmdlookup tgcmdhelp tgcmdstart tgcmdstop tgchan tgflagsstop
 global tgcmdstop tgflagshint tgcmdhint tgflagsskip tgcmdskip tgflagsreset tgcmdreset
 global tgcmdtarget tgcmderror tgcmdrules tgflagsstart
 if {$text==""} {
  [tgpriv] $nick "Tu ai access la urmatoarele comenzi prin /MSG :"
  [tgpriv] $nick "Pentru a folosi,scrie /MSG $botnick <comanda>"
  [tgpriv] $nick "  \002[strupr $tgcmdrules]\002"
  [tgpriv] $nick "   -- Arata regulile canlului."
  [tgpriv] $nick "  \002[strupr $tgcmdlookup]\002 \[nick\]"
  [tgpriv] $nick "   -- Iti arata locul si scorul pentru \[nick\], daca este specificat,"
  [tgpriv] $nick "    altfel, iti va arata propriul tau loc & scor."
  [tgpriv] $nick "  \002[strupr $tgcmdtarget]\002"
  [tgpriv] $nick "   -- Iti arata locul si scorul al persoaei de pe locul"
  [tgpriv] $nick "    one above you."
  [tgpriv] $nick "  \002[strupr $tgcmderror]\002 <numar> \[descriere\]"
  [tgpriv] $nick "   -- Raporteaza o eroare in intrebarea cu numarul <numar>"
  [tgpriv] $nick "    Descrierea este optionala, dar ajutatoare."
  if {[matchattr $hand $tgflagsreset $tgchan]} {
   [tgpriv] $nick "  \002[strupr $tgcmdreset]\002"
   [tgpriv] $nick "   -- Reseteaza scorurile."
  }
  [tgpriv] $nick "Pentru o lista de comenzi, /MSG $botnick [strupr $tgcmdhelp] PUBCMDS"
 }
 if {[strlwr $text]=="pubcmds"} {
  [tgpriv] $nick "Tu ai access la urmatoarele comenzi:"
  if {[matchattr $hand $tgflagsstart $tgchan]} {
   [tgpriv] $nick "  \002$tgcmdstart\002 -- porneste jocul de trivia."
  }
  if {[matchattr $hand $tgflagsstop $tgchan]} {
   [tgpriv] $nick "  \002$tgcmdstop\002 -- opreste jocul de trivia."
  }
  if {[matchattr $hand $tgflagshint $tgchan]} {
   [tgpriv] $nick "  \002$tgcmdhint\002 -- arata un indiciu."
  }
  if {[matchattr $hand $tgflagsskip $tgchan]} {
   [tgpriv] $nick "  \002$tgcmdskip\002 -- sare peste intrebarea curenta."
  }
  [tgpriv] $nick "Pentru o lista de comezi /MSG, /MSG $botnick [strupr $tgcmdhelp]"
 }
}

proc tggamemsg {what} {
 global tgchan
 putquick "PRIVMSG $tgchan :[tgbold]$what"
}

#Returns ordinal version of number passed to it.
#i.e. [tgordnum 1] returns "1st", [tgordnum 33] returns "33rd"
#Surely there's an easier way to do this?
proc tgordnum {num} {
 set _last1 [string range $num [expr [strlen $num]-1] end]
 set _last2 [string range $num [expr [strlen $num]-2] end]
 if {$_last1=="1"&&$_last2!="11"} {
  return "[expr $num]st"
 } elseif {$_last1=="2"&&$_last2!="12"} {
  return "[expr $num]nd"
 } elseif {$_last1=="3"&&$_last2!="13"} {
  return "[expr $num]rd"
 } else {
  return "[expr $num]th"
 }
}
proc tgbold {} {
 global tgusebold
 if {$tgusebold==1} { return "\002" }
}
proc tgcolstart {} {
 global tgcolourstart
 if {$tgcolourstart!=""} { return "\003$tgcolourstart" }
}
proc tgcolstop {} {
 global tgcolourstop
 if {$tgcolourstop!=""} { return "\003$tgcolourstop" }
}
proc tgcolskip {} {
 global tgcolourskip
 if {$tgcolourskip!=""} { return "\003$tgcolourskip" }
}
proc tgcolerr {} {
 global tgcolourerr
 if {$tgcolourerr!=""} { return "\003$tgcolourerr" }
}
proc tgcolmiss {} {
 global tgcolourmiss
 if {$tgcolourmiss!=""} { return "\003$tgcolourmiss" }
}
proc tgcolqhead {} {
 global tgcolourqhead
 if {$tgcolourqhead!=""} { return "\003$tgcolourqhead" }
}
proc tgcolqbody {} {
 global tgcolourqbody
 if {$tgcolourqbody!=""} { return "\003$tgcolourqbody" }
}
proc tgcolhint {} {
 global tgcolourhint
 if {$tgcolourhint!=""} { return "\003$tgcolourhint" }
}
proc tgcolstrk {} {
 global tgcolourstrk
 if {$tgcolourstrk!=""} { return "\003$tgcolourstrk" }
}
proc tgcolscr1 {} {
 global tgcolourscr1
 if {$tgcolourscr1!=""} { return "\003$tgcolourscr1" }
}
proc tgcolscr2 {} {
 global tgcolourscr2
 if {$tgcolourscr2!=""} { return "\003$tgcolourscr2" }
}
proc tgcolscr3 {} {
 global tgcolourscr3
 if {$tgcolourscr3!=""} { return "\003$tgcolourscr3" }
}
proc tgcolrset {} {
 global tgcolourrset
 if {$tgcolourrset!=""} { return "\003$tgcolourrset" }
}
proc tgcolstend {} {
 global tgcolourstend
 if {$tgcolourstend!=""} { return "\003$tgcolourstend" }
}
proc tgcolmisc1 {} {
 global tgcolourmisc1
 if {$tgcolourmisc1!=""} { return "\003$tgcolourmisc1" }
}
proc tgcolmisc2 {} {
 global tgcolourmisc2
 if {$tgcolourmisc2!=""} { return "\003$tgcolourmisc2" }
}
proc tgpriv {} {
 global tgpriv2msg
 if {$tgpriv2msg==1} { return "putmsg" } else { return "putnotc" }
}

#this generates an html file with all the people on the chan with
#their score, as well as a list of all scores, sorted by rank
proc tghtml {} {
 global tgchan botnick tghtmlfile tghtmlrefresh server tgscoresbyname tgranksbyname
 global tgscorestotal tgranksbyname tgrealnames tgscoresbyrank tgranksbynum tgplaying
 global tgquestionstotal tghtmlrefreshtimer tghtmlfont
 tggetscores
 tgreadqdb
 set _file [open $tghtmlfile w]
 puts $_file "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"
 puts $_file "<html>"
 puts $_file " <head>"
 puts $_file "  <title>Canalul de trivia gazduit de $botnick: $tgchan pe [lindex [split $server :] 0]</title>"
 puts $_file "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
 puts $_file "  <meta http-equiv=\"refresh\" content=\"$tghtmlrefresh\">"
 puts $_file "  <meta name=\"generator\" content=\"trivia.tcl script pentru eggdrop. http://www.geocities.com/triviatcl/\">"
 puts $_file "  <style type=\"text/css\">"
 puts $_file "  <!--"
 puts $_file "  body,td{font-family:$tghtmlfont;font-size:13px;}"
 puts $_file "  a{text-decoration:none;color:#09f;}"
 puts $_file "  -->"
 puts $_file "  </style>"
 puts $_file " </head>"
 puts $_file " <body>"
 puts $_file "  <h1>$tgchan pe [lindex [split $server :] 0]</h1>"
 puts $_file "  <hr size=\"1\" noshade>"
 if {![onchan $botnick $tgchan]} {
  puts $_file "  <p>Hmmm... pentru nu stiu ce motiv nu sunt pe canalul $tgchan momentan. Te rog sa incerci mai tarziu.</p>"
 } else {
  puts $_file "  <p>Trivia este momentan <b>[expr $tgplaying==1?"pornita":"oprita"]</b>. Sunt <b>$tgquestionstotal</b> intrebari in total in baza de date."
  puts $_file "  <p>Oameni pe $tgchan chiar acum:<br>"
  puts $_file "  <table width=\"50%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><table width=\"100%\" cellspacing=\"3\" border=\"0\">"
  puts $_file "   <tr>"
  puts $_file "    <td><b>Nick</b></td>"
  puts $_file "    <td><b>Scor</b></td>"
  puts $_file "    <td><b>Loc</b></td>"
  puts $_file "    <td><b>Idle</b></td>"
  puts $_file "   </tr>"
  foreach nick [lsort [chanlist $tgchan]] {
   puts $_file "   <tr>"
   puts $_file "    <td>[expr [isop $nick $tgchan]?"@":""][expr [isvoice $nick $tgchan]?"+":""]$nick[expr [string match $nick $botnick]?" (acesta sunt eu!)":""]</td>"
   if {[info exists tgscoresbyname([strlwr $nick])]} {
    puts $_file "    <td>$tgscoresbyname([strlwr $nick])</td>"
   } else {
    puts $_file "    <td>-</td>"
   }
   if {[info exists tgranksbyname([strlwr $nick])]} {
    puts $_file "    <td>$tgranksbyname([strlwr $nick])</td>"
   } else {
    puts $_file "    <td>-</td>"
   }
   puts $_file "   <td>[expr [getchanidle $nick $tgchan]>10?"[getchanidle $nick $tgchan]m":"-"]</td>"
   puts $_file "   </tr>"
  }
  puts $_file "  </table></td></tr></table>"
 }
 if {$tgscorestotal>0} {
  puts $_file "  <p><small>Acum [expr $tgscorestotal==1?"este":"sunt"] momentan <b>$tgscorestotal</b> [expr $tgscorestotal==1?"nick":"nickuri"] in tabelul cu scoruri:<br>"
  set _rank 1
  while {$_rank<=$tgscorestotal} {
   puts $_file "  <b>$_rank</b>. $tgrealnames($tgranksbynum($_rank)) $tgscoresbyrank($_rank)<br>"
   incr _rank
  }
 } else {
  puts $_file "  <p><small><p>Momentan nu exista nici un nick in tabelul cu scoruri.<br>"
 }
 puts $_file "  </small></p>"
 puts $_file "  <hr size=\"1\" noshade>"
 puts $_file "  <small>Generat pe data de [strftime %A,\ %d\ %B\ %Y\ @\ %H:%M:%S] de catre <a href=\"http://www.geocities.com/triviatcl/\">trivia.tcl</a> pentru <a href=\"http://www.egghelp.org\">eggdrop</a>.<br>"
 puts $_file "  Aceasta pagina este automat reactualizata (si reimprospatata daca suporta browesrul tau) la fiecare [expr $tghtmlrefresh==1?"secunda":"$tghtmlrefresh secunde"].</small>"
 puts $_file " </body>"
 puts $_file "</html>"
 close $_file
 file rename -force $tghtmlfile~new $tghtmlfile
 set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
}