Class: Qswarm::Speakers::Irc

Inherits:
Qswarm::Speaker show all
Defined in:
lib/qswarm/speakers/irc.rb

Constant Summary collapse

@@irc_servers =
{}

Instance Attribute Summary

Attributes inherited from Qswarm::Speaker

#agent, #heard, #metadata, #name

Instance Method Summary collapse

Methods inherited from Qswarm::Speaker

#arg, #bind, #get_broker, #log, #parse

Methods included from DSL

#dsl_accessor

Methods included from Loggable

#logger, logger

Constructor Details

#initialize(listener, name, args, &block) ⇒ Irc

Returns a new instance of Irc.



9
10
11
12
13
14
# File 'lib/qswarm/speakers/irc.rb', line 9

def initialize(listener, name, args, &block)        
  @admin_host = args[:admin_host]
  @channels = []
  @connected = false
  super
end

Instance Method Details

#inject(format = :text, msg) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/qswarm/speakers/irc.rb', line 16

def inject(format = :text, msg)
  if @connected
    routing_key = @bind || @name
    logger.debug "[#{@agent.name}] Sending '#{msg}' to channel #{routing_key}"
    publish format, routing_key, msg
  else
    EventMachine::Timer.new(5,self.inject(format, msg))
  end
end

#on_connect(m) ⇒ Object



38
39
40
# File 'lib/qswarm/speakers/irc.rb', line 38

def on_connect(m)
  @connected = true
end

#on_disconnect(m) ⇒ Object



42
43
44
# File 'lib/qswarm/speakers/irc.rb', line 42

def on_disconnect(m)
  @connected = false
end

#on_join(m) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/qswarm/speakers/irc.rb', line 30

def on_join(m)
  unless m.user.nick == m.bot.nick
    if @admin_host && Regexp.new(@admin_host).match(m.user.host)
      m.channel.op(m.user)
    end
  end
end

#runObject



26
27
28
# File 'lib/qswarm/speakers/irc.rb', line 26

def run
  @name.match(/([^#]*)(#.+)/) { irc_connect $1.empty? ? 'localhost' : $1, $2 }
end