Class: IRC::Object::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/syndi/irc/object/message.rb

Overview

A class which represents an IRC message, its associated properties, and offers methods for working with the message.

Since:

  • 4.0.0

API:

  • IRC

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(irc, sender, body, nature = :notice, channel = nil) ⇒ Message

Process a new message.

Examples:

message = IRC::Object::Message.new(irc, user, body, :msg, channel)

Parameters:

  • The server on which the message was received.

  • The user from whom the message was received.

  • The body of the message.

  • (defaults to: :notice)

    The nature of the message: either a :notice or a :msg.

  • (defaults to: nil)

    If it was received through a channel, the channel.

Since:

  • 4.0.0

API:

  • IRC



47
48
49
50
51
52
53
54
55
# File 'lib/syndi/irc/object/message.rb', line 47

def initialize(irc, sender, body, nature=:notice, channel=nil)

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

end

Instance Attribute Details

#bodyArray<String> (readonly)

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

Returns:

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

Since:

  • 4.0.0

API:

  • IRC



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

#channelnil, IRC::Object::Channel (readonly)

Returns:

  • If this message was received privately and not through a channel, this is nil.

  • If it was received through a channel, the channel in question.

See Also:

Since:

  • 4.0.0

API:

  • IRC



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

#ircIRC::Server (readonly)

Returns The server on which the message was received.

Returns:

  • The server on which the message was received.

Since:

  • 4.0.0

API:

  • IRC



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

#natureSymbol (readonly)

Returns The nature of the message, :notice or :msg.

Returns:

  • The nature of the message, :notice or :msg.

Since:

  • 4.0.0

API:

  • IRC



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

#senderIRC::Object::User (readonly)

Returns The user from whom the message was received.

Returns:

  • The user from whom the message was received.

Since:

  • 4.0.0

API:

  • IRC



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

Instance Method Details

#in_channel?true, false

Checks whether the message was received through a channel.

Returns:

Since:

  • 4.0.0

API:

  • IRC



91
# File 'lib/syndi/irc/object/message.rb', line 91

def in_channel?; @channel.nil?; end

#reply(msg, in_channel) ⇒ Object

TODO:

Unfinished.

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.

Reply to this message.

Examples:

msg.reply("The bar is of foo, indeed.", true)

Parameters:

  • The message with which to reply.

  • 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.

Since:

  • 4.0.0

API:

  • IRC



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/syndi/irc/object/message.rb', line 72

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