Class: Slacky::Message
- Inherits:
-
Object
- Object
- Slacky::Message
- Defined in:
- lib/slacky/message.rb
Constant Summary collapse
- @@decorator =
@@bot = nil
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
- #command? ⇒ Boolean
- #command_args ⇒ Object
-
#initialize(user, channel, raw) ⇒ Message
constructor
A new instance of Message.
- #no? ⇒ Boolean
- #reply(msg) ⇒ Object
- #typing ⇒ Object
- #yes? ⇒ Boolean
Constructor Details
#initialize(user, channel, raw) ⇒ Message
Returns a new instance of Message.
15 16 17 18 19 20 21 22 |
# File 'lib/slacky/message.rb', line 15 def initialize(user, channel, raw) @raw = raw @user = user @channel = channel @text = raw.text.strip @pieces = @text.split ' ' self.extend @@decorator if @@decorator end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
3 4 5 |
# File 'lib/slacky/message.rb', line 3 def channel @channel end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
3 4 5 |
# File 'lib/slacky/message.rb', line 3 def raw @raw end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/slacky/message.rb', line 3 def text @text end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'lib/slacky/message.rb', line 3 def user @user end |
Class Method Details
.bot=(bot) ⇒ Object
11 12 13 |
# File 'lib/slacky/message.rb', line 11 def self.bot=(bot) @@bot = bot end |
.decorator=(decorator) ⇒ Object
7 8 9 |
# File 'lib/slacky/message.rb', line 7 def self.decorator=(decorator) @@decorator = decorator end |
Instance Method Details
#command ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/slacky/message.rb', line 40 def command if @channel.type == :im command? ? downword(1) : downword(0) else command? ? downword(1) : nil end end |
#command? ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/slacky/message.rb', line 32 def command? first = downword 0 return false unless first [ @@bot.name, "<@#{@@bot.slack_id.downcase}>" ].any? do |name| first == name || first == "#{name}:" end end |
#command_args ⇒ Object
48 49 50 51 52 |
# File 'lib/slacky/message.rb', line 48 def command_args return nil unless command index = @text.downcase.index(command) + command.length @text[index..-1].strip end |
#no? ⇒ Boolean
58 59 60 |
# File 'lib/slacky/message.rb', line 58 def no? [ 'n', 'no', 'nope' ].include? @text.downcase end |
#reply(msg) ⇒ Object
24 25 26 |
# File 'lib/slacky/message.rb', line 24 def reply(msg) @@bot.client. channel: @channel.slack_id, reply_to: @raw.id, text: msg end |
#typing ⇒ Object
28 29 30 |
# File 'lib/slacky/message.rb', line 28 def typing @@bot.client.typing channel: @channel.slack_id end |
#yes? ⇒ Boolean
54 55 56 |
# File 'lib/slacky/message.rb', line 54 def yes? [ 'y', 'yes', 'yep' ].include? @text.downcase end |