View previous topic :: View next topic |
Author |
Message |
Goga Halfop
Joined: 19 Sep 2020 Posts: 83
|
Posted: Tue Jan 11, 2022 6:50 am Post subject: Dictionary |
|
|
Code: | # 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."
|
Everytime when it trigger with !dict WORD it replies always
Code: | No results found for 'help' in any of the active databases..
|
Help Please. |
|
Back to top |
|
 |
Arnold_X-P Master

Joined: 30 Oct 2006 Posts: 226 Location: DALnet - Trinidad - Beni - Bolivia
|
Posted: Wed Jan 12, 2022 10:05 pm Post subject: |
|
|
use in channel .dict word _________________ .:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005 |
|
Back to top |
|
 |
Goga Halfop
Joined: 19 Sep 2020 Posts: 83
|
Posted: Thu Jan 13, 2022 3:35 am Post subject: |
|
|
Same Result with .dict word
and error comes up in private window :
Quote: | No results found for 'Book' in any of the active databases.. |
|
|
Back to top |
|
 |
Goga Halfop
Joined: 19 Sep 2020 Posts: 83
|
Posted: Fri Jan 21, 2022 1:45 am Post subject: |
|
|
Anyone Please make it Happen this TCL Please. |
|
Back to top |
|
 |
jaxson Voice
Joined: 31 Dec 2021 Posts: 9
|
Posted: Sat Jan 22, 2022 12:46 am Post subject: Try this one |
|
|
Code: |
package require http 2.3
package require tls 1.6.4
package present Tcl 8.6
proc cblack {} {return \00301};
proc cltblue {} {return \00311};
proc cblue {} {return \00312};
proc coff {} {return \017}
set dt(link) "https://www.dictionary.com/browse/"
# set the following array to which chans to listen to (need to be lowercase)
array set dictChans {
#eggdrop e
#phoenix p
}
bind pub - ".dict" dictionaryLookup
proc httpsregister {} {
package require tls
if {[package vcompare [package present tls] 1.7] > 0 } {
::http::register https 443 [list ::tls::socket -autoservername 1]
} else {
::http::register https 443 [list ::tls::socket -request 0 -require 1 -ssl2 0 -ssl3 0 -tls1 1]
}
return 0
}
proc httpsunregister {} {
::http::unregister https
return 0
}
proc dictionaryLookup {nick uhost hand chan arg} {
global dt dictChans
if {([array get dictChans [string tolower $chan]] == "")} { return 0 }
if {$arg == "" || [regexp {\s} $arg]} {
putchan $chan "Usage: .dict <word>"
return 0
}
set fullurl "$dt(link)$arg"
putlog "$fullurl"
set ddoc [getpage "$fullurl"]
if {[llength [split $ddoc "\n"]] < 5} {
putchan $chan "[cblue]Nothing found for[cblack] $arg[cblue].[coff]"
}
foreach line [split $ddoc "\n"] {
if {[regexp {<meta\s+name=\"description\"\s+content=\"(.*?),(.*)\s+See\s+more\.\">} $line -> subj def]} {
set ssubj [string trim [lindex [split $subj] 0]]
set sdef [string trim $def]
putlog ".$ssubj.$sdef."
putchan $chan "[cblue]The Defition for[cblack] $ssubj[cblue] is:[cltblue] $sdef[coff]"
}
}
return 0
}
proc getpage url {
::httpsregister
if {[catch {set token [::http::geturl $url -binary 1 -timeout 15000]} error]} {
putlog "Error retrieving URL... try again later.[string map [list \n " "] $error]"
::httpsunregister
return 0
}
set data [::http::data $token]
::http::cleanup $token
::httpsunregister
return [encoding convertfrom utf-8 $data]
}
putlog "Dictionary Lookup by jax loaded..."
|
|
|
Back to top |
|
 |
jaxson Voice
Joined: 31 Dec 2021 Posts: 9
|
Posted: Sat Jan 22, 2022 5:45 am Post subject: Version 1.1 - Added .dictChan trigger for adding channels |
|
|
Code: |
# Description: This script will query dictionary.com and give a simple response
#
# v1.0 Initial release giving a simple dictionary result (jaxson)
# v1.1 Added the .dictChan command to allow a channel access to the .dict command (jaxson)
#
# Needed packages
package require http 2.3
package require tls 1.6.4
package present Tcl 8.6
# Colors available
proc cr {} {return \026}; #reverse
proc cul {} {return "\037"}; #underline
proc cbold {} {return \002}; #bold
proc coff {} {return \003}; #off
proc cwhite {} {return \00300};
proc cblack {} {return \00301};
proc cdkblue {} {return \00302};
proc cgreen {} {return \00303};
proc cltred {} {return \00304};
proc cbrown {} {return \00305};
proc cpurple {} {return \00306};
proc corange {} {return \00307};
proc cyellow {} {return \00308};
proc cltgreen {} {return \00309};
proc ccyan {} {return \00310};
proc cltcyan {} {return \00311};
proc cltblue {} {return \00312};
proc cpink {} {return \00313};
proc cgrey {} {return \00314};
proc cltgrey {} {return \00315};
# Some variables
set dt(link) "https://www.dictionary.com/browse/"
set dt(version) "v1.1"
# channel flag
# .dictChan on <- to enable on your #channel / .dictChan off <- for turn this off!
setudef flag dictionary
bind pub - ".dict" dictionaryLookup
bind pub o ".dictChan" dictionaryControl
proc httpsregister {} {
package require tls
if {[package vcompare [package present tls] 1.7] > 0 } {
::http::register https 443 [list ::tls::socket -autoservername 1]
} else {
::http::register https 443 [list ::tls::socket -request 0 -require 1 -ssl2 0 -ssl3 0 -tls1 1]
}
return 0
}
proc httpsunregister {} {
::http::unregister https
return 0
}
proc dictionaryLookup {nick uhost hand chan arg} {
global dt
if {![channel get $chan dictionary]} { return 0 }
if {$arg == "" || [regexp {\s} $arg]} {
putchan $chan "Usage: .dict <word>"
return 0
}
set fullurl "$dt(link)$arg"
putlog "$fullurl"
set ddoc [getpage "$fullurl"]
if {[llength [split $ddoc "\n"]] < 5} {
putchan $chan "[cblue]Nothing found for[cblack] $arg[cblue].[coff]"
}
foreach line [split $ddoc "\n"] {
if {[regexp {<meta\s+name=\"description\"\s+content=\"(.*?),(.*)\s+See\s+more\.\">} $line -> subj def]} {
set ssubj [string trim [lindex [split $subj] 0]]
set sdef [string trim $def]
putchan $chan "[cblue]The Defition for[cblack] $ssubj[cblue] is:[cltblue] $sdef[coff]"
}
}
return 0
}
proc getpage url {
::httpsregister
if {[catch {set token [::http::geturl $url -binary 1 -timeout 15000]} error]} {
putlog "Error retrieving URL... try again later.[string map [list \n " "] $error]"
::httpsunregister
return 0
}
set data [::http::data $token]
::http::cleanup $token
::httpsunregister
return [encoding convertfrom utf-8 $data]
}
proc dictionaryControl {nick uhost hand chan text} {
switch -nocase -- [lindex [split $text] 0] {
"on" {
if {[channel get $chan dictionary]} {
putchan $chan "Dictionary already running on $chan."
} else {
channel set $chan +dictionary
putchan $chan "Dictionary now running on $chan."
}
}
"off" {
if {![channel get $chan dictionary]} {
putchan $chan "Dictionary already disabled on $chan."
} {
channel set $chan -dictionary
putchan $chan "Dictionary now disabled on $chan."
}
}
default {
putchan $chan "Usage: $::lastbind <on/off>."
}
}
return 0
}
putlog "Dictionary Lookup (jax) $dt(version) loaded..."
|
|
|
Back to top |
|
 |
jaxson Voice
Joined: 31 Dec 2021 Posts: 9
|
Posted: Sat Jan 22, 2022 7:10 pm Post subject: v1.2 color proc fix |
|
|
Code: |
# Description: This script will query dictionary.com and give a simple response
#
# v1.0 Initial release giving a simple dictionary result (jaxson)
# v1.1 Added the .dictChan command to allow a channel access to the .dict command (jaxson)
# v1.2 Fix for wrong color procs - my bad for copying colors from one of my other scripts doh!
#
# Needed packages
package require http 2.3
package require tls 1.6.4
package present Tcl 8.6
# Colors available
proc cr {} {return \026}; #reverse
proc cul {} {return "\037"}; #underline
proc cbold {} {return \002}; #bold
proc coff {} {return \003}; #off
proc cwhite {} {return \00300};
proc cblack {} {return \00301};
proc cdkblue {} {return \00302};
proc cgreen {} {return \00303};
proc cltred {} {return \00304};
proc cbrown {} {return \00305};
proc cpurple {} {return \00306};
proc corange {} {return \00307};
proc cyellow {} {return \00308};
proc cltgreen {} {return \00309};
proc ccyan {} {return \00310};
proc cltblue {} {return \00311};
proc cblue {} {return \00312};
proc cpink {} {return \00313};
proc cgrey {} {return \00314};
proc cltgrey {} {return \00315};
# Some variables
set dt(link) "https://www.dictionary.com/browse/"
set dt(version) "v1.2"
# channel flag
# .dictChan on <- to enable on your #channel / .dictChan off <- for turn this off!
setudef flag dictionary
bind pub - ".dict" dictionaryLookup
bind pub o ".dictChan" dictionaryControl
proc httpsregister {} {
if {[package vcompare [package present tls] 1.7] > 0 } {
::http::register https 443 [list ::tls::socket -autoservername 1]
} else {
::http::register https 443 [list ::tls::socket -request 0 -require 1 -ssl2 0 -ssl3 0 -tls1 1]
}
}
proc httpsunregister {} {
::http::unregister https
return 0
}
proc dictionaryLookup {nick uhost hand chan arg} {
global dt
if {![channel get $chan dictionary]} { return 0 }
if {$arg == "" || [regexp {\s} $arg]} {
putchan $chan "Usage: .dict <word>"
return 0
}
set fullurl "$dt(link)$arg"
putlog "$fullurl"
set ddoc [getpage "$fullurl"]
if {[llength [split $ddoc "\n"]] < 5} {
putchan $chan "[cblue]Nothing found for[cblack] $arg[cblue].[coff]"
}
foreach line [split $ddoc "\n"] {
if {[regexp {<meta\s+name=\"description\"\s+content=\"(.*?),(.*)\s+See\s+more\.\">} $line -> subj def]} {
set ssubj [string trim [lindex [split $subj] 0]]
set sdef [string trim $def]
putchan $chan "[cblue]The Defition for[cblack] $ssubj[cblue] is:[cltblue] $sdef[coff]"
}
}
return 0
}
proc getpage url {
::httpsregister
if {[catch {set token [::http::geturl $url -binary 1 -timeout 15000]} error]} {
putlog "Error retrieving URL... try again later.[string map [list \n " "] $error]"
::httpsunregister
return 0
}
set data [::http::data $token]
::http::cleanup $token
::httpsunregister
return [encoding convertfrom utf-8 $data]
}
proc dictionaryControl {nick uhost hand chan text} {
switch -nocase -- [lindex [split $text] 0] {
"on" {
if {[channel get $chan dictionary]} {
putchan $chan "Dictionary already running on $chan."
} else {
channel set $chan +dictionary
putchan $chan "Dictionary now running on $chan."
}
}
"off" {
if {![channel get $chan dictionary]} {
putchan $chan "Dictionary already disabled on $chan."
} {
channel set $chan -dictionary
putchan $chan "Dictionary now disabled on $chan."
}
}
default {
putchan $chan "Usage: $::lastbind <on/off>."
}
}
return 0
}
putlog "Dictionary Lookup (jax) $dt(version) loaded..."
|
|
|
Back to top |
|
 |
jaxson Voice
Joined: 31 Dec 2021 Posts: 9
|
Posted: Thu Jan 27, 2022 7:17 am Post subject: v1.3 Fix for early versions of tcl-tls v1.7 |
|
|
Code: |
# Description: This script will query dictionary.com and give a simple response
#
# v1.0 Initial release giving a simple dictionary result (jaxson)
# v1.1 Added the .dictChan command to allow a channel access to the .dict command (jaxson)
# v1.2 Fix for wrong color procs - my bad for copying colors from one of my other scripts doh!
# v1.3 Fix for earlier versions of 1.7 (Thanks to SpiKe^^) and better checking of tcl-tls
# Needed packages
package require http 2.3
package require tls
package present Tcl 8.6
# Colors available
proc cr {} {return \026}; #reverse
proc cul {} {return "\037"}; #underline
proc cbold {} {return \002}; #bold
proc coff {} {return \003}; #off
proc cwhite {} {return \00300};
proc cblack {} {return \00301};
proc cdkblue {} {return \00302};
proc cgreen {} {return \00303};
proc cltred {} {return \00304};
proc cbrown {} {return \00305};
proc cpurple {} {return \00306};
proc corange {} {return \00307};
proc cyellow {} {return \00308};
proc cltgreen {} {return \00309};
proc ccyan {} {return \00310};
proc cltblue {} {return \00311};
proc cblue {} {return \00312};
proc cpink {} {return \00313};
proc cgrey {} {return \00314};
proc cltgrey {} {return \00315};
# Some variables
set dt(link) "https://www.dictionary.com/browse/"
set dt(version) "v1.3"
# channel flag
# .dictChan on <- to enable on your #channel / .dictChan off <- for turn this off!
setudef flag dictionary
bind pub - ".dict" dictionaryLookup
bind pub o ".dictChan" dictionaryControl
proc putchan {chan what} { puthelp "PRIVMSG $chan :$what" }
proc putmsg {nick msg} { puthelp "PRIVMSG $nick :$msg" }
proc putnot {nick msg} { puthelp "NOTICE $nick :$msg" }
proc httpsregister {} {
::http::register https 443 [list ::tls::socket -servername www.dictionary.com]
}
proc httpsunregister {} {
::http::unregister https
return 0
}
proc dictionaryLookup {nick uhost hand chan arg} {
global dt
if {![channel get $chan dictionary]} { return 0 }
if {$arg == "" || [regexp {\s} $arg]} {
putchan $chan "Usage: .dict <word>"
return 0
}
if {[package vcompare [package present tls] 1.7] == -1 } {
putnot $nick "You don't have a valid version of tcl-tls installed. Get the admin to either install tcl-tls package, or upgrade to at lea
st v1.7"
putnot $nick "If the admin doesn't want to you can try downloading https://core.tcl-lang.org/tcltls/uv/tcltls-1.7.22.tar.gz to your home
directory."
putnot $nick "Extract it and change to that directory; run './configure --prefix=$HOME; make; make install'"
putnot $nick "Then go to your eggdrop source directory & 'make clean'; './configure'; 'make'; 'make install DEST=~/xxxxx'"
putnot $nick "Then restart your bot. You should now have a working tcl-tls v1.7.22."
return 0
}
set fullurl "$dt(link)$arg"
putlog "$fullurl"
set ddoc [getpage "$fullurl"]
if {[llength [split $ddoc "\n"]] < 5} {
putchan $chan "[cblue]Nothing found for[cblack] $arg[cblue].[coff]"
}
foreach line [split $ddoc "\n"] {
if {[regexp {<meta\s+name=\"description\"\s+content=\"(.*?),(.*)\s+See\s+more\.\">} $line -> subj def]} {
set ssubj [string trim [lindex [split $subj] 0]]
set sdef [string trim $def]
putchan $chan "[cblue]The Defition for[cblack] $ssubj[cblue] is:[cltblue] $sdef[coff]"
}
}
return 0
}
proc getpage url {
::httpsregister
if {[catch {set token [::http::geturl $url -timeout 15000]} error]} {
putlog "Error retrieving URL... try again later.[string map [list \n " "] $error]"
::httpsunregister
return 0
}
set data [::http::data $token]
::http::cleanup $token
::httpsunregister
return [encoding convertfrom utf-8 $data]
}
proc dictionaryControl {nick uhost hand chan text} {
switch -nocase -- [lindex [split $text] 0] {
"on" {
if {[channel get $chan dictionary]} {
putchan $chan "Dictionary already running on $chan."
} else {
channel set $chan +dictionary
putchan $chan "Dictionary now running on $chan."
}
}
"off" {
if {![channel get $chan dictionary]} {
putchan $chan "Dictionary already disabled on $chan."
} {
channel set $chan -dictionary
putchan $chan "Dictionary now disabled on $chan."
}
}
default {
putchan $chan "Usage: $::lastbind <on/off>."
}
}
return 0
}
putlog "Dictionary Lookup (jax) $dt(version) loaded..."
[quote][/quote] |
|
|
Back to top |
|
 |
Goga Halfop
Joined: 19 Sep 2020 Posts: 83
|
Posted: Fri Jan 28, 2022 1:16 am Post subject: |
|
|
Thanks Jaxon for help  |
|
Back to top |
|
 |
jaxson Voice
Joined: 31 Dec 2021 Posts: 9
|
Posted: Fri Jan 28, 2022 2:47 am Post subject: Quick case fix for argument given |
|
|
Replace this line: set fullurl "$dt(link)$arg
With this line: set fullurl [string tolower "$dt(link)$arg"] |
|
Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 831 Location: Tennessee, USA
|
Posted: Sat Jan 29, 2022 3:17 am Post subject: Dictionary Lookup v1.2 (+redirectable) |
|
|
Dictionary Lookup v1.2 (+redirectable)
Addresses the no reply for things like "draws" and "Another" by following the redirect...
Code: |
# Description: This script will query dictionary.com and give a simple response
#
# v1.0 Initial release giving a simple dictionary result (jaxson)
# v1.1 Added the .dictChan command to allow a channel access to the .dict command (jaxson)
# v1.2 Fix for wrong color procs - my bad for copying colors from one of my other scripts doh!
#
# Needed packages
package require http 2.3
package require tls 1.6.4
package present Tcl 8.6
# Colors available
proc crev {} {return \026} ;#reverse
proc culine {} {return \037} ;#underline
proc cbold {} {return \002} ;#bold
proc coff {} {return \003} ;#color-off
proc cwhite {} {return \00300}
proc cblack {} {return \00301}
proc cdkblue {} {return \00302}
proc cgreen {} {return \00303}
proc cred {} {return \00304}
proc cbrown {} {return \00305}
proc cpurple {} {return \00306}
proc corange {} {return \00307}
proc cyellow {} {return \00308}
proc cltgreen {} {return \00309}
proc ccyan {} {return \00310}
proc cltblue {} {return \00311}
proc cblue {} {return \00312}
proc cpink {} {return \00313}
proc cgrey {} {return \00314}
proc cltgrey {} {return \00315}
# Some variables
set dt(link) "https://www.dictionary.com/browse/"
set dt(version) "v1.2 (+redirectable)"
# channel flag
# .dictChan on <- to enable on your #channel / .dictChan off <- for turn this off!
setudef flag dictionary
bind pub - ".dict" dictionaryLookup
bind pub o ".dictChan" dictionaryControl
######## made a new httpsregister ########
proc httpsregister {} {
set tlsver [package present tls]
if {[package vcompare $tlsver 1.7.11] >= 0 } {
::http::register https 443 [list ::tls::socket -autoservername 1]
} elseif {[package vcompare $tlsver 1.7] >= 0 } {
::http::register https 443 [list ::tls::socket -servername www.dictionary.com]
} else {
::http::register https 443 [list ::tls::socket -request 0 -require 1 -ssl2 0 -ssl3 0 -tls1 1]
}
}
######## end of new httpsregister ########
proc httpsunregister {} {
::http::unregister https
return 0
}
proc dictionaryLookup {nick uhost hand chan arg} {
global dt
if {![channel get $chan dictionary]} { return 0 }
if {$arg == "" || [regexp {\s} $arg]} {
putchan $chan "Usage: .dict <word>"
return 0
}
set fullurl "$dt(link)$arg"
putlog "$fullurl"
set ddoc [getpage "$fullurl"]
######## made a new follow redirect ########
if {[llength [split $ddoc "\n"]] < 5} {
set line1 [lindex [split $ddoc "\n"] 0]
if {[matchstr "moved permanently. redirecting to /browse/*" $line1]} {
set fullurl "$dt(link)[lindex [split $line1 /] end]"
putlog "$fullurl"
set ddoc [getpage "$fullurl"]
}
}
######## end of new follow redirect ########
if {[llength [split $ddoc "\n"]] < 5} {
putchan $chan "[cblue]Nothing found for[cblack] $arg[cblue].[coff]"
return 0
}
foreach line [split $ddoc "\n"] {
if {[regexp {<meta\s+name=\"description\"\s+content=\"(.*?),(.*)\s+See\s+more\.\">} $line -> subj def]} {
set ssubj [string trim [lindex [split $subj] 0]]
set sdef [string trim $def]
putchan $chan "[cblue]The Defition for[cblack] $ssubj[cblue] is:[cltblue] $sdef[coff]"
}
}
return 0
}
proc getpage url {
::httpsregister
if {[catch {set token [::http::geturl $url -binary 1 -timeout 15000]} error]} {
putlog "Error retrieving URL... try again later.[string map [list \n " "] $error]"
::httpsunregister
return 0
}
set data [::http::data $token]
::http::cleanup $token
::httpsunregister
return [encoding convertfrom utf-8 $data]
}
proc dictionaryControl {nick uhost hand chan text} {
switch -nocase -- [lindex [split $text] 0] {
"on" {
if {[channel get $chan dictionary]} {
putchan $chan "Dictionary already running on $chan."
} else {
channel set $chan +dictionary
putchan $chan "Dictionary now running on $chan."
}
}
"off" {
if {![channel get $chan dictionary]} {
putchan $chan "Dictionary already disabled on $chan."
} {
channel set $chan -dictionary
putchan $chan "Dictionary now disabled on $chan."
}
}
default {
putchan $chan "Usage: $::lastbind <on/off>."
}
}
return 0
}
putlog "Dictionary Lookup (jax) $dt(version) loaded..."
|
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 831 Location: Tennessee, USA
|
Posted: Thu Feb 24, 2022 2:24 pm Post subject: Dictionary Lookup v1.4 update... |
|
|
Dictionary Lookup (jaxson)
Version 1.4 (update by SpiKe^^)
New Experimental Fix for tcl-tls version checking and related errors.
New Code to follow redirect for "301 Moved Permanently" for things like "draws" and "Another".
New Code tries to query defitions for common phrases (Example: .dict trial by fire ).
Code: |
# Description: This script will query dictionary.com and give a simple response
#
# v1.0 Initial release giving a simple dictionary result (jaxson)
# v1.1 Added the .dictChan command to allow a channel access to the .dict command (jaxson)
# v1.2 Fix for wrong color procs - my bad for copying colors from one of my other scripts doh!
#
# v1.4 New Experimental Fix for tcl-tls version checking and related errors. (SpiKe^^)
# New Code to follow redirect for "301 Moved Permanently" for things like "draws" and "Another".
# New Code tries to query defitions for common phrases (Example: .dict trial by fire ).
# Needed packages
package require http 2.3
package require tls 1.6.4
package present Tcl 8.6
# Colors available
proc crev {} {return \026} ;#reverse
proc culine {} {return \037} ;#underline
proc cbold {} {return \002} ;#bold
proc coff {} {return \003} ;#color-off
proc cwhite {} {return \00300}
proc cblack {} {return \00301}
proc cdkblue {} {return \00302}
proc cgreen {} {return \00303}
proc cred {} {return \00304}
proc cbrown {} {return \00305}
proc cpurple {} {return \00306}
proc corange {} {return \00307}
proc cyellow {} {return \00308}
proc cltgreen {} {return \00309}
proc ccyan {} {return \00310}
proc cltblue {} {return \00311}
proc cblue {} {return \00312}
proc cpink {} {return \00313}
proc cgrey {} {return \00314}
proc cltgrey {} {return \00315}
# Some variables
set dt(link) "https://www.dictionary.com/browse/"
set dt(version) "v1.4"
# channel flag
# .dictChan on <- to enable on your #channel / .dictChan off <- for turn this off!
setudef flag dictionary
bind pub - ".dict" dictionaryLookup
bind pub o ".dictChan" dictionaryControl
######## made a new httpsregister ########
proc httpsregister {} {
set tlsver [package present tls]
set test 0
if {$test} {putlog "proc httpsregister::: tlsver = ($tlsver)"}
if {[package vcompare $tlsver 1.7.11] >= 0 } {
if {[catch {::http::register https 443 [list ::tls::socket -autoservername 1]} err]} {
if {$test} {putlog "check 1b :err = ($err)"}
::http::register https 443 [list ::tls::socket -servername www.dictionary.com]
} elseif {$test} {putlog "check 1"}
} elseif {[package vcompare $tlsver 1.7] >= 0 } {
if {$test} {putlog "check 2"}
::http::register https 443 [list ::tls::socket -servername www.dictionary.com]
} else {
if {$test} {putlog "check 3"}
::http::register https 443 [list ::tls::socket -request 0 -require 1 -ssl2 0 -ssl3 0 -tls1 1]
}
}
######## end of new httpsregister ########
proc httpsunregister {} {
::http::unregister https
return 0
}
proc putmsg {dest text} {
puthelp "PRIVMSG $dest :$text"
}
proc dictionaryLookup {nick uhost hand chan arg} {
global dt
if {![channel get $chan dictionary]} { return 0 }
set arg [regsub -all -- {\s{2,}} [string trim [stripcodes * $arg]] { }]
if {$arg eq "" || [string length $arg] > 70 || [llength [split $arg]] > 10} {
putmsg $chan "[cblue]Usage:[coff] [cbold].dict <word or short phrase>[cbold]"
return 0
}
set txt [string map [list " " "-" "'" "-" "`" "-"] $arg]
regsub -all {[^-a-zA-Z]} $txt "" txt
set fullurl "$dt(link)$txt"
#putlog "$fullurl"
set ddoc [getpage $fullurl]
######## made a new follow redirect ########
if {[llength [split $ddoc "\n"]] < 5} {
set line1 [lindex [split $ddoc "\n"] 0]
if {[matchstr "moved permanently. redirecting to /browse/*" $line1]} {
set fullurl "$dt(link)[lindex [split $line1 /] end]"
#putlog "$fullurl"
set ddoc [getpage $fullurl]
}
}
######## end of new follow redirect ########
set ddoc [split $ddoc "\n"]
if {[llength $ddoc] < 5} {
putmsg $chan "[cblue]Nothing found for[coff] [cbold]$arg[cbold][cblue].[coff] (1)"
return 0
}
foreach line $ddoc {
if {[regexp {<meta\s+name=\"description\"\s+content=\"(.*?),(.*)\s+See\s+more\.\">} $line -> subj def]} {
set ssubj [join [lrange [split $subj] 0 end-1]]
set sdef [string trim $def]
putmsg $chan "[cblue]The Defition for[coff] [cbold]$ssubj[cbold][cblue] is:[coff] $sdef"
break
}
if {[regexp {<meta\s+name=\"description\"\s+content=\"(.*?)definition\s+at\s+Dictionary} $line -> subj]} {
set ssubj [string trim $subj]
set line [lindex $ddoc 55]
if {![matchstr { );border-radius:50%;display:-webkit-*} $line]} { set line [lindex $ddoc 56] }
if {[regexp {\s+css-0\s+e1w1pzze4\">(.*?)<span\s+class=\"italic\">(.*?)</span>\.} $line -> def1 def2]} {
set sdef "[string trim $def1] [cgrey] ${def2}.[coff]"
putmsg $chan "[cblue]The Defition for[coff] [cbold]$ssubj[cbold][cblue] is:[coff] $sdef"
break
}
}
}
if {![info exists ssubj] || ![info exists sdef]} {
putmsg $chan "[cblue]Nothing found for[coff] [cbold]$arg[cbold][cblue].[coff] (2)"
}
return 0
}
proc getpage url {
::httpsregister
if {[catch {set token [::http::geturl $url -binary 1 -timeout 15000]} error]} {
putlog "Error retrieving URL... try again later. [string map [list \n " "] $error]"
::httpsunregister
return 0
}
set data [::http::data $token]
::http::cleanup $token
::httpsunregister
return [encoding convertfrom utf-8 $data]
}
proc dictionaryControl {nick uhost hand chan text} {
switch -nocase -- [lindex [split $text] 0] {
"on" {
if {[channel get $chan dictionary]} {
putmsg $chan "Dictionary already running on $chan."
} else {
channel set $chan +dictionary
putmsg $chan "Dictionary now running on $chan."
}
}
"off" {
if {![channel get $chan dictionary]} {
putmsg $chan "Dictionary already disabled on $chan."
} {
channel set $chan -dictionary
putmsg $chan "Dictionary now disabled on $chan."
}
}
default {
putmsg $chan "Usage: $::lastbind <on/off>."
}
}
return 0
}
putlog "Dictionary Lookup (jax) $dt(version) loaded..."
|
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
Back to top |
|
 |
|