Code: Select all
set matches [regexp -all -inline {<td class='text' colspan='3' id='.*?'>(.*?)</td} $data];
Code: Select all
set matches [regexp -all -inline {<td class='text' colspan='.' id='.*?'>(.*?)</td} $data];
Code: Select all
set matches [regexp -all -inline {<td class='text' colspan='3' id='.*?'>(.*?)</td} $data];
Code: Select all
set matches [regexp -all -inline {<td class='text' colspan='.' id='.*?'>(.*?)</td} $data];
Not really. It still follows the max lines limit that you set so if it's set to 2, then only two lines for the definition and two lines for the example is allowed (making up four lines in total). The default value is 3 lines, so that means a max of six lines for both. Set it to 1 if you only want it to take up a max of 2 lines.goalie204 wrote:Ya, that would be nice, but for long definitions it's going to be too spammy
Code: Select all
set matches [regexp -all -inline {<td class='text' colspan='.' id='.*?'>(.*?)</td} $data];
Code: Select all
set matches [regexp -all -inline {<div class='text' colspan='.' id='.*?'>(.*?)</div>\n} $data];
Code: Select all
set matches [regexp -all -inline {<div class='text' colspan='.' id='.*?'>(.*?)</div>\n<div class='zazzle_links'>} $data];
Code: Select all
# Urban Dictionary
# Copyright (C) 2006-2008 perpleXa
# http://perplexa.ugug.org / #perpleXa on QuakeNet
#
# Redistribution, with or without modification, are permitted provided
# that redistributions retain the above copyright notice, this condition
# and the following disclaimer.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# Usage:
# -ud [id] <term>
# fsck is available at http://perplexa.ugug.co.uk
package require fsck 1.10;
package require http;
namespace eval urbandict {
variable version 1.13;
# flood protection (seconds)
variable antiflood 10;
# maximum number of lines to output
variable max_lines 3;
variable encoding "utf-8";
variable client "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.14) Gecko/20080420 Firefox/2.0.0.14";
bind pub -|- "!ud" [namespace current]::pub;
bind pub -|- ".ud" [namespace current]::pub;
bind pub -|- "!urban" [namespace current]::pub;
bind pub -|- ".urban" [namespace current]::pub
namespace export pub;
}
proc urbandict::getdefinition {definition} {
variable client;
http::config -useragent $client;
set url "http://www.urbandictionary.com/define.php?term=[urlencode $definition]";
if {[catch {http::geturl $url -timeout 20000} token]} {
return [list 0 "Warning: Couldn't connect to \[$url\]"];
}
upvar 0 $token state;
if {![string equal -nocase $state(status) "ok"]} {
return [list 0 "Warning: Couldn't connect to \[$url\] (connection $state(status))."];
}
set data [http::data $token];
http::cleanup $token;
set matches [regexp -all -inline {<div class='text' colspan='.' id='.*?'>(.*?)</div>\n<div class='zazzle_links'>} $data];
set list [list];
foreach {null match} $matches {
set definition "n/a"
#regexp -nocase -- {<p>(.*?)</p>} $match -> definition
regexp -nocase -- {<div class="definition">(.*?)</div>} $match -> definition
regsub -all {[\r\n\s\t]+} $definition " " definition
regsub -all {<[^>]*?>} [string trim [decode $definition]] "" definition;
set example ""
#regexp -nocase -- {<p style="font-style: italic">(.*?)</p>} $match -> example
regexp -nocase -- {<div class="example">(.*?)</div>} $match -> example
regsub -all {[\r\n\s\t]+} [string trim $example] " " example
regsub -all {<[^>]*?>} [string trim [decode $example]] "" example;
lappend list "$definition[expr {$example == "" ? "" : " ($example)"}]";
}
return [concat [llength $list] $list];
}
proc urbandict::urlencode {i} {
variable encoding
set index 0;
set i [encoding convertto $encoding $i]
set length [string length $i]
set n ""
while {$index < $length} {
set activechar [string index $i $index]
incr index 1
if {![regexp {^[a-zA-Z0-9]$} $activechar]} {
append n %[format "%02X" [scan $activechar %c]]
} else {
append n $activechar
}
}
return $n
}
proc urbandict::pub {nick host hand chan argv} {
variable flood; variable antiflood; variable max_lines;
if {![info exists flood($chan)]} { set flood($chan) 0; }
if {![string compare $argv ""]} {
puthelp "NOTICE $nick :Usage: !ud \[id\] <definition>";
return 1;
}
if {[string is digit -strict [getword $argv 0]]} {
if {[splitline $argv cargv 2]!=2} {
puthelp "NOTICE $nick :Usage: !ud \[id\] <definition>";
return 1;
}
set id [lindex $cargv 0];
set argv [lindex $cargv 1];
if {!$id} {
set id 1;
}
} else {
set id 1;
}
if {[unixtime] - $flood($chan) <= $antiflood} { return 0; }
set flood($chan) [unixtime];
set definitions [getdefinition $argv];
set count [lindex $definitions 0];
if {!$count} {
puthelp "PRIVMSG $chan :Nothing found for \"$argv\".";
return 1;
} elseif {$id > $count} {
puthelp "PRIVMSG $chan :Only $count results found for \"$argv\".";
return 1;
}
set definition [lindex $definitions $id];
if {[string length $definition] <= 400} {
puthelp "PRIVMSG $chan :\[\002$id/$count\002\] $definition";
return 0;
}
set skip 0;
set definition [splitmsg $definition];
set required_lines [llength $definition];
foreach line $definition {
puthelp "PRIVMSG $chan :\[\002$id/$count\002\] $line";
if {[incr skip] == $max_lines && $required_lines != $max_lines} {
puthelp "PRIVMSG $chan :\[\002$id/$count\002\] Truncated output to 3 of $required_lines lines.";
break;
}
}
return 0;
}
proc urbandict::decode {content} {
if {![string match *&* $content]} {
return $content;
}
set escapes {
\x20 " \x22 & \x26 ' \x27 – \x2D
< \x3C > \x3E ˜ \x7E € \x80 ¡ \xA1
¢ \xA2 £ \xA3 ¤ \xA4 ¥ \xA5 ¦ \xA6
§ \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB
¬ \xAC \xAD ® \xAE &hibar; \xAF ° \xB0
± \xB1 ² \xB2 ³ \xB3 ´ \xB4 µ \xB5
¶ \xB6 · \xB7 ¸ \xB8 ¹ \xB9 º \xBA
» \xBB ¼ \xBC ½ \xBD ¾ \xBE ¿ \xBF
À \xC0 Á \xC1 Â \xC2 Ã \xC3 Ä \xC4
Å \xC5 Æ \xC6 Ç \xC7 È \xC8 É \xC9
Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE
Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3
Ô \xD4 Õ \xD5 Ö \xD6 × \xD7 Ø \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
÷ \xF7 ø \xF8 ù \xF9 ú \xFA û \xFB
ü \xFC ý \xFD þ \xFE ÿ \xFF
};
set content [string map $escapes $content];
set content [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] $content];
regsub -all -- {&#([[:digit:]]{1,5});} $content {[format %c [string trimleft "\1" "0"]]} content;
regsub -all -- {&#x([[:xdigit:]]{1,4});} $content {[format %c [scan "\1" %x]]} content;
regsub -all -- {&#?[[:alnum:]]{2,7};} $content "?" content;
return [subst $content];
}
putlog "Script loaded: Urban Dictionary v$urbandict::version by perpleXa";
Code: Select all
set matches [regexp -all -inline {<td class='text' colspan='.' id='.*?'>(.*?)</td} $data];
Code: Select all
if {[regexp -all -inline {<td class='text' colspan='.' id='.*?'>(.*?)</td} $data] != ""} {
set matches [regexp -all -inline {<td class='text' colspan='.' id='.*?'>(.*?)</td} $data];
} elseif {[regexp -all -inline {<div class='text' colspan='.' id='entry.*?'>(.*?)<a class} $data] != ""} {
set matches [regexp -all -inline {<div class='text' colspan='.' id='entry.*?'>(.*?)<a class} $data];
} else {
set matches "";
}