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.



216
217
218
219
220
221
222
# File 'lib/butler/bot.rb', line 216

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)



213
214
215
# File 'lib/butler/bot.rb', line 213

def invocation
  @invocation
end

#languageObject

the language of this message, as determined by butler



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

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”]



227
228
229
230
231
232
233
234
# File 'lib/butler/bot.rb', line 227

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



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

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"


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

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