Parent

Included Modules

Cinch::Channel

Attributes

bans[R]

@return [Array<Ban>] all active bans

bot[R]

@return [Bot]

invite_only[RW]

@return [Boolean] true if the channel is invite only (+i)

invite_only?[RW]

@return [Boolean] true if the channel is invite only (+i)

key[RW]

@return [String, nil] The channel's key (aka password)

limit[RW]

@return [Number] The maximum number of allowed users in the

channel. 0 if unlimited.
moderated[RW]

@return [Boolean] true if the channel is moderated (only users

with +o and +v are able to send messages)
moderated?[RW]

@return [Boolean] true if the channel is moderated (only users

with +o and +v are able to send messages)
modes[R]

@return [Hash<String => Object>]

name[R]

@return [String] the channel's name

secret[RW]

@return [Boolean] true if the channel is secret (+s)

secret?[RW]

@return [Boolean] true if the channel is secret (+s)

topic[RW]

@return [String] the channel's topic

users[R]

@return [Array<User>] all users in the channel

Public Class Methods

all() click to toggle source

@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
find(name) click to toggle source

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
find_ensured(name, bot) click to toggle source

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
new(name, bot) click to toggle source
# 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

Public Instance Methods

==(other) click to toggle source

@return [Boolean]

# File lib/cinch/channel.rb, line 452
def ==(other)
  @name == other.to_s
end
action(message) click to toggle source

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
add_user(user, modes = []) click to toggle source

@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
ban(target) click to toggle source

Bans someone from the channel.

@param [Ban, Mask, User, String] target the mask to ban @return [Mask] the mask used for banning

# File lib/cinch/channel.rb, line 236
def ban(target)
  mask = Mask.from(target)

  @bot.raw "MODE #@name +b #{mask}"
  mask
end
clear_users() click to toggle source

Removes all users

@api private @return [void]

# File lib/cinch/channel.rb, line 363
def clear_users
  @users.clear
end
ctcp(message) click to toggle source

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
deop(user) click to toggle source

@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
devoice(user) click to toggle source

@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
half_opped?(user) click to toggle source

@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
has_user?(user) click to toggle source

@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
hash() click to toggle source

@return [Fixnum]

# File lib/cinch/channel.rb, line 458
def hash
  @name.hash
end
inspect() click to toggle source

@return [String]

# File lib/cinch/channel.rb, line 469
def inspect
  "#<Channel name=#{@name.inspect}>"
end
invite(user) click to toggle source

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
invite_only=(bool) click to toggle source
# File lib/cinch/channel.rb, line 195
def invite_only=(bool)
  if bool
    mode "+i"
  else
    mode "-i"
  end
end
join(key = nil) click to toggle source

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
key=(new_key) click to toggle source
# 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
kick(user, reason = nil) click to toggle source

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
limit=(val) click to toggle source
# File lib/cinch/channel.rb, line 143
def limit=(val)
  if val == -1 or val.nil?
    mode "-l"
  else
    mode "+l #{val}"
  end
end
mode(s) click to toggle source

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
moderated=(val) click to toggle source
# File lib/cinch/channel.rb, line 178
def moderated=(val)
  if bool
    mode "+m"
  else
    mode "-m"
  end
end
msg(message) click to toggle source
Alias for: send
notice(message) click to toggle source

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
op(user) click to toggle source

@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
opped?(user) click to toggle source

@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
part(message = nil) click to toggle source

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
privmsg(message) click to toggle source
Alias for: send
remove_user(user) click to toggle source

@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
safe_action(message) click to toggle source

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
safe_msg(message) click to toggle source
Alias for: safe_send
safe_notice(message) click to toggle source

Like {safe_send} but for notices.

@param (see safe_send) @return (see safe_send) @see safe_send @todo (see safe_send)

# File lib/cinch/channel.rb, line 394
def safe_notice(message)
  @bot.safe_notice(@name, message)
end
safe_privmsg(message) click to toggle source
Alias for: safe_send
safe_send(message) click to toggle source

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
Also aliased as: safe_privmsg, safe_msg
secret=(bool) click to toggle source
# File lib/cinch/channel.rb, line 160
def secret=(bool)
  if bool
    mode "+s"
  else
    mode "-s"
  end
end
send(message) click to toggle source

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
Also aliased as: privmsg, msg
sync_modes(all = true) click to toggle source

@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
to_s() click to toggle source

@return [String]

# File lib/cinch/channel.rb, line 463
def to_s
  @name
end
Also aliased as: to_str
to_str() click to toggle source
Alias for: to_s
topic=(new_topic) click to toggle source

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
unban(target) click to toggle source

Unbans someone from the channel.

@param [Ban, Mask, User, String] target the mask to unban @return [Mask] the mask used for unbanning

# File lib/cinch/channel.rb, line 247
def unban(target)
  mask = Mask.from(target)

  @bot.raw "MODE #@name -b #{mask}"
  mask
end
voice(user) click to toggle source

@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
voiced?(user) click to toggle source

@return [Boolean] true if `user` is voiced in the channel

# File lib/cinch/channel.rb, line 127
def voiced?(user)
  user = @bot.user_manager.find_ensured(user) unless user.is_a?(User)
  @users[user].include? "v"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.