Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Created November 18, 2008 23:29
Show Gist options
  • Save ab5tract/26333 to your computer and use it in GitHub Desktop.
Save ab5tract/26333 to your computer and use it in GitHub Desktop.
ab5tract really is the bomb
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