Class: IRC::Server::Modules::Netlog

Inherits:
IRC::Server::Module show all
Defined in:
lib/failirc/server/modules/Netlog.rb

Instance Attribute Summary

Attributes inherited from IRC::Server::Module

#server

Instance Method Summary collapse

Methods inherited from IRC::Server::Module

#finalize

Constructor Details

#initialize(server) ⇒ Netlog

Returns a new instance of Netlog.



31
32
33
34
35
36
37
38
39
# File 'lib/failirc/server/modules/Netlog.rb', line 31

def initialize (server)
    @events = {
        :custom => {
            :message => Event::Callback.new(self.method(:netlog), -101),
        }
    }

    super(server)
end

Instance Method Details

#netlog(chain, fromRef, toRef, message, level = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/failirc/server/modules/Netlog.rb', line 41

def netlog (chain, fromRef, toRef, message, level=nil)
    if chain != :input
        return
    end

    from = fromRef.value
    to   = toRef.value

    URI.extract(message).each {|uri|
        if match = uri.match('http://(beta\.)?(\w+?)\.netlog.com.*photo.*?(\d+)')
            country = match[2]
            url     = match[3]
            code    = "000000000#{url}".match(/(\d{3})(\d{3})\d{3}$/)

            message.gsub!(/#{Regexp.escape(uri)}/, "http://#{country}.netlogstatic.com/p/oo/#{code[1]}/#{code[2]}/#{url}.jpg")
        elsif match = uri.match(/netlogstatic/)
            message.gsub!(/#{Regexp.escape(uri)}/, uri.sub(/\/[to]{2}\//, '/oo/'))
        end
    }
end