Class: Miu::Nodes::IRC::Client

Inherits:
Connection show all
Defined in:
lib/miu/nodes/irc/client.rb

Constant Summary

Constants inherited from Connection

Miu::Nodes::IRC::Connection::BUFFER_SIZE

Instance Attribute Summary collapse

Attributes inherited from Connection

#encoding, #host, #nick, #pass, #port, #real, #socket, #user

Instance Method Summary collapse

Methods inherited from Connection

#attach, #encode, #on_message, #readlines, #run, #send_message

Constructor Details

#initialize(node, options) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
20
# File 'lib/miu/nodes/irc/client.rb', line 12

def initialize(node, options)
  super options
  @node = node
  @channels = Array(options[:channels])
  @publisher = Publisher.new @node.options['pub-host'], @node.options['pub-port'], @node.options['pub-tag']
  @subscriber = Subscriber.new @node.options['sub-host'], @node.options['sub-port'], @node.options['sub-tag']

  async.run
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



9
10
11
# File 'lib/miu/nodes/irc/client.rb', line 9

def channels
  @channels
end

#nodeObject (readonly)

Returns the value of attribute node.



10
11
12
# File 'lib/miu/nodes/irc/client.rb', line 10

def node
  @node
end

#publisherObject (readonly)

Returns the value of attribute publisher.



10
11
12
# File 'lib/miu/nodes/irc/client.rb', line 10

def publisher
  @publisher
end

#subscriberObject (readonly)

Returns the value of attribute subscriber.



10
11
12
# File 'lib/miu/nodes/irc/client.rb', line 10

def subscriber
  @subscriber
end

Instance Method Details

#closeObject



22
23
24
25
26
# File 'lib/miu/nodes/irc/client.rb', line 22

def close
  @publisher.close
  @subscriber.close
  super
end

#on_376(msg) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/miu/nodes/irc/client.rb', line 28

def on_376(msg)
  @channels.each do |channel|
    send_message 'JOIN', *channel.split(/ +/)
  end

  @subscriber.async.run self
end

#on_join(msg) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/miu/nodes/irc/client.rb', line 48

def on_join(msg)
  channels = msg.params[0].split(',') rescue []
  channels.each do |channel|
    publish Miu::Messages::Enter do |c|
      c.room.name = channel
      c.user.name = to_name(msg)
    end
  end
end

#on_notice(msg) ⇒ Object



44
45
46
# File 'lib/miu/nodes/irc/client.rb', line 44

def on_notice(msg)
  publish_text msg, true
end

#on_part(msg) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/miu/nodes/irc/client.rb', line 58

def on_part(msg)
  channels = msg.params[0].split(',') rescue []
  channels.each do |channel|
    publish Miu::Messages::Leave do |c|
      c.room.name = channel
      c.user.name = to_name(msg)
    end
  end
end

#on_ping(msg) ⇒ Object



36
37
38
# File 'lib/miu/nodes/irc/client.rb', line 36

def on_ping(msg)
  send_message 'PONG', msg.params[0]
end

#on_privmsg(msg) ⇒ Object



40
41
42
# File 'lib/miu/nodes/irc/client.rb', line 40

def on_privmsg(msg)
  publish_text msg, false
end