Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'cinch'
- require 'open-uri'
- require 'nokogiri'
- require 'cgi'
- helpers do
- def google(query)
- url = "http://www.google.com/search?q=#{CGI.escape(query)}"
- res = Nokogiri::HTML(open(url)).at("h3.r")
- title = res.text
- link = res.at('a')[:href]
- desc = res.at("./following::div").children.first.text
- rescue
- "No results found"
- else
- CGI.unescape_html "#{title} - #{desc} (#{link})"
- end
- on :message, /^!google (.+)/ do |m, query|
- m.reply google(query)
- end
- bot = Cinch::Bot.new do
- configure do |c|
- c.server = "redacted"
- c.channels = ["#test"]
- c.nick = "Eve"
- c.user = "Eve"
- c.realname = "Eve 1.a"
- end
- on :message, "hello" do |m|
- m.reply "Hello, #{m.user.nick}"
- end
- on :action, "kicks the bot" do |m|
- m.reply "Ouch! Stop kicking me :(", true
- m.reply "I thought you loved me D:", true
- end
- end
- bot.start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement