module BannerLetterCommand
BannerLetterCommand — parse and handle !bannerletter. Public: parse, handle, usage_message Depends: BannerFontStore, BannerFontReport Tests: test/lib/banner_letter_command_test.rb
Public Instance Methods
Source
# File lib/banner_letter_command.rb, line 86 def channel_allowed?(channel) !channel.nil? && !channel.to_s.strip.empty? end
Source
# File lib/banner_letter_command.rb, line 91 def channel_error { error: true, reply: BannerFontReport.pm_error, multiline: false } end
Source
# File lib/banner_letter_command.rb, line 96 def error_result(message) { error: true, reply: BannerFontReport.error(message), multiline: false } end
Source
# File lib/banner_letter_command.rb, line 45 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 :show handle_show(parsed[:letter], network: network, channel: channel, store: store) when :set handle_set(parsed[:letter], parsed[:rows], network: network, channel: channel, store: store) when :reset handle_reset(parsed[:letter], network: network, channel: channel, store: store) else error_result(usage_message) end rescue ArgumentError => e error_result(e.message) end
Source
# File lib/banner_letter_command.rb, line 80 def handle_reset(letter, network:, channel:, store:) char = BannerFontStore.normalize_letter(letter) BannerFontStore.reset_glyph!(char, network: network, channel: channel, store: store) { error: false, reply: BannerFontReport.letter_reset(char), multiline: false } end
Source
# File lib/banner_letter_command.rb, line 74 def handle_set(letter, rows, network:, channel:, store:) char = BannerFontStore.normalize_letter(letter) BannerFontStore.set_glyph!(char, rows, network: network, channel: channel, store: store) { error: false, reply: BannerFontReport.letter_set(char), multiline: false } end
Source
# File lib/banner_letter_command.rb, line 65 def handle_show(letter, network:, channel:, store:) char = BannerFontStore.normalize_letter(letter) glyphs = BannerFontStore.effective_glyphs(network: network, channel: channel, store: store) rows = glyphs[char] || BannerFont::GLYPHS[char] || BannerFont::GLYPHS[" "] { error: false, reply: BannerFontReport.letter_show(char, rows), multiline: true } rescue ArgumentError => e error_result(e.message) end
Source
# File lib/banner_letter_command.rb, line 20 def parse(args) text = args.to_s.strip return { error: usage_message } if text.empty? parts = text.split(/\s+/) letter = parts[0].to_s.upcase return { error: usage_message } if letter.empty? if parts.length == 1 return { action: :show, letter: letter } end if parts[1].casecmp("reset").zero? return { action: :reset, letter: letter } end return { error: usage_message } unless parts.length == BannerFont::HEIGHT + 1 { action: :set, letter: letter, rows: parts[1, BannerFont::HEIGHT] } end
Source
# File lib/banner_letter_command.rb, line 16 def usage_message "Usage: !bannerletter <letter> | !bannerletter <letter> <row1> <row2> <row3> <row4> | !bannerletter <letter> reset" end