Module: OnyxCord::Bot::Runtime
- Included in:
- OnyxCord::Bot
- Defined in:
- lib/onyxcord/core/bot/runtime.rb
Instance Method Summary collapse
-
#connected? ⇒ true, false
Whether or not the bot is currently connected to Discord.
-
#debug=(new_debug) ⇒ Object
Sets debug mode.
- #join ⇒ Object (also: #sync)
- #latency ⇒ Object
-
#mode=(new_mode) ⇒ Object
Sets the logging mode.
-
#run(background = false) ⇒ Object
Runs the bot, which logs into Discord and connects the WebSocket.
- #run_forever ⇒ Object
- #runtime_stats ⇒ Object
- #stop(_no_sync = nil) ⇒ Object
-
#suppress_ready_debug ⇒ Object
Prevents the READY packet from being printed regardless of debug mode.
Instance Method Details
#connected? ⇒ true, false
Returns whether or not the bot is currently connected to Discord.
44 45 46 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 44 def connected? @gateway.open? end |
#debug=(new_debug) ⇒ Object
Sets debug mode. If debug mode is on, many things will be outputted to STDOUT.
53 54 55 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 53 def debug=(new_debug) LOGGER.debug = new_debug end |
#join ⇒ Object Also known as: sync
31 32 33 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 31 def join @run_task&.wait end |
#latency ⇒ Object
48 49 50 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 48 def latency @gateway.latency end |
#mode=(new_mode) ⇒ Object
Sets the logging mode
59 60 61 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 59 def mode=(new_mode) LOGGER.mode = new_mode end |
#run(background = false) ⇒ Object
Running the bot in the background means that you can call some methods that require a gateway connection before that connection is established. In most cases an exception will be raised if you try to do this. If you need a way to safely run code after the bot is fully connected, use a EventContainer#ready event handler instead.
Runs the bot, which logs into Discord and connects the WebSocket. This
prevents all further execution unless it is executed with
background = true.
18 19 20 21 22 23 24 25 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 18 def run(background = false) if background @run_task = Internal::AsyncRuntime.async { run_forever } return @run_task end Internal::AsyncRuntime.run { run_forever } end |
#run_forever ⇒ Object
27 28 29 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 27 def run_forever @gateway.run end |
#runtime_stats ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 63 def runtime_stats { mode: @mode, cache: cache_stats, event_executor: @event_executor.class.name, event_threads: @event_threads&.count(&:alive?) || 0, event_queue_size: @event_executor.respond_to?(:queue_size) ? @event_executor.queue_size : 0 } end |
#stop(_no_sync = nil) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 36 def stop(_no_sync = nil) @gateway.stop @event_executor.shutdown @run_task&.stop if @run_task.respond_to?(:stop) nil end |
#suppress_ready_debug ⇒ Object
Prevents the READY packet from being printed regardless of debug mode.
74 75 76 |
# File 'lib/onyxcord/core/bot/runtime.rb', line 74 def suppress_ready_debug @prevent_ready = true end |