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 

let me google that for you

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Skid00
Voice


Joined: 14 Jul 2009
Posts: 2

PostPosted: Tue Jul 14, 2009 12:34 am    Post subject: let me google that for you Reply with quote

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?
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: Tue Jul 14, 2009 6:09 pm    Post subject: Re: let me google that for you Reply with quote

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:
# 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.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Skid00
Voice


Joined: 14 Jul 2009
Posts: 2

PostPosted: Tue Jul 21, 2009 12:41 am    Post subject: Reply with quote

Many thanks again to speechles...

Works fine Smile
Back to top
View user's profile Send private message
Michiellll
Voice


Joined: 29 Jul 2011
Posts: 3

PostPosted: Fri Jul 29, 2011 6:22 am    Post subject: Reply with quote

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:
http://lmgtfy.com/?q=[join [lrange $text 1 end] "%20"]"

Code:
# 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"]"
    }
  }
}
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: Tue Nov 01, 2011 8:45 pm    Post subject: Reply with quote

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:
# 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. Wink
_________________
speechles' eggdrop tcl archive


Last edited by speechles on Sat Nov 12, 2011 12:27 am; edited 4 times in total
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Nov 02, 2011 1:39 am    Post subject: Reply with quote

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

set text [split $text]

_________________
Once the game is over, the king and the pawn go back in the same box.
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: Wed Nov 02, 2011 12:50 pm    Post subject: Reply with quote

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?
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Tipsacon
Guest





PostPosted: Thu Nov 10, 2011 12:00 pm    Post subject: Reply with quote

speechless
Thanx for the code and don't be picky Laughing There're cookies waiting for you in the kitchen Laughing


Last edited by Tipsacon on Fri Nov 18, 2011 5:52 pm; edited 1 time in total
Back to top
FightingNavyman
Voice


Joined: 18 Jan 2011
Posts: 35

PostPosted: Fri Nov 11, 2011 11:49 pm    Post subject: lmgtfy Reply with quote

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:
Tcl error [pub:lmgtfy]: can't read "uhand": no such variable
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 Nov 12, 2011 12:19 am    Post subject: Re: lmgtfy Reply with quote

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:
Tcl error [pub:lmgtfy]: can't read "uhand": no such variable


Try the edited code above. Sorry 'bout that.. heh
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
FightingNavyman
Voice


Joined: 18 Jan 2011
Posts: 35

PostPosted: Sat Nov 12, 2011 12:22 am    Post subject: Reply with quote

I try the one where you end the post with "enjoy Wink "
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 Nov 12, 2011 12:32 am    Post subject: Reply with quote

Code:
# 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 Wink
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
FightingNavyman
Voice


Joined: 18 Jan 2011
Posts: 35

PostPosted: Fri Nov 18, 2011 7:11 pm    Post subject: Reply with quote

thanks man this works flawlessly Laughing Laughing Laughing
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 Requests 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