Class: Twitch::Bot::Message::UserMessage
- Defined in:
- lib/twitch/bot/message/user_message.rb
Overview
This class stores the details of a user’s chat message.
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Attributes inherited from Event
Instance Method Summary collapse
- #command ⇒ Object
- #command? ⇒ Boolean
- #command_args ⇒ Object
- #command_name?(check_command) ⇒ Boolean
-
#initialize(text:, user:) ⇒ UserMessage
constructor
A new instance of UserMessage.
Constructor Details
#initialize(text:, user:) ⇒ UserMessage
Returns a new instance of UserMessage.
10 11 12 13 14 |
# File 'lib/twitch/bot/message/user_message.rb', line 10 def initialize(text:, user:) @text = text @user = user super(type: :user_message) end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
8 9 10 |
# File 'lib/twitch/bot/message/user_message.rb', line 8 def text @text end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/twitch/bot/message/user_message.rb', line 8 def user @user end |
Instance Method Details
#command ⇒ Object
24 25 26 27 28 |
# File 'lib/twitch/bot/message/user_message.rb', line 24 def command first_word&.match(/^!(\w+)/) do |match| match.captures&.first end end |
#command? ⇒ Boolean
20 21 22 |
# File 'lib/twitch/bot/message/user_message.rb', line 20 def command? !(command.nil? || command.empty?) end |
#command_args ⇒ Object
30 31 32 |
# File 'lib/twitch/bot/message/user_message.rb', line 30 def command_args text_words.tap(&:shift) end |
#command_name?(check_command) ⇒ Boolean
16 17 18 |
# File 'lib/twitch/bot/message/user_message.rb', line 16 def command_name?(check_command) command == check_command end |