Class: MessageFactory::Handlers::Who

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

Instance Method Summary collapse

Constructor Details

#initializeWho

Returns a new instance of Who.



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

def initialize
    @cache = {}
end

Instance Method Details

#fetch_target(target, orig, channel = true) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/messagefactory/handlers/352.rb', line 72

def fetch_target(target, orig, channel=true)
    unless(@cache[target])
        m = mk_struct(orig)
        m.type = :who
        m.raw = []
        m.nicks = []
        if(channel)
            m.ops = []
            m.voice = []
            m.channel = target
        end
        @cache[target] = m
    end
    @cache[target]
end

#process(string) ⇒ Object

string

string to process

Create a new Who message OpenStruct will contain: #type #direction #raw #received #source #channel #message :nodoc: Nick style: :swiftco.wa.us.dal.net 352 spox * ~metallic codemunkey.net punch.va.us.dal.net metallic H :2 Sean Grimes :swiftco.wa.us.dal.net 315 spox metallic :End of /WHO list.

Channel style:

:swiftco.wa.us.dal.net 352 spox #php ~chendo 24.47.233.220.static.exetel.com.au punch.va.us.dal.net chendo H@ :2 chendo :swiftco.wa.us.dal.net 315 spox #php :End of /WHO list.



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

def process(string)
    string = string.dup
    orig = string.dup
    m = nil
    begin
        server = string.slice!(0, string.index(' '))
        string.slice!(0)
        action = string.slice!(0, string.index(' ')).to_sym
        string.slice!(0)
        string.slice!(0, string.index(' ')+1)
        if(action == :'352')
            m = who_content(string, orig)
        elsif(action == :'315')
            m = who_end(string, orig)
        else
            raise
        end
    rescue
        raise "Failed to parse Who message: #{orig}"
    end
    m
end

#types_processObject



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

def types_process
    [:'352', :'315']
end

#who_content(string, orig) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/messagefactory/handlers/352.rb', line 46

def who_content(string, orig)
    name = string.slice!(0, string.index(' '))
    string.slice!(0)
    nick = OpenStruct.new
    nick.username = string.slice!(0, string.index(' '))
    string.slice!(0)
    nick.host = string.slice!(0, string.index(' '))
    string.slice!(0)
    nick.irc_host = string.slice!(0, string.index(' '))
    string.slice!(0)
    nick.nick = string.slice!(0, string.index(' '))
    string.slice!(0)
    status = string.slice!(0, string.index(' '))
    string.slice!(0, string.index(':')+1)
    nick.hops = string.slice!(0, string.index(' ')).to_i
    string.slice!(0)
    nick.real_name = string
    target = name == '*' ? nick.nick : name
    m = fetch_target(target, orig, name != '*')
    m.nicks << nick
    m.ops.push nick if status.index('@')
    m.voice.push nick if status.index('+')
    m.raw << orig
    nil
end

#who_end(string, orig) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/messagefactory/handlers/352.rb', line 88

def who_end(string, orig)
    name = string.slice!(0, string.index(' '))
    m = @cache[name]
    if(m)
        @cache.delete(name)
        m.raw << orig
    end
    m
end