module CharacterMention
Public Instance Methods
Source
# File lib/character_mention.rb, line 6 def command_for_bot?(message, nick) text = message.to_s.lstrip nick = nick.to_s.strip return false if text.empty? || nick.empty? text.match?(/\A!#{Regexp.escape(nick)}(?:\b|\s|:|,)/i) end
Source
# File lib/character_mention.rb, line 14 def command_message?(message) message.to_s.lstrip.start_with?("!") end
Source
# File lib/character_mention.rb, line 18 def mentioned?(message, nick) text = message.to_s nick = nick.to_s.strip return false if text.strip.empty? || nick.empty? text.match?(/(?<![A-Za-z0-9_-])#{Regexp.escape(nick)}(?![A-Za-z0-9_-])/i) end
Source
# File lib/character_mention.rb, line 26 def mentioned_any?(message, nicks) Array(nicks).any? { |nick| mentioned?(message, nick) } end
Source
# File lib/character_mention.rb, line 40 def profile_reply(profile, random: Random) responses = profile_responses(profile) return nil if responses.empty? responses.sample(random: random) end
Source
# File lib/character_mention.rb, line 30 def profile_responses(profile) return [] unless profile if profile.respond_to?(:mention_responses) && !profile.mention_responses.empty? profile.mention_responses else profile.examples.map { |entry| entry["bot"] } end end