Advertisement
Guest User

Untitled

a guest
Oct 29th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. require 'cinch'
  2. require 'open-uri'
  3. require 'nokogiri'
  4. require 'cgi'
  5.  
  6. helpers do
  7. def google(query)
  8. url = "http://www.google.com/search?q=#{CGI.escape(query)}"
  9. res = Nokogiri::HTML(open(url)).at("h3.r")
  10.  
  11. title = res.text
  12. link = res.at('a')[:href]
  13. desc = res.at("./following::div").children.first.text
  14. rescue
  15. "No results found"
  16. else
  17. CGI.unescape_html "#{title} - #{desc} (#{link})"
  18. end
  19.  
  20. on :message, /^!google (.+)/ do |m, query|
  21. m.reply google(query)
  22. end
  23.  
  24. bot = Cinch::Bot.new do
  25. configure do |c|
  26. c.server = "redacted"
  27. c.channels = ["#test"]
  28. c.nick = "Eve"
  29. c.user = "Eve"
  30. c.realname = "Eve 1.a"
  31. end
  32.  
  33. on :message, "hello" do |m|
  34. m.reply "Hello, #{m.user.nick}"
  35. end
  36. on :action, "kicks the bot" do |m|
  37. m.reply "Ouch! Stop kicking me :(", true
  38. m.reply "I thought you loved me D:", true
  39. end
  40. end
  41.  
  42. bot.start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement