Class: Weechat::IRC::Message

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

Direct Known Subclasses

CTCP, PRIVMSG

Defined Under Namespace

Classes: CTCP

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Message) initialize(line)

parses an irc message into its prefix, command and params. using Message.parse_message is normally better as it will return a more specific subclass for some types of messages



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/weechat/irc/message.rb', line 31

def initialize(line)
  @line = line

  parts = line.split(' ')

  if parts[0][0..0] == ':'
    @prefix = Prefix.new(parts.shift[1..-1])
  else
    @prefix = ''
  end

  @command = parts.shift

  @params = []
  until parts.empty? do
    if parts[0][0..0] == ':'
      @params << parts.join(' ')[1..-1]
      break
    else
      @params << parts.shift
    end
  end
end

Instance Attribute Details

- (Object) command (readonly)

Returns the value of attribute command



4
5
6
# File 'lib/weechat/irc/message.rb', line 4

def command
  @command
end

- (Object) params (readonly)

Returns the value of attribute params



4
5
6
# File 'lib/weechat/irc/message.rb', line 4

def params
  @params
end

- (Object) prefix (readonly)

Returns the value of attribute prefix



4
5
6
# File 'lib/weechat/irc/message.rb', line 4

def prefix
  @prefix
end

Class Method Details

+ (IRC::Message) parse_message(irc_message)

parses an irc message line, and returns an appropriate subclass of IRC::Message represent the message. TODO make more subclasses

Parameters:

  • irc_message (String)

    The irc message to parse

Returns:

  • (IRC::Message)

    Either the base message class or a specific message base class if one exists. Currently the only one that exists is PRIVMSG



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/weechat/irc/message.rb', line 13

def self.parse_message(irc_message)
  # todo this is a bit hacky as it parses the message twice

  result = Message.new(irc_message)
  case result.command
    when "PRIVMSG"
      PRIVMSG.new(irc_message)
    else
      result
  end




end

Instance Method Details

- (Boolean) ctcp?

Returns:



55
56
57
# File 'lib/weechat/irc/message.rb', line 55

def ctcp?
  @params.size == 2 && @params.last[0..0] == "\x01" && @params.last[-1..-1] == "\x01"
end

- (Object) to_ctcp



59
60
61
62
# File 'lib/weechat/irc/message.rb', line 59

def to_ctcp
  raise "not a ctcp" unless ctcp?
  Weechat::IRC::Message::CTCP.new(@line)
end