class Relayer::IRCClient
Attributes
events[RW]
nick[RW]
protocol[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/relayer/client.rb, line 11 def initialize(options = {}) @ssl = options[:ssl] @hostname = options[:hostname] @port = options[:port] @ping_reply = options[:ping_reply] @version_reply = options[:version_reply] @version_string = options[:version_string] @nick = options[:nick] @nick_pass = options[:pass] @ident = options[:ident] @real_name = options[:real_name] @first_channels = options[:channels] || [] default_options! @users = {} @channels = {} @protocol = IRCProtocol.new(self) @events = IRCEvents.new(@protocol, self) @mutex = Mutex.new default_handlers! end
Public Instance Methods
channel(channel)
click to toggle source
# 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!()
click to toggle source
# 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.message('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!()
click to toggle source
# File lib/relayer/client.rb, line 70 def default_options! 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)
click to toggle source
# File lib/relayer/client.rb, line 102 def process_raw(line) @protocol.process_line(line) end
readable()
click to toggle source
# File lib/relayer/client.rb, line 92 def readable @socket.read end
register()
click to toggle source
# File lib/relayer/client.rb, line 45 def register @protocol.user(@ident, @real_name) @protocol.nick(@nick) end
send_raw(line)
click to toggle source
# File lib/relayer/client.rb, line 106 def send_raw(line) @mutex.synchronize do @socket.send line end end
start()
click to toggle source
# File lib/relayer/client.rb, line 87 def start @socket = IRCSocket.new(self, @hostname, @port, @ssl) register end
user(hostmask)
click to toggle source
# 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()
click to toggle source
# File lib/relayer/client.rb, line 41 def version_string @version_string || "Relayer IRC Library v#{Relayer::VERSION}" end
writable()
click to toggle source
# File lib/relayer/client.rb, line 96 def writable @mutex.synchronize do @socket.write end end