Code: Select all
# config starts
# which method should be used when shortening the url?
# (0-3) will only use the one you've chosen.
# (4-5) will use them all.
# 0 --> http://tinyurl.com
# 1 --> http://u.nu
# 2 --> http://is.gd
# 3 --> http://cli.gs
# 4 --> randomly select one of the four above ( 2,0,0,3,1..etc )
# 5 --> cycle through the four above ( 0,1,2,3,0,1..etc )
# ---
variable lmgtfyShortType 5
# script starts
package require http
setudef flag lmgtfy
bind pub - !lmgtfy pub:lmgtfy
proc pub:lmgtfy {nick uhost hand chan text} {
if {[channel get $chan lmgtfy]} {
if {[llength [split $text]] < 2} {
putserv "privmsg $chan :!lmgtfy <nick> <search terms here>"
return
} elseif {![onchan [lindex [split $text] 0] $chan]} {
putserv "privmsg $chan :[lindex [split $text] 0] isn't on this channel. If your trying to be funny, consider this a failure to impress me with your wit."
return
} else {
putserv "privmsg $chan :[lindex [split $text] 0] -> [webbytin "http://lmgtfy.com/?[http::formatQuery q [join [lrange [split $text] 1 end]]]" $::lmgtfyShortType]"
}
}
}
proc webbytin {url type} {
set ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"
set http [::http::config -useragent $ua]
switch -- $type {
4 { set type [rand 4] }
5 { if {![info exists ::webbyCount]} {
set ::webbyCount 0
set type 0
} else {
set type [expr {[incr ::webbyCount] % 4}]
}
}
}
switch -- $type {
0 { set query "http://tinyurl.com/api-create.php?[http::formatQuery url $url]" }
1 { set query "http://u.nu/unu-api-simple?[http::formatQuery url $url]" }
2 { set query "http://is.gd/api.php?[http::formatQuery longurl $url]" }
3 { set query "http://cli.gs/api/v1/cligs/create?[http::formatQuery url $url]&title=&key=&appid=webby" }
}
set token [http::geturl $query -timeout 3000]
upvar #0 $token state
if {[string length $state(body)]} { return [string map {"\n" ""} $state(body)] }
return $url
}
Code: Select all
http://lmgtfy.com/?q=[join [lrange $text 1 end] "%20"]"
Code: Select all
# script starts
package require http
setudef flag lmgtfy
bind pub - !lmgtfy pub:lmgtfy
proc pub:lmgtfy {nick uhost hand chan text} {
if {[channel get $chan lmgtfy]} {
if {[llength [split $text]] < 2} {
putserv "privmsg $chan :!lmgtfy <nick> <search terms here>"
return
} elseif {![onchan [lindex [split $text] 0] $chan]} {
putserv "privmsg $chan :[lindex [split $text] 0] isn't on this channel. If your trying to be funny, consider this a failure to impress me with your wit."
return
} else {
putserv "privmsg $chan :[lindex $text 0] -> http://lmgtfy.com/?q=[join [lrange $text 1 end] "%20"]"
}
}
}
A user with a simple request via #eggtcl on efnet, wrote:<frayed> im looking to use a lmgtfy script you wrote a while back and i would like flood timer to go with it
Code: Select all
# config starts
# which method should be used when shortening the url?
# (0-2) will only use the one you've chosen.
# (3-4) will use them all.
# 0 --> http://tinyurl.com
# 1 --> http://is.gd
# 2 --> http://cli.gs
# 3 --> randomly select one of the three above ( 2,0,0,2,1..etc )
# 4 --> cycle through the three above ( 0,1,2,1,0,1..etc )
# ---
variable lmgtfyShortType 4
# seconds people must wait before reusing the command.
variable lmgtfySeconds 30
# script starts
package require http
setudef flag lmgtfy
bind pub - !lmgtfy pub:lmgtfy
proc pub:lmgtfy {nick uhost hand chan text} {
if {[channel get $chan lmgtfy]} {
if {[set throttle [lmgtfy:throttled $uhost,$chan $::lmgtfySeconds]] > 0} {
putserv "notice $nick :Throttled.. My head is spinning. Please wait $throttle seconds."
return
}
if {[llength [set text [split $text]]] < 2} {
putserv "privmsg $chan :!lmgtfy <nick> <search terms here>"
return
} elseif {![onchan [lindex $text 0] $chan]} {
putserv "privmsg $chan :[lindex $text 0] isn't on this channel. If you're trying to be funny, consider this a failure to impress me with your wit."
return
} else {
putserv "privmsg $chan :[lindex $text 0] -> [webbytin "http://lmgtfy.com/?[http::formatQuery q [join [lrange $text 1 end]]]" $::lmgtfyShortType]"
}
}
}
proc webbytin {url type} {
set ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"
set http [::http::config -useragent $ua]
switch -- $type {
3 { set type [rand 3] }
4 { if {![info exists ::webbyCount]} {
set ::webbyCount 0
set type 0
} else {
set type [expr {[incr ::webbyCount] % 3}]
}
}
}
switch -- $type {
0 { set query "http://tinyurl.com/api-create.php?[http::formatQuery url $url]" }
1 { set query "http://is.gd/api.php?[http::formatQuery longurl $url]" }
2 { set query "http://cli.gs/api/v1/cligs/create?[http::formatQuery url $url]&title=&key=&appid=webby" }
}
set token [http::geturl $query -timeout 3000]
upvar #0 $token state
if {[string length $state(body)]} { return [string map {"\n" ""} $state(body)] }
return $url
}
# Throttle Proc - Thanks to user
# see this post: http://forum.egghelp.org/viewtopic.php?t=9009&start=3
proc lmgtfy:throttled {id seconds} {
global lmgtfythrottle
if {[info exists lmgtfythrottle($id)]&&[set val [expr {[clock seconds]-$lmgtfythrottle($id)}]] > 0} {
set id $val
} {
set lmgtfythrottle($id) [expr {[clock seconds]+$seconds}]
set id 0
}
}
# delete expired entries every 10 minutes
bind time - ?0* lmgtfy:throttledCleanup
proc lmgtfy:throttledCleanup args {
global lmgtfythrottle
set now [clock seconds]
foreach {id time} [array get lmgtfythrottle] {
if {$time<=$now} {unset lmgtfythrottle($id)}
}
}
Code: Select all
set text [split $text]
Code: Select all
Tcl error [pub:lmgtfy]: can't read "uhand": no such variable
Try the edited code above. Sorry 'bout that.. hehFightingNavyman wrote:ok i copy pasted the script to a new .tcl fle then load it and go to party line and do: .chanset #chan +lmgtfy then i get this error
Code: Select all
Tcl error [pub:lmgtfy]: can't read "uhand": no such variable
Code: Select all
# config starts
# which method should be used when shortening the url?
# (0-2) will only use the one you've chosen.
# (3-4) will use them all.
# 0 --> http://tinyurl.com
# 1 --> http://is.gd
# 2 --> http://cli.gs
# 3 --> randomly select one of the three above ( 2,0,0,2,1..etc )
# 4 --> cycle through the three above ( 0,1,2,1,0,1..etc )
# ---
variable lmgtfyShortType 4
# seconds people must wait before reusing the command.
variable lmgtfySeconds 30
# script starts
package require http
setudef flag lmgtfy
bind pub - !lmgtfy pub:lmgtfy
proc pub:lmgtfy {nick uhost hand chan text} {
if {[channel get $chan lmgtfy]} {
if {[set throttle [lmgtfy:throttled $uhost,$chan $::lmgtfySeconds]] > 0} {
putserv "notice $nick :Throttled.. My head is spinning. Please wait $throttle seconds."
return
}
if {[llength [set text [split $text]]] < 2} {
putserv "privmsg $chan :!lmgtfy <nick> <search terms here>"
return
} elseif {![onchan [lindex $text 0] $chan]} {
putserv "privmsg $chan :[lindex $text 0] isn't on this channel. If you're trying to be funny, consider this a failure to impress me with your wit."
return
} else {
putserv "privmsg $chan :[lindex $text 0] -> [webbytin "http://lmgtfy.com/?[http::formatQuery q [join [lrange $text 1 end]]]" $::lmgtfyShortType]"
}
}
}
proc webbytin {url type} {
set ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"
set http [::http::config -useragent $ua]
switch -- $type {
3 { set type [rand 3] }
4 { if {![info exists ::webbyCount]} {
set ::webbyCount 0
set type 0
} else {
set type [expr {[incr ::webbyCount] % 3}]
}
}
}
switch -- $type {
0 { set query "http://tinyurl.com/api-create.php?[http::formatQuery url $url]" }
1 { set query "http://is.gd/api.php?[http::formatQuery longurl $url]" }
2 { set query "http://cli.gs/api/v1/cligs/create?[http::formatQuery url $url]&title=&key=&appid=webby" }
}
set token [http::geturl $query -timeout 3000]
upvar #0 $token state
if {[string length $state(body)]} { return [string map {"\n" ""} $state(body)] }
return $url
}
# Throttle Proc - Thanks to user
# see this post: http://forum.egghelp.org/viewtopic.php?t=9009&start=3
proc lmgtfy:throttled {id seconds} {
global lmgtfythrottle
if {[info exists lmgtfythrottle($id)]&&[set val [expr {$lmgtfythrottle($id) - [clock seconds]}]] > 0} {
set id $val
} {
set lmgtfythrottle($id) [expr {[clock seconds]+$seconds}]
set id 0
}
}
# delete expired entries every 10 minutes
bind time - ?0* lmgtfy:throttledCleanup
proc lmgtfy:throttledCleanup args {
global lmgtfythrottle
set now [clock seconds]
foreach {id time} [array get lmgtfythrottle] {
if {$time<=$now} {unset lmgtfythrottle($id)}
}
}