Sha256: f8a25612065712c3b578a8df25703e209502552a4627773d4e9eeddc8a6cf09b

Contents?: true

Size: 603 Bytes

Versions: 14

Compression:

Stored size: 603 Bytes

Contents

require 'open-uri'

module Cinch
  module Plugins
    class Shorturl
      include Cinch::Plugin

      match /short (https?:\/\/[^ ]*)/

      set :plugin_name, 'shorturl'
      set :help, <<EOT
Shorturl catches urls said on channel and shorten then
EOT

      def shorten(url)
        url = open("http://tinyurl.com/api-create.php?url=#{URI.escape(url)}").read
        url == "Error" ? nil : url
      rescue OpenURI::HTTPError
        nil
      end

      def new(bot)
        @bot = bot
      end

      def execute(m,url)
        m.reply("Shortening: " + shorten(url))
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cogbot-0.1.14 plugins/shorturl.rb
cogbot-0.1.13 plugins/shorturl.rb
cogbot-0.1.12 plugins/shorturl.rb
cogbot-0.1.11 plugins/shorturl.rb
cogbot-0.1.10 plugins/shorturl.rb
cogbot-0.1.9 plugins/shorturl.rb
cogbot-0.1.7 plugins/shorturl.rb
cogbot-0.1.6 plugins/shorturl.rb
cogbot-0.1.5 plugins/shorturl.rb
cogbot-0.1.4 plugins/shorturl.rb
cogbot-0.1.3 plugins/shorturl.rb
cogbot-0.1.2 plugins/shorturl.rb
cogbot-0.1.1 plugins/shorturl.rb
cogbot-0.1.0 plugins/shorturl.rb