Class: Sponge::IRC::Message

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#channelObject

Channel the message is for



31
32
33
# File 'lib/sponge/irc/message.rb', line 31

def channel
  @channel
end

#clientObject (readonly)

Our IRC::Client



16
17
18
# File 'lib/sponge/irc/message.rb', line 16

def client
  @client
end

#commandObject (readonly)

The IRC Command (PRIVMSG, MODE, 376, 372, etc)



28
29
30
# File 'lib/sponge/irc/message.rb', line 28

def command
  @command
end

#forObject

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

#fromObject

The IRC::User this message is from



37
38
39
# File 'lib/sponge/irc/message.rb', line 37

def from
  @from
end

#ircObject (readonly)

Our IRC::Socket instance



19
20
21
# File 'lib/sponge/irc/message.rb', line 19

def irc
  @irc
end

#nickObject

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

#paramsObject (readonly)

All params



46
47
48
# File 'lib/sponge/irc/message.rb', line 46

def params
  @params
end

#prefixObject (readonly)

The message prefix passed from IRC::Parser



25
26
27
# File 'lib/sponge/irc/message.rb', line 25

def prefix
  @prefix
end

#rawObject (readonly)

The raw IRC string received from the server



22
23
24
# File 'lib/sponge/irc/message.rb', line 22

def raw
  @raw
end

#textObject

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(message)
  return unless nick && channel
  @irc.privmsg(channel, [nick, message].join(': '))
end

#private?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/sponge/irc/message.rb', line 68

def private?
  @channel
end

#public?Boolean

Returns:

  • (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(message)
  who = channel || from
  @irc.privmsg(who, message)
end