Class: Butler::IRC::Message

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

Overview

IRC::User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Message

Returns a new instance of Message.



249
250
251
252
253
254
255
# File 'lib/butler/bot.rb', line 249

def initialize(*args, &block)
	butler_initialize(*args, &block)
	@language       = nil
	@invocation     = nil
	@arguments      = nil
	@post_arguments = nil
end

Instance Attribute Details

#invocationObject

the invocation-sequence (e.g. “butler, ”), nil if none was used (e.g. in private messages)



246
247
248
# File 'lib/butler/bot.rb', line 246

def invocation
  @invocation
end

#languageObject

the language of this message, as determined by butler



242
243
244
# File 'lib/butler/bot.rb', line 242

def language
  @language
end

Instance Method Details

#argumentsObject

parses a given string into argument-tokens. a token is either a word or a quoted string. escapes are respected. e.g. ‘Hallo “this is token2” “and this "token" is token3”’ would be parsed into: [“hallo”, “this is token2”, “and this "token" is token3”]



260
261
262
263
264
265
266
267
# File 'lib/butler/bot.rb', line 260

def arguments
	return [] unless text # only messages with text can be tokenized to parameters
	@arguments ||= begin # don't do double-work
		text[@invocation.length..-1].arguments
	rescue String::SingleQuoteException => ex
		ex.pre+[ex.post.join(" ")]
	end
end

#butler_initializeObject



248
# File 'lib/butler/bot.rb', line 248

alias butler_initialize initialize

#post_argumentsObject

FIXME due to it’s current working, post_arguments will strip formatting Returns the rest of message text after argument

Synopsis

"foo bar baz".post_arguments[0] # => "foo bar baz"
"foo bar baz".post_arguments[1] # => "bar baz"
"foo bar baz".post_arguments[2] # => "baz"


275
276
277
278
# File 'lib/butler/bot.rb', line 275

def post_arguments
	return [] unless text # only messages with text can be tokenized to parameters
	@post_arguments ||= text[@invocation.length..-1].post_arguments # don't do double-work
end