Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'cinch'
- require 'open-uri'
- require 'nokogiri'
- require 'cgi'
- class Google
- include Cinch::Plugin
- match /google (.+)/
- def search(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
- CGI.unescape_html "#{title} - #{desc} (#{link})"
- rescue
- "No results found"
- end
- def execute(m, query)
- m.reply(search(query))
- end
- end
- class UrbanDictionary
- include Cinch::Plugin
- match /urban (.+)/
- def lookup(word)
- url = "http://www.urbandictionary.com/define.php?term=#{CGI.escape(word)}"
- CGI.unescape_html Nokogiri::HTML(open(url)).at("div.definition").text.gsub(/\s+/, ' ') rescue nil
- end
- def execute(m, word)
- m.reply(lookup(word) || "No results found", true)
- end
- end
- class JoinPart
- include Cinch::Plugin
- match /join (.+)/, method: :join
- match /part(?: (.+))?/, method: :part
- def initialize(*args)
- super
- @admins = ["injekt", "DominikH"]
- end
- def check_user(user)
- user.refresh # be sure to refresh the data, or someone could steal
- # the nick
- @admins.include?(user.authname)
- end
- def join(m, channel)
- return unless check_user(m.user)
- Channel(channel).join
- end
- def part(m, channel)
- return unless check_user(m.user)
- channel ||= m.channel
- Channel(channel).part if channel
- end
- end
- bot = Cinch::Bot.new do
- configure do |c|
- c.server = "irc.sinsira.net"
- c.channels = ["#test"]
- c.nick = "Eve"
- c.user = "Eve"
- c.realname = "Eve 1.a"
- c.plugins.plugins = [Google]
- c.plugins.plugins = [UrbanDictionary]
- c.plugins.plugins = [JoinPart]
- 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