Class: Miu::Nodes::IRC::Client
- Inherits:
-
Connection
- Object
- Connection
- Miu::Nodes::IRC::Client
- Defined in:
- lib/miu/nodes/irc/client.rb
Constant Summary
Constants inherited from Connection
Miu::Nodes::IRC::Connection::BUFFER_SIZE
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
-
#subscriber ⇒ Object
readonly
Returns the value of attribute subscriber.
Attributes inherited from Connection
#encoding, #host, #nick, #pass, #port, #real, #socket, #user
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(node, options) ⇒ Client
constructor
A new instance of Client.
- #on_376(msg) ⇒ Object
- #on_join(msg) ⇒ Object
- #on_notice(msg) ⇒ Object
- #on_part(msg) ⇒ Object
- #on_ping(msg) ⇒ Object
- #on_privmsg(msg) ⇒ Object
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, ) super @node = node @channels = Array([:channels]) @publisher = Publisher.new @node.['pub-host'], @node.['pub-port'], @node.['pub-tag'] @subscriber = Subscriber.new @node.['sub-host'], @node.['sub-port'], @node.['sub-tag'] async.run end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
9 10 11 |
# File 'lib/miu/nodes/irc/client.rb', line 9 def channels @channels end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
10 11 12 |
# File 'lib/miu/nodes/irc/client.rb', line 10 def node @node end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
10 11 12 |
# File 'lib/miu/nodes/irc/client.rb', line 10 def publisher @publisher end |
#subscriber ⇒ Object (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
#close ⇒ Object
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| '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) '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 |