class Theme
Public Class Methods
Source
# File plugins/theme.rb, line 33 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/theme.rb, line 23 def self.command_pattern /theme(?:\s+(.+))?$/i end
Source
# File plugins/theme.rb, line 43 def self.handle(args, network:, channel:, admin_allowed:, store: RabbotDb) return [:error, ThemeReport.denial] unless admin_allowed parsed = ThemeCommand.parse(args) return [:error, ThemeReport.error_card(parsed[:error])] if parsed[:error] case parsed[:action] when :help [:ok, ThemeReport.help] when :list handle_list(network: network, channel: channel, store: store) when :show handle_show(parsed[:name], network: network, channel: channel, store: store) when :active handle_active(network: network, channel: channel, store: store) when :use handle_use(parsed[:name], network: network, channel: channel, store: store) when :paint handle_paint(parsed[:name], plugin: parsed[:plugin], network: network, channel: channel, store: store) when :analyse handle_analyse(parsed[:name], network: network, channel: channel, store: store) when :generate handle_generate(parsed[:seed], network: network, channel: channel, store: store) when :save handle_save(parsed[:name], network: network, channel: channel, store: store) else [:error, ThemeReport.error_card(ThemeCommand.usage_message)] end end
Source
# File plugins/theme.rb, line 86 def self.handle_active(network:, channel:, store:) active = ThemeStore.active(network: network, channel: channel, store: store) [:ok, ThemeReport.active(active)] end
Source
# File plugins/theme.rb, line 108 def self.handle_analyse(name, network:, channel:, store:) theme_id = name || ThemeStore.active(network: network, channel: channel, store: store) if theme_id.nil? || theme_id.to_s.strip.empty? return [:error, ThemeReport.error_card("No active theme — use !theme analyse <name> or !theme use <name>.")] end custom = ThemeStore.custom_themes(network: network, channel: channel, store: store) theme = ThemeCatalog.resolve(theme_id, custom: custom) return [:error, ThemeReport.error_card("Unknown theme #{theme_id} — try !theme list.")] unless theme result = PaintAnalyse.analyse(theme) [:ok, ThemeReport.analyse(result)] end
Source
# File plugins/theme.rb, line 122 def self.handle_generate(seed, network:, channel:, store:) theme = ThemeGenerate.from_seed(seed || Time.now.to_i.to_s) ThemeStore.set_last_generated!(theme, network: network, channel: channel, store: store) [:ok, ThemeReport.generated(theme)] end
Source
# File plugins/theme.rb, line 73 def self.handle_list(network:, channel:, store:) custom = ThemeStore.custom_themes(network: network, channel: channel, store: store) active = ThemeStore.active(network: network, channel: channel, store: store) [:ok, ThemeReport.list(builtin: ThemeCatalog.all, custom: custom, active: active)] end
Source
# File plugins/theme.rb, line 100 def self.handle_paint(name, plugin:, network:, channel:, store:) theme = resolve_theme(name, network: network, channel: channel, store: store) return [:error, ThemeReport.unknown_theme(name)] unless theme lines = ThemePaint.commands(theme, plugin: plugin) [:ok, ThemeReport.paint_batch(theme, lines)] end
Source
# File plugins/theme.rb, line 128 def self.handle_save(name, network:, channel:, store:) theme = ThemeStore.last_generated(network: network, channel: channel, store: store) return [:error, ThemeReport.no_generated_theme] unless theme slug = name.to_s.downcase.gsub(/[^a-z0-9_-]+/, "-").gsub(/\A-+|-+\z/, "") saved = theme.merge(id: slug, name: name.to_s) ThemeStore.save_custom!(saved, network: network, channel: channel, store: store) [:ok, ThemeReport.saved(slug)] end
Source
# File plugins/theme.rb, line 79 def self.handle_show(name, network:, channel:, store:) theme = resolve_theme(name, network: network, channel: channel, store: store) return [:error, ThemeReport.unknown_theme(name)] unless theme [:ok, ThemeReport.show(theme)] end
Source
# File plugins/theme.rb, line 91 def self.handle_use(name, network:, channel:, store:) theme = resolve_theme(name, network: network, channel: channel, store: store) return [:error, ThemeReport.unknown_theme(name)] unless theme ThemeStore.set_active!(theme[:id], network: network, channel: channel, store: store) ThemePaint.apply!(theme, network: network, channel: channel, store: store) [:ok, ThemeReport.applied(theme)] end
Source
# File plugins/theme.rb, line 29 def self.responds_to_command?(bot) BotIdentity.owner_bot?(bot) end
Public Instance Methods
Source
# File plugins/theme.rb, line 144 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 themed_flood_safe_reply(m, message, plugin: "theme", with_progress: false) end