Parent

Included Modules

Class/Module Index [+]

Quicksearch

Cinch::Channel

@attr limit @attr secret @attr moderated @attr invite_only @attr key

@version 2.0.0

Attributes

bans[R]

@return [Array<Ban>] all active bans

modes[R]

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.

@return [Hash{String => Object}]

owners[R]

@return [Array<User>] all channel owners @note Only some networks implement this

topic[RW]

@return [String] the channel's topic

users[R]

Users are represented by a Hash, mapping individual users to an array of modes (e.g. "o" for opped).

@return [Hash{User => Array<String}>] all users in the channel @version 1.1.0

Public Class Methods

new(name, bot) click to toggle source
# File lib/cinch/channel.rb, line 45
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

Public Instance Methods

add_user(user, modes = []) click to toggle source

@api private @return [User] The added user

# File lib/cinch/channel.rb, line 361
def add_user(user, modes = [])
  @in_channel = true if user == @bot
  @users[user] = modes
  user
end
admins() click to toggle source

@return [Array<User>] All admins in the channel @since 2.0.0

# File lib/cinch/channel.rb, line 136
def admins
  @users.select {|user, modes| modes.include?("a")}.keys
end
ban(target) click to toggle source

Bans someone from the channel.

@param [Mask, String, mask] target the mask, or an object having a mask, to ban @return [Mask] the mask used for banning @see unban unban for unbanning users

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

  @bot.irc.send "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 378
def clear_users
  @users.clear
end
deop(user) click to toggle source

Deops a user.

@param [String, User] user the user to deop @return [void]

# File lib/cinch/channel.rb, line 270
def deop(user)
  @bot.irc.send "MODE #@name -o #{user}"
end
devoice(user) click to toggle source

Devoices a user.

@param [String, User] user the user to devoice @return [void]

# File lib/cinch/channel.rb, line 286
def devoice(user)
  @bot.irc.send "MODE #@name -v #{user}"
end
half_opped?(user) click to toggle source

@return [Boolean] true if `user` is half-opped in the channel @since 1.1.0

# File lib/cinch/channel.rb, line 103
def half_opped?(user)
  @users[User(user)].include? "h"
end
half_ops() click to toggle source

@return [Array<User>] All half-ops in the channel @since 2.0.0

# File lib/cinch/channel.rb, line 124
def half_ops
  @users.select {|user, modes| modes.include?("h")}.keys
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 @since 1.1.0 @version 1.1.2

# File lib/cinch/channel.rb, line 91
def has_user?(user)
  @users.has_key?(User(user))
end
hash() click to toggle source

@return [Fixnum]

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

@return [String]

# File lib/cinch/channel.rb, line 406
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 294
def invite(user)
  @bot.irc.send("INVITE #{user} #@name")
end
invite_only() click to toggle source

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

# File lib/cinch/channel.rb, line 184
def invite_only
  @modes["i"]
end
Also aliased as: invite_only?
invite_only=(bool) click to toggle source
# File lib/cinch/channel.rb, line 189
def invite_only=(bool)
  if bool
    mode "+i"
  else
    mode "-i"
  end
end
invite_only?() click to toggle source
Alias for: invite_only
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 350
def join(key = nil)
  if key.nil? and self.key != true
    key = self.key
  end
  @bot.irc.send "JOIN #{[@name, key].compact.join(" ")}"
end
key() click to toggle source

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

# File lib/cinch/channel.rb, line 198
def key
  @modes["k"]
end
key=(new_key) click to toggle source
# File lib/cinch/channel.rb, line 202
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 318
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
limit() click to toggle source

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

channel. 0 if unlimited.
# File lib/cinch/channel.rb, line 143
def limit
  @modes["l"].to_i
end
limit=(val) click to toggle source
# File lib/cinch/channel.rb, line 147
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 333
def mode(s)
  @bot.irc.send "MODE #@name #{s}"
end
moderated() click to toggle source

@return [Boolean] true if the channel is moderated

# File lib/cinch/channel.rb, line 170
def moderated
  @modes["m"]
end
Also aliased as: moderated?
moderated=(bool) click to toggle source
# File lib/cinch/channel.rb, line 175
def moderated=(bool)
  if bool
    mode "+m"
  else
    mode "-m"
  end
end
moderated?() click to toggle source
Alias for: moderated
msg(text, notice = false) click to toggle source
# File lib/cinch/channel.rb, line 382
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
Also aliased as: send, privmsg
op(user) click to toggle source

Ops a user.

@param [String, User] user the user to op @return [void]

# File lib/cinch/channel.rb, line 262
def op(user)
  @bot.irc.send "MODE #@name +o #{user}"
end
opped?(user) click to toggle source

@return [Boolean] true if `user` is opped in the channel @since 1.1.0

# File lib/cinch/channel.rb, line 97
def opped?(user)
  @users[User(user)].include? "o"
end
ops() click to toggle source

@group User groups @return [Array<User>] All ops in the channel @since 2.0.0

# File lib/cinch/channel.rb, line 118
def ops
  @users.select {|user, modes| modes.include?("o")}.keys
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 341
def part(message = nil)
  @bot.irc.send "PART #@name :#{message}"
end
privmsg(text, notice = false) click to toggle source
Alias for: msg
remove_user(user) click to toggle source

@api private @return [User, nil] The removed user

# File lib/cinch/channel.rb, line 369
def remove_user(user)
  @in_channel = false if user == @bot
  @users.delete(user)
end
secret() click to toggle source

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

# File lib/cinch/channel.rb, line 156
def secret
  @modes["s"]
end
Also aliased as: secret?
secret=(bool) click to toggle source
# File lib/cinch/channel.rb, line 161
def secret=(bool)
  if bool
    mode "+s"
  else
    mode "-s"
  end
end
secret?() click to toggle source
Alias for: secret
send(text, notice = false) click to toggle source
Alias for: msg
sync_modes() click to toggle source

@api private @return [void]

# File lib/cinch/channel.rb, line 212
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
to_s() click to toggle source

@return [String]

# File lib/cinch/channel.rb, line 400
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] Raised if the bot is operating

in {Bot#strict? strict mode} and when the new topic is too long.
# File lib/cinch/channel.rb, line 304
def topic=(new_topic)
  if new_topic.size > @bot.irc.isupport["TOPICLEN"] && @bot.strict?
    raise Exceptions::TopicTooLong, new_topic
  end

  @bot.irc.send "TOPIC #@name :#{new_topic}"
end
unban(target) click to toggle source

Unbans someone from the channel.

@param [Mask, String, mask] target the mask to unban @return [Mask] the mask used for unbanning @see ban ban for banning users

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

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

Voices a user.

@param [String, User] user the user to voice @return [void]

# File lib/cinch/channel.rb, line 278
def voice(user)
  @bot.irc.send "MODE #@name +v #{user}"
end
voiced() click to toggle source

@return [Array<User>] All voiced users in the channel @since 2.0.0

# File lib/cinch/channel.rb, line 130
def voiced
  @users.select {|user, modes| modes.include?("v")}.keys
end
voiced?(user) click to toggle source

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

# File lib/cinch/channel.rb, line 109
def voiced?(user)
  @users[User(user)].include? "v"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.