Method: IRC::Object::Message#body

Defined in:
lib/syndi/irc/object/message.rb,
lib/syndi/irc/object/message.rb

#bodyArray<String> (readonly)

Returns The body of the message, divided into elements by its spaces.

Returns:

  • (Array<String>)

    The body of the message, divided into elements by its spaces.

Since:

  • 4.0.0



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/syndi/irc/object/message.rb', line 33

class Message

  attr_reader :irc, :sender, :body, :nature, :channel

  # Process a new message.
  #
  # @param [IRC::Server] irc The server on which the message was received.
  # @param [IRC::Object::User] sender The user from whom the message was received.
  # @param [String] body The body of the message.
  # @param [Symbol] nature The nature of the message: either a +:notice+ or a +:msg+.
  # @param [IRC::Object::Channel] channel If it was received through a channel, the channel.
  #
  # @example
  #   message = IRC::Object::Message.new(irc, user, body, :msg, channel)
  def initialize(irc, sender, body, nature=:notice, channel=nil)

    @irc     = irc
    @sender  = sender
    @body    = body
    @nature  = nature
    @channel = channel

  end

  # Reply to this message.
  #
  # @param [String] msg The message with which to reply.
  # @param [true, false] in_channel If the response should be in-channel (assuming it was received in a channel), specify +true+.
  #   If it should be private regardless of where it was received, specify +false+.
  #
  # @note Essentially reply() exists to simplify the API. 
  #   Rather than necessitating that commands use endless, illegible conditional
  #   nests to determine what to do, reply() is available so the API will just
  #   use some common sense to do it for them.
  #
  # @example
  #   msg.reply("The bar is of foo, indeed.", true)
  #
  # @todo Unfinished.
  def reply(msg, in_channel)
    
    case [@channel.nil, in_channel, @nature]
    
    # Respond in-channel if this was sent to a channel *and* in_channel
    # is specified as true.
    when false, true, :msg
      irc.msg(@channel, msg)

    # Likewise for channel notices. 
    when false, true, :notice
      
    end

  end

  # Checks whether the message was received through a channel.
  #
  # @return [true, false]
  def in_channel?; @channel.nil?; end

end