Created
November 18, 2008 23:29
-
-
Save ab5tract/26333 to your computer and use it in GitHub Desktop.
ab5tract really is the bomb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'net/yail/IRCBot' | |
require 'hpricot' # For spitting out titles | |
require 'open-uri' | |
class Chewy < IRCBot | |
BOTNAME = 'Chewbotca' | |
BOTVERSION = '0.0.1' | |
public | |
def initialize(options = {}) | |
options[:username] = BOTNAME | |
options[:realname] = BOTNAME | |
options[:nicknames] = %w[ chewy chewbotca surfxica ] | |
options[:irc_network] = 'irc.freenode.net' | |
options[:channels] = '#bottest' | |
# Set up IRCBot, our loving parent, and begin | |
super(options) | |
self.connect_socket | |
self.start_listening | |
end | |
# Add hooks on startup (base class's start method calls add_custom_handlers) | |
def add_custom_handlers | |
# Set up hooks | |
@irc.prepend_handler(:incoming_msg, self.method(:sort_incoming)) | |
end | |
private | |
def sort_incoming(fullactor, user, channel, text) | |
if channel =~ /#{bot_name}/ | |
in_privmsg(user, text) | |
else | |
in_channel(user, channel, text) | |
end | |
end | |
def in_channel(user, channel, text) | |
if text =~ /^http/ | |
site_title = grab_site_title(text) | |
msg(channel, "Title: #{site_title}") unless site_title.nil? | |
end | |
end | |
def grab_site_title(address) | |
site = Hpricot( open(address) ) | |
title = (site/"title").inner_html | |
title.strip | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment