Method: Autumn::CTCP#initialize

Defined in:
lib/autumn/ctcp.rb

#initialize(options = {}) ⇒ CTCP

Creates a new CTCP parser. Options are:

reply_queue_size

The maximum number of pending replies to store in the queue, after which new CTCP requests are ignored.

reply_rate

The minimum time, in seconds, between consecutive CTCP replies.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/autumn/ctcp.rb', line 82

def initialize(options={})
  @options = options
  @options[:reply_queue_size] ||= 10
  @options[:reply_rate] ||= 0.25
  @reply_thread = Hash.new
  @reply_queue = Hash.new do |hsh, key|
    hsh[key] = ForgetfulQueue.new(@options[:reply_queue_size])
    @reply_thread[key] = Thread.new(key) do |stem|
      loop do #TODO wake thread when stem is quitting so this thread can terminate?
        reply = @reply_queue[stem].pop
        stem.notice reply[:recipient], reply[:message]
        sleep @options[:reply_rate]
      end
    end
    hsh[key]
  end
end