Class: Twitch::Bot::Message::UserMessage

Inherits:
Base
  • Object
show all
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

Attributes inherited from Event

#type

Instance Method Summary collapse

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

#textObject (readonly)

Returns the value of attribute text.



8
9
10
# File 'lib/twitch/bot/message/user_message.rb', line 8

def text
  @text
end

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

#commandObject



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

Returns:



20
21
22
# File 'lib/twitch/bot/message/user_message.rb', line 20

def command?
  !(command.nil? || command.empty?)
end

#command_argsObject



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

Returns:



16
17
18
# File 'lib/twitch/bot/message/user_message.rb', line 16

def command_name?(check_command)
  command == check_command
end