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 

Twitter tweet displayer

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
fewyn
Voice


Joined: 28 Dec 2004
Posts: 15

PostPosted: Mon Aug 29, 2011 4:51 pm    Post subject: Twitter tweet displayer Reply with quote

I've seen bots that have done this in the past but for the life of me I can't find a script anywhere that does something like this.

Basically when someone pastes a a twitter url into chat it goes and fetches the tweet and spits it back out into IRC.

Example:
<fewyn> https://twitter.com/#!/wilw/statuses/108277782815051776
<Bot> Our caterers put out franks and beans to go with lunch, labeled as "Tubesteak Chowder." My inner 12 year-old is still laughing. #Eureka (wilw, 9m ago)

Any help?
Back to top
View user's profile Send private message AIM Address MSN Messenger
speechles
Revered One


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

PostPosted: Mon Aug 29, 2011 5:19 pm    Post subject: Reply with quote

Have you seen Birdy?

While it doesn't yet allow referencing an exact tweet via ID, such as what you are doing. It allows for much more "interaction" than just spewing what someone on twitter tweets. With Birdy you can also, reply to them via !tweet. !retweet them. Etc Etc

Maybe this is more than what you wanted. Basically any url-title fetching type script with minor changes to it's parsing template can do what you are asking. As basically, you are feeding it URL's. Pretty dead simple. Instead give the users of your IRC channel something more to play with. Their own twitter account for the channel to use. This is what Birdy allows you to do.

Anyways, didn't know if you've already seen Birdy or not. It shall be updated soon to fix the shortcomings and errors it presently has. It is a constant work-in-progress and users dictate its evolution. So if you have a feature or something to include within Birdy. Shout it out. Wink
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
fewyn
Voice


Joined: 28 Dec 2004
Posts: 15

PostPosted: Mon Aug 29, 2011 5:28 pm    Post subject: Reply with quote

speechles wrote:
Have you seen Birdy?

While it doesn't yet allow referencing an exact tweet via ID, such as what you are doing. It allows for much more "interaction" than just spewing what someone on twitter tweets. With Birdy you can also, reply to them via !tweet. !retweet them. Etc Etc

Maybe this is more than what you wanted. Basically any url-title fetching type script with minor changes to it's parsing template can do what you are asking. As basically, you are feeding it URL's. Pretty dead simple. Instead give the users of your IRC channel something more to play with. Their own twitter account for the channel to use. This is what Birdy allows you to do.

Anyways, didn't know if you've already seen Birdy or not. It shall be updated soon to fix the shortcomings and errors it presently has. It is a constant work-in-progress and users dictate its evolution. So if you have a feature or something to include within Birdy. Shout it out. Wink


Yeah I saw Birdy but it's a bit more than I want actually. Just want to keep it simple.
Back to top
View user's profile Send private message AIM Address MSN Messenger
speechles
Revered One


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

PostPosted: Mon Aug 29, 2011 7:40 pm    Post subject: Reply with quote

fewyn wrote:


Yeah I saw Birdy but it's a bit more than I want actually. Just want to keep it simple.


Problem is, with that /#!/ in the url. It is going to use twitter's api. This uses json xml payloads. You won't be able to go about it as easily as you are thinking reading those. Because they are handled under oauth.


Instead... What you can do is use their non-api method, which still exists.

Quote:
<speechles> !webby twitter.com/wilw/statuses/108277782815051776 --regexp class="entry-content">(.*?)</span>.*?<span class="published timestamp".*?>(.*?)</a></span>--
<sp33chy> regexp: capture1 ( Our caterers put out franks and beans to go with lunch, labeled as "Tubesteak Chowder." My inner 12 year-old is still laughing. #Eureka )
<sp33chy> regexp: capture2 ( about 2 hours ago via Twitter for iPad )


Webby proves that can be done.. So here's what I'm giving you.

Quote:
<speechles> http://twitter.com/wilw/statuses/108277782815051776
<sp33chy> wilw (Wil Wheaton): Our caterers put out franks and beans to go with lunch, labeled as "Tubesteak Chowder." My inner 12 year-old is still laughing. #Eureka ( http://twitter.com/search?q=%23Eureka ) ( about 3 hours ago via Twitter for iPad )


Code:
# Script to grab titles from webpages - Copyright C.Leonhardt (rosc2112 at yahoo com) Aug.11.2007
# http://members.dandy.net/~fbn/urltitle.tcl.txt
# Loosely based on the tinyurl script by Jer and other bits and pieces of my own..
# Hacked by speechles, to add special things for twitter! :P

################################################################################################################

# Usage:

# 1) Set the configs below
# 2) .chanset #channelname +urltitle        ;# enable script
# 3) .chanset #channelname +logurltitle     ;# enable logging
# Then just input a url in channel and the script will retrieve the title from the corresponding page.

# When reporting bugs, PLEASE include the .set errorInfo debug info!
# Read here: http://forum.egghelp.org/viewtopic.php?t=10215

################################################################################################################

# Configs:

set urltitle(ignore) "bdkqr|dkqr"    ;# User flags script will ignore input from
set urltitle(pubmflags) "-|-"       ;# user flags required for channel eggdrop use
set urltitle(length) 5          ;# minimum url length to trigger channel eggdrop use
set urltitle(delay) 1          ;# minimum seconds to wait before another eggdrop use
set urltitle(timeout) 60000       ;# geturl timeout (1/1000ths of a second)

################################################################################################################
# Script begins:

package require http         ;# You need the http package..
set urltitle(last) 111          ;# Internal variable, stores time of last eggdrop use, don't change..
setudef flag urltitle         ;# Channel flag to enable script.
setudef flag logurltitle      ;# Channel flag to enable logging of script.

set urltitlever "0.01a"
bind pubm $urltitle(pubmflags) {*://*} pubm:urltitle
proc pubm:urltitle {nick host user chan text} {
   global urltitle
   if {([channel get $chan urltitle]) && ([expr [unixtime] - $urltitle(delay)] > $urltitle(last)) && \
   (![matchattr $user $urltitle(ignore)])} {
      foreach word [split $text] {
         if {[string length $word] >= $urltitle(length) && \
         [regexp {^(f|ht)tp(s|)://} $word] && \
         ![regexp {://([^/:]*:([^/]*@|\d+(/|$))|.*/\.)} $word]} {
            set urltitle(last) [unixtime]
            set urtitle [urltitle $word]
            if {[llength $urtitle] < 2} {
               puthelp "PRIVMSG $chan :$nick: URL Title for $word - \002[join [url_map $urtitle]]\002"
            } else {
               puthelp "PRIVMSG $chan :[url_map [url_map [lindex $urtitle 0]]]"
            }
            break
         }
      }
        }
   if {[channel get $chan logurltitle]} {
      foreach word [split $text] {
         if {[string match "*://*" $word]} {
            putlog "<$nick:$chan> $word -> $urtitle"
         }
      }
   }
   # change to return 0 if you want the pubm trigger logged additionally..
   return 1
}

proc urltitle {url} {
   if {[info exists url] && [string length $url]} {
      catch {set http [::http::geturl $url -timeout $::urltitle(timeout)]} error
      if {[string match -nocase "*couldn't open socket*" $error]} {
         return "Error: couldn't connect..Try again later"
      }
      if { [::http::status $http] == "timeout" } {
         return "Error: connection timed out while trying to contact $url"
      }
      set data [::http::data $http]
      regsub -all {(?:\n|\t|\v|\r|\x01)} $data " " data
      set ncode [http::ncode $http]
      ::http::cleanup $http
      set title ""
      if {[string match *twitter.com* $url]} {
         while {[string match 30* $ncode]} {
            regexp -nocase -- {<a href="(.*?)">} $data - url
            regexp -all -- {/#!} $url "" url
            catch {set http [::http::geturl $url -timeout $::urltitle(timeout)]} error
            if {[string match -nocase "*couldn't open socket*" $error]} {
               return "Error: couldn't connect..Try again later"
            }
            if { [::http::status $http] == "timeout" } {
               return "Error: connection timed out while trying to contact $url"
            }
            set data [::http::data $http]
            set ncode [::http::ncode $http]
            http::cleanup $http
         }
         regsub -all {(?:\n|\t|\v|\r|\x01)} $data " " data
         if {[regexp -nocase {class="entry-content">(.*?)</span>.*?<span class="published timestamp" data=".*?">(.*?)</a></span>} $data match ltweet ago]} {
            # scrub html elements out
            regsub -all {<.*?>} $ago "" ago
            regsub -all -nocase -- {<a href="(/search\?q\=.*?)".*?>(.*?)</a>} [string trim $ltweet] "\\2 ( http://twitter.com\\1 \)" ltweet
            regsub -all -nocase -- {<a href="(.*?)".*?>(.*?)</a>} $ltweet "( \\1 \)" ltweet
            regsub -all -nocase -- {(?!&lt;@)<a class="tweet.*?href="(.*?)".*?>(.*?)</a>(?!&gt;)} $ltweet "\\2 \( _\?\=\\1 \)" ltweet
            regsub -all -nocase -- {&lt;\+@<a class="tweet.*?href=".*?".*?>(.*?)</a>&gt;} $ltweet "<+@\\1>" ltweet
            regsub -all -nocase -- {&lt;\@<a class="tweet.*?href=".*?".*?>(.*?)</a>&gt;} $ltweet "<@\\1>" ltweet
            regsub -all -nocase -- {_\?\=(.*?) } $ltweet "http://twitter.com\\1 " ltweet
            regexp -nocase {class="tweet-url screen-name" hreflang="[a-z]{2}" title="(.*?)">(.*?)</a>} $data match real screen
            return [list "\002$screen\002 ($real): $ltweet ( $ago )" "twitter"]
         }
      } elseif {[regexp -nocase {<title>(.*?)</title>} $data match title]} {
         return [list "[string map { {href=} "" \" "" } $title]"]
      } else {
         return [list "No title found."]
      }
   }
}

proc url_map {text {char "utf-8"} } {
   # code below is neccessary to prevent numerous html markups
   # from appearing in the output (ie, &quot;, ᘧ, etc)
   # stolen (borrowed is a better term) from tcllib's htmlparse ;)
   # works unpatched utf-8 or not, unlike htmlparse::mapEscapes
   # which will only work properly patched....
   set escapes {
      &nbsp; \xa0 &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
      &macr; \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 &fnof; \u192 &Alpha; \u391 &Beta; \u392 &Gamma; \u393 &Delta; \u394
      &Epsilon; \u395 &Zeta; \u396 &Eta; \u397 &Theta; \u398 &Iota; \u399
      &Kappa; \u39A &Lambda; \u39B &Mu; \u39C &Nu; \u39D &Xi; \u39E
      &Omicron; \u39F &Pi; \u3A0 &Rho; \u3A1 &Sigma; \u3A3 &Tau; \u3A4
      &Upsilon; \u3A5 &Phi; \u3A6 &Chi; \u3A7 &Psi; \u3A8 &Omega; \u3A9
      &alpha; \u3B1 &beta; \u3B2 &gamma; \u3B3 &delta; \u3B4 &epsilon; \u3B5
      &zeta; \u3B6 &eta; \u3B7 &theta; \u3B8 &iota; \u3B9 &kappa; \u3BA
      &lambda; \u3BB &mu; \u3BC &nu; \u3BD &xi; \u3BE &omicron; \u3BF
      &pi; \u3C0 &rho; \u3C1 &sigmaf; \u3C2 &sigma; \u3C3 &tau; \u3C4
      &upsilon; \u3C5 &phi; \u3C6 &chi; \u3C7 &psi; \u3C8 &omega; \u3C9
      &thetasym; \u3D1 &upsih; \u3D2 &piv; \u3D6 &bull; \u2022
      &hellip; \u2026 &prime; \u2032 &Prime; \u2033 &oline; \u203E
      &frasl; \u2044 &weierp; \u2118 &image; \u2111 &real; \u211C
      &trade; \u2122 &alefsym; \u2135 &larr; \u2190 &uarr; \u2191
      &rarr; \u2192 &darr; \u2193 &harr; \u2194 &crarr; \u21B5
      &lArr; \u21D0 &uArr; \u21D1 &rArr; \u21D2 &dArr; \u21D3 &hArr; \u21D4
      &forall; \u2200 &part; \u2202 &exist; \u2203 &empty; \u2205
      &nabla; \u2207 &isin; \u2208 &notin; \u2209 &ni; \u220B &prod; \u220F
      &sum; \u2211 &minus; \u2212 &lowast; \u2217 &radic; \u221A
      &prop; \u221D &infin; \u221E &ang; \u2220 &and; \u2227 &or; \u2228
      &cap; \u2229 &cup; \u222A &int; \u222B &there4; \u2234 &sim; \u223C
      &cong; \u2245 &asymp; \u2248 &ne; \u2260 &equiv; \u2261 &le; \u2264
      &ge; \u2265 &sub; \u2282 &sup; \u2283 &nsub; \u2284 &sube; \u2286
      &supe; \u2287 &oplus; \u2295 &otimes; \u2297 &perp; \u22A5
      &sdot; \u22C5 &lceil; \u2308 &rceil; \u2309 &lfloor; \u230A
      &rfloor; \u230B &lang; \u2329 &rang; \u232A &loz; \u25CA
      &spades; \u2660 &clubs; \u2663 &hearts; \u2665 &diams; \u2666
      &quot; \x22 &amp; \x26 &lt; \x3C &gt; \x3E O&Elig; \u152 &oelig; \u153
      &Scaron; \u160 &scaron; \u161 &Yuml; \u178 &circ; \u2C6
      &tilde; \u2DC &ensp; \u2002 &emsp; \u2003 &thinsp; \u2009
      &zwnj; \u200C &zwj; \u200D &lrm; \u200E &rlm; \u200F &ndash; \u2013
      &mdash; \u2014 &lsquo; \u2018 &rsquo; \u2019 &sbquo; \u201A
      &ldquo; \u201C &rdquo; \u201D &bdquo; \u201E &dagger; \u2020
      &Dagger; \u2021 &permil; \u2030 &lsaquo; \u2039 &rsaquo; \u203A
      &euro; \u20AC &apos; \u0027
   };
   if {![string equal $char [encoding system]]} { set text [encoding convertfrom $char $text] }
   set text [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\"" "\\\""] [string map $escapes $text]]
   regsub -all -- {&#([[:digit:]]{1,5});} $text {[format %c [string trimleft "\1" "0"]]} text
   regsub -all -- {&#x([[:xdigit:]]{1,4});} $text {[format %c [scan "\1" %x]]} text
   catch { set text "[subst "$text"]" }
   if {![string equal $char [encoding system]]} { set text [encoding convertto $char $text] }
   return "$text"
}


putlog "Url Title Grabber $urltitlever (rosc) script loaded.. (super action rocket missles by speechles :P)"

Basically, yeah, it's rosc2112's good old url-title grabber. Hacked together with my url decoder thingy from my other scripts. So this script will also, show the title of url's pasted. But when it's a twitter one it sees, it will reply differently. I hacked in small modification that is extensible. This is the direction the script Webby I wrote is headed in. It will have custom parsing templates and all sorts of crazy stuff. But this may take time, months, years.. who knows.. But I do know how to accomplish it, all I need is time, and motivation... haw
_________________
speechles' eggdrop tcl archive
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
Page 1 of 1

 
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