Sha256: 0da5db004fb76979a87227a202d268a34f106a34fbb4e3d628ed7e69e8d7c222

Contents?: true

Size: 767 Bytes

Versions: 2

Compression:

Stored size: 767 Bytes

Contents

require 'open-uri'
require 'nokogiri'
require 'cgi'

module Cinch
  module Plugins
    class Urban
      include Cinch::Plugin

      match /u (.*)$/

      set :plugin_name, 'urban'
      set :help, <<EOT
Urban connects to urban dictionary and returns the first result for a given query, replying with the result directly to the sender
EOT

      def query(query)
        url = "http://www.urbandictionary.com/define.php?term=#{CGI.escape(query)}"
        begin
          CGI.unescape_html Nokogiri::HTML(open(url)).at("div.definition").text.gsub(/\s+/, ' ')
        rescue
          "no result found"
        end
      end

      def new(bot)
        @bot = bot
      end

      def execute(m,words)
        m.reply(query(words.strip))
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cogbot-0.0.3 plugins/urban.rb
cogbot-0.0.2 plugins/urban.rb