Class: Isaac::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/isaac/bot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commandObject

Returns the value of attribute command.



202
203
204
# File 'lib/isaac/bot.rb', line 202

def command
  @command
end

#paramsObject

Returns the value of attribute params.



202
203
204
# File 'lib/isaac/bot.rb', line 202

def params
  @params
end

#prefixObject

Returns the value of attribute prefix.



202
203
204
# File 'lib/isaac/bot.rb', line 202

def prefix
  @prefix
end

#rawObject

Returns the value of attribute raw.



202
203
204
# File 'lib/isaac/bot.rb', line 202

def raw
  @raw
end

Instance Method Details

#channelObject



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

Returns:

  • (Boolean)


256
257
258
# File 'lib/isaac/bot.rb', line 256

def channel?
  !!channel
end

#errorObject



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

Returns:

  • (Boolean)


247
248
249
# File 'lib/isaac/bot.rb', line 247

def error?
  !!error
end

#hostObject



236
237
238
239
# File 'lib/isaac/bot.rb', line 236

def host
  return unless @prefix
  @host ||= @prefix[/@(\S+)$/, 1]
end

#messageObject



267
268
269
270
271
272
273
274
# File 'lib/isaac/bot.rb', line 267

def message
  return @message if @message
  if error?
    @message = error.to_s
  elsif regular_command?
    @message = params.last
  end
end

#nickObject



226
227
228
229
# File 'lib/isaac/bot.rb', line 226

def nick
  return unless @prefix
  @nick ||= @prefix[/^(\S+)!/, 1]
end

#numeric_reply?Boolean

Returns:

  • (Boolean)


209
210
211
# File 'lib/isaac/bot.rb', line 209

def numeric_reply?
  @numeric_reply ||= !!@command.match(/^\d\d\d$/)
end

#parseObject



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

#serverObject



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

#userObject



231
232
233
234
# File 'lib/isaac/bot.rb', line 231

def user
  return unless @prefix
  @user ||= @prefix[/^\S+!(\S+)@/, 1]
end