Class: IRCd::ChannelMode

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/rupircd/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#channame?, #correct_nick?, #mask_to_regex

Constructor Details

#initialize(server, chname) ⇒ ChannelMode

Returns a new instance of ChannelMode.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rupircd/channel.rb', line 22

def initialize(server, chname)
  @chname = chname
  @server = server
  @bans = []
  @topic_op_only = false
  @creators = []
  @ops = []
  @invite = false
  @voices = []
  @anony = false
  @moderate = false
  @n = false
  @quiet = false
  @private = false
  @secret = false
  @reops = []
  @key = ""
  @user_max = -1
  @excepts = []
  @invite_onlys = []
end

Instance Attribute Details

#anonyObject

Returns the value of attribute anony.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def anony
  @anony
end

#bansObject

Returns the value of attribute bans.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def bans
  @bans
end

#creatorsObject

Returns the value of attribute creators.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def creators
  @creators
end

#dont_need_inviteObject

Returns the value of attribute dont_need_invite.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def dont_need_invite
  @dont_need_invite
end

#exceptsObject

Returns the value of attribute excepts.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def excepts
  @excepts
end

#inviteObject

Returns the value of attribute invite.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def invite
  @invite
end

#keyObject

Returns the value of attribute key.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def key
  @key
end

#moderateObject

Returns the value of attribute moderate.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def moderate
  @moderate
end

#nObject

Returns the value of attribute n.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def n
  @n
end

#opsObject

Returns the value of attribute ops.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def ops
  @ops
end

#privateObject

Returns the value of attribute private.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def private
  @private
end

#quietObject

Returns the value of attribute quiet.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def quiet
  @quiet
end

#reopsObject

Returns the value of attribute reops.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def reops
  @reops
end

#secretObject

Returns the value of attribute secret.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def secret
  @secret
end

#topic_op_onlyObject

Returns the value of attribute topic_op_only.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def topic_op_only
  @topic_op_only
end

#user_maxObject

Returns the value of attribute user_max.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def user_max
  @user_max
end

#voicesObject

Returns the value of attribute voices.



18
19
20
# File 'lib/rupircd/channel.rb', line 18

def voices
  @voices
end

Instance Method Details

#add_op(hoge) ⇒ Object



181
182
183
# File 'lib/rupircd/channel.rb', line 181

def add_op(hoge)
  @ops.push hoge
end

#banned?(who) ⇒ Boolean

Returns:

  • (Boolean)


210
211
212
213
214
# File 'lib/rupircd/channel.rb', line 210

def banned?(who)
  @bans.any?{|mask|
    who.to_s =~ mask
  }
end

#can_change_topic?(who) ⇒ Boolean

Returns:

  • (Boolean)


198
199
200
# File 'lib/rupircd/channel.rb', line 198

def can_change_topic?(who)
  !@topic_op_only || op?(who)
end

#can_invite?(who) ⇒ Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/rupircd/channel.rb', line 206

def can_invite?(who)
  !@invite || op?(who)
end

#can_talk?(who) ⇒ Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/rupircd/channel.rb', line 202

def can_talk?(who)
  !@moderate || op?(who) || @voices.include?(who)
end

#get_flagsObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/rupircd/channel.rb', line 162

def get_flags
  params = []
  flg = "+"
  flg << "n" if @n
  flg << "i" if @invite
  flg << "a" if @anony
  flg << "m" if @moderate
  flg << "q" if @quiet
  flg << "p" if @private
  flg << "s" if @secret
  flg << "k" unless @key.empty?
  flg << "t" if @topic_op_only
  if @user_max > -1
    flg << "l"
    params << @user_max
  end
  params.unshift flg
end

#op?(who) ⇒ Boolean

Returns:

  • (Boolean)


190
191
192
# File 'lib/rupircd/channel.rb', line 190

def op?(who)
  @ops.include?(who)
end

#set_flags(who, flags, param) ⇒ Object



44
45
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rupircd/channel.rb', line 44

def set_flags(who, flags, param)
  args = param.dup
  toggle = flags[0] == ?+
  rpl = [flags[0,1]]
  flags = flags[1..3]
  flags.each_byte{|b|
    rpl.push b.chr
    case b
    when ?n
      @n = toggle
    when ?i
      @invite = toggle
    when ?a
      @anony = toggle
    when ?m
      @moderate = toggle
    when ?p
      @secret = false if toggle
      @private = toggle
    when ?s
      @private = false if toggle
      @secret = toggle
    when ?k
      key = param.shift
      if toggle
        @key = key
      elsif key == @key
        @key = ""
      end
    when ?l
      @user_max = param.shift.to_i
    when ?r
      if toggle
        @reops << mask_to_regex(param.shift)
      else
        @reops.delete(mask_to_regex(param.shift))
      end
    when ?t
      @topic_op_only = toggle
    when ?o
      user = @server.user_from_nick(param.shift)
      if toggle
        @ops << user
        @ops.compact!
        @ops.uniq!
      else
        @ops.delete(user)
      end
    when ?v
      user = @server.user_from_nick(param.shift)
      if toggle
        @voices << user
        @voices.uniq!
        @voices.compact!
      else
        @voices.delete(user)
      end
    when ?b, ?e, ?I
      masks = param.shift
      mask_list = []
      list_msg = ""
      endof_msg = ""
      what = ""
      case b
      when ?b
        mask_list = @bans
        list_msg = "367"
        endof_msg = "368"
        what = "ban"
      when ?e
        mask_list = @excepts
        list_msg = "348"
        endof_msg = "349"
        what = "exception"
      when ?I
        mask_list = @invite_onlys
        list_msg = "346"
        endof_msg = "347"
        what = "invite"
      end
      if masks
        if toggle
          mask_list << mask_to_regex(masks)
        else
          mask_list.delete(mask_to_regex(masks))
        end
      else
        rpl.pop
        mask_list.each{|msk|
          @server.send_server_message(who, list_msg, @chname, msk)
        }
        @server.send_server_message(who, endof_msg, @chname, "End of channel #{what} list")
      end
    else
      @server.send_server_message(who, "472", rpl.pop, "is unknown mode char to me for #@chname")
    end
  }
  [rpl.join(""), args].flatten if rpl.size > 1
end

#unregister(who) ⇒ Object



185
186
187
188
# File 'lib/rupircd/channel.rb', line 185

def unregister(who)
  @ops.delete(who)
  @voices.delete(who)
end

#voiced?(who) ⇒ Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/rupircd/channel.rb', line 194

def voiced?(who)
  @voices.include?(who)
end