Class: Codebot::Core
- Inherits:
-
Object
- Object
- Codebot::Core
- Defined in:
- lib/codebot/core.rb
Overview
This class represents a Codebot bot.
Instance Attribute Summary collapse
-
#config ⇒ Config
readonly
The configuration used by this bot.
-
#ipc_server ⇒ IRCClient
readonly
The IPC server.
-
#irc_client ⇒ IRCClient
readonly
The IRC client.
-
#web_server ⇒ IRCClient
readonly
The web server.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Core
constructor
Creates a new bot from the supplied hash.
-
#join ⇒ Object
Waits for this bot to stop.
-
#migrate! ⇒ Object
Requests that the running threads migrate to an updated configuration.
-
#start ⇒ Object
Starts this bot.
-
#stop ⇒ Object
Stops this bot.
-
#trap_signals ⇒ Object
Sets traps for SIGINT and SIGTERM so Codebot can shut down gracefully.
Constructor Details
#initialize(params = {}) ⇒ Core
Creates a new bot from the supplied hash.
28 29 30 31 32 33 |
# File 'lib/codebot/core.rb', line 28 def initialize(params = {}) @config = Config.new(self, params[:config_file]) @irc_client = IRCClient.new(self) @web_server = WebServer.new(self) @ipc_server = IPCServer.new(self, params[:ipc_pipe]) end |
Instance Attribute Details
#config ⇒ Config (readonly)
Returns the configuration used by this bot.
12 13 14 |
# File 'lib/codebot/core.rb', line 12 def config @config end |
#ipc_server ⇒ IRCClient (readonly)
Returns the IPC server.
21 22 23 |
# File 'lib/codebot/core.rb', line 21 def ipc_server @ipc_server end |
#irc_client ⇒ IRCClient (readonly)
Returns the IRC client.
15 16 17 |
# File 'lib/codebot/core.rb', line 15 def irc_client @irc_client end |
#web_server ⇒ IRCClient (readonly)
Returns the web server.
18 19 20 |
# File 'lib/codebot/core.rb', line 18 def web_server @web_server end |
Instance Method Details
#join ⇒ Object
Waits for this bot to stop. If any of the managed threads finish early, the bot is shut down immediately.
51 52 53 54 55 56 57 |
# File 'lib/codebot/core.rb', line 51 def join ipc = Thread.new { @ipc_server.join && stop } web = Thread.new { @web_server.join && stop } ipc.join web.join @irc_client.join end |
#migrate! ⇒ Object
Requests that the running threads migrate to an updated configuration.
60 61 62 |
# File 'lib/codebot/core.rb', line 60 def migrate! @irc_client.migrate! unless @irc_client.nil? end |
#start ⇒ Object
Starts this bot.
36 37 38 39 40 |
# File 'lib/codebot/core.rb', line 36 def start @irc_client.start @web_server.start @ipc_server.start end |
#stop ⇒ Object
Stops this bot.
43 44 45 46 47 |
# File 'lib/codebot/core.rb', line 43 def stop @ipc_server.stop @web_server.stop @irc_client.stop end |
#trap_signals ⇒ Object
Sets traps for SIGINT and SIGTERM so Codebot can shut down gracefully.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/codebot/core.rb', line 65 def trap_signals shutdown = proc do |signal| STDERR.puts "\nReceived #{signal}, shutting down..." stop join exit 1 end trap('INT') { shutdown.call 'SIGINT' } trap('TERM') { shutdown.call 'SIGTERM' } end |