class Quote
Constants
- STYLE_TITLE
Public Class Methods
Source
# File plugins/quote.rb, line 40 def self.format_quote(entry) header = IrcFormat.report_header(tag: "QUOTE", title: entry["nick"], style: STYLE_TITLE) [header, entry["text"].to_s].join("\n") end
Source
# File plugins/quote.rb, line 24 def self.parse_command(text) stripped = text.to_s.strip return { action: :random } if stripped.empty? if (match = stripped.match(/\Aadd\s+(.+)\z/i)) quote = match[1].to_s.strip return { error: usage_message } if quote.empty? return { action: :add, text: quote } end return { action: :random } if stripped.match?(/\Arandom\z/i) { error: usage_message } end
Source
# File plugins/quote.rb, line 20 def self.usage_message "Usage: !quote add <text> | !quote random" end
Public Instance Methods
Source
# File plugins/quote.rb, line 45 def execute(m, args = nil) unless m.channel m.reply "Use !quote in a channel" return end parsed = self.class.parse_command(args) if parsed[:error] m.reply parsed[:error] return end network = bot.config.server channel = m.channel.name message = case parsed[:action] when :add entry = QuoteStore.add(network: network, channel: channel, nick: m.user.nick, text: parsed[:text]) "Quote ##{entry['id']} saved" when :random entry = QuoteStore.random(network: network, channel: channel) entry ? self.class.format_quote(entry) : "No quotes saved yet" end themed_flood_safe_reply(m, message) end