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 1395 def initialize(name, topic=nil, users=[], opts={}) raise ArgumentError, "Channel name cannot be empty" if name.to_s.empty? warn "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 1335 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 1380 def add_user(user, opts={}) silent = opts.fetch(:silent, false) if has_user?(user) warn "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 1463 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 1424 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 1373 def get_user(nick) idx = has_user?(nick) @users[idx] if idx end
# File lib/rbot/irc.rb, line 1475 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 1367 def has_user?(nick) @users.index(nick.to_irc_user(server_and_casemap)) end
# File lib/rbot/irc.rb, line 1479 def has_voice?(user) @mode.has_key?(:v) and @mode[:v].list[user] end
# File lib/rbot/irc.rb, line 1344 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 1439 def local? name[0,1] == '&' end
A channel is modeless if it has the ‘+’ prefix
# File lib/rbot/irc.rb, line 1445 def modeless? name[0,1] == '+' end
# File lib/rbot/irc.rb, line 1467 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 1457 def normal? name[0,1] == '#' end
The channel prefix
# File lib/rbot/irc.rb, line 1433 def prefix name[0,1] end
A channel is safe if it has the ‘!’ prefix
# File lib/rbot/irc.rb, line 1451 def safe? name[0,1] == '!' end
Returns self
# File lib/rbot/irc.rb, line 1356 def to_irc_channel self end
TODO Ho
# File lib/rbot/irc.rb, line 1361 def user_nicks @users.map { |u| u.downcase } end