@return [Boolean] true if the channel is moderated (only users
with +o and +v are able to send messages)
@return [Array<Channel>] Returns all channels @deprecated See {Bot#channel_manager} and {CacheManager#each} instead @note This method does not work properly if running more than one bot @note This method will be removed in Cinch 2.0.0
# File lib/cinch/channel.rb, line 44 def all $stderr.puts "Deprecation warning: Beginning with version 1.1.0, User.all should not be used anymore." puts caller @channels.values end
Finds a channel.
@param [String] name name of a channel @return [Channel, nil] @deprecated See {Bot#channel_manager} and {ChannelManager#find} instead @note This method does not work properly if running more than one bot @note This method will be removed in Cinch 2.0.0
# File lib/cinch/channel.rb, line 33 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
Finds or creates a channel.
@param [String] name name of a channel @param [Bot] bot a bot @return [Channel] @see Bot#Channel @deprecated See {Bot#channel_manager} and {ChannelManager#find_ensured} instead @note This method does not work properly if running more than one bot @note This method will be removed in Cinch 2.0.0
# File lib/cinch/channel.rb, line 18 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
# File lib/cinch/channel.rb, line 73 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
@return [Boolean]
# File lib/cinch/channel.rb, line 452 def ==(other) @name == other.to_s end
Invoke an action (/me) in the channel.
@param [String] message the message @return [void] @see safe_action
# File lib/cinch/channel.rb, line 430 def action(message) @bot.action(@name, message) end
@api private @return [void]
# File lib/cinch/channel.rb, line 347 def add_user(user, modes = []) @in_channel = true if user == @bot @users[user] = modes end
Removes all users
@api private @return [void]
# File lib/cinch/channel.rb, line 363 def clear_users @users.clear end
Send a CTCP to the channel.
@param [String] message the ctcp message @return [void]
# File lib/cinch/channel.rb, line 421 def ctcp(message) send "\0001#{message}\0001" end
@param [String, User] user the user to deop @return [void]
# File lib/cinch/channel.rb, line 262 def deop(user) @bot.raw "MODE #@name -o #{user}" end
@param [String, User] user the user to devoice @return [void]
# File lib/cinch/channel.rb, line 274 def devoice(user) @bot.raw "MODE #@name -v #{user}" end
@return [Boolean] true if `user` is half-opped in the channel
# File lib/cinch/channel.rb, line 121 def half_opped?(user) user = @bot.user_manager.find_ensured(user) unless user.is_a?(User) @users[user].include? "h" end
@param [User, String] user An {User}-object or a nickname @return [Boolean] Check if a user is in the channel
# File lib/cinch/channel.rb, line 108 def has_user?(user) user = @bot.user_manager.find_ensured(user) unless user.is_a?(User) @users.has_key?(user) end
@return [Fixnum]
# File lib/cinch/channel.rb, line 458 def hash @name.hash end
@return [String]
# File lib/cinch/channel.rb, line 469 def inspect "#<Channel name=#{@name.inspect}>" end
Invites a user to the channel.
@param [String, User] user the user to invite @return [void]
# File lib/cinch/channel.rb, line 282 def invite(user) @bot.raw("INVITE #{user} #@name") end
# File lib/cinch/channel.rb, line 195 def invite_only=(bool) if bool mode "+i" else mode "-i" end end
Joins the channel
@param [String] key the channel key, if any. If none is
specified but @key is set, @key will be used
@return [void]
# File lib/cinch/channel.rb, line 336 def join(key = nil) if key.nil? and self.key != true key = self.key end @bot.raw "JOIN #{[@name, key].compact.join(" ")}" end
# File lib/cinch/channel.rb, line 211 def key=(new_key) if new_key.nil? mode "-k #{key}" else mode "+k #{new_key}" end end
Kicks a user from the channel.
@param [String, User] user the user to kick @param [String] a reason for the kick @raise [Exceptions::KickReasonTooLong] @return [void]
# File lib/cinch/channel.rb, line 304 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
# File lib/cinch/channel.rb, line 143 def limit=(val) if val == -1 or val.nil? mode "-l" else mode "+l #{val}" end end
Sets or unsets modes. Most of the time you won't need this but use setter methods like {Channel#invite_only=}.
@param [String] s a mode string @return [void] @example
channel.mode "+n"
# File lib/cinch/channel.rb, line 319 def mode(s) @bot.raw "MODE #@name #{s}" end
# File lib/cinch/channel.rb, line 178 def moderated=(val) if bool mode "+m" else mode "-m" end end
Send a notice to the channel.
@param [String] message the message @return [void]
# File lib/cinch/channel.rb, line 384 def notice(message) @bot.notice(@name, message) end
@param [String, User] user the user to op @return [void]
# File lib/cinch/channel.rb, line 256 def op(user) @bot.raw "MODE #@name +o #{user}" end
@return [Boolean] true if `user` is opped in the channel
# File lib/cinch/channel.rb, line 115 def opped?(user) user = @bot.user_manager.find_ensured(user) unless user.is_a?(User) @users[user].include? "o" end
Causes the bot to part from the channel.
@param [String] message the part message. @return [void]
# File lib/cinch/channel.rb, line 327 def part(message = nil) @bot.raw "PART #@name :#{message}" end
@api private @return [void]
# File lib/cinch/channel.rb, line 354 def remove_user(user) @in_channel = false if user == @bot @users.delete(user) end
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.
@param (see action) @return (see action) @see action @todo Handle mIRC color codes more gracefully.
# File lib/cinch/channel.rb, line 445 def safe_action(message) @bot.safe_action(@name, message) end
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.
@param (see send) @return (see send) @see send @todo Handle mIRC color codes more gracefully.
# File lib/cinch/channel.rb, line 409 def safe_send(message) @bot.safe_msg(@name, message) end
# File lib/cinch/channel.rb, line 160 def secret=(bool) if bool mode "+s" else mode "-s" end end
Send a message to the channel.
@param [String] message the message @return [void] @see safe_send
# File lib/cinch/channel.rb, line 374 def send(message) @bot.msg(@name, message) end
@api private @return [void]
# File lib/cinch/channel.rb, line 221 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
@return [String]
# File lib/cinch/channel.rb, line 463 def to_s @name end
Sets the topic.
@param [String] new_topic the new topic @raise [Exceptions::TopicTooLong]
# File lib/cinch/channel.rb, line 290 def topic=(new_topic) if new_topic.size > @bot.irc.isupport["TOPICLEN"] && @bot.strict? raise Exceptions::TopicTooLong, new_topic end @bot.raw "TOPIC #@name :#{new_topic}" end
@param [String, User] user the user to voice @return [void]
# File lib/cinch/channel.rb, line 268 def voice(user) @bot.raw "MODE #@name +v #{user}" end
Generated with the Darkfish Rdoc Generator 2.