Class: Twitch::Message
- Inherits:
-
Object
- Object
- Twitch::Message
- Defined in:
- lib/twitch_chatter/models/message.rb
Overview
Constant Summary collapse
- USERNAME =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Username regexp
/[a-zA-Z0-9_]{4,25}/
- LINK =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Link regexp
%r{(https?://[^\s]+)}
Instance Attribute Summary collapse
-
#channel ⇒ Channel
(also: #streamer)
readonly
Channel the message was sent to.
-
#content ⇒ String
(also: #text)
readonly
Content of the message.
-
#raw ⇒ String
readonly
Raw message from Twitch.
-
#sender ⇒ Channel
(also: #user)
readonly
Sender of the message.
Instance Method Summary collapse
-
#initialize(raw, bot: nil) ⇒ Message
constructor
A new instance of Message.
-
#links ⇒ Array<String>
List of links mentioned in the message.
-
#mentions ⇒ Array<Twitch::Channel>
List of usernames mentioned in the message.
Constructor Details
#initialize(raw, bot: nil) ⇒ Message
Returns a new instance of Message.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/twitch_chatter/models/message.rb', line 24 def initialize(raw, bot: nil) split = raw.split(" ") content = split[3..-1].join(" ")[1..-1] @content = content @bot = bot @channel = Channel.new(split[2][1..-1], bot: bot) @sender = Channel.new(split[0].split("!")[0][1..-1], bot: bot) @raw = raw end |
Instance Attribute Details
#channel ⇒ Channel (readonly) Also known as: streamer
Returns Channel the message was sent to.
14 15 16 |
# File 'lib/twitch_chatter/models/message.rb', line 14 def channel @channel end |
#content ⇒ String (readonly) Also known as: text
Returns Content of the message.
16 17 18 |
# File 'lib/twitch_chatter/models/message.rb', line 16 def content @content end |
#raw ⇒ String (readonly)
Returns Raw message from Twitch.
18 19 20 |
# File 'lib/twitch_chatter/models/message.rb', line 18 def raw @raw end |
#sender ⇒ Channel (readonly) Also known as: user
Returns Sender of the message.
12 13 14 |
# File 'lib/twitch_chatter/models/message.rb', line 12 def sender @sender end |
Instance Method Details
#links ⇒ Array<String>
Returns List of links mentioned in the message.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/twitch_chatter/models/message.rb', line 67 def links return @links if @links @links = [] @content.split(" ").each do |word| match = word.match(LINK) next unless match @links << match[0] end @links end |
#mentions ⇒ Array<Twitch::Channel>
Returns List of usernames mentioned in the message.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/twitch_chatter/models/message.rb', line 43 def mentions return @mentions if @mentions @mentions = [] @content.split(" ").each do |word| match = word.match(/@#{USERNAME}/) next unless match @mentions << Channel.new(match[0][1..-1], bot: @bot) end @mentions end |