Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. require 'rubygems'
  2. require 'net/yail/IRCBot'
  3.  
  4. require 'hpricot' # For spitting out titles
  5. require 'open-uri'
  6.  
  7. class Chewy < IRCBot
  8. BOTNAME = 'Chewbotca'
  9. BOTVERSION = '0.0.1'
  10.  
  11. public
  12.  
  13. def initialize(options = {})
  14. options[:username] = BOTNAME
  15. options[:realname] = BOTNAME
  16. options[:nicknames] = %w[ chewy chewbotca surfxica ]
  17. options[:irc_network] = 'irc.freenode.net'
  18. options[:channels] = '#bottest'
  19.  
  20. # Set up IRCBot, our loving parent, and begin
  21. super(options)
  22. self.connect_socket
  23. self.start_listening
  24. end
  25.  
  26. # Add hooks on startup (base class's start method calls add_custom_handlers)
  27. def add_custom_handlers
  28. # Set up hooks
  29. @irc.prepend_handler(:incoming_msg, self.method(:sort_incoming))
  30. end
  31.  
  32. private
  33.  
  34. def sort_incoming(fullactor, user, channel, text)
  35. if channel =~ /#{bot_name}/
  36. in_privmsg(user, text)
  37. else
  38. in_channel(user, channel, text)
  39. end
  40. end
  41.  
  42. def in_channel(user, channel, text)
  43. if text =~ /^http/
  44. site_title = grab_site_title(text)
  45. msg(channel, "Title: #{site_title}") unless site_title.nil?
  46. end
  47. end
  48.  
  49. def grab_site_title(address)
  50. site = Hpricot( open(address) )
  51. title = (site/"title").inner_html
  52. title.strip
  53. end
  54. end
Add Comment
Please, Sign In to add comment