Class: HackerSays

Inherits:
Plugin show all
Defined in:
lib/plugins/hackersays.rb

Instance Attribute Summary

Attributes inherited from Plugin

#name

Instance Method Summary collapse

Methods inherited from Plugin

#handle, #handle!, #handles?

Constructor Details

#initialize(name) ⇒ HackerSays

Returns a new instance of HackerSays.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/plugins/hackersays.rb', line 6

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

Instance Method Details

#say_quote(room) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/plugins/hackersays.rb', line 19

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