Class: S3PO::Message

Inherits:
Event
  • Object
show all
Defined in:
lib/s-3po/events.rb

Overview

Message Event class comes from Slack, or you would create one to send a message.

Instance Attribute Summary

Attributes inherited from Event

#object, #options

Instance Method Summary collapse

Methods inherited from Event

#channel, #channel=, #initialize, #is_hidden?, #is_im?, #is_message?, #is_simplemessage?, #subtype, #ts, #type, #user

Constructor Details

This class inherits a constructor from S3PO::Event

Instance Method Details

#instructionArray

Break up the message text into an Arrary per word when prefixed with bot username; e.g., “@bot echo hello”

Returns:

  • (Array)

    excluding the prefixed bot username


116
117
118
119
# File 'lib/s-3po/events.rb', line 116

def instruction
  return nil unless is_instruction?
  @instruction ||= Parser.instruction_from_plain(plain, options[:botid])
end

#is_instruction?Boolean

Is the message directed to me and/or prefixed with bot username?

Returns:

  • (Boolean)

103
104
105
106
107
108
109
110
111
112
# File 'lib/s-3po/events.rb', line 103

def is_instruction?
  return false unless plain
  withprefix = /^@#{options[:botid]}[!:;,.-]*\s+\S/
  withoutprefix = /^[^@]/
  return true if (withprefix =~ plain) == 0
  if is_im?
    return true if (withoutprefix =~ plain) == 0
  end
  return false
end

#mentionsObject


97
98
99
# File 'lib/s-3po/events.rb', line 97

def mentions
  @mentions ||= Parser.mentions_from_text(text)
end

#plainObject


86
87
88
89
# File 'lib/s-3po/events.rb', line 86

def plain
  return nil if text.nil?
  @plain ||= Parser.plain_from_text(text)
end

#plain=(string) ⇒ Object


91
92
93
94
95
# File 'lib/s-3po/events.rb', line 91

def plain=(string)
  fail 'Must be a String.' unless string.class == String
  @plain = string
  object[:text] = Generator.text_from_plain(@plain)
end

#textObject


76
77
78
# File 'lib/s-3po/events.rb', line 76

def text
  object[:text]
end

#text=(string) ⇒ Object


80
81
82
83
84
# File 'lib/s-3po/events.rb', line 80

def text=(string)
  fail 'Must be a String.' unless string.class == String
  object[:text] = string
  @plain = nil
end