Class: ModSpox::Handlers::Motd

Inherits:
Handler
  • Object
show all
Defined in:
lib/mod_spox/handlers/Motd.rb

Instance Method Summary collapse

Methods inherited from Handler

#preprocess

Constructor Details

#initialize(handlers) ⇒ Motd

Returns a new instance of Motd.



5
6
7
8
9
10
11
# File 'lib/mod_spox/handlers/Motd.rb', line 5

def initialize(handlers)
    handlers[RPL_MOTDSTART] = self
    handlers[RPL_MOTD] = self
    handlers[RPL_ENDOFMOTD] = self
    @motds = Hash.new
    @raw = Hash.new
end

Instance Method Details

#process(string) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mod_spox/handlers/Motd.rb', line 12

def process(string)
    if(string =~ /^:(\S+) #{RPL_MOTDSTART.to_s}.*?:-\s?(\S+)/)
        @motds[$1] = Array.new
        @raw[$1] = [string]
        return nil
    elsif(string =~ /^:(\S+) #{RPL_MOTD.to_s}.*?:-\s?(.+)$/)
        @motds[$1] ||= []
        @raw[$1] ||= []
        @motds[$1] << $2
        @raw[$1] << string
        return nil
    elsif(string =~ /^:(\S+) #{RPL_ENDOFMOTD.to_s}/)
        @raw[$1] ||= []
        @motds[$1] ||= []
        @raw[$1] << string
        message = Messages::Incoming::Motd.new(@raw[$1].join("\n"), @motds[$1].join("\n"), $1)
        @motds.delete($1)
        @raw.delete($1)
        return message
    else
        return nil
    end
end