Class: Ponder::AsyncIRC::Channel

Inherits:
Object
  • Object
show all
Includes:
EventMachine::Deferrable
Defined in:
lib/ponder/async_irc.rb

Constant Summary collapse

TIMEOUT =

number of seconds the deferrable will wait for a response before failing

15

Instance Method Summary collapse

Constructor Details

#initialize(channel, timeout_after, thaum) ⇒ Channel

Returns a new instance of Channel.



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ponder/async_irc.rb', line 103

def initialize(channel, timeout_after, thaum)
  @channel = channel
  @thaum = thaum
  @channel_information = {}

  self.timeout(timeout_after)
  self.errback { @ponder.deferrables.delete self }

  @thaum.deferrables.add self
  @thaum.raw "MODE #{@channel}"
end

Instance Method Details

#succeed(*args) ⇒ Object



131
132
133
134
# File 'lib/ponder/async_irc.rb', line 131

def succeed(*args)
  @thaum.deferrables.delete self
  set_deferred_status :succeeded, *args
end

#try(message) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ponder/async_irc.rb', line 115

def try(message)
  if message =~ /:\S+ (324|329|403|442) \S+ #{Regexp.escape(@channel)}/i
    case $1
    when '324'
      @channel_information[:modes] = message.scan(/^:\S+ 324 \S+ \S+ \+(\w*)/)[0][0].split('')
      limit = message.scan(/^:\S+ 324 \S+ \S+ \+\w* (\w*)/)[0]
      @channel_information[:channel_limit] = limit[0].to_i if limit
    when '329'
      @channel_information[:created_at] = Time.at(message.scan(/^:\S+ 329 \S+ \S+ (\d+)/)[0][0].to_i)
      succeed @channel_information
    when '403', '442'
      succeed false
    end
  end
end