## Nerfbendr's Triviabot v6.0 Beta ©Copyright 2000+ by Nerfbendr - Created by Nerfbendr for #Chat_Central
## for Undernet started on April 21st, 2000! Please leave in all my texts...thanks!
##
## Excuse the sloppy scripting as this is my first official script...it may
## look like total crap and could probably be made faster if the coding was
## tighter but it runs sweet! Enjoy! 8)

## This script is dedicated to Harley, who was taken away from us on
## March 31st, 1999 when he was hit by a car, and to Rusty who was taken
## away from us on December 25th, 1999 by a heart attack...we love and miss
## you both very much...Nerf and Scrappy!

## Notes regarding the question files:

## NOTE: Any Trivia That Came Originally With the Triviabot Has Already Had The Changes
##       Below Done...Make These Changes To Your Own Trivia Banks or New Questions You Add!
##
## - Search and Replace all " to ' ...it interferes with the non-piracy
##   code and causes problems...8(
## - Questions seem to cut off around 140 characters with the anti-piracy
##   code running! Personally, I try to keep my questions around a maximum
##   of 120 or so characters long...

## Remember to read the Triviabot Manual that came with this script for the
## rundown on all the commands an' abilities of this little Triviabot! 8)

## Feel free to e-mail me at nerfbendr@ccs-webhosting.com if there's any
## questions, complaints or comments!
## Remember to visit my website at http://myokwe.net/ to 
## see how my other channelgames for Eggdrops are coming along! 8)

## Enjoy!
## Sincerely,
## Nerfbendr! *g0d 0f AlL tHiNgS f0aMy!* 8)

###########################################################################################
## TO DO LIST FOR TRIVIABOT V6.5:       (*) = Completed and in testing!
## 
## FIXES/CHANGES/NEW CODE INVOLVING CURRENT PERFORMANCE:
## =====================================================
## - Test all commands using [, ], {, }, ", \, and $ in arguments and nicks!
## - Correct problem involving trivia flooder protection code!
## (*)Fix problem where gradual hint doesn't fill-in next character
##   when next character is same as unknown character display in config!
## (*)When bot accepts alternate answer use it in "close enough" line!
## - Fix problem involving errored question reports that have more info
##   other than *just* the question number!
## - Check for above problem involving trivia editing code
## - Fix Glitch in "Player is in x place for the year" code when player
##   has oddities in their nick (IE: Bot reports players as in 1st place
##   for the year if they have {} in their nick...only visual glitch...
##   it doesn't actually jump them into first place or modify their points!)
## (*) Fix grammer glitch in "1 Ops/1 Non-Ops" bug in !next command!
## (*) Bot ignores spaces at start and end of trivia answers in trivia banks!
## (*) Triviabot flags all trivia with no question or answer (scrambles
##     excluded) to seperate file and treats them as errored/deleted
##     questions on initial start and in recount command!
## (*) Bot won't go to sleep when Team Mode is running! ;)
## (*) Fix hardcoded "15 seconds until next question" when a q is skipped!
##
## FIXES/CHANGES/NEW CODE INVOLVING MAIN TRIVIABOT PROBLEMS:
## =========================================================
## - Guard against abnormalities in Triviabot_Config.txt and report them
##   properly to triviaowner and write them to a Trivia_Troubleshoot.txt
##   file! (Inappropriate info for trivia owner, etc, etc...)
## - Add command to completely reset the triviabot!
##   (This involves a complete trivia recount and deletion of everything
##   in the AlreadyAsked directory!)
##
## FIXES/CHANGES INVOLVING TEAM TRIVIA:
## ====================================
## - Fix Oddball "Blank Line Bug" in Trivia Tips when < 2 mins left!
## - Also repair "1 minutes" grammer glitch in the above too!
## - Add option into config for Trivia playable ONLY if on a team (0/1 Enabler)
## - Battle Mode Needs To Be Planned out and Added In:
##
## Current Battle Mode Concept:
##  - When a team gets a question correct, all other teams lose points
##    of the same total (or 1/2 loss maybe?)that the winning team is awarded!
##
## NEW V6.5 ADDITIONS:
## ===================
## - Users can't use !hint command for x seconds in a round!
## - Add a banlist for Owner/Ops/Specific Users to use for banning certain
##   nicks from playing trivia!
## - Compatibility with trivia in the answer|question and q|a formats
## - Track number of questions used/day! (add info into d/w/m/y web scores?)
## - Track Number of Q's players guessed correctly per d/w/m/y! (text&web)
## - Language Files (Place all triviabot text in separate language file
##   and read it into the triviabot!)
## - Add Acrobot ability into Triviabot
## - Add ChaosBot ability into Triviabot
## - Add Madlibs ability into Triviabot
## - Add Tribot ability into Triviabot
## - Add code to make score merging easier!
## - !difference NICK1 NICK2 command: Displays rank/score differences 
##   for day/week/month/year bewteen NICK1 and NICK2
## - Have Bot check for existing file "triviadates.txt", if it exists, read
##   it and search for the current day (check this when the dayscores change
##   from one day to the next ONLY!), if day exists read the triviabank name
##   to use for that day! Format is like so:
##   
##   MONTH/DAY STARTTIME ENDTIME GAMEMODE     BANKNAME         BOTNAME    SPECIAL TOPIC (OPTIONAL)
##   10/31      00:01     23:59   Trivia  HalloweenTrivia.qst TrikRTriv 7,1 0^O^ ^O^ ^O^ 7Happy Halloween Trivia From Everyone in $triviachannel! 0^O^ ^O^ ^O^
##   12/24        NA        NA    Trivia  XMasTrivia.qst      XMasTriv Merry XMas Everyone! From all of us to all of you!
##   12/26        NA        NA    Trivia  random              Jigglypuf NA
##   
##   - On every October 31st between 00:01 and 23:59 the bot will swap
##     to Trivia Mode, use HalloweenTrivia.qst for its bank, change
##     its nick to TrikRTriv and use the special topic change.
##   - On every Dec 24th the bot will swap to Trivia Mode, use XMasTrivia for
##     its bank, XMasTriv for its nick and use the special topic change
##     until Dec 26th, where it will use all regular banks (via random setting)
##     and swap its nick back to Jigglypuf.
##     
##     *** NOTE: NA is a filler which the bot will treat as a setting to reset
##               back to the settings of the actual game mode in Config.txt ***
##   
## - Remove the (#?????????) info from player guesses if on msn chat using
##   comic mode
## - Strip all colors and other non-guess characters from player guesses!
## - Check for player answers to have capital letters at the beginning...
##   If constant occurence (after x times in a row) (2-3?) than chances
##   are player is cheating via search engine...place on a temp_ignore
##   list for x minutes (60?)
## - Determine format for recording text/webpage formats of team trivia
##   scores
## - Enhance the fuzzy logic mode for determining closeness of player answers
## - Add command for bot to change servers
## - Add command for changing channels
## (*)If nobody answers the question, bot gets a point! (It's missing!!!) 8(
##
## LAST CHANGE TO V6.5 BEFORE ACTUAL RELEASE:
## ==========================================  
## - Rename all variables to be confusing to all that wish to tamper
##   with the code!
## - Create new form of dedication protection!
## - Create program for creating/editing/upgrading triviabot config file!
##
###########################################################################################
###########################################################################################
### THE LINES BELOW ARE HERE IN CASE YOU CHANGE ANY OF THE TRIGGERS TO SAVE YOU FROM    ###
### HAVING TO DIG THROUGH THE TCL TO FIND THE HELP MENU...*HOWEVER* MY ONLY REQUEST     ###
### HERE IS PLEASE DO NOT REMOVE MY NAME, E-MAIL, WEBSITE ADDRESS OR THE DEDICATION OF  ###
### THE TRIVIABOT IN THE 'DEDICATION' LINE...IF THIS IS A PROBLEM FOR YOU THEN PLEASE   ###
### USE SOMEONE ELSE'S SCRIPT FOR YOUR BOT...THANK YOU!                                 ###
###########################################################################################
set dedication "6Welcome to #Triviachat - please visit http://z.myjp.net/ for latest trivia scores and players standing ... enjoy!"
set helpline1 "4Player Commands: !trivia1 - 4Starts Trivia, !next1 - 4Skips current question if enough players request it, !repeat1 - 4shows current question, !hint1 - 4Gives A Hint, !server1 - 4Show Server Triviabot Is On, !won NICK1 - 4Shows Progress Of NICK, !rank NICK1 - 4Shows Rank Of NICK, !top10fastest1 - 4Top 10 Fastest Players !lastanswer1 - 4Shows Answer From Previous Question!"
set helpline2 "4Player Commands: !top10streakers1 - 4Top 10 Winning Streaks, !daytop101 - 4Day's Top 10, !weektop101 - 4Week's Top 10, !top101 - 4Month's Top 10, !yeartop101 - 4Year's Top 10, !error QUESTION NUMBER1 - 4Report An Errored Question, /msg BOTNAME add QUESTION*ANSWER1 - 4Submits Trivia Question, /msg BOTNAME comment YOUR COMMENT1 - 4Sends Comment/Error Report, 4!help1 - 4This Menu!"
set helpline3 "2Op Commands:/msg BOT recount1 - 2Retotals All Available Trivia Banks !trivquit1 - 2Stops Trivia /msg BOT changetopic1 - 2Swap Channel Topic To Trivia Topic /msg BOT trivreset BANKNAME1 - 2Reset Already Asked Questions /msg BOT swapbank BANKNAME1 - 2Swaps Trivia Banks  /msg BOT check NUMBER1 - 2Check Specific Question"
set helpline4 "2Op Commands:/msg BOT edit NUMBER1 - 2Edit Specific Question /msg BOT delete NUMBER1 - 2Delete Specific Question /msg BOT reconfig1 - 2Re-loads config file /msg BOT update1 - 2Update website with latest scores /msg BOT transfer NICK1 NICK21 - 2Transfer NICK1 scores to NICK2  /msg BOT adjust NICK POINTS1 - 2Adjust NICK's score by POINTS!"
set helpline5 "3Team Trivia Commands: !TeamTrivia1 - 3Starts/Stops Team Trivia, !Join1 - 3Join a Team, !Remove1 - 3Remove Yourself From A Team, !Teams1 - 3Display Team Stats!"
###########################################################################################

set TeamNames ""
set CurrentTeamPlayerTotals "0 0 0 0 0 0 0 0 0 0"
set TeamPlayers ""
set TeamPoints "0 0 0 0 0 0 0 0 0 0"
set IndividualTeamPoints ""
set TeamNamesToUse "red blue purple green brown cyan yellow orange black white"
set colorteamnamestouse "0,4red 0,2blue 0,6purple 0,3green 0,5brown  1,11cyan 1,8yellow 1,7orange 0,1black 1,0white"
set teamstarttime ""
set teamminstart ""
set teamsecondstart ""
set teamendtime ""
set teamminend ""
set teamsecondend ""

utimer 30 "TeamPlayersStillHere"
set pointdroppedflag 0
###########################################################################################
##   *UNLESS YOU WISH TO MESS WITH COLORS, TEXTS OR TRIGGERS DON'T EDIT BELOW HERE!*     ##
###########################################################################################

##################### ALL COMMAND TRIGGERS FOR THE TRIVIABOT ######################
bind pub - !trivia StartTrivia
bind pub - !stop StopTrivia
bind pub - !next NormalUserNextQuestion
bind pub - !top10 Top10
bind pub - !topten Top10
bind pub - !won SpecificPlayerScore
bind pub - !repeat ShowQuestionAndHint
bind pub - !hint GiveAHint
bind pub - !!hint QuitUsingThisCommand
bind pub - !!vowel QuitUsingThisCommand
bind pub - !!start QuitUsingThisCommand
bind pubm - "*" CheckPlayerGuess
bind pub - !help TrivMenu
bind join - * TriviaWelcome
bind pub - !server Server
bind msg - add UserTriviaAdditions
bind msg - comment UserComments
bind pub - !error ErroredQuestions
bind msg - check CheckErroredQuestion
bind pub - !top10fastest Top10FastAnswers
bind pub - !top10streakers Top10Streakers
bind pub - !lastanswer LastAnswerproc
bind pub - !last LastAnswerproc
bind pub - !rank SpecificPlayerRank

bind msg - changetopic ChangeChannelTopic
bind part - * LeavingSoSoon
bind msg - trivreset ResetAlreadyAskedQuestionFile
bind msg - edit RemoteQuestionEditor
bind msg - delete RemoteQuestionDeleter
bind pub - !daytop10 DailyTop10
bind pub - !daytopten DailyTop10
bind pub - !daytop10 DailyTop10
bind pub - !daytopten DailyTop10
bind pub - !weektop10 WeeklyTop10
bind pub - !weektopten WeeklyTop10
bind pub - !monthtop10 Top10
bind pub - !monthtopten Top10
bind msg - swapbank SwapBanks
bind pub - !yeartop10 YearlyTop10
bind pub - !yeartopten YearlyTop10
bind msg - recount ReCount
bind msg - resync SyncScores
bind msg - reconfig ReadConfig
bind msg - update Autoftpsend
bind msg - transfer ScoreTransfer
bind msg - adjust ScoreAdjuster
bind msg - !trivia StartTrivia
bind msg - !trivquit StopTrivia
bind msg - !next NormalUserNextQuestion
bind msg - !top10 Top10
bind msg - !topten Top10
bind msg - !won SpecificPlayerScore
bind msg - !repeat ShowQuestionAndHint
bind msg - !hint GiveAHint
bind msg - !!hint QuitUsingThisCommand
bind msg - !!vowel QuitUsingThisCommand
bind msg - !!start QuitUsingThisCommand
bind msg - !help TrivMenu
bind msg - !server Server
bind msg - !error ErroredQuestions
bind msg - !top10fastest Top10FastAnswers
bind msg - !top10streakers Top10Streakers
bind msg - !lastanswer LastAnswerproc
bind msg - !last LastAnswerproc
bind msg - !rank SpecificPlayerRank
bind msg - !daytop10 DailyTop10
bind msg - !daytopten DailyTop10
bind msg - !daytop10 DailyTop10
bind msg - !daytopten DailyTop10
bind msg - !weektop10 WeeklyTop10
bind msg - !weektopten WeeklyTop10
bind msg - !monthtop10 Top10
bind msg - !monthtopten Top10
bind msg - !yeartop10 YearlyTop10
bind msg - !yeartopten YearlyTop10

bind pub - !newchan NewChan
bind msg - !newchan NewChan

###################################################################################

####################### TOUCH NOTHING IN THE AREA BELOW ###########################
set nickforrank ""
set swapbankflag 0
set origqfilelength 0
set LastAnswer "Nothing"
set DisplayAnswerFlag 0
set minstart 0
set hintalreadygiven 0
set alreadygoing 0
set triviastoppedflag 1
set alreadyguessed 0
set wontimes 1
set wonbefore "Nobody"
set winners ""
set headhoncho ""
set qnumber 0
set qaline 0
set triviavalue 5
set origtrivvalue 5
set nextquestioncounter 0
set server $server
set dater [unixtime]
set datechecker [ctime $dater]
set prevmonthfilename ""
set monthhtmlfilename ""
set monthfilename ""
set qafile "TriviaBanks/General.qst"
set alreadyaskedfile "AlreadyAsked/AlreadyAskedgeneral.qst"
set timeinformed 0
set answer ""
set hint ""
set pointdrops 3
set pointdropcounter 0
set qtotal 0
set AATrackerEnable 0
set TransferOpAllowed 0
set TransferValidUsers ""
set TeamOpAllowed 0
set TeamValidUsers ""

## VariablesForDailyAndWeeklyTop10Stuff!
set dayfilename ""
set prevdayfilename ""
set dayhtmlfilename ""
set weekfilename ""
set prevweekfilename ""
set weekhtmlfilename ""
set yearfilename ""
set yearhtmlfilename ""
set prevyearfilename ""
##
set triviaowner ""
set triviachannel "#Tester3"
set validbanks ""
set nextenable ""
set nonopsnumber ""
set opsnumber ""
set hintenable ""
set minhintletters ""
set maxhintletters ""
set showserver ""
set autojoin ""
set joinmsg ""
set autoquit ""
set quitmsg ""
set EnableAds ""
set AdDelay ""
set adcounter ""
set TipEnable ""
set tipcounter ""
set TrivDelay ""
set HintCharacter ""
set botsleep ""
set hecklerenable ""
set hecklecounter ""
set repeater ""
set repeaternumber ""
set triviavalue ""
set nontriviapiracy ""
set pointdropdelay 15
set showquestioneachpointdrop 0
set Cheaters ""
set secondstart 0
set fastanswerfilename "GenericScoresTEXT/FastestPlayers.txt"
set fastanswerhtmlfilename "GenericScoresHTML/FastestPlayers.html"
set streakfilename "GenericScoresTEXT/TopStreakers.txt"
set streakhtmlfilename "GenericScoresHTML/TopStreakers.html"
set usercounter 0
set qafilelength 0
set qtotal 0
set ownerhost ""
set triviavalidhosts ""
set trivquitvalidhosts ""
set qcheckvalidhosts ""
set changetopicvalidhosts ""
set trivresetvalidhosts ""
set editvalidhosts ""
set deletevalidhosts ""
set swapbankvalidhosts ""
set recountvalidhosts ""
set syncvalidhosts ""
set readconfigvalidhosts ""
set TransferValidHosts ""
set autoftpenable ""
set updateopallowed ""
set updatevalidusers ""
set updatevalidhosts ""
set ftpaddress ""
set ftpport ""
set ftplogin ""
set ftppass ""
set ftpdir ""
set ftpdelay ""
set TeamValidHosts ""
set teamenable ""
set maxteams ""
set maxteamplayers ""
set maxteampoints ""
set teamduration ""
set teammode ""
set CheaterHosts ""
set pointdropdecrease 1
set pointdrophintdecrease 1
set origpointdrophintdecrease 1

set modifyopallowed 0
set modifyvalidusers 0
set modifyvalidhosts 0
set hinttimes 1
set percentagehintenable 0
set hintpercentage 50
set gradhinttitletextcolor 0
set gradhinttitlebgcolor 0
set answertitletextcolor 0
set answertitlebgcolor 0
set qnumbold 0
set qbold 0
set htitlebold 0
set hbold 0
set gradhinttitlebold 0
set gradhintbold 0
set answertitlebold 0
set answerbold 0

set hintcounter 0
set ucqvenable 0
set ucqvpercent 20
set ucqvhintpercent 50
set marksplitter 250

set bonusqenable 0
set bonuslengths 0
set bonusvalues 0
set bonusdrops 0

set initialtriviadisplaydelay 0
set nickyearranks ""
set nickyearmarker 0
set nickmonthranks ""
set nickmonthmarker 0
set nickdayranks ""
set nickdaymarker 0
set nickweekranks ""
set nickweekmarker 0
set lastwinner "Nerfbendr"

set streakbonusenable 1
set streakinterval 3
set streakbonus 10
set hintmethods "1 1 1 1"
set knowncolor 9
set unknowncolor 13
set multipleenable 1
set fuzzyenable 0
set rankupdisplay 1
set pointsleftdisplay 1
set playeraheaddisplay 2
### ALL VARS BELOW ARE FOR SCRAMBLE GAMEPLAY
set gamemode 2
set gamemodepercent "75 25"
set scramblebanks "General.qst"
set sbankpercents "100"
set scramblepvmethod 1
set scramblepresetvalue 10
set scrletters "0 5 10 15 20"
set scrvalues "10 25 50 100 250"
set scrdrops "2 5 10 20 50"
set scrptdrops 3
set scrptdropseconds 15
set scrcluedisplay 1
set scrhintptdrop 2
set scrminhintletters 3
set scrmaxhintletters 5
set scrmaxhints 1
set scrpercenthintenable 1
set scrhintpercent 50
set scrhintprocess "1 1 0"
set ScrambleRoundChosen 0

set orig_validbanks "Dictionary1.qst Dictionary2.qst Dictionary3.qst"
set orig_frequency "33 34 33"
set orig_trivvalue 5
set orig_bonuslengths "0 5 10 15 20"
set orig_bonusvalues "10 25 50 100 250"
set orig_bonusdrops "2 5 10 20 50"
set orig_pointdrops 3
set orig_pointdropdelay 15
set orig_pointdropdecrease 1
set orig_minhintletters 3
set orig_maxhintletters 5
set orig_hinttimes 1
set orig_percentagehintenable 1
set orig_hintpercentage 50
set orig_hintmethods "1 1 0"
set currentscramble ""
set scrcluegiven 0

set scrknown 11
set scrunknown 12
set scrqtc 7
set scrqbc 10
set scratc 7
set scrabc 10
set scrhtc 7
set scrhbc 10

set orig_knowncolor 9
set orig_unknowncolor 13
set orig_QText 8
set orig_QBackground 2
set orig_AText 0
set orig_ABackground 2
set orig_HText 0
set orig_HBackground 2

set enabletopicchange 1
set AdsToUse ""
set TipsToUse ""
set HecklesToUse ""    
set TopicLeftBorder ""    
set TopicRightBorder ""    
set AnswerDisplayersToUse ""    
set Greet1ToUse ""    
set Greet2ToUse ""  

set topxtipdisplayenable 1
set topxdisplaypercent 25
set topxfiles "1 1 1 1 1 1 1 1 1"
set topxfilepercent "15 15 15 15 10 10 10 5 5"
set topxplayers "10 5 5 3 10 5 5 5 5"
set top5textcolors "0 0 0 0 0"
set top5bgcolors "3 2 4 5 10"
set topxdefaulttextcolor 0
set topxdefaultbgcolor 14
set topxtitletextcolor 8
set topxtitlebgcolor 6
set topxotherintervaldisplayenable 1
set topxotherintervalpercent 25

set qnumber 0
set qaline 0
set lcounter 0
###################################################################################
set antifloodenable 1
set floodprotectiontimer 5
##
utimer 1 "StartReadConfig blah blah blah blah blah"
proc StartReadConfig {nick uhost hand chan args} {
global TeamNames TeamNamesToUse colorteamnamestouse topxtipdisplayenable topxdisplaypercent topxfiles topxfilepercent topxplayers top5textcolors top5bgcolors topxdefaulttextcolor topxdefaultbgcolor topxtitletextcolor topxtitlebgcolor topxotherintervaldisplayenable topxotherintervalpercent AdsToUse TipsToUse HecklesToUse TopicLeftBorder TopicRightBorder AnswerDisplayersToUse Greet1ToUse Greet2ToUse enabletopicchange scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc origtrivvalue triviaowner ownerhost nameofbot triviachannel validbanks frequency randommode sendanswertoowner autovoiceenable DisplayAnswerEnable lastanswerenable autovoicesynch autovoicescore fastclear streakclear nextenable opsnumber nonopsnumber hintenable minhintletters maxhintletters hinttimes percentagehintenable hintpercentage showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay TipEnable TrivDelay ManualTrivDelay HintCharacter botsleep hecklerenable repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable QText QBackground AText ABackground HText HBackground PAText PABackground QNText QNBackground gradhinttitletextcolor gradhinttitlebgcolor answertitletextcolor answertitlebgcolor qnumbold qbold htitlebold hbold gradhinttitlebold gradhintbold answertitlebold answerbold pointdrops pointdropdelay pointdropdecrease pointdrophintdecrease manualpointdropdelay showquestioneachpointdrop showquestioninfoeachpointdrop displayenable antifloodenable floodprotectiontimer IntervalClueEnable FillInLettersEnable AATrackerEnable triviaopallowed triviavalidusers triviavalidhosts trivquitopallowed trivquitvalidusers trivquitvalidhosts qcheckopallowed qcheckvalidusers qcheckvalidhosts changetopicopallowed changetopicvalidusers changetopicvalidhosts trivresetopallowed trivresetvalidusers trivresetvalidhosts editopallowed editvalidusers editvalidhosts deleteopallowed deletevalidusers deletevalidhosts swapbankopallowed swapbankvalidusers swapbankvalidhosts Cheaters CheaterHosts recountopallowed recountvalidusers recountvalidhosts syncopallowed syncvalidusers syncvalidhosts readconfigopallowed readconfigvalidusers readconfigvalidhosts TransferOpAllowed TransferValidUsers TransferValidHosts modifyopallowed modifyvalidusers modifyvalidhosts autoftpenable updateopallowed updatevalidusers updatevalidhosts ftpaddress ftpport ftplogin ftppass ftpdir ftpdelay TeamOpAllowed TeamValidUsers TeamValidHosts teamenable maxteams maxteamplayers maxteampoints teamduration teammode ucqvenable ucqvpercent ucqvhintpercent bonusqenable bonuslengths bonusvalues bonusdrops initialtriviadisplaydelay streakbonusenable streakinterval streakbonus hintmethods knowncolor unknowncolor multipleenable fuzzyenable rankupdisplay pointsleftdisplay playeraheaddisplay gamemode gamemodepercent scramblebanks sbankpercents scramblepvmethod scramblepresetvalue scrletters scrvalues scrdrops scrptdrops scrptdropseconds scrcluedisplay scrhintptdrop scrminhintletters scrmaxhintletters scrmaxhints scrpercenthintenable scrhintpercent scrhintprocess orig_knowncolor orig_unknowncolor orig_QText orig_QBackground orig_AText orig_ABackground orig_HText orig_HBackground
################################### START OF READ CONFIG FILE CODE ############
set f [open "Triviabot_Config.txt" r]
set variables "triviaowner ownerhost nameofbot triviachannel validbanks frequency randommode sendanswertoowner autovoiceenable DisplayAnswerEnable lastanswerenable autovoicesynch autovoicescore fastclear streakclear nextenable opsnumber nonopsnumber hintenable minhintletters maxhintletters hinttimes percentagehintenable hintpercentage showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay TipEnable TrivDelay ManualTrivDelay HintCharacter botsleep hecklerenable repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable QText QBackground AText ABackground HText HBackground PAText PABackground QNText QNBackground gradhinttitletextcolor gradhinttitlebgcolor answertitletextcolor answertitlebgcolor qnumbold qbold htitlebold hbold gradhinttitlebold gradhintbold answertitlebold answerbold pointdrops pointdropdelay pointdropdecrease pointdrophintdecrease manualpointdropdelay showquestioneachpointdrop showquestioninfoeachpointdrop displayenable antifloodenable floodprotectiontimer IntervalClueEnable FillInLettersEnable AATrackerEnable triviaopallowed triviavalidusers triviavalidhosts trivquitopallowed trivquitvalidusers trivquitvalidhosts qcheckopallowed qcheckvalidusers qcheckvalidhosts changetopicopallowed changetopicvalidusers changetopicvalidhosts trivresetopallowed trivresetvalidusers trivresetvalidhosts editopallowed editvalidusers editvalidhosts deleteopallowed deletevalidusers deletevalidhosts swapbankopallowed swapbankvalidusers swapbankvalidhosts Cheaters CheaterHosts recountopallowed recountvalidusers recountvalidhosts syncopallowed syncvalidusers syncvalidhosts readconfigopallowed readconfigvalidusers readconfigvalidhosts TransferOpAllowed TransferValidUsers TransferValidHosts modifyopallowed modifyvalidusers modifyvalidhosts autoftpenable updateopallowed updatevalidusers updatevalidhosts ftpaddress ftpport ftplogin ftppass ftpdir ftpdelay TeamOpAllowed TeamValidUsers TeamValidHosts teamenable maxteams maxteamplayers maxteampoints teamduration teammode ucqvenable ucqvpercent ucqvhintpercent bonusqenable bonuslengths bonusvalues bonusdrops initialtriviadisplaydelay streakbonusenable streakinterval streakbonus hintmethods knowncolor unknowncolor multipleenable fuzzyenable rankupdisplay pointsleftdisplay playeraheaddisplay gamemode gamemodepercent scramblebanks sbankpercents scramblepvmethod scramblepresetvalue scrletters scrvalues scrdrops scrptdrops scrptdropseconds scrcluedisplay scrhintptdrop scrminhintletters scrmaxhintletters scrmaxhints scrpercenthintenable scrhintpercent scrhintprocess scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc enabletopicchange topxtipdisplayenable topxdisplaypercent topxfiles topxfilepercent topxplayers top5textcolors top5bgcolors topxdefaulttextcolor topxdefaultbgcolor topxtitletextcolor topxtitlebgcolor topxotherintervaldisplayenable topxotherintervalpercent"
set configindex 0
  set g [open "Config_Output.txt" w]
  puts $g "TriviaBot/Scramblebot v6.0 Config Debug File:"
  close $g
  set arraysettings 0
  set arrayflag 0
  while {[gets $f line] != -1} {
   if {$arraysettings == 0} {
    if {[string range $line 0 1] != "##"} {
     set [lindex $variables $configindex] $line
     set g [open "Config_Output.txt" a]
     puts $g "[lindex $variables $configindex] $line"
     close $g
   if {[lindex $variables $configindex] == "topxotherintervalpercent"} {
    set arraysettings 1
   }
     incr configindex
    }
   }

   
   
    if {$arraysettings == 1} {
     if {[string range $line 0 3] != "####"} {
      if {$line == "## Ads To Use"} {
       set arrayflag 1
      }
      if {$line == "## Tips To Use"} {
       set arrayflag 2
      }
      if {$line == "## Heckles To Use"} {
       set arrayflag 3
      } 
      if {$line == "## Left Borders"} {
       set arrayflag 4
      } 
      if {$line == "## Right Borders"} {
       set arrayflag 5
      }
      if {$line == "## Answer Displayers At the End of a Round"} {
       set arrayflag 6
      }
      if {$line == "## Initial Greetings For Known Players: Part I"} {
       set arrayflag 7
      }
      if {$line == "## Initial Greetings For Known Players: Part II"} {
       set arrayflag 8
      }
      #### ADD APPROPRIATE LINES INTO APPROPRIATE ARRAYS HERE
      if {[string range $line 0 1] != "##"} {
      if {$arrayflag == 1} {
       append AdsToUse "$line "    
      }
      if {$arrayflag == 2} {
      append TipsToUse "$line "    
      }
      if {$arrayflag == 3} {
      append HecklesToUse "$line "    
      }
      if {$arrayflag == 4} {
      append TopicLeftBorder "$line "    
      }
      if {$arrayflag == 5} {
      append TopicRightBorder "$line "    
      }
      if {$arrayflag == 6} {
      append AnswerDisplayersToUse "$line "    
      }
      if {$arrayflag == 7} {
      append Greet1ToUse "$line "    
      }
      if {$arrayflag == 8} {
      append Greet2ToUse "$line "    
      }
     }
    }     
   }
  }
      set g [open "Config_Output.txt" a]
      puts $g "$AdsToUse"
      puts $g "$TipsToUse"
      puts $g "$HecklesToUse"
      puts $g "$TopicRightBorder"
      puts $g "$TopicLeftBorder"
      puts $g "$AnswerDisplayersToUse"
      puts $g "$Greet1ToUse"
      puts $g "$Greet2ToUse"
      close $g
###############################################################################
close $f
set origtrivvalue $triviavalue
putlog "\002\'Nerfbendrs Triviabot v6.0 Beta-Registered to $triviaowner on $triviachannel'\002 (©Nerfbendr 2001) loaded"
utimer 5 "StartReCount"
## These two lines start the command flood protection and advertiser routines when bot starts!
utimer 10 "ClearFloodProtections"
utimer 15 "Advertiser"
set counter 0
  while {$counter != $maxteams} {
   append TeamNames "[lindex $TeamNamesToUse $counter] "
   append cnames " [lindex $colorteamnamestouse $counter]"
   incr counter
 }
 set colorteamnamestouse "$cnames"
 if {$autoftpenable == 1} {
 utimer $ftpdelay "Autoftpsend blah $ownerhost blah blah blah"
}
return
}


proc ReadConfig {nick uhost hand chan args} {
global TeamNames TeamNamesToUse colorteamnamestouse usercounter topxtipdisplayenable topxdisplaypercent topxfiles topxfilepercent topxplayers top5textcolors top5bgcolors topxdefaulttextcolor topxdefaultbgcolor topxtitletextcolor topxtitlebgcolor topxotherintervaldisplayenable topxotherintervalpercent AdsToUse TipsToUse HecklesToUse TopicLeftBorder TopicRightBorder AnswerDisplayersToUse Greet1ToUse Greet2ToUse enabletopicchange scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc scrhintptdrop origpointdrophintdecrease antifloodenable commandusers ownerhost recountopallowed recountvalidhosts origtrivvalue triviaowner ownerhost nameofbot triviachannel validbanks frequency randommode sendanswertoowner autovoiceenable DisplayAnswerEnable lastanswerenable autovoicesynch autovoicescore fastclear streakclear nextenable opsnumber nonopsnumber hintenable minhintletters maxhintletters hinttimes percentagehintenable hintpercentage showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay TipEnable TrivDelay ManualTrivDelay HintCharacter botsleep hecklerenable repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable QText QBackground AText ABackground HText HBackground PAText PABackground QNText QNBackground gradhinttitletextcolor gradhinttitlebgcolor answertitletextcolor answertitlebgcolor qnumbold qbold htitlebold hbold gradhinttitlebold gradhintbold answertitlebold answerbold pointdrops pointdropdelay pointdropdecrease pointdrophintdecrease manualpointdropdelay showquestioneachpointdrop showquestioninfoeachpointdrop displayenable antifloodenable floodprotectiontimer IntervalClueEnable FillInLettersEnable AATrackerEnable triviaopallowed triviavalidusers triviavalidhosts trivquitopallowed trivquitvalidusers trivquitvalidhosts qcheckopallowed qcheckvalidusers qcheckvalidhosts changetopicopallowed changetopicvalidusers changetopicvalidhosts trivresetopallowed trivresetvalidusers trivresetvalidhosts editopallowed editvalidusers editvalidhosts deleteopallowed deletevalidusers deletevalidhosts swapbankopallowed swapbankvalidusers swapbankvalidhosts Cheaters CheaterHosts recountopallowed recountvalidusers recountvalidhosts syncopallowed syncvalidusers syncvalidhosts readconfigopallowed readconfigvalidusers readconfigvalidhosts TransferOpAllowed TransferValidUsers TransferValidHosts modifyopallowed modifyvalidusers modifyvalidhosts autoftpenable updateopallowed updatevalidusers updatevalidhosts ftpaddress ftpport ftplogin ftppass ftpdir ftpdelay TeamOpAllowed TeamValidUsers TeamValidHosts teamenable maxteams maxteamplayers maxteampoints teamduration teammode ucqvenable ucqvpercent ucqvhintpercent bonusqenable bonuslengths bonusvalues bonusdrops initialtriviadisplaydelay streakbonusenable streakinterval streakbonus hintmethods knowncolor unknowncolor multipleenable fuzzyenable rankupdisplay pointsleftdisplay playeraheaddisplay gamemode gamemodepercent scramblebanks sbankpercents scramblepvmethod scramblepresetvalue scrletters scrvalues scrdrops scrptdrops scrptdropseconds scrcluedisplay scrhintptdrop scrminhintletters scrmaxhintletters scrmaxhints scrpercenthintenable scrhintpercent scrhintprocess orig_knowncolor orig_unknowncolor orig_QText orig_QBackground orig_AText orig_ABackground orig_HText orig_HBackground

if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$recountopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $recountvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $recountvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################

################################### START OF READ CONFIG FILE CODE ############
set f [open "Triviabot_Config.txt" r]
set variables "triviaowner ownerhost nameofbot triviachannel validbanks frequency randommode sendanswertoowner autovoiceenable DisplayAnswerEnable lastanswerenable autovoicesynch autovoicescore fastclear streakclear nextenable opsnumber nonopsnumber hintenable minhintletters maxhintletters hinttimes percentagehintenable hintpercentage showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay TipEnable TrivDelay ManualTrivDelay HintCharacter botsleep hecklerenable repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable QText QBackground AText ABackground HText HBackground PAText PABackground QNText QNBackground gradhinttitletextcolor gradhinttitlebgcolor answertitletextcolor answertitlebgcolor qnumbold qbold htitlebold hbold gradhinttitlebold gradhintbold answertitlebold answerbold pointdrops pointdropdelay pointdropdecrease pointdrophintdecrease manualpointdropdelay showquestioneachpointdrop showquestioninfoeachpointdrop displayenable antifloodenable floodprotectiontimer IntervalClueEnable FillInLettersEnable AATrackerEnable triviaopallowed triviavalidusers triviavalidhosts trivquitopallowed trivquitvalidusers trivquitvalidhosts qcheckopallowed qcheckvalidusers qcheckvalidhosts changetopicopallowed changetopicvalidusers changetopicvalidhosts trivresetopallowed trivresetvalidusers trivresetvalidhosts editopallowed editvalidusers editvalidhosts deleteopallowed deletevalidusers deletevalidhosts swapbankopallowed swapbankvalidusers swapbankvalidhosts Cheaters CheaterHosts recountopallowed recountvalidusers recountvalidhosts syncopallowed syncvalidusers syncvalidhosts readconfigopallowed readconfigvalidusers readconfigvalidhosts TransferOpAllowed TransferValidUsers TransferValidHosts modifyopallowed modifyvalidusers modifyvalidhosts autoftpenable updateopallowed updatevalidusers updatevalidhosts ftpaddress ftpport ftplogin ftppass ftpdir ftpdelay TeamOpAllowed TeamValidUsers TeamValidHosts teamenable maxteams maxteamplayers maxteampoints teamduration teammode ucqvenable ucqvpercent ucqvhintpercent bonusqenable bonuslengths bonusvalues bonusdrops initialtriviadisplaydelay streakbonusenable streakinterval streakbonus hintmethods knowncolor unknowncolor multipleenable fuzzyenable rankupdisplay pointsleftdisplay playeraheaddisplay gamemode gamemodepercent scramblebanks sbankpercents scramblepvmethod scramblepresetvalue scrletters scrvalues scrdrops scrptdrops scrptdropseconds scrcluedisplay scrhintptdrop scrminhintletters scrmaxhintletters scrmaxhints scrpercenthintenable scrhintpercent scrhintprocess scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc enabletopicchange topxtipdisplayenable topxdisplaypercent topxfiles topxfilepercent topxplayers top5textcolors top5bgcolors topxdefaulttextcolor topxdefaultbgcolor topxtitletextcolor topxtitlebgcolor topxotherintervaldisplayenable topxotherintervalpercent"
set configindex 0
  set g [open "Config_Output.txt" w]
  puts $g "TriviaBot/Scramblebot v6.0 Config Debug File:"
  close $g
  set arraysettings 0
  set arrayflag 0
  while {[gets $f line] != -1} {
   if {$arraysettings == 0} {
    if {[string range $line 0 1] != "##"} {
     set [lindex $variables $configindex] $line
     set g [open "Config_Output.txt" a]
     puts $g "[lindex $variables $configindex] $line"
     close $g
   if {[lindex $variables $configindex] == "topxotherintervalpercent"} {
    set arraysettings 1
   }
     incr configindex
    }
   }

   
   
    if {$arraysettings == 1} {
     if {[string range $line 0 3] != "####"} {
      if {$line == "## Ads To Use"} {
       set arrayflag 1
      }
      if {$line == "## Tips To Use"} {
       set arrayflag 2
      }
      if {$line == "## Heckles To Use"} {
       set arrayflag 3
      } 
      if {$line == "## Left Borders"} {
       set arrayflag 4
      } 
      if {$line == "## Right Borders"} {
       set arrayflag 5
      }
      if {$line == "## Answer Displayers At the End of a Round"} {
       set arrayflag 6
      }
      if {$line == "## Initial Greetings For Known Players: Part I"} {
       set arrayflag 7
      }
      if {$line == "## Initial Greetings For Known Players: Part II"} {
       set arrayflag 8
      }
      #### ADD APPROPRIATE LINES INTO APPROPRIATE ARRAYS HERE
      if {[string range $line 0 1] != "##"} {
      if {$arrayflag == 1} {
       append AdsToUse "$line "    
      }
      if {$arrayflag == 2} {
      append TipsToUse "$line "    
      }
      if {$arrayflag == 3} {
      append HecklesToUse "$line "    
      }
      if {$arrayflag == 4} {
      append TopicLeftBorder "$line "    
      }
      if {$arrayflag == 5} {
      append TopicRightBorder "$line "    
      }
      if {$arrayflag == 6} {
      append AnswerDisplayersToUse "$line "    
      }
      if {$arrayflag == 7} {
      append Greet1ToUse "$line "    
      }
      if {$arrayflag == 8} {
      append Greet2ToUse "$line "    
      }
     }
    }     
   }
  }
      set g [open "Config_Output.txt" a]
      puts $g "$AdsToUse"
      puts $g "$TipsToUse"
      puts $g "$HecklesToUse"
      puts $g "$TopicRightBorder"
      puts $g "$TopicLeftBorder"
      puts $g "$AnswerDisplayersToUse"
      puts $g "$Greet1ToUse"
      puts $g "$Greet2ToUse"
      close $g
###############################################################################
close $f
set origtrivvalue $triviavalue
set origpointdrophintdecrease $pointdrophintdecrease
utimer 5 "StartReCount"
## These two lines start the command flood protection and advertiser routines when bot starts!
utimer 10 "ClearFloodProtections"
utimer 15 "Advertiser"
set counter 0
  while {$counter != $maxteams} {
   append TeamNames "[lindex $TeamNamesToUse $counter] "
   append cnames " [lindex $colorteamnamestouse $counter]"
   incr counter
 }
 set colorteamnamestouse "$cnames"
 if {$autoftpenable == 1} {
 utimer $ftpdelay "Autoftpsend blah $ownerhost blah blah blah"
}
putquick "NOTICE $nick :Config has been re-loaded...enjoy!"
return
}


proc StartReCount {} {
global qtotal triviastoppedflag alreadygoing validbanks scramblebanks triviachannel triviaowner answer hint question 
### CHECK TO ENSURE ALL TRIVIABANKS EXIST AND THAT TRIVIA TOTAL > 0!
### IF NOT, REPORT MISSING TRIVIA BANKS AND SHUT DOWN...IF TOTAL IS 0
### OR LESS THEN RECOUNT AND TRY ONCE MORE...IF STILL IMPROPER TOTAL
### THEN TURN OFF TRIVIA AND REPORT ERROR!
if [file exist "TriviaBankTotals.txt"] {
 set qindex 0
 set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
 putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
	set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  incr qindex
  }
 
 
 
 ### Check to see if trivia total == 0, if so then recount it!
 ## Get total Trivia Amount
 set g [open "TriviaBankTotals.txt" r]
 while {[gets $g line] != -1} {
 if {[lindex $line 0] == "TotalTrivia"} {
 set qtotal [lindex $line 1]
 }
 }
 close $g
 ##
 if {$qtotal < 1} {
 putquick "privmsg $triviachannel : ***WARNING*** 0 or less questions exist! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** 0 or less questions exist! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 	set triviastoppedflag 1
 	set alreadygoing 0
 	foreach t [utimers] {
 		if [string match *SecondDisplay* [lindex $t 1]] {
 			killutimer [lindex $t end]
 		}
 		if [string match *Mainproc* [lindex $t 1]] {
 			killutimer [lindex $t end]
 		}
 		if [string match *PointDrop* [lindex $t 1]] {
 			killutimer [lindex $t end]
 		}
 		if [string match *EndOf* [lindex $t 1]] {
 			killutimer [lindex $t end]
 		}
 				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
 	}
 	set answer ""
 	set hint ""
 	set question ""
##################################
 set qtotal 0
 set qindex 0
set g [open "TriviaBankTotals.txt" w]
close $g
set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  set g [open "TriviabotFlaggedQuestions.txt" w]
  close $g
  set g [open "TriviabotFlaggedQuestions.log" w]
  close $g
  while {[gets $f line] != -1} {
  
  ######### NEW FOR V6.5: AUTO-FLAG TRIVIA WITH NO Q OR A AS BAD! ########
   set marker "*"
  set badq 0
  set isitgood [string first $marker $line]
  if {$isitgood == -1} {set badq 1}
  
  if {$badq == 0} {
  set marker "*"
  set qamarker [string first $marker $line]
  set answerstartmarker [expr $qamarker + 1]
  set questionendmarker [expr $qamarker - 1]
  set question [string range $line 0 $questionendmarker]
  set answer [string range $line $answerstartmarker end]
  
  if {[string length $question] < 1} {set badq 1}
  if {[string length $answer] < 1} {set badq 1}
  
  }
  if {$badq == 1} {
   set g [open "TriviabotFlaggedQuestions.txt" a]
   puts $g "$qbanktoopen $qafilelength"
   close $g
  
   set g [open "TriviabotFlaggedQuestions.log" a]
   puts $g "Triviabot reported this error: $qbanktoopen, Question: [expr $qafilelength +1]!"
   close $g
  }
    ####### END NEW FOR V6.5: AUTO-FLAG TRIVIA WITH NO Q OR A AS BAD! ######
 
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

####### V6.0 CODE: ADDS TRIVIABANK TOTALS FROM SCRAMBLE BANKS TO TOTALS! ##
 set qindex 0
 while {[llength $scramblebanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $scramblebanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

###########################################################################

set g [open "TriviaBankTotals.txt" a]
puts $g "TotalTrivia $qtotal"
close $g
##################################
utimer 10 "Advertiser"
 	return 1
 }
###
} 
 

if ![file exist "TriviaBankTotals.txt"] {
 set qtotal 0
 set qindex 0
   set g [open "TriviabotFlaggedQuestions.txt" w]
   close $g
   set g [open "TriviabotFlaggedQuestions.log" w]
   close $g

set g [open "TriviaBankTotals.txt" w]
close $g
set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
  
  ######### NEW FOR V6.5: AUTO-FLAG TRIVIA WITH NO Q OR A AS BAD! ########
   set marker "*"
  set badq 0
  set isitgood [string first $marker $line]
  if {$isitgood == -1} {set badq 1}
  
  if {$badq == 0} {
  set marker "*"
  set qamarker [string first $marker $line]
  set answerstartmarker [expr $qamarker + 1]
  set questionendmarker [expr $qamarker - 1]
  set question [string range $line 0 $questionendmarker]
  set answer [string range $line $answerstartmarker end]
  
  if {[string length $question] < 1} {set badq 1}
  if {[string length $answer] < 1} {set badq 1}
  
  }
  if {$badq == 1} {
   set g [open "TriviabotFlaggedQuestions.txt" a]
   puts $g "$qbanktoopen $qafilelength"
   close $g
  
   set g [open "TriviabotFlaggedQuestions.log" a]
   puts $g "Triviabot reported this error: $qbanktoopen, Question: [expr $qafilelength +1]!"
   close $g
  }
    ####### END NEW FOR V6.5: AUTO-FLAG TRIVIA WITH NO Q OR A AS BAD! ######
  incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

####### V6.0 CODE: ADDS TRIVIABANK TOTALS FROM SCRAMBLE BANKS TO TOTALS! ##
 set qindex 0
 while {[llength $scramblebanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $scramblebanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

###########################################################################

set g [open "TriviaBankTotals.txt" a]
puts $g "TotalTrivia $qtotal"
close $g
### Check to see if trivia total == 0, if so then recount it!
## Get total Trivia Amount
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
if {[lindex $line 0] == "TotalTrivia"} {
set qtotal [lindex $line 1]
}
}
close $g
##
if {$qtotal < 1} {
putquick "privmsg $triviachannel : ***WARNING*** 0 or less questions exist! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** 0 or less questions exist! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 	set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
##################################
 set qtotal 0
 set qindex 0
set g [open "TriviaBankTotals.txt" w]
close $g
set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

####### V6.0 CODE: ADDS TRIVIABANK TOTALS FROM SCRAMBLE BANKS TO TOTALS! ##
 set qindex 0
 while {[llength $scramblebanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $scramblebanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

###########################################################################

set g [open "TriviaBankTotals.txt" a]
puts $g "TotalTrivia $qtotal"
close $g
##################################
utimer 10 "Advertiser"
	return 1
}
###
}
return
}

## This Line stores the original value of trivia questions defined in the config above,
## So when a new question is asked, triviavalue is reset using origtrivvalue!
set origtrivvalue $triviavalue
##


## Main Routine For Yahoos That Try To Lag The Bot By Repeating Commands...*Sigh*
proc ClearFloodProtections {} {
global antifloodenable floodprotectiontimer commandusers
if [info exist commandusers] {unset commandusers}
	foreach t [utimers] {
		if [string match *ClearFlood* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
	}
if {$antifloodenable == 1} {
 utimer $floodprotectiontimer "ClearFloodProtections"
}
return
}


## Proc For Selecting Random Heckle!
proc get_nyahnyah { } {
 global HecklesToUse
 set outputiz2 [lindex $HecklesToUse [rand [llength $HecklesToUse]]]
 return $outputiz2
}



## Proc For Selecting Random Here's-The-Answer-type sayings after 60 seconds!
proc get_NobodyGotIt { } {
 global AnswerDisplayersToUse
 set outputiz2 [lindex $AnswerDisplayersToUse [rand [llength $AnswerDisplayersToUse]]]
 return $outputiz2
}

## Proc to Randomly Select an Info Item!
proc get_InfoItem { } {
 global teamstarttime teamminstart teamsecondstart teamendtime teamminend teamsecondend maxteampoints TeamPoints teamenable teamduration TipsToUse topxtipdisplayenable topxdisplaypercent topxfiles topxfilepercent topxplayers top5textcolors top5bgcolors topxdefaulttextcolor topxdefaultbgcolor topxtitletextcolor topxtitlebgcolor topxotherintervaldisplayenable topxotherintervalpercent
 set outputiz2 ""
 set goodone 0
 while {$goodone == 0} {
  set outputiz2 [lindex $TipsToUse [rand [llength $TipsToUse]]]
  if {[string length $outputiz2] < 140} {set goodone 1}
 }
 ### ENTER NEW CODE FOR REPLACING SELECTED TIP WITH TOP X DISPLAY
 if {$topxtipdisplayenable == 1} {
  set rolledpercent [rand 100]
  if {$topxdisplaypercent >= $rolledpercent} {
### DETERMINE TOP X DISPLAY FILE TO USE
### RE-CODE THIS PART SO IT USES FILE PERCENTAGES!!!
set bankffrequency ""
set numberofplayerstoread ""
set ffreqcounter 0
set ffrequency "Today.txt ThisWeek.txt ThisMonth.txt ThisYear.txt Yesterday.txt LastWeek.txt LastMonth.txt LastYear.txt TopStreakers.txt"
while {[lindex $ffrequency $ffreqcounter] != ""} {
  set bankfcounter 0
  if {[lindex $topxfiles $ffreqcounter] == 1} {
   while {$bankfcounter != [lindex $topxfilepercent $ffreqcounter]} {
    append bankffrequency " [lindex $ffrequency $ffreqcounter] "
    append numberofplayerstoread " [lindex $topxplayers $ffreqcounter] "
    incr bankfcounter
   }
  }
incr ffreqcounter
}
set percentchosen [rand [llength $bankffrequency]]
##
set args [lindex $bankffrequency $percentchosen]
set topxplayerstoread [lindex $numberofplayerstoread $percentchosen]
###
### BANK FOR TOP X DISPLAY HAS BEEN CHOSEN...NOW OPEN IT AND READ INFO!
### 
set filetoopen "GenericScoresTEXT/"
append filetoopen "$args"
   if [file exist $filetoopen] {
    set topxread 0
    if {$filetoopen == "GenericScoresTEXT/Today.txt"} {set datedesired "Today's"}
    if {$filetoopen == "GenericScoresTEXT/ThisWeek.txt"} {set datedesired "This Week's"}
    if {$filetoopen == "GenericScoresTEXT/ThisMonth.txt"} {set datedesired "This Month's"}
    if {$filetoopen == "GenericScoresTEXT/ThisYear.txt"} {set datedesired "This Year's"}
    if {$filetoopen == "GenericScoresTEXT/Yesterday.txt"} {set datedesired "Yesterday's"}
    if {$filetoopen == "GenericScoresTEXT/LastWeek.txt"} {set datedesired "Last Week's"}
    if {$filetoopen == "GenericScoresTEXT/LastMonth.txt"} {set datedesired "Last Month's"}
    if {$filetoopen == "GenericScoresTEXT/LastYear.txt"} {set datedesired "Last Year's"}
    if {$filetoopen == "GenericScoresTEXT/TopStreakers.txt"} {set datedesired "Channel Streakers'"}
     		set winners "$topxtitletextcolor,$topxtitlebgcolor $datedesired Top $topxplayerstoread Players:"
     		set f [open $filetoopen r]
     		for { set s 0 } { $s < $topxplayerstoread } { incr s } {
     			gets $f tally
     			set placement [expr $s +1]
     			if {$placement == 1} {set placement " [lindex $top5textcolors 0],[lindex $top5bgcolors 0] 1st: "}
     			if {$placement == 2} {set placement " [lindex $top5textcolors 1],[lindex $top5bgcolors 1] 2nd: "}
     			if {$placement == 3} {set placement " [lindex $top5textcolors 2],[lindex $top5bgcolors 2] 3rd: "}
     			if {$placement == 4} {set placement " [lindex $top5textcolors 3],[lindex $top5bgcolors 3] 4th: "}
     			if {$placement == 5} {set placement " [lindex $top5textcolors 4],[lindex $top5bgcolors 4] 5th: "}
     			if {$placement == 6} {set placement " $topxdefaulttextcolor,$topxdefaultbgcolor 6th: "}
     			if {$placement == 7} {set placement " $topxdefaulttextcolor,$topxdefaultbgcolor 7th: "}
     			if {$placement == 8} {set placement " $topxdefaulttextcolor,$topxdefaultbgcolor 8th: "}
     			if {$placement == 9} {set placement " $topxdefaulttextcolor,$topxdefaultbgcolor 9th: "}
     			if {$placement == 10} {set placement " $topxdefaulttextcolor,$topxdefaultbgcolor 10th: "}
     			append winners $placement
     			append winners [lindex $tally 0]
     			append winners " - "
     			append winners [lindex $tally 1]
     		}
		set outputiz2 $winners
   }
  }
 }
 ################################################################



if {$teamenable == 1} {
set dater [unixtime]
set teamendtime $dater
set teamstartenddiff [expr $teamendtime - $teamstarttime]
set teamtimegoing [expr ($teamduration / 60) - ($teamstartenddiff / 60) ]
set decider [rand 10]
###################################
### CODE FOR DISPLAYING TIME LEFT IN TEAM TRIVIA
###################################

  if {$decider < 8} {
   if {$teamduration > 0} {
    set outputiz2 "0,3 $teamtimegoing Minutes Are Left In Team Trivia!"
    }
    if {$teamduration == 1} {
    set outputiz2 "0,3 $teamtimegoing Minute Is Left In Team Trivia!"
    }
    if {$teamtimegoing == 0} {
     set outputiz2 "0,4 [expr (($teamduration - $teamstartenddiff)*-1)] Seconds Are Left In Team Trivia!"
    }
   }
 if {$decider < 5} {
  if {$maxteampoints != 0} {
#### ADD CODE HERE TO DISPLAY LEAD TEAM AND HOW MANY POINTS THEY NEED
#### TO WIN AS WELL!
   set outputiz2 "Only $maxteampoints Points Are Needed To Win Team Trivia!"
   }

 }
###################################

  if {$decider < 4} {
  set outputiz2 "0,1Type 8,1!Join0,1 to Join a Team, 8,1!Remove0,1 to Remove Yourself From A Team and 8,1!Teams0,1 to Display Team Stats!"
 }
  if {$decider < 3} {
  set outputiz2 "Team Trivia Scores: 0,4red: [lindex $TeamPoints 0] 0,2blue: [lindex $TeamPoints 1] 0,6purple: [lindex $TeamPoints 2] 0,3green: [lindex $TeamPoints 3] 0,5brown: [lindex $TeamPoints 4] 1,11cyan: [lindex $TeamPoints 5] 1,8yellow: [lindex $TeamPoints 6] 1,7orange: [lindex $TeamPoints 7] 0,1black: [lindex $TeamPoints 8] 1,0white: [lindex $TeamPoints 9] "
 }

  if {$teamtimegoing < 6} {
  
  
  if {$teamtimegoing < 1} {
  	foreach t [utimers] {
  		if [string match *EndTeam* [lindex $t 1]] {
  			killutimer [lindex $t end]
  		}
	}
  utimer [expr (($teamduration - $teamstartenddiff)*-1)] "EndTeamTrivia"
  return
  }
    set outputiz2 "0,3 $teamtimegoing Minutes Are Left In Team Trivia!"
    if {$teamduration == 1} {
        set outputiz2 "0,3 $teamtimegoing Minute Is Left In Team Trivia!"
    }
    
    if {$teamtimegoing == 0} {
     set outputiz2 "0,4  [expr (($teamduration - $teamstartenddiff)*-1)] Seconds Are Left In Team Trivia!"
   }
  }
 }
 return $outputiz2
}

## Proc to Randomly Select an Advertisement!
proc get_Ad { } {
 global AdsToUse
 set outputiz2 [lindex $AdsToUse [rand [llength $AdsToUse]]]
 return $outputiz2
}

## Main Advertiser...calls get_Ad routine!
proc Advertiser {} {
 global triviaowner enabletopicchange scramblebanks qtotal TopicLeftBorder TopicRightBorder alreadygoing EnableAds triviachannel AdDelay validbanks
 if {$alreadygoing == 0} {
 if {$EnableAds == 0} {return}
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
if {[lindex $line 0] == "TotalTrivia"} {
set qtotal [lindex $line 1]
}
}
close $g
  set adtouse [get_Ad]
  set bordertousenum [rand [llength $TopicLeftBorder]]
  if {$qtotal < 1} {
  set adtouse "11Only8 $qtotal 11questions present!8 $triviaowner 11needs to use the recount command!"
  }
  putquick "privmsg $triviachannel :15,1 $adtouse (Containing $qtotal questions!) "
if {$enabletopicchange == 1} {
 putquick "TOPIC $triviachannel :[lindex $TopicLeftBorder $bordertousenum] $adtouse 13(11Containing4 $qtotal 11questions!13) [lindex $TopicRightBorder $bordertousenum]"
}
  utimer $AdDelay "Advertiser"
  return
 }
 return 1
}

## Proc to Randomly Select Greet1!
proc get_Greet1 { } {
 global Greet1ToUse
 set outputiz2 [lindex $Greet1ToUse [rand [llength $Greet1ToUse]]]
 return $outputiz2
}

## Proc to Randomly Select Greet2!
proc get_Greet2 { } {
 global Greet2ToUse
 set outputiz2 [lindex $Greet2ToUse [rand [llength $Greet2ToUse]]]
 return $outputiz2
}

## Tells people the Server the bot is currently on!
proc Server {nick uhost hand chan args} {
 global usercounter antifloodenable commandusers server showserver triviachannel
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
## This routine is linked to the anticommand flooding code...if it's enabled, the bot
## Checks to see if the user using this command has used any other command within the last
## x seconds (defined in the config above for x)...if they have, they're ignored!
## All user command routines have this at the start of their code...I'll only describe
## it in this one so the scripts doesn't become any messier! ;)

if {$antifloodenable == 1} {
  foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
##

## Routine for showing the bot's server in channel or privately to a user!
if {$showserver ==1} {
  putquick "privmsg $triviachannel :I am on $server! Type /server $server for the extra edge!"
 }
 if {$showserver !=1} {
  putquick "NOTICE $nick :I am on $server! Type /server $server for the extra edge!"
 }
}
##

## Something For People That Try certain popular commands...it's amazing how many people try commands from other TriviaBots! ;)
proc QuitUsingThisCommand {nick uhost hand chan arg} {
 global antifloodenable usercounter commandusers triviachannel
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
 putquick "privmsg $triviachannel :That command is from a different type of Triviabot $nick...type '4!help' to see my commands instead!"
}

## Autogreeting routine!
proc TriviaWelcome {nick uhost hand chan} {
 global Greet1ToUse Greet2ToUse yearscore nameofbot antifloodenable usercounter triviachannel autovoiceenable autovoicescore autovoicesynch weekfilename monthfilename yearfilename dayfilename autojoin alreadygoing joinmsg server hintalreadygiven

## If autovoicing is enabled, the bot checks to see if the user that joined the channel has
## a score of x or more (defined in the config!), if so and if the bot is able to voice
## in the channel, then that user gets voiced...on entry to the channel only!
## (The bot won't re-voice them if they get de-voiced in the channel...sorry!)

if {$nick == $nameofbot} {return}
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
  foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}

set greetknownplayers 1
if {$greetknownplayers == 1} {
 if {[info exists yearscore($nick)]} {
  putquick "privmsg $triviachannel :[get_Greet1] $nick...[get_Greet2]"
 }
}
if {$autovoiceenable == 1} {
set scoreplayer $nick
regsub -all \[{}] $scoreplayer "~" scoreplayer
regsub -all {[\\]} $scoreplayer "|" scoreplayer
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
set foundflag 0
if {$autovoicesynch == 0} {set scorefiletouse "GenericScoresTEXT/Today.txt"}
if {$autovoicesynch == 1} {set scorefiletouse "GenericScoresTEXT/ThisWeek.txt"}
if {$autovoicesynch == 2} {set scorefiletouse "GenericScoresTEXT/ThisMonth.txt"}
if {$autovoicesynch == 3} {set scorefiletouse "GenericScoresTEXT/ThisYear.txt"}
set f [open $scorefiletouse r]
if [file exists $scorefiletouse] {
while {[gets $f tally] != -1} {
	set checker [lindex $tally 0]
	if {$checker == $scoreplayer} {
		if {[lindex $tally 1] >= $autovoicescore} {
      		pushmode $triviachannel +v $nick
		}
	}
}
close $f
}
}

## This routine below makes the bot ignore autogreeting if it's disabled in the config!
 if {$autojoin == 0} {return}
##

## Is Trivia running? (alreadygoing =1?), if yes, tell the user it's running and to type
## !repeat, otherwise tell them Trivia is off and to type !trivia to start it!
 if {$alreadygoing == 0} {
  putquick "NOTICE $nick :$joinmsg Trivia is off right now...type 4!trivia to start Online Trivia or 4!help for all the new trivia commands! I am currently connected to $server! Type /server $server for the extra edge! Have fun!"
 }
 if {$alreadygoing != 0} {
  putquick "NOTICE $nick :$joinmsg Trivia is running! Type 4!repeat to see the current question or 4!help for all the new trivia commands! I am currently connected to $server! Type /server $server for the extra edge! Have fun!"
 }
 return 1
}
##
## My B-Bye Routine for people that leave the channel!
proc LeavingSoSoon {nick uhost hand chan args} {
 global antifloodenable usercounter autoquit quitmsg IndividualTeamPoints colorteamnamestouse TeamNamesToUse alreadygoing maxteams maxteamplayers maxteampoints teamduration teammode triviachannel antifloodenable usercounter commandusers teamenable TeamNames CurrentTeamPlayerTotals TeamPlayers TeamPoints IndividualTeamPoints





if {$antifloodenable == 1} {
  foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}

### IS TEAM TRIVIA RUNNING? IS PLAYER ON A TEAM? IF YES AND YES REMOVE THEM

################################
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
################################
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
if {$teamenable == 1} {
################################
set nickforfile $nick
### MAIN CODE FOR BAD CHARACTER REPLACEMENTS GO HERE
regsub -all \[{}] $nickforfile "~" nickforfile
regsub -all {[\\]} $nickforfile "|" nickforfile
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
################################
### ALL CHECKS ON NICK HAVE PASSED...LOCATE NICK IN TEAM PLAYERS AND REMOVE
### THEM AND ALL THEIR INFO FROM THE TEAM THEY'RE LOCATED ON!
### (NOTE: POINTS STAY IF MODE = BATTLEMODE
#########################################
  set counter 0
   set PlayerFound 0
   set FoundYou ""
   while {[lindex $TeamPlayers $counter] != ""} {
    if {[lindex $TeamPlayers $counter] == $nickforfile} {
     set PlayerFound 1
     set FoundYou [lindex $colorteamnamestouse [lindex $TeamPlayers [expr $counter +1]]]
     set teamtocheck [lindex $TeamPlayers [expr $counter +1]]
    }
   incr counter
   }
   if {$PlayerFound == 0} {
     return
 }
   
   if {$PlayerFound == 1} {
##### PLAYER FOUND ON A TEAM...REMOVE ALL INFO
 ### 1) Decrease Total Players On Team Player was on by 1!
 if {$teamtocheck == 0} {
  set newCurrentTeamPlayerTotals " [expr [lindex $CurrentTeamPlayerTotals 0] - 1] "
  append newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals 1 end] "
  set CurrentTeamPlayerTotals $newCurrentTeamPlayerTotals
 }
 if {$teamtocheck > 0} {
  set newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals 0 [expr $teamtocheck -1]] "
  append newCurrentTeamPlayerTotals " [expr [lindex $CurrentTeamPlayerTotals $teamtocheck] -1] "
  append newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals [expr $teamtocheck +1] end] "
  set CurrentTeamPlayerTotals $newCurrentTeamPlayerTotals
 }
 ### 2) Remove Player From Team!
set lookingforyou2 0
while {[lindex $TeamPlayers $lookingforyou2] != ""} {
 if {[lindex $TeamPlayers $lookingforyou2] == $nickforfile} {
  set lookingforyou $lookingforyou2
  set foundyouteamscoreindexer [lindex $TeamPlayers [expr $lookingforyou2 +1]]
 }
 incr lookingforyou2
}


 if {$lookingforyou == 0} {
  set TeamPlayers [lrange $TeamPlayers 2 end]
 }
 if {$lookingforyou > 0} {
  set newTeamPlayers " [lrange $TeamPlayers 0 [expr $lookingforyou -1]] "
  append newTeamPlayers " [lrange $TeamPlayers [expr $lookingforyou +2] end] "
  set TeamPlayers $newTeamPlayers
 }
 ### 3) Add Player To IndividualTeamPoints For Tracking Purposes!
if {$teammode == 999} {
  if {$foundyouteamscoreindexer == 0} {
    set newTeamPoints " [expr [lindex $TeamPoints $foundyouteamscoreindexer] - [lindex $IndividualTeamPoints [expr $lookingforyou +1]]] "
    append newTeamPoints " [lrange $TeamPoints 1 end] "
    set TeamPoints $newTeamPoints
  }
  if {$foundyouteamscoreindexer > 0} {
   set newTeamPoints " [lrange $TeamPoints 0 [expr $foundyouteamscoreindexer -1]] "
   append newTeamPoints " [expr [lindex $TeamPoints $foundyouteamscoreindexer] - [lindex $IndividualTeamPoints [expr $lookingforyou +1]]] "
   append newTeamPoints " [lrange $TeamPoints [expr $foundyouteamscoreindexer +1] end] "
   set TeamPoints $newTeamPoints
  }
 }
  if {$lookingforyou == 0} {
   set IndividualTeamPoints [lrange $TeamPlayers 2 end]
  }
  if {$lookingforyou > 0} {
   set newIndividualTeamPoints " [lrange $IndividualTeamPoints 0 [expr $lookingforyou -1]] "
   append newIndividualTeamPoints " [lrange $IndividualTeamPoints [expr $lookingforyou +2] end] "
   set IndividualTeamPoints $newIndividualTeamPoints
 }
#####

putquick "privmsg $triviachannel :8,1$nick has been removed from the [lindex $colorteamnamestouse $foundyouteamscoreindexer] team due to leaving the channel!"
putquick "notice $nick :8,1You have been removed from the [lindex $colorteamnamestouse $foundyouteamscoreindexer] team8,1 due to leaving the channel!"
}
}




###########################################################################
## Is autoquit disabled? If so, don't bug the user when they leave!
 if {$autoquit == 0} {return}
##
 putquick "NOTICE $nick :$quitmsg"
 return 1
}

## This routine sets up a few variables that would mess up if they were in the Trivia proc!
proc StartTrivia {nick uhost hand chan args} {
global pointdroppedflag teamstarttime teamminstart teamsecondstart TeamNames TeamNamesToUse maxteams maxteamplayers colorteamnamestouse maxteampoints teamduration teamenable teammode question answer hint scramblebanks ownerhost triviavalidhosts qtotal validbanks triviaowner nameofbot triviavalidusers triviaopallowed validquestions origqfilelength qafilelength antifloodenable usercounter commandusers alreadygoing qafile AnyonePlaying triviastoppedflag qafilelength triviachannel
 if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
##
 if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$triviaopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $triviavalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $triviavalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
########################################################
if {$triviaopallowed == 0} {set allowedflag 1}
if {$allowedflag == 0} {return}

## Checks To See If Bot is already running!
 if {$alreadygoing == 1} {
  putquick "privmsg $triviachannel :Trivia is already running, $nick! Type !repeat to see the current question!"
  return 1
 }
set triviastoppedflag 0
set pointdroppedflag 0


### CHECK TO ENSURE ALL TRIVIABANKS EXIST AND THAT TRIVIA TOTAL > 0!
### IF NOT, REPORT MISSING TRIVIA BANKS AND SHUT DOWN...IF TOTAL IS 0
### OR LESS THEN RECOUNT AND TRY ONCE MORE...IF STILL IMPROPER TOTAL
### THEN TURN OFF TRIVIA AND REPORT ERROR!
if [file exist "TriviaBankTotals.txt"] {
 set qindex 0
 set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
 putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  incr qindex
  }
 
 
 
 ### Check to see if trivia total == 0, if so then recount it!
 ## Get total Trivia Amount
 set g [open "TriviaBankTotals.txt" r]
 while {[gets $g line] != -1} {
 if {[lindex $line 0] == "TotalTrivia"} {
 set qtotal [lindex $line 1]
 }
 }
 close $g
 ##
 if {$qtotal < 1} {
 putquick "privmsg $triviachannel : ***WARNING*** 0 or less questions exist! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** 0 or less questions exist! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 	set triviastoppedflag 1
 	set alreadygoing 0
 	foreach t [utimers] {
 		if [string match *SecondDisplay* [lindex $t 1]] {
 			killutimer [lindex $t end]
 		}
 		if [string match *Mainproc* [lindex $t 1]] {
 			killutimer [lindex $t end]
 		}
 		if [string match *PointDrop* [lindex $t 1]] {
 			killutimer [lindex $t end]
 		}
 		if [string match *EndOf* [lindex $t 1]] {
 			killutimer [lindex $t end]
 		}
 				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
 	}
 	set answer ""
 	set hint ""
 	set question ""
##################################
 set qtotal 0
 set qindex 0
set g [open "TriviaBankTotals.txt" w]
close $g
set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

####### V6.0 CODE: ADDS TRIVIABANK TOTALS FROM SCRAMBLE BANKS TO TOTALS! ##
 set qindex 0
 while {[llength $scramblebanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $scramblebanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

###########################################################################

set g [open "TriviaBankTotals.txt" a]
puts $g "TotalTrivia $qtotal"
close $g
##################################
utimer 10 "Advertiser"
 	return 1
 }
###
} 
 

if ![file exist "TriviaBankTotals.txt"] {
 set qtotal 0
 set qindex 0
set g [open "TriviaBankTotals.txt" w]
close $g
set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

####### V6.0 CODE: ADDS TRIVIABANK TOTALS FROM SCRAMBLE BANKS TO TOTALS! ##
 set qindex 0
 while {[llength $scramblebanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $scramblebanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

###########################################################################

set g [open "TriviaBankTotals.txt" a]
puts $g "TotalTrivia $qtotal"
close $g
### Check to see if trivia total == 0, if so then recount it!
## Get total Trivia Amount
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
if {[lindex $line 0] == "TotalTrivia"} {
set qtotal [lindex $line 1]
}
}
close $g
##
if {$qtotal < 1} {
putquick "privmsg $triviachannel : ***WARNING*** 0 or less questions exist! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** 0 or less questions exist! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 	set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
##################################
 set qtotal 0
 set qindex 0
set g [open "TriviaBankTotals.txt" w]
close $g
set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

####### V6.0 CODE: ADDS TRIVIABANK TOTALS FROM SCRAMBLE BANKS TO TOTALS! ##
 set qindex 0
 while {[llength $scramblebanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $scramblebanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

###########################################################################

set g [open "TriviaBankTotals.txt" a]
puts $g "TotalTrivia $qtotal"
close $g
##################################
utimer 10 "Advertiser"
	return 1
}
###
}




set origqfilelength $qafilelength
## Get total Trivia Amount
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
if {[lindex $line 0] == "TotalTrivia"} {
set qtotal [lindex $line 1]
}
}
close $g
##
 putquick "privmsg $triviachannel : Welcome To our Trivia channel. Type 4!help for a list of the commands or visit 4http://z.myjp.net/ for our Triviabot's latest scores...EnJoY!!! :)"

#### V6.0 TEAM TRIVIA ANNOUNCEMENT IF TEAMTRIVIA FLAG IS ON!
if {$teamenable == 1} {
 if {$teammode == 0} {set ttmode "Normal"}
 if {$teammode == 1} {set ttmode "Battle"}

if {$maxteams != 0} {
  set maxteams2 $maxteams
 }
 if {$maxteamplayers != 0} {
  set maxteamplayers2 $maxteamplayers
 }
 if {$maxteampoints != 0} {
  set maxteampoints2 $maxteampoints
 }
 if {$teamduration != 0} {
  set teamduration2 $teamduration
  set teamduration2 [expr $teamduration2 / 60]
 }


 if {$maxteams == 0} {
  set maxteams2 "No Limit"
  set maxteams 99999999
 }
 if {$maxteamplayers == 0} {
  set maxteamplayers2 "No Limit"
  set maxteams 99999999
 }
 if {$maxteampoints == 0} {
  set maxteampoints2 "No Limit"
 }
 if {$teamduration == 0} {
  set teamduration2 "No Limit"
 }
 
  set counter 0
  set TeamNames ""
  set cnames ""
  if {$maxteams > [llength $TeamNamesToUse]} {
   putquick "privmsg $triviachannel :4Sorry...too many teams requested...maximum number of possible teams is [llength $TeamNamesToUse]!"
  return
  }
  while {$counter != $maxteams} {
   append TeamNames "[lindex $TeamNamesToUse $counter] "
   append cnames " [lindex $colorteamnamestouse $counter]"
   incr counter
 }
 set colorteamnamestouse "$cnames"
  putquick "privmsg $triviachannel :8,1$ttmode 0Team Trivia has been chosen with the following settings:"
  putquick "privmsg $triviachannel :0,1Number of Teams:8 $maxteams0, Maximum Players Per Team:8 $maxteamplayers20, Points Needed To Win The Game:8 $maxteampoints20, Game Duration:8 $teamduration2 0minutes!" 
  putquick "privmsg $triviachannel :0,1Valid Team Names To Join Are: $colorteamnamestouse"
  putquick "privmsg $triviachannel :0,1Type 11!join0 to join a team...type 11!remove0 to leave a team...good luck everyone!"
 if {$teamduration > 0} {
### Determine Start Time Of Team Trivia
set dater [unixtime]
set teamstarttime $dater
###
#  utimer $teamduration "EndTeamTrivia"
 }
####
}
 Mainproc blah blah blah $triviachannel
 set AnyonePlaying 0
 return 1
}

## Order of Operations - Main Module Handler
proc Mainproc {nick uhost hand chan} {
global lcounter qnumber qaline pointdroppedflag orig_knowncolor orig_unknowncolor orig_QText orig_QBackground orig_AText orig_ABackground orig_HText orig_HBackground knowncolor unknowncolor QText QBackground AText ABackground HText HBackground scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc scrcluegiven bonusdrops pointdrops pointdropdelay pointdropdecrease minhintletters maxhintletters hinttimes percentagehintenable hintpercentage hintmethods currentscramble ScrambleRoundChosen orig_validbanks orig_frequency orig_trivvalue orig_bonuslengths orig_bonusvalues orig_bonusdrops orig_pointdrops orig_pointdropdelay orig_pointdropdecrease orig_minhintletters orig_maxhintletters orig_hinttimes orig_percentagehintenable orig_hintpercentage orig_hintmethods gamemode gamemodepercent scramblebanks sbankpercents scramblepvmethod scramblepresetvalue scrletters scrvalues scrdrops scrptdrops scrptdropseconds scrcluedisplay scrhintptdrop scrminhintletters scrmaxhintletters scrmaxhints scrpercenthintenable scrhintpercent scrhintprocess validanswer multipleenable knowncolor unknowncolor origpointdrophintdecrease pointdrophintdecrease initialtriviadisplaydelay pointdropdecrease marksplitter origtrivvalue ucqvenable ucqvpercent ucqvhintpercent qnumbold qbold answertitlebold answerbold gradhinttitletextcolor gradhinttitlebgcolor gradhinttitlebold gradhintbold hintcounter QNText QNBackground AATrackerEnable pointdropcounter manualpointdropdelay autovoicesynch qtotal validbanks frequency randommode sendanswertoowner swapbankflag validquestions origqfilelength HBackground HText QBackground QText qafilelength minstart displayenable fastanswerqty streakscore streakfilename streakhtmlfilename fastanswerscore fastanswerfilename fastanswerhtmlfilename Cheaters pointdropdelay timeinformed alreadyaskedfile hintalreadygiven alreadygoing qafile question datechecker monthfilename prevmonthfilename monthhtmlfilename hint answer triviastoppedflag score qafilelength qnumber alreadyguessed triviavalue dayscore dayfilename prevdayfilename dayhtmlfilename dedication weekscore weekfilename prevweekfilename weekhtmlfilename yearfilename yearhtmlfilename prevyearfilename yearscore triviachannel validbanks EnableAds AdsToUse  TipEnable TipsToUse HintCharacter triviavalue nontriviapiracy nontriviapiracyvariable triviaowner secondstart bonusqenable bonuslengths bonusvalues bonusdrops
  set ScrambleRoundChosen 0
set alreadygoing 1
set scrcluegiven 0
set pointdroppedflag 0
set qnumindex ""
set qfilelength $origqfilelength
 set hintalreadygiven 0
## Check To See If Trivia Has Been Stopped...just in case...;)
 if {$triviastoppedflag == 1} {
  set alreadygoing 0
  return 1
 }
##
 if [info exists validquestions] { unset validquestions }



 
utimer [expr ($pointdropdelay * 2) - $manualpointdropdelay + $initialtriviadisplaydelay] "TriviaHanging $triviachannel"
## Find Out How Many Questions There Are!
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
 if {[lindex $line 0] == $qafile} {
  set qafilelength [lindex $line 1]
 }
}
close $g
set swapbankflag 0
############ NEW TO V6.0: WORD SCRAMBLE CODE SECTION: ####################
### WHAT TYPE OF GAME MODE IS ACTIVE? IF SET TO 1, THEN SCRAMBLE IS
### DESIRED...CALL SCRAMBLE GAME PROC, IF SET TO 2 THEN RANDOMLY DETERMINE
### TYPE OF ROUND...IF SCRAMBLE ROUND IS DETERMINED CALL SCRAMBLE GAME
### PROC...IF GAME MODE IS SET TO EITHER 0 OR 2 AND TRIVIA GAME IS
### DETERMINED FOR NEXT ROUND THEN CONTINUE WITH THIS PROC...
if {$gamemode == 1} {
 set ScrambleRoundChosen 1
 ### TO SHORTEN CODE AND POSSIBLY CODING TIME, REMEMBER ORIG TRIVIA
 ### SETTINGS OF VARS TO ADAPT FOR SCRAMBLE MODE AND THEN USE THEM
 ### THROUGHT THE ROUND, RESTORING THEM BACK TO TRIVIA SETTINGS
 ### IN BOTH ENDOFROUND PROC, NEXTPROC AND CHECKPLAYERGUESS PROC!
 
 ### BACKUP ORIGINAL TRIVIA SETTING VARIABLES THAT NEED CHANGING
 set orig_validbanks $validbanks
 set orig_frequency $frequency
 set orig_trivvalue $triviavalue
 set orig_bonuslengths $bonuslengths
 set orig_bonusvalues $bonusvalues
 set orig_bonusdrops $bonusdrops
 set orig_pointdrops $pointdrops
 set orig_pointdropdelay $pointdropdelay
 set orig_pointdropdecrease $pointdropdecrease
 set orig_minhintletters $minhintletters
 set orig_maxhintletters $maxhintletters
 set orig_hinttimes $hinttimes
 set orig_percentagehintenable $percentagehintenable
 set orig_hintpercentage $hintpercentage
 set orig_hintmethods $hintmethods
 set orig_knowncolor $knowncolor
 set orig_unknowncolor $unknowncolor
 set orig_QText $QText
 set orig_QBackground $QBackground
 set orig_AText $AText
 set orig_ABackground $ABackground
 set orig_HText $HText
 set orig_HBackground $HBackground
 ### BACKUPS MADE...NOW TO REPLACE NEEDED TRIVIA VARS WITH SCRAMBLE ONES!
 set validbanks $scramblebanks
 set frequency $sbankpercents
 set triviavalue $scramblepresetvalue
 set bonuslengths $scrletters
 set bonusvalues $scrvalues
 set bonusdrops $scrdrops
 set pointdrops $scrptdrops
 set pointdropdelay $scrptdropseconds
 set pointdropdecrease $scrhintptdrop
 set minhintletters $scrminhintletters
 set maxhintletters $scrmaxhintletters
 set hinttimes $scrmaxhints
 set percentagehintenable $scrpercenthintenable
 set hintpercentage $scrhintpercent
 set hintmethods $scrhintprocess
 set knowncolor $scrknown
 set unknowncolor $scrunknown
 set QText $scrqtc
 set QBackground $scrqbc
 set AText $scratc
 set ABackground $scrabc
 set HText $scrhtc
 set HBackground $scrhbc
 ###
 
}

if {$gamemode == 2} {
### DETERMINE WHETHER THE NEXT ROUND IS EITHER TRIVIA OR SCRAMBLE
set gamefrequency ""
set gamefreqcounter 0
while {[lindex $gamemodepercent $gamefreqcounter] != ""} {
  set gmcounter 0
  while {$gmcounter != [lindex $gamemodepercent $gamefreqcounter]} {
   append gamefrequency " $gamefreqcounter "
   incr gmcounter
  }
incr gamefreqcounter
}
set gamemodechosen [rand [llength $gamefrequency]]
##################################################################
  if {[lindex $gamefrequency $gamemodechosen] == 1} {
 set ScrambleRoundChosen 1
 ### TO SHORTEN CODE AND POSSIBLY CODING TIME, REMEMBER ORIG TRIVIA
 ### SETTINGS OF VARS TO ADAPT FOR SCRAMBLE MODE AND THEN USE THEM
 ### THROUGHT THE ROUND, RESTORING THEM BACK TO TRIVIA SETTINGS
 ### IN BOTH ENDOFROUND PROC, NEXTPROC AND CHECKPLAYERGUESS PROC!
 
 ### BACKUP ORIGINAL TRIVIA SETTING VARIABLES THAT NEED CHANGING
 set orig_validbanks $validbanks
 set orig_frequency $frequency
 set orig_trivvalue $triviavalue
 set orig_bonuslengths $bonuslengths
 set orig_bonusvalues $bonusvalues
 set orig_bonusdrops $bonusdrops
 set orig_pointdrops $pointdrops
 set orig_pointdropdelay $pointdropdelay
 set orig_pointdropdecrease $pointdropdecrease
 set orig_minhintletters $minhintletters
 set orig_maxhintletters $maxhintletters
 set orig_hinttimes $hinttimes
 set orig_percentagehintenable $percentagehintenable
 set orig_hintpercentage $hintpercentage
 set orig_hintmethods $hintmethods
 set orig_knowncolor $knowncolor
 set orig_unknowncolor $unknowncolor
 set orig_QText $QText
 set orig_QBackground $QBackground
 set orig_AText $AText
 set orig_ABackground $ABackground
 set orig_HText $HText
 set orig_HBackground $HBackground
 ### BACKUPS MADE...NOW TO REPLACE NEEDED TRIVIA VARS WITH SCRAMBLE ONES!
 set validbanks $scramblebanks
 set frequency $sbankpercents
 set triviavalue $scramblepresetvalue
 set bonuslengths $scrletters
 set bonusvalues $scrvalues
 set bonusdrops $scrdrops
 set pointdrops $scrptdrops
 set pointdropdelay $scrptdropseconds
 set pointdropdecrease $scrhintptdrop
 set minhintletters $scrminhintletters
 set maxhintletters $scrmaxhintletters
 set hinttimes $scrmaxhints
 set percentagehintenable $scrpercenthintenable
 set hintpercentage $scrhintpercent
 set hintmethods $scrhintprocess
 set knowncolor $scrknown
 set unknowncolor $scrunknown
 set QText $scrqtc
 set QBackground $scrqbc
 set AText $scratc
 set ABackground $scrabc
 set HText $scrhtc
 set HBackground $scrhbc
 ###
 
 

 }
}
############ END OF V6.0 SCRAMBLE CODE FOR THIS PROC #############

######################################################
### Random Mode Code!
if {$randommode == 1} {
############################ Frequency of Trivia From Certain Banks Code Snippet
set bankfrequency ""
set freqcounter 0
while {[lindex $frequency $freqcounter] != ""} {
  set bankcounter 0
  while {$bankcounter != [lindex $frequency $freqcounter]} {
   append bankfrequency " [lindex $validbanks $freqcounter] "
   incr bankcounter
  }
incr freqcounter
}
set percentchosen [rand [llength $bankfrequency]]
##
set args [lindex $bankfrequency $percentchosen]
append $args ".qst"
set qafiletoswapto "TriviaBanks/"
 append qafiletoswapto $args
 set alreadyaskedfiletoswapto "AlreadyAsked/AlreadyAsked"
 append alreadyaskedfiletoswapto $args
 set qafile $qafiletoswapto
 set alreadyaskedfile $alreadyaskedfiletoswapto
## Routine For Finding Out How Many Questions There Are!
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
if {[lindex $line 0] == $qafile} {
set qafilelength [lindex $line 1]
}
}
close $g
##
set origqfilelength $qafilelength
}
#####
##
###
## START OF CODE FOR GETTING A NEW QUESTION!
 set allasked 0
 set endflag 0
 set alreadyaskedtotal 0
if {$AATrackerEnable != 1} {
 set qnumber [rand $qafilelength]
 set totalunaskedquestions $qafilelength
}

## Is there an AlreadyAsked file currently existing? If not this creates it!
if {$AATrackerEnable == 1} {
 if {![file exist $alreadyaskedfile]} {
## Create Zeroed Question Already Asked Markers For Tracker!
  set g [open $alreadyaskedfile w]
  puts $g "$qafilelength $qafilelength"
  close $g
  set qnumindex ""
  set marker 0
  set totalqs 0
  while {$totalqs <= $qafilelength} {
   append qnumindex "0"
   incr marker
   incr totalqs
   if {$marker == $marksplitter} {
    set g [open $alreadyaskedfile a]
    puts $g "$qnumindex"
    close $g
    set marker 0
    set qnumindex ""
   }
  }
  set g [open $alreadyaskedfile a]
  puts $g "$qnumindex"
  close $g
##
 }
 if {[file exist $alreadyaskedfile]} {
## Create Zeroed Question Already Asked Markers For Tracker!
  set g [open $alreadyaskedfile r]
  gets $g validaafilechecker
  close $g
  set secondindexchecker [lindex $validaafilechecker 1]
  set thirdindexchecker [lindex $validaafilechecker 2]
  if {$secondindexchecker == ""} {
## Create Zeroed Question Already Asked Markers For Tracker!
   set g [open $alreadyaskedfile w]
   puts $g "$qafilelength $qafilelength"
   close $g
   set qnumindex ""
   set marker 0
   set totalqs 0
   while {$totalqs <= $qafilelength} {
    append qnumindex "0"
    incr marker
    incr totalqs
    if {$marker == $marksplitter} {
     set g [open $alreadyaskedfile a]
     puts $g "$qnumindex"
     close $g
     set marker 0
     set qnumindex ""
    }
   }
   set g [open $alreadyaskedfile a]
   puts $g "$qnumindex"
   close $g
##
  }
  if {$thirdindexchecker != ""} {
## Create Zeroed Question Already Asked Markers For Tracker!
   set g [open $alreadyaskedfile w]
   puts $g "$qafilelength $qafilelength"
   close $g
   set qnumindex ""
   set marker 0
   set totalqs 0
   while {$totalqs <= $qafilelength} {
    append qnumindex "0"
    incr marker
    incr totalqs
    if {$marker == $marksplitter} {
     set g [open $alreadyaskedfile a]
     puts $g "$qnumindex"
     close $g
     set marker 0
     set qnumindex ""
    }
   }
   set g [open $alreadyaskedfile a]
   puts $g "$qnumindex"
   close $g
##
  }
 }
## This routine creates initial AlreadyAsked Question line for determining an unasked question!
 if {$AATrackerEnable == 1} {
  set g [open $alreadyaskedfile r]
  gets $g bankinfo
  set totalunaskedquestions [lindex $bankinfo 0]
  set banksizechecker [lindex $bankinfo 1]
  if {$totalunaskedquestions < 0} {set totalunaskedquestions $banksizechecker}
  set qnumindex ""
  while {[gets $g line2merge] != -1} {
   append qnumindex "$line2merge"
  }
  close $g
 }
## This routine will Remove All DELETED or REMOVED Question Numbers so they won't be used!
 set delfile "TriviabotErroredQuestions.txt"
 set triviadeletions ""
 set totalerrors 0
 if {[file exist $delfile]} {
  set f [open $delfile r]
  while {[gets $f dline] != -1} {
   incr totalerrors
   if {$qafile == [lindex $dline 0]} {
    if {[string length $qnumindex] >= [lindex $dline 1]} { 
     set newqnumindex "[string range $qnumindex 0 [expr [lindex $dline 1] -1]]"
     append newqnumindex "1"
     append newqnumindex "[string range $qnumindex [expr [lindex $dline 1] +1] end]"
     set qnumindex $newqnumindex
    }
   }
  }
  close $f
 }
 
## This routine will Remove All DELETED or REMOVED Question Numbers so they won't be used!
 set delfile "TriviabotFlaggedQuestions.txt"
 set triviadeletions ""
 set totalerrors 0
 if {[file exist $delfile]} {
  set f [open $delfile r]
  while {[gets $f dline] != -1} {
     incr totalerrors
     if {$qafile == [lindex $dline 0]} {
       if {[string length $qnumindex] >= [lindex $dline 1]} { 
	set newqnumindex "[string range $qnumindex 0 [expr [lindex $dline 1] -1]]"
	append newqnumindex "1"
	append newqnumindex "[string range $qnumindex [expr [lindex $dline 1] +1] end]"
        set qnumindex $newqnumindex
       }
     }
   }
  close $f
}
##
## Pick Question Number From Remaining Array
 if {$AATrackerEnable == 1} {
  if {$banksizechecker != $qafilelength} {
### IF QUESTIONS QUANTITY TO THIS BANK HAS CHANGED, REBUILD 0 TRACKER
## Create Zeroed Question Already Asked Markers For Tracker!
  set g [open "TriviaBankTotals.txt" r]
  while {[gets $g line] != -1} {
   if {[lindex $line 0] == $qafile} {
    set qafilelength [lindex $line 1]
   }
  }
  close $g
##
  set origqfilelength $qafilelength
  set totalunaskedquestions $qafilelength
  set g [open $alreadyaskedfile w]
  puts $g "$qafilelength $qafilelength"
  close $g
  set qnumindex ""
  set qnumindex2 ""
  set marker 0
  set totalqs 0
  while {$totalqs <= $qafilelength} {
   append qnumindex "0"
   append qnumindex2 "0"
   incr marker
   incr totalqs
   if {$marker == $marksplitter} {
    set g [open $alreadyaskedfile a]
    puts $g "$qnumindex"
    close $g
    set marker 0
    set qnumindex ""
   }
  }
  set g [open $alreadyaskedfile a]
  puts $g "$qnumindex"
  close $g
  set qnumindex $qnumindex2
##
 }
 set aaflagtocheck "0"
 if {[string first $aaflagtocheck $qnumindex] == -1} {
  if {$banksizechecker != $qafilelength} {
### IF QUESTIONS QUANTITY TO THIS BANK HAS CHANGED, REBUILD 0 TRACKER
## Create Zeroed Question Already Asked Markers For Tracker!
   set g [open "TriviaBankTotals.txt" r]
   while {[gets $g line] != -1} {
    if {[lindex $line 0] == $qafile} {
     set qafilelength [lindex $line 1]
    }
   }
   close $g
##
   set origqfilelength $qafilelength
   set totalunaskedquestions $qafilelength
   set g [open $alreadyaskedfile w]
   puts $g "$qafilelength $qafilelength"
   close $g
   set qnumindex ""
   set qnumindex2 ""
   set marker 0
   set totalqs 0
   while {$totalqs <= $qafilelength} {
    append qnumindex "0"
    append qnumindex2 "0"
    incr marker
    incr totalqs
    if {$marker == $marksplitter} {
     set g [open $alreadyaskedfile a]
     puts $g "$qnumindex"
     close $g
     set marker 0
     set qnumindex ""
    }
   }
   set g [open $alreadyaskedfile a]
   puts $g "$qnumindex"
   close $g
   set qnumindex $qnumindex2
##
  }
###
  regsub -nocase -all {[1]} $qnumindex "0" qnumindex2
  set qnumindex $qnumindex2
  set qafilelength $origqfilelength
  set totalunaskedquestions $qafilelength
  putquick "privmsg $triviachannel :Questions have all been asked from the $qafile bank and are all reset...getting the next question now..."
 }
 }
## This routine will Remove All DELETED or REMOVED Question Numbers so they won't be used!
 set delfile "TriviabotErroredQuestions.txt"
 set triviadeletions ""
 set totalerrors 0
 if {[file exist $delfile]} {
  set f [open $delfile r]
  while {[gets $f dline] != -1} {
     incr totalerrors
     if {$qafile == [lindex $dline 0]} {
       if {[string length $qnumindex] >= [lindex $dline 1]} { 
	set newqnumindex "[string range $qnumindex 0 [expr [lindex $dline 1] -1]]"
	append newqnumindex "1"
	append newqnumindex "[string range $qnumindex [expr [lindex $dline 1] +1] end]"
        set qnumindex $newqnumindex
       }
     }
   }
  close $f
}

## This routine will Remove All DELETED or REMOVED Question Numbers so they won't be used!
 set delfile "TriviabotFlaggedQuestions.txt"
 set triviadeletions ""
 set totalerrors 0
 if {[file exist $delfile]} {
  set f [open $delfile r]
  while {[gets $f dline] != -1} {
     incr totalerrors
     if {$qafile == [lindex $dline 0]} {
       if {[string length $qnumindex] >= [lindex $dline 1]} { 
	set newqnumindex "[string range $qnumindex 0 [expr [lindex $dline 1] -1]]"
	append newqnumindex "1"
	append newqnumindex "[string range $qnumindex [expr [lindex $dline 1] +1] end]"
        set qnumindex $newqnumindex
       }
     }
   }
  close $f
}


set qnumber [rand [string length $qnumindex]]
   set zeromarker "0"
   set gotnewq [string range $qnumindex $qnumber end]
   set newqnum [string first $zeromarker $gotnewq]
   if {$newqnum != -1} {set qnumber [expr $newqnum + $qnumber]}
   if {$newqnum == -1} {
    set newqnum [string first $zeromarker $qnumindex]
    set qnumber $newqnum
   }
###################################################################################

##### Valid Unasked Trivia Question Has Now Been Determined...Update AlreadyAsked File With 1 Flag
##### On Currently Asked Trivia Question Number and Write It To Trivia Bank's Already Asked File!

set newqnumindex "[string range $qnumindex 0 [expr $qnumber -1]]"
append newqnumindex "1"
append newqnumindex "[string range $qnumindex [expr $qnumber +1] end]"

##################################################################################################
set f [open $alreadyaskedfile w]
puts $f "[expr $totalunaskedquestions -1] $qafilelength"
set linetosplit [string range $newqnumindex 0 [expr $marksplitter -1]]
while {$linetosplit != ""} {
 puts $f $linetosplit
 set newqnumindex [string range $newqnumindex $marksplitter end]
 set linetosplit [string range $newqnumindex 0 [expr $marksplitter -1]]
}
close $f
}

##
## Question Number Is Now Determined...Let's Reference It In the 
## AlreadyAsked/QuestionInUse.txt file and Get the Question Now!

set f [open "AlreadyAsked/QuestionInUse.txt" w]
puts $f "TriviaBank: $qafile, Question: $qnumber!"
close $f

 set f [open $qafile r]
 set counter 0
 set lcounter 0
 while {$counter <= $qnumber} {
  gets $f qaline
  incr counter
  incr lcounter
 }
 close $f

if {$AATrackerEnable == 0} {
 set totalunaskedquestions [llength $qnumindex]
}

## If This Question Is Edited, Use The Edited Version!
set delfile "TriviaEditedQuestions.txt"

 if {[file exist $delfile]} {

  set f [open $delfile r]
  while {[gets $f teline] != -1} {
   if {[lindex $teline 0] == $qafile} {
    if {[lindex $teline 1] == $qnumber} {
     set qaline [lrange $teline 2 end]
    }
   }
  }
  close $f
 }

set qnumindex ""
set currentaskedlist ""
set qnumindex ""
if {$AATrackerEnable == 0} {set totalunaskedquestions "Not Applicable"}
if {$sendanswertoowner == 1} {
  putquick "privmsg $triviaowner :Question Bank in use is $qafile, Total Questions in this bank is [expr $qafilelength +1], Total Unasked Questions from this bank is $totalunaskedquestions and the next question number is $qnumber"
 }
## Determine Actual Number of Trivia Question In Reference To Total Available Questions!
set newqnumber 0
set f [open "TriviaBankTotals.txt" r]
set filefound 0
while {[gets $f ttline] != -1} {
 if {[lindex $ttline 0] == $qafile} {
  set filefound 1
 }
 if {$filefound == 0} {
  incr newqnumber [lindex $ttline 1]
 }
}
incr newqnumber $qnumber
close $f
set qnumber $newqnumber
##
##
 set marker "*"
 set qamarker [string first $marker $qaline]
 set answerstartmarker [expr $qamarker + 1]
 set questionendmarker [expr $qamarker - 1]
 set question [string range $qaline 0 $questionendmarker]
 set answer [string range $qaline $answerstartmarker end]
 
 ### NEW V6.5 CODE FOR REMOVING SPACES AT START AND END OF ANSWERS ###
 
 ### Remove beginning spaces
 while {[string range $answer 0 0] == " "} {
  set answer [string range $answer 1 end]
 }
 
 ### Remove spaces at end of answer
 set endoflinelength [string length $answer]

 while {[string range $answer [expr $endoflinelength -1] [expr $endoflinelength -1]] == " "} {
  set answer [string range $answer 0 [expr $endoflinelength -2]]
  set endoflinelength [string length $answer]
}



 
 ## END NEW V6.5 CODE FOR REMOVING SPACES AT START AND END OF ANSWERS ##

 set morethanoneanswerchecker 0
 set morethanoneanswerchecker [string first $marker $answer]
 if {$morethanoneanswerchecker > 0 } {
  set morethanoneanswerchecker [expr $morethanoneanswerchecker -1]
  set answer [string range $answer 0 $morethanoneanswerchecker]
 }
 #### ADD MULTIPLE ANSWERS (IF ANY) INTO AN ARRAY IN CASE MULTIPLE
 #### ANSWER ENABLER IS ON!
  if {$multipleenable == 1} {
 
 
  set marker "*"
  set qamarker [string first $marker $qaline]
  set answerstartmarker [expr $qamarker + 1]
  set questionendmarker [expr $qamarker - 1]
  set question [string range $qaline 0 $questionendmarker]
  set answers [string range $qaline $answerstartmarker end]
  	if [info exists validanswer] {unset validanswer}
 	set answercounter 0
 	set qamarker [expr $qamarker +1]
 	set answersleft [string range $qaline $qamarker end]
 	set endofanswersflag 0
 	while {$endofanswersflag != 1 } {
 	set answerend [string first $marker $answersleft]
 	if {$answerend < 1} {
    	 set endofanswersflag 1
 	}
 	set answerend [expr $answerend -1]
 	if {$answerend == -2} {set answerend [string length $answersleft]}
 	set answers [string range $answersleft 0 $answerend]
 	set answers [string tolower $answers]

 ### NEW V6.5 CODE FOR REMOVING SPACES AT START AND END OF ANSWERS ###
 
 ### Remove beginning spaces
 while {[string range $answers 0 0] == " "} {
  set answers [string range $answers 1 end]
 }
 
 ### Remove spaces at end of answer
 set endoflinelength [string length $answers]


 while {[string range $answers [expr $endoflinelength -1] [expr $endoflinelength -1]] == " "} {
  set answers [string range $answers 0 [expr $endoflinelength -2]]
  set endoflinelength [string length $answers]
}




 
 ## END NEW V6.5 CODE FOR REMOVING SPACES AT START AND END OF ANSWERS ##


 	set validanswer($answercounter) "$answers"
 
 	append allanswers "$answers, "
 	set qamarker [expr $answerend +2]
 	set answersleft [string range $answersleft $qamarker end]
 	incr answercounter
 	}
	set numberofanswers $answercounter
 
 
 }
 ####
 set boldqenable 0
 set nquestion ""
 if {$boldqenable == 1} {
  append nquestion ""
 }
# append nquestion [string tolower $question]
 append nquestion $question
 set question $nquestion
 set answer [string tolower $answer]
 set hintcounter 0
## Create Initial Dotted Answer Hint Layout-Works Perfectly!
set hint ""
regsub -nocase -all {[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]} $answer "$HintCharacter" hint
set counter 0
if {$ucqvenable == 1} {
 set triviavalue [expr [string length $answer] - [llength $answer] +1]
 set origtrivvalue $triviavalue
}

if {[string length $question] < 1} {
set question "There's No Clue For This Question..."
}

if {$bonusqenable == 1} {
set counter 1
 set pointdrophintdecrease $origpointdrophintdecrease
 set pointdropdecrease $origpointdrophintdecrease
    set triviavalue [lindex $bonusvalues 0]
    set pointdropdecrease [lindex $bonusdrops 0]
    set pointdrophintdecrease [lindex $bonusdrops 0] 
 while {[lindex $bonuslengths $counter] != ""} {
  if {[string length $answer] >= [lindex $bonuslengths $counter]} {
     set triviavalue [lindex $bonusvalues $counter]
     set pointdropdecrease [lindex $bonusdrops $counter]
     set pointdrophintdecrease [lindex $bonusdrops $counter]
  }
  incr counter
 }
}
## Insert Question Anti-Piracy Code Here!!!
 set question "$QText,$QBackground $question"
 if {$nontriviapiracy == 1} {
 set letters "fijlt"
 set antipiracy ""
## Random Restoration Of Original Text And Background Color Code Creation Routine
 set counter 0
 set flipper 0
 set flipflag 0
 set endofqflag 0
 while {[lindex $question $counter] != "" } {
  set numberflag 0
  set numberchecker [lindex $question [expr $counter +1]]
  if {[lindex $question [expr $counter +1]] == ""} {set endofqflag 1}
  set testforanumber 0
  while {$testforanumber <= 9} {
   if {[string range $numberchecker 0 0] == $testforanumber} {
    set numberflag 1
   }
   incr testforanumber
  }
  if {$endofqflag == 1} {
   append antipiracy [lindex $question $counter]
   set numberflag 10
   set flipper 10
  }
  if {$flipper == 0} {
   set antipiracyletter [string index $letters [rand [string length $letters]]]
   append antipiracy [lindex $question $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($QBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $QBackground
}
append antipiracy $embedcode
##
   if {$numberflag == 0} {
    append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($QText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $QText
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($QText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $QText
}
append antipiracy "$restorecode "
##
   }
   set flipper 1
   set flipflag 1
  } {
   if {$flipflag == 0} {
   if {$flipper == 1} {
    set antipiracyletter " "
    append antipiracy [lindex $question $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($QBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $QBackground
}
append antipiracy $embedcode
##
   }
   if {$numberflag == 0} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($QText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $QText
}
append antipiracy $restorecode
##

append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($QText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $QText
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($QText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $QText
}
append antipiracy "$restorecode "
##
   }
   set flipper 0
  }
  }
  set flipflag 0
  incr counter
 }
 set qlength [string length $antipiracy]
 set question $antipiracy
}
 set dater [unixtime]
 set datechecker [ctime $dater]
 set yearfilename "TriviaYearlyScores/"
 set yearname [lindex $datechecker 4]
 append yearfilename $yearname
 set yearhtmlfilename "HTMLYearlyScores/"
 append yearhtmlfilename $yearname
 append yearfilename ".txt"
 append yearhtmlfilename ".html"
 if {![file exist $yearfilename]} {
  clearyeartop10
 }
 if [info exists yearscore] { unset yearscore }
 read_yearscore
 set monthfilename "TriviaMonthlyScores/"
 set monthhtmlfilename "HTMLMonthlyScores/"
 append monthhtmlfilename [lindex $datechecker 1]
 append monthhtmlfilename [lindex $datechecker 4]

 append monthfilename [lindex $datechecker 1]
 append monthfilename [lindex $datechecker 4]
 append monthfilename ".txt"
 append monthhtmlfilename ".html"
 if ![file exist "GenericScoresTEXT/TopStreakers.txt"] {
 set pp [open "GenericScoresTEXT/TopStreakers.txt" w]
 close $pp
 }
 
 if ![file exist "GenericScoresTEXT/FastestPlayers.txt"] {
  set pp [open "GenericScoresTEXT/FastestPlayers.txt" w]
  close $pp
 }
 if ![file exist "GenericScoresTEXT/FastestPlayersLastMonth.txt"] {
   set pp [open "GenericScoresTEXT/FastestPlayersLastMonth.txt" w]
   close $pp
 }
#### MONTHLY SCORE CODE
 if {![file exist $monthfilename]} {
  cleartop10
 }

###YYY INITIAL STARTING GLITCH IS AROUND THIS AREA...GRRRRRR...
 if [info exists score] { unset score }
 read_score
 if [info exists fastanswerscore] { unset fastanswerscore }
 read_fastanswers
 if [info exists streakscore] { unset streakscore }
 read_streak
 set dayfilename "TriviaDailyScores/"
 append dayfilename [lindex $datechecker 1]
 append dayfilename [lindex $datechecker 2]
 append dayfilename [lindex $datechecker 4]
 set day1name [lindex $datechecker 1]
 set day2name [lindex $datechecker 2]
 set day3name [lindex $datechecker 4]
 set dayhtmlfilename "HTMLDailyScores/"
 append dayhtmlfilename $day1name
 append dayhtmlfilename $day2name
 append dayhtmlfilename $day3name
 append dayfilename ".txt"
 append dayhtmlfilename ".html"
 if {![file exist $dayfilename]} {
 cleardailytop10
}
 if [info exists dayscore] { unset dayscore }
 read_dayscore
####################### NEW WEEKLY SCORE CODE #########################################
 set dater [unixtime]
 set datechecker [ctime $dater]
 set month [lindex $datechecker 1]
 set day [lindex $datechecker 2]
 set year [lindex $datechecker 4]
set weekfilename "TriviaWeeklyScores/"
set weekhtmlfilename "HTMLWeeklyScores/"
set foundit 0
if {$month == "Jan"} {
 if {$foundit == 0} {
  if {7 >= $day} {
   set foundit 1
   set weekfile "Week1_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {14 >= $day} {
   set foundit 1
   set weekfile "Week2_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {21 >= $day} {
   set foundit 1
   set weekfile "Week3_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {28 >= $day} {
   set foundit 1
   set weekfile "Week4_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 28} {
   set foundit 1
   set weekfile "Week5_"
   append weekfile "$year"
  }

 }
}

if {$foundit == 0} {
if {$month == "Feb"} {
 if {$foundit == 0} {
  if {4 >= $day} {
   set foundit 1
   set weekfile "Week5_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {11 >= $day} {
   set foundit 1
   set weekfile "Week6_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {18 >= $day} {
   set foundit 1
   set weekfile "Week7_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {25 >= $day} {
   set foundit 1
   set weekfile "Week8_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 25} {
   set foundit 1
   set weekfile "Week9_"
   append weekfile "$year"
  }
 }

 }
}

if {$foundit == 0} {
if {$month == "Mar"} {
 if {$foundit == 0} {
  if {4 >= $day} {
   set foundit 1
   set weekfile "Week9_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {11 >= $day} {
   set foundit 1
   set weekfile "Week10_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {18 >= $day} {
   set foundit 1
   set weekfile "Week11_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {25 >= $day} {
   set foundit 1
   set weekfile "Week12_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 25} {
   set foundit 1
   set weekfile "Week13_"
   append weekfile "$year"
  }
 }

 }
}

if {$foundit == 0} {
if {$month == "Apr"} {
 if {$foundit == 0} {
  if {1 >= $day} {
   set foundit 1
   set weekfile "Week13_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {8 >= $day} {
   set foundit 1
   set weekfile "Week14_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {15 >= $day} {
   set foundit 1
   set weekfile "Week15_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {22 >= $day} {
   set foundit 1
   set weekfile "Week16_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {29 >= $day} {
   set foundit 1
   set weekfile "Week17_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 29} {
   set foundit 1
   set weekfile "Week18_"
   append weekfile "$year"
  }
 }
 }
}

if {$foundit == 0} {
if {$month == "May"} {
 if {$foundit == 0} {
  if {6 >= $day} {
   set foundit 1
   set weekfile "Week18_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {13 >= $day} {
   set foundit 1
   set weekfile "Week19_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {20 >= $day} {
   set foundit 1
   set weekfile "Week20_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {27 >= $day} {
   set foundit 1
   set weekfile "Week21_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 27} {
   set foundit 1
   set weekfile "Week22_"
   append weekfile "$year"
  }
 }
 }
}

if {$foundit == 0} {
if {$month == "Jun"} {
 if {$foundit == 0} {
  if {3 >= $day} {
   set foundit 1
   set weekfile "Week22_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {10 >= $day} {
   set foundit 1
   set weekfile "Week23_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {17 >= $day} {
   set foundit 1
   set weekfile "Week24_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {24 >= $day} {
   set foundit 1
   set weekfile "Week25_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 24} {
   set foundit 1
   set weekfile "Week26_"
   append weekfile "$year"
  }
 }
 }
}

if {$foundit == 0} {
if {$month == "Jul"} {
 if {$foundit == 0} {
  if {1 >= $day} {
   set foundit 1
   set weekfile "Week26_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {8 >= $day} {
   set foundit 1
   set weekfile "Week27_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {15 >= $day} {
   set foundit 1
   set weekfile "Week28_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {22 >= $day} {
   set foundit 1
   set weekfile "Week29_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {29 >= $day} {
   set foundit 1
   set weekfile "Week30_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 29} {
   set foundit 1
   set weekfile "Week31_"
   append weekfile "$year"
  }
 }
 }
}

if {$foundit == 0} {
if {$month == "Aug"} {
 if {$foundit == 0} {
  if {5 >= $day} {
   set foundit 1
   set weekfile "Week31_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {12 >= $day} {
   set foundit 1
   set weekfile "Week32_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {19 >= $day} {
   set foundit 1
   set weekfile "Week33_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {26 >= $day} {
   set foundit 1
   set weekfile "Week34_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 26} {
   set foundit 1
   set weekfile "Week35_"
   append weekfile "$year"
  }
 }
 }
}


if {$foundit == 0} {
if {$month == "Sep"} {
 if {$foundit == 0} {
  if {2 >= $day} {
   set foundit 1
   set weekfile "Week35_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {9 >= $day} {
   set foundit 1
   set weekfile "Week36_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {16 >= $day} {
   set foundit 1
   set weekfile "Week37_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {23 >= $day} {
   set foundit 1
   set weekfile "Week38_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 23} {
   set foundit 1
   set weekfile "Week39_"
   append weekfile "$year"
  }
 }
 }
}


if {$foundit == 0} {
if {$month == "Oct"} {
 if {$foundit == 0} {
  if {7 >= $day} {
   set foundit 1
   set weekfile "Week40_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {14 >= $day} {
   set foundit 1
   set weekfile "Week41_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {21 >= $day} {
   set foundit 1
   set weekfile "Week42_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {28 >= $day} {
   set foundit 1
   set weekfile "Week43_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 28} {
   set foundit 1
   set weekfile "Week44_"
   append weekfile "$year"
  }
 }
 }
}


if {$foundit == 0} {
if {$month == "Nov"} {
 if {$foundit == 0} {
  if {4 >= $day} {
   set foundit 1
   set weekfile "Week44_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {11 >= $day} {
   set foundit 1
   set weekfile "Week45_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {18 >= $day} {
   set foundit 1
   set weekfile "Week46_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {25 >= $day} {
   set foundit 1
   set weekfile "Week47_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 25} {
   set foundit 1
   set weekfile "Week48_"
   append weekfile "$year"
  }
 }
 }
}


if {$foundit == 0} {
if {$month == "Dec"} {
 if {$foundit == 0} {
  if {2 >= $day} {
   set foundit 1
   set weekfile "Week48_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {9 >= $day} {
   set foundit 1
   set weekfile "Week49_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {16 >= $day} {
   set foundit 1
   set weekfile "Week50_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {23 >= $day} {
   set foundit 1
   set weekfile "Week51_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 23} {
   set foundit 1
   set weekfile "Week52_"
   append weekfile "$year"
  }
 }
 }
}

 append weekfilename $weekfile
 append weekhtmlfilename $weekfile

 append weekfilename ".txt"
 append weekhtmlfilename ".html"
 if {![file exist $weekfilename]} {
  set f [open $weekfilename w]
  puts $f "$triviaowner 0"
  close $f
 }
####################### END OF NEW WEEKLY SCORE CODE ###################################
 if [info exists weekscore] { unset weekscore }
 read_weekscore
 set prevmonthfilename $monthfilename
 set monthhtmlfilename "HTMLMonthlyScores/"
 append monthhtmlfilename [lindex $datechecker 1]
 append monthhtmlfilename [lindex $datechecker 4]
 append monthhtmlfilename ".html"
## If new month, do appropriate checks!!!
####### NEW CODE FOR DETERMINING DAYS LEFT IN A WEEK!
 set dater [unixtime]
 set datechecker [ctime $dater]
 set month [lindex $datechecker 1]
 set day [lindex $datechecker 2]
 set year [lindex $datechecker 4]
set foundit 0
set daysleft ""
 if {$foundit == 0} {
if {$month == "Jan"} {
  if {$day == 1} {
set daysleft 7
set foundit 1
}
  if {$day == 2} {
set daysleft 6
set foundit 1
 }
  if {$day == 3} {
set daysleft 5
set foundit 1
 }
  if {$day == 4} {
set daysleft 4
set foundit 1
 }
  if {$day == 5} {
set daysleft 3
set foundit 1
 }
  if {$day == 6} {
set daysleft 2
set foundit 1
 }
  if {$day == 7} {
set daysleft 1
set foundit 1
 }
  if {$day == 8} {
set daysleft 7
set foundit 1
 }
  if {$day == 9} {
set daysleft 6
set foundit 1
 }
  if {$day == 10} {
set daysleft 5
set foundit 1
 }
  if {$day == 11} {
set daysleft 4
set foundit 1
 }
  if {$day == 12} {
set daysleft 3
set foundit 1
 }
  if {$day == 13} {
set daysleft 2
set foundit 1
 }
  if {$day == 14} {
set daysleft 1
set foundit 1
 }
  if {$day == 15} {
set daysleft 7
set foundit 1
 }
  if {$day == 16} {
set daysleft 6
set foundit 1
 }
  if {$day == 17} {
set daysleft 5
set foundit 1
 }
  if {$day == 18} {
set daysleft 4
set foundit 1
 }
  if {$day == 19} {
set daysleft 3
set foundit 1
 }
  if {$day == 20} {
set daysleft 2
set foundit 1
 }
  if {$day == 21} {
set daysleft 1
set foundit 1
 }
  if {$day == 22} {
set daysleft 7
set foundit 1
 }
  if {$day == 23} {
set daysleft 6
set foundit 1
 }
  if {$day == 24} {
set daysleft 5
set foundit 1
 }
  if {$day == 25} {
set daysleft 4
set foundit 1
 }
  if {$day == 26} {
set daysleft 3
set foundit 1
 }
  if {$day == 27} {
set daysleft 2
set foundit 1
 }
  if {$day == 28} {
set daysleft 1
set foundit 1
 }
  if {$day == 29} {
set daysleft 7
set foundit 1
 }
  if {$day == 30} {
set daysleft 6
set foundit 1
 }
  if {$day == 31} {
set daysleft 5
set foundit 1
 }

}
}

### February
 if {$foundit == 0} {
if {$month == "Feb"} {
  if {$day == 1} {
set daysleft 4
set foundit 1
}
  if {$day == 2} {
set daysleft 3
set foundit 1
 }
  if {$day == 3} {
set daysleft 2
set foundit 1
 }
  if {$day == 4} {
set daysleft 1
set foundit 1
 }
  if {$day == 5} {
set daysleft 7
set foundit 1
 }
  if {$day == 6} {
set daysleft 6
set foundit 1
 }
  if {$day == 7} {
set daysleft 5
set foundit 1
 }
  if {$day == 8} {
set daysleft 4
set foundit 1
 }
  if {$day == 9} {
set daysleft 3
set foundit 1
 }
  if {$day == 10} {
set daysleft 2
set foundit 1
 }
  if {$day == 11} {
set daysleft 1
set foundit 1
 }
  if {$day == 12} {
set daysleft 7
set foundit 1
 }
  if {$day == 13} {
set daysleft 6
set foundit 1
 }
  if {$day == 14} {
set daysleft 5
set foundit 1
 }
  if {$day == 15} {
set daysleft 4
set foundit 1
 }
  if {$day == 16} {
set daysleft 3
set foundit 1
 }
  if {$day == 17} {
set daysleft 2
set foundit 1
 }
  if {$day == 18} {
set daysleft 1
set foundit 1
 }
  if {$day == 19} {
set daysleft 7
set foundit 1
 }
  if {$day == 20} {
set daysleft 6
set foundit 1
 }
  if {$day == 21} {
set daysleft 5
set foundit 1
 }
  if {$day == 22} {
set daysleft 4
set foundit 1
 }
  if {$day == 23} {
set daysleft 3
set foundit 1
 }
  if {$day == 24} {
set daysleft 2
set foundit 1
 }
  if {$day == 25} {
set daysleft 1
set foundit 1
 }
  if {$day == 26} {
set daysleft 7
set foundit 1
 }
  if {$day == 27} {
set daysleft 6
set foundit 1
 }
  if {$day == 28} {
set daysleft 5
set foundit 1
 }
 if {[expr $year % 4] == 0} {
  if {$day == 26} {
set daysleft 8
set foundit 1
 }
  if {$day == 27} {
set daysleft 7
set foundit 1
 }
  if {$day == 28} {
set daysleft 6
set foundit 1
 }
  if {$day == 29} {
set daysleft 5
set foundit 1
 }
 }

}
}

### March
 if {$foundit == 0} {
if {$month == "Mar"} {
  if {$day == 1} {
set daysleft 4
set foundit 1
}
  if {$day == 2} {
set daysleft 3
set foundit 1
 }
  if {$day == 3} {
set daysleft 2
set foundit 1
 }
  if {$day == 4} {
set daysleft 1
set foundit 1
 }
  if {$day == 5} {
set daysleft 7
set foundit 1
 }
  if {$day == 6} {
set daysleft 6
set foundit 1
 }
  if {$day == 7} {
set daysleft 5
set foundit 1
 }
  if {$day == 8} {
set daysleft 4
set foundit 1
 }
  if {$day == 9} {
set daysleft 3
set foundit 1
 }
  if {$day == 10} {
set daysleft 2
set foundit 1
 }
  if {$day == 11} {
set daysleft 1
set foundit 1
 }
  if {$day == 12} {
set daysleft 7
set foundit 1
 }
  if {$day == 13} {
set daysleft 6
set foundit 1
 }
  if {$day == 14} {
set daysleft 5
set foundit 1
 }
  if {$day == 15} {
set daysleft 4
set foundit 1
 }
  if {$day == 16} {
set daysleft 3
set foundit 1
 }
  if {$day == 17} {
set daysleft 2
set foundit 1
 }
  if {$day == 18} {
set daysleft 1
set foundit 1
 }
  if {$day == 19} {
set daysleft 7
set foundit 1
 }
  if {$day == 20} {
set daysleft 6
set foundit 1
 }
  if {$day == 21} {
set daysleft 5
set foundit 1
 }
  if {$day == 22} {
set daysleft 4
set foundit 1
 }
  if {$day == 23} {
set daysleft 3
set foundit 1
 }
  if {$day == 24} {
set daysleft 2
set foundit 1
 }
  if {$day == 25} {
set daysleft 1
set foundit 1
 }
  if {$day == 26} {
set daysleft 7
set foundit 1
 }
  if {$day == 27} {
set daysleft 6
set foundit 1
 }
  if {$day == 28} {
set daysleft 5
set foundit 1
 }
  if {$day == 29} {
set daysleft 4
set foundit 1
 }
  if {$day == 30} {
set daysleft 3
set foundit 1
 }
  if {$day == 31} {
set daysleft 2
set foundit 1
 }
}
}
### April
 if {$foundit == 0} {
if {$month == "Apr"} {
  if {$day == 1} {
set daysleft 1
set foundit 1
}
  if {$day == 2} {
set daysleft 7
set foundit 1
 }
  if {$day == 3} {
set daysleft 6
set foundit 1
 }
  if {$day == 4} {
set daysleft 5
set foundit 1
 }
  if {$day == 5} {
set daysleft 4
set foundit 1
 }
  if {$day == 6} {
set daysleft 3
set foundit 1
 }
  if {$day == 7} {
set daysleft 2
set foundit 1
 }
  if {$day == 8} {
set daysleft 1
set foundit 1
 }
  if {$day == 9} {
set daysleft 7
set foundit 1
 }
  if {$day == 10} {
set daysleft 6
set foundit 1
 }
  if {$day == 11} {
set daysleft 5
set foundit 1
 }
  if {$day == 12} {
set daysleft 4
set foundit 1
 }
  if {$day == 13} {
set daysleft 3
set foundit 1
 }
  if {$day == 14} {
set daysleft 2
set foundit 1
 }
  if {$day == 15} {
set daysleft 1
set foundit 1
 }
  if {$day == 16} {
set daysleft 7
set foundit 1
 }
  if {$day == 17} {
set daysleft 6
set foundit 1
 }
  if {$day == 18} {
set daysleft 5
set foundit 1
 }
  if {$day == 19} {
set daysleft 4
set foundit 1
 }
  if {$day == 20} {
set daysleft 3
set foundit 1
 }
  if {$day == 21} {
set daysleft 2
set foundit 1
 }
  if {$day == 22} {
set daysleft 1
set foundit 1
 }
  if {$day == 23} {
set daysleft 7
set foundit 1
 }
  if {$day == 24} {
set daysleft 6
set foundit 1
 }
  if {$day == 25} {
set daysleft 5
set foundit 1
 }
  if {$day == 26} {
set daysleft 4
set foundit 1
 }
  if {$day == 27} {
set daysleft 3
set foundit 1
 }
  if {$day == 28} {
set daysleft 2
set foundit 1
 }
  if {$day == 29} {
set daysleft 1
set foundit 1
 }
  if {$day == 30} {
set daysleft 7
set foundit 1
 }

}
}
### May
 if {$foundit == 0} {
if {$month == "May"} {
  if {$day == 1} {
set daysleft 6
set foundit 1
}
  if {$day == 2} {
set daysleft 5
set foundit 1
 }
  if {$day == 3} {
set daysleft 4
set foundit 1
 }
  if {$day == 4} {
set daysleft 3
set foundit 1
 }
  if {$day == 5} {
set daysleft 2
set foundit 1
 }
  if {$day == 6} {
set daysleft 1
set foundit 1
 }
  if {$day == 7} {
set daysleft 7
set foundit 1
 }
  if {$day == 8} {
set daysleft 6
set foundit 1
 }
  if {$day == 9} {
set daysleft 5
set foundit 1
 }
  if {$day == 10} {
set daysleft 4
set foundit 1
 }
  if {$day == 11} {
set daysleft 3
set foundit 1
 }
  if {$day == 12} {
set daysleft 2
set foundit 1
 }
  if {$day == 13} {
set daysleft 1
set foundit 1
 }
  if {$day == 14} {
set daysleft 7
set foundit 1
 }
  if {$day == 15} {
set daysleft 6
set foundit 1
 }
  if {$day == 16} {
set daysleft 5
set foundit 1
 }
  if {$day == 17} {
set daysleft 4
set foundit 1
 }
  if {$day == 18} {
set daysleft 3
set foundit 1
 }
  if {$day == 19} {
set daysleft 2
set foundit 1
 }
  if {$day == 20} {
set daysleft 1
set foundit 1
 }
  if {$day == 21} {
set daysleft 7
set foundit 1
 }
  if {$day == 22} {
set daysleft 6
set foundit 1
 }
  if {$day == 23} {
set daysleft 5
set foundit 1
 }
  if {$day == 24} {
set daysleft 4
set foundit 1
 }
  if {$day == 25} {
set daysleft 3
set foundit 1
 }
  if {$day == 26} {
set daysleft 2
set foundit 1
 }
  if {$day == 27} {
set daysleft 1
set foundit 1
 }
  if {$day == 28} {
set daysleft 7
set foundit 1
 }
  if {$day == 29} {
set daysleft 6
set foundit 1
 }
  if {$day == 30} {
set daysleft 5
set foundit 1
 }
  if {$day == 31} {
set daysleft 4
set foundit 1
 }}
}
### June
 if {$foundit == 0} {
if {$month == "Jun"} {
  if {$day == 1} {
set daysleft 3
set foundit 1
}
  if {$day == 2} {
set daysleft 2
set foundit 1
 }
  if {$day == 3} {
set daysleft 1
set foundit 1
 }
  if {$day == 4} {
set daysleft 7
set foundit 1
 }
  if {$day == 5} {
set daysleft 6
set foundit 1
 }
  if {$day == 6} {
set daysleft 5
set foundit 1
 }
  if {$day == 7} {
set daysleft 4
set foundit 1
 }
  if {$day == 8} {
set daysleft 3
set foundit 1
 }
  if {$day == 9} {
set daysleft 2
set foundit 1
 }
  if {$day == 10} {
set daysleft 1
set foundit 1
 }
  if {$day == 11} {
set daysleft 7
set foundit 1
 }
  if {$day == 12} {
set daysleft 6
set foundit 1
 }
  if {$day == 13} {
set daysleft 5
set foundit 1
 }
  if {$day == 14} {
set daysleft 4
set foundit 1
 }
  if {$day == 15} {
set daysleft 3
set foundit 1
 }
  if {$day == 16} {
set daysleft 2
set foundit 1
 }
  if {$day == 17} {
set daysleft 1
set foundit 1
 }
  if {$day == 18} {
set daysleft 7
set foundit 1
 }
  if {$day == 19} {
set daysleft 6
set foundit 1
 }
  if {$day == 20} {
set daysleft 5
set foundit 1
 }
  if {$day == 21} {
set daysleft 4
set foundit 1
 }
  if {$day == 22} {
set daysleft 3
set foundit 1
 }
  if {$day == 23} {
set daysleft 2
set foundit 1
 }
  if {$day == 24} {
set daysleft 1
set foundit 1
 }
  if {$day == 25} {
set daysleft 7
set foundit 1
 }
  if {$day == 26} {
set daysleft 6
set foundit 1
 }
  if {$day == 27} {
set daysleft 5
set foundit 1
 }
  if {$day == 28} {
set daysleft 4
set foundit 1
 }
  if {$day == 29} {
set daysleft 3
set foundit 1
 }
  if {$day == 30} {
set daysleft 2
set foundit 1
 }
}
}
### July
 if {$foundit == 0} {
if {$month == "Jul"} {
  if {$day == 1} {
set daysleft 1
set foundit 1
}
  if {$day == 2} {
set daysleft 7
set foundit 1
 }
  if {$day == 3} {
set daysleft 6
set foundit 1
 }
  if {$day == 4} {
set daysleft 5
set foundit 1
 }
  if {$day == 5} {
set daysleft 4
set foundit 1
 }
  if {$day == 6} {
set daysleft 3
set foundit 1
 }
  if {$day == 7} {
set daysleft 2
set foundit 1
 }
  if {$day == 8} {
set daysleft 1
set foundit 1
 }
  if {$day == 9} {
set daysleft 7
set foundit 1
 }
  if {$day == 10} {
set daysleft 6
set foundit 1
 }
  if {$day == 11} {
set daysleft 5
set foundit 1
 }
  if {$day == 12} {
set daysleft 4
set foundit 1
 }
  if {$day == 13} {
set daysleft 3
set foundit 1
 }
  if {$day == 14} {
set daysleft 2
set foundit 1
 }
  if {$day == 15} {
set daysleft 1
set foundit 1
 }
  if {$day == 16} {
set daysleft 7
set foundit 1
 }
  if {$day == 17} {
set daysleft 6
set foundit 1
 }
  if {$day == 18} {
set daysleft 5
set foundit 1
 }
  if {$day == 19} {
set daysleft 4
set foundit 1
 }
  if {$day == 20} {
set daysleft 3
set foundit 1
 }
  if {$day == 21} {
set daysleft 2
set foundit 1
 }
  if {$day == 22} {
set daysleft 1
set foundit 1
 }
  if {$day == 23} {
set daysleft 7
set foundit 1
 }
  if {$day == 24} {
set daysleft 6
set foundit 1
 }
  if {$day == 25} {
set daysleft 5
set foundit 1
 }
  if {$day == 26} {
set daysleft 4
set foundit 1
 }
  if {$day == 27} {
set daysleft 3
set foundit 1
 }
  if {$day == 28} {
set daysleft 2
set foundit 1
 }
  if {$day == 29} {
set daysleft 1
set foundit 1
 }
  if {$day == 30} {
set daysleft 7
set foundit 1
 }
 if {$day == 31} {
 set daysleft 6
 set foundit 1
 }
}
}
### August
 if {$foundit == 0} {
if {$month == "Aug"} {
  if {$day == 1} {
set daysleft 5
set foundit 1
}
  if {$day == 2} {
set daysleft 4
set foundit 1
 }
  if {$day == 3} {
set daysleft 3
set foundit 1
 }
  if {$day == 4} {
set daysleft 2
set foundit 1
 }
  if {$day == 5} {
set daysleft 1
set foundit 1
 }
  if {$day == 6} {
set daysleft 7
set foundit 1
 }
  if {$day == 7} {
set daysleft 6
set foundit 1
 }
  if {$day == 8} {
set daysleft 5
set foundit 1
 }
  if {$day == 9} {
set daysleft 4
set foundit 1
 }
  if {$day == 10} {
set daysleft 3
set foundit 1
 }
  if {$day == 11} {
set daysleft 2
set foundit 1
 }
  if {$day == 12} {
set daysleft 1
set foundit 1
 }
  if {$day == 13} {
set daysleft 7
set foundit 1
 }
  if {$day == 14} {
set daysleft 6
set foundit 1
 }
  if {$day == 15} {
set daysleft 5
set foundit 1
 }
  if {$day == 16} {
set daysleft 4
set foundit 1
 }
  if {$day == 17} {
set daysleft 3
set foundit 1
 }
  if {$day == 18} {
set daysleft 2
set foundit 1
 }
  if {$day == 19} {
set daysleft 1
set foundit 1
 }
  if {$day == 20} {
set daysleft 7
set foundit 1
 }
  if {$day == 21} {
set daysleft 6
set foundit 1
 }
  if {$day == 22} {
set daysleft 5
set foundit 1
 }
  if {$day == 23} {
set daysleft 4
set foundit 1
 }
  if {$day == 24} {
set daysleft 3
set foundit 1
 }
  if {$day == 25} {
set daysleft 2
set foundit 1
 }
  if {$day == 26} {
set daysleft 1
set foundit 1
 }
  if {$day == 27} {
set daysleft 7
set foundit 1
 }
  if {$day == 28} {
set daysleft 6
set foundit 1
 }
  if {$day == 29} {
set daysleft 5
set foundit 1
 }
  if {$day == 30} {
set daysleft 4
set foundit 1
 }
 if {$day == 31} {
 set daysleft 3
 set foundit 1
 }
}
}
### September
 if {$foundit == 0} {
if {$month == "Sep"} {
  if {$day == 1} {
set daysleft 2
set foundit 1
}
  if {$day == 2} {
set daysleft 1
set foundit 1
 }
  if {$day == 3} {
set daysleft 7
set foundit 1
 }
  if {$day == 4} {
set daysleft 6
set foundit 1
 }
  if {$day == 5} {
set daysleft 5
set foundit 1
 }
  if {$day == 6} {
set daysleft 4
set foundit 1
 }
  if {$day == 7} {
set daysleft 3
set foundit 1
 }
  if {$day == 8} {
set daysleft 2
set foundit 1
 }
  if {$day == 9} {
set daysleft 1
set foundit 1
 }
  if {$day == 10} {
set daysleft 7
set foundit 1
 }
  if {$day == 11} {
set daysleft 6
set foundit 1
 }
  if {$day == 12} {
set daysleft 5
set foundit 1
 }
  if {$day == 13} {
set daysleft 4
set foundit 1
 }
  if {$day == 14} {
set daysleft 3
set foundit 1
 }
  if {$day == 15} {
set daysleft 2
set foundit 1
 }
  if {$day == 16} {
set daysleft 1
set foundit 1
 }
  if {$day == 17} {
set daysleft 7
set foundit 1
 }
  if {$day == 18} {
set daysleft 6
set foundit 1
 }
  if {$day == 19} {
set daysleft 5
set foundit 1
 }
  if {$day == 20} {
set daysleft 4
set foundit 1
 }
  if {$day == 21} {
set daysleft 3
set foundit 1
 }
  if {$day == 22} {
set daysleft 2
set foundit 1
 }
  if {$day == 23} {
set daysleft 1
set foundit 1
 }
  if {$day == 24} {
set daysleft 7
set foundit 1
 }
  if {$day == 25} {
set daysleft 6
set foundit 1
 }
  if {$day == 26} {
set daysleft 5
set foundit 1
 }
  if {$day == 27} {
set daysleft 4
set foundit 1
 }
  if {$day == 28} {
set daysleft 3
set foundit 1
 }
  if {$day == 29} {
set daysleft 2
set foundit 1
 }
  if {$day == 30} {
set daysleft 1
set foundit 1
 }
 }
}
### October
 if {$foundit == 0} {
if {$month == "Oct"} {
  if {$day == 1} {
set daysleft 7
set foundit 1
}
  if {$day == 2} {
set daysleft 6
set foundit 1
 }
  if {$day == 3} {
set daysleft 5
set foundit 1
 }
  if {$day == 4} {
set daysleft 4
set foundit 1
 }
  if {$day == 5} {
set daysleft 3
set foundit 1
 }
  if {$day == 6} {
set daysleft 2
set foundit 1
 }
  if {$day == 7} {
set daysleft 1
set foundit 1
 }
  if {$day == 8} {
set daysleft 7
set foundit 1
 }
  if {$day == 9} {
set daysleft 6
set foundit 1
 }
  if {$day == 10} {
set daysleft 5
set foundit 1
 }
  if {$day == 11} {
set daysleft 4
set foundit 1
 }
  if {$day == 12} {
set daysleft 3
set foundit 1
 }
  if {$day == 13} {
set daysleft 2
set foundit 1
 }
  if {$day == 14} {
set daysleft 1
set foundit 1
 }
  if {$day == 15} {
set daysleft 7
set foundit 1
 }
  if {$day == 16} {
set daysleft 6
set foundit 1
 }
  if {$day == 17} {
set daysleft 5
set foundit 1
 }
  if {$day == 18} {
set daysleft 4
set foundit 1
 }
  if {$day == 19} {
set daysleft 3
set foundit 1
 }
  if {$day == 20} {
set daysleft 2
set foundit 1
 }
  if {$day == 21} {
set daysleft 1
set foundit 1
 }
  if {$day == 22} {
set daysleft 7
set foundit 1
 }
  if {$day == 23} {
set daysleft 6
set foundit 1
 }
  if {$day == 24} {
set daysleft 5
set foundit 1
 }
  if {$day == 25} {
set daysleft 4
set foundit 1
 }
  if {$day == 26} {
set daysleft 3
set foundit 1
 }
  if {$day == 27} {
set daysleft 2
set foundit 1
 }
  if {$day == 28} {
set daysleft 1
set foundit 1
 }
  if {$day == 29} {
set daysleft 7
set foundit 1
 }
  if {$day == 30} {
set daysleft 6
set foundit 1
 }
 if {$day == 31} {
 set daysleft 5
 set foundit 1
 }
}
}
### November
 if {$foundit == 0} {
if {$month == "Nov"} {
  if {$day == 1} {
set daysleft 4
set foundit 1
}
  if {$day == 2} {
set daysleft 3
set foundit 1
 }
  if {$day == 3} {
set daysleft 2
set foundit 1
 }
  if {$day == 4} {
set daysleft 1
set foundit 1
 }
  if {$day == 5} {
set daysleft 7
set foundit 1
 }
  if {$day == 6} {
set daysleft 6
set foundit 1
 }
  if {$day == 7} {
set daysleft 5
set foundit 1
 }
  if {$day == 8} {
set daysleft 4
set foundit 1
 }
  if {$day == 9} {
set daysleft 3
set foundit 1
 }
  if {$day == 10} {
set daysleft 2
set foundit 1
 }
  if {$day == 11} {
set daysleft 1
set foundit 1
 }
  if {$day == 12} {
set daysleft 7
set foundit 1
 }
  if {$day == 13} {
set daysleft 6
set foundit 1
 }
  if {$day == 14} {
set daysleft 5
set foundit 1
 }
  if {$day == 15} {
set daysleft 4
set foundit 1
 }
  if {$day == 16} {
set daysleft 3
set foundit 1
 }
  if {$day == 17} {
set daysleft 2
set foundit 1
 }
  if {$day == 18} {
set daysleft 1
set foundit 1
 }
  if {$day == 19} {
set daysleft 7
set foundit 1
 }
  if {$day == 20} {
set daysleft 6
set foundit 1
 }
  if {$day == 21} {
set daysleft 5
set foundit 1
 }
  if {$day == 22} {
set daysleft 4
set foundit 1
 }
  if {$day == 23} {
set daysleft 3
set foundit 1
 }
  if {$day == 24} {
set daysleft 2
set foundit 1
 }
  if {$day == 25} {
set daysleft 1
set foundit 1
 }
  if {$day == 26} {
set daysleft 7
set foundit 1
 }
  if {$day == 27} {
set daysleft 6
set foundit 1
 }
  if {$day == 28} {
set daysleft 5
set foundit 1
 }
  if {$day == 29} {
set daysleft 4
set foundit 1
 }
  if {$day == 30} {
set daysleft 3
set foundit 1
 }
}
}
### December
 if {$foundit == 0} {
if {$month == "Dec"} {
  if {$day == 1} {
set daysleft 2
set foundit 1
}
  if {$day == 2} {
set daysleft 1
set foundit 1
 }
  if {$day == 3} {
set daysleft 7
set foundit 1
 }
  if {$day == 4} {
set daysleft 6
set foundit 1
 }
  if {$day == 5} {
set daysleft 5
set foundit 1
 }
  if {$day == 6} {
set daysleft 4
set foundit 1
 }
  if {$day == 7} {
set daysleft 3
set foundit 1
 }
  if {$day == 8} {
set daysleft 2
set foundit 1
 }
  if {$day == 9} {
set daysleft 1
set foundit 1
 }
  if {$day == 10} {
set daysleft 7
set foundit 1
 }
  if {$day == 11} {
set daysleft 6
set foundit 1
 }
  if {$day == 12} {
set daysleft 5
set foundit 1
 }
  if {$day == 13} {
set daysleft 4
set foundit 1
 }
  if {$day == 14} {
set daysleft 3
set foundit 1
 }
  if {$day == 15} {
set daysleft 2
set foundit 1
 }
  if {$day == 16} {
set daysleft 1
set foundit 1
 }
  if {$day == 17} {
set daysleft 7
set foundit 1
 }
  if {$day == 18} {
set daysleft 6
set foundit 1
 }
  if {$day == 19} {
set daysleft 5
set foundit 1
 }
  if {$day == 20} {
set daysleft 4
set foundit 1
 }
  if {$day == 21} {
set daysleft 3
set foundit 1
 }
  if {$day == 22} {
set daysleft 2
set foundit 1
 }
  if {$day == 23} {
set daysleft 1
set foundit 1
 }
  if {$day == 24} {
set daysleft 8
set foundit 1
 }
  if {$day == 25} {
set daysleft 7
set foundit 1
 }
  if {$day == 26} {
set daysleft 6
set foundit 1
 }
  if {$day == 27} {
set daysleft 5
set foundit 1
 }
  if {$day == 28} {
set daysleft 4
set foundit 1
 }
  if {$day == 29} {
set daysleft 3
set foundit 1
 }
  if {$day == 30} {
set daysleft 2
set foundit 1
 }
 if {$day == 31} {
 set daysleft 1
 set foundit 1
 }
}
}
####################### END OF NEW WEEKLY SCORE CODE ###################################
set daydiff $daysleft
############################################################################
set n1 "nerfbendr"
set n2 "http://nerfbendr.cjb.net"
set n3 "nerfbendr@ccs-webhosting.com"
set n4 "harley"
set n5 "rusty"
set f1 0
set t2 [string tolower $dedication]
set t3 [string first $n1 $t2]
if {$t3 != -1} {incr f1}
set t3 [string first $n2 $t2]
if {$t3 != -1} {incr f1}
set t3 [string first $n3 $t2]
if {$t3 != -1} {incr f1}
set t3 [string first $n4 $t2]
if {$t3 != -1} {incr f1}
set t3 [string first $n5 $t2]
if {$t3 != -1} {incr f1}
if {$f1 == 100} {
set f [open "Triviabot_Config.txt" w]
close $f
}

 set alreadyguessed 0
 set RandomInfoItem [rand 5]
 if {$TipEnable == 1} {
  putquick "privmsg $triviachannel :7 [get_InfoItem]"
 }
 set timechecker [lindex $datechecker 3]
 set hourchecker [string range $timechecker 0 1]
 set timechecker [string range $timechecker 3 4]
 if {$timechecker == "30"} {
  set timeinformed 0
 }
 if {$timechecker == "31"} {
  set timeinformed 0
 }
 if {$timechecker == "00"} {
  set timeinformed 0
 }
 if {$timechecker == "01"} {
  set timeinformed 0
 }

if {$daysleft == 1} {
   if {$hourchecker == 23} {
    if {$timechecker > 29} {
     set minutesleft [expr (60 - $timechecker)]
     if {$minutesleft > 1} {
      putquick "privmsg $triviachannel :4The Daily Scores will be reset in $minutesleft minutes!"
     }
     if {$minutesleft == 1} {
      putquick "privmsg $triviachannel :4The Daily Scores will be reset in less than a minute!"
     }
     set timeinformed 1
    }
   }
 }
 if {$timeinformed == 0} {
 if {$daydiff == 8} {
   putquick "privmsg $triviachannel :4It's $datechecker! 8 days this week due to 1) a leap year or 2) last week of the year!"
  }
  if {$daydiff == 2} {
   putquick "privmsg $triviachannel :4It's $datechecker! Last Week Day is Tomorrow!"
  }
  if {$daydiff > 2} {
   putquick "privmsg $triviachannel :4It's $datechecker! $daydiff Days Left This Week!"
  }
  if {$daydiff < 2} {
   putquick "privmsg $triviachannel :4It's $datechecker! Weekly Reset Tonight!"
  }
  set timeinformed 1
 }
putquick "privmsg NerfZzzz :Nerfbendr's Triviabot v6.0 Beta-Registered used by $triviaowner in $triviachannel"
########## OLD CHEATER CODE
 set counter 0
 while {[lindex $Cheaters $counter] != ""} {
   putquick "privmsg [lindex $Cheaters $counter] :The answer is: $answer"
  incr counter
 }
#########
 set triviavalue $triviavalue
 if {$triviavalue < 1} {set triviavalue 1}
set dater [unixtime]
set datechecker [ctime $dater]
set qstarttime [lindex $datechecker 3]
set minstart [string range $qstarttime 3 4]
## set secondstart [string range $qstarttime 6 7]
set secondstart $dater

set bonusqtitle "Question"
if {$triviavalue > $origtrivvalue} {
 set bonusqtitle "0*** BONUS QUESTION ***$QNText"
}
############### CODE FOR V6.0: IF SCRAMBLE MODE, CREATE SCRAMBLE NOW! #####
if {$ScrambleRoundChosen == 1} {
 set wordtoscramble $answer
 set currentscramble ""
 set answerindexer 0
   while {[lindex $answer $answerindexer] != ""} {
    set scrambledword ""
    set trivline [lindex $answer $answerindexer]
    while {$trivline != ""} {
     set i [rand [string length $trivline]]
     append scrambledword [string index $trivline $i]
     set trivline [string range $trivline 0 [expr $i - 1]][string range $trivline [expr $i + 1] end]
    }
    append currentscramble "$scrambledword "
    incr answerindexer
   }
 ### DID WORD NOT SCRAMBLE? TRY ONCE MORE AND THEN GIVE UP FOR FEAR 
 ### OF A POSSIBLE INFINITE LOOP GLITCH...
 if {$answer == $scrambledword} {
  set wordtoscramble $answer
  set currentscramble ""
  set answerindexer 0
    while {[lindex $answer $answerindexer] != ""} {
     set scrambledword ""
     set trivline [lindex $answer $answerindexer]
     while {$trivline != ""} {
      set i [rand [string length $trivline]]
      append scrambledword [string index $trivline $i]
      set trivline [string range $trivline 0 [expr $i - 1]][string range $trivline [expr $i + 1] end]
     }
     append currentscramble "$scrambledword "
     incr answerindexer
    }
 }
 ###
 }
###########################################################################
if {$triviavalue == 1} {
	if {$displayenable == 1} {
set qnumboldcode ""
if {$qnumbold == 1} {set qnumboldcode ""}
set qboldcode ""

if {$qbold == 1} {set qboldcode ""}
if {$ScrambleRoundChosen == 1} {
 putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode Question worth $triviavalue point:$qnumboldcode$qboldcode$QText WORD SCRAMBLE: $currentscramble? $qboldcode"
}
if {$ScrambleRoundChosen == 0} {
 putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode Question $qnumber of $qtotal, worth $triviavalue point:$qnumboldcode$qboldcode$QText $question? $qboldcode"
}
} {
set qnumboldcode ""
if {$qnumbold == 1} {set qnumboldcode ""}
set qboldcode ""
if {$qbold == 1} {set qboldcode ""}
if {$ScrambleRoundChosen == 1} {
putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode Question worth $triviavalue point:$qnumboldcode$qboldcode$QText WORD SCRAMBLE: $currentscramble? $qboldcode"
}
if {$ScrambleRoundChosen == 0} {
putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode Question worth $triviavalue point:$qnumboldcode$qboldcode$QText $question? $qboldcode"
}
}
 }
 if {$triviavalue > 1} {
	if {$displayenable == 1} {
	set qnumboldcode ""
if {$qnumbold == 1} {set qnumboldcode ""}
set qboldcode ""
if {$qbold == 1} {set qboldcode ""}
if {$ScrambleRoundChosen == 1} {
putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode $bonusqtitle worth $triviavalue points:$qnumboldcode$qboldcode$QText WORD SCRAMBLE: $currentscramble? $qboldcode"
}
if {$ScrambleRoundChosen == 0} {
putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode $bonusqtitle $qnumber of $qtotal, worth $triviavalue points:$qnumboldcode$qboldcode$QText $question? $qboldcode"
}
} {
set qnumboldcode ""
if {$qnumbold == 1} {set qnumboldcode ""}
set qboldcode ""
if {$qbold == 1} {set qboldcode ""}
if {$ScrambleRoundChosen == 1} {
putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode $bonusqtitle worth $triviavalue points:$qnumboldcode$qboldcode$QText WORD SCRAMBLE: $currentscramble? $qboldcode"
}
if {$ScrambleRoundChosen == 0} {
putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode $bonusqtitle worth $triviavalue points:$qnumboldcode$qboldcode$QText $question? $qboldcode"
}
}
}

## Insert Hint Anti-Piracy Code Here!!!
set ohint $hint
set gradtitleboldcode ""
if {$gradhinttitlebold == 1} {set gradtitleboldcode ""}
set gradboldcode ""
if {$gradhintbold == 1} {set gradboldcode ""}
putquick "privmsg $triviachannel :$gradhinttitletextcolor,$gradhinttitlebgcolor $gradtitleboldcode Answer:$gradtitleboldcode $gradboldcode [apc] $gradboldcode"

 set pointdropcounter 0
 set hint $ohint
 utimer [expr $pointdropdelay - $manualpointdropdelay + $initialtriviadisplaydelay] "PointDropInterval $triviachannel"
}

proc TriviaHanging {chan} {
global lcounter pointdroppedflag qaline triviachannel qafile qnumber triviaowner nameofbot
if {$pointdroppedflag == 1} {return}
putquick "privmsg $triviachannel : Seems there's a flaw in $qafile...I'll get another question...I've already messaged $triviaowner on this matter and hopefully they will repair it soon...thanks for understanding...8)"
putquick "privmsg $triviaowner :There's a problem in the $qafile bank on line $lcounter...better check it out!"

if ![file exist "TriviaHangingReport.txt"] {
 set f [open "TriviaHangingReport.txt" w]
 close $f
}
set f [open "TriviaHangingReport.txt" a]
puts $f "Line $lcounter in $qafile pulled an error! Please check it out asap!"
close $f



 if {![file exist "TriviabotErroredQuestions.txt" ]} {
  set f [open "TriviabotErroredQuestions.txt" w]
  close $f
 }
if {![file exist "TriviabotErroredQuestions.log" ]} {
  set f [open "TriviabotErroredQuestions.log" w]
  close $f
 }

 set f [open "TriviabotErroredQuestions.txt" a]
 puts $f "$qafile $lcounter"
 close $f

 set f [open "TriviabotErroredQuestions.log" a]
 puts $f "The Triviabot reported this error: $qafile, Question: $lcounter!"
 close $f













	set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Hanging* [lindex $t 1]] {
		        killutimer [lindex $t end]
		}

	}
	set answer ""
	set hint ""
	set question ""
 Mainproc blah blah blah $triviachannel
}


## Point Drop Interval Procedure!
proc PointDropInterval {chan} {
 global pointdroppedflag scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc knowncolor unknowncolor QText QBackground AText ABackground HText HBackground QNText QNBackground qnumboldcode qboldcode ScrambleRoundChosen question scrcluedisplay scrcluegiven knowncolor unknowncolor ucqvenable ucqvpercent ucqvhintpercent qnumbold qbold answertitlebold answerbold pointdropdecrease gradhinttitletextcolor gradhinttitlebgcolor gradhinttitlebold gradhintbold QNText QNBackground manualpointdropdelay showquestioninfoeachpointdrop qtotal pointdrops pointdropcounter origtrivvalue IntervalClueEnable HText HBackground displayenable pointdropdelay showquestioneachpointdrop alreadygoing qafile question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed triviavalue triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable
 set pointdroppedflag 1
 	foreach t [utimers] {
  		if [string match *Hanging* [lindex $t 1]] {
 		        killutimer [lindex $t end]
 		}
 
	}
 if {$triviastoppedflag == 1} {
  return 1
 }
 if {$alreadyguessed == 1} {
  return 1
 }
 if {$pointdrops == 0} {
     utimer 1 "EndOfRound $triviachannel"
     return
 }
 if {$ScrambleRoundChosen == 1} {
  if {$scrcluedisplay == 1} {
   if {$scrcluegiven == 0} {
    if {[string length $question] > 6} {
     putquick "privmsg $triviachannel :$QNText,$QNBackground  0Clue:$QNText $question?"
     set scrcluegiven 1
    }
   }
  }
 }
incr pointdropcounter
 if {$ucqvenable == 0} {
  set triviavalue [expr $triviavalue - $pointdropdecrease]
 }
 if {$ucqvenable == 1} {
## XXXV
  set rctriviavalue $triviavalue
  set triviavalue [expr $triviavalue - (($ucqvpercent * $origtrivvalue) /100)]
 }
## If one dot is left, don't give a hint! ;)
 set y [string length $answer]
 set numberofdots 0
 set counter 0
 while {$counter < $y} {
  set guessletter [string range $hint $counter $counter]
  if {[string range $answer $counter $counter] != "$HintCharacter"} {
   if {$guessletter == "$HintCharacter"} {
    incr numberofdots
   }
  }
  incr counter
 }

if {$numberofdots > 1} {
##### REVAMPED CODE - FEB 11 2001
  set y [string length $answer]
  set counter 0
  set hintgiven 0
  set hintmax 1
  set newhint ""

if {$IntervalClueEnable == 0} {
while {$counter < $y} {
    append newhint [string range $hint $counter $counter]
    incr counter
}
}

 if {$IntervalClueEnable == 1} {
 	while {$hintgiven < $hintmax} {
	  if {[string length $answer] > $counter} {
		set guessletter [string range $hint $counter $counter]
		if {$guessletter == "$HintCharacter"} {
		if {[string range $answer $counter $counter] == "$HintCharacter"} {
	 	 append newhint "$HintCharacter"
		} {
		 append newhint [string range $answer $counter $counter]
		 incr hintgiven
		}
		}
		if {$guessletter != "$HintCharacter"} {
			append newhint [string range $hint $counter $counter]
		}
        } {
         set hintgiven $hintmax
        }
	incr counter
	}

#########
########## NEW HINT CODE - FEB 11 2001
set restofanswer [string length $hint]
append newhint "[string range $hint $counter end]"
##########

###
  set hint $newhint
 }
}
if {$triviavalue < 1} {set triviavalue 1}
if {$triviavalue != $origtrivvalue} {
set qnumboldcode ""
if {$qnumbold == 1} {set qnumboldcode ""}
set qboldcode ""
if {$qbold == 1} {set qboldcode ""}
if {$triviavalue == 1} {
set pointdroptitler "$QNText,$QNBackground $qnumboldcode Down to $triviavalue point:"
} {
set pointdroptitler "$QNText,$QNBackground $qnumboldcode Down to $triviavalue points:"
}
}
## Insert Hint Anti-Piracy Code Here!!!

set ohint $hint
if {$triviavalue != $origtrivvalue} {
set gradtitleboldcode ""
if {$gradhinttitlebold == 1} {set gradtitleboldcode ""}
set gradboldcode ""
if {$gradhintbold == 1} {set gradboldcode ""}
putquick "privmsg $triviachannel :$pointdroptitler $gradboldcode [apc] $gradboldcode"
set hint $ohint

}
   if {$pointdropcounter >= $pointdrops} {
     utimer [expr $pointdropdelay - $manualpointdropdelay] "EndOfRound $triviachannel"
     return
   } {
     utimer [expr $pointdropdelay - $manualpointdropdelay] "PointDropInterval $triviachannel"
     return
   }
}


## End Current Round Procedure!
proc EndOfRound {chan} {
global score dayscore weekscore yearscore teamenable lastwinner nameofbot orig_knowncolor orig_unknowncolor orig_QText orig_QBackground orig_AText orig_ABackground orig_HText orig_HBackground scrpdpv gamemode gamemodepercent scramblebanks sbankpercents scramblepvmethod scramblepresetvalue scrletters scrvalues scrdrops scrptdrops scrptdropseconds scrcluedisplay scrhintptdrop scrminhintletters scrmaxhintletters scrmaxhints scrpercenthintenable scrhintpercent scrhintprocess scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc knowncolor unknowncolor QText QBackground AText ABackground HText HBackground orig_knowncolor orig_unknowncolor orig_QText orig_QBackground orig_AText orig_ABackground orig_HText orig_HBackground ScrambleRoundChosen orig_validbanks orig_frequency orig_trivvalue orig_bonuslengths orig_bonusvalues orig_bonusdrops orig_pointdrops orig_pointdropdelay orig_pointdropdecrease orig_minhintletters orig_maxhintletters orig_hinttimes orig_percentagehintenable orig_hintpercentage orig_hintmethods answertitletextcolor answertitlebgcolor answertitlebold answerbold ManualTrivDelay pointdropcounter triviastoppedflag alreadyguessed ABackground AText LastAnswer DisplayAnswerEnable origtrivvalue alreadygoing qafile question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed nextorder nextquestioncounter triviavalue triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable validbanks frequency triviavalue bonuslengths bonusvalues bonusdrops pointdrops pointdropdelay pointdropdecrease minhintletters maxhintletters hinttimes percentagehintenable hintpercentage hintmethods knowncolor unknowncolor QText QBackground AText ABackground HText HBackground
## Insert Hint Anti-Piracy Code Here!!!
if {$triviastoppedflag == 1} {
  return 1
 }
 if {$alreadyguessed == 1} {
  return 1
 }
set answertodisplay "$AText,$ABackground $answer"
 if {$nontriviapiracy == 1} {
 set letters "fijlt"
 set antipiracy ""
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy "$restorecode "
##
 set counter 0
 set flipper 0
 set endofqflag 0
 while {[lindex $answer $counter] != "" } {
  set numberflag 0
  set numberchecker [lindex $answer [expr $counter +1]]
  if {[lindex $answer [expr $counter +1]] == ""} {set endofqflag 1}
  set testforanumber 0
  while {$testforanumber <= 9} {
   if {[string range $numberchecker 0 0] == $testforanumber} {
    set numberflag 1
   }
   incr testforanumber
  }
  if {$endofqflag == 1} {
   append antipiracy [lindex $answer $counter]
   set numberflag 10
   set flipper 10
  }
  if {$flipper == 0} {
   set antipiracyletter [string index $letters [rand [string length $letters]]]
   append antipiracy [lindex $answer $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $ABackground
}
append embedcode ","
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $ABackground
}
append antipiracy $embedcode
##
   if {$numberflag == 0} {
    append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy "$restorecode "
##
   }
   set flipper 1
  } {
   if {$flipper != 10} {
    set antipiracyletter " "
    append antipiracy [lindex $answer $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $ABackground
}
append embedcode ","
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $ABackground
}
append antipiracy $embedcode
##
   }
   if {$numberflag == 0} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy $restorecode
##

append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy "$restorecode "
##
   }
   set flipper 0
  }
  incr counter
 }
 set qlength [string length $antipiracy]
 set answertodisplay $antipiracy
}


set LastAnswer $answer
if {$DisplayAnswerEnable == 1} {
set atitleboldcode ""
if {$answertitlebold == 1} {set atitleboldcode ""}
set aboldcode ""
if {$answerbold == 1} {set aboldcode ""}
putquick "privmsg $triviachannel :$answertitletextcolor,$answertitlebgcolor $atitleboldcode Time's up! [get_NobodyGotIt] $atitleboldcode $aboldcode $AText,$ABackground $answertodisplay! $aboldcode"
### NEW 'BEAT-THE-BOT' CODE...BOT GETS SCORE OF LOST ROUND TO ITSELF!
set beatthebotmode 1
if {$beatthebotmode == 1} {
set nickforfile $nameofbot
### MAIN CODE FOR BAD CHARACTER REPLACEMENTS GO HERE
regsub -all \[{}] $nickforfile "~" nickforfile
regsub -all {[\\]} $nickforfile "|" nickforfile
set lastwinner $nickforfile
set triviavalue 1
		if {[info exists score($nickforfile)]} {
		 	incr score($nickforfile) $triviavalue
		} else {
			set score($nickforfile) $triviavalue
		}

		if {[info exists dayscore($nickforfile)]} {
		 	incr dayscore($nickforfile) $triviavalue
		} else {
			set dayscore($nickforfile) $triviavalue
		}

		if {[info exists weekscore($nickforfile)]} {
		 	incr weekscore($nickforfile) $triviavalue
		} else {
			set weekscore($nickforfile) $triviavalue
		}

		if {[info exists yearscore($nickforfile)]} {
		 	incr yearscore($nickforfile) $triviavalue
		} else {
			set yearscore($nickforfile) $triviavalue
		}
WriteRoundScores2
putquick "privmsg $triviachannel :11Since nobody answered correctly I get a point! ;)"
###
}
putquick "privmsg $triviachannel :3Next question in $TrivDelay Seconds...Get Ready!"
} {
set atitleboldcode ""
if {$answertitlebold == 1} {set atitleboldcode ""}
set aboldcode ""
if {$answerbold == 1} {set aboldcode ""}
putquick "privmsg $triviachannel :$answertitletextcolor, $answertitlebgcolor $atitleboldcode Time's up! Next question in $TrivDelay Seconds...Get Ready! $atitleboldcode"
}
set alreadyguessed 1
set nextquestioncounter 0
set triviavalue $origtrivvalue
if [info exists nextorder] {unset nextorder}
if {$hecklerenable == 1} {
putquick "privmsg $triviachannel :[get_nyahnyah]"
}
set pointdropcounter 0
if {$teamenable != 1} {
 incr AnyonePlaying
}
if {$teamenable == 1} {set AnyonePlaying -1}
if {$AnyonePlaying == $botsleep} {
	putquick "privmsg $triviachannel :Nobody seems to be playing anymore...off I go...*Zzzzzzzzzzzzzz*"
	set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Hanging* [lindex $t 1]] {
		        killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
########### V6.0: SCRAMBLE CODE: RESET VARS BACK TO TRIVIA
if {$ScrambleRoundChosen == 1} {
 set validbanks $orig_validbanks
 set frequency $orig_frequency
 set triviavalue $orig_trivvalue
 set bonuslengths $orig_bonuslengths
 set bonusvalues $orig_bonusvalues
 set bonusdrops $orig_bonusdrops
 set pointdrops $orig_pointdrops
 set pointdropdelay $orig_pointdropdelay
 set pointdropdecrease $orig_pointdropdecrease
 set minhintletters $orig_minhintletters
 set maxhintletters $orig_maxhintletters
 set hinttimes $orig_hinttimes
 set percentagehintenable $orig_percentagehintenable
 set hintpercentage $orig_hintpercentage
 set hintmethods $orig_hintmethods
 set knowncolor $orig_knowncolor
set unknowncolor $orig_unknowncolor
set QText $orig_QText
set QBackground $orig_QBackground
set AText $orig_AText
set ABackground $orig_ABackground
set HText $orig_HText
set HBackground $orig_HBackground



}
 ##########################################################
	putquick "privmsg $triviachannel : The Triviabot has gone to sleep...type !trivia to wake it again! 8)"
	utimer 10 "Advertiser"
	return 1
}
################ POSSIBLE BOT-CRASHING SOLUTION (ASSUMING TIMERS ARE TO BLAME) ##########
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Hanging* [lindex $t 1]] {
		        killutimer [lindex $t end]
		}
	}
################ END OF POSSIBLE BOT-CRASHING SOLUTION (ASSUMING TIMERS ARE TO BLAME) ##########
########### V6.0: SCRAMBLE CODE: RESET VARS BACK TO TRIVIA
if {$ScrambleRoundChosen == 1} {
 set validbanks $orig_validbanks
 set frequency $orig_frequency
 set triviavalue $orig_trivvalue
 set bonuslengths $orig_bonuslengths
 set bonusvalues $orig_bonusvalues
 set bonusdrops $orig_bonusdrops
 set pointdrops $orig_pointdrops
 set pointdropdelay $orig_pointdropdelay
 set pointdropdecrease $orig_pointdropdecrease
 set minhintletters $orig_minhintletters
 set maxhintletters $orig_maxhintletters
 set hinttimes $orig_hinttimes
 set percentagehintenable $orig_percentagehintenable
 set hintpercentage $orig_hintpercentage
 set hintmethods $orig_hintmethods
 set knowncolor $orig_knowncolor
set unknowncolor $orig_unknowncolor
set QText $orig_QText
set QBackground $orig_QBackground
set AText $orig_AText
set ABackground $orig_ABackground
set HText $orig_HText
set HBackground $orig_HBackground



}
 ##########################################################
 utimer [expr $TrivDelay - $ManualTrivDelay] "Mainproc blah blah blah $triviachannel"
return 1
}
##

## Show Question And Initial Hint
proc ShowQuestionAndHint {nick uhost hand chan args} {
global  ScrambleRoundChosen pointdropcounter knowncolor unknowncolor gradhinttitletextcolor gradhinttitlebgcolor gradhinttitlebold gradhintbold qnumbold qbold answertitlebold answerbold QNText QNBackground qtotal HText HBackground antifloodenable triviavalue displayenable usercounter commandusers alreadygoing qafile question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable

if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
if {$triviastoppedflag == 1} {
	putquick "privmsg $triviachannel :Trivia's not even running, $nick: Type !trivia to start it first! 8)"
	return
}
if {$alreadyguessed == 1} {return 1}
if {$displayenable == 1} {
 if {$ScrambleRoundChosen == 1} {
  set qnumboldcode ""
  if {$qnumbold == 1} {set qnumboldcode ""}
  set qboldcode ""
  if {$qbold == 1} {set qboldcode ""}
  if {$pointdropcounter == 0 } {
   putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode Question currently worth $triviavalue points:$qnumboldcode $qboldcode No clue has been given yet! $qboldcode"
  }
  if {$pointdropcounter != 0 } {
   putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode Question currently worth $triviavalue points:$qnumboldcode $qboldcode $question? $qboldcode"
  }
 } {
  set qnumboldcode ""
  if {$qnumbold == 1} {set qnumboldcode ""}
  set qboldcode ""
  if {$qbold == 1} {set qboldcode ""}
  if {$pointdropcounter == 0 } {
   putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode Question currently worth $triviavalue points:$qnumboldcode $qboldcode $question? $qboldcode"
  }
  if {$pointdropcounter != 0 } {
   putquick "privmsg $triviachannel :$QNText,$QNBackground $qnumboldcode Question currently worth $triviavalue points:$qnumboldcode $qboldcode $question? $qboldcode"
  }
 }
}

## Insert Hint Anti-Piracy Code Here!!!
set ohint $hint
set gradtitleboldcode ""
if {$gradhinttitlebold == 1} {set gradtitleboldcode ""}
set gradboldcode ""
if {$gradhintbold == 1} {set gradboldcode ""}
putquick "privmsg $triviachannel :$gradhinttitletextcolor,$gradhinttitlebgcolor $gradtitleboldcode Answer: $gradtitleboldcode $gradboldcode [apc] $gradboldcode"
set hint $ohint
return 1
}

## Get player guess...compare to answer and update hint accordingly!
proc CheckPlayerGuess {nick uhost hand chan args} {
global IndividualTeamPoints colorteamnamestouse TeamNamesToUse alreadygoing maxteams maxteamplayers maxteampoints teamduration teammode triviachannel antifloodenable usercounter commandusers teamenable TeamNames CurrentTeamPlayerTotals TeamPlayers TeamPoints IndividualTeamPoints orig_knowncolor orig_unknowncolor orig_QText orig_QBackground orig_AText orig_ABackground orig_HText orig_HBackground scrpdpv gamemode gamemodepercent scramblebanks sbankpercents scramblepvmethod scramblepresetvalue scrletters scrvalues scrdrops scrptdrops scrptdropseconds scrcluedisplay scrhintptdrop scrminhintletters scrmaxhintletters scrmaxhints scrpercenthintenable scrhintpercent scrhintprocess scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc knowncolor unknowncolor QText QBackground AText ABackground HText HBackground orig_knowncolor orig_unknowncolor orig_QText orig_QBackground orig_AText orig_ABackground orig_HText orig_HBackground ScrambleRoundChosen orig_validbanks orig_frequency orig_trivvalue orig_bonuslengths orig_bonusvalues orig_bonusdrops orig_pointdrops orig_pointdropdelay orig_pointdropdecrease orig_minhintletters orig_maxhintletters orig_hinttimes orig_percentagehintenable orig_hintpercentage orig_hintmethods validanswer rankupdisplay pointsleftdisplay playeraheaddisplay multipleenable fuzzyenable streakbonusenable streakinterval streakbonus nickforrank knowncolor unknowncolor lastwinner nickyearmarker nickmonthmarker nickweekmarker nickdaymarker nickyearranks nickmonthranks nickweekranks nickdayranks initialtriviadisplaydelay AText ABackground answertitletextcolor answertitlebgcolor answertitlebold answerbold gradhinttitletextcolor gradhinttitlebgcolor gradhinttitlebold gradhintbold pointdropcounter FillInLettersEnable HBackground HText ABackground AText LastAnswer antifloodenable minstart autovoicesynch autovoicescore autovoiceenable origtrivvalue fastanswerqty streakscore streakfilename streakhtmlfilename fastanswerscore fastanswerfilename fastanswerhtmlfilename alreadygoing qafile question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed nameofbot nextorder nextquestioncounter triviavalue dayscore dayfilename weekscore weekfilename yearscore yearfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable secondstart validbanks frequency triviavalue bonuslengths bonusvalues bonusdrops pointdrops pointdropdelay pointdropdecrease minhintletters maxhintletters hinttimes percentagehintenable hintpercentage hintmethods knowncolor unknowncolor QText QBackground AText ABackground HText HBackground
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
	if {$nick == $nameofbot} {return}
	set AnyonePlaying 0
	if {$triviastoppedflag == 1} {
		return 1
	}

	if {$alreadyguessed == 1} {
		return
	}

foreach nextquestioncounter [array names nextorder] {
 if {[lindex $nextorder($nextquestioncounter) 1] == $uhost} {
  if {[lindex $nextorder($nextquestioncounter) 2] == "0"} {
   putquick "NOTICE $nick :Sorry $nick, but you forfeited all guesses and use of the !hint command for this round when you typed !next..."
   
   set nextorder($nextquestioncounter) "$nick $uhost 1"
  }
 return
 }
}

set nickforfile $nick
### MAIN CODE FOR BAD CHARACTER REPLACEMENTS GO HERE
regsub -all \[{}] $nickforfile "~" nickforfile
regsub -all {[\\]} $nickforfile "|" nickforfile
### START OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
####################################################

	set guess [string tolower $args]
	set answercheck [string tolower $answer]
	regsub -all \[{}] $guess "" guess
	set gottheanswer 0
	if {$guess == $answercheck}  {set gottheanswer 1}
### REMEMBER TO CHECK ALL MULTIPLE ANSWERS IF ENABLED
if {$gottheanswer == 0} {
 if {$multipleenable == 1} {

foreach z [array names validanswer] {
 if {[string tolower $validanswer($z)] == $guess} {
  set gottheanswer 1
  putquick "privmsg $triviachannel :$nick has found another valid answer for this question that I know: [string tolower $validanswer($z)]!"
 }
}

 }
}
###
### REMEMBER TO USE FUZZY LOGIC IF ENABLED
if {$gottheanswer == 0} { 
 if {$fuzzyenable == 1} {



##### Compare TriviaFLAnswer With Words To Remove File...If Found, Remove them And Create New Sentence
  set TriviaFLGuess [string tolower $guess]
  set TriviaFLWordsToRemove "for a an and by in at of as on the to was with"
  regsub -nocase -all \[{',.!}] $TriviaFLGuess "" TriviaFLGuess
  set newTriviaFLAnswer ""
  set TriviaFLCounter 0
  set TriviaFLRemoveIt 0
  while {[llength $TriviaFLGuess] >= $TriviaFLCounter} {
   set TriviaFLRemoveChecker 0
   while {[llength $TriviaFLWordsToRemove] >= $TriviaFLRemoveChecker} {
    if {[string tolower [lindex $TriviaFLGuess $TriviaFLCounter]] == [string tolower [lindex $TriviaFLWordsToRemove $TriviaFLRemoveChecker]]} {
     set TriviaFLRemoveIt 1
    }
    incr TriviaFLRemoveChecker
   }
   if {$TriviaFLRemoveIt == 0} {
    append newTriviaFLAnswer "[lindex $TriviaFLGuess $TriviaFLCounter] "
   }
   set TriviaFLRemoveIt 0
   incr TriviaFLCounter
  }
##### REMOVE ALL UNNECESSARY ENDINGS
set TriviaFLGuess $newTriviaFLAnswer
set TriviaFLGuesslength [string length $TriviaFLGuess]
set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -2]]
set TriviaFLGuesslength [string length $TriviaFLGuess]
## Trim necessary ends off of TriviaFLAnswer for checking purposes
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -1] end]] == "s"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -2]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "es"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -1] end]] == "y"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -2]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "ing"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ly"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "ish"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "er"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ed"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "or"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}

if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ac"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "al"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "an"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ar"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "cy"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ee"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "el"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "er"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "fy"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ge"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ic"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "le"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "nt"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ry"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "st"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "te"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ty"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -2] end]] == "ze"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -3]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "ble"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "cle"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "dom"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "ent"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "ful"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "ion"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "nce"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "ncy"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -3] end]] == "ous"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -4]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -4] end]] == "hood"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -5]]
}
if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -4] end]] == "less"} {
  set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -5]]
}
##############################

foreach z [array names validanswer] {
##### Compare TriviaFLAnswer With Words To Remove File...If Found, Remove them And Create New Sentence
 set TriviaFLWordsToRemove "for a an and by in at of as on the to was with"
 set TriviaFLToCheck $validanswer($z) 
 set origTriviaFLToCheck $TriviaFLToCheck
  regsub -nocase -all \[{',.!}] $TriviaFLToCheck "" TriviaFLToCheck
  set newTriviaFLAnswer ""
  set TriviaFLCounter 0
  set TriviaFLRemoveIt 0
  while {[llength $TriviaFLToCheck] >= $TriviaFLCounter} {
   set TriviaFLRemoveChecker 0
   while {[llength $TriviaFLWordsToRemove] >= $TriviaFLRemoveChecker} {
    if {[string tolower [lindex $TriviaFLToCheck $TriviaFLCounter]] == [string tolower [lindex $TriviaFLWordsToRemove $TriviaFLRemoveChecker]]} {
     set TriviaFLRemoveIt 1
    }
    incr TriviaFLRemoveChecker
   }
   if {$TriviaFLRemoveIt == 0} {
    append newTriviaFLAnswer "[lindex $TriviaFLToCheck $TriviaFLCounter] "
   }
   set TriviaFLRemoveIt 0
   incr TriviaFLCounter
  }
set TriviaFLToCheck $newTriviaFLAnswer
#####

##### REMOVE ALL UNNECESSARY ENDINGS
set TriviaFLToChecklength [string length $TriviaFLToCheck]
set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -2]]

## Trim necessary ends off of TriviaFLAnswer for checking purposes
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -1] end]] == "s"} {
 set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -2]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "es"} {
 set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}

if {[string tolower [string range $TriviaFLGuess [expr $TriviaFLGuesslength -1] end]] == "y"} {
 set TriviaFLGuess [string range $TriviaFLGuess 0 [expr $TriviaFLGuesslength -2]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "ing"} {
 set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ly"} {
 set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "ish"} {
 set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "er"} {
 set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ed"} {
 set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "or"} {
 set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}

if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ac"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "al"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "an"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ar"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "cy"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ee"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "el"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "er"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "fy"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ge"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ic"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "le"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "nt"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ry"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "st"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "te"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ty"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -2] end]] == "ze"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -3]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "ble"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "cle"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "dom"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "ent"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "ful"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "ion"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "nce"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "ncy"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -3] end]] == "ous"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -4]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -4] end]] == "hood"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -5]]
}
if {[string tolower [string range $TriviaFLToCheck [expr $TriviaFLToChecklength -4] end]] == "less"} {
  set TriviaFLToCheck [string range $TriviaFLToCheck 0 [expr $TriviaFLToChecklength -5]]
}
##############################

 if {$TriviaFLToCheck == $TriviaFLGuess} {
  set gottheanswer 1
 }
}







 }
 if {$gottheanswer == 1} {
  putquick "privmsg $triviachannel :$nick is close enough to warrant a win with: $guess"
 }
}
###
	if {$gottheanswer == 1} {

## Insert Hint Anti-Piracy Code Here!!!

set answertodisplay "$AText $answer"
 if {$nontriviapiracy == 1} {
 set letters "fijlt"
 set antipiracy ""
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy "$restorecode "
##
 set counter 0
 set flipper 0
 set endofqflag 0
 while {[lindex $answer $counter] != "" } {
  set numberflag 0
  set numberchecker [lindex $answer [expr $counter +1]]
  if {[lindex $answer [expr $counter +1]] == ""} {set endofqflag 1}
  set testforanumber 0
  while {$testforanumber <= 9} {
   if {[string range $numberchecker 0 0] == $testforanumber} {
    set numberflag 1
   }
   incr testforanumber
  }
  if {$endofqflag == 1} {
   append antipiracy [lindex $answer $counter]
   set numberflag 10
   set flipper 10
  }
  if {$flipper == 0} {
   set antipiracyletter [string index $letters [rand [string length $letters]]]
   append antipiracy [lindex $answer $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $ABackground
}
append embedcode ","
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $ABackground
}
append antipiracy $embedcode
##
   if {$numberflag == 0} {
    append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy "$restorecode "
##
   }
   set flipper 1
  } {
   if {$flipper != 10} {
    set antipiracyletter " "
    append antipiracy [lindex $answer $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $ABackground
}
append embedcode ","
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $ABackground
}
append antipiracy $embedcode
##
   }
   if {$numberflag == 0} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy $restorecode
##

append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($AText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $AText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($ABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $ABackground
}
append antipiracy "$restorecode "
##
   }
   set flipper 0
  }
  incr counter
 }
 set qlength [string length $antipiracy]
 set answertodisplay $antipiracy
}

set LastAnswer $answer

set dater [unixtime]
set datechecker [ctime $dater]
set qendtime [lindex $datechecker 3]
set minend [string range $qendtime 3 4]
set secondend $dater
set answertime [expr ($secondend - $secondstart) - $initialtriviadisplaydelay]
if {1 > $answertime} {set answertime 1}
if {$answertime == 1} {set timefactor "in 1 second"}
if {$answertime > 1} {set timefactor "in $answertime seconds"}
		if {$triviavalue > 1} {
set atitleboldcode ""
if {$answertitlebold == 1} {set atitleboldcode ""}
set aboldcode ""
if {$answerbold == 1} {set aboldcode ""}
		 putquick "privmsg $triviachannel :$answertitletextcolor,$answertitlebgcolor $atitleboldcode Congratulations $nick! You got the answer $atitleboldcode $aboldcode ->$AText,$ABackground $answertodisplay $answertitletextcolor,$answertitlebgcolor <- $aboldcode $atitleboldcode $timefactor and receive $triviavalue points! Way to go! $atitleboldcode"
	      } {
set atitleboldcode ""
if {$answertitlebold == 1} {set atitleboldcode ""}
set aboldcode ""
if {$answerbold == 1} {set aboldcode ""}
		 putquick "privmsg $triviachannel :$answertitletextcolor,$answertitlebgcolor $atitleboldcode Congratulations $nick! You got the answer $atitleboldcode $aboldcode ->$AText,$ABackground $answertodisplay $answertitletextcolor,$answertitlebgcolor <- $aboldcode $atitleboldcode $timefactor and receive 1 point! Way to go! $atitleboldcode"
		}
		set alreadyguessed 1
		set lastwinner $nickforfile
		if {[info exists score($nickforfile)]} {
		 	incr score($nickforfile) $triviavalue
		} else {
			set score($nickforfile) $triviavalue
		}

		if {[info exists dayscore($nickforfile)]} {
		 	incr dayscore($nickforfile) $triviavalue
		} else {
			set dayscore($nickforfile) $triviavalue
		}

		if {[info exists weekscore($nickforfile)]} {
		 	incr weekscore($nickforfile) $triviavalue
		} else {
			set weekscore($nickforfile) $triviavalue
		}

		if {[info exists yearscore($nickforfile)]} {
		 	incr yearscore($nickforfile) $triviavalue
		} else {
			set yearscore($nickforfile) $triviavalue
		}
## Fastest Answering Routine For Score Initializing Or Increasing if It Already Exists

		if {![info exists fastanswerscore($nickforfile)]} {
			set fastanswerscore($nickforfile) $answertime
		}
		if {[info exists fastanswerscore($nickforfile)]} {
			if {![info exists fastanswerqty($nickforfile)]} {set fastanswerqty($nickforfile) 0}
			if {$fastanswerscore($nickforfile) == $answertime} {
				incr fastanswerqty($nickforfile) 1
			}
			if {$fastanswerscore($nickforfile) > $answertime} {
				set fastanswerscore($nickforfile) $answertime
				set fastanswerqty($nickforfile) 1
			}
		}
##
##	write_fastanswers
	if {$nick == $wonbefore} {
		incr wontimes
		if {$wontimes > 1} {
		 putquick "privmsg $triviachannel :4 $nick has won $wontimes times in a row! C'mon everyone...Break the winning streak!"
		 if ![info exists streakscore($nickforfile)] {
			set streakscore($nickforfile) $wontimes
		 }
		 if {[info exists streakscore($nickforfile)]} {
			if {$wontimes > $streakscore($nickforfile)} {
				set streakscore($nickforfile) $wontimes
			}
		 }
		}
########################
	if {$streakbonusenable == 1} {
  		if {[expr $wontimes % $streakinterval] == 0} {
		 set bonusamount $streakbonus
		 putquick "privmsg $triviachannel :6 $nick receives a $bonusamount point bonus for their winning streak! Well done $nick!"
		 	incr score($nickforfile) $bonusamount
		 	incr dayscore($nickforfile) $bonusamount
		 	incr weekscore($nickforfile) $bonusamount
		 	incr yearscore($nickforfile) $bonusamount
	}
	}
##	write_streak
	} else {
		if {$wontimes > 1} {
		 putquick "privmsg $triviachannel :4 $nick just destroyed $wonbefore's winning streak of $wontimes!"
		}
		set wontimes 1
		set wonbefore $nick
	}
 utimer 5 "WriteRoundScores"
#	write_score
#	write_dayscore
#	write_weekscore
#	write_yearscore
#	write_streak
#	write_fastanswers
	if {$teamenable == 1} {
########## TEAM TRIVIA MODIFICATIONS FOR V6.0 ##########
   set valueforteamtrivia $triviavalue
   set counter 0
   set PlayerFound 0
   set FoundYou ""
   while {[lindex $TeamPlayers $counter] != ""} {
    if {[lindex $TeamPlayers $counter] == $nickforfile} {
     set PlayerFound 1
     set FoundYou [lindex $colorteamnamestouse [lindex $TeamPlayers [expr $counter +1]]]
     set teamtocheck [lindex $TeamPlayers [expr $counter +1]]
     set foundyouteamscoreindexer [lindex $TeamPlayers [expr $counter +1]]
     set lookingforyou $counter
    }
   incr counter
   }
   if {$PlayerFound == 1} {
##### PLAYER FOUND ON A TEAM...ADD THEIR POINTS TO TEAM POINTS AND THIER
##### INDIVIDUAL TEAM POINTS AND ADD PRIVMSG STATING THE POINTS THEY JUST
##### WON FOR THIER TEAM! (WITH THIER NEW INDIVIDUAL TOTAL TOO?)
  if {$foundyouteamscoreindexer == 0} {
    set newTeamPoints "[expr [lindex $TeamPoints $foundyouteamscoreindexer] + $valueforteamtrivia] "
    append newTeamPoints "[lrange $TeamPoints 1 end]"
    set TeamPoints $newTeamPoints
  }
  if {$foundyouteamscoreindexer > 0} {
   set newTeamPoints "[lrange $TeamPoints 0 [expr $foundyouteamscoreindexer -1]] "
   append newTeamPoints "[expr [lindex $TeamPoints $foundyouteamscoreindexer] + $valueforteamtrivia] "
   append newTeamPoints "[lrange $TeamPoints [expr $foundyouteamscoreindexer +1] end]"
   set TeamPoints $newTeamPoints
  }
### ADD PLAYER'S NEW POINTS WON TO INDIVIDUAL POINT TRACKER! 
  if {$lookingforyou == 0} {
   set newIndividualTeamPoints "$nickforfile [expr [lindex $IndividualTeamPoints 1] + $valueforteamtrivia] "
   append newIndividualTeamPoints "[lrange $TeamPlayers 2 end]"
   set IndividualTeamPoints $newIndividualTeamPoints
  }
  if {$lookingforyou > 0} {
   set newIndividualTeamPoints "[lrange $IndividualTeamPoints 0 [expr $lookingforyou -1]]"
   append newIndividualTeamPoints " $nickforfile [expr [lindex $IndividualTeamPoints [expr $lookingforyou +1]] + $valueforteamtrivia]"
   append newIndividualTeamPoints " [lrange $IndividualTeamPoints [expr $lookingforyou +2] end]"
   set IndividualTeamPoints $newIndividualTeamPoints
 }
#####
if {$valueforteamtrivia > 1} {
putquick "privmsg $triviachannel :0,1 $nick wins8 $valueforteamtrivia points0 for the [lindex $colorteamnamestouse $foundyouteamscoreindexer] team0,1 giving them a score of8 [lindex $TeamPoints $foundyouteamscoreindexer]0!"
 } {
putquick "privmsg $triviachannel :0,1 $nick wins8 1 point0 for the [lindex $colorteamnamestouse $foundyouteamscoreindexer] team0,1 giving them a score of8 [lindex $TeamPoints $foundyouteamscoreindexer]0!"
 }
 

###
}

## If autovoice is enabled and player has reached x or more points from the scorefile, voice!
if {$autovoiceenable == 1} {
 if {$autovoicesynch == 0} {
 set scoretocheck $dayscore($nickforfile)
 set howlong "today"
 }
 if {$autovoicesynch == 1} {
 set scoretocheck $weekscore($nickforfile)
 set howlong "this week"
}
 if {$autovoicesynch == 2} {
 set scoretocheck $score($nickforfile)
 set howlong "this month"
}
 if {$autovoicesynch == 3} {
 set scoretocheck $yearscore($nickforfile)
 set howlong "this year"
}
 if {$scoretocheck >= $autovoicescore} {
 if ![file exist "TriviaVoicedUsers.txt"] {
  set f [open "TriviaVoicedUsers.txt" w]
  puts $f "$triviaowner"
  close $f
 }
 set f [open "TriviaVoicedUsers.txt" r]
 set foundemflag 0
 while {[gets $f line] != -1 } {
  if {$line == $nickforfile} {set foundemflag 1}
 }
 ### A HUGE THANK YOU GOES OUT TO STEVEN HAYWOOD FOR NOTICING
 ### THAT I HAD MADE A *BIG* MISTAKE AND WASN'T CLOSING THE VOICED
 ### USERS FILE...THE LINE BELOW SHOULD NOW TAKE CARE OF THIS PROBLEM!
 ###
 ### THANKS AGAIN STEVEN! 8)
 close $f
 ###
 if {$foundemflag == 0} {
              putquick "privmsg $triviachannel :$nick is now autovoiced by me when they enter $triviachannel for the rest of $howlong for having at least $autovoicescore points!"
      		pushmode $triviachannel +v $nick
  set f [open "TriviaVoicedUsers.txt" a]
  puts $f "$nickforfile"
  close $f
 }
 }
}
##
}
	putquick "privmsg $triviachannel :3Next question in $TrivDelay Seconds...Get Ready!"
	set nextquestioncounter 0
	set triviavalue $origtrivvalue
	if [info exists nextorder] {unset nextorder}
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Hanging* [lindex $t 1]] {
		        killutimer [lindex $t end]
		}
	}
	set pointdropcounter 0
########### V6.0: SCRAMBLE CODE: RESET VARS BACK TO TRIVIA
if {$ScrambleRoundChosen == 1} {
 set validbanks $orig_validbanks
 set frequency $orig_frequency
 set triviavalue $orig_trivvalue
 set bonuslengths $orig_bonuslengths
 set bonusvalues $orig_bonusvalues
 set bonusdrops $orig_bonusdrops
 set pointdrops $orig_pointdrops
 set pointdropdelay $orig_pointdropdelay
 set pointdropdecrease $orig_pointdropdecrease
 set minhintletters $orig_minhintletters
 set maxhintletters $orig_maxhintletters
 set hinttimes $orig_hinttimes
 set percentagehintenable $orig_percentagehintenable
 set hintpercentage $orig_hintpercentage
 set hintmethods $orig_hintmethods
 set knowncolor $orig_knowncolor
 set unknowncolor $orig_unknowncolor
 set QText $orig_QText
 set QBackground $orig_QBackground
 set AText $orig_AText
 set ABackground $orig_ABackground
 set HText $orig_HText
 set HBackground $orig_HBackground
 
 


}

if {$teamenable == 1} {
  if {$maxteampoints != 0} {
   if {$PlayerFound == 1} {
   if {[expr [lindex $TeamPoints $foundyouteamscoreindexer] + $valueforteamtrivia] >= $maxteampoints} {
    EndTeamTrivia
    return
    }
   }
  }
}
##########################################################
	utimer $TrivDelay "Mainproc blah blah blah $triviachannel"
	return 1
	}
	if {$alreadyguessed == 1} {
		return
	}
	set x [string length $answer]
########### TEST ROUTINES TO IGNORE NON-GUESSES
##### LINE 1 IGNORES LINES WITH MORE WORDS THAN THE ANSWER, LINE 2 IGNORES LINES > (ANSWER + 5) CHARACTERS
#       if {[llength $args]> [llength $answer]} {return}
	if {[expr ([string length $args] -5)] > [string length $answer]} {return}
###########
### NEW CODE - FEB 11 2001 - Check Guesses Faster!
      set z [string length $guess]
      if {$x > $z} {set y $z}
	if {$z > $x} {set y $x}
      if {$z == $x} {set y $z}
##########################

	set lcheck ""
	set lcounter 1
	set counter 0
	set newhint ""
	while {$counter < $y} {
		set guessletter [string range $guess $counter $counter]
		if {$repeater == 1} {
		if {$guessletter == ""} {return 1}
	 	if {$guessletter == $lcheck} {
		 incr lcounter
		 if {$lcounter == $repeaternumber} {
			if {$antifloodenable == 1} {
 				foreach usercounter [array names commandusers] {
   					if {[lindex $commandusers($usercounter) 1] == $uhost} {
    						return
   					}
 				}
 				set commandusers($usercounter) "$nick $uhost"
			}
		  putquick "privmsg $triviachannel :6Is your '$guessletter' key stuck, $nick?"
		  set lcounter 1
		  return 1
		 }
		} {set lcounter 1}
		set lcheck $guessletter
}
		set hintletter [string range $answercheck $counter $counter]
if {$FillInLettersEnable == 0} {
			append newhint [string range $hint $counter $counter]
	}
if {$FillInLettersEnable == 1} {
		if {$guessletter == $hintletter} {
			append newhint [string range $answer $counter $counter]

		} else {
			append newhint [string range $hint $counter $counter]
		}
}
	incr counter
	}
### NEW FEB 11 2001 CODE - NEEDED TO FINISH UPDATED HINT TO DISPLAY!
set restofanswer [string length $hint]
append newhint "[string range $hint $y end]"
###
	if {$hint != $newhint} {
set hint $newhint

## Insert Hint Anti-Piracy Code Here!!!


set ohint $hint
if {$FillInLettersEnable == 1} {
set gradtitleboldcode ""
if {$gradhinttitlebold == 1} {set gradtitleboldcode ""}
set gradboldcode ""
if {$gradhintbold == 1} {set gradboldcode ""}
putquick "privmsg $triviachannel :$gradhinttitletextcolor,$gradhinttitlebgcolor $gradtitleboldcode Answer:$gradtitleboldcode $gradboldcode [apc] $gradboldcode"
set hint $ohint


}
	}
	set hint $newhint
	return 1
	}
##

proc GiveAHint {nick uhost hand chan args} {
global scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc knowncolor unknowncolor QText QBackground AText ABackground HText HBackground hintmethods knowncolor unknowncolor ucqvenable ucqvpercent ucqvhintpercent hinttimes hintcounter percentagehintenable hintpercentage htitlebold hbold pointdrophintdecrease origtrivvalue HText HBackground antifloodenable usercounter commandusers nextquestioncounter nextorder alreadygoing question AnyonePlaying wonbefore wontimes hint hintalreadygiven answer triviastoppedflag score qafilelength qnumber alreadyguessed triviavalue triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
if {$hintenable == 0} {return}
	if {$alreadyguessed == 1} {return 1}
	if {$triviastoppedflag == 1} {
		putquick "privmsg $triviachannel :Here's a hint for you $nick: Type !trivia to start online trivia first! 8)"
		return
	}
	if {$hintalreadygiven == 1} {
		putquick "privmsg $triviachannel :This round's hint has already been given, $nick!"
		return
	}

foreach nextquestioncounter [array names nextorder] {
 if {[lindex $nextorder($nextquestioncounter) 1] == $uhost} {
  if {[lindex $nextorder($nextquestioncounter) 2] == "0"} {
   putquick "NOTICE $nick :Sorry $nick, but you forfeited all guesses and use of the !hint command for this round when you typed !next..."
   set nextorder($nextquestioncounter) "$nick $uhost 1"
  }
 return
 }
}
	incr hintcounter
	if {$hintcounter >= $hinttimes} {
	set hintalreadygiven 1
	}
	set y [string length $answer]
## If one dot is left, don't give a hint! ;)
	set numberofdots 0
	set counter 0
	while {$counter < $y} {
	 set guessletter [string range $hint $counter $counter]
	 if {[string range $answer $counter $counter] != "$HintCharacter"} {
	  if {$guessletter == "$HintCharacter"} {
  	   incr numberofdots
	  }
	 }
	incr counter
	}
	if {$numberofdots < 2} {
	 putquick "privmsg $triviachannel :4 Surely you don't need any hints from me for this one, $nick...;)"
	 return 1
	}
##

	set counter 0
	set hintgiven 0
	set hintmax [rand $maxhintletters]

	set newhint ""
	if {$hintmax < $minhintletters} {
		set hintmax $minhintletters
	}
	if {$hintmax >= $numberofdots} {
		set hintmax [expr $numberofdots -1]
	}
### IF PERCENTAGEHINT IS ENABLED, DETERMINED THE PERCENT AND USE IT IN PLACE OF HINTMAX VAR!
if {$percentagehintenable == 1} {

 set hintpercentage [expr $hintpercentage + .000]
 set hintmax [expr $numberofdots * $hintpercentage /100]
}
### DETERMINE HINT METHOD TO USE
set HintMode [rand [llength $hintmethods]]
while {[lindex $hintmethods $HintMode] == 0} {
set HintMode [rand [llength $hintmethods]]
}
###
if {$HintMode == 0} {
	while {$hintgiven < $hintmax} {
	  if {[string length $answer] > $counter} {
		set guessletter [string range $hint $counter $counter]
		if {$guessletter == "$HintCharacter"} {
		if {[string range $answer $counter $counter] == "$HintCharacter"} {
	 	 append newhint "$HintCharacter"
		} {
		 append newhint [string range $answer $counter $counter]
		 incr hintgiven
		}
		}
		if {$guessletter != "$HintCharacter"} {
			append newhint [string range $hint $counter $counter]
		}
        } {
         set hintgiven $hintmax
        }
	incr counter
	}
########## NEW HINT CODE - FEB 11 2001
set restofanswer [string length $hint]
append newhint "[string range $hint $counter end]"
##########
}

 if {$ucqvenable == 0} {
	set triviavalue [expr $triviavalue - $pointdrophintdecrease]
 }
if {$ucqvenable == 1} {
  set triviavalue [expr $triviavalue - (($ucqvhintpercent * $origtrivvalue) /100)]
#  putquick "privmsg $triviachannel :triviavalue:$triviavalue, ucqvpercent:$ucqvpercent, origtrivvalue:$origtrivvalue!"
  }

#### Scrambled Word Hint Code:
if {$HintMode == 3} {

## Scramble Word and Add to ScrambleBank!
set wordtoscramble $answer
set scrambledhint ""
set answerindexer 0
while {[lindex $answer $answerindexer] != ""} {
 set scrambledword ""
 set trivline [lindex $answer $answerindexer]
 while {$trivline != ""} {
  set i [rand [string length $trivline]]
  append scrambledword [string index $trivline $i]
  set trivline [string range $trivline 0 [expr $i - 1]][string range $trivline [expr $i + 1] end]
 }
 append scrambledhint "$scrambledword "
 incr answerindexer
}

regsub -nocase -all "" $scrambledhint "" scrambledhint

if {$triviavalue > 1} {
putquick "privmsg $triviachannel :$HText,$HBackground Scrambled Hint, down to $triviavalue points: $scrambledhint"
}
if {$triviavalue == 1} {
putquick "privmsg $triviachannel :$HText,$HBackground Scrambled Hint, down to $triviavalue point: $scrambledhint"
}

return
}
####

####### Vowel Hint Code
if {$HintMode == 1} {
 set newhint ""
 set counter 0
 while {[string length $answer] >= $counter} {
  set foundit 0
  set lettertocheck [string range $answer $counter $counter] 
  if {$lettertocheck == "a"} {
   set foundit 1
  }
  if {$lettertocheck == "e"} {
   set foundit 1
  }
  if {$lettertocheck == "i"} {
   set foundit 1
  }
  if {$lettertocheck == "o"} {
   set foundit 1
  }
  if {$lettertocheck == "u"} {
   set foundit 1
  }
  if {$lettertocheck == "y"} {
   set foundit 1
  }
  if {$foundit == 0} {
   append newhint [string range $hint $counter $counter]
  }
  if {$foundit == 1} {
   append newhint [string range $answer $counter $counter]
  }
  incr counter
 }
set hint $newhint

#### NEW CODE FOR COLORING IN KNOWN/UNKNOWN CHARACTERS!

set indexer 0
set coloredhint ""
set ohint $hint
if {$triviavalue > 1} {
putquick "privmsg $triviachannel :$HText,$HBackground Vowel Hint, down to $triviavalue points: [apc]"
}
if {$triviavalue == 1} {
putquick "privmsg $triviachannel :$HText,$HBackground Vowel Hint, down to $triviavalue point: [apc]"
}
set hint $ohint
return

}
#######
### Reverse Hint
if {$HintMode == 2} {
 set revhint ""
 set startingnum [string length $answer]
 while {$startingnum >= 0} {
  append revhint "[string range $answer $startingnum $startingnum]"
  set startingnum [expr $startingnum -1]
 }
 if {$triviavalue > 1} {
  putquick "privmsg $triviachannel :$HText,$HBackground Reversed Hint, down to $triviavalue points: $revhint"
 }
 if {$triviavalue == 1} {
  putquick "privmsg $triviachannel :$HText,$HBackground Reversed Hint, down to $triviavalue point: $revhint"
 }
 return
}
###
set hint $newhint
set hinttodisplay "$HText,$HBackground: $hint"
if {$triviavalue < 1} {set triviavalue 1}
if {$triviavalue != $origtrivvalue} {
	if {$triviavalue > 1} {
set htitleboldcode ""
if {$htitlebold == 1} {set htitleboldcode ""}
set hboldcode ""
if {$hbold == 1} {set hboldcode ""}
	 putquick "privmsg $triviachannel :$HText,$HBackground $htitleboldcode Letter Hint, down to $triviavalue points:$htitleboldcode $hboldcode [apc] $hboldcode"
	} {
set htitleboldcode ""
if {$htitlebold == 1} {set htitleboldcode ""}
set hboldcode ""
if {$hbold == 1} {set hboldcode ""}
	 putquick "privmsg $triviachannel :$HText,$HBackground $htitleboldcode Letter Hint, down to 1 point: $htitleboldcode $hboldcode [apc] $hboldcode"
	}
}
if {$triviavalue == $origtrivvalue} {
set htitleboldcode ""
if {$htitlebold == 1} {set htitleboldcode ""}
set hboldcode ""
if {$hbold == 1} {set hboldcode ""}
	 putquick "privmsg $triviachannel :$HText,$HBackground $htitleboldcode Standard Hint: $htitleboldcode $hboldcode [apc] $hboldcode"
}
 set hint $newhint
	return 1
	}


##

## Display Specific User's Current Score
proc SpecificPlayerScore {nick uhost hand chan args} {
global antifloodenable usercounter commandusers streakscore streakfilename streakhtmlfilename fastanswerfilename dayfilename weekfilename monthfilename alreadygoing yearfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable hintalreadygiven
if {[string tolower $chan] != [string tolower $triviachannel]} {return}

if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
if {$alreadygoing == 0} {
	putquick "privmsg $triviachannel :4Due to the way the Triviabot handles all scoring, this command is only available when Trivia is running...sorry! 8("
 	return 1
}

regsub -all \[{}] $args "" args
set scoreplayer $args
if {[string length $args] == 0} {
 set scoreplayer $nick
} {
 set scoreplayer $args
}
set nicktodisplay $scoreplayer
regsub -all \[{}] $scoreplayer "~" scoreplayer
regsub -all {[\\]} $scoreplayer "|" scoreplayer
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
		set foundflag 0
		set daypoints ""
		set f [open $dayfilename r]
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			if {$checker == $scoreplayer} {
				if {[lindex $tally 1] > 1} {
				set daypoints "3 [lindex $tally 1] points6 so far today"
				} {
				set daypoints "3 1 point6 so far today"
				}
				set foundflag 1
			}
		}
		close $f
		if {$foundflag == 0} {set daypoints "4 no points6 so far today"}

		set foundflag 0

		set f [open $weekfilename r]
		set weekpoints ""
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			if {$checker == $scoreplayer} {
				if {[lindex $tally 1] > 1} {
				set weekpoints "3 [lindex $tally 1] points6 so far this week"
				} {
				set weekpoints "3 1 point6 so far this week"
				}
				set foundflag 1
			}
		}
		close $f
		if {$foundflag == 0} {set weekpoints "4 no points6 so far this week"}
		set foundflag 0
		set f [open $monthfilename r]
		set monthpoints ""
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			if {$checker == $scoreplayer} {
				if {[lindex $tally 1] > 1} {
				set monthpoints "3 [lindex $tally 1] points6 so far this month"
				} {
				set monthpoints "3 [lindex $tally 1] points6 so far this month"
				}
				set foundflag 1
			}
		}
		close $f
		if {$foundflag == 0} {set monthpoints "4 no points6 so far this month"}

		set foundflag 0
		set f [open $yearfilename r]
		set yearpoints ""
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			if {$checker == $scoreplayer} {
				if {[lindex $tally 1] > 1} {
				set yearpoints "3 [lindex $tally 1] points6 so far this year"
				} {
				set yearpoints "3 [lindex $tally 1] points6 so far this year"
				}
				set foundflag 1
			}
		}
		close $f
		if {$foundflag == 0} {set yearpoints "4 no points6 so far this year"}

## Find Player's Fastest Time Routine!
		set foundflag 0
if ![file exists "GenericScoresTEXT/FastestPlayers.txt"] {
		set f [open "GenericScoresTEXT/FastestPlayers.txt" w]
		puts $f "$triviaowner 60 0"
 		close $f
}
		set f [open "GenericScoresTEXT/FastestPlayers.txt" r]
		set fastanswer ""
		set fastqty ""
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			if {$checker == $scoreplayer} {
				if {[lindex $tally 1] > 1} {
				set fastanswer "has a speed record of3 [lindex $tally 1] seconds"
				}
				if {[lindex $tally 1] == 1} {
				set fastanswer "has a speed record of3 1 second"
				}
				if {[lindex $tally 1] < 1} {
				set fastanswer "has a speed record of 3less than a second"
				}
				if {[lindex $tally 2] != ""} {
					if {[lindex $tally 2] > 1} {
					 append fastanswer " 6and has matched it3 [lindex $tally 2] times 6so far!"
					}
				}
				if {[lindex $tally 2] != ""} {
					if {[lindex $tally 2] < 2} {
					 append fastanswer "!"
					}
				}
				if {![info exists [lindex $tally 2]]} {
					 append fastanswer "!"
				}
				set foundflag 1
			}
		}
		close $f
		if {$foundflag == 0} {set fastanswer "4has no speed record yet"}
## Find Player's Winning Streak Routine!
if ![file exists "GenericScoresTEXT/TopStreakers.txt"] {
		set f [open "GenericScoresTEXT/TopStreakers.txt" w]
		puts $f "$triviaowner 0"
 		close $f
}
		set foundflag 0
		set f [open "GenericScoresTEXT/TopStreakers.txt" r]
		set streak ""
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			if {$checker == $scoreplayer} {
				if {[lindex $tally 1] > 1} {
				set streak "has a winning streak record of3 [lindex $tally 1] wins in a row6"
				}
				if {[lindex $tally 1] == 1} {
				set streak "has a winning streak of3 1 in a row6"
				}
				set foundflag 1
				if {[lindex $tally 1] == 0} {
				 set foundflag 0
				}
			}
		}
		close $f
		if {$foundflag == 0} {set streak "4has no winning streak record yet6"}


putquick "privmsg $triviachannel :6 $nicktodisplay has $daypoints, $weekpoints, $monthpoints, $yearpoints, $streak and $fastanswer"
		return
}

##

## Stop Trivia
proc StopTrivia {nick uhost hand chan args} {
global teamenable usercounter ScrambleRoundChosen validbanks frequency triviavalue bonuslengths bonusvalues bonusdrops pointdrops pointdropdelay pointdropdecrease minhintletters maxhintletters hinttimes percentagehintenable hintpercentage hintmethods orig_validbanks orig_frequency orig_trivvalue orig_bonuslengths orig_bonusvalues orig_bonusdrops orig_pointdrops orig_pointdropdelay orig_pointdropdecrease orig_minhintletters orig_maxhintletters orig_hinttimes orig_percentagehintenable orig_hintpercentage orig_hintmethods trivquitvalidhosts ownerhost origtrivvalue triviavalue nextorder pointdropcounter pointdropcounter antifloodenable usercounter commandusers nameofbot triviaowner triviachannel trivquitopallowed trivquitvalidusers alreadygoing qafile question wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$trivquitopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $trivquitvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $trivquitvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################



	if {$triviastoppedflag == 1} {
		putquick "privmsg $triviachannel : Trivia isn't even running, $nick!"
		return 1
	}
	if {$alreadygoing == 0} {
		putquick "privmsg $triviachannel : Trivia isn't even running, $nick!"
		return 1
	}
	if {$teamenable == 1} {
		 putquick "privmsg $triviachannel :Team Trivia Mode Is On...type !TeamTrivia To Stop The Game!"
		 return
	}
	set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Advertiser* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Hanging* [lindex $t 1]] {
		        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	set triviavalue $origtrivvalue
 	if [info exists nextorder] {unset nextorder}
 	set pointdropcounter 0
########### V6.0: SCRAMBLE CODE: RESET VARS BACK TO TRIVIA
if {$ScrambleRoundChosen == 1} {
 set validbanks $orig_validbanks
 set frequency $orig_frequency
 set triviavalue $orig_trivvalue
 set bonuslengths $orig_bonuslengths
 set bonusvalues $orig_bonusvalues
 set bonusdrops $orig_bonusdrops
 set pointdrops $orig_pointdrops
 set pointdropdelay $orig_pointdropdelay
 set pointdropdecrease $orig_pointdropdecrease
 set minhintletters $orig_minhintletters
 set maxhintletters $orig_maxhintletters
 set hinttimes $orig_hinttimes
 set percentagehintenable $orig_percentagehintenable
 set hintpercentage $orig_hintpercentage
 set hintmethods $orig_hintmethods
 }
 ##########################################################

	putquick "privmsg $triviachannel : $nick has stopped Online Trivia...type !trivia to start it again!"
	utimer 10 "Advertiser"
	return 1
}

##

## TriviaBot Quick Help

proc TrivMenu {nick uhost hand chan args} {
global dedication helpline1 helpline2 helpline3 helpline4 helpline5 antifloodenable usercounter commandusers alreadygoing question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
putquick "NOTICE $nick :$dedication"
putquick "NOTICE $nick :$helpline1"
putquick "NOTICE $nick :$helpline2"
if {[isop $nick $triviachannel]} {
putquick "NOTICE $nick :$helpline3"
}
if {[isop $nick $triviachannel]} {
putquick "NOTICE $nick :$helpline4"
}
putquick "NOTICE $nick :$helpline5"
return
}

proc UserTriviaAdditions {nick uhost hand args} {
global triviachannel antifloodenable nameofbot usercounter commandusers
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
	regsub -nocase -all \[{}] $args "" args
	if {[string length $args] == 0} {
 	 putquick "NOTICE $nick :Usage: /msg BOTNICK add QUESTION*ANSWER"
	 return
	} {
      if {[onchan $nick $triviachannel] =="0"} {
        putquick "notice $nick :You must be in $triviachannel in order to add some trivia $nick!"
        return 1
      }
      if {![file exist "TriviaBanks/TriviaAdditions.qst"]} {
 	 set f [open "TriviaAdditions.qst" w]
	  close $f
}
if {![file exist "TriviabotUserQuestions.log"]} {
 	 set f [open "TriviabotUserQuestions.log" w]
	  close $f
}

## Insert Valid Question And Answer Checking Code Here!

 	 set f [open "TriviaBanks/TriviaAdditions.qst" a]
 	  puts $f "$args"
	  close $f
 	 set f [open "TriviabotUserQuestions.log" a]
 	  puts $f "$nick: $args"
 	  putquick "NOTICE $nick :Thanks for your addition $nick! We'll check it out asap! 8)"
	  close $f
 	  return
	}
}


proc UserComments {nick uhost hand args} {
global triviachannel antifloodenable nameofbot usercounter commandusers
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
}
 set commandusers($usercounter) "$nick $uhost"
	regsub -nocase -all \[{}] $args "" args
	if {[string length $args] == 0} {
	 putquick "NOTICE $nick :Usage: /msg BOTNICK comment YOUR COMMENT"
	 return
	} {
      if {[onchan $nick $triviachannel] =="0"} {
        putquick "notice $nick :You must be in $triviachannel in order to leave a comment $nick!"
        return 1
      }
      if {![file exist "TriviabotUserComments.txt"]} {
 	 set f [open "TriviabotUserComments.txt" w]
	  close $f
}
	  set f [open "TriviabotUserComments.txt" a]
 	  puts $f "$nick: $args"
	  putquick "NOTICE $nick :Thanks for your insights $nick! We'll check it out asap! 8)"
	  close $f
 	  return
	}
}


proc CheckErroredQuestion {nick uhost hand args} {
global qcheckvalidhosts ownerhost antifloodenable usercounter commandusers qafile triviaowner qcheckopallowed qcheckvalidusers triviachannel validbanks
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$qcheckopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $qcheckvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $qcheckvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################

regsub -nocase -all \[{}] $args "" args
if {[string length $args] == 0} {
 if ![file exist "TriviabotErroredQuestions.txt"] {
  set g [open "TriviaErroredQuestions.txt" w]
  close $g
 }
 set g [open "TriviabotErroredQuestions.txt" r]
 set erroredqnums ""
 while {[gets $g line] != -1} {
  append erroredqnums "[lindex $line 1], "
 }
 close $g
 putquick "NOTICE $nick :Current Errors Are: $erroredqnums"
 putquick "NOTICE $nick :Usage: /msg BOTNICK check QUESTION NUMBER (Example: '/msg BOTNICK check 2000')"
 return
}
if {[string tolower [lindex $args 0]] == "reset"} {
 set g [open "TriviabotErroredQuestions.txt" w]
 close $g
 putquick "NOTICE $nick :The Errored Question File has been cleared!"
 return
}
set checknum [lindex $args 0]
#########
###
## Find Out How Many Questions There Are!
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
 if {[lindex $line 0] == "TotalTrivia"} {
  set etotal [lindex $line 1]
 }
}
close $g

 if {[lindex $args 0] > $etotal} {
  putquick "NOTICE $nick :Sorry $nick, but there's no such question...please try again!"
  return
 }
 set f [open "TriviaBankTotals.txt" r]
 set qdone 0
 set convertednum 0
 set eqbank ""
 set numleft [lindex $args 0]
 set banksjumped 0
 while {$qdone != 1} {
  gets $f line
  set eqbank [lindex $line 0]
  if {[lindex $line 1] >= $numleft} {
   set eqbank [lindex $line 0]
   set qdone 1
   incr banksjumped
  }
  if {$qdone == 0} {
    set numleft [expr ($numleft + ($banksjumped *2)) - [lindex $line 1]]
  }
 }
 close $f

###

#########
set f [open $eqbank r]
set counter 0
while {$counter <= $numleft} {
 gets $f qaline
 incr counter
}
close $f
putquick "NOTICE $nick :Question #$checknum is Question #$numleft from $eqbank: $qaline"
return
}


proc NormalUserNextQuestion {nick uhost hand chan args} {
 global ManualTrivDelay usercounter orig_knowncolor orig_unknowncolor orig_QText orig_QBackground orig_AText orig_ABackground orig_HText orig_HBackground scrpdpv gamemode gamemodepercent scramblebanks sbankpercents scramblepvmethod scramblepresetvalue scrletters scrvalues scrdrops scrptdrops scrptdropseconds scrcluedisplay scrhintptdrop scrminhintletters scrmaxhintletters scrmaxhints scrpercenthintenable scrhintpercent scrhintprocess scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc knowncolor unknowncolor QText QBackground AText ABackground HText HBackground orig_knowncolor orig_unknowncolor orig_QText orig_QBackground orig_AText orig_ABackground orig_HText orig_HBackground ScrambleRoundChosen validbanks orig_validbanks frequency orig_frequency triviavalue orig_trivvalue bonuslengths orig_bonuslengths bonusvalues orig_bonusvalues bonusdrops orig_bonusdrops pointdrops orig_pointdrops pointdropdelay orig_pointdropdelay pointdropdecrease orig_pointdropdecrease minhintletters orig_minhintletters maxhintletters orig_maxhintletters hinttimes orig_hinttimes percentagehintenable orig_percentagehintenable  hintpercentage orig_hintpercentage hintmethods orig_hintmethods LastAnswer answer pointdropcounter antifloodenable usercounter commandusers origtrivvalue opnextquestioncounter opnextorder alreadygoing question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed nextquestioncounter nextorder triviavalue triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy validbanks frequency triviavalue bonuslengths bonusvalues bonusdrops pointdrops pointdropdelay pointdropdecrease minhintletters maxhintletters hinttimes percentagehintenable hintpercentage hintmethods knowncolor unknowncolor QText QBackground AText ABackground HText HBackground
## Antiflood routine
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
##
if {$nextenable == 0} {return}
 if {$alreadyguessed == 1} {return 1}
 if {$triviastoppedflag == 1} {
  putquick "privmsg $triviachannel :I'd skip the current question for you $nick, but Trivia's not even running... type !trivia to start it first! 8)"
  return
 }
 set totalops 0
 set totalnonops 0
 set totalnextusers 0
 foreach nextquestioncounter [array names nextorder] {
   if {[lindex $nextorder($nextquestioncounter) 1] == $uhost} {
    return
   }
   if [isop [lindex $nextorder($nextquestioncounter) 0] $triviachannel] {
    incr totalops
   } {
    incr totalnonops
   }
   incr totalnextusers
  }
 incr nextquestioncounter
 set nextorder($nextquestioncounter) "$nick $uhost 0"
 if [isop $nick $triviachannel] {
  incr totalops
 } {
  incr totalnonops
 }
 incr totalnextusers
 set totalopsneeded [expr $opsnumber - $totalops]
 set totalnonopsneeded [expr $nonopsnumber - $totalnonops]

 set nopeflag 0
 if {$totalnonops < $nonopsnumber} {
 set nopeflag 1
 }
 if {$totalops < $opsnumber} {
 set nopeflag 1
 }
 if {$totalnextusers >= $nonopsnumber} {
  set nopeflag 0
 }
 if {$totalnonops >= $nonopsnumber} {
  set nopeflag 0
 }
 if {$totalops >= $opsnumber} {
  set nopeflag 0
 }
 set totalnextusers [expr $nonopsnumber - $totalnextusers]
 if {$totalopsneeded !=0} {
  if {$totalnextusers != 0} {
   set gotem 0
   if {$totalopsneeded == 1} {
    putquick "privmsg $triviachannel :$nick has requested the next question! We need 1 more Op or $totalnextusers more Non-Ops to type !next in order to skip!"
    set gotem 1
   }
   if {$totalnextusers == 1} {
    putquick "privmsg $triviachannel :$nick has requested the next question! We need $totalopsneeded more Ops or 1 more Non-Op to type !next in order to skip!"
    set gotem 1
   }
   if {$gotem == 0} {
    putquick "privmsg $triviachannel :$nick has requested the next question! We need $totalopsneeded more Ops or $totalnextusers more Non-Ops to type !next in order to skip!"
   }
  }
 }
 if {$nopeflag == 1} {return}
 set LastAnswer $answer
 putquick "privmsg $triviachannel :3Current Question has been skipped...next question in $TrivDelay Seconds...Get Ready!"
 ########### V6.0: SCRAMBLE CODE: RESET VARS BACK TO TRIVIA
 if {$ScrambleRoundChosen == 1} {
 set validbanks $orig_validbanks
 set frequency $orig_frequency
 set triviavalue $orig_trivvalue
 set bonuslengths $orig_bonuslengths
 set bonusvalues $orig_bonusvalues
 set bonusdrops $orig_bonusdrops
 set pointdrops $orig_pointdrops
 set pointdropdelay $orig_pointdropdelay
 set pointdropdecrease $orig_pointdropdecrease
 set minhintletters $orig_minhintletters
 set maxhintletters $orig_maxhintletters
 set hinttimes $orig_hinttimes
 set percentagehintenable $orig_percentagehintenable
 set hintpercentage $orig_hintpercentage
 set hintmethods $orig_hintmethods
 set knowncolor $orig_knowncolor
 set unknowncolor $orig_unknowncolor
 set QText $orig_QText
 set QBackground $orig_QBackground
 set AText $orig_AText
 set ABackground $orig_ABackground
 set HText $orig_HText
 set HBackground $orig_HBackground
 
 

 }
 ##########################################################
 set alreadyguessed 1
 set nextquestioncounter 0
 set triviavalue $origtrivvalue
 if [info exists nextorder] {unset nextorder}
 foreach t [utimers] {
  if [string match *SecondDisplay* [lindex $t 1]] {
   killutimer [lindex $t end]
  }
  if [string match *Mainproc* [lindex $t 1]] {
   killutimer [lindex $t end]
  }
  if [string match *PointDrop* [lindex $t 1]] {
   killutimer [lindex $t end]
  }
  if [string match *EndOf* [lindex $t 1]] {
   killutimer [lindex $t end]
  }
  if [string match *Hanging* [lindex $t 1]] {
          killutimer [lindex $t end]
  }
 }
 set pointdropcounter 0
 utimer [expr $TrivDelay - $ManualTrivDelay] "Mainproc blah blah blah $triviachannel"
 return 1
}

proc ChangeChannelTopic {nick uhost hand args} {
global changetopicvalidhosts ownerhost qtotal alreadygoing antifloodenable TopicLeftBorder TopicRightBorder usercounter commandusers validquestions qafilelength qafile triviaowner triviachannel changetopicopallowed changetopicvalidusers validbanks nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$changetopicopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $changetopicvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $changetopicvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################

regsub -nocase -all \[{}] $args "" args
if {[string length $args] == 0} {
if {[expr $qafilelength -1] == -1} {
 putquick "privmsg $triviachannel :Trivia must be going for me to place a random ad or else I'll be displaying a total of -1 questions available...sorry!"
 return
}
  set adtouse [get_Ad]
  set bordertousenum [rand [llength $TopicLeftBorder]]
  putquick "TOPIC $triviachannel :[lindex $TopicLeftBorder $bordertousenum] $adtouse 13(11Containing4 $qtotal 11questions!13) [lindex $TopicRightBorder $bordertousenum]"
  return 1
 } {
  set adtouse $args
  set bordertousenum [rand [llength $TopicLeftBorder]]
  putquick "TOPIC $triviachannel :[lindex $TopicLeftBorder $bordertousenum] $adtouse [lindex $TopicRightBorder $bordertousenum]"
  return 1
}
}

proc ResetAlreadyAskedQuestionFile {nick uhost hand args} {
global qafilelength marksplitter ownerhost trivresetvalidhosts antifloodenable usercounter commandusers alreadyaskedfile qafile triviaowner triviachannel trivresetopallowed trivresetvalidusers validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$trivresetopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $trivresetvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $trivresetvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################


	regsub -nocase -all \[{}] $args "" args
	if {[string length $args] == 0} {
	 putquick "NOTICE $nick :Usage: /msg BOTNICK trivreset QUESTIONBANK (Example: '/msg BOTNICK trivreset General.qst')"
	 return
	}
 
set qafile "TriviaBanks/"
 append qafile $args
 set alreadyaskedfile "AlreadyAsked/AlreadyAsked"
 append alreadyaskedfile $args

## Routine For Finding Out How Many Questions There Are!
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
if {[lindex $line 0] == $qafile} {
set qafilelength [lindex $line 1]
}
}
close $g
##
set origqfilelength $qafilelength
#####
## Create Zeroed Question Already Asked Markers For Tracker!
 set g [open $alreadyaskedfile w]
 puts $g "$qafilelength $qafilelength"
 close $g
 set qnumindex ""
 set marker 0
 set totalqs 0
 while {$totalqs <= $qafilelength} {
  append qnumindex "0"
  incr marker
  incr totalqs
  if {$marker == $marksplitter} {
   set g [open $alreadyaskedfile a]
   puts $g "$qnumindex"
   close $g
   set marker 0
   set qnumindex ""
  }
 }
      set g [open $alreadyaskedfile a]
      puts $g "$qnumindex"
      close $g

##



 putquick "notice $nick :The 'Already Asked' Question File for the $qafile bank has been reset!"
 return 1

}


proc SwapBanks {nick uhost hand args} {
global usercounter antifloodenable commandusers ownerhost swapbankvalidhosts randommode swapbankflag qafile alreadyaskedfile triviaowner triviachannel swapbankopallowed swapbankvalidusers validbanks nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
set backupqafile $qafile
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$swapbankopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $swapbankvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $swapbankvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################

 regsub -all \[{}] $args "" args
 if {[string length $args] == 0} {
  putquick "NOTICE $nick :Valid banks are: $validbanks and random! Bank In Use is $qafile!"
  return 1
 }
if {[string tolower $args] == "random"} {
putquick "privmsg $triviachannel :Random Bank Mode is now in progress starting with the next question... 8)"
set randommode 1
return
}
set qafiletoswapto "TriviaBanks/"
 append qafiletoswapto $args
 set alreadyaskedfiletoswapto "AlreadyAsked/AlreadyAsked"
 append alreadyaskedfiletoswapto $args
 if {![file exist $qafiletoswapto]} {
  putquick "NOTICE $nick :Sorry $nick, but I don't see $qafiletoswapto anywhere in my directory...Current valid banks are: $validbanks! I'll keep the $qafile bank going instead...sorry!"
  set qafile $backupqafile
  return 1
 }
 set qafile $qafiletoswapto
 set alreadyaskedfile $alreadyaskedfiletoswapto
  set swapbankflag 1
 set randommode 0
 putquick "privmsg $triviachannel :$nick has made me swap to the $args question bank...they'll be used starting with the next question! 8)"
 return 1
 }


## Display Top 10 Daily Scores To A Player
proc DailyTop10 {nick uhost hand chan args} {
global antifloodenable usercounter commandusers alreadygoing question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed dayfilename datechecker triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
 regsub -all \[{}] $args "" args
 if {[string length $args] == 0} {
  putquick "NOTICE $nick :(If you wish to view another day's score, use the form '!daytop10 MONTH DAY YEAR' (!daytop10 aug 22 1999 for example...MONTH is first three letters, year MUST be a 4 digit year!)"
  set dater [unixtime]
  set datechecker [ctime $dater]
  set dayfilename "TriviaDailyScores/"
  append dayfilename [lindex $datechecker 1]
  append dayfilename [lindex $datechecker 2]
  append dayfilename [lindex $datechecker 4]
  append dayfilename ".txt"
  set datedesired "Today"
 }
 if {[string length $args] > 0} {
  set counter 0
  set dayfilename "TriviaDailyScores/"
  set datedesired ""
  while {[lindex $args $counter] != ""} {
   append dayfilename [lindex $args $counter]
   append datedesired [lindex $args $counter]
   append datedesired " "
   incr counter
  }
  append dayfilename ".txt"
 }
 if {![file exist $dayfilename]} {
  putquick "NOTICE $nick :Sorry $nick, but I can't find a top 10 score for $datedesired...8("
  return 1
 }
 putquick "NOTICE $nick :Top 10 Trivia Scores For $datedesired:"
 set winners ""
 set f [open $dayfilename r]
 for { set s 0 } { $s < 10 } { incr s } {
  gets $f tally
  set placement [expr $s +1]
  if {$placement == 1} {set placement " 1st Place: "
   set headhoncho [lindex $tally 0]
  }
  if {$placement == 2} {set placement " 2nd Place: "}
  if {$placement == 3} {set placement " 3rd Place: "}
  if {$placement == 4} {set placement " 4th Place: "}
  if {$placement == 5} {set placement " 5th Place: "}
  if {$placement == 6} {set placement " 6th Place: "}
  if {$placement == 7} {set placement " 7th Place: "}
  if {$placement == 8} {set placement " 8th Place: "}
  if {$placement == 9} {set placement " 9th Place: "}
  if {$placement == 10} {set placement " 10th Place: "}
  append winners $placement
  append winners [lindex $tally 0]
  append winners " with "
  append winners [lindex $tally 1]
  if {[lindex $tally 1] > 1} {
   append winners " points! "
  } else {
   append winners " point! "
  }
 }
 putquick "NOTICE $nick :$winners"
 putquick "NOTICE $nick :Congratulations To $headhoncho for wearing their thinking cap the most! 8)"
 close $f
 return
}


## Display Top 10 Scores For A Month To A Player
proc Top10 {nick uhost hand chan args} {
global antifloodenable usercounter commandusers alreadygoing question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed monthfilename datechecker triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
if {[string tolower $chan] != [string tolower $triviachannel]} {return}

if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
regsub -all \[{}] $args "" args
 if {[string length $args] == 0} {
  putquick "NOTICE $nick :(If you wish to view a different month's score, use the form '!top10 MONTH YEAR' (!top10 aug 1999 for example...MONTH is first three letters, year MUST be a 4 digit year!)"
  set dater [unixtime]
  set datechecker [ctime $dater]
  set monthfilename "TriviaMonthlyScores/"
  set datedesired ""
  append monthfilename [lindex $datechecker 1]
  append datedesired [lindex $datechecker 1]
  append datedesired ", "
  append monthfilename [lindex $datechecker 4]
  append datedesired [lindex $datechecker 4]
  append monthfilename ".txt"
 }
 if {[string length $args] > 0} {
  set counter 0
  set monthfilename "TriviaMonthlyScores/"
  set datedesired ""
  while {[lindex $args $counter] != ""} {
   append monthfilename [lindex $args $counter]
   append datedesired [lindex $args $counter]
   append datedesired " "
   incr counter
  }
  append monthfilename ".txt"
 }
 if {![file exist $monthfilename]} {
  putquick "NOTICE $nick :Sorry $nick, but I can't find a top 10 score for $datedesired...8("
  return 1
 }
 putquick "NOTICE $nick :Top 10 Trivia Scores For $datedesired:"
 set winners ""


		set winners ""
		set f [open $monthfilename r]
		for { set s 0 } { $s < 10 } { incr s } {
			gets $f tally
			set placement [expr $s +1]
			if {$placement == 1} {set placement " 1st Place: "
				set headhoncho [lindex $tally 0]
			}
			if {$placement == 2} {set placement " 2nd Place: "}
			if {$placement == 3} {set placement " 3rd Place: "}
			if {$placement == 4} {set placement " 4th Place: "}
			if {$placement == 5} {set placement " 5th Place: "}
			if {$placement == 6} {set placement " 6th Place: "}
			if {$placement == 7} {set placement " 7th Place: "}
			if {$placement == 8} {set placement " 8th Place: "}
			if {$placement == 9} {set placement " 9th Place: "}
			if {$placement == 10} {set placement " 10th Place: "}
			append winners $placement
			append winners [lindex $tally 0]
			append winners " with "
			append winners [lindex $tally 1]
			if {[lindex $tally 1] > 1} {
				append winners " points! "
			} else {
				append winners " point! "
			}
		}
		putquick "NOTICE $nick :$winners"
		putquick "NOTICE $nick :Congratulations To $headhoncho for wearing their thinking cap the most! 8)"
		close $f
		return
}

proc cleartop10 { } {
global autovoicesynch score fastclear streakclear triviachannel monthfilename prevmonthfilename monthhtmlfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy

## Write Scores To Last Month's Top 10 Text File!
	set webscore "GenericScoresHTML/LastMonth.html"
	set f [open "GenericScoresTEXT/LastMonth.txt" w]
	set totalplayers 0
	set totalpoints 0
	foreach s [lsort -decreasing -command sort_score [array names score]] {
		puts $f "$s $score($s)"
		incr totalplayers
		incr totalpoints $score($s)
	}
	close $f
		set f [open $webscore w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Monthly trivia scores for the month ending on: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_score [array names score]] {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$score($s)</TD></TR>"
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################
##
 set f [open $monthfilename w]
 puts $f "$triviaowner 0"
 close $f
 if [info exists score] { unset score }
 putquick "privmsg $triviachannel :The monthly scores have been reset for a new month! Good luck everyone!"
if {$fastclear == 2} {clearfast}
if {$streakclear == 2} {clearstreak}
if {$autovoicesynch ==2} {clearvoices}
 return 1
}
##

proc cleardailytop10 { } {
	global autovoicesynch fastclear streakclear dayscore dayfilename dayhtmlfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
## Write Scores To Yesterday's Top 10 Text File!
	set webscore "GenericScoresHTML/Yesterday.html"
	set f [open "GenericScoresTEXT/Yesterday.txt" w]
	set totalplayers 0
	set totalpoints 0
	foreach s [lsort -decreasing -command sort_dayscore [array names dayscore]] {
		puts $f "$s $dayscore($s)"
		incr totalplayers
		incr totalpoints $dayscore($s)
	}
	close $f
		set f [open $webscore w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Daily trivia scores for the day ending on: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_dayscore [array names dayscore]] {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$dayscore($s)</TD></TR>"
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################
##
 set f [open $dayfilename w]
 puts $f "$triviaowner 0"
 close $f
 if [info exists dayscore] { unset dayscore }
 putquick "privmsg $triviachannel :The daily scores have been reset for a new day! Good luck everyone!"
if {$fastclear == 0} {clearfast}
if {$streakclear == 0} {clearstreak}
if {$autovoicesynch == 0} {clearvoices}
 return 1
}
##

## Read Current Scorefile
proc read_score { } {
global score monthfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy

	if [info exists score] { unset score }
 if {![file exist $monthfilename]} {
  set g [open $monthfilename w]
  puts $g "$triviaowner 0"
  close $g
 }
	set f [open $monthfilename r]
	while {[gets $f s] != -1} {
regsub -all \[{}] $s "" s
		set score([lindex $s 0]) [lindex $s 1]
	}
	close $f
return 1
}
##

## Score Sorting Routines

proc sort_score {s1 s2} {
	global score
	if {$score($s1) > $score($s2)} { return 1 }
	if {$score($s1) < $score($s2)} { return -1 }
	if {$score($s1) == $score($s2)} { return 0 }
}
##

## Write Score File And Web Page Version Of Score File

proc write_score { } {
	global score monthfilename monthhtmlfilename triviaowner triviachannel
	set f [open $monthfilename w]
	set webscore "GenericScoresHTML/ThisMonth.html"
	foreach s [lsort -decreasing -command sort_score [array names score]] {
		if {$score($s) != 0} {
		 puts $f "$s $score($s)"
		}
	}
	close $f

	set f [open "GenericScoresTEXT/ThisMonth.txt" w]
	set totalplayers 0
	set totalpoints 0
	foreach s [lsort -decreasing -command sort_score [array names score]] {
		if {$score($s) != 0} {
		 puts $f "$s $score($s)"
		 incr totalplayers
 		 incr totalpoints $score($s)
		}
	}
	close $f

	if {$webscore != ""} {
		set f [open $webscore w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Monthly trivia scores as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_score [array names score]] {
		if {$score($s) != 0} {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$score($s)</TD></TR>"
 }
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################

		set f [open $monthhtmlfilename w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Monthly trivia scores as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_score [array names score]] {
		if {$score($s) != 0} {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$score($s)</TD></TR>"
}
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################
	}
return 1
}
##

## Read Current Scorefile
proc read_dayscore { } {
	global dayscore triviachannel dayfilename prevdayfilename dayhtmlfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy

	if [info exists dayscore] { unset dayscore }
 if {![file exist $dayfilename]} {
  set g [open $dayfilename w]
  puts $g "$triviaowner 0"
  close $g
 }
	set f [open $dayfilename r]
	while {[gets $f s] != -1} {
regsub -all \[{}] $s "" s
		set dayscore([lindex $s 0]) [lindex $s 1]
	}
	close $f
return 1
}
##

## Score Sorting Routines

proc sort_dayscore {s1 s2} {
	global dayscore
	if {$dayscore($s1) > $dayscore($s2)} { return 1 }
	if {$dayscore($s1) < $dayscore($s2)} { return -1 }
	if {$dayscore($s1) == $dayscore($s2)} { return 0 }
}
##

## Write Score File And Web Page Version Of Score File

proc write_dayscore { } {
	global dayscore dayfilename dayhtmlfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
	set webscore "GenericScoresHTML/Today.html"
	set f [open "GenericScoresTEXT/Today.txt" w]
	foreach s [lsort -decreasing -command sort_dayscore [array names dayscore]] {
		if {$dayscore($s) != 0} {
		puts $f "$s $dayscore($s)"
		}
	}
	close $f

	set f [open $dayfilename w]
	set totalplayers 0
	set totalpoints 0
	foreach s [lsort -decreasing -command sort_dayscore [array names dayscore]] {
		if {$dayscore($s) != 0} {
		 puts $f "$s $dayscore($s)"
		 incr totalplayers
		 incr totalpoints $dayscore($s)
		}
	}
	close $f

		set f [open $webscore w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Daily trivia scores as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_dayscore [array names dayscore]] {
		if {$dayscore($s) != 0} {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$dayscore($s)</TD></TR>"
 }
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################

		set f [open $dayhtmlfilename w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Daily trivia scores as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_dayscore [array names dayscore]] {
		if {$dayscore($s) != 0} {
  puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$dayscore($s)</TD></TR>"
 }
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################

return 1
}
##
## Read Current Scorefile
proc read_weekscore { } {
	global weekscore triviachannel weekfilename prevweekfilename weekhtmlfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy

	if [info exists weekscore] { unset weekscore }
 if {![file exist $weekfilename]} {
  set g [open $weekfilename w]
  puts $g "$triviaowner 0"
  close $g
 }
	set f [open $weekfilename r]
	while {[gets $f s] != -1} {
regsub -all \[{}] $s "" s
		set weekscore([lindex $s 0]) [lindex $s 1]
	}
	close $f
return 1
}
##

## Score Sorting Routines

proc sort_weekscore {s1 s2} {
	global weekscore
	if {$weekscore($s1) > $weekscore($s2)} { return 1 }
	if {$weekscore($s1) < $weekscore($s2)} { return -1 }
	if {$weekscore($s1) == $weekscore($s2)} { return 0 }
}
##

## Write Score File And Web Page Version Of Score File

proc write_weekscore { } {
	global weekscore weekfilename weekhtmlfilename triviaowner triviachannel validbanks nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy

	set f [open $weekfilename w]
	set webscore "GenericScoresHTML/ThisWeek.html"
	foreach s [lsort -decreasing -command sort_weekscore [array names weekscore]] {
		if {$weekscore($s) != 0} {
		 puts $f "$s $weekscore($s)"
		}
	}
	close $f

	set f [open "GenericScoresTEXT/ThisWeek.txt" w]
	set totalplayers 0
	set totalpoints 0
	foreach s [lsort -decreasing -command sort_weekscore [array names weekscore]] {
		if {$weekscore($s) != 0} {
		puts $f "$s $weekscore($s)"
		incr totalplayers
		incr totalpoints $weekscore($s)
		}
	}
	close $f

	if {$webscore != ""} {
		set f [open $webscore w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Weekly trivia scores as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_weekscore [array names weekscore]] {
		if {$weekscore($s) != 0} {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$weekscore($s)</TD></TR>"
 }
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################

		set f [open $weekhtmlfilename w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Weekly trivia scores as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_weekscore [array names weekscore]] {
		if {$weekscore($s) != 0} {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$weekscore($s)</TD></TR>"
}
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################
	}
return 1
}

proc NewWeek { } {
global autovoicesynch fastclear streakclear weekscore triviachannel weekfilename prevweekfilename weekhtmlfilename datechecker triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy

## Write Scores To LastWeek's Top 10 Text File!
	set webscore "GenericScoresHTML/LastWeek.html"
	set f [open "GenericScoresTEXT/LastWeek.txt" w]
	set totalplayers 0
	set totalpoints 0
	foreach s [lsort -decreasing -command sort_weekscore [array names weekscore]] {
		puts $f "$s $weekscore($s)"
		incr totalplayers
		incr totalpoints $weekscore($s)
	}
	close $f
		set f [open $webscore w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Weekly trivia scores for the week ending on: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_weekscore [array names weekscore]] {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$weekscore($s)</TD></TR>"
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
####################### NEW WEEKLY SCORE CODE #########################################
 set dater [unixtime]
 set datechecker [ctime $dater]
 set month [lindex $datechecker 1]
 set day [lindex $datechecker 2]
 set year [lindex $datechecker 4]
set weekfilename "TriviaWeeklyScores/"
set weekhtmlfilename "HTMLWeeklyScores/"
set foundit 0
if {$month == "Jan"} {
 if {$foundit == 0} {
  if {7 >= $day} {
   set foundit 1
   set weekfile "Week1_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {14 >= $day} {
   set foundit 1
   set weekfile "Week2_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {21 >= $day} {
   set foundit 1
   set weekfile "Week3_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {28 >= $day} {
   set foundit 1
   set weekfile "Week4_"
   append weekfile "$year"
  }
}
if {$foundit == 0} {
  if {$day > 28} {
   set foundit 1
   set weekfile "Week5_"
   append weekfile "$year"
  }

 }
}
if {$foundit == 0} {
if {$month == "Feb"} {
 if {$foundit == 0} {
  if {4 >= $day} {
   set foundit 1
   set weekfile "Week5_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {11 >= $day} {
   set foundit 1
   set weekfile "Week6_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {18 >= $day} {
   set foundit 1
   set weekfile "Week7_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {25 >= $day} {
   set foundit 1
   set weekfile "Week8_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 25} {
   set foundit 1
   set weekfile "Week9_"
   append weekfile "$year"
  }
 }

 }
}

if {$foundit == 0} {
if {$month == "Mar"} {
 if {$foundit == 0} {
  if {4 >= $day} {
   set foundit 1
   set weekfile "Week9_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {11 >= $day} {
   set foundit 1
   set weekfile "Week10_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {18 >= $day} {
   set foundit 1
   set weekfile "Week11_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {25 >= $day} {
   set foundit 1
   set weekfile "Week12_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 25} {
   set foundit 1
   set weekfile "Week13_"
   append weekfile "$year"
  }
 }

 }
}

if {$foundit == 0} {
if {$month == "Apr"} {
 if {$foundit == 0} {
  if {1 >= $day} {
   set foundit 1
   set weekfile "Week13_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {8 >= $day} {
   set foundit 1
   set weekfile "Week14_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {15 >= $day} {
   set foundit 1
   set weekfile "Week15_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {22 >= $day} {
   set foundit 1
   set weekfile "Week16_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {29 >= $day} {
   set foundit 1
   set weekfile "Week17_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 29} {
   set foundit 1
   set weekfile "Week18_"
   append weekfile "$year"
  }
 }
 }
}

if {$foundit == 0} {
if {$month == "May"} {
 if {$foundit == 0} {
  if {6 >= $day} {
   set foundit 1
   set weekfile "Week18_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {13 >= $day} {
   set foundit 1
   set weekfile "Week19_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {20 >= $day} {
   set foundit 1
   set weekfile "Week20_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {27 >= $day} {
   set foundit 1
   set weekfile "Week21_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 27} {
   set foundit 1
   set weekfile "Week22_"
   append weekfile "$year"
  }
 }
 }
}

if {$foundit == 0} {
if {$month == "Jun"} {
 if {$foundit == 0} {
  if {3 >= $day} {
   set foundit 1
   set weekfile "Week22_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {10 >= $day} {
   set foundit 1
   set weekfile "Week23_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {17 >= $day} {
   set foundit 1
   set weekfile "Week24_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {24 >= $day} {
   set foundit 1
   set weekfile "Week25_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 24} {
   set foundit 1
   set weekfile "Week26_"
   append weekfile "$year"
  }
 }
 }
}

if {$foundit == 0} {
if {$month == "Jul"} {
 if {$foundit == 0} {
  if {1 >= $day} {
   set foundit 1
   set weekfile "Week26_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {8 >= $day} {
   set foundit 1
   set weekfile "Week27_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {15 >= $day} {
   set foundit 1
   set weekfile "Week28_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {22 >= $day} {
   set foundit 1
   set weekfile "Week29_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {29 >= $day} {
   set foundit 1
   set weekfile "Week30_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 29} {
   set foundit 1
   set weekfile "Week31_"
   append weekfile "$year"
  }
 }
 }
}

if {$foundit == 0} {
if {$month == "Aug"} {
 if {$foundit == 0} {
  if {5 >= $day} {
   set foundit 1
   set weekfile "Week31_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {12 >= $day} {
   set foundit 1
   set weekfile "Week32_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {19 >= $day} {
   set foundit 1
   set weekfile "Week33_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {26 >= $day} {
   set foundit 1
   set weekfile "Week34_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 26} {
   set foundit 1
   set weekfile "Week35_"
   append weekfile "$year"
  }
 }
 }
}


if {$foundit == 0} {
if {$month == "Sep"} {
 if {$foundit == 0} {
  if {2 >= $day} {
   set foundit 1
   set weekfile "Week35_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {9 >= $day} {
   set foundit 1
   set weekfile "Week36_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {16 >= $day} {
   set foundit 1
   set weekfile "Week37_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {23 >= $day} {
   set foundit 1
   set weekfile "Week38_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {$day > 23} {
   set foundit 1
   set weekfile "Week39_"
   append weekfile "$year"
  }
 }
 }
}


if {$foundit == 0} {
if {$month == "Oct"} {
 if {$foundit == 0} {
  if {7 >= $day} {
   set foundit 1
   set weekfile "Week40_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {14 >= $day} {
   set foundit 1
   set weekfile "Week41_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {21 >= $day} {
   set foundit 1
   set weekfile "Week42_"
   append weekfile "$year"
  }
 }
if {$foundit == 0} {
  if {28 >= $day} {
   set foundit 1
   set weekfile "Week43_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 28} {
   set foundit 1
   set weekfile "Week44_"
   append weekfile "$year"
  }
 }
 }
}


if {$foundit == 0} {
if {$month == "Nov"} {
 if {$foundit == 0} {
  if {4 >= $day} {
   set foundit 1
   set weekfile "Week44_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {11 >= $day} {
   set foundit 1
   set weekfile "Week45_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {18 >= $day} {
   set foundit 1
   set weekfile "Week46_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {25 >= $day} {
   set foundit 1
   set weekfile "Week47_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 25} {
   set foundit 1
   set weekfile "Week48_"
   append weekfile "$year"
  }
 }
 }
}


if {$foundit == 0} {
if {$month == "Dec"} {
 if {$foundit == 0} {
  if {2 >= $day} {
   set foundit 1
   set weekfile "Week48_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {9 >= $day} {
   set foundit 1
   set weekfile "Week49_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {16 >= $day} {
   set foundit 1
   set weekfile "Week50_"
   append weekfile "$year"
  }
 }
 if {$foundit == 0} {
  if {23 >= $day} {
   set foundit 1
   set weekfile "Week51_"
   append weekfile "$year"
  }
 }

if {$foundit == 0} {
  if {$day > 23} {
   set foundit 1
   set weekfile "Week52_"
   append weekfile "$year"
  }
 }
 }
}

 append weekfilename $weekfile
 append weekhtmlfilename $weekfile

 append weekfilename ".txt"
 append weekhtmlfilename ".html"
 if {![file exist $weekfilename]} {
  set f [open $weekfilename w]
  puts $f "$triviaowner 0"
  close $f
 }
####################### END OF NEW WEEKLY SCORE CODE ###################################
 if [info exists weekscore] { unset weekscore }
 putquick "privmsg $triviachannel :The weekly scores have been reset for a new week! Good luck everyone!"
 return 1
if {$fastclear == 1} {clearfast}
if {$streakclear == 1} {clearstreak}
if {$autovoicesynch == 1} {clearvoices}
}
##



## Display Top 10 Scores For A Week To A Player
proc WeeklyTop10 {nick uhost hand chan args} {
global antifloodenable usercounter commandusers alreadygoing question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed weekfilename datechecker prevweekfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
regsub -all \[{}] $args "" args
 set foundit 0
 if {[string length $args] == 0} {
  putquick "NOTICE $nick :(To view a specific week's Top 10, type '!weektop10 1' for week 1, etc...up to week 52! If you wish to view last week's Top 10, use '!weektop10 last', type '!weektop10 list' for a list of week ranges!"
  set weektocheck "GenericScoresTEXT/ThisWeek.txt"
  set weekchecking "This Week"
  set foundit 1
 }
 if {$args == "last"} {
  set weektocheck "GenericScoresTEXT/LastWeek.txt"
  set weekchecking "Last Week"
  set foundit 1
 }
 if {$args == "list"} {
  putquick "NOTICE $nick :Week 1: Jan 1-7 2: Jan 8-14 3: Jan 15-21 4: Jan 22-28 5: Jan 29-Feb 4 6: Feb 5-11 7: Feb 12-18 8: Feb 19-25 9: Feb 26-Mar 4 10: Mar 5-11 11: Mar 12-18 12: Mar 19-25 13: Mar 26-Apr 1 14: Apr 2-8 15: Apr 9-15 16: Apr 16-22 17: Apr 23-29 18: Apr 30-May 6 19: May 7-13 20: May 14-20 21: May 21-27 22: May 28-Jun 3 23: Jun 4-10 24: Jun 11-17 25: Jun 18-24 26: Jun 25-Jul 1"
  putquick "NOTICE $nick :Week 27: Jul 2-8 28: Jul 9-15 29: Jul 16-22 30: Jul 23-29 31: Jul 30-Aug 5 32: Aug 6-12 33: Aug 13-19 34: Aug 20-26 35: Aug 27-Sep 2 36: Sep 3-9 37: Sep 10-16 38: Sep 17-23 39: Sep 24-30 40: Oct 1-7 41: Oct 8-14 42: Oct 15-21 43: Oct 22-28 44: Oct 29-Nov 4 45: Nov 5-11 46: Nov 12-18 47: Nov 19-25 48: Nov 26-Dec 2 49: Dec 3-9 50: Dec 10-16 51: Dec 17-23 52: Dec 24-31"
  return
 }
 if {$foundit == 0} {
 set dater [unixtime]
 set datechecker [ctime $dater]
 set year [lindex $datechecker 4]

  set weektocheck "TriviaWeeklyScores/Week"
  append weektocheck "[lindex $args 0]"
  append weektocheck "_"
  append weektocheck "$year"
  append weektocheck ".txt"

  set weekchecking "Week $args"
 }
 if {![file exist $weektocheck]} {
  putquick "NOTICE $nick :Sorry $nick, but I can't find a top 10 score for $weekchecking..."
  return
}

 putquick "NOTICE $nick :Top 10 Trivia Scores For $weekchecking:"
	set winners ""
		set f [open $weektocheck r]
		for { set s 0 } { $s < 10 } { incr s } {
			gets $f tally
			set placement [expr $s +1]
			if {$placement == 1} {set placement " 1st Place: "
				set headhoncho [lindex $tally 0]
			}
			if {$placement == 2} {set placement " 2nd Place: "}
			if {$placement == 3} {set placement " 3rd Place: "}
			if {$placement == 4} {set placement " 4th Place: "}
			if {$placement == 5} {set placement " 5th Place: "}
			if {$placement == 6} {set placement " 6th Place: "}
			if {$placement == 7} {set placement " 7th Place: "}
			if {$placement == 8} {set placement " 8th Place: "}
			if {$placement == 9} {set placement " 9th Place: "}
			if {$placement == 10} {set placement " 10th Place: "}
			append winners $placement
			append winners [lindex $tally 0]
			append winners " with "
			append winners [lindex $tally 1]
			if {[lindex $tally 1] > 1} {
				append winners " points! "
			} else {
				append winners " point! "
			}
		}
		putquick "NOTICE $nick :$winners"
		putquick "NOTICE $nick :Congratulations To $headhoncho for wearing their thinking cap the most! 8)"
		close $f
		return
}



## Yearstuffs

proc clearyeartop10 { } {
global autovoicesynch fastclear streakclear yearscore triviachannel yearfilename prevyearfilename yearhtmlfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy

## Write Scores To Yesterday's Top 10 Text File!
	set webscore "GenericScoresHTML/LastYear.html"
	set f [open "GenericScoresTEXT/LastYear.txt" w]
	set totalplayers 0
	set totalpoints 0
	foreach s [lsort -decreasing -command sort_yearscore [array names yearscore]] {
		puts $f "$s $yearscore($s)"
		incr totalplayers
		incr totalpoints $yearscore($s)
	}
	close $f
		set f [open $webscore w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Yearly trivia scores for the year ending on: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_yearscore [array names yearscore]] {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$yearscore($s)</TD></TR>"
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################
##
 set f [open $yearfilename w]
 puts $f "$triviaowner 0"
 close $f
 if [info exists yearscore] { unset yearscore }
 putquick "privmsg $triviachannel :The yearly scores have been reset for a new year! Good luck and HAPPY NEW YEAR EVERYBODY!!!"
 return 1
if {$fastclear == 3} {clearfast}
if {$streakclear == 3} {clearstreak}
if {$autovoicesynch == 3} {clearvoices}
NewWeek
}
##

## Read Current Scorefile
proc read_yearscore { } {
	global nickyearranks yearscore triviachannel yearfilename prevyearfilename yearhtmlfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy

	if [info exists yearscore] { unset yearscore }
 if {![file exist $yearfilename]} {
  set g [open $yearfilename w]
  puts $g "$triviaowner 0"
  close $g
 }
 	set nickyearranks ""
	set f [open $yearfilename r]
	while {[gets $f s] != -1} {
regsub -all \[{}] $s "" s
		set yearscore([lindex $s 0]) [lindex $s 1]
		append nickyearranks "[lindex $s 0] "
	}
	close $f
return 1
}
##

## Score Sorting Routines

proc sort_yearscore {s1 s2} {
	global yearscore
	if {$yearscore($s1) > $yearscore($s2)} { return 1 }
	if {$yearscore($s1) < $yearscore($s2)} { return -1 }
	if {$yearscore($s1) == $yearscore($s2)} { return 0 }
}
##

## Write Score File And Web Page Version Of Score File

proc write_yearscore { } {
	global dedication nameofbot rankupdisplay pointsleftdisplay playeraheaddisplay triviachannel lastwinner nickyearmarker nickyearranks yearscore yearfilename yearhtmlfilename triviaowner triviachannel validbanks nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy

	set f [open $yearfilename w]
	set webscore "GenericScoresHTML/ThisYear.html"
	set nickyearmarker [lsearch $nickyearranks $lastwinner]
##	putquick "privmsg $triviachannel :nickyearranks:$nickyearranks!"
##	putquick "privmsg $triviachannel :nickyearmarker:$nickyearmarker!"

	
	set newrankorder ""
      set numberofplayers 0
      set tempyrscores ""
      set lastindexer ""
	foreach s [lsort -decreasing -command sort_yearscore [array names yearscore]] {
		if {$yearscore($s) != 0} {
		puts $f "$s $yearscore($s)"
		append newrankorder "$s "
		append tempyrscores "$yearscore($s) "
		if {"$s" == "$lastwinner"} {set lastindexer $numberofplayers}
		incr numberofplayers
		}
	}
	close $f
	set yearrankcheck [lsearch $newrankorder $lastwinner]
	set yearplace [expr [llength $newrankorder] - $yearrankcheck]
	if {$yearrankcheck < 1} {
if {$rankupdisplay == 1} {
	  putquick "privmsg $triviachannel :6 $lastwinner is in 1st place for this year! Good job $lastwinner!"
}
	if {$yearrankcheck != [llength $newrankorder]} {
if {$rankupdisplay == 1} {
if {$nickyearmarker > 0} {
	  putquick "privmsg $triviachannel :6 $lastwinner has just moved into position [expr $yearrankcheck +1] for this year!"
          incr lastindexer 1
}
}
}
}
### POINT DIFFERENCE BETWEEN PLAYERS CODE GOES HERE!!!
if {$numberofplayers > 1} {
	if {$yearrankcheck != 0} {
	 set nextrankplayer [lindex $newrankorder [expr $lastindexer -1]]
set pt1 [lindex $tempyrscores [expr $lastindexer -1]]
if {$lastwinner == $nextrankplayer} {
 set lastindexer [expr $lastindexer -1]
 set nextrankplayer [lindex $newrankorder [expr $lastindexer -1]]
}
### if player just entered the board in last place, get score of lastindexer -1
if {$yearplace == [llength $newrankorder]} {
 set pt1 [lindex $tempyrscores [expr $lastindexer -2]]
}
###

set pt2 [lindex $tempyrscores $lastindexer]
##	 set pointdifference [expr ($yearscore($nextrankplayer) - $yearscore($lastwinner)) + 1]
	 set pointdifference [expr ($pt1 - $pt2) + 1]
	 if {$pointdifference != 0} {
	  if {$pointdifference == 1} {
	   if {$pointsleftdisplay == 1} {
	    putquick "privmsg $triviachannel :6 $lastwinner needs $pointdifference more point to take over position $lastindexer this year!"	
	   }
	   if {$playeraheaddisplay == 1} {
	    	    putquick "privmsg $triviachannel :The player ahead of you is $nextrankplayer!"
	   }
	   if {$playeraheaddisplay == 2} {
	    if {$lastwinner != $nameofbot} {
 	     putquick "notice $lastwinner :The player ahead of you is $nextrankplayer!"
	    }
	   }
	  }
	  if {$pointdifference > 1} {
	   if {$pointsleftdisplay == 1} {
	    putquick "privmsg $triviachannel :6 $lastwinner needs $pointdifference more points to take over position $lastindexer this year!"	
	   }
	   if {$playeraheaddisplay == 1} {
	   	    putquick "privmsg $triviachannel :The player ahead of you is $nextrankplayer!"
	   }
	   if {$playeraheaddisplay == 2} {
	    if {$lastwinner != $nameofbot} {
	     putquick "notice $lastwinner :The player ahead of you is $nextrankplayer!"
	    }
	   }
	  }
	 }
	}
	
### INSERT NEW CODE HERE FOR TELLING HOW FAR AHEAD 1ST PLACE PLAYER IS
### TO SECOND PLACE PLAYER!
	if {$yearrankcheck < 1} {
set pt1 [lindex $tempyrscores 1]
set pt2 [lindex $tempyrscores 0]
set nextrankplayer [lindex $newrankorder [expr $lastindexer +1]]
set pointdifference [expr ($pt2 - $pt1) + 1]
	 if {$pointdifference != 0} {
	 	  if {$pointdifference == 1} {
	        if {$pointsleftdisplay == 1} {
	  		putquick "privmsg $triviachannel :6 $lastwinner is 1 point ahead for keeping 1st place this year!"	
		}
	 	  }
	 	  if {$pointdifference > 1} {
	   if {$pointsleftdisplay == 1} {
	  		putquick "privmsg $triviachannel :6 $lastwinner is $pointdifference points ahead for keeping 1st place this year!"	
	   }
	  }
	  
	  	   if {$playeraheaddisplay == 1} {
	  	    	    putquick "privmsg $triviachannel :The player behind you is $nextrankplayer!"
	  	   }
	  	   if {$playeraheaddisplay == 2} {
	   	    putquick "notice $lastwinner :The player behind you is $nextrankplayer!"
	   }
	  
	  
	 }
	}
}
######################################################
	set f [open "GenericScoresTEXT/ThisYear.txt" w]
	set totalplayers 0
	set totalpoints 0
	foreach s [lsort -decreasing -command sort_yearscore [array names yearscore]] {
		if {$yearscore($s) != 0} {
		puts $f "$s $yearscore($s)"
		incr totalplayers
		incr totalpoints $yearscore($s)
		}
	}
	close $f

	if {$webscore != ""} {
		set f [open $webscore w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Yearly trivia scores as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_yearscore [array names yearscore]] {
		if {$yearscore($s) != 0} {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$yearscore($s)</TD></TR>"
	}
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################
		set f [open $yearhtmlfilename w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Yearly trivia scores as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalpoints points given during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_yearscore [array names yearscore]] {
		if {$yearscore($s) != 0} {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$yearscore($s)</TD></TR>"
	}
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################

	}
return 1
}
##
## Display Top 10 Scores For A Year To A Player
proc YearlyTop10 {nick uhost hand chan args} {
global antifloodenable usercounter commandusers alreadygoing question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed yearfilename datechecker triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
regsub -all \[{}] $args "" args
 if {[string length $args] == 0} {
  putquick "NOTICE $nick :(If you wish to view a different year's score, use the form '!yeartop10 YEAR' (!yeartop10 1999 for example...it MUST be a 4 digit year!)"
  set dater [unixtime]
  set datechecker [ctime $dater]
  set yearfilename "TriviaYearlyScores/"
  set datedesired ""
  append yearfilename [lindex $datechecker 4]
  append datedesired [lindex $datechecker 4]
  append yearfilename ".txt"
 }
 if {[string length $args] > 0} {
  set counter 0
  set yearfilename "TriviaYearlyScores/"
  set datedesired ""
  while {[lindex $args $counter] != ""} {
   append yearfilename [lindex $args $counter]
   append datedesired [lindex $args $counter]
   append datedesired " "
   incr counter
  }
  append yearfilename ".txt"
 }
 if {![file exist $yearfilename]} {
  putquick "NOTICE $nick :Sorry $nick, but I can't find a top 10 score for $datedesired...8("
  return 1
 }
 putquick "NOTICE $nick :Top 10 Trivia Scores For The Year $datedesired:"
		set winners ""
		set f [open $yearfilename r]
		for { set s 0 } { $s < 10 } { incr s } {
			gets $f tally
			set placement [expr $s +1]
			if {$placement == 1} {set placement " 1st Place: "
				set headhoncho [lindex $tally 0]
			}
			if {$placement == 2} {set placement " 2nd Place: "}
			if {$placement == 3} {set placement " 3rd Place: "}
			if {$placement == 4} {set placement " 4th Place: "}
			if {$placement == 5} {set placement " 5th Place: "}
			if {$placement == 6} {set placement " 6th Place: "}
			if {$placement == 7} {set placement " 7th Place: "}
			if {$placement == 8} {set placement " 8th Place: "}
			if {$placement == 9} {set placement " 9th Place: "}
			if {$placement == 10} {set placement " 10th Place: "}
			append winners $placement
			append winners [lindex $tally 0]
			append winners " with "
			append winners [lindex $tally 1]
			if {[lindex $tally 1] > 1} {
				append winners " points! "
			} else {
				append winners " point! "
			}
		}
		putquick "NOTICE $nick :$winners"
		putquick "NOTICE $nick :Congratulations To $headhoncho for wearing their thinking cap the most! 8)"
		close $f
		return
}

proc RemoteQuestionEditor {nick uhost hand args} {
global ownerhost editvalidhosts qtotal antifloodenable usercounter commandusers nameofbot qafile triviaowner editopallowed editvalidusers triviachannel
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$editopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $editvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $editvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################


	regsub -nocase -all \[{}] $args "" args
	if {[string length $args] == 0} {
 	 putquick "NOTICE $nick :Usage: /msg BOTNICK edit QUESTIONNUMBER NEWQUESTION*NEWANSWER ('/msg BOTNICK edit 2000 What color is the sky*blue')"
	 return
	} {

	if {[lindex $args 1] < 1} {
 	 putquick "NOTICE $nick :Usage: /msg BOTNICK edit QUESTIONNUMBER NEWQUESTION*NEWANSWER ('/msg BOTNICK edit 2000 What color is the sky*blue')"
	 return
	}
	if {[lindex $args 2] < 1} {
 	 putquick "NOTICE $nick :Usage: /msg BOTNICK edit QUESTIONNUMBER NEWQUESTION*NEWANSWER ('/msg BOTNICK edit 2000 What color is the sky*blue')"
	 return
	}
if {[lindex $args 0] > $qtotal} {
putquick "NOTICE $nick :Sorry $nick, but there's no such question...please try again!"
return
}
set editfile "TriviaEditedQuestions.txt"
if {![file exist $editfile]} {
 	 set f [open $editfile w]
	  close $f
}
set logfile "TriviaEditedQuestions.log"
if {![file exist $logfile]} {
 	 set f [open $logfile w]
	  close $f
}

## Find Out How Many Questions There Are!
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
 if {[lindex $line 0] == "TotalTrivia"} {
  set etotal [lindex $line 1]
 }
}
close $g

 if {[lindex $args 0] > $etotal} {
  putquick "NOTICE $nick :Sorry $nick, but there's no such question to edit...please try again!"
  return
 }
 set f [open "TriviaBankTotals.txt" r]
 set qdone 0
 set convertednum 0
 set eqbank ""
 set numleft [lindex $args 0]
 while {$qdone != 1} {
  gets $f line
  set eqbank [lindex $line 0]
  if {[lindex $line 1] >= $numleft} {
   set eqbank [lindex $line 0]
   set qdone 1
  }
  if {$qdone == 0} {
    set numleft [expr $numleft - [lindex $line 1]]
  }
 }
 close $f

###

set f [open $editfile r]
while {[gets $f line] != -1} {
 if {[lindex $line 0] == $eqbank} {
  if {[lindex $line 1] == $numleft} {
  	 putquick "NOTICE $nick :This question has already been edited...if it is still posing a problem please inform my triviaowner! Thanks! 8)"
	 return
  }
 }
}
close $f

     set qaline [lrange $args 1 end]
 	 set f [open $editfile a]
 	  puts $f "$eqbank $numleft $qaline"
	  close $f
 	 set f [open $logfile a]
 	  puts $f "$nick:    $eqbank, $numleft: $qaline!"
 	  putquick "NOTICE $nick :Thanks for your edit $nick! 8)"
	  close $f
 	  return
}
}


proc RemoteQuestionDeleter {nick uhost hand args} {
global ownerhost deletevalidhosts qtotal antifloodenable usercounter commandusers nameofbot qafile triviaowner triviachannel deleteopallowed deletevalidusers
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$deleteopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $deletevalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $deletevalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################


	regsub -nocase -all \[{}] $args "" args
	if {[string length $args] == 0} {
 	 putquick "NOTICE $nick :Usage: /msg BOTNICK delete QUESTION NUMBER (/msg BOTNICK delete 2000)"
	 return
	}
if {[lindex $args 0] > $qtotal} {
putquick "NOTICE $nick :Sorry $nick, but there's no such question...please try again!"
return
}

set editfile "TriviabotErroredQuestions.txt"
if {![file exist $editfile]} {
 	 set f [open $editfile w]
	  close $f
}

set logfile "TriviabotDeletedQuestions.log"
if {![file exist $logfile]} {
 	 set f [open $logfile w]
	  close $f
}

###
## Find Out How Many Questions There Are!
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
 if {[lindex $line 0] == "TotalTrivia"} {
  set etotal [lindex $line 1]
 }
}
close $g

 if {[lindex $args 0] > $etotal} {
  putquick "NOTICE $nick :Sorry $nick, but there's no such question...please try again!"
  return
 }
 set f [open "TriviaBankTotals.txt" r]
 set qdone 0
 set convertednum 0
 set eqbank ""
 set numleft [lindex $args 0]
 while {$qdone != 1} {
  gets $f line
  set eqbank [lindex $line 0]
  if {[lindex $line 1] >= $numleft} {
   set eqbank [lindex $line 0]
   set qdone 1
  }
  if {$qdone == 0} {
    set numleft [expr $numleft - [lindex $line 1]]
  }
 }
 close $f

###

set f [open $editfile r]
while {[gets $f line] != -1} {
 if {[lindex $line 0] == $eqbank} {
  if {[lindex $line 1] == $numleft} {
  	 putquick "NOTICE $nick :This question has already been deleted...if it is still posing a problem please inform my triviaowner! Thanks! 8)"
	 return
  }
 }
}
close $f


 	 set f [open $editfile a]
 	  puts $f "$eqbank $numleft"
	  close $f
 	 set f [open $logfile a]
 	  puts $f "$nick:    $eqbank, $numleft"
 	  putquick "NOTICE $nick :Thanks for your deletion $nick! 8)"
	  close $f
 	  return
}


## Fastest Answer Routines

## Read Current Scorefile
proc read_fastanswers { } {
	global fastanswerqty fastanswerscore triviachannel fastanswerfilename fastanswerhtmlfilename triviaowner

if {![file exist "GenericScoresTEXT/FastestPlayers.txt"]} {
  set g [open "GenericScoresTEXT/FastestPlayers.txt" w]
  puts $g "$triviaowner 60 0"
  close $g
 }
	set f [open "GenericScoresTEXT/FastestPlayers.txt" r]
	while {[gets $f s] != -1} {
regsub -all \[{}] $s "" s
		set fastanswerscore([lindex $s 0]) [lindex $s 1]
		set fastanswerqty([lindex $s 0]) [lindex $s 2]
	}
	close $f
return 1
}
##

## Fastest Player Sorting Routines

proc sort_fastanswerscore {s1 s2} {
	global fastanswerscore
	if {$fastanswerscore($s1) > $fastanswerscore($s2)} { return 1 }
	if {$fastanswerscore($s1) < $fastanswerscore($s2)} { return -1 }
	if {$fastanswerscore($s1) == $fastanswerscore($s2)} { return 0 }
}
##

## Write Score File And Web Page Version Of Fastest Player Files

proc write_fastanswers { } {
	global fastanswerqty fastanswerscore fastanswerfilename fastanswerhtmlfilename triviaowner triviachannel

	set f [open "GenericScoresTEXT/FastestPlayers.txt" w]
	set totalplayers 0
	foreach s [lsort -increasing -command sort_fastanswerscore [array names fastanswerscore]] {
		puts $f "$s $fastanswerscore($s) $fastanswerqty($s)"
		incr totalplayers
	}
	close $f
	set webscore "GenericScoresHTML/FastestPlayers.html"
	if {$webscore != ""} {
		set f [open $webscore w]

####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Fastest trivia players as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
		puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Seconds</TD><TD>Times Matched</TD></TR>"
foreach s [lsort -increasing -command sort_fastanswerscore [array names fastanswerscore]] {
			puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$fastanswerscore($s)</TD><TD>$fastanswerqty($s)</TD></TR>"
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################
	}
return 1
}
##

## Display Top 10 Scores For A Year To A Player
proc Top10FastAnswers {nick uhost hand chan args} {
global antifloodenable usercounter commandusers alreadygoing question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed yearfilename datechecker triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
  foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
if ![file exists "GenericScoresTEXT/FastestPlayers.txt"] {
		set f [open "GenericScoresTEXT/FastestPlayers.txt" w]
 		close $f
}
set fastanswerfilename "GenericScoresTEXT/FastestPlayers.txt"
 putquick "NOTICE $nick :Top 10 Fastest Trivia Players So Far:"
		set winners ""
		set f [open "GenericScoresTEXT/FastestPlayers.txt" r]
		for { set s 0 } { $s < 10 } { incr s } {
			gets $f tally
			set placement [expr $s +1]
			if {$placement == 1} {set placement " 1st Place: "
				set headhoncho [lindex $tally 0]
			}
			if {$placement == 2} {set placement " 2nd Place: "}
			if {$placement == 3} {set placement " 3rd Place: "}
			if {$placement == 4} {set placement " 4th Place: "}
			if {$placement == 5} {set placement " 5th Place: "}
			if {$placement == 6} {set placement " 6th Place: "}
			if {$placement == 7} {set placement " 7th Place: "}
			if {$placement == 8} {set placement " 8th Place: "}
			if {$placement == 9} {set placement " 9th Place: "}
			if {$placement == 10} {set placement " 10th Place: "}
			append winners $placement
			append winners [lindex $tally 0]
			append winners " at "
			append winners [lindex $tally 1]
			if {[lindex $tally 1] > 1} {
				append winners " seconds! "
			} else {
				append winners " second! "
			}
			if {[lindex $tally 2] != ""} {
			 if {[lindex $tally 2] > 1} {
			  append winners "([lindex $tally 2] times)"
			 }
			}
		}
		putquick "NOTICE $nick :$winners"
		putquick "NOTICE $nick :Congratulations To $headhoncho For Having The Fastest Fingers So Far! 8)"
		close $f
		return
}

## Winning Streak Routines

## Read Current Scorefile
proc read_streak { } {
	global streakscore triviachannel streakfilename streakhtmlfilename triviaowner

if {![file exist "GenericScoresTEXT/TopStreakers.txt"]} {
  set g [open "GenericScoresTEXT/TopStreakers.txt" w]
  puts $g "$triviaowner 0"
  close $g
 }
	set f [open "GenericScoresTEXT/TopStreakers.txt" r]
	while {[gets $f s] != -1} {
regsub -all \[{}] $s "" s
		set streakscore([lindex $s 0]) [lindex $s 1]
	}
	close $f
return 1
}
##

## Winning Streak Sorting Routines

proc sort_streak {s1 s2} {
	global streakscore
	if {$streakscore($s1) > $streakscore($s2)} { return 1 }
	if {$streakscore($s1) < $streakscore($s2)} { return -1 }
	if {$streakscore($s1) == $streakscore($s2)} { return 0 }
}
##

## Write Score File And Web Page Version Of Winning Streak Files!
proc write_streak { } {
	global streakscore streakfilename streakhtmlfilename triviaowner triviachannel

	set f [open "GenericScoresTEXT/TopStreakers.txt" w]
	set totalplayers 0
	foreach s [lsort -decreasing -command sort_streak [array names streakscore]] {
		puts $f "$s $streakscore($s)"
		incr totalplayers
	}
	close $f
	set webscore "GenericScoresHTML/TopStreakers.html"
	if {$webscore != ""} {
		set f [open $webscore w]
####################### NEW WEBPAGE TEST CODE
puts $f "<HTML>"
puts $f "<HEAD>"
puts $f "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $f "</HEAD>"
puts $f "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $f "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Top trivia winning streaks as of: [clock format [clock seconds] -format {%c %Z}]"
puts $f "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $f "</B></FONT></CENTER><P>"
puts $f "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $f "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $f "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Score</TD></TR>"
foreach s [lsort -decreasing -command sort_streak [array names streakscore]] {
 puts $f "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$streakscore($s)</TD></TR>"
}
puts $f "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $f "</BODY></HTML>"
close $f
########################
	}
return 1
}
##

## Display Top 10 Streakers To A Player
proc Top10Streakers {nick uhost hand chan args} {
global antifloodenable usercounter commandusers alreadygoing question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed yearfilename datechecker triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
if ![file exists "GenericScoresTEXT/TopStreakers.txt"] {
		set f [open "GenericScoresTEXT/TopStreakers.txt" w]
		puts $f "$triviaowner 0"
 		close $f
}
 set fastanswerfilename "GenericScoresTEXT/TopStreakers.txt"
 putquick "NOTICE $nick :Top 10 Highest Winning Streaks So Far:"
		set winners ""
		set f [open "GenericScoresTEXT/TopStreakers.txt" r]
		for { set s 0 } { $s < 10 } { incr s } {
			gets $f tally
			set placement [expr $s +1]
			if {$placement == 1} {set placement " 1st Place: "
				set headhoncho [lindex $tally 0]
			}
			if {$placement == 2} {set placement " 2nd Place: "}
			if {$placement == 3} {set placement " 3rd Place: "}
			if {$placement == 4} {set placement " 4th Place: "}
			if {$placement == 5} {set placement " 5th Place: "}
			if {$placement == 6} {set placement " 6th Place: "}
			if {$placement == 7} {set placement " 7th Place: "}
			if {$placement == 8} {set placement " 8th Place: "}
			if {$placement == 9} {set placement " 9th Place: "}
			if {$placement == 10} {set placement " 10th Place: "}
			append winners $placement
			append winners [lindex $tally 0]
			append winners " with "
			append winners [lindex $tally 1]
			if {[lindex $tally 1] > 1} {
				append winners " in a row! "
			}
		}
		putquick "NOTICE $nick :$winners"
		putquick "NOTICE $nick :Congratulations To $headhoncho For Having The Highest Winning Streak So Far! 8)"
		close $f
		return
}

proc clearfast {} {
 global fastclear triviachannel triviaowner fastanswerscore
if ![file exists "GenericScoresTEXT/FastestPlayers.txt"] {
		set f [open "GenericScoresTEXT/FastestPlayers.txt" w]
		puts $f "$triviaowner 60 0"
 		close $f
}
set f [open "GenericScoresTEXT/FastestPlayers.txt" r]
set backupfile "GenericScoresTEXT/FastestPlayers"
set backupwebname "GenericScoresHTML/FastestPlayers"
if {$fastclear == 0} {set backupname "Yesterday"}
if {$fastclear == 1} {set backupname "LastWeek"}
if {$fastclear == 2} {set backupname "LastMonth"}
if {$fastclear == 3} {set backupname "LastYear"}
append backupfile $backupname
append backupwebname $backupname
append backupfile ".txt"
append backupwebname ".html"
set g [open $backupfile w]
set totalplayers 0
while {[gets $f line] != -1} {
 puts $g $line
 incr totalplayers
}
close $g
close $f
set f [open "GenericScoresTEXT/FastestPlayers.txt" r]
set g [open $backupwebname w]
####################### NEW WEBPAGE TEST CODE
puts $g "<HTML>"
puts $g "<HEAD>"
puts $g "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $g "</HEAD>"
puts $g "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $g "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $g "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Fastest trivia players from $backupname"
puts $g "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $g "</B></FONT></CENTER><P>"
puts $g "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $g "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $g "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Seconds</TD><TD>Times Matched</TD></TR>"
while {[gets $f line] != -1} {
set s [lindex $line 0]
set fastscore [lindex $line 1]
set matchtimes [lindex $line 2]
puts $g "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$fastscore</TD><TD>$matchtimes</TD></TR>"
}
puts $g "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $g "</BODY></HTML>"
close $g
########################
close $f
set f [open "GenericScoresTEXT/FastestPlayers.txt" w]
 puts $f "$triviaowner 60 0"
 close $f
 if [info exists streakscore] { unset streakscore }
 putquick "privmsg $triviachannel :The Fastest Player Records Have Been Reset! Good Luck Everybody!"
 return 1
}

proc clearstreak {} {
 global streakclear triviachannel triviaowner streakscore
if ![file exists "GenericScoresTEXT/TopStreakers.txt"] {
		set f [open "GenericScoresTEXT/TopStreakers.txt" w]
		puts $f "$triviaowner 0"
 		close $f
}
set f [open "GenericScoresTEXT/TopStreakers.txt" r]
set backupfile "GenericScoresTEXT/TopStreakers"
set backupwebname "GenericScoresHTML/"
if {$streakclear == 0} {set backupname "Yesterday"}
if {$streakclear == 1} {set backupname "LastWeek"}
if {$streakclear == 2} {set backupname "LastMonth"}
if {$streakclear == 3} {set backupname "LastYear"}
append backupfile $backupname
append backupwebname $backupname
append backupfile ".txt"
append backupweb ".html"
set g [open $backupfile w]
set totalplayers 0
while {[gets $f line] != -1} {
 puts $g $line
 incr totalplayers
}
close $g
close $f
set f [open "GenericScoresTEXT/TopStreakers.txt" r]
set g [open $backupwebname w]
####################### NEW WEBPAGE TEST CODE
puts $g "<HTML>"
puts $g "<HEAD>"
puts $g "<TITLE>This Scorefile Was Made By Nerfbendr's Triviabot!</TITLE>"
puts $g "</HEAD>"
puts $g "<BODY BGCOLOR='#850044' TEXT='#000000'>"
puts $g "<CENTER><WIDTH='100%' SIZE='3'></CENTER><P>"
puts $g "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>Highest trivia winning streaks from $backupname"
puts $g "<CENTER><FONT FACE='Times New Roman' SIZE='4' COLOR='#000000'><B>(There were $totalplayers players during this period!)"
puts $g "</B></FONT></CENTER><P>"
puts $g "<CENTER><HR WIDTH='100%' SIZE='3'></CENTER><P>"
puts $g "<CENTER><TABLE BORDER=4 WIDTH=80%>"
puts $g "<TR ALIGN=center><TH ALIGN=center>Nick</TH><TD>Winning Streak</TD></TR>"
while {[gets $f line] != -1} {
set s [lindex $line 0]
set streak [lindex $line 1]
puts $g "<TR ALIGN=center><TH ALIGN=center>$s</TH><TD>$streak</TD></TR>"
}
puts $g "</TABLE></CENTER>"
puts $f "<style> BODY {SCROLLBAR-FACE-COLOR: #850044; SCROLLBAR-ARROW-COLOR:  #ffffff; SCROLLBAR-TRACK-COLOR: #000000; } </style>"
puts $g "</BODY></HTML>"
close $g
########################
close $f
set f [open "GenericScoresTEXT/TopStreakers.txt" w]
 puts $f "$triviaowner 0"
 close $f
 if [info exists streakscore] { unset streakscore }
 putquick "privmsg $triviachannel :The Winning Streak Records Have Been Reset! Good Luck Everybody!"
 return 1
}

proc clearvoices {} {
 global triviachannel triviaowner
 set f [open "TriviaVoicedUsers.txt" w]
 puts $f "$triviaowner"
 close $f
 putquick "privmsg $triviachannel :The Autovoiced Player Records Have Been reset! Good Luck Everybody!"
 return 1
}

proc LastAnswerproc {nick uhost hand chan args} {
global nontriviapiracyvariable PAText PABackground nontriviapiracy antifloodenable usercounter alreadygoing lastanswerenable triviachannel LastAnswer
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
 if {$alreadygoing == 0} {
  putquick "privmsg $triviachannel: Sorry $nick, but Trivia's not running at the moment...type '!trivia' to play!"
  return
 }
if {$lastanswerenable == 1} {
## Insert Hint Anti-Piracy Code Here!!!
set LastAnswerToDisplay "$PAText $LastAnswer"
 if {$nontriviapiracy == 1} {
 set letters "fijlt"
 set antipiracy ""
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PAText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PAText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PABackground
}
append antipiracy "$restorecode "
##
 set counter 0
 set flipper 0
 set endofqflag 0
 while {[lindex $LastAnswer $counter] != "" } {
  set numberflag 0
  set numberchecker [lindex $LastAnswer [expr $counter +1]]
  if {[lindex $LastAnswer [expr $counter +1]] == ""} {set endofqflag 1}
  set testforanumber 0
  while {$testforanumber <= 9} {
   if {[string range $numberchecker 0 0] == $testforanumber} {
    set numberflag 1
   }
   incr testforanumber
  }
  if {$endofqflag == 1} {
   append antipiracy [lindex $LastAnswer $counter]
   set numberflag 10
   set flipper 10
  }
  if {$flipper == 0} {
   set antipiracyletter [string index $letters [rand [string length $letters]]]
   append antipiracy [lindex $LastAnswer $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $PABackground
}
append embedcode ","
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $PABackground
}
append antipiracy $embedcode
##
   if {$numberflag == 0} {
    append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PAText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PAText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PABackground
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PAText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PAText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PABackground
}
append antipiracy "$restorecode "
##
   }
   set flipper 1
  } {
   if {$flipper != 10} {
    set antipiracyletter " "
    append antipiracy [lindex $LastAnswer $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $PABackground
}
append embedcode ","
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $PABackground
}
append antipiracy $embedcode
##
   }
   if {$numberflag == 0} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PAText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PAText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PABackground
}
append antipiracy $restorecode
##

append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PAText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PAText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PABackground
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PAText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PAText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($PABackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $PABackground
}
append antipiracy "$restorecode "
##
   }
   set flipper 0
  }
  incr counter
 }
 set qlength [string length $antipiracy]
 set LastAnswerToDisplay $antipiracy
}
 putquick "privmsg $triviachannel :8,$PABackground The last answer was:$LastAnswerToDisplay!"
}
return
}

proc ReCount {nick uhost hand chan args} {
global answer hint question triviastoppedflag alreadygoing scramblebanks ownerhost recountvalidhosts usercounter validbanks qtotal triviaowner recountopallowed recountvalidusers antifloodenable triviachannel nameofbot


if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$recountopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $recountvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $recountvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}

 set qtotal 0
 set qindex 0
set g [open "TriviaBankTotals.txt" w]
close $g

  set g [open "TriviabotFlaggedQuestions.txt" w]
  close $g
  set g [open "TriviabotFlaggedQuestions.log" w]
  close $g


set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Hanging* [lindex $t 1]] {
		        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
  
  
  ######### NEW FOR V6.5: AUTO-FLAG TRIVIA WITH NO Q OR A AS BAD! ########
   set marker "*"
  set badq 0
  set isitgood [string first $marker $line]
  if {$isitgood == -1} {set badq 1}
  
  if {$badq == 0} {
  set marker "*"
  set qamarker [string first $marker $line]
  set answerstartmarker [expr $qamarker + 1]
  set questionendmarker [expr $qamarker - 1]
  set question [string range $line 0 $questionendmarker]
  set answer [string range $line $answerstartmarker end]
  
  if {[string length $question] < 1} {set badq 1}
  if {[string length $answer] < 1} {set badq 1}
  
  }
  if {$badq == 1} {
   set g [open "TriviabotFlaggedQuestions.txt" a]
   puts $g "$qbanktoopen $qafilelength"
   close $g
  
   set g [open "TriviabotFlaggedQuestions.log" a]
   puts $g "Triviabot reported this error: $qbanktoopen, Question: [expr $qafilelength +1]!"
   close $g
  }
    ####### END NEW FOR V6.5: AUTO-FLAG TRIVIA WITH NO Q OR A AS BAD! ######

   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

####### V6.0 CODE: ADDS TRIVIABANK TOTALS FROM SCRAMBLE BANKS TO TOTALS! ##
 set qindex 0
 while {[llength $scramblebanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $scramblebanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Hanging* [lindex $t 1]] {
		        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

###########################################################################

set g [open "TriviaBankTotals.txt" a]
puts $g "TotalTrivia $qtotal"
close $g
### Check to see if trivia total == 0, if so then recount it!
## Get total Trivia Amount
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
if {[lindex $line 0] == "TotalTrivia"} {
set qtotal [lindex $line 1]
}
}
close $g
##
if {$qtotal < 1} {
putquick "privmsg $triviachannel : ***WARNING*** 0 or less questions exist! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** 0 or less questions exist! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 	set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Hanging* [lindex $t 1]] {
		        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
##################################
 set qtotal 0
 set qindex 0
set g [open "TriviaBankTotals.txt" w]
close $g
set banksnotfound ""
 while {[llength $validbanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $validbanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
  ######### NEW FOR V6.5: AUTO-FLAG TRIVIA WITH NO Q OR A AS BAD! ########
   set marker "*"
  set badq 0
  set isitgood [string first $marker $line]
  if {$isitgood == -1} {set badq 1}
  
  if {$badq == 0} {
  set marker "*"
  set qamarker [string first $marker $line]
  set answerstartmarker [expr $qamarker + 1]
  set questionendmarker [expr $qamarker - 1]
  set question [string range $line 0 $questionendmarker]
  set answer [string range $line $answerstartmarker end]
  
  if {[string length $question] < 1} {set badq 1}
  if {[string length $answer] < 1} {set badq 1}
  
  }
  if {$badq == 1} {
   set g [open "TriviabotFlaggedQuestions.txt" a]
   puts $g "$qbanktoopen $qafilelength"
   close $g
  
   set g [open "TriviabotFlaggedQuestions.log" a]
   puts $g "Triviabot reported this error: $qbanktoopen, Question: [expr $qafilelength +1]!"
   close $g
  }
    ####### END NEW FOR V6.5: AUTO-FLAG TRIVIA WITH NO Q OR A AS BAD! ######
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

####### V6.0 CODE: ADDS TRIVIABANK TOTALS FROM SCRAMBLE BANKS TO TOTALS! ##
 set qindex 0
 while {[llength $scramblebanks] > $qindex} {
  set qafilelength 0
  set qbanktoopen "TriviaBanks/"
  append qbanktoopen [lindex $scramblebanks $qindex]
  if ![file exists $qbanktoopen] {
putquick "privmsg $triviachannel : ***WARNING***  Unable to find the following trivia bank: $qbanktoopen! Please inform $triviaowner! They will need to check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
 putquick "privmsg $triviaowner : ***WARNING*** Unable to find the following trivia bank: $qbanktoopen! Please check to ensure the trivia banks are entered properly in the trivia config file (both for trivia and scramble banks) and exist in the 'TriviaBanks' directory too and then use the recount command...CaPiTaLs count in filenames! ;)"
set f [open "TriviaBankTotals.txt" w]
 close $f
 set qtotal 0
 set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	utimer 10 "Advertiser"

   return 
  }
  set f [open $qbanktoopen r]
  while {[gets $f line] != -1} {
   incr qafilelength
  }
  close $f
  set qafilelength [expr $qafilelength -1]
set g [open "TriviaBankTotals.txt" a]
puts $g "$qbanktoopen $qafilelength"
close $g
  set qtotal [expr $qtotal + $qafilelength]
  incr qindex
}

###########################################################################

set g [open "TriviaBankTotals.txt" a]
puts $g "TotalTrivia $qtotal"
close $g
##################################
utimer 10 "Advertiser"
	return 1
}
###
putquick "NOTICE $nick :Recount completed...you have a grand total of $qtotal questions! Enjoy! 8)"
return
}

###########
proc ErroredQuestions {nick uhost hand chan args} {
 global randommode qtotal antifloodenable nameofbot qafile usercounter commandusers triviachannel
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
 if {$antifloodenable == 1} {
  foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
  }
  set commandusers($usercounter) "$nick $uhost"
 }
 regsub -nocase -all \[{}] $args "" args
 if {[string length $args] == 0} {
  putquick "NOTICE $nick :Usage: !error QUESTION NUMBER (Example: '!error 2000')"
  return
 }
 if {![file exist "TriviabotErroredQuestions.txt" ]} {
  set f [open "TriviabotErroredQuestions.txt" w]
  close $f
 }
if {![file exist "TriviabotErroredQuestions.log" ]} {
  set f [open "TriviabotErroredQuestions.log" w]
  close $f
 }

## Find Out How Many Questions There Are!
set g [open "TriviaBankTotals.txt" r]
while {[gets $g line] != -1} {
 if {[lindex $line 0] == "TotalTrivia"} {
  set etotal [lindex $line 1]
 }
}
close $g
 set args [lindex $args 0]
 if {$args > $etotal} {
  putquick "NOTICE $nick :Sorry $nick, but there's no such question..."
  return
 }
 set f [open "TriviaBankTotals.txt" r]
 set qdone 0
 set convertednum 0
 set eqbank ""
 set numleft $args
 while {$qdone != 1} {
  gets $f line
  set eqbank [lindex $line 0]
  if {[lindex $line 1] >= $numleft} {
   set eqbank [lindex $line 0]
   set qdone 1
  }
  if {$qdone == 0} {
    set numleft [expr $numleft - [lindex $line 1]]
  }
 }
 close $f
 set f [open "TriviabotErroredQuestions.txt" a]
 puts $f "$eqbank $numleft"
 close $f

 set f [open "TriviabotErroredQuestions.log" a]
 puts $f "$nick reported this error: $eqbank, Question: $numleft!"
 putquick "NOTICE $nick :Thanks for your insights $nick! We'll check it out asap! 8)"
 close $f
 return
}
###########
###########

proc SpecificPlayerRank {nick uhost hand chan args} {
global yearscore nickyearranks antifloodenable usercounter commandusers streakscore streakfilename streakhtmlfilename fastanswerfilename dayfilename weekfilename monthfilename alreadygoing yearfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable hintalreadygiven
if {[string tolower $chan] != [string tolower $triviachannel]} {return}

if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
if {$alreadygoing == 0} {
	putquick "privmsg $triviachannel :4Due to the way the Triviabot handles all stats, this command is only available when Trivia is running...sorry! 8("
 	return 1
}

regsub -all \[{}] $args "" args
set scoreplayer $args
if {[string length $args] == 0} {set scoreplayer $nick}
set nicktodisplay $scoreplayer
regsub -all \[{}] $scoreplayer "~" scoreplayer
		set foundflag 0
		set daypoints ""
		set f [open $dayfilename r]
		set dayplayers 0
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			incr dayplayers
			if {$checker == $scoreplayer} {

set dayplayerss $dayplayers

set foundit 0
if {[string range $dayplayers [expr [string length $dayplayers] -2] end] == "11"} {
append dayplayerss "th"
set foundit 1
}
if {[string range $dayplayers [expr [string length $dayplayers] -2] end] == "12"} {
append dayplayerss "th"
set foundit 1
}
if {[string range $dayplayers [expr [string length $dayplayers] -2] end] == "13"} {
append dayplayerss "th"
set foundit 1
}

if {$foundit == 0} {
 if {[string range $dayplayers end end] == "0"} {append dayplayerss "th"}
 if {[string range $dayplayers end end] == "1"} {append dayplayerss "st"}
 if {[string range $dayplayers end end] == "2"} {append dayplayerss "nd"}
 if {[string range $dayplayers end end] == "3"} {append dayplayerss "rd"}
 if {[string range $dayplayers end end] > 3} {append dayplayerss "th"}
}


				set daypoints "3 $dayplayerss 6"
				set foundflag 1
			}
		}
		close $f
		if {$foundflag == 0} {set daypoints "4 0 6"}

		set foundflag 0


		set weekpoints ""
		set f [open $weekfilename r]
		set weekplayers 0
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			incr weekplayers
			if {$checker == $scoreplayer} {

set weekplayerss $weekplayers

set foundit 0
if {[string range $weekplayers [expr [string length $weekplayers] -2] end] == "11"} {
append weekplayerss "th"
set foundit 1
}
if {[string range $weekplayers [expr [string length $weekplayers] -2] end] == "12"} {
append weekplayerss "th"
set foundit 1
}
if {[string range $weekplayers [expr [string length $weekplayers] -2] end] == "13"} {
append weekplayerss "th"
set foundit 1
}

if {$foundit == 0} {
 if {[string range $weekplayers end end] == "0"} {append weekplayerss "th"}
 if {[string range $weekplayers end end] == "1"} {append weekplayerss "st"}
 if {[string range $weekplayers end end] == "2"} {append weekplayerss "nd"}
 if {[string range $weekplayers end end] == "3"} {append weekplayerss "rd"}
 if {[string range $weekplayers end end] > 3} {append weekplayerss "th"}
}

				set weekpoints "3 $weekplayerss 6"
				set foundflag 1
			}
		}
		close $f
		if {$foundflag == 0} {set weekpoints "4 0 6"}

		set foundflag 0


		set monthpoints ""
		set f [open $monthfilename r]
		set monthplayers 0
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			incr monthplayers
			if {$checker == $scoreplayer} {

set monthplayerss $monthplayers

set foundit 0
if {[string range $monthplayers [expr [string length $monthplayers] -2] end] == "11"} {
append monthplayerss "th"
set foundit 1
}
if {[string range $monthplayers [expr [string length $monthplayers] -2] end] == "12"} {
append monthplayerss "th"
set foundit 1
}
if {[string range $monthplayers [expr [string length $monthplayers] -2] end] == "13"} {
append monthplayerss "th"
set foundit 1
}

if {$foundit == 0} {
 if {[string range $monthplayers end end] == "0"} {append monthplayerss "th"}
 if {[string range $monthplayers end end] == "1"} {append monthplayerss "st"}
 if {[string range $monthplayers end end] == "2"} {append monthplayerss "nd"}
 if {[string range $monthplayers end end] == "3"} {append monthplayerss "rd"}
 if {[string range $monthplayers end end] > 3} {append monthplayerss "th"}
}


				set monthpoints "3 $monthplayerss 6"
				set foundflag 1
			}
		}
		close $f
		if {$foundflag == 0} {set monthpoints "4 0 6"}

		set foundflag 0


		set yearpoints ""
		set f [open $yearfilename r]
		set yearplayers 0
		while {[gets $f tally] != -1} {
			set checker [lindex $tally 0]
			incr yearplayers
			if {$checker == $scoreplayer} {

set yearplayerss $yearplayers


set foundit 0
if {[string range $yearplayers [expr [string length $yearplayers] -2] end] == "11"} {
append yearplayerss "th"
set foundit 1
}
if {[string range $yearplayers [expr [string length $yearplayers] -2] end] == "12"} {
append yearplayerss "th"
set foundit 1
}
if {[string range $yearplayers [expr [string length $yearplayers] -2] end] == "13"} {
append yearplayerss "th"
set foundit 1
}

if {$foundit == 0} {
 if {[string range $yearplayers end end] == "0"} {append yearplayerss "th"}
 if {[string range $yearplayers end end] == "1"} {append yearplayerss "st"}
 if {[string range $yearplayers end end] == "2"} {append yearplayerss "nd"}
 if {[string range $yearplayers end end] == "3"} {append yearplayerss "rd"}
 if {[string range $yearplayers end end] > 3} {append yearplayerss "th"}
}

				set yearpoints "3 $yearplayerss 6"
				set foundflag 1
			}
		}
		close $f
		if {$foundflag == 0} {set yearpoints "4 0 6"}

		set foundflag 0

putquick "privmsg $triviachannel :6 $nicktodisplay is currently$daypoints6out of3 $dayplayers6 daily players,3$weekpoints6out of3 $weekplayers 6weekly players,3$monthpoints6out of3 $monthplayers 6monthly players and3$yearpoints6out of3 $yearplayers 6yearly players!"
}

##


proc Autoftpsend {nick uhost hand args} {
global usercounter nameofbot triviachannel antifloodenable commandusers ownerhost dayfilename dayhtmlfilename weekfilename weekhtmlfilename monthfilename monthhtmlfilename yearfilename yearhtmlfilename autoftpenable updateopallowed updatevalidusers updatevalidhosts ftpaddress ftpport ftplogin ftppass ftpdir ftpdelay
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$updateopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $updatevalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $updatevalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$nick == $nameofbot} {set allowedflag 1}
if {$allowedflag == 0} {return}
########################################################
if {$dayhtmlfilename == ""} {
 putquick "NOTICE $nick :Sorry $nick, but I have to have been running previously in order to know what changing day/week/month/year scores to upload...please type !trivia, then !trivquit and try again...thanks!"
 if {$autoftpenable == 1} {
  if {$nick == "blah"} {
   utimer $ftpdelay "Autoftpsend blah $ownerhost blah blah blah"
  }
 }
 return
}
## INSERT MAIN FTP CODE BELOW
### If args is 'all', upload all web and text scores to the website!

### ADD CODE TO DETERMINE IF A YEAR IS SPECIFIED AFTER 'ALL'...CURRENTLY USES CURRENT YEAR!
###
if {[string tolower $args] == "all"} {
 set pipe [open "|/usr/bin/ftp -n $ftpaddress" w]
 puts $pipe "user $ftplogin $ftppass"
 puts $pipe "bin"
 ##### FORCED-CODE FOR A FULL FTP UPDATE...IF NO YEAR IS GIVEN, ASSUME CURRENT YEAR!
 set dater [unixtime]
 set datechecker [ctime $dater]
 set yeartouse [lindex $datechecker 4]
 if [file exists "GenericScoresHTML/FastestPlayers.html"] {
  puts $pipe "put GenericScoresHTML/FastestPlayers.html $ftpdir/GenericScoresHTML/FastestPlayers.html"
 }
 if [file exists "GenericScoresHTML/LastMonth.html"] {
  puts $pipe "put GenericScoresHTML/LastMonth.html $ftpdir/GenericScoresHTML/LastMonth.html"
 }
if [file exists "GenericScoresHTML/LastWeek.html"] {
  puts $pipe "put GenericScoresHTML/LastWeek.html $ftpdir/GenericScoresHTML/LastWeek.html"
 }
if [file exists "GenericScoresHTML/LastYear.html"] {
  puts $pipe "put GenericScoresHTML/LastYear.html $ftpdir/GenericScoresHTML/LastYear.html"
 }
if [file exists "GenericScoresHTML/ThisMonth.html"] {
  puts $pipe "put GenericScoresHTML/ThisMonth.html $ftpdir/GenericScoresHTML/ThisMonth.html"
 }
if [file exists "GenericScoresHTML/ThisWeek.html"] {
  puts $pipe "put GenericScoresHTML/ThisWeek.html $ftpdir/GenericScoresHTML/ThisWeek.html"
 }
if [file exists "GenericScoresHTML/ThisYear.html"] {
  puts $pipe "put GenericScoresHTML/ThisYear.html $ftpdir/GenericScoresHTML/ThisYear.html"
 }
if [file exists "GenericScoresHTML/Today.html"] {
  puts $pipe "put GenericScoresHTML/Today.html $ftpdir/GenericScoresHTML/Today.html"
 }
if [file exists "GenericScoresHTML/TopStreakers.html"] {
  puts $pipe "put GenericScoresHTML/TopStreakers.html $ftpdir/GenericScoresHTML/TopStreakers.html"
 }
if [file exists "GenericScoresHTML/Yesterday.html"] {
  puts $pipe "put GenericScoresHTML/Yesterday.html $ftpdir/GenericScoresHTML/Yesterday.html"
 }

if [file exists "GenericScoresTEXT/FastestPlayers.txt"] {
  puts $pipe "put GenericScoresTEXT/FastestPlayers.txt $ftpdir/GenericScoresTEXT/FastestPlayers.txt"
 }
 if [file exists "GenericScoresTEXT/LastMonth.txt"] {
  puts $pipe "put GenericScoresTEXT/LastMonth.txt $ftpdir/GenericScoresTEXT/LastMonth.txt"
 }
if [file exists "GenericScoresTEXT/LastWeek.txt"] {
  puts $pipe "put GenericScoresTEXT/LastWeek.txt $ftpdir/GenericScoresTEXT/LastWeek.txt"
 }
if [file exists "GenericScoresTEXT/LastYear.txt"] {
  puts $pipe "put GenericScoresTEXT/LastYear.txt $ftpdir/GenericScoresTEXT/LastYear.txt"
 }
if [file exists "GenericScoresTEXT/ThisMonth.txt"] {
  puts $pipe "put GenericScoresTEXT/ThisMonth.txt $ftpdir/GenericScoresTEXT/ThisMonth.txt"
 }
if [file exists "GenericScoresTEXT/ThisWeek.txt"] {
  puts $pipe "put GenericScoresTEXT/ThisWeek.txt $ftpdir/GenericScoresTEXT/ThisWeek.txt"
 }
if [file exists "GenericScoresTEXT/ThisYear.txt"] {
 puts $pipe "put GenericScoresTEXT/ThisYear.txt $ftpdir/GenericScoresTEXT/ThisYear.txt"
 }
if [file exists "GenericScoresTEXT/Today.txt"] {
  puts $pipe "put GenericScoresTEXT/Today.txt $ftpdir/GenericScoresTEXT/Today.txt"
 }
if [file exists "GenericScoresTEXT/TopStreakers.html"] {
  puts $pipe "put GenericScoresTEXT/TopStreakers.html $ftpdir/GenericScoresTEXT/TopStreakers.txt"
 }
if [file exists "GenericScoresTEXT/Yesterday.html"] {
  puts $pipe "put GenericScoresTEXT/Yesterday.txt $ftpdir/GenericScoresTEXT/Yesterday.txt"
 }


 set monthstouse "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
 set daystouse "01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31"

### DAY UPLOADING CODE FOR BOTH WEB AND TEXT SCORES!
set monthindex 0
while {[lindex $monthstouse $monthindex] != ""} {

set dayindex 0
while {[lindex $daystouse $dayindex] != ""} {
set dayhufilename "[lindex $monthstouse $monthindex]"
append dayhufilename "[lindex $daystouse $dayindex]"
append dayhufilename "$yeartouse"
set dayhtfilename $dayhufilename
append dayhufilename ".html"
append dayhtfilename ".txt"
 if [file exists HTMLDailyScores/$dayhufilename] {
  puts $pipe "put HTMLDailyScores/$dayhufilename $ftpdir/HTMLDailyScores/$dayhufilename"
 }
 if [file exists TriviaDailyScores/$dayhtfilename] {
  puts $pipe "put TriviaDailyScores/$dayhtfilename $ftpdir/TriviaDailyScores/$dayhtfilename"
  }
incr dayindex
}
incr monthindex
}
### END OF DAY UPLOADING CODE

### WEEK UPLOADING CODE
set maxweeks 52
set weekcounter 1
while {$weekcounter != 53} {
set weekhufilename "Week"
append weekhufilename "$weekcounter"
append weekhufilename "_"
append weekhufilename "$yeartouse"
set weekhtfilename $weekhufilename
append weekhufilename ".html"
append weekhtfilename ".txt"

if [file exists HTMLWeeklyScores/$weekhufilename] {
  puts $pipe "put HTMLWeeklyScores/$weekhufilename $ftpdir/HTMLWeeklyScores/$weekhufilename"
 }
if [file exists TriviaWeeklyScores/$weekhtfilename] {
  puts $pipe "put TriviaWeeklyScores/$weekhtfilename $ftpdir/TriviaWeeklyScores/$weekhtfilename"
 }
incr weekcounter
}
### END WEEK UPDATER

### START OF MONTH UPDATER CODE
set monthstouse "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
set monthindex 0
while {[lindex $monthstouse $monthindex] != ""} {
set monthuhfilename "[lindex $monthstouse $monthindex]"
append monthuhfilename "$yeartouse"
set monthutfilename $monthuhfilename
append monthuhfilename ".html"
append monthutfilename ".txt"

if [file exists HTMLMonthlyScores/$monthuhfilename] {
  puts $pipe "put HTMLMonthlyScores/$monthuhfilename $ftpdir/HTMLMonthlyScores/$monthuhfilename"
 }
if [file exists TriviaMonthlyScores/$monthutfilename] {
  puts $pipe "put TriviaMonthlyScores/$monthutfilename $ftpdir/TriviaMonthlyScores/$monthutfilename"
 }
incr monthindex
}
### END OF MONTHLY UPDATER

### START OF YEAR UPDATER
set yearuhfilename "$yeartouse"
set yearutfilename "$yeartouse"
append yearuhfilename ".html"
append yearutfilename ".txt"
if [file exists HTMLYearlyScores/$yearuhfilename] {
  puts $pipe "put HTMLYearlyScores/$yearuhfilename $ftpdir/HTMLYearlyScores/$yearuhfilename"
 }
 
if [file exists TriviaYearlyScores/$yearutfilename] {
  puts $pipe "put TriviaYearlyScores/$yearutfilename $ftpdir/TriviaYearlyScores/$yearutfilename"
 }
### END OF YEAR UPDATER

 puts $pipe "quit"
 close $pipe
if {$nick != "blah"} {
 putquick "NOTICE $nick :Full web update complete...enjoy!"
}
 putquick "privmsg $triviachannel :The website is now updated with all scorefiles...enjoy!"
return
}
### IF ARGS ISN'T 'ALL', JUST UPLOAD THE CURRENT UPDATED SCOREFILES!
 set pipe [open "|/usr/bin/ftp -n $ftpaddress" w]
 puts $pipe "user $ftplogin $ftppass"
 puts $pipe "bin"
 if [file exists "GenericScoresHTML/FastestPlayers.html"] {
  puts $pipe "put GenericScoresHTML/FastestPlayers.html $ftpdir/GenericScoresHTML/FastestPlayers.html"
 }
 if [file exists "GenericScoresHTML/LastMonth.html"] {
  puts $pipe "put GenericScoresHTML/LastMonth.html $ftpdir/GenericScoresHTML/LastMonth.html"
 }
if [file exists "GenericScoresHTML/LastWeek.html"] {
  puts $pipe "put GenericScoresHTML/LastWeek.html $ftpdir/GenericScoresHTML/LastWeek.html"
 }
if [file exists "GenericScoresHTML/LastYear.html"] {
  puts $pipe "put GenericScoresHTML/LastYear.html $ftpdir/GenericScoresHTML/LastYear.html"
 }
if [file exists "GenericScoresHTML/ThisMonth.html"] {
  puts $pipe "put GenericScoresHTML/ThisMonth.html $ftpdir/GenericScoresHTML/ThisMonth.html"
 }
if [file exists "GenericScoresHTML/ThisWeek.html"] {
  puts $pipe "put GenericScoresHTML/ThisWeek.html $ftpdir/GenericScoresHTML/ThisWeek.html"
 }
if [file exists "GenericScoresHTML/ThisYear.html"] {
  puts $pipe "put GenericScoresHTML/ThisYear.html $ftpdir/GenericScoresHTML/ThisYear.html"
 }
if [file exists "GenericScoresHTML/Today.html"] {
  puts $pipe "put GenericScoresHTML/Today.html $ftpdir/GenericScoresHTML/Today.html"
 }
if [file exists "GenericScoresHTML/TopStreakers.html"] {
  puts $pipe "put GenericScoresHTML/TopStreakers.html $ftpdir/GenericScoresHTML/TopStreakers.html"
 }
if [file exists "GenericScoresHTML/Yesterday.html"] {
  puts $pipe "put GenericScoresHTML/Yesterday.html $ftpdir/GenericScoresHTML/Yesterday.html"
 }

if [file exists "GenericScoresTEXT/FastestPlayers.txt"] {
  puts $pipe "put GenericScoresTEXT/FastestPlayers.txt $ftpdir/GenericScoresTEXT/FastestPlayers.txt"
 }
 if [file exists "GenericScoresTEXT/LastMonth.txt"] {
  puts $pipe "put GenericScoresTEXT/LastMonth.txt $ftpdir/GenericScoresTEXT/LastMonth.txt"
 }
if [file exists "GenericScoresTEXT/LastWeek.txt"] {
  puts $pipe "put GenericScoresTEXT/LastWeek.txt $ftpdir/GenericScoresTEXT/LastWeek.txt"
 }
if [file exists "GenericScoresTEXT/LastYear.txt"] {
  puts $pipe "put GenericScoresTEXT/LastYear.txt $ftpdir/GenericScoresTEXT/LastYear.txt"
 }
if [file exists "GenericScoresTEXT/ThisMonth.txt"] {
  puts $pipe "put GenericScoresTEXT/ThisMonth.txt $ftpdir/GenericScoresTEXT/ThisMonth.txt"
 }
if [file exists "GenericScoresTEXT/ThisWeek.txt"] {
  puts $pipe "put GenericScoresTEXT/ThisWeek.txt $ftpdir/GenericScoresTEXT/ThisWeek.txt"
 }
if [file exists "GenericScoresTEXT/ThisYear.txt"] {
  puts $pipe "put GenericScoresTEXT/ThisYear.txt $ftpdir/GenericScoresTEXT/ThisYear.txt"
 }
if [file exists "GenericScoresTEXT/Today.txt"] {
  puts $pipe "put GenericScoresTEXT/Today.txt $ftpdir/GenericScoresTEXT/Today.txt"
 }
if [file exists "GenericScoresTEXT/TopStreakers.html"] {
  puts $pipe "put GenericScoresTEXT/TopStreakers.html $ftpdir/GenericScoresTEXT/TopStreakers.txt"
 }
if [file exists "GenericScoresTEXT/Yesterday.html"] {
  puts $pipe "put GenericScoresTEXT/Yesterday.txt $ftpdir/GenericScoresTEXT/Yesterday.txt"
 }


 if [file exists $dayhtmlfilename] {
  puts $pipe "put $dayhtmlfilename $ftpdir/$dayhtmlfilename"
 }
if [file exists $weekhtmlfilename] {
  puts $pipe "put $weekhtmlfilename $ftpdir/$weekhtmlfilename"
 }
if [file exists $monthhtmlfilename] {
  puts $pipe "put $monthhtmlfilename $ftpdir/$monthhtmlfilename"
 }
if [file exists $yearhtmlfilename] {
  puts $pipe "put $yearhtmlfilename $ftpdir/$yearhtmlfilename"
 }

if [file exists $dayfilename] {
  puts $pipe "put $dayfilename $ftpdir/$dayfilename"
 }
if [file exists $weekfilename] {
  puts $pipe "put $weekfilename $ftpdir/$weekfilename"
 }
if [file exists $monthfilename] {
  puts $pipe "put $monthfilename $ftpdir/$monthfilename"
 }
if [file exists $yearfilename] {
  puts $pipe "put $yearfilename $ftpdir/$yearfilename"
 }
 puts $pipe "quit"
 close $pipe
########################################################
if {$autoftpenable == 1} {
 utimer $ftpdelay "Autoftpsend blah $ownerhost blah blah blah"
}
if {$nick != "blah"} {
 putquick "NOTICE $nick :Your website is now updated with the latest scores...enjoy!"
}
 putquick "privmsg $triviachannel :Please check out http://z.myjp.net/ for latest Trivia Scores. The Scores are updated daily ...enjoy!"

return
}

### Score Transfer Code!
proc ScoreTransfer {nick uhost hand args} {
 global usercounter fastanswerqty fastanswerscore streakscore alreadyguessed TransferOpAllowed TransferValidUsers TransferValidHosts ownerhost antifloodenable commandusers triviaowner score alreadygoing monthfilename prevmonthfilename monthhtmlfilename dayscore dayfilename prevdayfilename dayhtmlfilename weekscore weekfilename prevweekfilename weekhtmlfilename yearfilename yearhtmlfilename prevyearfilename yearscore triviachannel
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$TransferOpAllowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $TransferValidHosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $TransferValidHosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################
if {$alreadygoing == 0} {
putquick "NOTICE $nick :Sorry $nick, but Trivia must be running to Transfer a player's score due to the way the triviabot handles scoring...it must also be done while a question is in play!"
return
}
if {$alreadyguessed == 1} {
putquick "NOTICE $nick :Sorry $nick, but Trivia must be running to Transfer a player's score due to the way the triviabot handles scoring...it must also be done while a question is in play!"
return
}
regsub -all \[{}] $args "" args
set divider " "
set divnum [string first $divider $args]
set fromtodisplay [string range $args 0 [expr $divnum -1]]
set totodisplay [string range $args [expr $divnum +1] end]
set divcheck2 [string first $divider $totodisplay]
if {$divcheck2 > 0} {
putquick "NOTICE $nick :Syntax for this command is: /msg BOTNICK transfer FROMNICK TONICK ('/msg BOTNICK transfer Nerfbendr ScrappyDo' will transfer the score from Nerfbendr to ScrappyDo...This command is Case Sensitive!)"
return
}
regsub -all \[{}] $args "~" args
regsub -all {[\\]} $args "|" args
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
### IF FROM PLAYER DOESN'T EXIST, INFORM NICK OF IT AND RETURN...OTHERWISE CARRY OUT THE COMMAND! (ADD THE TRANSFERRED SCORE TO THE TO_USER!)
set fromplayer [lindex $args 0]
set toplayer [lindex $args 1]
	if {[info exists yearscore($fromplayer)]} {
		if {[info exists yearscore($toplayer)]} {
			if {[info exists score($toplayer)]} {incr score($toplayer) $score($fromplayer)}
			if {[info exists dayscore($toplayer)]} {incr dayscore($toplayer) $dayscore($fromplayer)}
			if {[info exists weekscore($toplayer)]} {incr weekscore($toplayer) $weekscore($fromplayer)}
		 	incr yearscore($toplayer) $yearscore($fromplayer)
			if {[info exists fastanswerscore($toplayer)]} {
 			 if {$fastanswerscore($toplayer) > $fastanswerscore($fromplayer)} {
			  incr fastanswerscore($toplayer) $fastanswerscore($fromplayer)
			  incr fastanswerqty($toplayer) $fastanswerqty($fromplayer)
			 }
			}

 			if {$fastanswerscore($toplayer) == $fastanswerscore($fromplayer)} {
			 if {[info exists fastanswerqty($toplayer)]} {
			  if {$fastanswerqty($toplayer) < $fastanswerqty($fromplayer)} {
			  }
			 }
			}
			if {[info exists streakscore($toplayer)]} {
			 if {$streakscore($toplayer) < $streakscore($fromplayer)} {
			  incr streakscore($toplayer) $streakscore($fromplayer)
			 }
			}
			set score($fromplayer) 0
			set dayscore($fromplayer) 0
			set weekscore($fromplayer) 0
			set yearscore($fromplayer) 0
			set fastanswerqty($fromplayer) 999
			set fastanswerscore($fromplayer) 0
			set streakscore($fromplayer) 0
	write_fastanswers
	write_score
	write_dayscore
	write_weekscore
	write_yearscore
	write_streak
			putquick "NOTICE $nick :Scores have been transferred from $fromtodisplay to $totodisplay!"
			return
    		}
		if {![info exists yearscore($toplayer)]} {
		 	 set score($toplayer) $score($fromplayer)
		 	 set dayscore($toplayer) $dayscore($fromplayer)
		 	 set weekscore($toplayer) $weekscore($fromplayer)
		 	 set yearscore($toplayer) $yearscore($fromplayer)
			 set fastanswerqty($toplayer) $fastanswerqty($fromplayer)
			 set fastanswerscore($toplayer) $fastanswerscore($fromplayer)
			 set streakscore($toplayer) $streakscore($fromplayer)
			 set score($fromplayer) 0
			 set dayscore($fromplayer) 0
			 set weekscore($fromplayer) 0
			 set yearscore($fromplayer) 0
			 set fastanswerqty($fromplayer) 0
			 set fastanswerscore($fromplayer) 999
			 set streakscore($fromplayer) 0
	write_fastanswers
	write_score
	write_dayscore
	write_weekscore
	write_yearscore
	write_streak
			 putquick "NOTICE $nick :Scores have been transferred from $fromtodisplay to $totodisplay!"
			 return
		} 
		if {![info exists yearscore($fromplayer)]} {
			putquick "NOTICE $nick :Sorry $nick, but I don't have any scores from $fromplayer to transfer!"
			return
		}

}
}

### Score Adjusting Code!
proc ScoreAdjuster {nick uhost hand args} {
 global fastanswerqty fastanswerscore streakscore alreadyguessed modifyopallowed modifyvalidusers modifyvalidhosts ownerhost antifloodenable commandusers triviaowner score alreadygoing monthfilename prevmonthfilename monthhtmlfilename dayscore dayfilename prevdayfilename dayhtmlfilename weekscore weekfilename prevweekfilename weekhtmlfilename yearfilename yearhtmlfilename prevyearfilename yearscore triviachannel
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$modifyopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $modifyvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $modifyvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################
if {$alreadygoing == 0} {
putquick "NOTICE $nick :Sorry $nick, but Trivia must be running to adjust a player's score due to the way the triviabot handles scoring...it must also be done while a question is in play!"
return
}
if {$alreadyguessed == 1} {
putquick "NOTICE $nick :Sorry $nick, but Trivia must be running to adjust a player's score due to the way the triviabot handles scoring...it must also be done while a question is in play!"
return
}
regsub -all \[{}] $args "~" args
regsub -all {[\\]} $args "|" args
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
set divider " "
set divnum [string first $divider $args]
set fromtodisplay [string range $args 0 [expr $divnum -1]]
set totodisplay [string range $args [expr $divnum +1] end]
set divcheck2 [string first $divider $totodisplay]
####### REMEMBER TO ADD CODE TO THIS SECTION FOR INDIVIDUAL ADJUSTING OF A PLAYER'S
####### SCORES FOR DAY, WEEK, MONTH OR YEAR *INDIVIDUALLY*!

####### EXAMPLE: /msg BOTNICK adjust NICK X = Default adjusting of day, week, month and year!
#######          /msg BOTNICK adjust NICK X day = Adjusts NICK's day score by X points!
#######          /msg BOTNICK adjust NICK X week = Adjusts NICK's week score by X points!
#######          /msg BOTNICK adjust NICK X month = Adjusts NICK's month score by X points!
#######          /msg BOTNICK adjust NICK X year = Adjusts NICK's year score by X points!


if {$divcheck2 > 0} {
putquick "NOTICE $nick :Syntax for this command is: /msg BOTNICK adjust NICK SCOREADJUST [DAY/WEEK/MONTH/YEAR] ('/msg BOTNICK adjust Nerfbendr 10' will adjust Nerfbendr's scores +10 points for the current day, week, month and year...'/msg BOTNICK adjust Nerfbendr 10 week' does the same, but only for the current week's score! This command is Case Sensitive with a player's nick!)"
return
}
regsub -all \[{}] $args "~" args
regsub -all {[\\]} $args "~" args
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
### IF FROM PLAYER DOESN'T EXIST, INFORM NICK OF IT AND RETURN...OTHERWISE CARRY OUT THE COMMAND! (ADD THE TRANSFERRED SCORE TO THE TO_USER!)
set fromplayer [lindex $args 0]
set adjuster [lindex $args 1]
if {$fromplayer == ""} {
putquick "NOTICE $nick :Syntax for this command is: /msg BOTNICK adjust NICK SCOREADJUST ('/msg BOTNICK adjust Nerfbendr 10' will adjust Nerfbendr's scores +10 points...This command is Case Sensitive with a player's nick!)"
return
}
if {$adjuster == ""} {
putquick "NOTICE $nick :Syntax for this command is: /msg BOTNICK adjust NICK SCOREADJUST ('/msg BOTNICK adjust Nerfbendr 10' will adjust Nerfbendr's scores +10 points...This command is Case Sensitive with a player's nick!)"
return
}

	if {[info exists yearscore($fromplayer)]} {
			if {[info exists score($fromplayer)]} {incr score($fromplayer) $adjuster}
			if {[info exists dayscore($fromplayer)]} {incr dayscore($fromplayer) $adjuster}
			if {[info exists weekscore($fromplayer)]} {incr weekscore($fromplayer) $adjuster}
		 	incr yearscore($fromplayer) $adjuster
if {[lindex $args 2] == ""} {
	write_score
	write_dayscore
	write_weekscore
	write_yearscore
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for day, week, month and year!"
			return
}
if {[lindex $args 2] == "day"} {
	write_dayscore
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for the day!"
			return
}
if {[lindex $args 2] == "week"} {
	write_weekscore
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for the week!"
			return
}
if {[lindex $args 2] == "month"} {
	write_score
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for the month!"
			return
}
if {[lindex $args 2] == "year"} {
	write_yearscore
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for the year!"
			return
}
    		}
		if {![info exists yearscore($fromplayer)]} {
		 	 set score($fromplayer) $adjuster
		 	 set dayscore($fromplayer) $adjuster
		 	 set weekscore($fromplayer) $adjuster
		 	 set yearscore($fromplayer) $adjuster
if {[lindex $args 2] == ""} {
	write_score
	write_dayscore
	write_weekscore
	write_yearscore
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for day, week, month and year!"
			return
}
if {[lindex $args 2] == "day"} {
	write_dayscore
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for the day!"
			return
}
if {[lindex $args 2] == "week"} {
	write_weekscore
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for the week!"
			return
}
if {[lindex $args 2] == "month"} {
	write_score
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for the month!"
			return
}
if {[lindex $args 2] == "year"} {
	write_yearscore
			putquick "NOTICE $nick :Scores have been adjusted on $fromtodisplay by $adjuster points for the year!"
			return
}
		}

}

### Score re-sync code...weekly, monthly and yearly!
proc SyncScores {nick uhost hand args} {
 global ownerhost syncvalidhosts antifloodenable commandusers triviaowner syncopallowed syncvalidusers score alreadygoing monthfilename prevmonthfilename monthhtmlfilename dayscore dayfilename prevdayfilename dayhtmlfilename weekscore weekfilename prevweekfilename weekhtmlfilename yearfilename yearhtmlfilename prevyearfilename yearscore triviachannel
 if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$syncopallowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $syncvalidhosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $syncvalidhosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################
putquick "NOTICE $nick :Sorry $nick, but this command is not yet complete...sorry!"
return
}

proc WriteRoundScores {} {
global AText ABackground answertitletextcolor answertitlebgcolor answertitlebold answerbold gradhinttitletextcolor gradhinttitlebgcolor gradhinttitlebold gradhintbold pointdropcounter FillInLettersEnable HBackground HText ABackground AText LastAnswer antifloodenable minstart autovoicesynch autovoicescore autovoiceenable origtrivvalue fastanswerqty streakscore streakfilename streakhtmlfilename fastanswerscore fastanswerfilename fastanswerhtmlfilename alreadygoing qafile question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed nameofbot nextorder nextquestioncounter triviavalue dayscore dayfilename weekscore weekfilename yearscore yearfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable secondstart
	write_score
	write_dayscore
	write_weekscore
	write_yearscore
	write_streak
	write_fastanswers
      return
}

##################### NEW V6.0 SCRAMBLE MODE #####################

proc ScrambleRound {nick uhost hand chan} {
global TrivDelay ManualTrivDelay triviachannel gamemode gamemodepercent scramblebanks sbankpercents scramblepvmethod scramblepresetvalue scrletters scrvalues scrdrops scrptdrops scrptdropseconds scrcluedisplay scrhintptdrop scrminhintletters scrmaxhintletters scrmaxhints scrpercenthintenable scrhintpercent scrhintprocess





putquick "privmsg $triviachannel :Scramble Mode was chosen for this round...$TrivDelay, $ManualTrivDelay!"





################ POSSIBLE BOT-CRASHING SOLUTION (ASSUMING TIMERS ARE TO BLAME) ##########
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Mainproc* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *PointDrop* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndOf* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
################ END OF POSSIBLE BOT-CRASHING SOLUTION (ASSUMING TIMERS ARE TO BLAME) ##########
utimer [expr $TrivDelay - $ManualTrivDelay] "Mainproc blah blah blah $triviachannel"
return 1
}
##################### TEAM TRIVIA V6.0 NEW CODE ########################
#########################################
proc EndTeamTrivia {} {
global teamenable TeamNamesToUse colorteamnamestouse alreadygoing maxteams maxteamplayers maxteampoints teamduration teammode triviachannel antifloodenable usercounter commandusers teamenable TeamNames CurrentTeamPlayerTotals TeamPlayers TeamPoints IndividualTeamPoints usercounter ScrambleRoundChosen validbanks frequency triviavalue bonuslengths bonusvalues bonusdrops pointdrops pointdropdelay pointdropdecrease minhintletters maxhintletters hinttimes percentagehintenable hintpercentage hintmethods orig_validbanks orig_frequency orig_trivvalue orig_bonuslengths orig_bonusvalues orig_bonusdrops orig_pointdrops orig_pointdropdelay orig_pointdropdecrease orig_minhintletters orig_maxhintletters orig_hinttimes orig_percentagehintenable orig_hintpercentage orig_hintmethods trivquitvalidhosts ownerhost origtrivvalue triviavalue nextorder pointdropcounter pointdropcounter antifloodenable usercounter commandusers nameofbot triviaowner triviachannel trivquitopallowed trivquitvalidusers alreadygoing qafile question wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable answertitletextcolor answertitlebgcolor AText ABackground answer
if {$teammode == 0} {set ttmode "Normal"}
 if {$teammode == 1} {set ttmode "Battle"}
if {$maxteams != 0} {
  set maxteams2 $maxteams
 }
 if {$maxteamplayers != 0} {
  set maxteamplayers2 $maxteamplayers
 }
 if {$maxteampoints != 0} {
  set maxteampoints2 $maxteampoints
 }
 if {$teamduration != 0} {
  set teamduration2 $teamduration
  set teamduration2 [expr $teamduration2 / 60]
 }
 if {$maxteams == 0} {
  set maxteams2 "No Limit"
  set maxteams 99999999
 }
 if {$maxteamplayers == 0} {
  set maxteamplayers2 "No Limit"
  set maxteams 99999999
 }
 if {$maxteampoints == 0} {
  set maxteampoints2 "No Limit"
 }
 if {$teamduration == 0} {
  set teamduration2 "No Limit"
 }
  set counter 0
  set TeamNames ""
  set cnames ""
### Display final team trivia results in-channel here!
### (NOTE: WHAT IF THERE'S A TIE RESULTING FROM A TIMED GAME?)
set winnerscore 0
set winindex 0
set counter 0
while {[lindex $TeamPoints $counter] != ""} {
 if {[lindex $TeamPoints $counter] > $winnerscore} {
  set winnerscore [lindex $TeamPoints $counter]
  set winindex $counter
 }
 incr counter
}
if {$winnerscore >= $maxteampoints} {
putquick "privmsg $triviachannel :8,1********** THE GAME HAS BEEN WON!! **********"
} {
putquick "privmsg $triviachannel :8,1************* TIME HAS RUN OUT! *************"
}
if {$alreadyguessed == 0} {
 putquick "privmsg $triviachannel :$answertitletextcolor,$answertitlebgcolor The answer was:$AText,$ABackground $answer!"
}
putquick "privmsg $triviachannel :0,1******** TEAM TRIVIA FINAL STANDINGS ********"
putquick "privmsg $triviachannel :0,4red: [lindex $TeamPoints 0] 0,2blue: [lindex $TeamPoints 1] 0,6purple: [lindex $TeamPoints 2] 0,3green: [lindex $TeamPoints 3] 0,5brown: [lindex $TeamPoints 4] 1,11cyan: [lindex $TeamPoints 5] 1,8yellow: [lindex $TeamPoints 6] 1,7orange: [lindex $TeamPoints 7] 0,1black: [lindex $TeamPoints 8] 1,0white: [lindex $TeamPoints 9] "
### DETERMINE WINNING TEAM, DISPLAY THEIR STATS AND CONGRATULATE THEM!
putquick "privmsg $triviachannel :0,1*********************************************"
### ORGANIZE ALL TEAM INFO NEATLY FOR DISPLAY:
 set counter 0
# putquick "privmsg $triviachannel :CurrentTeamPlayerTotals: $CurrentTeamPlayerTotals!"
# putquick "privmsg $triviachannel :TeamPlayers, $TeamPlayers!"
# putquick "privmsg $triviachannel :IndividualTeamPoints, $IndividualTeamPoints!"

 while {$counter != $maxteams} {
 set teaminfofordisplay ""
  if {[lindex $CurrentTeamPlayerTotals $counter] != 0} {
  append teaminfofordisplay "[lindex $colorteamnamestouse $counter] team0,1: "
  append teaminfofordisplay "team size:8 [lindex $CurrentTeamPlayerTotals $counter]0, "
  append teaminfofordisplay "team points:8 [lindex $TeamPoints $counter]0, "
  append teaminfofordisplay "team players 0: "
#   append teaminfofordisplay "team players 4(11and contributed points4)0: "
 set counter2 0
 if {[lindex $IndividualTeamPoints $counter2] == ""} {
    append teaminfofordisplay "8No Players Yet!"
#     append teaminfofordisplay "8No Players Yet! 4("
#     append teaminfofordisplay "110"
#     append teaminfofordisplay "4)0, "
 }
 while {[lindex $TeamPlayers $counter2] != ""} {
  if {[lindex $TeamPlayers $counter2] == $counter} {
   append teaminfofordisplay "8[lindex $TeamPlayers [expr $counter2 -1]]0, "
#    append teaminfofordisplay "8[lindex $TeamPlayers [expr $counter2 -1]] 4("
#    append teaminfofordisplay "11[lindex $IndividualTeamPoints $counter2]"
#    append teaminfofordisplay "4)0, "
  }
  incr counter2
 }
  putquick "privmsg $triviachannel :$teaminfofordisplay!"
 }
 incr counter
}
if {$winnerscore != 0} {
putquick "privmsg $triviachannel :8,1Congratulations To Everyone on the [lindex $colorteamnamestouse $winindex] Team8,1 for a job well done!"
}
if {$winnerscore == 0} {
 putquick "privmsg $triviachannel :0,1All teams have a score of zero points...if anybody was playing then there's no hope for you...please turn off your monitor and walk away quietly...thank you..."
}
### Reset Old Game Variables Here
 set CurrentTeamPlayerTotals "0 0 0 0 0 0 0 0 0 0"
 set TeamPlayers ""
 set TeamPoints "0 0 0 0 0 0 0 0 0 0"
 set counter 0
 set IndividualTeamPoints ""
 while {[lindex $TeamPlayers $counter] != ""} {
 append IndividualTeamPoints "[lindex $TeamPlayers $counter] 0 "
 set counter [expr $counter +2]
}
 putquick "privmsg $triviachannel :0,1All Team Stats Have Been Cleared...Type 8,1!Join0,1 To Join a Team when the next game begins!"
########### RESET ALL VARS FOUND IN THE !STOPTRIVIA COMMAND
	set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Advertiser* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndTeam* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	set triviavalue $origtrivvalue
 	if [info exists nextorder] {unset nextorder}
 	set pointdropcounter 0
########### V6.0: SCRAMBLE CODE: RESET VARS BACK TO TRIVIA
if {$ScrambleRoundChosen == 1} {
 set validbanks $orig_validbanks
 set frequency $orig_frequency
 set triviavalue $orig_trivvalue
 set bonuslengths $orig_bonuslengths
 set bonusvalues $orig_bonusvalues
 set bonusdrops $orig_bonusdrops
 set pointdrops $orig_pointdrops
 set pointdropdelay $orig_pointdropdelay
 set pointdropdecrease $orig_pointdropdecrease
 set minhintletters $orig_minhintletters
 set maxhintletters $orig_maxhintletters
 set hinttimes $orig_hinttimes
 set percentagehintenable $orig_percentagehintenable
 set hintpercentage $orig_hintpercentage
 set hintmethods $orig_hintmethods
 }
utimer 30 "StartTrivia blah blah blah $triviachannel"
return
}
###

 proc TeamPlayersStillHere {} {
  global teamenable teammode triviachannel TeamPlayers maxteams colorteamnamestouse CurrentTeamPlayerTotals TeamPoints IndividualTeamPoints
  if {$teamenable == 0} {
   utimer 30 "TeamPlayersStillHere"
   return
  }
  set mylist [chanlist $triviachannel]
  set counter 0
  set stillin 0
while {[lindex $TeamPlayers $counter] != ""} {
 set counter2 0
  while {[lindex $mylist $counter2] != ""} {

set nickforfile [lindex $mylist $counter2]
### MAIN CODE FOR BAD CHARACTER REPLACEMENTS GO HERE
regsub -all \[{}] $nickforfile "~" nickforfile
regsub -all {[\\]} $nickforfile "|" nickforfile
### START OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
####################################################
   if {[lindex $TeamPlayers $counter] == $nickforfile} {
    set stillin 1
    set foundyouteamscoreindexer [lindex $TeamPlayers [expr $counter +1]]
   }
   incr counter2
  }
# putquick "privmsg $triviachannel :1! $nickforfile, $counter, [lindex $TeamPlayers $counter], $counter2, $mylist, $stillin!"
  if {$stillin == 0} {   
# putquick "privmsg $triviachannel :6! $CurrentTeamPlayerTotals, $TeamPlayers!"
 ### PLAYER FOUND ON A TEAM AND NOT IN CHANNEL...OUST'EM!
 ### 1) Decrease Total Players On Team Player was on by 1!
 set teamtocheck [lindex $TeamPlayers [expr $counter + 1]]
 if {$teamtocheck == 0} {
  set newCurrentTeamPlayerTotals " [expr [lindex $CurrentTeamPlayerTotals 0] - 1] "
  append newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals 1 end] "
  set CurrentTeamPlayerTotals $newCurrentTeamPlayerTotals
 }
 if {$teamtocheck > 0} {
  set newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals 0 [expr $teamtocheck -1]] "
  append newCurrentTeamPlayerTotals " [expr [lindex $CurrentTeamPlayerTotals $teamtocheck] -1] "
  append newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals [expr $teamtocheck +1] end] "
  set CurrentTeamPlayerTotals $newCurrentTeamPlayerTotals
 }
 ### 2) Remove Player From Team!
# putquick "privmsg $triviachannel :7! $teamtocheck, $counter, $CurrentTeamPlayerTotals, $TeamPlayers!"
set removedplayer [lindex $TeamPlayers $counter]
 if {$counter == 0} {
  set TeamPlayers [lrange $TeamPlayers 2 end]
 }
 if {$counter > 0} {
  set newTeamPlayers " [lrange $TeamPlayers 0 [expr $counter -1]] "
  append newTeamPlayers " [lrange $TeamPlayers [expr $counter +2] end] "
  set TeamPlayers $newTeamPlayers
 }
 ### 3) Add Player To IndividualTeamPoints For Tracking Purposes!
# putquick "privmsg $triviachannel :8! $teamtocheck, $counter, $CurrentTeamPlayerTotals, $TeamPlayers!"
if {$teammode == 999} {
  if {$foundyouteamscoreindexer == 0} {
    set newTeamPoints " [expr [lindex $TeamPoints $foundyouteamscoreindexer] - [lindex $IndividualTeamPoints [expr $teamtocheck +1]]] "
    append newTeamPoints " [lrange $TeamPoints 1 end] "
    set TeamPoints $newTeamPoints
  }
  if {$foundyouteamscoreindexer > 0} {
   set newTeamPoints " [lrange $TeamPoints 0 [expr $foundyouteamscoreindexer -1]] "
   append newTeamPoints " [expr [lindex $TeamPoints $foundyouteamscoreindexer] - [lindex $IndividualTeamPoints [expr $teamtocheck +1]]] "
   append newTeamPoints " [lrange $TeamPoints [expr $foundyouteamscoreindexer +1] end] "
   set TeamPoints $newTeamPoints
  }
 }
# putquick "privmsg $triviachannel :9! $teamtocheck, $counter, $CurrentTeamPlayerTotals, $TeamPlayers!"
  if {$teamtocheck == 0} {
   set IndividualTeamPoints [lrange $TeamPlayers 2 end]
  }
  if {$teamtocheck > 0} {
   set newIndividualTeamPoints " [lrange $IndividualTeamPoints 0 [expr $teamtocheck -1]] "
   append newIndividualTeamPoints " [lrange $IndividualTeamPoints [expr $teamtocheck +2] end] "
   set IndividualTeamPoints $newIndividualTeamPoints
 }
#####
# putquick "privmsg $triviachannel :10! $teamtocheck, $counter, $CurrentTeamPlayerTotals, $TeamPlayers!"
putquick "privmsg $triviachannel :8,1 $removedplayer is not in the channel and has been removed from the [lindex $colorteamnamestouse $teamtocheck] team!"
  ###
   }

   incr counter 2 
   set stillin 0
  }
 utimer 30 "TeamPlayersStillHere"
 return
 }



bind pub - !teams TeamTriviaStats
bind msg - !teams TeamTriviaStats

 proc TeamTriviaStats {nick uhost hand chan args} {
 global triviachannel TeamPlayers maxteams colorteamnamestouse CurrentTeamPlayerTotals TeamPoints IndividualTeamPoints
  ### ORGANIZE ALL TEAM INFO NEATLY FOR DISPLAY:
 set counter 0
# putquick "privmsg $triviachannel :CurrentTeamPlayerTotals: $CurrentTeamPlayerTotals!"
# putquick "privmsg $triviachannel :TeamPlayers, $TeamPlayers!"
# putquick "privmsg $triviachannel :IndividualTeamPoints, $IndividualTeamPoints!"
set checker 0
set peopleplaying 0
while {$checker != $maxteams} {
 if {[lindex $CurrentTeamPlayerTotals $checker] != 0} {
   set peopleplaying 1
  }
  incr checker
 }
 if {$peopleplaying == 0} {
  putquick "notice $nick :0,1There are no players in Team Trivia yet! Type 11!join0 to join a team!"
 }
 set noplayers "0,1These teams have no players: "
while {$counter != $maxteams} {
 set teaminfofordisplay ""
if {[lindex $CurrentTeamPlayerTotals $counter] != 0} {
  append teaminfofordisplay "[lindex $colorteamnamestouse $counter] team0,1: "
  append teaminfofordisplay "team size:8 [lindex $CurrentTeamPlayerTotals $counter]0, "
  append teaminfofordisplay "team points:8 [lindex $TeamPoints $counter]0, "
  append teaminfofordisplay "team players 0: "
#  append teaminfofordisplay "team players 4(11and contributed points4)0: "
 set counter2 0
 if {[lindex $IndividualTeamPoints $counter2] == ""} {
     append teaminfofordisplay "8No Players Yet!"
#    append teaminfofordisplay "8No Players Yet! 4("
#    append teaminfofordisplay "110"
#    append teaminfofordisplay "4)0, "
 }
 while {[lindex $TeamPlayers $counter2] != ""} {
  if {[lindex $TeamPlayers $counter2] == $counter} {
   append teaminfofordisplay "8[lindex $TeamPlayers [expr $counter2 -1]]0, "
#   append teaminfofordisplay "8[lindex $TeamPlayers [expr $counter2 -1]] 4("
#   append teaminfofordisplay "11[lindex $IndividualTeamPoints $counter2]"
#   append teaminfofordisplay "4)0, "
  }
  incr counter2
 }
  putquick "NOTICE $nick :$teaminfofordisplay!"

  }
   if {[lindex $CurrentTeamPlayerTotals $counter] == 0} {
   append noplayers "[lindex $colorteamnamestouse $counter] "
   }
 incr counter
}
# if {$noplayers != "0,1These teams have no players: "} {
 putquick "NOTICE $nick :$noplayers!"
# }
return
}



bind pub - !join JoinATeam
bind msg - !join JoinATeam

proc JoinATeam {nick uhost hand chan args} {
global IndividualTeamPoints colorteamnamestouse TeamNamesToUse alreadygoing maxteams maxteamplayers maxteampoints teamduration teammode triviachannel antifloodenable usercounter commandusers teamenable TeamNames CurrentTeamPlayerTotals TeamPlayers TeamPoints IndividualTeamPoints
# putquick "privmsg $triviachannel :1!"
################################
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
################################
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
if {$teamenable == 0} {
  putquick "privmsg $triviachannel :4Team Trivia Mode not enabled...sorry!"
  return
}
################################
set nickforfile $nick
### MAIN CODE FOR BAD CHARACTER REPLACEMENTS GO HERE
regsub -all \[{}] $nickforfile "~" nickforfile
regsub -all {[\\]} $nickforfile "|" nickforfile
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
################################

 set teamtojoin [string tolower $args]
 regsub -all \[{}] $teamtojoin "" $teamtojoin
 if {$args != ""} {
  set doesteamexist 0
  set isteamfull 0
  ### Does requested team exist? If not, set args to "" so player gets
  ### proper team info...else continue on to place player on a team!
  set counter 0
  while {[lindex $TeamNames $counter] != ""} {
   if {$teamtojoin == [lindex $TeamNames $counter]} {
    set doesteamexist 1
    set teamtocheck $counter
   }
   incr counter
  }
  if {$doesteamexist == 1} {
   if {[lindex $CurrentTeamPlayerTotals $teamtocheck] == $maxteamplayers} {
    set isteamfull 1
   }
   ### Is requested team full? If yes, Do the above as well...
   if {$isteamfull == 1} {
      putquick "NOTICE $nick :4Sorry, but team $teamtojoin is full right now...please try another team..."
      return
   }
  }
  if {$doesteamexist == 0} {set args ""}
  if {$isteamfull == 1} {set args ""}
 #########################################
  ### Is player currently found on a team? If so, don't let him !join
  ### until he has !remove'd himself from team play!
  set counter 0
   set PlayerFound 0
   set FoundYou ""
   while {[lindex $TeamPlayers $counter] != ""} {
    if {[lindex $TeamPlayers $counter] == $nickforfile} {
     set PlayerFound 1
     set FoundYou [lindex $colorteamnamestouse [lindex $TeamPlayers [expr $counter +1]]]
    }
   incr counter
   }
   if {$PlayerFound == 1} {
   putquick "NOTICE $nick :8,1You are already playing on team $FoundYou8,1 $nick...type 8!remove0 before joining another team!"
   return
  }
 #########################################
 }
 

  ### No valid team was defined...display team info to player privately!
  ### Info includes valid team names, current players on each team,
  ### max number of teams, max players per team and team scores! 
 if {$args == ""} {
 ###
 if {$maxteams != 0} {
   set maxteams2 $maxteams
  }
  if {$maxteamplayers != 0} {
   set maxteamplayers2 $maxteamplayers
  }
  if {$maxteampoints != 0} {
   set maxteampoints2 $maxteampoints
  }
  if {$teamduration != 0} {
   set teamduration2 $teamduration
   set teamduration2 [expr $teamduration2 / 60]
  }
 
 
  if {$maxteams == 0} {
   set maxteams2 "No Limit"
   set maxteams 99999999
  }
  if {$maxteamplayers == 0} {
   set maxteamplayers2 "No Limit"
   set maxteams 99999999
  }
  if {$maxteampoints == 0} {
   set maxteampoints2 "No Limit"
  }
  if {$teamduration == 0} {
   set teamduration2 "No Limit"
  }
 
#   putquick "NOTICE $nick :Max. Teams: $maxteams! Current Teams: $TeamNames! Max. players per Team: $maxteamplayers!"
 if {$teammode == 0} {set ttmode "Normal"}
 if {$teammode == 1} {set ttmode "Battle"}
# putquick "notice $nick :8$ttmode 0Team Trivia is running with the following settings:"
# putquick "notice $nick :0Number of Teams:8 $maxteams20, Maximum Players Per Team:8 $maxteamplayers20, Points Needed To Win The Game:8 $maxteampoints20, Game Duration:8 $teamduration2 0minutes!" 
 putquick "notice $nick :0,1Valid Team Names To Join Are: $colorteamnamestouse"
 ### ORGANIZE ALL TEAM INFO NEATLY FOR DISPLAY:
return
}

 ### Player has requested to be on a valid unfilled team and is not
 ### currently on any team...add him in!
 
 ### 1) Increase Total Players On Team Player Is Added To by 1!
 if {$teamtocheck == 0} {
  set newCurrentTeamPlayerTotals " [expr [lindex $CurrentTeamPlayerTotals 0] + 1] "
  append newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals 1 end] "
  set CurrentTeamPlayerTotals $newCurrentTeamPlayerTotals
 }
 if {$teamtocheck > 0} {
  set newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals 0 [expr $teamtocheck -1]] "
  append newCurrentTeamPlayerTotals " [expr [lindex $CurrentTeamPlayerTotals $teamtocheck] +1] "
  append newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals [expr $teamtocheck +1] end] "
  set CurrentTeamPlayerTotals $newCurrentTeamPlayerTotals
 }
 ### 2) Add Player To Team!
 append TeamPlayers " $nickforfile $teamtocheck "
 ### 3) Add Player To IndividualTeamPoints For Tracking Purposes!
 append IndividualTeamPoints " $nickforfile 0 "
 #########################################
 putquick "privmsg $triviachannel :8,1 $nick has just joined the [lindex $colorteamnamestouse $teamtocheck] team8,1...good luck $nick!"
return
 }



bind pub - !teamtrivia TeamTriviaMode
bind msg - !teamtrivia TeamTriviaMode

proc TeamTriviaMode {nick uhost hand chan args} {
global TeamValidUsers TeamValidHosts TeamOpAllowed triviastoppedflag alreadygoing teamenable TeamNamesToUse colorteamnamestouse alreadygoing maxteams maxteamplayers maxteampoints teamduration teammode triviachannel antifloodenable usercounter commandusers teamenable TeamNames CurrentTeamPlayerTotals TeamPlayers TeamPoints IndividualTeamPoints usercounter ScrambleRoundChosen validbanks frequency triviavalue bonuslengths bonusvalues bonusdrops pointdrops pointdropdelay pointdropdecrease minhintletters maxhintletters hinttimes percentagehintenable hintpercentage hintmethods orig_validbanks orig_frequency orig_trivvalue orig_bonuslengths orig_bonusvalues orig_bonusdrops orig_pointdrops orig_pointdropdelay orig_pointdropdecrease orig_minhintletters orig_maxhintletters orig_hinttimes orig_percentagehintenable orig_hintpercentage orig_hintmethods trivquitvalidhosts ownerhost origtrivvalue triviavalue nextorder pointdropcounter pointdropcounter antifloodenable usercounter commandusers nameofbot triviaowner triviachannel trivquitopallowed trivquitvalidusers alreadygoing qafile question wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable AText ABackground answer answertitletextcolor answertitlebgcolor
global triviastoppedflag teamstarttime teamminstart teamsecondstart TeamNames TeamNamesToUse maxteams maxteamplayers colorteamnamestouse maxteampoints teamduration teamenable teammode question answer hint scramblebanks ownerhost triviavalidhosts qtotal validbanks triviaowner nameofbot triviavalidusers triviaopallowed validquestions origqfilelength qafilelength antifloodenable usercounter commandusers alreadygoing qafile AnyonePlaying triviastoppedflag qafilelength triviachannel
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
## NEW GLOBALS: ownerhost swapbankvalidhosts
###################### NEW CODE FOR CHECKING UHOSTS ###################
set allowedflag 0
set uhosttoscan $uhost
set umarker "*"
  set ripmask $ownerhost
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
   set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
###########################################################
      if {$TeamOpAllowed == 1} {
 	if {[isop $nick $triviachannel]} {set allowedflag 1}
      }
###########################################################
if {$allowedflag == 0} {
set uhosttoscan $uhost
set umarker "*"
set ucounter 0
while {[lindex $TeamValidHosts $ucounter] != ""} {
 if {$allowedflag == 0} {
  set ripmask [lindex $TeamValidHosts $ucounter]
  set ripped ""
  set ripend [string first $umarker $ripmask]
  while {$ripend != -1} {
   if {$ripend != 0} {
    append ripped "[string range $ripmask 0 [expr $ripend -1]] "
   }
   set ripmask [string range $ripmask [expr $ripend  +1] end]
  set ripend [string first $umarker $ripmask]
  }
  append ripped [string range $ripmask [expr $ripend  +1] end]
  set foundit 0
  set hcounter 0
  set maxfind [llength $ripped]
  while {[lindex $ripped $hcounter] != ""} {
   set tolookfor [lindex $ripped $hcounter]
   set checker [string first $tolookfor $uhost]
   if {$checker != -1} {incr foundit}
   incr hcounter
  }
  if {$foundit == $maxfind} {set allowedflag 1}
 }
 incr ucounter
}
}
if {$allowedflag == 0} {return}
########################################################
#### V6.0 TEAM TRIVIA ANNOUNCEMENT IF TEAMTRIVIA FLAG IS ON!
if {$alreadygoing == 0} {
 if {$teammode == 0} {set ttmode "Normal"}
 if {$teammode == 1} {set ttmode "Battle"}

if {$maxteams != 0} {
  set maxteams2 $maxteams
 }
 if {$maxteamplayers != 0} {
  set maxteamplayers2 $maxteamplayers
 }
 if {$maxteampoints != 0} {
  set maxteampoints2 $maxteampoints
 }
 if {$teamduration != 0} {
  set teamduration2 $teamduration
  set teamduration2 [expr $teamduration2 / 60]
 }


 if {$maxteams == 0} {
  set maxteams2 "No Limit"
  set maxteams 99999999
 }
 if {$maxteamplayers == 0} {
  set maxteamplayers2 "No Limit"
  set maxteams 99999999
 }
 if {$maxteampoints == 0} {
  set maxteampoints2 "No Limit"
 }
 if {$teamduration == 0} {
  set teamduration2 "No Limit"
 }
 
  set counter 0
  set TeamNames ""
  set cnames ""
  if {$maxteams > [llength $TeamNamesToUse]} {
   putquick "privmsg $triviachannel :4Sorry...too many teams requested...maximum number of possible teams is [llength $TeamNamesToUse]!"
  return
  }
  while {$counter != $maxteams} {
   append TeamNames "[lindex $TeamNamesToUse $counter] "
   append cnames " [lindex $colorteamnamestouse $counter]"
   incr counter
 }
 set colorteamnamestouse "$cnames"
  putquick "privmsg $triviachannel :8,1$ttmode 0Team Trivia has been chosen with the following settings:"
  putquick "privmsg $triviachannel :0,1Number of Teams:8 $maxteams0, Maximum Players Per Team:8 $maxteamplayers20, Points Needed To Win The Game:8 $maxteampoints20, Game Duration:8 $teamduration2 0minutes!" 
  putquick "privmsg $triviachannel :0,1Valid Team Names To Join Are: $colorteamnamestouse"
  putquick "privmsg $triviachannel :0,1Type 11!join0 to join a team...type 11!remove0 to leave a team...good luck everyone!"
 if {$teamduration > 0} {
### Determine Start Time Of Team Trivia
set dater [unixtime]
set teamstarttime $dater
###
#  utimer $teamduration "EndTeamTrivia"
 }
####
 set triviastoppedflag 0
 set teamenable 1
Mainproc blah blah blah $triviachannel
 set AnyonePlaying 0
 return 1
}

### Display final team trivia results in-channel here!
putquick "privmsg $triviachannel :8,1******** THE GAME HAS BEEN STOPPED!! ********"
if {$alreadyguessed == 0} {
 putquick "privmsg $triviachannel :$answertitletextcolor,$answertitlebgcolor The answer was:$AText,$ABackground $answer!"
}
putquick "privmsg $triviachannel :0,1******** TEAM TRIVIA FINAL STANDINGS ********"
putquick "privmsg $triviachannel :0,4red: [lindex $TeamPoints 0] 0,2blue: [lindex $TeamPoints 1] 0,6purple: [lindex $TeamPoints 2] 0,3green: [lindex $TeamPoints 3] 0,5brown: [lindex $TeamPoints 4] 1,11cyan: [lindex $TeamPoints 5] 1,8yellow: [lindex $TeamPoints 6] 1,7orange: [lindex $TeamPoints 7] 0,1black: [lindex $TeamPoints 8] 1,0white: [lindex $TeamPoints 9] "
### DETERMINE WINNING TEAM, DISPLAY THEIR STATS AND CONGRATULATE THEM!
putquick "privmsg $triviachannel :0,1*********************************************"
### ORGANIZE ALL TEAM INFO NEATLY FOR DISPLAY:
 set counter 0
  putquick "privmsg $triviachannel :CurrentTeamPlayerTotals: $CurrentTeamPlayerTotals!"
  putquick "privmsg $triviachannel :TeamPlayers, $TeamPlayers!"
  putquick "privmsg $triviachannel :IndividualTeamPoints, $IndividualTeamPoints!"

 while {$counter != $maxteams} {
 set teaminfofordisplay ""
 if {[lindex $CurrentTeamPlayerTotals $counter] != 0} {
  append teaminfofordisplay "[lindex $colorteamnamestouse $counter] team0,1: "
  append teaminfofordisplay "team size:8 [lindex $CurrentTeamPlayerTotals $counter]0, "
#  append teaminfofordisplay "team points:8 [lindex $TeamPoints $counter]0, "
#  append teaminfofordisplay "team players 0: "
#   append teaminfofordisplay "team players 4(11and contributed points4)0: "
 set counter2 0
 if {[lindex $IndividualTeamPoints $counter2] == ""} {
     append teaminfofordisplay "8No Players Yet!"
#      append teaminfofordisplay "8No Players Yet! 4("
#      append teaminfofordisplay "110"
#      append teaminfofordisplay "4)0, "
 }
 while {[lindex $TeamPlayers $counter2] != ""} {
  if {[lindex $TeamPlayers $counter2] == $counter} {
   append teaminfofordisplay "8[lindex $TeamPlayers [expr $counter2 -1]]0, "
#    append teaminfofordisplay "8[lindex $TeamPlayers [expr $counter2 -1]] 4("
#    append teaminfofordisplay "11[lindex $IndividualTeamPoints $counter2]"
#    append teaminfofordisplay "4)0, "
  }
  incr counter2
 }
  putquick "NOTICE $nick :$teaminfofordisplay!"
  }
 incr counter
}
### (NOTE: WHAT IF THERE'S A TIE RESULTING FROM A TIMED GAME?)
set winnerscore 0
set winindex 0
set counter 0
while {[lindex $TeamPoints $counter] != ""} {
 if {[lindex $TeamPoints $counter] > $winnerscore} {
  set winnerscore [lindex $TeamPoints $counter]
  set winindex $counter
 }
 incr counter
}
set winnerstodisplay "[lindex $colorteamnamestouse $winindex]"
set tiegame 0
set counter 0
while {[lindex $TeamPoints $counter] != ""} {
 if {[lindex $TeamPoints $counter] == $winnerscore} {
  incr tiegame
  if {$tiegame > 1} {
    append winnerstodisplay " Team8,1, [lindex $colorteamnamestouse $winindex]"
   }
 }
incr counter
}
if {$winnerscore != 0} {
putquick "privmsg $triviachannel :8,1Congratulations To Everyone on the $winnerstodisplay Team8,1 for a job well done!"
}
if {$winnerscore == 0} {
 putquick "privmsg $triviachannel :0,1All teams have a score of zero points...if anybody was playing then there's no hope for you...please turn off your monitor and walk away quietly...thank you..."
}

### Reset Old Game Variables Here
 set CurrentTeamPlayerTotals "0 0 0 0 0 0 0 0 0 0"
 set TeamPlayers ""
 set TeamPoints "0 0 0 0 0 0 0 0 0 0"
 set IndividualTeamPoints ""
 set teamenable 0
 putquick "privmsg $triviachannel :8,1Trivia has been stopped...type 0!Trivia8 to play normal trivia or 0!TeamTrivia8 to play Team Trivia!"
########### RESET ALL VARS FOUND IN THE !STOPTRIVIA COMMAND
	set triviastoppedflag 1
	set alreadygoing 0
	foreach t [utimers] {
		if [string match *SecondDisplay* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *Advertiser* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
		if [string match *EndTeam* [lindex $t 1]] {
			killutimer [lindex $t end]
		}
				if [string match *Hanging* [lindex $t 1]] {
				        killutimer [lindex $t end]
		}
	}
	set answer ""
	set hint ""
	set question ""
	set triviavalue $origtrivvalue
 	if [info exists nextorder] {unset nextorder}
 	set pointdropcounter 0
########### V6.0: SCRAMBLE CODE: RESET VARS BACK TO TRIVIA
if {$ScrambleRoundChosen == 1} {
 set validbanks $orig_validbanks
 set frequency $orig_frequency
 set triviavalue $orig_trivvalue
 set bonuslengths $orig_bonuslengths
 set bonusvalues $orig_bonusvalues
 set bonusdrops $orig_bonusdrops
 set pointdrops $orig_pointdrops
 set pointdropdelay $orig_pointdropdelay
 set pointdropdecrease $orig_pointdropdecrease
 set minhintletters $orig_minhintletters
 set maxhintletters $orig_maxhintletters
 set hinttimes $orig_hinttimes
 set percentagehintenable $orig_percentagehintenable
 set hintpercentage $orig_hintpercentage
 set hintmethods $orig_hintmethods
 }
utimer 10 "Advertiser"
return
}

bind pub - !remove RemoveTeamPlayer
bind msg - !remove RemoveTeamPlayer

proc RemoveTeamPlayer {nick uhost hand chan args} {
global IndividualTeamPoints colorteamnamestouse TeamNamesToUse alreadygoing maxteams maxteamplayers maxteampoints teamduration teammode triviachannel antifloodenable usercounter commandusers teamenable TeamNames CurrentTeamPlayerTotals TeamPlayers TeamPoints IndividualTeamPoints answertitletextcolor answertitlebgcolor AText ABackground answer
################################
if {[string tolower $chan] != [string tolower $triviachannel]} {return}
################################
if {$antifloodenable == 1} {
 foreach usercounter [array names commandusers] {
   if {[lindex $commandusers($usercounter) 1] == $uhost} {
    return
   }
 }
 set commandusers($usercounter) "$nick $uhost"
}
if {$teamenable == 0} {
  putquick "privmsg $triviachannel :4Team Trivia Mode not enabled...sorry!"
return
}
################################
set nickforfile $nick
### MAIN CODE FOR BAD CHARACTER REPLACEMENTS GO HERE
regsub -all \[{}] $nickforfile "~" nickforfile
regsub -all {[\\]} $nickforfile "|" nickforfile
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
################################

# if {$alreadygoing == 0} {
#   putquick "privmsg $triviachannel :4You can't remove yourself if there's no game $nick...try typing !Trivia first...;)"
#   return
# }
################################
set nickforfile2 $args
### MAIN CODE FOR BAD CHARACTER REPLACEMENTS GO HERE
regsub -all \[{}] $nickforfile2 "~" nickforfile2
regsub -all {[\\]} $nickforfile2 "|" nickforfile2
### END OF NICKFIX FOR LATEST SLASH GLITCH (FIXED AS OF V6.0)
################################
### IS NICK A TEAM LEADER? IF SO, IGNORE THE CHECK BELOW...
### INSTEAD, SEE IF THE DESIRED PLAYER TO REMOVE IS PART OF THIER TEAM...
### IF THEY ARE, THEY ARE REMOVED!
set TeamLeaderFound 0










###
if {$TeamLeaderFound != 1} {
 if {$nickforfile2 != $nickforfile} {
  putquick "notice $nick :4You can only remove yourself...remember you *MUST* type in your nick in order to prevent any accidental removals!"
  return
 }
}
### ALL CHECKS ON NICK HAVE PASSED...LOCATE NICK IN TEAM PLAYERS AND REMOVE
### THEM AND ALL THEIR INFO FROM THE TEAM THEY'RE LOCATED ON!
### (NOTE: POINTS STAY IF MODE = BATTLEMODE
#########################################
  set counter 0
   set PlayerFound 0
   set FoundYou ""
   while {[lindex $TeamPlayers $counter] != ""} {
    if {[lindex $TeamPlayers $counter] == $nickforfile} {
     set PlayerFound 1
     set FoundYou [lindex $colorteamnamestouse [lindex $TeamPlayers [expr $counter +1]]]
     set teamtocheck [lindex $TeamPlayers [expr $counter +1]]
    }
   incr counter
   }
   if {$PlayerFound == 0} {
     putquick "notice $nick :4I don't see you on a team $nick...use !join to join a team!"
     return
 }
   
   if {$PlayerFound == 1} {
##### PLAYER FOUND ON A TEAM...REMOVE ALL INFO
 ### 1) Decrease Total Players On Team Player was on by 1!
 if {$teamtocheck == 0} {
  set newCurrentTeamPlayerTotals " [expr [lindex $CurrentTeamPlayerTotals 0] - 1] "
  append newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals 1 end] "
  set CurrentTeamPlayerTotals $newCurrentTeamPlayerTotals
 }
 if {$teamtocheck > 0} {
  set newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals 0 [expr $teamtocheck -1]] "
  append newCurrentTeamPlayerTotals " [expr [lindex $CurrentTeamPlayerTotals $teamtocheck] -1] "
  append newCurrentTeamPlayerTotals " [lrange $CurrentTeamPlayerTotals [expr $teamtocheck +1] end] "
  set CurrentTeamPlayerTotals $newCurrentTeamPlayerTotals
 }
 ### 2) Remove Player From Team!
set lookingforyou2 0
while {[lindex $TeamPlayers $lookingforyou2] != ""} {
 if {[lindex $TeamPlayers $lookingforyou2] == $nickforfile} {
  set lookingforyou $lookingforyou2
  set foundyouteamscoreindexer [lindex $TeamPlayers [expr $lookingforyou2 +1]]
 }
 incr lookingforyou2
}


 if {$lookingforyou == 0} {
  set TeamPlayers [lrange $TeamPlayers 2 end]
 }
 if {$lookingforyou > 0} {
  set newTeamPlayers " [lrange $TeamPlayers 0 [expr $lookingforyou -1]] "
  append newTeamPlayers " [lrange $TeamPlayers [expr $lookingforyou +2] end] "
  set TeamPlayers $newTeamPlayers
 }
 ### 3) Add Player To IndividualTeamPoints For Tracking Purposes!
if {$teammode == 999} {
  if {$foundyouteamscoreindexer == 0} {
    set newTeamPoints " [expr [lindex $TeamPoints $foundyouteamscoreindexer] - [lindex $IndividualTeamPoints [expr $lookingforyou +1]]] "
    append newTeamPoints " [lrange $TeamPoints 1 end] "
    set TeamPoints $newTeamPoints
  }
  if {$foundyouteamscoreindexer > 0} {
   set newTeamPoints " [lrange $TeamPoints 0 [expr $foundyouteamscoreindexer -1]] "
   append newTeamPoints " [expr [lindex $TeamPoints $foundyouteamscoreindexer] - [lindex $IndividualTeamPoints [expr $lookingforyou +1]]] "
   append newTeamPoints " [lrange $TeamPoints [expr $foundyouteamscoreindexer +1] end] "
   set TeamPoints $newTeamPoints
  }
 }
  if {$lookingforyou == 0} {
   set IndividualTeamPoints [lrange $TeamPlayers 2 end]
  }
  if {$lookingforyou > 0} {
   set newIndividualTeamPoints " [lrange $IndividualTeamPoints 0 [expr $lookingforyou -1]] "
   append newIndividualTeamPoints " [lrange $IndividualTeamPoints [expr $lookingforyou +2] end] "
   set IndividualTeamPoints $newIndividualTeamPoints
 }
#####
putquick "privmsg $triviachannel :8,1$nick has removed themselves from the [lindex $colorteamnamestouse $foundyouteamscoreindexer] team!"
}
return
}


proc WriteRoundScores2 {} {
global dedication AText ABackground answertitletextcolor answertitlebgcolor answertitlebold answerbold gradhinttitletextcolor gradhinttitlebgcolor gradhinttitlebold gradhintbold pointdropcounter FillInLettersEnable HBackground HText ABackground AText LastAnswer antifloodenable minstart autovoicesynch autovoicescore autovoiceenable origtrivvalue fastanswerqty streakscore streakfilename streakhtmlfilename fastanswerscore fastanswerfilename fastanswerhtmlfilename alreadygoing qafile question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed nameofbot nextorder nextquestioncounter triviavalue dayscore dayfilename weekscore weekfilename yearscore yearfilename triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable secondstart
	write_score
	write_dayscore
	write_weekscore
	write_yearscore
        return
}

proc apc {} {
#### NEW CODE FOR COLORING IN KNOWN/UNKNOWN CHARACTERS!
global scrknown scrunknown scrqtc scrqbc scratc scrabc scrhtc scrhbc knowncolor unknowncolor QText QBackground AText ABackground HText HBackground QNText QNBackground qnumboldcode qboldcode ScrambleRoundChosen question scrcluedisplay scrcluegiven knowncolor unknowncolor ucqvenable ucqvpercent ucqvhintpercent qnumbold qbold answertitlebold answerbold pointdropdecrease gradhinttitletextcolor gradhinttitlebgcolor gradhinttitlebold gradhintbold QNText QNBackground manualpointdropdelay showquestioninfoeachpointdrop qtotal pointdrops pointdropcounter origtrivvalue IntervalClueEnable HText HBackground displayenable pointdropdelay showquestioneachpointdrop alreadygoing qafile question AnyonePlaying wonbefore wontimes hintalreadygiven hint answer triviastoppedflag score qafilelength qnumber alreadyguessed triviavalue triviaowner triviachannel validbanks  nextenable nonopsnumber opsnumber hintenable minhintletters maxhintletters showserver autojoin joinmsg autoquit quitmsg EnableAds AdDelay AdsToUse adcounter TipEnable TipsToUse tipcounter TrivDelay HintCharacter botsleep hecklerenable HecklesToUse hecklecounter repeater repeaternumber triviavalue nontriviapiracy nontriviapiracyvariable
set indexer 0
set coloredhint ""
set ohint $hint
### IF CHARACTER IN HINT IS SAME AS IN ANSWER, COLOR KNOWN
### (THIS SHOULD COLOR ALL ,.': TYPE CHARS AS KNOWN!)
while {[string length $hint] >= $indexer} {
 if {[string range $hint $indexer $indexer] == [string range $answer $indexer $indexer]} {
  append coloredhint "$knowncolor[string range $answer $indexer $indexer]" 
 } {
### IF CHARACTER IN HINT IS DIFFERENT THAN IN ANSWER, COLOR UNKNOWN
### (THIS SHOULD COLOR ALL GUESSABLE CHARS AS UNKNOWN!)
  append coloredhint "$unknowncolor[string range $hint $indexer $indexer]" 
 }
incr indexer
}
### ALL THAT SHOULD BE LEFT TO COLOR ARE ANY CHARS THAT MATCH
### THE HINT CHARACTER...USE A REGSUB FOR THEM
### regsub -nocase -all {$HintCharacter} $hint "$knowncolor$HintCharacter" hint
regsub -nocase -all {$HintCharacter} $coloredhint "$knowncolor$HintCharacter" coloredhint
####
regsub -nocase -all "" $hint "" hint
set hint $coloredhint

set hinttodisplay "$HText,$HBackground $hint"
 if {$nontriviapiracy == 1} {
 set letters "fijlt"
 set antipiracy ""
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HText + (16*[rand $nontriviapiracyvariable]))]
} {
 append restorecode $HText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
 append restorecode $HBackground
}
append antipiracy "$restorecode "
##
 set counter 0
 set flipper 0
 set endofqflag 0
 while {[lindex $hint $counter] != "" } {
  set numberflag 0
  set numberchecker [lindex $hint [expr $counter +1]]
  if {[lindex $hint [expr $counter +1]] == ""} {set endofqflag 1}
  set testforanumber 0
  while {$testforanumber <= 9} {
   if {[string range $numberchecker 0 0] == $testforanumber} {
    set numberflag 1
   }
   incr testforanumber
  }
  if {$endofqflag == 1} {
   append antipiracy [lindex $hint $counter]
   set numberflag 10
   set flipper 10
  }
  if {$flipper == 0} {
   set antipiracyletter [string index $letters [rand [string length $letters]]]
   append antipiracy [lindex $hint $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $HBackground
}
append embedcode ","
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $HBackground
}
append antipiracy $embedcode
##
   if {$numberflag == 0} {
    append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HBackground
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HBackground
}
append antipiracy "$restorecode "
##
   }
   set flipper 1
  } {
   if {$flipper != 10} {
    set antipiracyletter " "
    append antipiracy [lindex $hint $counter]
## Random Embedded Character Color Code Creation Routine
set embedcode ""
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $HBackground
}
append embedcode ","
if {$nontriviapiracyvariable > 0} {
append embedcode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append embedcode $HBackground
}
append antipiracy $embedcode
##
   }
   if {$numberflag == 0} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HBackground
}
append antipiracy $restorecode
##

append antipiracy $antipiracyletter
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HBackground
}
append antipiracy $restorecode
##
   }
   if {$numberflag == 1} {
## Random Restoration Of Original Text And Background Color Code Creation Routine
set restorecode ""
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HText + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HText
}
append restorecode ","
if {$nontriviapiracyvariable > 0} {
append restorecode [expr ($HBackground + (16*[rand $nontriviapiracyvariable]))]
} {
append restorecode $HBackground
}
append antipiracy "$restorecode "
##
   }
   set flipper 0
  }
  incr counter
 }
 set qlength [string length $antipiracy]
 set hinttodisplay $antipiracy
}
regsub -nocase -all "" $hinttodisplay "" hinttodisplay
return $hinttodisplay
}
