Class: ModSpox::Models::Nick

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

Overview

Attributes provided by model:

nick

nick string

username

username of the user

real_name

real name of the user

address

ip of the user

host

hostname/ip of the user

source

full source string of the user

connected_at

time user connected

connected_to

server user connected to

seconds_idle

seconds user has been idle

visible

can the bot see the user (is in a channel the bot is parked)

away

is nick away

botnick

is the nick of the bot

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.filter(args) ⇒ Object



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

def Nick.filter(args)
    args[:nick].downcase! if args[:nick]
    super(args)
end

.find_or_create(args) ⇒ Object



39
40
41
42
# File 'lib/mod_spox/models/Nick.rb', line 39

def Nick.find_or_create(args)
    args[:nick].downcase! if args[:nick]
    super(args)
end

.locate(string, create = true) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/mod_spox/models/Nick.rb', line 49

def Nick.locate(string, create = true)
    nick = nil
    string.downcase!
    nick = Nick.filter(:nick => string).first
    if(!nick && create)
        nick = Nick.find_or_create(:nick => string)
    end
    return nick
end

.transfer_groups(old_nick, new_nick) ⇒ Object

TODO: rewrite this to work



189
190
191
# File 'lib/mod_spox/models/Nick.rb', line 189

def Nick.transfer_groups(old_nick, new_nick)
    # do nothing
end

Instance Method Details

#add_channel(c) ⇒ Object



176
177
178
179
180
# File 'lib/mod_spox/models/Nick.rb', line 176

def add_channel(c)
    unless(channels_dataset.filter(:channel_id => c.pk).count > 0)
        super(c)
    end
end

#address=(addr) ⇒ Object

addr: users address make sure everything is set properly when the address is set



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mod_spox/models/Nick.rb', line 62

def address=(addr)
    return if (!values[:address].nil? && !values[:host].nil?) && (values[:address] == addr || values[:host] == addr)
    oldaddress = values[:address]
    begin
        info =  Object::Socket.getaddrinfo(address, nil)
        addr = info[0][3]
        update :host => info[0][2]
        super(addr)
    rescue Object => boom
        super(addr)
        update :host => address
    ensure
        if values[:address] != oldaddress
            auth.update(:authed => false)
        end
    end
end

#authObject

Auth model associated with nick



100
101
102
103
104
105
106
107
# File 'lib/mod_spox/models/Nick.rb', line 100

def auth
    if(auths.empty?)
        a = Auth.find_or_create(:nick_id => pk)
        add_auth(a)
    end
    auths[0].refresh
    return auths[0]
end

#auth_groupsObject

AuthGroups nick is authed to



110
111
112
113
114
115
116
# File 'lib/mod_spox/models/Nick.rb', line 110

def auth_groups
    g = (auth.groups.empty? || !auth.authed) ? [] : auth.groups
    unless(auth_masks.empty?)
        auth_masks.each{|am| g += am.groups}
    end
    return g
end

#check_masksObject

Checks nick’s source against available authentication masks



120
121
122
123
124
# File 'lib/mod_spox/models/Nick.rb', line 120

def check_masks
    AuthMask.all.each do |am|
        add_auth_mask(am) if source =~ /#{am.mask}/ && !auth_masks.include?(am)
    end
end

#clear_channelsObject

Remove all channels



139
140
141
142
# File 'lib/mod_spox/models/Nick.rb', line 139

def clear_channels
    remove_all_channels
    visible = false
end

#in_group?(group) ⇒ Boolean

group

Models::Group

Return if nick is member of given group

Returns:

  • (Boolean)


128
129
130
131
# File 'lib/mod_spox/models/Nick.rb', line 128

def in_group?(group)
    group = Group.filter(:name => group).first if group.is_a?(String)
    return group.nil? ? false : auth_groups.include?(group)
end

#is_op?(channel) ⇒ Boolean

channel

Models::Channel

Return if nick is operator in given channel

Returns:

  • (Boolean)

Raises:



146
147
148
149
150
# File 'lib/mod_spox/models/Nick.rb', line 146

def is_op?(channel)
    raise Exceptions::NotInChannel.new(channel) unless channels_dataset.filter(:channel_id => channel.pk).count > 0
    m = NickMode.filter(:nick_id => pk, :channel_id => channel.pk).first
    return m ? m.set?('o') : false
end

#is_voice?(channel) ⇒ Boolean

channel

Models::Channel

Return if nick is voiced in given channel

Returns:

  • (Boolean)

Raises:



154
155
156
157
158
# File 'lib/mod_spox/models/Nick.rb', line 154

def is_voice?(channel)
    raise Exceptions::NotInChannel.new(channel) unless channels_dataset.filter(:channel_id => channel.pk).count > 0
    m = NickMode.filter(:nick_id => pk, :channel_id => channel.pk).first
    return m ? m.set?('v') : false
end

#mode_set?(m) ⇒ Boolean

Returns:

  • (Boolean)


172
173
174
# File 'lib/mod_spox/models/Nick.rb', line 172

def mode_set?(m)
    return !mode.index(m).nil?
end

#nick=(nick_name) ⇒ Object

nick_name

nick of user

override to downcase nick



34
35
36
37
# File 'lib/mod_spox/models/Nick.rb', line 34

def nick=(nick_name)
    nick_name.downcase!
    super(nick_name)
end

#nick_modesObject

Modes associated with this nick



134
135
136
# File 'lib/mod_spox/models/Nick.rb', line 134

def nick_modes
    modes
end

#remove_channel(c) ⇒ Object



182
183
184
185
186
# File 'lib/mod_spox/models/Nick.rb', line 182

def remove_channel(c)
    if(channels_dataset.filter(:channel_id => c.pk).count > 0)
        super(c)
    end
end

#set_mode(m) ⇒ Object



160
161
162
163
164
# File 'lib/mod_spox/models/Nick.rb', line 160

def set_mode(m)
    m.each_char do |c|
        update(:mode => "#{mode}#{c}") if mode.index(c).nil?
    end
end

#unset_mode(m) ⇒ Object



166
167
168
169
170
# File 'lib/mod_spox/models/Nick.rb', line 166

def unset_mode(m)
    m.each_char do |c|
        update(:mode => mode.gsub(c,'')) unless mode.index(c).nil?
    end
end

#visible=(val) ⇒ Object

val

bool

sets if nick is currently visible. if not all relating information is cleared



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/mod_spox/models/Nick.rb', line 83

def visible=(val)
    unless(val)
        update :username => nil
        update :real_name => nil
        update :address => nil
        update :source => nil
        update :connected_at => nil
        update :connected_to => nil
        update :seconds_idle => nil
        update :away => false
        remove_all_channels
        auth.update(:authed => false)
    end
    super(val)
end