Class: ModSpox::Models::Channel

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

Overview

Attributes provided by model:

name

Channel name

password

Channel password

autojoin

Set bot to autojoin this channel

topic

Channel topic

quiet

Silence the bot in this channel

parked

Bot is currently in this channel

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.filter(args) ⇒ Object



31
32
33
34
# File 'lib/mod_spox/models/Channel.rb', line 31

def Channel.filter(args)
    args[:name].downcase! if args[:name]
    super(args)
end

.find_or_create(args) ⇒ Object



26
27
28
29
# File 'lib/mod_spox/models/Channel.rb', line 26

def Channel.find_or_create(args)
    args[:name].downcase! if args[:name]
    super(args)
end

.locate(string, create = true) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/mod_spox/models/Channel.rb', line 36

def Channel.locate(string, create = true)
    string.downcase!
    chan = Channel.filter(:name => string).first
    if(!chan && create)
        chan = Channel.find_or_create(:name => string)
    end
    return chan
end

Instance Method Details

#add_nick(n) ⇒ Object



74
75
76
77
78
# File 'lib/mod_spox/models/Channel.rb', line 74

def add_nick(n)
    unless(nicks_dataset.filter(:nick_id => n.pk).count > 0)
        super(n)
    end
end

#clear_modesObject



65
66
67
# File 'lib/mod_spox/models/Channel.rb', line 65

def clear_modes
    update(:mode => '')
end

#clear_nicksObject

Removes all nicks from this channel



70
71
72
# File 'lib/mod_spox/models/Channel.rb', line 70

def clear_nicks
    remove_all_nicks
end

#name=(chan_name) ⇒ Object

chan_name

string

set channel name after downcase



21
22
23
24
# File 'lib/mod_spox/models/Channel.rb', line 21

def name=(chan_name)
    chan_name.downcase!
    super(chan_name)
end

#remove_nick(n) ⇒ Object



80
81
82
83
84
# File 'lib/mod_spox/models/Channel.rb', line 80

def remove_nick(n)
    if(nicks_dataset.filter(:nick_id => n.pk).count > 0)
        super(n)
    end
end

#set?(m) ⇒ Boolean

m

single character mode

returns if mode is currently set for channel

Returns:

  • (Boolean)


48
49
50
# File 'lib/mod_spox/models/Channel.rb', line 48

def set?(m)
    return mode.nil? ? false : !mode.index(m).nil?
end

#set_mode(m) ⇒ Object

m

single character mode

set a mode for the channel TODO: add some type checks



55
56
57
# File 'lib/mod_spox/models/Channel.rb', line 55

def set_mode(m)
    update(:mode => "#{values[:mode]}#{m}") if values[:mode].nil? || values[:mode].index(m).nil?
end

#unset_mode(m) ⇒ Object

m

single character mode

unset a mode for the channel



61
62
63
# File 'lib/mod_spox/models/Channel.rb', line 61

def unset_mode(m)
    update(:mode => values[:mode].gsub(m, ''))
end