lib/hipbot/message.rb in hipbot-0.2.0 vs lib/hipbot/message.rb in hipbot-1.0.0.rc1
- old
+ new
@@ -1,28 +1,28 @@
module Hipbot
- class Message
- attr_reader :body, :sender, :raw_body
+ class Message < Struct.new(:raw_body, :room, :sender)
+ attr_accessor :body, :recipients
- def initialize body, sender
- @raw_body = body
- @body = strip_recipient(body)
- @sender = sender
+ def initialize *args
+ super
+ Hipbot.logger.info("MESSAGE from #{sender} in #{room}")
+ self.body = strip_recipient(raw_body)
+ self.recipients = raw_body.scan(/@(\p{Word}++)/).flatten.compact.uniq
end
- def recipients
- results = raw_body.scan(/@(\w+)/) + raw_body.scan(/@"(.*)"/)
- results.flatten.uniq
- end
-
def for? recipient
- recipients.include? recipient.to_s.gsub(/\s+/, '')
+ recipients.include? recipient.mention
end
def strip_recipient body
- body.gsub(/^@\w+\W*/, '')
+ body.gsub(/^@\p{Word}++[^\p{Word}]*/, '').strip
end
def mentions
recipients[1..-1] || [] # TODO: Fix global message case
+ end
+
+ def private?
+ room.nil?
end
end
end