Class: Isaac::Message
- Inherits:
-
Object
- Object
- Isaac::Message
- Defined in:
- lib/isaac/bot.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#params ⇒ Object
Returns the value of attribute params.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
- #channel ⇒ Object
- #channel? ⇒ Boolean
- #error ⇒ Object
- #error? ⇒ Boolean
- #host ⇒ Object
-
#initialize(msg = nil) ⇒ Message
constructor
A new instance of Message.
- #message ⇒ Object
- #nick ⇒ Object
- #numeric_reply? ⇒ Boolean
- #parse ⇒ Object
- #server ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(msg = nil) ⇒ Message
Returns a new instance of Message.
204 205 206 207 |
# File 'lib/isaac/bot.rb', line 204 def initialize(msg=nil) @raw = msg parse if msg end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
202 203 204 |
# File 'lib/isaac/bot.rb', line 202 def command @command end |
#params ⇒ Object
Returns the value of attribute params.
202 203 204 |
# File 'lib/isaac/bot.rb', line 202 def params @params end |
#prefix ⇒ Object
Returns the value of attribute prefix.
202 203 204 |
# File 'lib/isaac/bot.rb', line 202 def prefix @prefix end |
#raw ⇒ Object
Returns the value of attribute raw.
202 203 204 |
# File 'lib/isaac/bot.rb', line 202 def raw @raw end |
Instance Method Details
#channel ⇒ Object
260 261 262 263 264 265 |
# File 'lib/isaac/bot.rb', line 260 def channel return @channel if @channel if regular_command? and params.first.start_with?("#") @channel = params.first end end |
#channel? ⇒ Boolean
256 257 258 |
# File 'lib/isaac/bot.rb', line 256 def channel? !!channel end |
#error ⇒ Object
251 252 253 254 |
# File 'lib/isaac/bot.rb', line 251 def error return @error if @error @error = command.to_i if numeric_reply? && command[/[45]\d\d/] end |
#error? ⇒ Boolean
247 248 249 |
# File 'lib/isaac/bot.rb', line 247 def error? !!error end |
#host ⇒ Object
236 237 238 239 |
# File 'lib/isaac/bot.rb', line 236 def host return unless @prefix @host ||= @prefix[/@(\S+)$/, 1] end |
#message ⇒ Object
267 268 269 270 271 272 273 274 |
# File 'lib/isaac/bot.rb', line 267 def return @message if @message if error? @message = error.to_s elsif regular_command? @message = params.last end end |
#nick ⇒ Object
226 227 228 229 |
# File 'lib/isaac/bot.rb', line 226 def nick return unless @prefix @nick ||= @prefix[/^(\S+)!/, 1] end |
#numeric_reply? ⇒ Boolean
209 210 211 |
# File 'lib/isaac/bot.rb', line 209 def numeric_reply? @numeric_reply ||= !!@command.match(/^\d\d\d$/) end |
#parse ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/isaac/bot.rb', line 213 def parse match = @raw.match(/(^:(\S+) )?(\S+)(.*)/) _, @prefix, @command, raw_params = match.captures raw_params.strip! if match = raw_params.match(/:(.*)/) @params = match.pre_match.split(" ") @params << match[1] else @params = raw_params.split(" ") end end |
#server ⇒ Object
241 242 243 244 245 |
# File 'lib/isaac/bot.rb', line 241 def server return unless @prefix return if @prefix.match(/[@!]/) @server ||= @prefix[/^(\S+)/, 1] end |
#user ⇒ Object
231 232 233 234 |
# File 'lib/isaac/bot.rb', line 231 def user return unless @prefix @user ||= @prefix[/^\S+!(\S+)@/, 1] end |