Sha256: e8478652072144515c51e4cf452537e7c8de7123f1e10f36a856124cca05a6f2

Contents?: true

Size: 872 Bytes

Versions: 3

Compression:

Stored size: 872 Bytes

Contents

require 'json'
require 'open-uri'
require 'timeout'

class HackerSays < Plugin
    def initialize name
        super
        self.handle(/^hackersays$/i) do |data|
            begin
                Timeout::timeout(2) {
                    say_quote(data[:room])
                }
            rescue Timeout::Error
                data[:room].say("Request to hackersays.com timed out.")
            end
        end
    end

    def say_quote room
        quote = get_quote()
        if quote.nil?
            room.say "Could not fetch a quote. :-("
        else
            room.say "\u{201C}#{quote['c']}\u{201D} \u{2014} \002#{quote['a']}\002 \00315[Quote \##{quote['id']}]\003"
        end
    end

private

    def get_quote
        return JSON::load(open("http://hackersays.com/quote").read)
    end
end

plugin = HackerSays.new "hackersays"
$bot.plugins.add(plugin)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fantasy-irc-0.3.0 lib/plugins/hackersays.rb
fantasy-irc-0.2.3 lib/plugins/hackersays.rb
fantasy-irc-0.2.2 lib/plugins/hackersays.rb