class Paint
Public Class Methods
Source
# File plugins/paint.rb, line 34 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/paint.rb, line 24 def self.command_pattern /paint(?:\s+(.+))?$/i end
Source
# File plugins/paint.rb, line 44 def self.handle(args, network:, channel:, admin_allowed:, store: RabbotDb) return [:error, PaintReport.denial] unless admin_allowed parsed = PaintCommand.parse(args) return [:error, PaintReport.error_card(parsed[:error])] if parsed[:error] case parsed[:action] when :help [:ok, PaintReport.help] when :list handle_list(parsed, network: network, channel: channel, store: store) when :preview handle_preview(parsed, network: network, channel: channel, store: store) when :reset handle_reset(parsed, network: network, channel: channel, store: store) when :analyse handle_analyse(parsed, network: network, channel: channel, store: store) when :paint handle_paint(parsed, network: network, channel: channel, store: store) else [:error, PaintReport.error_card(PaintCommand.usage_message)] end end
Source
# File plugins/paint.rb, line 108 def self.handle_analyse(parsed, network:, channel:, store:) theme_id = parsed[:theme] || ThemeStore.active(network: network, channel: channel, store: store) if theme_id.nil? || theme_id.to_s.strip.empty? return [:error, PaintReport.error_card("No active theme — use !paint analyse <theme> or !theme use <name>.")] end custom = ThemeStore.custom_themes(network: network, channel: channel, store: store) theme = ThemeCatalog.resolve(theme_id, custom: custom) return [:error, PaintReport.error_card("Unknown theme — try !theme list.")] unless theme result = PaintAnalyse.analyse(theme) [:ok, PaintReport.analyse(result)] end
Source
# File plugins/paint.rb, line 68 def self.handle_list(parsed, network:, channel:, store:) if parsed[:plugin] lines = PaintSamples.lines(parsed[:plugin]) return [:error, PaintReport.error_card("Unknown plugin — try !paint list.")] unless lines [:ok, PaintReport.list_lines(plugin: parsed[:plugin], lines: lines)] else [:ok, PaintReport.list_plugins(PaintSamples.known)] end end
Source
# File plugins/paint.rb, line 122 def self.handle_paint(parsed, network:, channel:, store:) lines = PaintSamples.lines(parsed[:plugin]) return [:error, PaintReport.error_card("Unknown plugin — try !paint list.")] unless lines target_lines = select_target_lines(lines, parsed) return [:error, PaintReport.error_card("No sample lines matched that snippet.")] if target_lines.empty? saved = target_lines.map do |line_number| line_text = lines[line_number - 1] result = IrcPaint.recolor_at(line_text, parsed[:pos], fg: parsed[:fg], bg: parsed[:bg]) PaintStore.save_override!( network: network, channel: channel, override: { plugin: parsed[:plugin], line: line_number, plain_start: result[:plain_start], plain_end: result[:plain_end], fg: result[:fg], bg: result[:bg], snippet: parsed[:snippet] }, store: store ) end summary_line = saved.map { |entry| entry[:line] }.join("-") message = PaintReport.updated( plugin: parsed[:plugin], line: summary_line, fg: parsed[:fg], bg: parsed[:bg], snippet: parsed[:snippet] ) [:ok, message] rescue ArgumentError => e [:error, PaintReport.error_card(e.message)] end
Source
# File plugins/paint.rb, line 79 def self.handle_preview(parsed, network:, channel:, store:) lines = PaintSamples.lines(parsed[:plugin]) return [:error, PaintReport.error_card("Unknown plugin — try !paint list.")] unless lines overrides = PaintStore.list(network: network, channel: channel, plugin: parsed[:plugin], store: store) painted = PaintApply.to_lines(lines: lines, overrides: overrides) [:ok, PaintReport.preview(plugin: parsed[:plugin], lines: painted, override_count: overrides.length)] end
Source
# File plugins/paint.rb, line 88 def self.handle_reset(parsed, network:, channel:, store:) if parsed[:line] PaintStore.remove_for_line!( network: network, channel: channel, plugin: parsed[:plugin], line: parsed[:line], store: store ) else PaintStore.remove_for_plugin!( network: network, channel: channel, plugin: parsed[:plugin], store: store ) end [:ok, PaintReport.reset(plugin: parsed[:plugin], line: parsed[:line])] end
Source
# File plugins/paint.rb, line 30 def self.responds_to_command?(bot) BotIdentity.owner_bot?(bot) end
Public Instance Methods
Source
# File plugins/paint.rb, line 173 def execute(m, args) return unless self.class.responds_to_command?(bot) network = bot.config.server channel = m.channel&.name return unless channel status, message = self.class.handle( args, network: network, channel: channel, admin_allowed: self.class.admin_allowed?( network: network, channel: channel, nick: m.user.nick, is_op: m.channel.opped?(m.user) ) ) _ = status flood_safe_reply(m, message) end