# SPELLCHK.IRC # Written by tijiez # http://www.jircii.info # # Requires jIRCii version 07.30.05 # # Chat as you normally would. If a misspelled word is found in the dictionary it will be replaced- # automatically. I.e. "i am awya." would be outputted as "I am away." Moreover, to temporarily- # disable spellchecking insert a '\' before the text. I.e. "\don;t cpoy." # set SPCHK_ECHO { return "\t\bSPCH\rK\r ;\b $0-"; } sub necho { echo(parseSet("SPCHK_ECHO", $1)); } sub exists { local('@pass $ref'); @pass = sorta(keys(%words)); foreach $ref (@pass) { if($ref eq $1) { return $ref; } } } sub getUserList { local('$lFile $tmpHandle @aList $fLine $left'); $lFile = getScriptResource("spellchk.irc", "userlist.txt"); if(-exists $lFile && -canread $lFile) { $tmpHandle = openf($lFile); @aList = readAll($tmpHandle); closef($tmpHandle); foreach $fLine (@aList) { $left = iff("|" isin $fLine, substr($fLine, 2, indexOf($fLine, "|")), right($fLine, strlen($fLine) - 2)); if(charAt($fLine, 0) eq "a") { %words[$left] = right($fLine, strlen($fLine) - (indexOf($fLine, "|") + 1)); } else if(charAt($fLine, 0) eq "d") { if(exists($left)) { remove(%words, $left); } } } } } sub getWordList { local('$spelldict $handle @wData $def $x'); $spelldict = getScriptResource("spellchk.irc", "spelldict.txt"); clear(%words); if(-exists $spelldict && -canread $spelldict) { $handle = openf($spelldict); @wData = readAll($handle); foreach $def (@wData) { $x = left($def, indexOf($def, "|")); %words[$x] = substr($def, indexOf($def, "|") + 1, strlen($def)); } closef($handle); if(checkError($error)) { necho("uh oh, " . $error); setProperty("spellchk.on", "false"); } } else { necho("couldn't open spelldict.txt for reading."); setProperty("spellchk.on", "false"); } getUserList(); } alias _getUserList { getUserList(); } alias _getWordList { getWordList(); } sub userSessionUpdate { local('$s'); for($s = 0; $s < getTotalSessions(); $s++) { callInSession($s, "/_getUserList"); } } sub writeWordList { local('$x'); if(strlen($2) > 0 && charAt($2, 0) ismatch '[a-z]') { if($2 ne "eof") { println($file, $2); } else { closef($wSocket); closef($file); necho("download of spelldict.txt completed."); for($x = 0; $x < getTotalSessions(); $x++) { callInSession($x, "/_getWordList"); } } } } sub webUpdate { local('$tmp'); $tmp = getScriptResource("spellchk.irc", "spelldict.txt"); if(-canwrite $tmp || !-exists $tmp) { $file = openf(">" . getScriptPath("spellchk.irc") . "/spelldict.txt"); $wSocket = connect("67.19.69.116", 80); println($wSocket, "GET /spelldict.txt HTTP/1.1"); println($wSocket, "Host: www.leenux.net"); println($wSocket, "User-Agent: jIRCii " . versionString()); println($wSocket, "Connection: close\n"); read($wSocket, &writeWordList); } else { necho("download of spelldict.txt failed."); } } sub writeUserList { local('$wFile'); $wFile = openf(">>" . getScriptPath("spellchk.irc") . "/userlist.txt"); println($wFile, $1); closef($wFile); } sub spellchk { local('$token $c $str $append $what'); $token = tokenize($1, " "); for($c = 0; $c < getTotalTokens($token); $c++) { $str = getToken($token, $c); if(strlen($str) > 1 && charAt($str, strlen($str) - 1) ismatch '[\.\?!:;,]') { $append = charAt($str, strlen($str) - 1); $str = left($str, strlen($str) - 1); } $what = $what . iff(exists($str), %words[$str] . iff(!$append, "", $append), $str . $append) . " "; $append = $null; } return left($what, strlen($what) - 1); } menu __options { item "Close Window" { closeWindow(getActiveWindow()); } } alias sp { if(lc($1) eq "on" || lc($1) eq "off") { setProperty("spellchk.on", iff(lc($1) eq "on", "true", "false")); necho("script turned, \b" . lc($1) . "\b."); } else if(lc($1) eq "add") { if($2 && $3) { writeUserList(charAt($1, 0) . "!" . $2 . "|" . $3-); userSessionUpdate(); necho("entry added."); } else { necho("wrong syntax. try /sp \badd\b \uwrongword\u \urightword\u"); } } else if(lc($1) eq "del") { if($2) { if(exists($2)) { writeUserList(charAt($1, 0) . "!" . $2); userSessionUpdate(); necho("entry deleted."); } else { necho("that word didn't exist."); } } else { necho("wrong syntax. try /sp \bdel\b \uwrongword\u"); } } else if(lc($1) eq "sync") { necho("syncing dictionary with leenux.net."); webUpdate(); } else { echo("\t\b.s\bpellchk\b.i\b\rrc\r \bv\b2 [s: \r" . size(keys(%words)) . "\r]"); echo("\t\t/sp \bon\b|\boff\b - alter script state"); echo("\t\t/sp \badd\b \uwrongword\u \urightword\u - add word to dictionary"); echo("\t\t/sp \bdel\b \uwrongword\u - remove word from dictionary"); echo("\t\t/sp \bsync\b - update dictionary file"); echo("\t\t/spdict - show dictionary window"); } } alias spdict { local('@keyList $b @items $title $cat $win'); @keyList = keys(%words); foreach $b (@keyList) { push(@items, $b . "\t" . %words[$b]); } $title = "Dictionary"; $cat = "Replace This"; if(!-iswindow $title) { $win = showSortedList($title, "__options", sorta(@items), "$[10]cat", "With That"); refreshData($win); } activateWindow($title); } on input { local('$new'); if(-isSetF "spellchk.on" && strlen($1-) > 1) { $new = spellchk($1-); if(($1- ne $new && charAt($1, 0) ne "/") || "\\" isin $1) { iff(charAt($1, 0) eq "\\", say(right($1-, strlen($1-) - 1)), say($new)); halt; } } } if(getProperty("spellchk.ver") ne "v2") { necho("script loaded, thanks for downloading."); necho("http://www.jircii.info"); setProperty("spellchk.ver", "v2"); webUpdate(); call("/sp"); } else { getWordList(); } setProperty("spellchk.on", "true");