Class: ModSpox::Handlers::Nick

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

Instance Method Summary collapse

Methods inherited from Handler

#preprocess

Constructor Details

#initialize(handlers) ⇒ Nick

Returns a new instance of Nick.



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

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

Instance Method Details

#process(string) ⇒ Object

:[email protected] NICK :flock_of_deer



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mod_spox/handlers/Nick.rb', line 9

def process(string)
    orig = string.dup
    string = string.dup
    begin
        string.slice!(0)
        old_nick = find_model(string.slice!(0..string.index('!')-1))
        string.slice!(0..string.index(':'))
        new_nick = find_model(string)
        old_nick.channels.each do |channel|
            channel.remove_nick(old_nick)
            channel.add_nick(new_nick)
            m = Models::NickMode.filter(:nick_id => old_nick.pk, :channel_id => channel.pk).first
            if(m)
                m.nick_id = new_nick.pk
                m.save
            end
        end
        new_nick.username = old_nick.username
        new_nick.address = old_nick.address
        new_nick.real_name = old_nick.real_name
        new_nick.connected_to = old_nick.connected_to
        new_nick.away = old_nick.away
        new_nick.visible = true
        new_nick.save_changes
        old_nick.visible = false
        old_nick.remove_all_channels
        if(old_nick.botnick == true)
            old_nick.botnick = false
            new_nick.botnick = true
        end
        new_nick.save
        old_nick.save
        return Messages::Incoming::Nick.new(orig, old_nick, new_nick)
    rescue Object => boom
        Logger.error("Failed to parse NICK message: #{orig}")
        raise boom
    end
end