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 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
piggy
Voice


Joined: 21 Aug 2005
Posts: 14
Location: London

PostPosted: Fri Aug 25, 2006 10:30 am    Post subject: Latest Urban Dictionary tcl Reply with quote

If anyone can help me out with this it would be most appreciated.
Alternatively if i should be contacting the author directly for this please let me know.

1) Is it possible to make it that the script below can be set for specific channels, eg: .chanset #channel +urbandictionary or any otherway of specifying what channels it should respond in?

2) Is there something that can be added that it prevents two users from issueing the same command within say 3 minutes.
eg:
<nick1> -ud irc
<nick2> -ud irc

Because as it is now when <nick1> issues "-ud irc" the bot displays the result and if <nick2> where to issue the same "-ud irc" 5 seconds later the bot would then display the result again.

Code:
# Urban Dictionary
# Copyright (C) 2006 perpleXa
# http://perplexa.ugug.co.uk / #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.7;
  variable encoding "utf-8";
  variable client "Mozilla/5.0 (compatible; Y!J; for robot study; keyoshid)";
  bind pub -|- "-ud" [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=\"def_p\">.*?<p>(.*?)<\/p>} $data];
  set list [list];
  foreach {null definition} $matches {
    regsub -all {<[^>]*?>} [decode $definition] "" definition;
    regsub -all {[\r\n\s\t]+} $definition " " definition;
    lappend list $definition;
  }
  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} {
  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;
  }
  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 :\[$id/$count\] $definition";
    return 0;
  }
  foreach line [splitmsg $definition] {
    puthelp "PRIVMSG $chan :\[$id/$count\] $line";
  }
  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
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Aug 25, 2006 12:36 pm    Post subject: Reply with quote

Yep. That's a mod I did to this script myself, too:

Code:

Near the top add:

set udchans "#mychan #chan2 #etc"

Then at the top of "proc urbandict::pub" add:

if {[lsearch -exact $::udchans $chan] == -1} {return}


That's it! Nice script by the way, thank you perplexa! Smile

Opps I missed the 2nd part of your question. I did not add a timer, I changed the responses from $chan to $nick, since the responses can be really long and I don't need it spamming the channel. Someone else might be able to post a timer for you tho.
Back to top
View user's profile Send private message
piggy
Voice


Joined: 21 Aug 2005
Posts: 14
Location: London

PostPosted: Fri Aug 25, 2006 12:57 pm    Post subject: Reply with quote

rosc2112

Thanks for the help on that one, your solution works perfectly Very Happy

Quote:
I did not add a timer, I changed the responses from $chan to $nick,

I will keep that in mind if i allow -ud to be used in other channels, but for now i have one channel specificly for urban dictionary requests.

Thanks again.
Back to top
View user's profile Send private message
piggy
Voice


Joined: 21 Aug 2005
Posts: 14
Location: London

PostPosted: Sat Sep 02, 2006 11:23 am    Post subject: Reply with quote

rosc2112:

You wouldnt perhaps know what i can add to the code of this tcl to make it that a user can /msg <botnick> -ud <search string> and the bot will then display the result in private to that user that msg'd the bot?

Thanks
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Sep 02, 2006 5:55 pm    Post subject: Reply with quote

Add this somewhere above where the proc's begin:
Code:

bind msg - !ud udmsg
proc udmsg {nick uhost hand text} {
        urbandict::pub $nick $uhost $hand privmsg $text
}


And in proc urbandict::pub

Change:

        if {[lsearch -exact $::udchans $chan] == -1} {return}

to:

        if {([lsearch -exact $::udchans $chan] == -1) && ($chan != "privmsg")} {return} 

And add:

        if {$chan == "privmsg"} {set chan $nick}


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


Joined: 21 Aug 2005
Posts: 14
Location: London

PostPosted: Sun Sep 03, 2006 2:31 am    Post subject: Reply with quote

rosc2112: You right, that does do the trick.

Thanks alot for your help Smile
Back to top
View user's profile Send private message
teeone
Voice


Joined: 30 Jun 2007
Posts: 2

PostPosted: Sat Jun 30, 2007 12:34 am    Post subject: fsck package Reply with quote

# fsck is available at http://perplexa.ugug.co.uk
package require fsck 1.10;

does anybody have this package available to download? That website has been dead for the last few weeks now :(

thx
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sat Jun 30, 2007 12:57 am    Post subject: Re: fsck package Reply with quote

teeone wrote:
# fsck is available at http://perplexa.ugug.co.uk
package require fsck 1.10;

does anybody have this package available to download? That website has been dead for the last few weeks now Sad

thx
Here is perplexa's package:
* fsck package 1.14+

Here is the latest urban dictionary script:
* urbandict.tcl [v1.8]
Back to top
View user's profile Send private message
teeone
Voice


Joined: 30 Jun 2007
Posts: 2

PostPosted: Sat Jun 30, 2007 7:51 am    Post subject: Reply with quote

Thank you thank you thank you! UD is hilarious ;)
Back to top
View user's profile Send private message
doubleu
Voice


Joined: 10 Feb 2008
Posts: 11

PostPosted: Fri May 02, 2008 1:15 pm    Post subject: Reply with quote

is anyone else having problems with this script now?
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Fri May 02, 2008 2:50 pm    Post subject: Reply with quote

replace:
Code:
set matches [regexp -all -inline {<div class=\"def_p\">.*?<p>(.*?)<\/p>} $data];

with:
Code:
set matches [regexp -all -inline {<div class='definition'>(.*?)</div} $data];
Back to top
View user's profile Send private message
shadrach
Halfop


Joined: 14 Dec 2007
Posts: 74

PostPosted: Mon May 05, 2008 2:17 pm    Post subject: Reply with quote

Appears not to be working again.
Back to top
View user's profile Send private message MSN Messenger
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Wed May 07, 2008 2:55 am    Post subject: Reply with quote

http://forum.egghelp.org/viewtopic.php?t=15715

issues like this should really go thru the ears of the original author first...
contact info for perplexa can be found at the above link.
Back to top
View user's profile Send private message
shadrach
Halfop


Joined: 14 Dec 2007
Posts: 74

PostPosted: Thu May 08, 2008 1:57 pm    Post subject: Reply with quote

It's come back to life.
Back to top
View user's profile Send private message MSN Messenger
doubleu
Voice


Joined: 10 Feb 2008
Posts: 11

PostPosted: Sun May 11, 2008 11:22 pm    Post subject: Reply with quote

and dead again!

Last edited by doubleu on Wed May 21, 2008 3:18 pm; edited 1 time in total
Back to top
View user's profile Send private message
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 1, 2, 3, 4, 5, 6  Next
Page 1 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