Class: EventMachine::IRC::Client
- Inherits:
-
Object
- Object
- EventMachine::IRC::Client
- Includes:
- DslAccessor, Commands, Responses
- Defined in:
- lib/em-irc/client.rb
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Set of channels that this client is connected to.
Instance Method Summary collapse
- #channel?(string) ⇒ Boolean protected
-
#connect ⇒ EventMachine::Connection
Creates a Eventmachine TCP connection with :host and :port.
- #connected? ⇒ Boolean
-
#initialize(options = {}) {|client| ... } ⇒ Client
constructor
Build a new unconnected IRC client.
-
#on(name, &blk) ⇒ Object
Register a callback with ‘:name` as one of the following, and a block with the same number of params.
-
#run! ⇒ Object
Start running the client.
Methods included from Commands
#admin, #away, #channel_mode, #die, #error, #info, #invite, #ison, #join, #kick, #kill, #links, #list, #lusers, #mode, #motd, #names, #nick, #notice, #oper, #part, #part_all, #pass, #ping, #pong, #privmsg, #quit, #rehash, #restart, #server_connect, #service, #servlist, #squery, #squit, #stats, #summon, #time, #topic, #trace, #user, #userhost, #users, #version, #wallops, #who, #whois, #whowas
Constructor Details
#initialize(options = {}) {|client| ... } ⇒ Client
Build a new unconnected IRC client
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/em-irc/client.rb', line 49 def initialize( = {}, &blk) .symbolize_keys! = { :host => '127.0.0.1', :port => '6667', :ssl => false, :realname => 'Anonymous Annie' }.merge!() @host = [:host] @port = [:port] @ssl = [:ssl] @realname = [:realname] @channels = Set.new @callbacks = Hash.new @connected = false if block_given? if blk.arity == 1 yield self else instance_eval(&blk) end end end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Set of channels that this client is connected to
33 34 35 |
# File 'lib/em-irc/client.rb', line 33 def channels @channels end |
Instance Method Details
#channel?(string) ⇒ Boolean (protected)
174 175 176 |
# File 'lib/em-irc/client.rb', line 174 def channel?(string) !!(string =~ /^(#|&)/) end |
#connect ⇒ EventMachine::Connection
Creates a Eventmachine TCP connection with :host and :port. It should be called after callbacks are registered.
79 80 81 |
# File 'lib/em-irc/client.rb', line 79 def connect self.conn ||= EventMachine::connect(@host, @port, Dispatcher, :parent => self, :ssl => @ssl) end |
#connected? ⇒ Boolean
84 85 86 |
# File 'lib/em-irc/client.rb', line 84 def connected? @connected end |
#on(name, &blk) ⇒ Object
Register a callback with ‘:name` as one of the following, and a block with the same number of params.
123 124 125 126 127 |
# File 'lib/em-irc/client.rb', line 123 def on(name, &blk) # TODO: I thought Hash.new([]) would work, but it gets empted out # TODO: normalize aliases :privmsg, :message, etc (@callbacks[name.to_sym] ||= []) << blk end |
#run! ⇒ Object
Start running the client
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/em-irc/client.rb', line 89 def run! EM.epoll EventMachine.run do trap("TERM") { EM::stop } trap("INT") { EM::stop } connect log Logger::INFO, "Starting IRC client..." end log Logger::INFO, "Stopping IRC client" @logger.close if @logger end |