Code: Select all
# dictionary.com script - rosc2112 at yahoo com - Copyright C.Leonhardt 2006
# http://members.dandy.net/~fbn/dictcom.tcl.txt
set dcdictver "0.02l"
#
# This script pulls definitions from dictionary.reference.com. It can show suggested spellings if you
# misspell a word, shows results including the pronunciation key, parts of speech, definitions, word origin,
# synonyms and antonyms. You can also search for phrases/idioms, cities, states, countries, zipcodes, etc.
# Check the list of available databases in the helpfile, that gives a good indication of the retrievable data.
#
# Usage: .dict dicthelp |
# or .dict | Show the helpfile (typed in privmsg or in channel)
#
# History - Oct. 08 2006 - Initial conception
# - Oct. 11 2006 - Added more db's, added ability for user to specify line-limit (still respecting
# admin's choice of max line-limit, and added option for admin to allow user to
# override that limit or not), etc.
# - Removed dcorigin/dcsynant options, added combined commandline options.
# - Added a 'dbmatch' option to show which databases a word might be found in.
# - Added the rest of the db's (if dictionary.com provided the VERA, GCIDE and
# Ambrose Bierce's Devil's dictionaries, this script would be complete compared to
# db's available from dict.org.)
# - Consolidated redundant regexp's into a seperate proc.
# Oct. 12 2006 - Minor changes to dbnames.
# Oct. 13 2006 - Fixed a mistake in the variable used for selecting a database.
# Added a string map for 'dbmatch' to show the dbname's as used in the script (rather
# than the names as known to dictionary.com)
# - Added additional error msg when user selects a database and the word is not found.
# - Changed proc dictmsg test to see if user is either on the channel or validuser,
# if neither, script quietly returns (unknown users outside of channels cannot use.)
# - Made a configuration option for limiting input length.
# - Forgot to initialize dcactivelimit if no dclinelimit is specified in the configs.
# - Added error msgs when user tries dcorigin or dcsyn options and specifies a db other
# than dbluna (origin, and synonyms/antonyms not available from other db's.)
# Oct. 14 2006 - Fixed a typo in otherdb regexp (dbwsw was misspelled.)
# Oct. 17 2006 - Gah...another typo (missing bracket in the dictmsg proc :P)
# - Added a 'string is integer' check for dclimit, some other tweaks to dclimit..
# - Changed dclimit section again, to handle 'dclimit' cmd in any order.
# Oct. 18 2006 - Tweaked 'additional suggestions' so it doesn't show | on end of string.
# Nov. 14 2006 - Various html/unicode chars added to the string map.
# Dec. 03 2006 - Website changes/code fixed.
# Dec. 07 2006 - More string map additions.
#
# Databases: Dictionary.com Unabridged Dictionary; Webster's 1913 Unabridged Dictionary;
# Webster's New Millenium Dictionary; WordNet Dictionary; American Heritage Dictionary;
# American Heritage Stedman's Medical Dictionary; American Heritage Dictionary of Idioms;
# Merriam-Webster Medical Dictionary; Merriam-Webster Law Dictionary; Investopedia; Wall Street Words;
# Easton's 1897 Bible Dictionary; Hitchcock's Bible Names Dictionary;Free On-line Dictionary of Computing;
# Jargon File; US Gazetteer 1990 Census; CIA 1995 World Factbook; Atomic Elements Database.
#
# There will no doubt be unicode chars/html that are not in the string map "set smaps" for substituting the
# html code with the real characters. If you come across these, please send me a note about them so I can add
# them into the string map for future versions.
#
# TODO: New databases: American Heritage Science Dictionary; American Heritage Abbreviations Dictionary;
# American Heritage New Dictionary of Cultural Literacy.. Hmm well, I went to add these
# today and they're no longer showing up on the website. I'll keep notes and if they become
# permanent additions to dictionary.com, I'll add them.
#
################################################################################################################
# Configs:
#~~~~~~~~~
# Channels where we allow public use
set dcomchans "#elegance"
# Channels that respond only via privmsg
set dcquietchans "#elegance"
# Timeout for geturl (1/1000th's of a second)
set dcomtimeout "30000"
# If you want to limit output, set the max number of lines to output here (this will truncate results.)
# Set to 0 for no-limit (show the complete definition results, which could be *extremely* long.)
set dclinelimit 40
# Allow users to specify a higher limit (override dclinelimit)? This option has no effect unless dclinelimit is
# set to a number above zero. Output is sent to privmsg instead of channel when dclinelimit and this option
# are enabled together, when the user chooses a 'dclimit' higher than dclinelimit.
# Set to 1 == yes, 0 == no
set dclineoride 1
# Set the max input length (number of chars.) IRC has an input limit of about 400 chars but that may be excessive.
# Set this var to 0 if you do not want any input limit.
set dcmaxlength 150
################################################################################################################
# Code begins #
###############
package require http 2.3
bind pub - .dict dictpub
bind msg - .dict dictmsg
proc dictmsg {nick uhost hand text} {
if {(![onchan $nick]) && (![validuser $nick])} {return}
dictpub $nick $uhost $hand privmsg $text
return
}
proc dictpub {nick uhost hand chan text} {
if {([lsearch -exact $::dcomchans $chan] == -1) && ($chan != "privmsg")} {return}
if {([lsearch -exact $::dcquietchans $chan] != -1) || ($chan == "privmsg")} {set chan $nick}
set text [string trim $text];set text [split $text]
if {$::dclinelimit > 0} {set dcactivelim $::dclinelimit} else {set dcactivelim 0}
set dcomdef "";set ahddef "";set websterdef "";set amsmddef "";set mwmeddef "";set pronun "";set defins ""
set dcori "";set dcsynon "";set word1 "";set dcsuggests "";set i 0;set dcanton "";set dictname ""
set showdcorigin 0;set showsynant 0;set otherdb 0;set templim "";set templim2 "";set investdef ""
set wswdef "";set remvar "";set showdef 0;set dbmatches "";set dbmatch1 "";set showmatch 0
set newdbl "";set dcomurl "";set ahdidef "";set foldef "";set eastdef "";set gazdef "";set jardef ""
set mlawdef "";set wmdef "";set wndef "";set w95def "";set hitdef "";set elmdef "";set dbvar ""
set dblist [list dbluna dbahd dbweb dbamd dbmmd dbinv dbwsw dbahi dbeast dbfold dbgaz dbjar dbmlaw dbwnm dbword dbcia dbhit dbelem]
set dbmatchlist [list luna ahd4 web1913 ahsmd mwmed ivst wsw ahdi easton foldoc gazetteer jargon mwlaw wmde wn world95 hitchcock elements]
# user asking for matching db names only
if {[set remvar [lsearch -exact $text dbmatch]] != -1} {
set showmatch 1
set text [lreplace $text $remvar $remvar]
set text [string trim [join $text]]
}
# user asking for 'origin' output only
if {[set remvar [lsearch -exact $text dcorigin]] != -1} {
set showdcorigin 1;set showdef 1
set text [lreplace $text $remvar $remvar]
set text [string trim [join $text]]
}
# user asking for synonyms/antonyms only
if {[set remvar [lsearch -exact $text dcsyn]] != -1} {
set showsynant 1;set showdef 1
set text [lreplace $text $remvar $remvar]
set text [string trim [join $text]]
}
# user setting a line limit to restrict number of definition lines shown.
if {[set remvar [lsearch $text dclimit:*]] != -1} {
set templim [lindex $text $remvar];set templim2 [lindex [split $templim :] 1]
set templim2 [string trimleft $templim2 0]
if {$templim2 == ""} {
set dcactivelim 1
puthelp "PRIVMSG $nick :dclimit cannot be below 1, so we'll use a limit of 1 line.."
} elseif {![string is integer -strict $templim2]} {
puthelp "PRIVMSG $nick :dclimit requires a number, not '$templim2'"
return
} elseif {$templim2 < 1} {
set dcactivelim 1
puthelp "PRIVMSG $nick :dclimit cannot be below 1, so we'll use a limit of 1 line.."
} else {
if {$::dclinelimit > 0} {
if {($::dclineoride == 0) && ($templim2 > $::dclinelimit)} {
puthelp "PRIVMSG $chan :Admin has set a strict line limit of $::dclinelimit max lines. Cannot override."
} elseif {($::dclineoride == 1) && ($templim2 > $::dclinelimit)} {
puthelp "PRIVMSG $nick :Overriding line limit with dclimit $templim2 (results will be sent to privmsg.)"
set chan $nick
set dcactivelim $templim2
} else {
set dcactivelim $templim2
}
} else {
set dcactivelim $templim2
}
}
set text [lreplace $text $remvar $remvar]
set text [string trim [join $text]]
}
# user asking to search a specific database
# otherdb's: 0=dbluna 1=dbahd 2=dbweb 3=dbamd 4=dbmmd 5=dbinv 6=dbwsw 7=dbahi 8=dbeast 9=dbfold 10=dbgaz
# 11=dbjar 12=dbmlaw 13=dbwnm 14=dbword 15=dbcia 16=dbhit 17=dbelem
if {[regexp {(\mdbluna\M|\mdbahd\M|\mdbweb\M|\mdbamd\M|\mdbmmd\M|\mdbinv\M|\mdbwsw\M|\mdbahi\M|\mdbeast\M|\mdbfold\M|\mdbgaz\M|\mdbjar\M|\mdbmlaw\M|\mdbwnm\M|\mdbword\M|\mdbcia\M|\mdbhit\M|\mdbelem\M)} $text match dbvar]} {
set remvar [lsearch -exact $text $dbvar]
switch -- $dbvar {
"dbluna" {set otherdb 0;set dcomurl "http://dictionary.reference.com/search?db=luna&q="}
"dbahd" {set otherdb 1;set dcomurl "http://dictionary.reference.com/search?db=ahd4&q="}
"dbweb" {set otherdb 2;set dcomurl "http://dictionary.reference.com/search?db=web1913&q="}
"dbamd" {set otherdb 3;set dcomurl "http://dictionary.reference.com/search?db=ahsmd&q="}
"dbmmd" {set otherdb 4;set dcomurl "http://dictionary.reference.com/search?db=mwmed&q="}
"dbinv" {set otherdb 5;set dcomurl "http://dictionary.reference.com/search?db=ivst&q="}
"dbwsw" {set otherdb 6;set dcomurl "http://dictionary.reference.com/search?db=wsw&q="}
"dbahi" {set otherdb 7;set dcomurl "http://dictionary.reference.com/search?db=ahdi&q="}
"dbeast" {set otherdb 8;set dcomurl "http://dictionary.reference.com/search?db=easton&q="}
"dbfold" {set otherdb 9;set dcomurl "http://dictionary.reference.com/search?db=foldoc&q="}
"dbgaz" {set otherdb 10;set dcomurl "http://dictionary.reference.com/search?db=gazetteer&q="}
"dbjar" {set otherdb 11;set dcomurl "http://dictionary.reference.com/search?db=jargon&q="}
"dbmlaw" {set otherdb 12;set dcomurl "http://dictionary.reference.com/search?db=mwlaw&q="}
"dbwnm" {set otherdb 13;set dcomurl "http://dictionary.reference.com/search?db=wmde&q="}
"dbword" {set otherdb 14;set dcomurl "http://dictionary.reference.com/search?db=wn&q="}
"dbcia" {set otherdb 15;set dcomurl "http://dictionary.reference.com/search?db=world95&q="}
"dbhit" {set otherdb 16;set dcomurl "http://dictionary.reference.com/search?db=hitchcock&q="}
"dbelem" {set otherdb 17;set dcomurl "http://dictionary.reference.com/search?db=elements&q="}
}
set text [lreplace $text $remvar $remvar]
set text [string trim [join $text]]
if {$showmatch == 1} {
#user asked to show matching databases (dbmatch) so we can't use the other databases.
set otherdb 0;set dcomurl "http://dictionary.reference.com/search?q="
}
}
if {($text == "dicthelp") || ($text == "")} {
puthelp "PRIVMSG $nick :\002Dictionary.com TCL\002 - Commands are typed in PRIVMSG to $::botnick or in channel:"
puthelp "PRIVMSG $nick :Parameters shown in \002<>\002 are required, while \002\[\]\002 are optional."
puthelp "PRIVMSG $nick :To look up a word, simply use : \002.dict <word>\002"
puthelp "PRIVMSG $nick :To show only the word origins : \002.dict dcorigin <word>\002"
puthelp "PRIVMSG $nick :To show only synonyms/antonyms: \002.dict dcsyn <word>\002"
puthelp "PRIVMSG $nick : Origin and Synonyms/Antonyms available only from dbluna (default database)"
puthelp "PRIVMSG $nick :To show results from a particular dictionary: \002.dict <dbname> <word>\002"
puthelp "PRIVMSG $nick : The following dbname's are available:"
puthelp "PRIVMSG $nick : \002dbluna\002 - Dictionary.com Unabridged Dictionary (v1.0.1 2006)"
puthelp "PRIVMSG $nick : \002dbweb\002 - Webster's Revised Unabridged Dictionary (pub.date 1913)"
puthelp "PRIVMSG $nick : \002dbwnm\002 - Webster's New Millenium Dictionary (v0.9.6 2005)"
puthelp "PRIVMSG $nick : \002dbahd\002 - American Heritage Dictionary (4th Ed. 2000)"
puthelp "PRIVMSG $nick : \002dbahi\002 - American Heritage Dictionary of Idioms (pub.date 1997)"
puthelp "PRIVMSG $nick : \002dbamd\002 - American Heritage Stedman's Medical Dictionary (pub.date 2002)"
puthelp "PRIVMSG $nick : \002dbmmd\002 - Merriam-Webster's Medical Dictionary (pub.date 2002)"
puthelp "PRIVMSG $nick : \002dbmlaw\002 - Merriam-Webster's Law Dictionary (pub.date 1996)"
puthelp "PRIVMSG $nick : \002dbword\002 - WordNet Dictionary (v2.0 2003)"
puthelp "PRIVMSG $nick : \002dbfold\002 - Free Online Dictionary of Computing (pub.date 2005)"
puthelp "PRIVMSG $nick : \002dbjar\002 - Jargon File (v4.2.0, 2000)"
puthelp "PRIVMSG $nick : \002dbelem\002 - Atomic Elements Database (pub.date 1998)"
puthelp "PRIVMSG $nick : \002dbinv\002 - Investopedia (pub.date 2005)"
puthelp "PRIVMSG $nick : \002dbwsw\002 - Wall Street Words (pub.date 2003)"
puthelp "PRIVMSG $nick : \002dbgaz\002 - U.S. Gazetteer (1990 U.S. Census)"
puthelp "PRIVMSG $nick : \002dbcia\002 - CIA World Factbook (pub.date 1995)"
puthelp "PRIVMSG $nick : \002dbeast\002 - Easton's Bible Dictionary (pub.date 1897)"
puthelp "PRIVMSG $nick : \002dbhit\002 - Hitchcock's Bible Names Dictionary (pub.date late 1800's)"
puthelp "PRIVMSG $nick : When no database is specified, 1st matching result from all db's is shown."
puthelp "PRIVMSG $nick :To limit the number of lines shown for a word: \002.dict dclimit:<lines> \[dbname\] <word>\002"
puthelp "PRIVMSG $nick : Example: \002.dict dclimit:3 fubar\002 will show only the first 3 definition lines of 'fubar'"
puthelp "PRIVMSG $nick :To show which databases a word \002matches\002 in: \002.dict dbmatch <word>\002"
puthelp "PRIVMSG $nick :To show the list of databases: \002.dict showdb\002"
puthelp "PRIVMSG $nick :\[end of dictionary.tcl help\]"
return
}
if {$text == "showdb"} {
puthelp "PRIVMSG $nick :The following dbname's are available for the dictionary script:"
puthelp "PRIVMSG $nick : \002dbluna\002 - Dictionary.com Unabridged Dictionary (v1.0.1 2006)"
puthelp "PRIVMSG $nick : \002dbweb\002 - Webster's Revised Unabridged Dictionary (pub.date 1913)"
puthelp "PRIVMSG $nick : \002dbwnm\002 - Webster's New Millenium Dictionary (v0.9.6 2005)"
puthelp "PRIVMSG $nick : \002dbahd\002 - American Heritage Dictionary (4th Ed. 2000)"
puthelp "PRIVMSG $nick : \002dbahi\002 - American Heritage Dictionary of Idioms (pub.date 1997)"
puthelp "PRIVMSG $nick : \002dbamd\002 - American Heritage Stedman's Medical Dictionary (pub.date 2002)"
puthelp "PRIVMSG $nick : \002dbmmd\002 - Merriam-Webster's Medical Dictionary (pub.date 2002)"
puthelp "PRIVMSG $nick : \002dbmlaw\002 - Merriam-Webster's Law Dictionary (pub.date 1996)"
puthelp "PRIVMSG $nick : \002dbword\002 - WordNet Dictionary (v2.0 2003)"
puthelp "PRIVMSG $nick : \002dbfold\002 - Free Online Dictionary of Computing (pub.date 2005)"
puthelp "PRIVMSG $nick : \002dbjar\002 - Jargon File (v4.2.0, 2000)"
puthelp "PRIVMSG $nick : \002dbelem\002 - Atomic Elements Database (pub.date 1998)"
puthelp "PRIVMSG $nick : \002dbinv\002 - Investopedia (pub.date 2005)"
puthelp "PRIVMSG $nick : \002dbwsw\002 - Wall Street Words (pub.date 2003)"
puthelp "PRIVMSG $nick : \002dbgaz\002 - U.S. Gazetteer (1990 U.S. Census)"
puthelp "PRIVMSG $nick : \002dbcia\002 - CIA World Factbook (pub.date 1995)"
puthelp "PRIVMSG $nick : \002dbeast\002 - Easton's Bible Dictionary (pub.date 1897)"
puthelp "PRIVMSG $nick : \002dbhit\002 - Hitchcock's Bible Names Dictionary (pub.date late 1800's)"
puthelp "PRIVMSG $nick :\[End of database list\]"
return
}
# Need to test for illegal chars, as dictionary.com only accepts specific characters in words.
# The list of legal chars is: a-z A-Z 0-9 space + ( ) ' , - . % :
# If you find other chars that should be added to this list, let me know.
set testchars [split $text {}]
foreach letter [lrange $testchars 0 end] {
if {[regexp {[a-zA-Z0-9[:space:]{1,}\+\(\)\'\,\-\.\%\:üü]} $letter] != 1} {
puthelp "PRIVMSG $nick :'[join $text]' contains illegal characters. Cannot look up."
return
}
}
# test input length. The longest english word is 45 chars (according to wikipedia) but dictionary.com
# can also look up phrases, so we'll set the length limit to $dcmaxlength (configured above)
if {($::dcmaxlength > 0) && ([string length $text] > $::dcmaxlength)} {
puthelp "PRIVMSG $nick :Your input is too long. Please limit input length to less than $::dcmaxlength chars\."
return
}
set originaltext $text
regsub -all { } $text {%20} text
regsub -all {\+} $text {%2B} text
regsub -all {\(} $text {%28} text
regsub -all {\)} $text {%29} text
regsub -all {\'} $text {%27} text
regsub -all {,} $text {%2C} text
if {$dcomurl == ""} {
set dcomurl "http://dictionary.reference.com/search?q=$text"
} else {
set dcomurl "$dcomurl$text"
}
putquick "PRIVMSG $chan :\001ACTION peers over its glasses at a really huge book and flips through the pages..\001"
catch {set page [::http::geturl $dcomurl -timeout $::dcomtimeout]} error
if {[string match -nocase "*couldn't open socket*" $error]} {
puthelp "PRIVMSG $nick :dictionary.com error: couldn't connect..Try again later"
::http::cleanup $page
return
}
if {[::http::status $page] == "timeout" } {
puthelp "PRIVMSG $nick :dictionary.com error: Connection timed out. Try again."
::http::cleanup $page
return
}
set html [::http::data $page]
::http::cleanup $page
if {[regexp -nocase {<title>Dictionary.com: Bad Request</title>} $html]} {
puthelp "PRIVMSG $nick :Dictionary.com error: Bad request '[join $originaltext]' - request could not be understood."
return
}
if {[regexp -nocase {<h1>No results found for.*?<p>No spelling suggestions were found.</p>} $html]} {
puthelp "PRIVMSG $nick :Dictionary.com: No results and no spelling suggestions found for '[join $originaltext]'"
return
}
if {[regexp -nocase {<p>Sorry, an error occured while displaying this definition.</p>} $html]} {
puthelp "PRIVMSG $nick :Dictionary.com: An error occurred while trying to display '[join $originaltext]'"
return
}
if {[regexp -nocase {<TITLE>302 Found</TITLE>} $html]} {
puthelp "PRIVMSG $nick :Dictionary.com :Document 302 error (page moved) - Please retry your request '[join $originaltext]'"
return
}
if {[regexp -nocase {<h1>No results found for.*?</h1>.*?Did you mean <a href=".*?">(.*?)</a>.*?<td>Dictionary suggestions:<br />(.*?)</td>} $html match word1 dcsuggests]} {
regsub -all {\n} $dcsuggests {} dcsuggests
regsub -all -nocase {<a href="/search\?r=2&q=.*?">} $dcsuggests { } dcsuggests
regsub -all -nocase {</a><br />} $dcsuggests { 11|} dcsuggests
regsub { 11\|$} $dcsuggests {} dcsuggests
if {$otherdb != 0} {
puthelp "PRIVMSG $chan :No results were found for '[join $originaltext]' in the requested database \002[lindex $dblist $otherdb]\002. Try \002.dict dbmatch <word>\002 to see which databases the word might be found in, or try a search with no database specified (\002.dict <word>\002) Otherwise, this could just be a spelling error."
}
puthelp "PRIVMSG $chan :Couldn't find '[join $originaltext]' Maybe you spelled it wrong? Dictionary.com suggested:\002 $word1 \002"
set dcsuggests [dcwordwrap $nick $chan $originaltext $dcsuggests]
foreach line $dcsuggests {
regsub {^\s{0,}11\|} $line {} line
set line [string trim $line]
if {$line != ""} {
puthelp "PRIVMSG $chan :\002Addtional Suggestions:\002 $line"
}
}
puthelp "PRIVMSG $chan :\[end of '[join $originaltext]' suggestions\]"
return
}
# show matching db's on request
if {$showmatch == 1} {
foreach line [split $html \n] {
if {[regexp -all -nocase -- {<!-- begin (.*?) -->} $line match dbmatch1]} {
lappend dbmatches $dbmatch1
}
}
set dbmatches [lsort -unique $dbmatches]
foreach dbnam $dbmatches {
if {[lsearch -exact $dbmatchlist $dbnam] != -1} {
lappend newdbl $dbnam
}
}
set newdbl [string map {luna dbluna ahd4 dbahd web1913 dbweb ahsmd dbamd mwmed dbmmd ivst dbinv wsw dbwsw ahdi dbahi easton dbeast foldoc dbfold gazetteer dbgaz jargon dbjar mwlaw dbmlaw wmde dbwnm wn dbword world95 dbcia hitchcock dbhit elements dbelem} $newdbl]
puthelp "PRIVMSG $chan :Matches for '[join $originaltext]' found in these databases:\002 $newdbl\002"
return
}
if {($otherdb == 0) && ([regexp -nocase {<!-- begin luna -->(.*?)<!-- end luna -->} $html match dcomdef])} {
set dictname "Dictionary.com Unabridged"
if {[regexp -nocase {class="prondelim">\[</span>(.*?)<span.class="prondelim">\]} $dcomdef match pronun]} {
regsub -all -nocase {<b>.*?</b>} $pronun {&} pronun
set pronun [defproc $pronun]
set pronun [string trim $pronun]
regsub {,$} $pronun {} pronun
set pronun "\[pronunciation key: $pronun \]"
}
if {[regexp -nocase {<div.*?class="body">(.*?)</div>} $dcomdef match defins]} {
regsub -all -nocase {\n} $defins { } defins
regsub -all -nocase {<table class="luna-Ent">} $defins "\n" defins
regsub -all -nocase {</table>} $defins "\n" defins
regsub -all {Pronunciation Key} $defins {} defins
regsub -all {Show Spelled Pronunciation} $defins {} defins
regsub -all {Show IPA Pronunciation} $defins {} defins
set defins [defproc $defins]
}
if {[regexp -nocase {<div.*?class="ety">\[(.*?)\].*?</div>} $dcomdef match dcori]} {
regsub {Origin:} $dcori {Origin:} dcori
set dcori [defproc $dcori]
}
if {[regexp {class="sectionLabel">.+?Synonyms.*?</span>(.*?)</div>} $dcomdef match dcsynon]} {
regsub -all -nocase {<b>.*?</b>} $dcsynon {&} dcsynon
set dcsynon [defproc $dcsynon]
set dcsynon "\002Synonyms:\002 $dcsynon"
}
if {[regexp {class="sectionLabel">.+?Antonyms.*?</span>(.*?)</div>} $dcomdef match dcanton]} {
regsub -all -nocase {<b>.*?</b>} $dcanton {&} dcanton
set dcanton [defproc $dcanton]
set dcanton "\002Antonyms:\002 $dcanton"
}
} elseif {(($otherdb == 1) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin ahd4 -->(.*?)<!-- end ahd4 -->} $html match ahddef])} {
set dictname "American-Heritage Dictionary"
regexp -nocase {<br />(.*?)</TABLE>} $ahddef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 2) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin web1913 -->(.*?)<!-- end web1913 -->} $html match websterdef])} {
# webster 1913 dictionary
set dictname "Webster's 1913 Unabridged"
regexp -nocase {>Cite.*?</a>(.*?)<cite>Webster.*?} $websterdef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 3) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin ahsmd -->(.*?)<!-- end ahsmd -->} $html match amsmddef])} {
# american heritage steadman medical dictionary
set dictname "American-Heritage-Stedman's Medical Dictionary"
regexp -nocase {>Cite.*?</a>(.*?)<cite>The.*?American.*?Heritage} $amsmddef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 4) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin mwmed -->(.*?)<!-- end mwmed -->} $html match mwmeddef])} {
# meriam webster medical dictionary
set dictname "Merriam-Webster Medical Dictionary"
regexp -nocase {>Cite.*?</a>(.*?)<cite>Merriam-Webster's} $mwmeddef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 5) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin ivst -->(.*?)<!-- end ivst -->} $html match investdef])} {
# Investopedia
set dictname "Investopedia"
regexp -nocase {>Cite.*?</a>(.*?)<cite>Investopedia} $investdef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 6) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin wsw -->(.*?)<!-- end wsw -->} $html match wswdef])} {
# Wall Street Words
set dictname "Wall Street Words"
regexp -nocase {>Cite.*?</a>(.*?)<cite>Wall} $wswdef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 7) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin ahdi -->(.*?)<!-- end ahdi -->} $html match ahdidef])} {
# American Heritage Dictionary of Idioms
set dictname "American-Heritage Dictionary of Idioms"
regexp -nocase {>Cite.*?</a>(.*?)<cite>The.*?American.*?Heritage} $ahdidef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 8) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin easton -->(.*?)<!-- end easton -->} $html match eastdef])} {
# Easton's Bible Dictionary
set dictname "Easton's 1897 Bible Dictionary"
regexp -nocase {>Cite.*?</a>(.*?)<cite>Easton.*?</cite>} $eastdef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 9) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin foldoc -->(.*?)<!-- end foldoc -->} $html match foldef])} {
# FOLDOC
set dictname "FOLDOC Computer Dictionary"
regexp -nocase {>Cite.*?</a>(.*?)<cite>The.*? Free.*?</cite>} $foldef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 10) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin gazetteer -->(.*?)<!-- end gazetteer -->} $html match gazdef])} {
# US Gazetteer Census
set dictname "US Gazetteer 1990 Census"
regexp -nocase {>Cite.*?</a>(.*?)<cite>U\.S\..*?</cite>} $gazdef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 11) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin jargon -->(.*?)<!-- end jargon -->} $html match jardef])} {
# Jargon File
set dictname "Jargon File"
regexp -nocase {>Cite.*?</a>(.*?)<cite>Jargon.*?</cite>} $jardef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 12) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin mwlaw -->(.*?)<!-- end mwlaw -->} $html match mlawdef])} {
# Merriam-Webster Law Dictionary
set dictname "Merriam-Webster Law Dictionary"
regexp -nocase {>Cite.*?</a>(.*?)<cite>Merriam-Webster.*?</cite>} $mlawdef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 13) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin wmde -->(.*?)<!-- end wmde -->} $html match wmdef])} {
# Webster New Millenium Dictionary
set dictname "Webster's New Millenium Dictionary"
regexp -nocase {>Cite.*?</a>(.*?)<cite>Webster.*?</cite>} $wmdef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 14) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin wn -->(.*?)<!-- end wn -->} $html match wndef])} {
# WordNet Dictionary
set dictname "WordNet Dictionary"
regexp -nocase {>Cite.*?</a>(.*?)<cite>WordNet.*?</cite>} $wndef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 15) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin world95 -->(.*?)<!-- end world95 -->} $html match w95def])} {
# WordNet Dictionary
set dictname "CIA World Factbook"
regexp -nocase {>Cite.*?</a>(.*?)<cite>The.*?CIA.*?</cite>} $w95def match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 16) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin hitchcock -->(.*?)<!-- end hitchcock -->} $html match hitdef])} {
# Hitchcock's Bible Names Dictionary
set dictname "Hitchcock's Bible Names"
regexp -nocase {>Cite.*?</a>(.*?)<cite>Hitchcock.*?</cite>} $hitdef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} elseif {(($otherdb == 17) || (($defins == "") && ($otherdb == 0))) && ([regexp -nocase {<!-- begin elements -->(.*?)<!-- end elements -->} $html match elmdef])} {
# Elements Database
set dictname "Atomic Elements DB"
regexp -nocase {>Cite.*?</a>(.*?)<cite>The.*?Elements</cite>} $elmdef match defins
regsub -all {\n} $defins { } defins
set defins [defproc $defins]
} else {
puthelp "PRIVMSG $chan :No results found for '[join $originaltext]' in any of the active databases.."
return
}
if {($defins != "") || ($dcori != "") || ($dcsynon != "") || ($dcanton != "")} {
puthelp "PRIVMSG $chan :\002$dictname\002: Results for '\002[join $originaltext]\002' - $pronun"
if {$showdef == 0} {
set defins [dcwordwrap $nick $chan $originaltext $defins]
foreach line $defins {
set line [string trim $line]
if {$line != ""} {
if {$dcactivelim != 0} {
if {$i < [expr $dcactivelim + 1]} {
puthelp "PRIVMSG $chan :[join $line]"
incr i
} else {
puthelp "PRIVMSG $chan :\002Output limit reached\002 \[$dcactivelim lines max\]"
break
}
} else {
puthelp "PRIVMSG $chan :[join $line]"
}
}
}
}
if {(($showdef == 0) || ($showdcorigin == 1)) && ($dcori != "")} {
set dcori [dcwordwrap $nick $chan $originaltext $dcori]
foreach line $dcori {
if {$line != ""} {
set line [string trim $line]
puthelp "PRIVMSG $chan :[join $line]"
}
}
} elseif {($showdcorigin == 1) && ($dcori == "") && ($otherdb == 0)} {
puthelp "PRIVMSG $chan :No word origin found for '\002[join $originaltext]\002'"
} elseif {($otherdb != 0) && ($showdcorigin == 1)} {
puthelp "PRIVMSG $chan :Word origins only available from dbluna. You do not need to specify any db to use the dcorigin option."
}
if {(($showdef == 0) || ($showsynant == 1)) && (($dcsynon != "") || ($dcanton != ""))} {
if {$dcsynon != ""} {
set dcsynon [dcwordwrap $nick $chan $originaltext $dcsynon]
foreach line $dcsynon {
if {$line != ""} {
set line [string trim $line]
puthelp "PRIVMSG $chan :[join $line]"
}
}
} elseif {($dcsynon == "") && ($showsynant == 1) && ($otherdb == 0)} {
puthelp "PRIVMSG $chan :No synonyms found for '\002[$orignaltext]\002'"
} elseif {($otherdb != 0) && ($showsynant == 1)} {
puthelp "PRIVMSG $chan :Synonyms only availble from dbluna. You do not need to specify any db to use the dcsyn option."
}
if {$dcanton != ""} {
set dcanton [dcwordwrap $nick $chan $originaltext $dcanton]
foreach line $dcanton {
if {$line != ""} {
set line [string trim $line]
puthelp "PRIVMSG $chan :[join $line]"
}
}
} elseif {($dcanton == "") && ($showsynant == 1) && ($otherdb == 0)} {
puthelp "PRIVMSG $chan :No antonyms found for '\002[join $originaltext]\002'"
} elseif {($otherdb != 0) && ($showsynant == 1)} {
puthelp "PRIVMSG $chan :Antonyms only available from dbluna. You do not need to specify any db to use the dcsyn option."
}
} elseif {($showsynant == 1) && ($dcsynon == "") && ($dcanton == "") && ($otherdb == 0)} {
puthelp "PRIVMSG $chan :No synonyms or antonyms found for '\002[join $originaltext]\002'"
} elseif {($showsynant == 1) && ($dcsynon == "") && ($dcanton == "") && ($otherdb != 0)} {
puthelp "PRIVMSG $chan :Synonyms/Antonyms only available from dbluna. You do not need to specify any db to use the dcsyn option."
}
puthelp "PRIVMSG $chan :\[End $dictname - '[join $originaltext]'\]"
return
} else {
puthelp "PRIVMSG $chan :Hmm, definition for '[join $originaltext]' from dictionary.com was empty?"
return
}
return
}
proc dcwordwrap {nick channel origword input} {
# word wrapper - somewhat modified from other word wrappers I've done, this one does not append titles.
set j 0
set dcwct 0
set tempdef ""
foreach line [split $input \n] {
if {$line != ""} {
set len 375
set splitChr " "
set out [set cur {}]; set i 0
foreach word [split $line $splitChr] {
if {[incr i [string len $word]]>$len} {
lappend out [join $cur $splitChr]
set cur [list $word]
set i [string len $word]
incr j
} else {
lappend cur $word
}
incr i
}
lappend out [join $cur $splitChr]
foreach line2 $out {
incr dcwct
if {$j >= 1} {
set line2 [linsert $line2 end \002(con't)\002]
set j [expr $j -1]
}
lappend tempdef $line2
}
}
}
return $tempdef
}
proc defproc {defins} {
regsub -all -nocase {<p>} $defins "\n" defins
regsub -all -nocase {<LI.*?>} $defins "\n" defins
regsub -all -nocase {<br />} $defins "\n" defins
regsub -all -nocase {<tr>} $defins "\n" defins
regsub -all -nocase {<blockquote>} $defins "\n" defins
regsub -all -nocase {<ol.*?>} $defins {} defins
regsub -all -nocase {<table.*?>} $defins {} defins
regsub -all -nocase {<a.*?>} $defins {} defins
regsub -all -nocase {<td.*?>} $defins {} defins
regsub -all -nocase {<span.*?>} $defins {} defins
regsub -all -nocase {<img.*?>} $defins {} defins
regsub -all -nocase {<font.*?>} $defins {} defins
regsub -all -nocase {<hr.*?>} $defins {} defins
regsub -all -nocase {<!--.*?>} $defins {} defins
set defins [string map -nocase $::smaps $defins]
return $defins
}
set smaps {
" ' ' \x27 & \x26 < \x3C > \x3E \x20
¡ \xA1 ¤ \xA4 ¢ \xA2 £ \xA3 ¥ \xA5 ¦ \xA6
§ \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB ¬ \xAC
\xAD ® \xAE ¯ \xAF ° \xB0 ± \xB1 ² \xB2
³ \xB3 ´ \xB4 µ \xB5 ¶ \xB6 · \xB7 ¸ \xB8
¹ \xB9 º \xBA » \xBB ¼ \xBC ½ \xBD ¾ \xBE
¿ \xBF × \xD7 ÷ \xF7 À \xC0 Á \xC1 Â \xC2
à \xC3 Ä \xC4 Å \xC5 Æ \xC6 Ç \xC7 È \xC8
É \xC9 Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE
Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3 Ô \xD4
Õ \xD5 Ö \xD6 Ø \xD8 Ù \xD9 Ú \xDA Û \xDB
Ü \xDC Ý \xDD Þ \xDE ß \xDF à \xE0 á \xE1
â \xE2 ã \xE3 ä \xE4 å \xE5 æ \xE6 ç \xE7
è \xE8 é \xE9 ê \xEA ë \xEB ì \xEC í \xED
î \xEE ï \xEF ð \xF0 ñ \xF1 ò \xF2 ó \xF3
ô \xF4 õ \xF5 ö \xF6 ø \xF8 ù \xF9 ú \xFA
û \xFB ü \xFC ý \xFD þ \xFE ÿ \xFF ‖ ||
\" ' “ ` ” ' <b> "" </b> "" <i> ""
</i> "" <tr> "" </tr> "" </a> "" – "-" — "-"
</table> "" </td> "" </span> "" ē e ā a ̄ "-"
́ ' <sup> "" </sup> "" </font> "" ō o " '
& & [ ( \ / ] ) { ( } )
£ £ ¨ ¨ © © « « ® ®
¡ ¡ ¿ ¿ ´ ´ · · ¹ ¹ » »
¼ ¼ ½ ½ ¾ ¾ À À Á Á Â Â
Ã Ã Ä Ä Å Å Æ Æ Ç Ç È È
É É Ê Ê Ë Ë Ì Ì Í Í Î Î
Ï Ï Ð Ð Ñ Ñ Ò Ò Ó Ó Ô Ô
Õ Õ Ö Ö × × Ø Ø Ù Ù Ú Ú
Û Û Ü Ü Ý Ý Þ Þ ß ß à à
á á â â ã ã ä ä å å æ æ
ç ç è è é é ê ê ë ë ì ì
í í î î ï ï ð ð ñ ñ ò ò
ó ó ô ô õ õ ö ö ÷ ÷ ø ø
ù ù ú ú û û ü ü ý ý þ þ
° ° ‧ · ˌ . ū u ī i ˈ '
ɔ o ɪ i </li> "" <cite> "" </cite> "" </ol> ""
"<br />" "" <tt> "" </tt> "" “ ' ” ' <em> ""
</em> "" <BLOCKQUOTE> "" </BLOCKQUOTE> "" ’ ' <dd> "" </dd> ""
<dl> "" </dl> "" <dt> "" </dt> "" <ol> "" </p> ""
ŋ n — "-" ǫ Q ̃ ~ ŭ u <br/> ""
<br> "" ǣ "ae" ɛ e <div> "" </div> "" <sub> ""
</sub> "" ≪ "<<" ə e ŷ ý ɑ a ʊ u
ʿ c <tbody> "" </tbody> "" \{ ( \} )
}
putlog "Dictionary.com tcl script $dcdictver by rosc loaded."
Code: Select all
No results found for 'help' in any of the active databases..