Class: Sponge::IRC::Message
- Inherits:
-
Object
- Object
- Sponge::IRC::Message
- Defined in:
- lib/sponge/irc/message.rb
Overview
Author
-
Lee Jarvis
Description
This class should only be used by IRC::Parser
Synopsis
Instance Attribute Summary collapse
-
#channel ⇒ Object
Channel the message is for.
-
#client ⇒ Object
readonly
Our IRC::Client.
-
#command ⇒ Object
readonly
The IRC Command (PRIVMSG, MODE, 376, 372, etc).
-
#for ⇒ Object
The channel or the client name (if it’s a private message).
-
#from ⇒ Object
The IRC::User this message is from.
-
#irc ⇒ Object
readonly
Our IRC::Socket instance.
-
#nick ⇒ Object
The nick the message is from (sugar for IRC::User#nick).
-
#params ⇒ Object
readonly
All params.
-
#prefix ⇒ Object
readonly
The message prefix passed from IRC::Parser.
-
#raw ⇒ Object
readonly
The raw IRC string received from the server.
-
#text ⇒ Object
Message text.
Instance Method Summary collapse
-
#answer(message) ⇒ Object
Reply to a user with their nickname prefix’d.
-
#initialize(client, raw, prefix, command, params) ⇒ Message
constructor
A new instance of Message.
- #private? ⇒ Boolean
- #public? ⇒ Boolean
-
#reply(message) ⇒ Object
Reply to a message with a PRIVMSG back to the sender (channel or nick).
Constructor Details
#initialize(client, raw, prefix, command, params) ⇒ Message
Returns a new instance of Message.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sponge/irc/message.rb', line 48 def initialize(client, raw, prefix, command, params) @client = client @irc = client.irc @raw = raw @prefix = prefix @command = command @params = [] params.scan(/(?!:)(\S+)|:(.*)/) { @params << ($1 || $2) } if params @channel = nil @for = nil @from = nil @nick = nil end |
Instance Attribute Details
#channel ⇒ Object
Channel the message is for
31 32 33 |
# File 'lib/sponge/irc/message.rb', line 31 def channel @channel end |
#client ⇒ Object (readonly)
Our IRC::Client
16 17 18 |
# File 'lib/sponge/irc/message.rb', line 16 def client @client end |
#command ⇒ Object (readonly)
The IRC Command (PRIVMSG, MODE, 376, 372, etc)
28 29 30 |
# File 'lib/sponge/irc/message.rb', line 28 def command @command end |
#for ⇒ Object
The channel or the client name (if it’s a private message)
34 35 36 |
# File 'lib/sponge/irc/message.rb', line 34 def for @for end |
#from ⇒ Object
The IRC::User this message is from
37 38 39 |
# File 'lib/sponge/irc/message.rb', line 37 def from @from end |
#irc ⇒ Object (readonly)
Our IRC::Socket instance
19 20 21 |
# File 'lib/sponge/irc/message.rb', line 19 def irc @irc end |
#nick ⇒ Object
The nick the message is from (sugar for IRC::User#nick)
40 41 42 |
# File 'lib/sponge/irc/message.rb', line 40 def nick @nick end |
#params ⇒ Object (readonly)
All params
46 47 48 |
# File 'lib/sponge/irc/message.rb', line 46 def params @params end |
#prefix ⇒ Object (readonly)
The message prefix passed from IRC::Parser
25 26 27 |
# File 'lib/sponge/irc/message.rb', line 25 def prefix @prefix end |
#raw ⇒ Object (readonly)
The raw IRC string received from the server
22 23 24 |
# File 'lib/sponge/irc/message.rb', line 22 def raw @raw end |
#text ⇒ Object
Message text
43 44 45 |
# File 'lib/sponge/irc/message.rb', line 43 def text @text end |
Instance Method Details
#answer(message) ⇒ Object
Reply to a user with their nickname prefix’d
83 84 85 86 |
# File 'lib/sponge/irc/message.rb', line 83 def answer() return unless nick && channel @irc.privmsg(channel, [nick, ].join(': ')) end |
#private? ⇒ Boolean
68 69 70 |
# File 'lib/sponge/irc/message.rb', line 68 def private? @channel end |
#public? ⇒ Boolean
72 73 74 |
# File 'lib/sponge/irc/message.rb', line 72 def public? !@channel end |
#reply(message) ⇒ Object
Reply to a message with a PRIVMSG back to the sender (channel or nick)
77 78 79 80 |
# File 'lib/sponge/irc/message.rb', line 77 def reply() who = channel || from @irc.privmsg(who, ) end |