Class: Cinch::Channel
Instance Attribute Summary collapse
-
#bans ⇒ Array<Ban>
readonly
All active bans.
- #bot ⇒ Bot readonly
-
#invite_only ⇒ Boolean
(also: #invite_only?)
True if the channel is invite only (+i).
-
#key ⇒ String?
The channel’s key (aka password).
-
#limit ⇒ Number
The maximum number of allowed users in the channel.
-
#moderated ⇒ Boolean
(also: #moderated?)
True if the channel is moderated (only users with o and v are able to send messages).
- #modes ⇒ Hash<String => Object> readonly
-
#name ⇒ String
readonly
The channel’s name.
-
#secret ⇒ Boolean
(also: #secret?)
True if the channel is secret (+s).
-
#topic ⇒ String
The channel’s topic.
-
#users ⇒ Array<User>
readonly
All users in the channel.
Checks collapse
-
#half_opped?(user) ⇒ Boolean
True if ‘user` is half-opped in the channel.
-
#has_user?(user) ⇒ Boolean
Check if a user is in the channel.
-
#opped?(user) ⇒ Boolean
True if ‘user` is opped in the channel.
-
#voiced?(user) ⇒ Boolean
True if ‘user` is voiced in the channel.
Channel Manipulation collapse
-
#ban(target) ⇒ Mask
Bans someone from the channel.
- #deop(user) ⇒ void
- #devoice(user) ⇒ void
-
#invite(user) ⇒ void
Invites a user to the channel.
-
#join(key = nil) ⇒ void
Joins the channel.
-
#kick(user, reason = nil) ⇒ void
Kicks a user from the channel.
-
#mode(s) ⇒ void
Sets or unsets modes.
- #op(user) ⇒ void
-
#part(message = nil) ⇒ void
Causes the bot to part from the channel.
-
#unban(target) ⇒ Mask
Unbans someone from the channel.
- #voice(user) ⇒ void
Sending messages collapse
-
#action(message) ⇒ void
Invoke an action (/me) in the channel.
-
#ctcp(message) ⇒ void
Send a CTCP to the channel.
-
#notice(message) ⇒ void
Send a notice to the channel.
-
#safe_action(message) ⇒ void
Invoke an action (/me) in the channel but remove any non-printable characters.
-
#safe_notice(message) ⇒ void
Like #safe_send but for notices.
-
#safe_send(message) ⇒ void
(also: #safe_privmsg, #safe_msg)
Send a message to the channel, but remove any non-printable characters.
-
#send(message) ⇒ void
(also: #privmsg, #msg)
Send a message to the channel.
Class Method Summary collapse
-
.all ⇒ Array<Channel>
deprecated
Deprecated.
See Bot#channel_manager and Cinch::CacheManager#each instead
-
.find(name) ⇒ Channel?
deprecated
Deprecated.
See Bot#channel_manager and Cinch::ChannelManager#find instead
-
.find_ensured(name, bot) ⇒ Channel
deprecated
Deprecated.
See Bot#channel_manager and Cinch::ChannelManager#find_ensured instead
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #add_user(user, modes = []) ⇒ void private
-
#clear_users ⇒ void
private
Removes all users.
- #hash ⇒ Fixnum
-
#initialize(name, bot) ⇒ Channel
constructor
A new instance of Channel.
- #inspect ⇒ String
- #remove_user(user) ⇒ void private
- #sync_modes(all = true) ⇒ void private
- #to_s ⇒ String (also: #to_str)
Methods included from Syncable
#attr, #mark_as_synced, #sync, #synced?, #unsync, #unsync_all, #wait_until_synced
Constructor Details
#initialize(name, bot) ⇒ Channel
Returns a new instance of Channel.
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 |
# File 'lib/cinch/channel.rb', line 74 def initialize(name, bot) @bot = bot @name = name @users = Hash.new {|h,k| h[k] = []} @bans = [] @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.raw "NAMES #@name" when :topic @bot.raw "TOPIC #@name" when :bans @bot.raw "MODE #@name +b" when :modes @bot.raw "MODE #@name" end end } end |
Instance Attribute Details
#bans ⇒ Array<Ban> (readonly)
Returns all active bans.
68 69 70 |
# File 'lib/cinch/channel.rb', line 68 def bans @bans end |
#invite_only ⇒ Boolean Also known as: invite_only?
Returns true if the channel is invite only (+i).
188 189 190 |
# File 'lib/cinch/channel.rb', line 188 def invite_only @invite_only end |
#key ⇒ String?
Returns The channel’s key (aka password).
205 206 207 |
# File 'lib/cinch/channel.rb', line 205 def key @key end |
#limit ⇒ Number
Returns The maximum number of allowed users in the channel. 0 if unlimited.
137 138 139 |
# File 'lib/cinch/channel.rb', line 137 def limit @limit end |
#moderated ⇒ Boolean Also known as: moderated?
Returns true if the channel is moderated (only users with o and v are able to send messages).
171 172 173 |
# File 'lib/cinch/channel.rb', line 171 def moderated @moderated end |
#modes ⇒ Hash<String => Object> (readonly)
72 73 74 |
# File 'lib/cinch/channel.rb', line 72 def modes @modes end |
#name ⇒ String (readonly)
Returns the channel’s name.
57 58 59 |
# File 'lib/cinch/channel.rb', line 57 def name @name end |
#secret ⇒ Boolean Also known as: secret?
Returns true if the channel is secret (+s).
153 154 155 |
# File 'lib/cinch/channel.rb', line 153 def secret @secret end |
#topic ⇒ String
Returns the channel’s topic.
64 65 66 |
# File 'lib/cinch/channel.rb', line 64 def topic @topic end |
#users ⇒ Array<User> (readonly)
Returns all users in the channel.
60 61 62 |
# File 'lib/cinch/channel.rb', line 60 def users @users end |
Class Method Details
.all ⇒ Array<Channel>
See Bot#channel_manager and Cinch::CacheManager#each instead
This method does not work properly if running more than one bot
This method will be removed in Cinch 2.0.0
Returns all channels
45 46 47 48 49 50 |
# File 'lib/cinch/channel.rb', line 45 def all $stderr.puts "Deprecation warning: Beginning with version 1.1.0, User.all should not be used anymore." puts caller @channels.values end |
.find(name) ⇒ Channel?
See Bot#channel_manager and Cinch::ChannelManager#find instead
This method does not work properly if running more than one bot
This method will be removed in Cinch 2.0.0
Finds a channel.
34 35 36 37 38 39 |
# File 'lib/cinch/channel.rb', line 34 def find(name) $stderr.puts "Deprecation warning: Beginning with version 1.1.0, Channel.find should not be used anymore." puts caller @channels[name] end |
.find_ensured(name, bot) ⇒ Channel
See Bot#channel_manager and Cinch::ChannelManager#find_ensured instead
This method does not work properly if running more than one bot
This method will be removed in Cinch 2.0.0
Finds or creates a channel.
19 20 21 22 23 24 25 |
# File 'lib/cinch/channel.rb', line 19 def find_ensured(name, bot) $stderr.puts "Deprecation warning: Beginning with version 1.1.0, Channel.find_ensured should not be used anymore." puts caller downcased_name = name.irc_downcase(bot.irc.isupport["CASEMAPPING"]) @channels[downcased_name] ||= bot.channel_manager.find_ensured(name) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
453 454 455 |
# File 'lib/cinch/channel.rb', line 453 def ==(other) @name == other.to_s end |
#action(message) ⇒ void
This method returns an undefined value.
Invoke an action (/me) in the channel.
431 432 433 |
# File 'lib/cinch/channel.rb', line 431 def action() @bot.action(@name, ) end |
#add_user(user, modes = []) ⇒ void
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.
348 349 350 351 |
# File 'lib/cinch/channel.rb', line 348 def add_user(user, modes = []) @in_channel = true if user == @bot @users[user] = modes end |
#ban(target) ⇒ Mask
Bans someone from the channel.
237 238 239 240 241 242 |
# File 'lib/cinch/channel.rb', line 237 def ban(target) mask = Mask.from(target) @bot.raw "MODE #@name +b #{mask}" mask end |
#clear_users ⇒ void
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
364 365 366 |
# File 'lib/cinch/channel.rb', line 364 def clear_users @users.clear end |
#ctcp(message) ⇒ void
This method returns an undefined value.
Send a CTCP to the channel.
422 423 424 |
# File 'lib/cinch/channel.rb', line 422 def ctcp() send "\001#{}\001" end |
#deop(user) ⇒ void
This method returns an undefined value.
263 264 265 |
# File 'lib/cinch/channel.rb', line 263 def deop(user) @bot.raw "MODE #@name -o #{user}" end |
#devoice(user) ⇒ void
This method returns an undefined value.
275 276 277 |
# File 'lib/cinch/channel.rb', line 275 def devoice(user) @bot.raw "MODE #@name -v #{user}" end |
#half_opped?(user) ⇒ Boolean
Returns true if ‘user` is half-opped in the channel.
122 123 124 125 |
# File 'lib/cinch/channel.rb', line 122 def half_opped?(user) user = @bot.user_manager.find_ensured(user) unless user.is_a?(User) @users[user].include? "h" end |
#has_user?(user) ⇒ Boolean
Returns Check if a user is in the channel.
109 110 111 112 |
# File 'lib/cinch/channel.rb', line 109 def has_user?(user) user = @bot.user_manager.find_ensured(user) unless user.is_a?(User) @users.has_key?(user) end |
#hash ⇒ Fixnum
459 460 461 |
# File 'lib/cinch/channel.rb', line 459 def hash @name.hash end |
#inspect ⇒ String
470 471 472 |
# File 'lib/cinch/channel.rb', line 470 def inspect "#<Channel name=#{@name.inspect}>" end |
#invite(user) ⇒ void
This method returns an undefined value.
Invites a user to the channel.
283 284 285 |
# File 'lib/cinch/channel.rb', line 283 def invite(user) @bot.raw("INVITE #{user} #@name") end |
#join(key = nil) ⇒ void
This method returns an undefined value.
Joins the channel
337 338 339 340 341 342 |
# File 'lib/cinch/channel.rb', line 337 def join(key = nil) if key.nil? and self.key != true key = self.key end @bot.raw "JOIN #{[@name, key].compact.join(" ")}" end |
#kick(user, reason = nil) ⇒ void
This method returns an undefined value.
Kicks a user from the channel.
305 306 307 308 309 310 311 |
# File 'lib/cinch/channel.rb', line 305 def kick(user, reason = nil) if reason.to_s.size > @bot.irc.isupport["KICKLEN"] && @bot.strict? raise Exceptions::KickReasonTooLong, reason end @bot.raw("KICK #@name #{user} :#{reason}") end |
#mode(s) ⇒ void
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=.
320 321 322 |
# File 'lib/cinch/channel.rb', line 320 def mode(s) @bot.raw "MODE #@name #{s}" end |
#notice(message) ⇒ void
This method returns an undefined value.
Send a notice to the channel.
385 386 387 |
# File 'lib/cinch/channel.rb', line 385 def notice() @bot.notice(@name, ) end |
#op(user) ⇒ void
This method returns an undefined value.
257 258 259 |
# File 'lib/cinch/channel.rb', line 257 def op(user) @bot.raw "MODE #@name +o #{user}" end |
#opped?(user) ⇒ Boolean
Returns true if ‘user` is opped in the channel.
116 117 118 119 |
# File 'lib/cinch/channel.rb', line 116 def opped?(user) user = @bot.user_manager.find_ensured(user) unless user.is_a?(User) @users[user].include? "o" end |
#part(message = nil) ⇒ void
This method returns an undefined value.
Causes the bot to part from the channel.
328 329 330 |
# File 'lib/cinch/channel.rb', line 328 def part( = nil) @bot.raw "PART #@name :#{}" end |
#remove_user(user) ⇒ void
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.
355 356 357 358 |
# File 'lib/cinch/channel.rb', line 355 def remove_user(user) @in_channel = false if user == @bot @users.delete(user) end |
#safe_action(message) ⇒ void
Handle mIRC color codes more gracefully.
This method returns an undefined value.
Invoke an action (/me) in the channel but remove any non-printable characters. The purpose of this method is to send text from untrusted sources, like other users or feeds.
Note: this will break any mIRC color codes embedded in the string.
446 447 448 |
# File 'lib/cinch/channel.rb', line 446 def safe_action() @bot.safe_action(@name, ) end |
#safe_notice(message) ⇒ void
Handle mIRC color codes more gracefully.
This method returns an undefined value.
Like #safe_send but for notices.
395 396 397 |
# File 'lib/cinch/channel.rb', line 395 def safe_notice() @bot.safe_notice(@name, ) end |
#safe_send(message) ⇒ void Also known as: safe_privmsg, safe_msg
Handle mIRC color codes more gracefully.
This method returns an undefined value.
Send a message to the channel, but remove any non-printable characters. The purpose of this method is to send text from untrusted sources, like other users or feeds.
Note: this will break any mIRC color codes embedded in the string.
410 411 412 |
# File 'lib/cinch/channel.rb', line 410 def safe_send() @bot.safe_msg(@name, ) end |
#send(message) ⇒ void Also known as: privmsg, msg
This method returns an undefined value.
Send a message to the channel.
375 376 377 |
# File 'lib/cinch/channel.rb', line 375 def send() @bot.msg(@name, ) end |
#sync_modes(all = true) ⇒ void
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.
222 223 224 225 226 227 228 229 |
# File 'lib/cinch/channel.rb', line 222 def sync_modes(all = true) unsync :users unsync :bans unsync :modes @bot.raw "NAMES #@name" if all @bot.raw "MODE #@name +b" # bans @bot.raw "MODE #@name" end |
#to_s ⇒ String Also known as: to_str
464 465 466 |
# File 'lib/cinch/channel.rb', line 464 def to_s @name end |
#unban(target) ⇒ Mask
Unbans someone from the channel.
248 249 250 251 252 253 |
# File 'lib/cinch/channel.rb', line 248 def unban(target) mask = Mask.from(target) @bot.raw "MODE #@name -b #{mask}" mask end |
#voice(user) ⇒ void
This method returns an undefined value.
269 270 271 |
# File 'lib/cinch/channel.rb', line 269 def voice(user) @bot.raw "MODE #@name +v #{user}" end |
#voiced?(user) ⇒ Boolean
Returns true if ‘user` is voiced in the channel.
128 129 130 131 |
# File 'lib/cinch/channel.rb', line 128 def voiced?(user) user = @bot.user_manager.find_ensured(user) unless user.is_a?(User) @users[user].include? "v" end |