module RabbotMetaAiGuardBypass
Constants
- AI_COMMAND_PATTERN
- CONTEXT_TTL_SEC
- EDUCATIONAL_PATH_PATTERNS
- NICK_AI_COMMAND_PATTERN
- WHICH_RELATIVE_PRONOUN_PATTERN
Public Instance Methods
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 181 def bypass_key(network:, channel:, nick:) [ network.to_s.strip.downcase, Normalize.channel(channel), Normalize.user_key(nick) ].join("|") end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 162 def bypass_pending?(network:, channel:, nick:) @mutex.synchronize do @pending.key?(bypass_key(network: network, channel: channel, nick: nick)) end end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 174 def consume_bypass!(network:, channel:, nick:) @mutex.synchronize do key = bypass_key(network: network, channel: channel, nick: nick) @pending.delete(key) ? true : false end end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 122 def current_context @mutex.synchronize do ctx = @current_context return nil unless ctx return nil if Time.now.to_f - ctx[:noted_at].to_f > CONTEXT_TTL_SEC ctx.slice(:network, :channel, :nick) end end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 95 def extract_ai_question(text) message = text.to_s.lstrip return nil unless message.start_with?("!") if (match = message.match(AI_COMMAND_PATTERN)) return match[1].to_s.strip end return nil unless (match = message.match(NICK_AI_COMMAND_PATTERN)) match[2].to_s.strip end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 132 def false_positive?(question) text = question.to_s.strip return false if text.empty? text.match?(WHICH_RELATIVE_PRONOUN_PATTERN) end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 168 def grant_bypass!(network:, channel:, nick:) @mutex.synchronize do @pending[bypass_key(network: network, channel: channel, nick: nick)] = Time.now.to_f end end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 84 def hook_active? @installed end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 69 def install! return if @installed AiGuard.singleton_class.prepend(GuardHook) unless AiGuard.singleton_class.ancestors.include?(GuardHook) @installed = true end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 80 def installed? @installed end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 108 def note_message(network:, channel:, nick:, text:) question = extract_ai_question(text) return if question.nil? @mutex.synchronize do @current_context = { network: network.to_s, channel: channel.to_s, nick: nick.to_s, noted_at: Time.now.to_f } end end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 155 def raw_system_request?(text) normalized = text.to_s.strip return false if normalized.empty? AiGuard.scrub_urls(normalized).match?(AiGuard::SYSTEM_REQUEST_PATTERN) end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 88 def reset! @mutex.synchronize do @pending = {} @current_context = nil end end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 139 def scrub_educational_paths(text) scrubbed = text.to_s EDUCATIONAL_PATH_PATTERNS.each do |pattern| scrubbed = scrubbed.gsub(pattern, " ") end scrubbed end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 147 def should_grant_bypass?(question:) text = question.to_s.strip return false if text.empty? return false unless raw_system_request?(text) false_positive?(text) end
Source
# File lib/rabbot_meta_ai_guard_bypass.rb, line 76 def uninstall! @installed = false end