Class: ModSpox::Handlers::Notice

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

Instance Method Summary collapse

Methods inherited from Handler

#preprocess

Constructor Details

#initialize(handlers) ⇒ Notice

Returns a new instance of Notice.



5
6
7
# File 'lib/mod_spox/handlers/Notice.rb', line 5

def initialize(handlers)
    handlers[:NOTICE] = self
end

Instance Method Details

#process(string) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mod_spox/handlers/Notice.rb', line 9

def process(string)
    if(string =~ /:(\S+)\sNOTICE\s(\S+)\s:(.+)$/)
        base_source = $1
        target = $2
        message = $3
        if(base_source =~ /\!/)
            source = find_model(base_source.gsub(/!.+$/, ''))
            if(base_source =~ /!(.+)@(.+)$/)
                source.username == $1
                source.address = $2
                source.source = base_source
                source.save_changes
            end
            target = find_model(target)
        else
            source = base_source
        end
        return Messages::Incoming::Notice.new(string, source, target, message)
    else
        Logger.warn('Failed to match NOTICE message')
        return nil
    end
end