Class: ModSpox::Handlers::Privmsg

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

Instance Method Summary collapse

Constructor Details

#initialize(handlers) ⇒ Privmsg

Returns a new instance of Privmsg.



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

def initialize(handlers)
    handlers[:PRIVMSG] = 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
# File 'lib/mod_spox/handlers/Privmsg.rb', line 9

def process(string)
    if(string =~ /^:(\S+)\sPRIVMSG\s(\S+)\s:(.+)$/)
        message = $3
        target = find_model($2)
        base_source = $1
        source = find_model(base_source.gsub(/!.+$/, ''))
        if(base_source =~ /!(.+)@(.+)$/)
            source.username == $1
            source.address = $2
            source.source = base_source
            source.save_changes
        end
        Models::NickChannel.find_or_create(:channel_id => target.pk, :nick_id => source.pk) if target.is_a?(ModSpox::Models::Channel)
        return Messages::Incoming::Privmsg.new(string, source, target, message)
    else
        Logger.log('Failed to match PRIVMSG message')
        return nil
    end
end