class RFlow::Components::IRC::Client
Component that subscribes to an IRC
channel and issues +RFlow::Message+s of type {RFlow::Message::Data::IRC::Message} when it receives messages.
Assumes a single connection, meaning that it can choose to be 'promiscuous' and not limit its sending to only those messages derived from one of its own
Accepts config parameters:
-
server
- server address -
port
- server port -
server_password
- server password, not sent if nil -
nickname
-IRC
nickname -
username
- server username -
oper_user
- op username, defaults to nickname if nil -
oper_password
- op password -
nickserv_password
- nickserv password, not sent if nil -
reconnect_interval
- reconnect interval in seconds -
promiscuous
- true to listen to all messages; false to listen only to those with provenance linking to us
Constants
- DEFAULT_CONFIG
Default configuration.
Attributes
@!visibility private
@!visibility private
@!visibility private
@!visibility private
Public Instance Methods
RFlow-called method at startup. @return [void]
# File lib/rflow/components/irc/client.rb, line 99 def configure!(config) @config = DEFAULT_CONFIG.merge config @config['port'] = @config['port'].to_i @config['reconnect_interval'] = @config['reconnect_interval'].to_i # TODO: More config sanitization @server = @config['server'] @port = @config['port'].to_i end
RFlow-called method at message arrival. @return [void]
# File lib/rflow/components/irc/client.rb, line 121 def process_message(input_port, input_port_key, connection, message) RFlow.logger.debug { "#{name}: Received a message" } return unless message.data_type_name == 'RFlow::Message::Data::IRC::Message' if config['promiscuous'] RFlow.logger.debug { "#{name}: Received an IRC::Message message, sending to client connection" } client_connection.send_irc_message message else RFlow.logger.debug { "#{name}: Received an IRC::Message message, determining if it's mine" } my_events = message.provenance.find_all {|event| event.component_instance_uuid == uuid} RFlow.logger.debug { "#{name}: Found #{my_events.size} processing events from me" } # Attempt to send the data to each context match. # TODO: check for correctness my_events.each do |event| RFlow.logger.debug { "#{name}: Inspecting context #{client_connection.signature.to_s} == #{event.context.to_s}" } if client_connection.signature.to_s == event.context.to_s RFlow.logger.debug { "#{name}: Found connection for #{event.context}, sending message to associated client connection" } client_connection.send_irc_message message end end end end
RFlow-called method at startup. @return [void]
# File lib/rflow/components/irc/client.rb, line 112 def run! @client_connection = EM.connect(@server, @port, Connection) do |conn| conn.client = self RFlow.logger.debug { "#{name}: Connection from #{@client_ip}:#{@client_port} to #{@server_ip}:#{@server_port}" } end end