class AthfRabbot
Constants
- BRISBANE_UTC_OFFSET
- COLOR_PRESETS
- DARK_BACKGROUNDS
- DARK_FOREGROUNDS
- IRC_CTRL
- IRC_RESET
- LIGHT_BACKGROUNDS
- LIGHT_FOREGROUNDS
-
mIRC palette: light text on dark bg, dark text on light bg, plus a few medium accents.
- LOW_CONTRAST_PRESETS
- MEDIUM_BACKGROUNDS
- MEDIUM_FOREGROUNDS
- MESSAGES
- MESSAGE_TOKEN_PATTERN
-
Keep each inter-word space inside the preceding wordβs colour block.
- NUMBERS_MESSAGE
- WEEKDAYS_MESSAGE
Public Class Methods
Source
# File plugins/athf_rabbot.rb, line 96 def self.colorize_token(token, fg, bg, message:, date: nil) date ||= today_in_brisbane body = weekdays_message?(message) ? underline_today_weekday(token, date: date) : token "#{irc_color(fg, bg)}#{body}#{IRC_RESET}" end
Source
# File plugins/athf_rabbot.rb, line 102 def self.colorize_words(text, rng: Random, date: nil) date ||= today_in_brisbane tokens = tokens_for_color(text) return "" if tokens.empty? pairs = COLOR_PRESETS.shuffle(random: rng).first(tokens.length) colored = tokens.zip(pairs).map do |token, (fg, bg)| colorize_token(token, fg, bg, message: text, date: date) end structured_message?(text) ? colored.join : colored.join(" ") end
Source
# File plugins/athf_rabbot.rb, line 52 def self.command_message?(message) CharacterMention.command_message?(message) end
Source
# File plugins/athf_rabbot.rb, line 115 def self.format_quote(message, rng: Random, date: nil) colorize_words(message, rng: rng, date: date) end
Source
# File plugins/athf_rabbot.rb, line 45 def self.irc_color(fg, bg) # Pad to 2 digits so digit-words like "1," are not parsed as part of the colour code. "#{IRC_CTRL}#{fg.to_i.to_s.rjust(2, "0")},#{bg.to_i.to_s.rjust(2, "0")}" end
Source
# File plugins/athf_rabbot.rb, line 56 def self.mentioned?(message, nick) CharacterMention.mentioned?(message, nick) end
Source
# File plugins/athf_rabbot.rb, line 64 def self.numbers_message?(text) text.to_s == NUMBERS_MESSAGE end
Source
# File plugins/athf_rabbot.rb, line 119 def self.random_quote(rng: Random, date: nil) format_quote(MESSAGES.sample(random: rng), rng: rng, date: date) end
Source
# File plugins/athf_rabbot.rb, line 84 def self.structured_message?(text) weekdays_message?(text) || numbers_message?(text) end
Source
# File plugins/athf_rabbot.rb, line 72 def self.today_in_brisbane(clock: Time.now) clock.getlocal(BRISBANE_UTC_OFFSET).to_date end
Source
# File plugins/athf_rabbot.rb, line 68 def self.token_day_name(token) token.to_s.strip.sub(/[,.]\z/, "") end
Source
# File plugins/athf_rabbot.rb, line 88 def self.tokens_for_color(text) if structured_message?(text) text.scan(MESSAGE_TOKEN_PATTERN) else text.split(/\s+/) end end
Source
# File plugins/athf_rabbot.rb, line 76 def self.underline_today_weekday(token, date: nil) date ||= today_in_brisbane day = token_day_name(token) return token unless day.casecmp?(Date::DAYNAMES[date.wday]) IrcFormat.underline(token) end
Source
# File plugins/athf_rabbot.rb, line 60 def self.weekdays_message?(text) text.to_s == WEEKDAYS_MESSAGE end
Public Instance Methods
Source
# File plugins/athf_rabbot.rb, line 123 def respond_to_mention(m) return if m.user.nick == bot.nick return if self.class.command_message?(m.message) return unless self.class.mentioned?(m.message, bot.nick) safe_reply(m, self.class.random_quote) end