Class: MessageFactory::Handlers::Whois

Inherits:
Handler
  • Object
show all
Defined in:
lib/messagefactory/handlers/311.rb

Instance Method Summary collapse

Constructor Details

#initializeWhois

Returns a new instance of Whois.



7
8
9
# File 'lib/messagefactory/handlers/311.rb', line 7

def initialize
    @cache = {}
end

Instance Method Details

#clear_cacheObject



10
11
12
# File 'lib/messagefactory/handlers/311.rb', line 10

def clear_cache
    @cache.clear
end

#process(string) ⇒ Object

string

string to process

Create a new Mode message OpenStruct will contain: #type #direction #raw #received #source #target #channels #voice #ops #irc_host #idle #signon #nickserv



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/messagefactory/handlers/311.rb', line 21

def process(string)
    string = string.dup
    orig = string.dup
    m = nil
    begin
        string.slice!(0)
        server = string.slice!(0, string.index(' '))
        string.slice!(0)
        action = string.slice!(0, string.index(' '))
        raise unless types_process.include?(action.to_sym)
        string.slice!(0)
        action = ('process_'+action)
        if(self.methods.include?(action))
            m = self.send(action, string, orig)
        else
            m = store_raw(string, orig)
        end
        m.source = server if m
    rescue => boom
        raise "Failed to parse Whois message: #{orig}"
    end
    m
end

#process_307(string, orig) ⇒ Object

:swiftco.wa.us.dal.net 307 spox spox :has identified for this nick



114
115
116
117
118
119
120
121
122
# File 'lib/messagefactory/handlers/311.rb', line 114

def process_307(string, orig)
    parts = string.split
    parts.shift
    m = @cache[parts.shift]
    raise unless m
    m.nickserv = :identified
    m.raw << orig
    nil
end

#process_311(string, orig) ⇒ Object

:swiftco.wa.us.dal.net 311 spox spox ~spox pool-96-225-201-176.ptldor.dsl-w.verizon.net * :spox



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/messagefactory/handlers/311.rb', line 54

def process_311(string, orig)
    m = mk_struct(orig)
    m.raw = [orig]
    m.type = :whois
    parts = string.split
    m.target = parts[1]
    m.username = parts[2]
    m.host = parts[3]
    parts[5].slice!(0)
    m.real_name = parts[5]
    @cache[m.target] = m
    nil
end

#process_312(string, orig) ⇒ Object

:swiftco.wa.us.dal.net 312 spox spox swiftco.wa.us.dal.net :www.swiftco.net - Swift Communications



104
105
106
107
108
109
110
111
112
# File 'lib/messagefactory/handlers/311.rb', line 104

def process_312(string, orig)
    parts = string.split
    parts.shift
    m = @cache[parts.shift]
    raise unless m
    m.raw << orig
    m.irc_host = parts.shift
    nil
end

#process_317(string, orig) ⇒ Object

:swiftco.wa.us.dal.net 317 spox spox 529 1265393189 :seconds idle, signon time



93
94
95
96
97
98
99
100
101
102
# File 'lib/messagefactory/handlers/311.rb', line 93

def process_317(string, orig)
    parts = string.split
    parts.shift
    m = @cache[parts.shift]
    raise unless m
    m.raw << orig
    m.idle = parts.shift.to_i
    m.signon = parts.shift.to_i
    nil
end

#process_318(string, orig) ⇒ Object

:wolfe.freenode.net 318 spox spox :End of /WHOIS list.



128
129
130
131
132
133
134
135
136
137
# File 'lib/messagefactory/handlers/311.rb', line 128

def process_318(string, orig)
    parts = string.split
    parts.shift
    target = parts.shift
    m = @cache[target]
    raise unless m
    m.raw << orig
    @cache.delete(target)
    m
end

#process_319(string, orig) ⇒ Object

:swiftco.wa.us.dal.net 319 spox spox :+#php #ruby #mysql @#mod_spox



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/messagefactory/handlers/311.rb', line 68

def process_319(string, orig)
    parts = string.split
    parts.shift
    m = @cache[parts.shift]
    raise unless m
    m.raw << orig
    parts[0].slice!(0)
    parts.each do |chan|
        start = chan[0,1]
        case start
        when '+'
            chan.slice!(0)
            m.voice ||= []
            m.voice << chan
        when '@'
            chan.slice!(0)
            m.ops ||= []
            m.ops << chan
        end
        m.channels ||= []
        m.channels << chan
    end
    nil
end

#process_330(string, orig) ⇒ Object

:wolfe.freenode.net 330 spox spox spox :is logged in as



124
125
126
# File 'lib/messagefactory/handlers/311.rb', line 124

def process_330(string, orig)
    process_307(string, orig)
end

#store_raw(string, orig) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/messagefactory/handlers/311.rb', line 45

def store_raw(string, orig)
    parts = string.split
    m = @cache[parts[1]]
    raise unless m
    m.raw << orig
    nil
end

#types_processObject



13
14
15
# File 'lib/messagefactory/handlers/311.rb', line 13

def types_process
    [:'311', :'319', :'312', :'307', :'330', :'317', :'318', :'378']
end