Sha256: 9474feb90408d2f650ebecef656e547a07d97c43aea6d9295a1522915d060d19
Contents?: true
Size: 844 Bytes
Versions: 1
Compression:
Stored size: 844 Bytes
Contents
# encoding: utf-8 module Hipbot class Message < Struct.new(:raw_body, :room, :sender) include Cache attr_accessor :body MENTION_REGEXP = /@(\p{Word}++):?/.freeze def initialize *args super Hipbot.logger.info("MESSAGE from #{sender} in ##{room}") self.raw_body = raw_body.force_encoding('UTF-8') self.body = strip_bot_mention end def for? user recipients.include? user.mention end attr_cache :recipients do raw_body.scan(MENTION_REGEXP).flatten.compact.uniq end attr_cache :mentions do recipients.tap{ |r| r.delete(bot_mention) } end def private? room.nil? end protected def bot_mention Hipbot.user.mention end def strip_bot_mention raw_body.gsub(/^@#{bot_mention}[^\p{Word}]*/, '') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hipbot-1.0.4 | lib/hipbot/message.rb |