class Irc::Channel
An IRC Channel
is identified by its name, and it has a set of properties:
-
a
UserList
-
a set of Channel::Modes
The Channel::Topic
and Channel::Mode
classes are defined within the Channel
namespace because they only make sense there
Here we start with the actual Channel
class
Attributes
Public Class Methods
Creates a new channel with the given name, optionally setting the topic and an initial users list.
No additional info is created here, because the channel flags and userlists allowed depend on the server.
# File lib/rbot/irc.rb, line 1402 def initialize(name, topic=nil, users=[], opts={}) raise ArgumentError, "Channel name cannot be empty" if name.to_s.empty? warning "Unknown channel prefix #{name[0,1]}" if name !~ /^[&#+!]/ raise ArgumentError, "Invalid character in #{name.inspect}" if name =~ /[ \x07,]/ init_server_or_casemap(opts) @name = name @topic = topic ? topic.to_irc_channel_topic : Channel::Topic.new @users = UserList.new users.each { |u| add_user(u) } # Flags @mode = ModeHash.new # creation time, only on some networks @creation_time = nil # URL, only on some networks @url = nil end
Return the non-prefixed part of a channel name. Also works with ## channels found on some networks (e.g. FreeNode)
# File lib/rbot/irc.rb, line 1342 def self.npname(str) return str.to_s.sub(/^[&#+!]+/,'') end
Public Instance Methods
Adds a user to the channel
# File lib/rbot/irc.rb, line 1387 def add_user(user, opts={}) silent = opts.fetch(:silent, false) if has_user?(user) warning "Trying to add user #{user} to channel #{self} again" unless silent else @users << user.to_irc_user(server_and_casemap) end end
Create a new mode
# File lib/rbot/irc.rb, line 1470 def create_mode(sym, kl) @mode[sym.to_sym] = kl.new(self) end
Removes a user from the channel
# File lib/rbot/irc.rb, line 1431 def delete_user(user) @mode.each { |sym, mode| mode.reset(user) if mode.kind_of?(UserMode) } @users.delete(user) end
Returns the user with nick nick, if available
# File lib/rbot/irc.rb, line 1380 def get_user(nick) idx = has_user?(nick) @users[idx] if idx end
# File lib/rbot/irc.rb, line 1482 def has_op?(user) @mode.has_key?(:o) and @mode[:o].list[user] end
Checks if the receiver already has a user with the given nick
# File lib/rbot/irc.rb, line 1374 def has_user?(nick) @users.index(nick.to_irc_user(server_and_casemap)) end
# File lib/rbot/irc.rb, line 1486 def has_voice?(user) @mode.has_key?(:v) and @mode[:v].list[user] end
# File lib/rbot/irc.rb, line 1351 def inspect str = self.__to_s__[0..-2] str << " on server #{server}" if server str << " @name=#{@name.inspect} @topic=#{@topic.text.inspect}" str << " @users=[#{user_nicks.sort.join(', ')}]" str << " (created on #{creation_time})" if creation_time str << " (URL #{url})" if url str << ">" end
A channel is local to a server if it has the ‘&’ prefix
# File lib/rbot/irc.rb, line 1446 def local? name[0,1] == '&' end
A channel is modeless if it has the ‘+’ prefix
# File lib/rbot/irc.rb, line 1452 def modeless? name[0,1] == '+' end
# File lib/rbot/irc.rb, line 1474 def modes_of(user) l = [] @mode.map { |s, m| l << s if (m.class <= UserMode and m.list[user]) } l end
A channel is normal if it has the ‘#’ prefix
# File lib/rbot/irc.rb, line 1464 def normal? name[0,1] == '#' end
The channel prefix
# File lib/rbot/irc.rb, line 1440 def prefix name[0,1] end
A channel is safe if it has the ‘!’ prefix
# File lib/rbot/irc.rb, line 1458 def safe? name[0,1] == '!' end
Returns self
# File lib/rbot/irc.rb, line 1363 def to_irc_channel self end
TODO Ho
# File lib/rbot/irc.rb, line 1368 def user_nicks @users.map { |u| u.downcase } end