Class: Relayer::IRCClient
- Inherits:
-
Object
- Object
- Relayer::IRCClient
- Defined in:
- lib/relayer/client.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns the value of attribute events.
-
#nick ⇒ Object
Returns the value of attribute nick.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
Instance Method Summary collapse
- #channel(channel) ⇒ Object
- #default_handlers! ⇒ Object
- #default_options! ⇒ Object
-
#initialize(options = {}) ⇒ IRCClient
constructor
A new instance of IRCClient.
- #process_raw(line) ⇒ Object
- #readable ⇒ Object
- #register ⇒ Object
- #send_raw(line) ⇒ Object
- #start ⇒ Object
- #user(hostmask) ⇒ Object
- #version_string ⇒ Object
- #writable ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ IRCClient
Returns a new instance of IRCClient.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/relayer/client.rb', line 11 def initialize( = {}) @ssl = [:ssl] @hostname = [:hostname] @port = [:port] @ping_reply = [:ping_reply] @version_reply = [:version_reply] @version_string = [:version_string] @nick = [:nick] @nick_pass = [:pass] @ident = [:ident] @real_name = [:real_name] @first_channels = [:channels] || [] @users = {} @channels = {} @protocol = IRCProtocol.new(self) @events = IRCEvents.new(@protocol, self) @mutex = Mutex.new default_handlers! end |
Instance Attribute Details
#events ⇒ Object
Returns the value of attribute events.
7 8 9 |
# File 'lib/relayer/client.rb', line 7 def events @events end |
#nick ⇒ Object
Returns the value of attribute nick.
8 9 10 |
# File 'lib/relayer/client.rb', line 8 def nick @nick end |
#protocol ⇒ Object
Returns the value of attribute protocol.
9 10 11 |
# File 'lib/relayer/client.rb', line 9 def protocol @protocol end |
Instance Method Details
#channel(channel) ⇒ Object
119 120 121 122 |
# File 'lib/relayer/client.rb', line 119 def channel(channel) channel = channel.downcase @channels[channel] ||= IRC::Channel.new(channel) if IRC::Channel.is_channel?(channel) end |
#default_handlers! ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/relayer/client.rb', line 50 def default_handlers! @events.ping do |irc, event| @protocol.pong event[:token] end @events.connected do unless @nick_pass.nil? @protocol.('NickServ', "identify #{@nick_pass}") end @first_channels.each do |channel| @protocol.join(channel) end end @events.ctcp do |irc, event| @protocol.ctcp_reply :version, event[:actor], version_string if event[:query] == :version end end |
#default_options! ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/relayer/client.rb', line 70 def if @ssl.nil? @ssl = false end unless @port @port = 6697 if @ssl @port ||= 6667 end @nick ||= "Relayer" @ident ||= "relayer" @real_name ||= "Relayer" @hostname ||= 'irc.freenode.net' end |
#process_raw(line) ⇒ Object
102 103 104 |
# File 'lib/relayer/client.rb', line 102 def process_raw(line) @protocol.process_line(line) end |
#readable ⇒ Object
92 93 94 |
# File 'lib/relayer/client.rb', line 92 def readable @socket.read end |
#register ⇒ Object
45 46 47 48 |
# File 'lib/relayer/client.rb', line 45 def register @protocol.user(@ident, @real_name) @protocol.nick(@nick) end |
#send_raw(line) ⇒ Object
106 107 108 109 110 |
# File 'lib/relayer/client.rb', line 106 def send_raw(line) @mutex.synchronize do @socket.send line end end |
#start ⇒ Object
87 88 89 90 |
# File 'lib/relayer/client.rb', line 87 def start @socket = IRCSocket.new(self, @hostname, @port, @ssl) register end |
#user(hostmask) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/relayer/client.rb', line 112 def user(hostmask) parts = IRC::User.parse_hostmask(hostmask) nickname = parts[:nick].downcase @users[nickname] ||= IRC::User.new(hostmask) if IRC::User.is_user?(hostmask) end |
#version_string ⇒ Object
41 42 43 |
# File 'lib/relayer/client.rb', line 41 def version_string @version_string || "Relayer IRC Library v#{Relayer::VERSION}" end |
#writable ⇒ Object
96 97 98 99 100 |
# File 'lib/relayer/client.rb', line 96 def writable @mutex.synchronize do @socket.write end end |