egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Latest Urban Dictionary tcl
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
Trixar_za
Op


Joined: 18 Nov 2009
Posts: 143
Location: South Africa

PostPosted: Mon Jul 08, 2013 7:14 pm    Post subject: Reply with quote

Change:
Code:
set matches [regexp -all -inline {<td class='text' colspan='3' id='.*?'>(.*?)</td} $data];
to
Code:
set matches [regexp -all -inline {<td class='text' colspan='.' id='.*?'>(.*?)</td} $data];

For those that are interested, I modified this script to be more like mine and made a zip archive of it with fsck.tcl and http.tcl included for easy use. You can download it here.
_________________
http://www.trixarian.net/Projects
Back to top
View user's profile Send private message Visit poster's website
goalie204
Halfop


Joined: 28 Apr 2011
Posts: 44

PostPosted: Mon Jul 08, 2013 8:14 pm    Post subject: Reply with quote

thx for the fix,

what is yours like that it is more like yours?
Back to top
View user's profile Send private message
Trixar_za
Op


Joined: 18 Nov 2009
Posts: 143
Location: South Africa

PostPosted: Mon Jul 08, 2013 8:45 pm    Post subject: Reply with quote

Default:
[~Trixar_za] -ud test
[@GameBot] [1/8] A process for testing things (This is a test message)

My way:
[~Trixar_za] !ud test
[@GameBot] Definition [1/8]: A process for testing things
[@GameBot] Example [1/8]: This is a test message

Just feels nicer this way.
_________________
http://www.trixarian.net/Projects
Back to top
View user's profile Send private message Visit poster's website
goalie204
Halfop


Joined: 28 Apr 2011
Posts: 44

PostPosted: Wed Jul 10, 2013 7:14 am    Post subject: Reply with quote

Ya, that would be nice, but for long definitions it's going to be too spammy Sad
Back to top
View user's profile Send private message
Trixar_za
Op


Joined: 18 Nov 2009
Posts: 143
Location: South Africa

PostPosted: Sat Jul 13, 2013 11:49 pm    Post subject: Reply with quote

goalie204 wrote:
Ya, that would be nice, but for long definitions it's going to be too spammy Sad
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.
_________________
http://www.trixarian.net/Projects
Back to top
View user's profile Send private message Visit poster's website
Trixar_za
Op


Joined: 18 Nov 2009
Posts: 143
Location: South Africa

PostPosted: Tue Sep 17, 2013 5:44 pm    Post subject: Reply with quote

Update: http://www.trixarian.net/downloads/urband.zip

Changes:
* The maximum amount of lines for definitions and examples can now be set individually.
* The bug that made it not show definitions without examples has been fixed.
* The included http.tcl has been updated.

Enjoy! Wink
_________________
http://www.trixarian.net/Projects
Back to top
View user's profile Send private message Visit poster's website
spithash
Master


Joined: 12 Jul 2007
Posts: 245
Location: DALnet, EFnet & Freenode

PostPosted: Thu Sep 26, 2013 8:58 am    Post subject: Reply with quote

awesome Smile
_________________
DALnet #CodeMasters - EFnet #eggtcl Nick: spithash
Click here for troll.tcl
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
spithash
Master


Joined: 12 Jul 2007
Posts: 245
Location: DALnet, EFnet & Freenode

PostPosted: Sat Oct 05, 2013 4:00 pm    Post subject: Reply with quote

I think that the script needs update again Rolling Eyes
_________________
DALnet #CodeMasters - EFnet #eggtcl Nick: spithash
Click here for troll.tcl
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
sputnik
Voice


Joined: 23 Feb 2011
Posts: 20

PostPosted: Mon Oct 07, 2013 8:49 am    Post subject: Reply with quote

Replacing
Code:
set matches [regexp -all -inline {<td class='text' colspan='.' id='.*?'>(.*?)</td} $data];

with
Code:
set matches [regexp -all -inline {<div class='text' colspan='.' id='.*?'>(.*?)</div>\n} $data];

should do the trick.
Back to top
View user's profile Send private message
sputnik
Voice


Joined: 23 Feb 2011
Posts: 20

PostPosted: Mon Oct 07, 2013 9:13 am    Post subject: Reply with quote

Ok, this should work a little bit better:
Code:
set matches [regexp -all -inline {<div class='text' colspan='.' id='.*?'>(.*?)</div>\n<div class='zazzle_links'>} $data];

but it's still dirty one. It's gonna stop working as soon as urban dictionary changes their html again.
Back to top
View user's profile Send private message
slaapliedje
Voice


Joined: 30 Jul 2012
Posts: 5

PostPosted: Tue Oct 08, 2013 9:14 am    Post subject: Reply with quote

I made the changes to the new version of the urband.tcl file as posted here yesterday, but unfortunately, (after unzipping the latest version a few posts back) the script no longer works at all.

I'm getting this error;

[07:11:23] Tcl error [::urbandict::pub]: can't read "define": no such variable

Any ideas?
Back to top
View user's profile Send private message
sputnik
Voice


Joined: 23 Feb 2011
Posts: 20

PostPosted: Tue Oct 08, 2013 9:40 am    Post subject: Reply with quote

The thing is i don't really remember which version of the script i have. The above solution only works with the version i have. So here's the script:
Code:
# 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 {
    &nbsp; \x20 &quot; \x22 &amp; \x26 &apos; \x27 &ndash; \x2D
    &lt; \x3C &gt; \x3E &tilde; \x7E &euro; \x80 &iexcl; \xA1
    &cent; \xA2 &pound; \xA3 &curren; \xA4 &yen; \xA5 &brvbar; \xA6
    &sect; \xA7 &uml; \xA8 &copy; \xA9 &ordf; \xAA &laquo; \xAB
    &not; \xAC &shy; \xAD &reg; \xAE &hibar; \xAF &deg; \xB0
    &plusmn; \xB1 &sup2; \xB2 &sup3; \xB3 &acute; \xB4 &micro; \xB5
    &para; \xB6 &middot; \xB7 &cedil; \xB8 &sup1; \xB9 &ordm; \xBA
    &raquo; \xBB &frac14; \xBC &frac12; \xBD &frac34; \xBE &iquest; \xBF
    &Agrave; \xC0 &Aacute; \xC1 &Acirc; \xC2 &Atilde; \xC3 &Auml; \xC4
    &Aring; \xC5 &AElig; \xC6 &Ccedil; \xC7 &Egrave; \xC8 &Eacute; \xC9
    &Ecirc; \xCA &Euml; \xCB &Igrave; \xCC &Iacute; \xCD &Icirc; \xCE
    &Iuml; \xCF &ETH; \xD0 &Ntilde; \xD1 &Ograve; \xD2 &Oacute; \xD3
    &Ocirc; \xD4 &Otilde; \xD5 &Ouml; \xD6 &times; \xD7 &Oslash; \xD8
    &Ugrave; \xD9 &Uacute; \xDA &Ucirc; \xDB &Uuml; \xDC &Yacute; \xDD
    &THORN; \xDE &szlig; \xDF &agrave; \xE0 &aacute; \xE1 &acirc; \xE2
    &atilde; \xE3 &auml; \xE4 &aring; \xE5 &aelig; \xE6 &ccedil; \xE7
    &egrave; \xE8 &eacute; \xE9 &ecirc; \xEA &euml; \xEB &igrave; \xEC
    &iacute; \xED &icirc; \xEE &iuml; \xEF &eth; \xF0 &ntilde; \xF1
    &ograve; \xF2 &oacute; \xF3 &ocirc; \xF4 &otilde; \xF5 &ouml; \xF6
    &divide; \xF7 &oslash; \xF8 &ugrave; \xF9 &uacute; \xFA &ucirc; \xFB
    &uuml; \xFC &yacute; \xFD &thorn; \xFE &yuml; \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";
Back to top
View user's profile Send private message
slaapliedje
Voice


Joined: 30 Jul 2012
Posts: 5

PostPosted: Tue Oct 08, 2013 10:08 am    Post subject: Reply with quote

Sweet, thanks! That version works! At least until next time.
Back to top
View user's profile Send private message
neocharles
Voice


Joined: 23 Apr 2013
Posts: 34

PostPosted: Tue Oct 08, 2013 11:26 am    Post subject: Reply with quote

Is there a version that doesn't use fsck?

I noticed when I have fsck loading (well, I had to take out the package require fsck 1.10; line from the ud.tcl file to get ud to load, but I noticed that it had an error when I rehashed:

fatal error(fsck): Couldn't load scripts/steiner-youtube.tcl [can't find package json]

Without fsck, it loads fine..
Back to top
View user's profile Send private message
Trixar_za
Op


Joined: 18 Nov 2009
Posts: 143
Location: South Africa

PostPosted: Wed Oct 09, 2013 8:38 am    Post subject: Reply with quote

Replace
Code:
set matches [regexp -all -inline {<td class='text' colspan='.' id='.*?'>(.*?)</td} $data];
with
Code:
  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 "";
  }
This should make it a bit more future proof and it's already updated @ http://www.trixarian.net/downloads/urband.zip

I try to keep the regexes as generic as possible because zazzle_links and it's like may change in the future. The initial one actually broke examples, which is why my version freaked out

neocharles: Try my urban.tcl @ http://www.trixarian.net/Projects/
_________________
http://www.trixarian.net/Projects


Last edited by Trixar_za on Wed Oct 09, 2013 4:26 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 3 of 6

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber