This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

let me google that for you

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
S
Skid00
Voice
Posts: 2
Joined: Tue Jul 14, 2009 12:17 am

let me google that for you

Post by Skid00 »

Hi There


Im searching a tcl script for eggdrop that let me make querys on
"let me google that for you" (http://lmgtfy.com/)

The script should work with a trigger e.g: !lmgtfy <nick> "query"
and should post the result in tinyurl-format in the chan e.g: "<nick>:<tinyurl>"


somebody know a solution?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: let me google that for you

Post by speechles »

Here is a fairly basic adaptation. It lacks several features such as flood protection, checking the url is proper, and other such amenities. This should get you going in the right direction. The webbytin procedure is taken from webby. The name of the procedure altered slightly to prevent conflicting with webby in case both are loaded at the same time.

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
}
*partyline*
.chanset #yourchan +lmgtfy

*afterwards in #yourchan*
<nick> !lmgfty Other_Nick annoying me with your lame requests
<bot> Other_Nick -> http://u.nu/792k

The url given depends on how you set the lmgtfyShortType in the above config.
S
Skid00
Voice
Posts: 2
Joined: Tue Jul 14, 2009 12:17 am

Post by Skid00 »

Many thanks again to speechles...

Works fine :)
M
Michiellll
Voice
Posts: 3
Joined: Fri Jul 29, 2011 6:13 am

Post by Michiellll »

Can I somehow have it not use the shortening url part.

I want it to just spit out the lmgtfy url (apparantly lmgtfy scripts aren't that easy to find)

---
I turned it into this, probably can be done easier I guess, but I just fiddled around a bit with what was in there. Works fine.

Thanks to Snakes on EFnet/#eggtcl with this bit:

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"]"
    }
  }
}
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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)}
	}
}
Enjoy. ;)
Last edited by speechles on Sat Nov 12, 2011 12:27 am, edited 4 times in total.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Why don't you just split $text once and use it from there? Something like

Code: Select all

set text [split $text]
Once the game is over, the king and the pawn go back in the same box.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

While not actually useful to go back and make that change. It does add style points I guess when you read it, knowing that, I felt ashasmed. Check above. +1 for style? Am I right? Do I get a cookie? Anyone? Bueller? Bueller?

Yeah, okay, having made that change what other tiny details did I forget? Any i's undotted or t's uncrossed? Any grammar or spelling teachers reading this thread?
T
Tipsacon

Post by Tipsacon »

speechless
Thanx for the code and don't be picky :lol: There're cookies waiting for you in the kitchen :lol:
Last edited by Tipsacon on Fri Nov 18, 2011 5:52 pm, edited 1 time in total.
F
FightingNavyman
Voice
Posts: 35
Joined: Tue Jan 18, 2011 12:39 pm

lmgtfy

Post by FightingNavyman »

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
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: lmgtfy

Post by speechles »

FightingNavyman 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
Try the edited code above. Sorry 'bout that.. heh
F
FightingNavyman
Voice
Posts: 35
Joined: Tue Jan 18, 2011 12:39 pm

Post by FightingNavyman »

I try the one where you end the post with "enjoy :wink: "
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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)}
   }
}
Enjoy^ 2 ;)
F
FightingNavyman
Voice
Posts: 35
Joined: Tue Jan 18, 2011 12:39 pm

Post by FightingNavyman »

thanks man this works flawlessly :lol: :lol: :lol:
Post Reply