class Ehc
Constants
- COMMAND_PATTERN
Public Class Methods
Source
# File plugins/ehc.rb, line 30 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/ehc.rb, line 143 def self.channel_user_entries(channel_users) case channel_users when Hash channel_users.keys else Array(channel_users) end end
Source
# File plugins/ehc.rb, line 152 def self.channel_users_from(channel) return [] unless channel raw = if channel.respond_to?(:user_list) channel.user_list else channel.users end channel_user_entries(raw).map do |entry| if entry.is_a?(Hash) entry else { nick: entry.nick, host: entry.host } end end end
Source
# File plugins/ehc.rb, line 40 def self.dispatch(args:, nick:, ai_allowed:, admin_allowed: false, network: nil, channel: nil, channel_users: nil, fetch: nil, eh_fetch: nil, runner: nil, tool_runner: nil, pacman: nil, store: RabbotDb, model: EhcAgent::AGENT_MODEL, now: Time.now.utc) stripped = args.to_s.strip return EhcToolkit.dispatch(pacman: pacman) if stripped.match?(/\Atoolkit\z/i) if stripped.match?(/\Aissue\s+\d+\z/i) return EhcHarden.dispatch_issue( args: stripped, network: network, channel: channel, admin_allowed: admin_allowed, store: store ) end target = EhcHardenTarget.resolve(args: stripped, channel_users: channel_users, admin: admin_allowed) if target[:harden_target] if target[:kind] == :url && !admin_allowed # Non-admin voice+ keeps AI recon on public URLs (including unsafe → recon error). elsif !admin_allowed return EhcHarden.admin_denial_result elsif target[:error] return { success: false, reply: EhcHardenReport.format_target_error(target[:error]) } else return EhcHarden.scan( target: target, network: network, channel: channel, fetch: fetch, pacman: pacman, runner: tool_runner, store: store ) end end return { success: false, reply: AiAccess.denial_message } unless ai_allowed EhcAnalyze.dispatch( args: args, nick: nick, ai_allowed: ai_allowed, fetch: fetch, eh_fetch: eh_fetch, runner: runner, store: store, model: model, now: now ) end
Public Instance Methods
Source
# File plugins/ehc.rb, line 171 def channel_users_from(channel) self.class.channel_users_from(channel) end
Source
# File plugins/ehc.rb, line 92 def execute(m, args = nil) unless m.channel m.reply "Use !ehc in a channel" return end network = bot.config.server channel = m.channel.name result = self.class.dispatch( args: args, nick: m.user.nick, ai_allowed: AiAccess.user_allowed?( channel: m.channel, user: m.user, network: network, nick: m.user.nick, irc: true ), admin_allowed: self.class.admin_allowed?( network: network, channel: channel, nick: m.user.nick, is_op: m.channel.opped?(m.user) ), network: network, channel: channel, channel_users: channel_users_from(m.channel), fetch: method(:fetch_page), eh_fetch: method(:fetch_eh_json), pacman: method(:query_pacman), tool_runner: method(:run_tool) ) themed_flood_safe_reply(m, result[:reply]) end
Source
# File plugins/ehc.rb, line 129 def fetch_eh_json(url) RabbotHttp.fetch(url, user_agent: EhSearch::USER_AGENT) end
Source
# File plugins/ehc.rb, line 133 def query_pacman(flag, arg = nil) args = ["pacman", flag] args << arg if arg && !arg.to_s.empty? Open3.capture2(*args) end