package require http 2.3 package require ncgi 1.3 # SHORTEN # shortens a long url [shorten "http://long.url"] # set tinyurl(antiflags) "bdkqr|dkqr" ;# user flags to ignore for eggdrop use set tinyurl(msgmflags) "o|o" ;# user flags required for message eggdrop use set tinyurl(pubmflags) "-|-" ;# user flags required for channel eggdrop use set tinyurl(length) 50 ;# minimum url length to trigger channel eggdrop use set tinyurl(delay) 10 ;# minimum seconds to wait before another eggdrop use set tinyurl(last) 408 ;# internal variable, stores time of last eggdrop use bind pub - !short bind pub - !url bind pub - !long lengthen bind pubm - {*://*} shorten-pub proc shorten-engine {word} { set encoded [::ncgi::encode $word] set query [::http::geturl \ http://metamark.net/api/rest/simple?long_url=${encoded}] return [lindex [split [::http::data $query] \n] 0] } proc shorten-pub {nick userhost user chan text} { global tinyurl #putlog "last: $tinyurl(last); now: [unixtime]; delay: $tinyurl(delay)" if {([channel get $chan tinyurl] || [channel get $chan untinyurl]) && [expr\ [unixtime] - $tinyurl(delay)] > $tinyurl(last) && ![matchattr $user\ $tinyurl(antiflags)]} { foreach word [split $text] { if {([channel get $chan tinyurl] && [string length $word] >=\ $tinyurl(length) && [regexp {(f|ht)tp(s|)://} $word] && ![regexp\ {://([^/:]*:([^/]*@|\d+(/|$))|.*/\.)} $word]) && ![regexp {tinyurl} $word] } { set tinyurl(last) [unixtime] putlog "shorten invoked by $nick!$userhost with $word" set url [shorten-engine $word] puthelp "PRIVMSG $chan : $url" } } } } # LENGTHEN proc lengthen {nick userhost handle channel input} { putlog "lengthen invoked by $nick!$userhost with text $input" set query\ [::http::geturl http://metamark.net/api/rest/simple?short_url=${input}] #putlog "[::http::data $query]" set url [lindex [split [::http::data $query] \n] 0] puthelp "PRIVMSG $channel : $url" } setudef flag tinyurl setudef flag untinyurl setudef flag logallurl putlog "urls.tcl by dre^ is loaded."