class Bot::PluginOutputQueue
Constants
- BYPASS_TRIGGER
Public Class Methods
Source
# File plugins/bot.rb, line 628 def bypass_trigger?(text) text.to_s.strip.match?(BYPASS_TRIGGER) end
Source
# File plugins/bot.rb, line 632 def channel_key(message) channel = extract_channel(message) if channel channel.name.to_s.downcase elsif message.respond_to?(:user) && message.user "private:#{message.user.nick.to_s.downcase}" else "unknown" end end
Source
# File plugins/bot.rb, line 672 def for_bot(bot) key = bot.object_id @registry_mutex.synchronize do @registry[key] ||= new end end
Source
# File plugins/bot.rb, line 665 def hold_seconds_for_pieces(piece_count) count = piece_count.to_i return 0.0 if count <= 1 FloodSafe::CHUNK_DELAY_SEC * (count - 1) end
Source
# File plugins/bot.rb, line 684 def initialize(scheduler: default_scheduler) @mutex = Mutex.new @channels = {} @scheduler = scheduler end
Source
# File plugins/bot.rb, line 679 def reset_registry! @registry_mutex.synchronize { @registry.clear } end
Public Instance Methods
Source
# File plugins/bot.rb, line 690 def active_plugin(channel) @mutex.synchronize do @channels[channel.to_s.downcase]&.[](:active)&.fetch(:plugin, nil) end end
Source
# File plugins/bot.rb, line 696 def defer(plugin:, channel:, hold_sec:, &block) run_now = false channel = channel.to_s.downcase @mutex.synchronize do state = (@channels[channel] ||= { active: nil, waiters: [] }) if state[:active].nil? state[:active] = { plugin: plugin, hold_sec: hold_sec.to_f } run_now = true else state[:waiters] << { plugin: plugin, hold_sec: hold_sec.to_f, block: block } end end if run_now begin block.call ensure schedule_release(channel, hold_sec.to_f) end end end