menu menubar {
  -
  ScraBoggle
  .$iif($group(#scraboggle) == on,$style(1),$style(0)) On && Set SB Chan: enable #ScraBoggle | scinit | set %ScraBoggle Loaded | msg %SBchan ScraBoggle ~ Enabled. Type !ScraBoggle to Play | echo %SBchan Scraboggle - on 
  .$iif($group(#scraboggle) == off,$style(1),$style(0)) Off && UnSet SB Chan: disable #ScraBoggle | unset %SBchan | set %ScraBoggle Unloaded | msg # ScraBoggle ~ Disabled. Thanks for playing ScraBoggle | echo -a Scraboggle - off
  .-  
  .View Scraboggle Channel: echo -a Scraboggle channel currently set to %SBchan
  .Reset Score Files : write -c ScraBoggleScores.ini | write -c ScraBoggleFilteredScores.txt | echo %SBchan All Scraboggle Scores Reset
  .Create Scores HTML: { ScraBogglehtmlbuild }
  .Read HTML Scores: run Iexplore.exe $scriptdir\ScraBoggle.htm
  .- 
  .ScraBoggle Dictionary: run notepad.exe text\dictionary.txt 
  .Word Submissions: run notepad.exe text\ScraBoggleaddword.txt 
  -
}

#ScraBoggle off

On *:TEXT:!ScraBoggle:#: { 
  if (!%msg.ScraBoggle. [ $+ [ $nick ] ]) { Docoll purple b (dk) Lets play ScraBoggle (dk) . } 
  if (!%msg.ScraBoggle. [ $+ [ $nick ] ]) { Docoll darkred b :P Type !SbStart to play, !SBHelp for commands  } 
  set -u5 %msg.Boggle. [ $+ [ $nick ] ] $true 
} 

on Zyrus:text:*:%SBchan: checkoptext $strip($1-) 
on Zyrus:action:*:%SBchan: checkoptext $strip($1-) 

on *:text:*:%SBchan: { playgame $Strip($1-) | if (%ScraBoggle.Playing == Yes) ScraBoggleIdleTimers } 
on *:action:*:%SBchan: { playgame $Strip($1-) | if (%ScraBoggle.Playing == Yes) ScraBoggleIdleTimers } 

on *:start: { 
  scinit start 
} 

alias scinit {
  set %sbchan $chan 
  set %ScraBoggle.Playing No 
  set %ScraBoggle.Font Verdana 
  set %ScraBoggle.Min 3 
  set %ScraBoggle.Max 10 
  set %ScraBoggle.ReSpam 6 
  ;if ($1 != ScraBoggleStart) { describe $me has initialized the ScraBoggle game. Type !ScraBoggle for play (Y) | return } 
} 

alias CheckOpText { 
  if ($1 == @SBReset) { scinit $2 | return } 
  if ($1 == @SBStart) { startgame $2- | return } 
  if ($1 == @SBStop) { stopgame $2- | return } 
  if ($1 == @SBSpam) { dospam | return } 
  if ($1 == @SBLetters) { spamword | return } 
  if ($1 == @SBScores) { showallscores | return } 
  if ($1 == @SBAdminCommands) { doScraBoggleAdminCommands | return } 
  playgame $1- 
} 

alias PlayGame { 
  if ($1 == !SBStart) { startgame $2- | return } 
  if ($1 == !SBStop) { stopgame $2- | return } 
  if ($1 == !SBScores) { showallscores | return } 
  if (!SBHelp isin $1) { dohelp | return } 
  if (!SBCommands isin $1) { doScraBoggleCommands | return } 
  if (!SBAdminCommands isin $1) { doScraBoggleAdminCommands | return } 
  if (!SBChamp isin $1) { doScraBoggleChamp | return } 
  if (!SB5 isin $1) { doScraBoggleTop5 | return } 
  if (!SBStat isin $1) && ($2) { doScraBoggleStatother $2 | return } 
  if (!SBStat isin $1) { doScraBoggleStat $nick | return } 
  if (!SBObject isin $1) { doScraBoggleObject | return } 
  if (!SBAddword isin $1) { doScraBoggleAddword $2- | return } 
  if (%ScraBoggle.Playing == No) return 
  inc %ScraBoggle.LinesSaid 1 
  if (%ScraBoggle.Playing != Yes) return 
  if ($Len($1) >= %ScraBoggle.Min) { 
    set %ScraBoggle.Guess $upper($1) 
    set %ScraBoggle.Check %ScraBoggleDone. [ $+ [ %ScraBoggle.Guess ] ] 
    if (%ScraBoggle.Check != $null) { 
      ; Don't show who said it 
      showaction %ScraBoggle.Check said %ScraBoggle.Guess 
      return 
    } 
    ; Check for letters being used more than once etc... 
    if ($checkletters(%ScraBoggle.Guess, %rand10) == bad) return 
    ; Do not check words automatically 
    if ($validateword(%ScraBoggle.Guess) == bad) return 
    DoColl darkgreen b :P $nick scores $len($1) points for %ScraBoggle.Guess 
    .timerScraBoggleIdle 1 300 StopIdle 
    set %ScraBoggleDone. $+ %ScraBoggle.Guess $nick 
    addpoint $nick $len(%ScraBoggle.Guess) 
  } 
  if (%ScraBoggle.LinesSaid >= %ScraBoggle.ReSpam) { spamword } 
} 

alias AddPoint { 
  var %Score $readini(ScraBoggleScores.ini, $1, score) 
  inc %Score $2 
  writeini ScraBoggleScores.ini $1 score %Score 
} 

Alias DoScraBoggleCommands { 
  ctcpreply $nick TIME type !SBStart ~ to Begin Game (*) 
  ctcpreply $nick TIME type !SBStop ~ to End Game (*) 
  ctcpreply $nick TIME type !SBChamp ~ to See CHAMP Score (*) 
  ctcpreply $nick TIME type !SB5 ~ to See Top 5 Scores (*) 
  ctcpreply $nick TIME type !SBStat ~ to See Your Score (*) 
  ctcpreply $nick TIME type !SBStat <nickname> ~ to See That Player's Score (*) 
  ctcpreply $nick TIME type !SBScores ~ to See Current Players Scores (*) 
  ctcpreply $nick TIME type !SBObject ~ to See object of the game (*) 
} 

Alias DoScraBoggleAdminCommands { 
  ctcpreply $nick TIME (*) You have use of all normal commands (*) 
  ctcpreply $nick TIME type @SBReset ~ to Reinitialize Game (*) 
  ctcpreply $nick TIME type @SBtart ~ to Start Game (*) 
  ctcpreply $nick TIME type @SBStop ~ to Stop Game (*) 
  ctcpreply $nick TIME type @SBScores ~ to See Current Players Scores (*) 
  ctcpreply $nick TIME type @SBSpam ~ to Spam Game (*) 
  ctcpreply $nick TIME type @SBLetters ~ to Spam current Letter Set (*) 
} 

alias DoHelp { 
  ctcpreply $nick TIME (*) ScraBoggle ~ Help (*) 
  ctcpreply $nick TIME type !SBObject to see the object of the game 
  ctcpreply $nick TIME type !SBCommands for game commands 
  ctcpreply $nick TIME type !SBAddword <word> to submit the word to Game Dictionary  
} 

alias StartGame { 
  if (%ScraBoggle.Playing == Yes) return 
  DoColl teal b :P Starting ScraBoggle. The first Letter Set will appear in 5 seconds :P  (o)Type !SBHelp for ScraBoggle help at any time. 
  DoColl red b (o) Now is a good time to click Ignore on me, if you dislike the game (Y)
  .timerScraBoggleIdle 1 300 StopIdle  
  .timerScraBogglestart 1 5 ShowWord 
} 

alias ShowWord { 
  setrand10
  Docoll dark b (dk) Your ScraBoggle Letters are %rand10 (dk)
  DoColl green b :P You have 70 seconds to type as many words as you can of %ScraBoggle.Min letters or more, made from the letters of the ScraBoggle Set :P 
  set %ScraBoggle.Playing Yes 
  unset %ScraBoggleDone.* 
  set %ScraBoggle.LinesSaid 0 
  .timerScraBoggleTimer 1 70 EndWord 
} 

alias EndWord { 
  DoColl darkred b (o) Time Is Up! 
  set %ScraBoggle.Playing No 
  DoColl darkNavy b Next ScraBoggle Set in 50 seconds.
  DoColl darkred b Type !SBStat to see own score. :D
  .timerdotop 1 4 DoWhat
  .timerScraBoggleTimer 1 50 ShowWord 
} 

alias setrand10 { 
  set %rand10 $null 
  var %i = 10 
  while (%i > 0) { 
    var %vow = $regex(%rand10,/[AEIOUY]/g) 
    if (((%i < 4) && (%vow < 2)) || ((%i = 1) && (%vow < 3))) { 
    %rand10 = %rand10 $+ $mid(AEIOUY,$r(1,6),1) } 
    else %rand10 = %rand10 $+ $r(A,Z) 
    dec %i 
  } 
} 

alias StopGame { 
  .timerScraBoggleTimer off 
  DoColl darkred b [br] [br] (brb) ScraBoggle has stopped. Type !SBStart to play again :d 
  set %ScraBoggle.Playing No 
} 

alias StopIdle { 
  .timerScraBoggleTimer off 
  DoColl darkred b [br] [br] (brb) No Play for 5 Minutes ~ ScraBoggle has stopped. Type !SBStart to play again. |^: 
  set %ScraBoggle.Playing No 
} 

alias showallscores {
  var %x 1 
  var %ScraBoggleScores [br]
  while (%x <= $nick($RName,0)) { 
    set %Name $nick($RName,%x)
    var %ScraBoggleScore = $getscore(%Name) 
    if (%ScraBoggleScore != 0) var %ScraBoggleScores %ScraBoggleScores [br] %Name = %ScraBoggleScore
    inc %x 
  }
  var %ScraBoggleScores ScraBoggle %ScraBoggleScores
  msg $RName %ScraBoggleScores
  return
}

alias GetScore { 
  var %Score $readini(ScraBoggleScores.ini, $1, score) 
  inc %Score 0 
  return %Score 
} 
alias docoll { 
  if ($1-2 == darkgreen b) { show S Tahoma;0 $3-  } 
  elseif ($1-2 == teal b) { show S Tahoma;0 $3-  } 
  elseif ($1-2 == darkred b) { show S eTahoma;0 $3-  } 
  elseif ($1-2 == red b) { show S eTahoma;0 $3-  } 
  elseif ($1-2 == darkNavy b) { show S eTahoma; $3-  } 
  elseif ($1-2 == Navy b) { show S Tahoma;0 $3-  }
  elseif ($1-2 == dark b) { show S Tahoma;0 $3-  } 
  elseif ($1-2 == purple b) { show S Tahoma;0  $3-  } 
}

Alias DoScraBoggleObject { 
  ctcpreply $nick TIME :P We're Playing ScraBoggle :P [br]The object is to make as many 3 or more letter words in one minute as you can, from the ScraBoggle Letters given. 
  ctcpreply $nick TIME Type quickly; Only the first person to say them in each round will gain points. Type !SBHelp for full details.(*) [br]Core coding from Frenzy game by alphawolf & geezer, enhanced by CalSingle & [Ice][Angel] & Petertje.
} 

alias DoScraBoggleChamp { 
  DoScraBogglesort 
  Docoll darkred b [br] Current ScraBoggle Champ is ({) $gettok($read(ScraBoggleFilteredScores.txt,1),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,1),2,32) 
} 

alias DoScraBoggleTop5 { 
  DoScraBoggleSort 
  Docoll purple b ScraBoggle's Current Leaders  
  if ($read(ScraBoggleFilteredScores.txt,1)) { Docoll purple b 1. ({) $gettok($read(ScraBoggleFilteredScores.txt,1),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,1),2,32) } 
  if ($read(ScraBoggleFilteredScores.txt,2)) { Docoll purple b 2. ({) $gettok($read(ScraBoggleFilteredScores.txt,2),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,2),2,32) } 
  if ($read(ScraBoggleFilteredScores.txt,3)) { Docoll purple b 3. ({) $gettok($read(ScraBoggleFilteredScores.txt,3),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,3),2,32) } 
  if ($read(ScraBoggleFilteredScores.txt,4)) { Docoll purple b 4. ({) $gettok($read(ScraBoggleFilteredScores.txt,4),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,4),2,32) } 
  if ($read(ScraBoggleFilteredScores.txt,5)) { Docoll purple b 5. ({) $gettok($read(ScraBoggleFilteredScores.txt,5),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,5),2,32) } 
} 

alias DoWhat { 
  DoScraBoggleSort 
  Docoll purple b ScraBoggle's Current Leaders  
  if ($read(ScraBoggleFilteredScores.txt,1)) { Docoll purple b 1. ({) $gettok($read(ScraBoggleFilteredScores.txt,1),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,1),2,32) } 
  if ($read(ScraBoggleFilteredScores.txt,2)) { Docoll purple b 2. ({) $gettok($read(ScraBoggleFilteredScores.txt,2),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,2),2,32) } 
  if ($read(ScraBoggleFilteredScores.txt,3)) { Docoll purple b 3. ({) $gettok($read(ScraBoggleFilteredScores.txt,3),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,3),2,32) } 
  if ($read(ScraBoggleFilteredScores.txt,4)) { Docoll purple b 4. ({) $gettok($read(ScraBoggleFilteredScores.txt,4),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,4),2,32) } 
  if ($read(ScraBoggleFilteredScores.txt,5)) { Docoll purple b 5. ({) $gettok($read(ScraBoggleFilteredScores.txt,5),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,5),2,32) } 
} 

alias DoScraBoggleSort { 
  var %a = 1, %b = $ini(ScraBoggleScores.ini,0) 
  .remove ScraBoggleFilteredScores.txt 
  while (%a <= %b) { 
    write ScraBoggleFilteredScores.txt $ini(ScraBoggleScores.ini,%a) $readini(ScraBoggleScores.ini,$ini(ScraBoggleScores.ini,%a),score) 
    inc %a 
  } 
  filter -ffcteu 2 32 ScraBoggleFilteredScores.txt ScraBoggleFilteredScores.txt 
} 

alias DoScraBoggleStat { 
  DoScraBoggleSort 
  if (!$read(ScraBoggleFilteredScores.txt,w,* $+ $1 $+ *)) { 
    ctcpreply $1 TIME [br] I'm sorry, :S but you have yet to score! 
  } 
  if ($read(ScraBoggleFilteredScores.txt,w,* $+ $1 $+ *)) { 
    ctcpreply $1 TIME [br](o) Your current ScraBoggle score is ({) $gettok($read(ScraBoggleFilteredScores.txt, $readn),2,32) 
  } 
  ctcpreply $1 TIME [br](o)(*) Current ScraBoggle Champ is ({) $gettok($read(ScraBoggleFilteredScores.txt,1),1,32) with (H) $gettok($read(ScraBoggleFilteredScores.txt,1),2,32)  
} 

alias DoScraBoggleStatother { 
  DoScraBoggleSort 
  if (!$read(ScraBoggleFilteredScores.txt,w,* $+ $1 $+ *)) { 
    ctcpreply $nick TIME [br] :P I'm sorry, but $2 has yet to score! 
  } 
  if ($read(ScraBoggleFilteredScores.txt,w,* $+ $1 $+ *)) { 
    ctcpreply $nick TIME [br](o) $1 $+ 's current ScraBoggle score is ({) $gettok($read(ScraBoggleFilteredScores.txt, $readn),2,32)
  } 
} 

alias DoSpam { 
  doColl darkNavy b :P We're Playing ScraBoggle :P [br] :P The object is to make as many 3 or more letter words in one minute, as you can out of the letters given. 
  doColl Navy b :P Type quickly; Only the first person to say them in each round will gain points. Type !SBHelp for full details. 
} 

alias SpamWord { 
  if (%ScraBoggle.Playing == No) return 
  DoColl darkNavy b (dk) Your ScraBoggle Letters are %rand10 (dk) 
  set %ScraBoggle.LinesSaid 0 
} 


; The ScraBoggleIdleTimers alias prevents the game running nonstop when nobody is playing.
; It turns off the game after 5 minutes of no playing.
; To disable it, so it WILL keep going, just put a semi-colon ; in front of the line below
alias ScraBoggleIdleTimers { 
  .timerScraBoggleIdle off 
  .timerScraBoggleIdle 1 300 StopIdle 
} 

; Dictionary routine (C) 2003 Geezer & Wolf 
; checks if word is in dictionary.txt - wordlist provided by Justin White 

; $validateword(word) - returns good or bad 
alias ValidateWord { 
  set %D.Word *. $+ $1 $+ .* 
  if ($read(text\dictionary.txt, w, %D.Word ) == $null) { return bad } 
  else { return good } 
} 

; $checkletters(word, letters) - returns good or bad 
alias CheckLetters { 
  set %D.FLetters $2 
  set %D.WLet 0 
  set %D.Letters $len($1) 
  while (%D.WLet < %D.Letters) { 
    inc %D.WLet 
    set %D.CLet $mid($1,%D.WLet,1) 
    set %D.FLet $pos(%D.FLetters, %D.CLet, 1) 
    if (%D.FLet == $null) return bad 
    if (%D.FLet == 1) { set %D.FLetters $mid(%D.FLetters, 2, $calc($Len(%D.FLetters) - 1)) } 
    if (%D.FLet == $len(%D.FLetters)) { set %D.FLetters $mid(%D.FLetters, 1, $calc($Len(%D.FLetters) - 1)) } 
    if (%D.FLet > 1) && (%D.FLet < $len(%D.FLetters)) { 
      set %D.FLetters $mid(%D.FLetters, 1, $Calc(%D.FLet -1) ) $+ $mid(%D.FLetters, $calc(%D.FLet +1 ), $Len(%D.Fletters) - %D.FLet) 
    } 
  } 
  return good 
} 

alias showaction { describe %SBchan $1- } 

alias show { msg %SBchan $1- } 


alias doScraBoggleAddword { 
  privmsg $nick :P Thanks for your ScraBoggle word addition (e) It has been recorded, and will be read later (Y) $+ 
  write text\ScraBoggleAddword.txt $date $time $bdc($nick)  << Add Word = >> $1- 
  echo %SBchan $dspot(ScraBoggle Add Word from $nick Recorded) 
} 

alias ScraBoggleHtmlbuild { 
  var %start.ticks = $ticks 
  if ($exists(ScraBoggle.html)) { .remove ScraBoggle.html } 
  doScraBoggleSort 
  if ($exists(ScraBoggle.htm)) { .remove ScraBoggle.htm } 
  write ScraBoggle.htm <HTML><head><title> $+ ScraBoggle Scores By: CalSingle & [Ice][Angel] (code by NightChillz) $+ </title></head> 
  write ScraBoggle.htm <body bgcolor="#000000" text="#339933" link="#33FF00" alink="#666600" vlink="#666666"> 
  write ScraBoggle.htm The Scores File was Compiled By: CalSingle & [Ice][Angel] <br> 
  write ScraBoggle.htm The Creation Date of the Scores file is: $time $adate <br><ol> 
  write ScraBoggle.htm <table BORDER COLS=3 WIDTH="100%" > 
  write ScraBoggle.htm <tr> 
  write ScraBoggle.htm <TR> 
  write ScraBoggle.htm <TH>Ranking</TH><TH>Name</TH><TH>Score</TH> 
  write ScraBoggle.htm </TR> 
  var %i = 1, %x = $lines(ScraBoggleFilteredScores.txt) 
  while (%i <= %x) { 
    write ScraBoggle.htm <tr><TH> $+ %i $+ </TH> <td> $+ $gettok($read(ScraBoggleFilteredScores.txt, %i),1,32) $+ </td> <td> $+ $gettok($read(ScraBoggleFilteredScores.txt, %i),2,32) $+ </td> </tr> 
    inc %i 
  } 
  write ScraBoggle.htm </table><br> 
  echo 12ScraBoggle ~ HTML Created = 3 in $calc(($ticks - %start.ticks) / 1000) $+ secs. 
} 

#ScraBoggle end
