Add Programmer Excuses to Your Eggdrop Bot
Display an excuse from programmerexcuses.com to your channel.
I stumbled across this programmer excuses website and was really amused, so I decided to have a little fun and brush up on my Eggdrop/Tcl skills and create a simple script to have your Eggdrop bot display a random programmer excuse taken from programmerexcuses.com. Simply add this code to your bot's TCL script:
# include the http package
package require http
# bind the procedure to when someone types '!excuse'
bind pub - !excuse pub_excuse
# procedure to display the excuse
proc pub_excuse {nick mask hand channel args} {
# scrape the website to get its full content
set token [http::geturl "http://www.programmerexcuses.com"]
# set the excuse variable which is contained between the only href tag
regexp {<a href(.+?)>(.+?)</a>} [http::data $token]] -> inner_href excuse
# cleanup the connection to avoid memory leaks
http::cleanup $token
# output to the channel
putserv "PRIVMSG $channel :$excuse"
}
Usage in the channel / example:<jayroman> !excuse
<jayrobot> It can't be broken, it passes all unit tests
Before you say anything, yes, the code might a be a little over-commented, but since most developers I run into have limited or no experience with Eggdrop or Tcl, I wanted to be very clear on what every line is doing.
comments powered by Disqus