Class: IRC::Object::Message
- Inherits:
-
Object
- Object
- IRC::Object::Message
- 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.
Instance Attribute Summary collapse
-
#body ⇒ Array<String>
readonly
The body of the message, divided into elements by its spaces.
- #channel ⇒ nil, IRC::Object::Channel readonly
-
#irc ⇒ IRC::Server
readonly
The server on which the message was received.
-
#nature ⇒ Symbol
readonly
The nature of the message, +:notice+ or +:msg+.
-
#sender ⇒ IRC::Object::User
readonly
The user from whom the message was received.
Instance Method Summary collapse
-
#in_channel? ⇒ true, false
Checks whether the message was received through a channel.
-
#initialize(irc, sender, body, nature = :notice, channel = nil) ⇒ Message
constructor
Process a new message.
-
#reply(msg, in_channel) ⇒ Object
Reply to this message.
Constructor Details
#initialize(irc, sender, body, nature = :notice, channel = nil) ⇒ Message
Process a new message.
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
#body ⇒ Array<String> (readonly)
Returns The body of the message, divided into elements by its spaces.
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 |
#channel ⇒ nil, IRC::Object::Channel (readonly)
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 |
#irc ⇒ IRC::Server (readonly)
Returns The server on which the message was received.
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 |
#nature ⇒ Symbol (readonly)
Returns The nature of the message, +:notice+ or +:msg+.
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 |
#sender ⇒ IRC::Object::User (readonly)
Returns The user from whom the message was received.
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.
91 |
# File 'lib/syndi/irc/object/message.rb', line 91 def in_channel?; @channel.nil?; end |
#reply(msg, in_channel) ⇒ Object
Unfinished.
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.
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 |