Class: Twitch::Bot::IrcMessage
- Inherits:
-
Object
- Object
- Twitch::Bot::IrcMessage
- Defined in:
- lib/twitch/bot/irc_message.rb
Overview
This class splits an IRC message into its basic parts. see ircv3.net/specs/extensions/message-tags.html#format
rubocop:disable Layout/LineLength <message> ::= [‘@’ <tags> <SPACE>] [‘:’ <prefix> <SPACE> ] <command> <params> <crlf> rubocop:enable Layout/LineLength
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#channel ⇒ Object
Not really a :reek:NilCheck.
- #error ⇒ Object
- #error? ⇒ Boolean
-
#initialize(msg) ⇒ IrcMessage
constructor
A new instance of IrcMessage.
- #target ⇒ Object
- #text ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(msg) ⇒ IrcMessage
Returns a new instance of IrcMessage.
102 103 104 105 106 107 108 109 |
# File 'lib/twitch/bot/irc_message.rb', line 102 def initialize(msg) , @prefix, @command, raw_params = msg.match( /^(?:@(\S+) )?(?::(\S+) )?(\S+)(.*)/, ).captures = IrcMessageTags.new() @params = IrcMessageParams.new(raw_params).params end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
100 101 102 |
# File 'lib/twitch/bot/irc_message.rb', line 100 def command @command end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
100 101 102 |
# File 'lib/twitch/bot/irc_message.rb', line 100 def params @params end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
100 101 102 |
# File 'lib/twitch/bot/irc_message.rb', line 100 def prefix @prefix end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
100 101 102 |
# File 'lib/twitch/bot/irc_message.rb', line 100 def end |
Instance Method Details
#channel ⇒ Object
Not really a :reek:NilCheck
138 139 140 |
# File 'lib/twitch/bot/irc_message.rb', line 138 def channel params.detect { |param| param.start_with?("#") }&.delete("#") end |
#error ⇒ Object
111 112 113 |
# File 'lib/twitch/bot/irc_message.rb', line 111 def error command[/[45]\d\d/] ? command.to_i : 0 end |
#error? ⇒ Boolean
115 116 117 |
# File 'lib/twitch/bot/irc_message.rb', line 115 def error? error.positive? end |
#target ⇒ Object
119 120 121 |
# File 'lib/twitch/bot/irc_message.rb', line 119 def target channel || user end |
#text ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/twitch/bot/irc_message.rb', line 123 def text if error? error.to_s else params.last end end |
#user ⇒ Object
131 132 133 134 135 |
# File 'lib/twitch/bot/irc_message.rb', line 131 def user return unless prefix prefix[/^(\S+)!/, 1] end |