Class: Cinch::Channel
- Inherits:
-
Target
- Object
- Target
- Cinch::Channel
- Includes:
- Helpers, Syncable
- Defined in:
- lib/cinch/channel.rb
Overview
Instance Attribute Summary (collapse)
-
- (Array<Ban>) bans
readonly
All active bans.
-
- (Boolean) invite_only
(also: #invite_only?)
True if the channel is invite only (+i).
-
- (String?) key
The channel’s key (aka password).
-
- (Integer) limit
The maximum number of allowed users in the channel.
-
- (Boolean) moderated
(also: #moderated?)
True if the channel is moderated.
-
- (Hash{String => Object}) modes
readonly
This attribute describes all modes set in the channel.
-
- (Array<User>) owners
readonly
All channel owners.
-
- (Boolean) secret
(also: #secret?)
True if the channel is secret (+s).
-
- (String) topic
The channel’s topic.
-
- (Hash{User => Array<String}>) users
readonly
Users are represented by a Hash, mapping individual users to an array of modes (e.g. “o” for opped).
Attributes inherited from Target
Checks (collapse)
-
- (Boolean) half_opped?(user)
True if
useris half-opped in the channel. -
- (Boolean) has_user?(user)
Check if a user is in the channel.
-
- (Boolean) opped?(user)
True if
useris opped in the channel. -
- (Boolean) voiced?(user)
True if
useris voiced in the channel.
User groups (collapse)
-
- (Array<User>) admins
All admins in the channel.
-
- (Array<User>) half_ops
All half-ops in the channel.
-
- (Array<User>) ops
All ops in the channel.
-
- (Array<User>) voiced
All voiced users in the channel.
Channel Manipulation (collapse)
-
- (Mask) ban(target)
Bans someone from the channel.
-
- deop(user)
Deops a user.
-
- devoice(user)
Devoices a user.
-
- invite(user)
Invites a user to the channel.
-
- join(key = nil)
Joins the channel.
-
- kick(user, reason = nil)
Kicks a user from the channel.
-
- mode(s)
Sets or unsets modes.
-
- op(user)
Ops a user.
-
- part(message = nil)
Causes the bot to part from the channel.
-
- (Mask) unban(target)
Unbans someone from the channel.
-
- voice(user)
Voices a user.
Instance Method Summary (collapse)
-
- (User) add_user(user, modes = [])
private
The added user.
-
- clear_users
private
Removes all users.
-
- (Fixnum) hash
-
- (Channel) initialize(name, bot)
constructor
A new instance of Channel.
-
- (String) inspect
-
- (Object) msg(text, notice = false)
(also: #send, #privmsg)
-
- (User?) remove_user(user)
private
The removed user.
-
- sync_modes
private
-
- (String) to_s
(also: #to_str)
Methods included from Helpers
#Channel, #Format, #Target, #Timer, #User, #debug, #error, #exception, #fatal, #incoming, #info, #log, #outgoing, #rescue_exception, #warn
Methods included from Syncable
#attr, #mark_as_synced, #sync, #synced?, #unsync, #unsync_all, #wait_until_synced
Methods inherited from Target
#<=>, #action, #concretize, #ctcp, #eql?, #notice, #safe_action, #safe_msg, #safe_notice
Constructor Details
- (Channel) initialize(name, bot)
A new instance of Channel
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 |
# File 'lib/cinch/channel.rb', line 46 def initialize(name, bot) @bot = bot @name = name @users = Hash.new {|h, k| h[k] = []} @bans = [] @owners = [] @modes = {} # TODO raise if not a channel @topic = nil @in_channel = false @synced_attributes = Set.new @when_requesting_synced_attribute = lambda {|attr| unless @in_channel unsync(attr) case attr when :users @bot.irc.send "NAMES #@name" when :topic @bot.irc.send "TOPIC #@name" when :bans @bot.irc.send "MODE #@name +b" when :owners if @bot.irc.network.owner_list_mode @bot.irc.send "MODE #@name +#{@bot.irc.network.owner_list_mode}" else # the current IRCd does not support channel owners, so # just mark the empty array as synced mark_as_synced(:owners) end when :modes @bot.irc.send "MODE #@name" end end } end |
Instance Attribute Details
- (Array<Ban>) bans (readonly)
All active bans
30 31 32 |
# File 'lib/cinch/channel.rb', line 30 def bans @bans end |
- (Boolean) invite_only Also known as: invite_only?
True if the channel is invite only (+i)
13 14 15 |
# File 'lib/cinch/channel.rb', line 13 def invite_only @invite_only end |
- (String?) key
The channel’s key (aka password)
13 14 15 |
# File 'lib/cinch/channel.rb', line 13 def key @key end |
- (Integer) limit
The maximum number of allowed users in the channel. 0 if unlimited.
13 14 15 |
# File 'lib/cinch/channel.rb', line 13 def limit @limit end |
- (Boolean) moderated Also known as: moderated?
True if the channel is moderated
13 14 15 |
# File 'lib/cinch/channel.rb', line 13 def moderated @moderated end |
- (Hash{String => Object}) modes (readonly)
This attribute describes all modes set in the channel. They’re represented as a Hash, mapping the mode (e.g. “i”, “k”, …) to either a value in the case of modes that take an option (e.g. “k” for the channel key) or true.
44 45 46 |
# File 'lib/cinch/channel.rb', line 44 def modes @modes end |
- (Array<User>) owners (readonly)
Only some networks implement this
All channel owners
35 36 37 |
# File 'lib/cinch/channel.rb', line 35 def owners @owners end |
- (Boolean) secret Also known as: secret?
True if the channel is secret (+s)
13 14 15 |
# File 'lib/cinch/channel.rb', line 13 def secret @secret end |
- (String) topic
The channel’s topic
26 27 28 |
# File 'lib/cinch/channel.rb', line 26 def topic @topic end |
Instance Method Details
- (User) add_user(user, modes = [])
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The added user
362 363 364 365 366 |
# File 'lib/cinch/channel.rb', line 362 def add_user(user, modes = []) @in_channel = true if user == @bot @users[user] = modes user end |
- (Array<User>) admins
All admins in the channel
137 138 139 |
# File 'lib/cinch/channel.rb', line 137 def admins @users.select {|user, modes| modes.include?("a")}.keys end |
- (Mask) ban(target)
Bans someone from the channel.
240 241 242 243 244 245 |
# File 'lib/cinch/channel.rb', line 240 def ban(target) mask = Mask.from(target) @bot.irc.send "MODE #@name +b #{mask}" mask end |
- clear_users
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Removes all users
379 380 381 |
# File 'lib/cinch/channel.rb', line 379 def clear_users @users.clear end |
- deop(user)
This method returns an undefined value.
Deops a user.
271 272 273 |
# File 'lib/cinch/channel.rb', line 271 def deop(user) @bot.irc.send "MODE #@name -o #{user}" end |
- devoice(user)
This method returns an undefined value.
Devoices a user.
287 288 289 |
# File 'lib/cinch/channel.rb', line 287 def devoice(user) @bot.irc.send "MODE #@name -v #{user}" end |
- (Boolean) half_opped?(user)
True if user is half-opped in the channel
104 105 106 |
# File 'lib/cinch/channel.rb', line 104 def half_opped?(user) @users[User(user)].include? "h" end |
- (Array<User>) half_ops
All half-ops in the channel
125 126 127 |
# File 'lib/cinch/channel.rb', line 125 def half_ops @users.select {|user, modes| modes.include?("h")}.keys end |
- (Boolean) has_user?(user)
Check if a user is in the channel
92 93 94 |
# File 'lib/cinch/channel.rb', line 92 def has_user?(user) @users.has_key?(User(user)) end |
- (Fixnum) hash
396 397 398 |
# File 'lib/cinch/channel.rb', line 396 def hash @name.hash end |
- (String) inspect
407 408 409 |
# File 'lib/cinch/channel.rb', line 407 def inspect "#<Channel name=#{@name.inspect}>" end |
- invite(user)
This method returns an undefined value.
Invites a user to the channel.
295 296 297 |
# File 'lib/cinch/channel.rb', line 295 def invite(user) @bot.irc.send("INVITE #{user} #@name") end |
- join(key = nil)
This method returns an undefined value.
Joins the channel
351 352 353 354 355 356 |
# File 'lib/cinch/channel.rb', line 351 def join(key = nil) if key.nil? and self.key != true key = self.key end @bot.irc.send "JOIN #{[@name, key].compact.join(" ")}" end |
- kick(user, reason = nil)
This method returns an undefined value.
Kicks a user from the channel.
319 320 321 322 323 324 325 |
# File 'lib/cinch/channel.rb', line 319 def kick(user, reason = nil) if reason.to_s.size > @bot.irc.isupport["KICKLEN"] && @bot.strict? raise Exceptions::KickReasonTooLong, reason end @bot.irc.send("KICK #@name #{user} :#{reason}") end |
- mode(s)
This method returns an undefined value.
Sets or unsets modes. Most of the time you won’t need this but use setter methods like #invite_only=.
334 335 336 |
# File 'lib/cinch/channel.rb', line 334 def mode(s) @bot.irc.send "MODE #@name #{s}" end |
- (Object) msg(text, notice = false) Also known as: send, privmsg
383 384 385 386 387 388 389 390 391 |
# File 'lib/cinch/channel.rb', line 383 def msg(text, notice = false) text = text.to_s if @modes["c"] # Remove all formatting and colors if the channel doesn't # allow colors. text.gsub!(/[\x02\x1F\x16\x0F]|\x03\d{2}(,\d{2})?/, "") end super(text, notice) end |
- op(user)
This method returns an undefined value.
Ops a user.
263 264 265 |
# File 'lib/cinch/channel.rb', line 263 def op(user) @bot.irc.send "MODE #@name +o #{user}" end |
- (Boolean) opped?(user)
True if user is opped in the channel
98 99 100 |
# File 'lib/cinch/channel.rb', line 98 def opped?(user) @users[User(user)].include? "o" end |
- (Array<User>) ops
All ops in the channel
119 120 121 |
# File 'lib/cinch/channel.rb', line 119 def ops @users.select {|user, modes| modes.include?("o")}.keys end |
- part(message = nil)
This method returns an undefined value.
Causes the bot to part from the channel.
342 343 344 |
# File 'lib/cinch/channel.rb', line 342 def part( = nil) @bot.irc.send "PART #@name :#{}" end |
- (User?) remove_user(user)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The removed user
370 371 372 373 |
# File 'lib/cinch/channel.rb', line 370 def remove_user(user) @in_channel = false if user == @bot @users.delete(user) end |
- sync_modes
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/cinch/channel.rb', line 213 def sync_modes unsync :users unsync :bans unsync :modes unsync :owners if @bot.irc.isupport["WHOX"] @bot.irc.send "WHO #@name %acfhnru" else @bot.irc.send "WHO #@name" end @bot.irc.send "MODE #@name +b" # bans @bot.irc.send "MODE #@name" if @bot.irc.network.owner_list_mode @bot.irc.send "MODE #@name +#{@bot.irc.network.owner_list_mode}" else mark_as_synced :owners end end |
- (String) to_s Also known as: to_str
401 402 403 |
# File 'lib/cinch/channel.rb', line 401 def to_s @name end |
- (Mask) unban(target)
Unbans someone from the channel.
252 253 254 255 256 257 |
# File 'lib/cinch/channel.rb', line 252 def unban(target) mask = Mask.from(target) @bot.irc.send "MODE #@name -b #{mask}" mask end |
- voice(user)
This method returns an undefined value.
Voices a user.
279 280 281 |
# File 'lib/cinch/channel.rb', line 279 def voice(user) @bot.irc.send "MODE #@name +v #{user}" end |
- (Array<User>) voiced
All voiced users in the channel
131 132 133 |
# File 'lib/cinch/channel.rb', line 131 def voiced @users.select {|user, modes| modes.include?("v")}.keys end |
- (Boolean) voiced?(user)
True if user is voiced in the channel
110 111 112 |
# File 'lib/cinch/channel.rb', line 110 def voiced?(user) @users[User(user)].include? "v" end |