Class: ModSpox::Models::Nick

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

Overview

TODO: for nick field -> “tack a COLLATE NOCASE onto the columns”

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cleanObject

Purge all nick information



133
134
135
136
137
138
139
# File 'lib/mod_spox/models/Nick.rb', line 133

def self.clean
    Nick.set(:username => nil, :real_name => nil, :address => nil,
                       :source => nil, :connected_at => nil, :connected_to => nil,
                       :seconds_idle => nil, :away => false, :visible => false, :botnick => false)
    NickMode.destroy_all
    Auth.set(:authed => false)
end

.locate(string, create = true) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/mod_spox/models/Nick.rb', line 21

def Nick.locate(string, create = true)
    nick = nil
    if(Database.type == :pgsql)
        nick = Nick.filter('nick = lower(?)', string).first
    end
    nick = Nick.find_or_create(:nick => string) if !nick && create
    return nick
end

Instance Method Details

#authObject

Auth model associated with nick



50
51
52
# File 'lib/mod_spox/models/Nick.rb', line 50

def auth
    Auth.find_or_create(:nick_id => pk)
end

#auth_groupsObject

AuthGroups nick is authed to



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/mod_spox/models/Nick.rb', line 55

def auth_groups
    groups = []
    auth_ids = []
    group_ids = []
    auth = Auth.filter('nick_id = ?', pk).filter('authed = ?', true).first
    if(auth)
        groups = auth.groups
    end
    Auth.where('mask is not null').each do |a|
        Logger.log("Matching AUTH against #{a.mask}", 30)
        if(source =~ /#{a.mask}/)
            auth_ids << a.pk
        end
    end
    auth_ids.each{|id| AuthGroup.filter(:auth_id => id).each{|ag| group_ids << ag.group_id}}
    group_ids.each{|id| groups << Group[id]}
    groups.uniq!
    return groups
end

#channel_add(channel) ⇒ Object

Add channel nick is found in



91
92
93
# File 'lib/mod_spox/models/Nick.rb', line 91

def channel_add(channel)
    NickChannel.find_or_create(:nick_id => pk, :channel_id => channel.pk)
end

#channel_remove(channel) ⇒ Object

Remove channel nick is no longer found in



96
97
98
# File 'lib/mod_spox/models/Nick.rb', line 96

def channel_remove(channel)
    NickChannel.filter(:nick_id => pk, :channel_id => channel.pk).first.destroy
end

#channelsObject

Channels nick is currently in



106
107
108
109
110
111
112
# File 'lib/mod_spox/models/Nick.rb', line 106

def channels
    chans = []
    NickChannel.filter(:nick_id => pk).each do |nc|
        chans << nc.channel
    end
    return chans
end

#clear_channelsObject

Remove all channels



101
102
103
# File 'lib/mod_spox/models/Nick.rb', line 101

def clear_channels
    NickChannel.filter(:nick_id => pk).each{|o|o.destroy}
end

#group=(group) ⇒ Object

Set nick as member of given group



76
77
78
# File 'lib/mod_spox/models/Nick.rb', line 76

def group=(group)
    auth.group = group
end

#is_op?(channel) ⇒ Boolean

channel

Models::Channel

Return if nick is operator in given channel



116
117
118
119
120
121
# File 'lib/mod_spox/models/Nick.rb', line 116

def is_op?(channel)
    NickMode.filter(:channel_id => channel.pk, :nick_id => pk).each do |mode|
        return true if mode.mode == 'o'
    end
    return false
end

#is_voice?(channel) ⇒ Boolean

channel

Models::Channel

Return if nick is voiced in given channel



125
126
127
128
129
130
# File 'lib/mod_spox/models/Nick.rb', line 125

def is_voice?(channel)
    NickMode.filter(:channel_id => channel.pk, :nick_id => pk).each do |mode|
        return true if mode.mode == 'v'
    end
    return false
end

#nick_modesObject

Modes associated with this nick



86
87
88
# File 'lib/mod_spox/models/Nick.rb', line 86

def nick_modes
    NickMode.filter(:nick_id => pk)
end

#remove_group(group) ⇒ Object

Remove nick from given group



81
82
83
# File 'lib/mod_spox/models/Nick.rb', line 81

def remove_group(group)
    auth.remove_group(group)
end

#source=(mask) ⇒ Object



44
45
46
47
# File 'lib/mod_spox/models/Nick.rb', line 44

def source=(mask)
    update_values :source => mask
    auth.check_mask(mask)
end

#visible=(val) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mod_spox/models/Nick.rb', line 30

def visible=(val)
    unless(val)
        update_with_params :username => nil
        update_with_params :real_name => nil
        update_with_params :address => nil
        update_with_params :source => nil
        update_with_params :connected_at => nil
        update_with_params :connected_to => nil
        update_with_params :seconds_idle => nil
        update_with_params :away => false
    end
    update_values :visible => val
end