module BannerFontCommand
BannerFontCommand — parse and handle !bannerfont subcommands. Public: parse, handle, usage_message Depends: BannerFontStore, BannerFontReport Tests: test/lib/banner_font_command_test.rb
Public Instance Methods
Source
# File lib/banner_font_command.rb, line 126 def channel_allowed?(channel) !channel.nil? && !channel.to_s.strip.empty? end
Source
# File lib/banner_font_command.rb, line 131 def channel_error { error: true, reply: BannerFontReport.pm_error, multiline: false } end
Source
# File lib/banner_font_command.rb, line 136 def error_result(message) { error: true, reply: BannerFontReport.error(message), multiline: false } end
Source
# File lib/banner_font_command.rb, line 55 def handle(args, network:, channel:, store: RabbotDb) return channel_error unless channel_allowed?(channel) parsed = parse(args) return error_result(parsed[:error]) if parsed[:error] case parsed[:action] when :help { error: false, reply: BannerFontReport.help, multiline: true } when :list handle_list(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 :new handle_new(parsed[:name], network: network, channel: channel, store: store) when :show handle_show(parsed[:name], network: network, channel: channel, store: store) when :reset handle_reset(parsed[:letter], network: network, channel: channel, store: store) when :delete handle_delete(parsed[:name], network: network, channel: channel, store: store) else error_result(usage_message) end rescue ArgumentError => e error_result(e.message) end
Source
# File lib/banner_font_command.rb, line 91 def handle_active(network:, channel:, store:) active = BannerFontStore.active(network: network, channel: channel, store: store) { error: false, reply: BannerFontReport.active_font(active), multiline: true } end
Source
# File lib/banner_font_command.rb, line 121 def handle_delete(name, network:, channel:, store:) deleted = BannerFontStore.delete_font!(name, network: network, channel: channel, store: store) { error: false, reply: BannerFontReport.deleted(deleted), multiline: true } end
Source
# File lib/banner_font_command.rb, line 85 def handle_list(network:, channel:, store:) active = BannerFontStore.active(network: network, channel: channel, store: store) custom = BannerFontStore.custom_font_names(network: network, channel: channel, store: store) { error: false, reply: BannerFontReport.list(active: active, custom: custom), multiline: true } end
Source
# File lib/banner_font_command.rb, line 101 def handle_new(name, network:, channel:, store:) created = BannerFontStore.create_font!(name, network: network, channel: channel, store: store) { error: false, reply: BannerFontReport.created(created), multiline: true } end
Source
# File lib/banner_font_command.rb, line 113 def handle_reset(letter, network:, channel:, store:) BannerFontStore.reset_font!(letter: letter, network: network, channel: channel, store: store) char = letter ? BannerFontStore.normalize_letter(letter) : nil { error: false, reply: BannerFontReport.reset_scope(letter: char), multiline: true } rescue ArgumentError => e error_result(e.message) end
Source
# File lib/banner_font_command.rb, line 106 def handle_show(name, network:, channel:, store:) font_name = name || BannerFontStore.active(network: network, channel: channel, store: store) letters = BannerFontStore.customized_letters(network: network, channel: channel, font_name: font_name, store: store) glyphs = BannerFontStore.glyphs_for_font(font_name, network: network, channel: channel, store: store) { error: false, reply: BannerFontReport.show_font(font_name, letters, glyphs: glyphs), multiline: true } end
Source
# File lib/banner_font_command.rb, line 96 def handle_use(name, network:, channel:, store:) applied = BannerFontStore.set_active!(name, network: network, channel: channel, store: store) { error: false, reply: BannerFontReport.applied(applied), multiline: true } end
Source
# File lib/banner_font_command.rb, line 19 def parse(args) text = args.to_s.strip return { action: :help } if text.empty? || text.casecmp("help").zero? parts = text.split(/\s+/, 2) verb = parts[0].downcase rest = parts[1].to_s.strip case verb when "list" { action: :list } when "active" { action: :active } when "use" return { error: usage_message } if rest.empty? { action: :use, name: rest.split(/\s+/).first.downcase } when "new" return { error: usage_message } if rest.empty? { action: :new, name: rest.split(/\s+/).first.downcase } when "show" name = rest.empty? ? nil : rest.split(/\s+/).first.downcase { action: :show, name: name } when "reset" letter = rest.empty? ? nil : rest.split(/\s+/).first { action: :reset, letter: letter } when "delete" return { error: usage_message } if rest.empty? { action: :delete, name: rest.split(/\s+/).first.downcase } else { error: usage_message } end end
Source
# File lib/banner_font_command.rb, line 15 def usage_message "Usage: !bannerfont list|active|use|new|show|reset|delete|help" end