Class: IrcMachine::Session
- Inherits:
-
Object
- Object
- IrcMachine::Session
- Includes:
- Commands
- Defined in:
- lib/irc_machine/session.rb
Instance Attribute Summary collapse
-
#irc_connection ⇒ Object
Returns the value of attribute irc_connection.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #disconnected ⇒ Object
-
#initialize(options) ⇒ Session
constructor
A new instance of Session.
- #log(message) ⇒ Object
- #receive_line(line) ⇒ Object
- #start ⇒ Object
Methods included from Commands
#join, #msg, #nick, #part, #password, #quit, #raw, #user
Constructor Details
#initialize(options) ⇒ Session
Returns a new instance of Session.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/irc_machine/session.rb', line 9 def initialize() IrcMachine::Plugin::Reloader.load_all @options = OpenStruct.new() @state = State.new @router = HttpRouter.new(self) @plugins = [ Core.new(self), Plugin::Hello.new(self), Plugin::Reloader.new(self), Plugin::GithubNotifier.new(self) ] end |
Instance Attribute Details
#irc_connection ⇒ Object
Returns the value of attribute irc_connection.
7 8 9 |
# File 'lib/irc_machine/session.rb', line 7 def irc_connection @irc_connection end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/irc_machine/session.rb', line 5 def @options end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/irc_machine/session.rb', line 6 def state @state end |
Instance Method Details
#disconnected ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/irc_machine/session.rb', line 52 def disconnected if @shutdown log "Stopping EventMachine" EM.stop else log "Waiting to reconnect" EM.add_timer(2) do log "Reconnecting to #{.server}:#{.port}" irc_connection.reconnect .server, .port @state.reset dispatch :connected end end end |
#log(message) ⇒ Object
71 72 73 |
# File 'lib/irc_machine/session.rb', line 71 def log puts "! " << if .verbose end |
#receive_line(line) ⇒ Object
67 68 69 |
# File 'lib/irc_machine/session.rb', line 67 def receive_line(line) dispatch :receive_line, line end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/irc_machine/session.rb', line 23 def start EM.run do signal_traps log "Connecting to #{.server}:#{.port}" EM.connect( .server, .port, IrcConnection, {:ssl => @options.ssl, :session => self} ) do |c| self.irc_connection = c end log "Starting HTTP API on port #{.http_port}" EM.start_server "0.0.0.0", .http_port, HttpServer do |c| c.router = @router end log "Starting UDP API on port #{.udp_port}" EM.open_datagram_socket "0.0.0.0", .udp_port, UdpServer do |c| c.session = self end dispatch :connected end end |