class Autovoice
Constants
- AGENT_MODEL
- AWARD_PING_FALLBACK_SEC
- POLL_TICK_SEC
Public Class Methods
Source
# File plugins/autovoice.rb, line 64 def self.activity_message?(network:, channel:, nick:, text:, channel_obj:, bot_nick:, bot_nicks: ChannelTrust.persona_bot_nicks) AutovoiceActivity.qualifies?( network: network, channel: channel, nick: nick, text: text, channel_obj: channel_obj, bot_nick: bot_nick, bot_nicks: bot_nicks ) end
Source
# File plugins/autovoice.rb, line 49 def self.admin_allowed?(network:, channel:, nick:, is_op:) RabbotDb.user_allowed_at_level?( network: network, channel: channel, nick: nick, is_op: is_op, minimum: RabbotDb::LEVEL_ADMIN ) end
Source
# File plugins/autovoice.rb, line 120 def self.announce_award(award, ping_ms: nil) build_announcement( nick: award[:nick], count: award[:count], flair: award[:flair], lag_ms: award[:lag_ms], ping_ms: ping_ms, server: award[:server] ) end
Source
# File plugins/autovoice.rb, line 104 def self.begin_award_ping!(user:, award:, sent_at: Process.clock_gettime(Process::CLOCK_MONOTONIC)) token = IrcLag.lag_probe_token(sent_at) IrcUserPing.register!( nick: award[:nick], sent_at: sent_at, context: token, award: award ) user.ctcp("PING #{IrcUserPing.ping_message(token: token)}") token end
Source
# File plugins/autovoice.rb, line 80 def self.build_announcement(nick:, count:, flair: nil, lag_ms: 0, ping_ms: nil, server: nil) AutovoiceReport.format_announcement( nick: nick, count: count, flair: flair, lag_ms: lag_ms, ping_ms: ping_ms, server: server ) end
Source
# File plugins/autovoice.rb, line 116 def self.complete_award_ping!(nick:, args:, received_at:) IrcUserPing.record_award_reply!(nick: nick, args: args, received_at: received_at) end
Source
# File plugins/autovoice.rb, line 59 def self.lag_ms_from_bot(bot = nil) stored = bot&.data&.fetch(:irc_lag_ms, nil) stored.nil? ? 0 : stored.to_i end
Source
# File plugins/autovoice.rb, line 131 def initialize(bot) super PluginTimers.start(self) end
Calls superclass method
Source
# File plugins/autovoice.rb, line 41 def self.parse_command(args) AutovoiceCommand.parse(args) end
Source
# File plugins/autovoice.rb, line 207 def self.poll_channels(bot, lag_ms: 0, runner: nil, force: false, store: RabbotDb) AutovoicePoll.poll_channels( bot, store: store, force: force, runner: runner, lag_ms: lag_ms ) end
Source
# File plugins/autovoice.rb, line 91 def self.prepare_award(nick:, flair: nil, lag_ms: 0, ping_ms: nil, server: nil, store: RabbotDb) count = AutovoiceStore.increment_total!(store: store) announcement = build_announcement( nick: nick, count: count, flair: flair, lag_ms: lag_ms, ping_ms: ping_ms, server: server ) { count: count, announcement: announcement } end
Source
# File plugins/autovoice.rb, line 45 def self.responds_to_command?(bot) BotIdentity.room_reader_bot?(bot) end
Source
# File plugins/autovoice.rb, line 76 def self.touch_activity!(network:, channel:, at: Time.now, store: RabbotDb) AutovoiceStore.touch_activity!(network: network, channel: channel, at: at, store: store) end
Source
# File plugins/autovoice.rb, line 37 def self.usage_message AutovoiceCommand.usage_message end
Public Instance Methods
Source
# File plugins/autovoice.rb, line 217 def ctcp_ping(m, *args) result = self.class.complete_award_ping!( nick: m.user.nick, args: args, received_at: Process.clock_gettime(Process::CLOCK_MONOTONIC) ) return unless result&.dig(:award) deliver_pending_announcement(result[:award], ping_ms: result[:ms]) end
Source
# File plugins/autovoice.rb, line 163 def execute(m, args = nil) return unless m.channel return unless self.class.responds_to_command?(bot) network = bot.config.server channel = m.channel.name lag_ms = self.class.lag_ms_from_bot(bot) unless self.class.admin_allowed?( network: network, channel: channel, nick: m.user.nick, is_op: m.channel.opped?(m.user) ) themed_flood_safe_reply(m, AutovoiceReport.format_denial(lag_ms: lag_ms)) return end parsed = self.class.parse_command(args) if parsed[:error] themed_flood_safe_reply(m, parsed[:error]) return end state = AutovoiceStore.load_state(network: network, channel: channel) case parsed[:action] when :on AutovoiceStore.set_enabled!(network: network, channel: channel, enabled: true) reply_status(m, network: network, channel: channel, lag_ms: lag_ms) when :off AutovoiceStore.set_enabled!(network: network, channel: channel, enabled: false) reply_status(m, network: network, channel: channel, lag_ms: lag_ms) when :interval updated = state.merge("interval_min" => parsed[:minutes]) AutovoiceStore.save_state(network: network, channel: channel, state: updated) reply_status(m, network: network, channel: channel, lag_ms: lag_ms) when :status reply_status(m, network: network, channel: channel, lag_ms: lag_ms) when :now deliver_award(network: network, channel_name: channel, reply_to: m, force: true, lag_ms: lag_ms) end end
Source
# File plugins/autovoice.rb, line 228 def flush_stale_autovoice_awards return unless self.class.responds_to_command?(bot) now = Process.clock_gettime(Process::CLOCK_MONOTONIC) IrcUserPing.stale_awards(max_age_sec: AWARD_PING_FALLBACK_SEC, now: now).each do |_key, entry| deliver_pending_announcement(entry[:award], ping_ms: nil) IrcUserPing.remove!(nick: entry[:nick]) end end
Source
# File plugins/autovoice.rb, line 136 def poll_autovoice return unless self.class.responds_to_command?(bot) lag_ms = self.class.lag_ms_from_bot(bot) self.class.poll_channels(bot, lag_ms: lag_ms, runner: award_runner).each do |entry| user = find_user(entry[:channel], entry[:nick]) next unless user entry[:channel].voice(user) queue_award_announcement(user: user, award: entry, reply_to: entry[:channel]) end end
Source
# File plugins/autovoice.rb, line 149 def record_channel_activity(m) return unless m.channel return unless self.class.responds_to_command?(bot) AutovoiceActivity.record_from_message( network: bot.config.server, channel: m.channel.name, nick: m.user.nick, text: m.message, channel_obj: m.channel, bot_nick: bot.nick ) end