Class: Slacky::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/slacky/message.rb

Constant Summary collapse

@@decorator =
@@bot = nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#channelObject (readonly)

Returns the value of attribute channel.



3
4
5
# File 'lib/slacky/message.rb', line 3

def channel
  @channel
end

#rawObject (readonly)

Returns the value of attribute raw.



3
4
5
# File 'lib/slacky/message.rb', line 3

def raw
  @raw
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/slacky/message.rb', line 3

def text
  @text
end

#userObject (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

#commandObject



34
35
36
37
38
39
40
# File 'lib/slacky/message.rb', line 34

def command
  if @channel.type == :im
    command? ? downword(1) : downword(0)
  else
    command? ? downword(1) : nil
  end
end

#command?Boolean

Returns:



28
29
30
31
32
# File 'lib/slacky/message.rb', line 28

def command?
  first = word 0
  return false unless first
  first == @@bot.name || first == "<@#{@@bot.slack_id}>"
end

#command_argsObject



42
43
44
45
46
# File 'lib/slacky/message.rb', line 42

def command_args
  return nil unless command
  index = @text.index(command) + command.length
  @text[index..-1].strip
end

#no?Boolean

Returns:



52
53
54
# File 'lib/slacky/message.rb', line 52

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.message channel: @channel.slack_id, reply_to: @raw.id, text: msg
end

#yes?Boolean

Returns:



48
49
50
# File 'lib/slacky/message.rb', line 48

def yes?
  [ 'y', 'yes', 'yep' ].include? @text.downcase
end