Class: Irc::Channel
- Inherits:
-
Object
- Object
- Irc::Channel
- Includes:
- ServerOrCasemap
- Defined in:
- /home/apoc/projects/ruby/rbot/lib/rbot/irc.rb,
/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb
Overview
Here we start with the actual Channel class
Defined Under Namespace
Classes: Mode, ModeHash, ModeTypeA, ModeTypeB, ModeTypeC, ModeTypeD, Topic, UserMode
Instance Attribute Summary (collapse)
-
- (Object) creation_time
Returns the value of attribute creation_time.
-
- (Object) mode
readonly
Returns the value of attribute mode.
-
- (Object) name
(also: #to_s)
readonly
Returns the value of attribute name.
-
- (Object) topic
readonly
Returns the value of attribute topic.
-
- (Object) url
Returns the value of attribute url.
-
- (Object) users
readonly
Returns the value of attribute users.
Attributes included from ServerOrCasemap
Class Method Summary (collapse)
-
+ (Object) npname(str)
Return the non-prefixed part of a channel name.
Instance Method Summary (collapse)
-
- (Object) add_user(user, opts = {})
Adds a user to the channel.
-
- (Object) create_mode(sym, kl)
Create a new mode.
-
- (Object) delete_user(user)
Removes a user from the channel.
-
- (Object) get_user(nick)
Returns the user with nick nick, if available.
- - (Boolean) has_op?(user)
-
- (Boolean) has_user?(nick)
Checks if the receiver already has a user with the given nick.
- - (Boolean) has_voice?(user)
-
- (Channel) initialize(name, topic = nil, users = [], opts = {})
constructor
Creates a new channel with the given name, optionally setting the topic and an initial users list.
- - (Object) inspect
-
- (Boolean) local?
A channel is local to a server if it has the '&' prefix.
-
- (Boolean) modeless?
A channel is modeless if it has the '+' prefix.
- - (Object) modes_of(user)
-
- (Boolean) normal?
A channel is normal if it has the '#' prefix.
-
- (Object) prefix
The channel prefix.
-
- (Boolean) safe?
A channel is safe if it has the '!' prefix.
-
- (Object) to_irc_channel
Returns self.
-
- (Object) user_nicks
TODO Ho.
Methods included from ServerOrCasemap
#casemap, #downcase, #fits_with_server_and_casemap?, #init_server_or_casemap, #irc_downcase, #irc_upcase, #server_and_casemap, #upcase
Constructor Details
- (Channel) initialize(name, topic = nil, users = [], opts = {})
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.
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 |
# File '/home/apoc/projects/ruby/rbot/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 |
Instance Attribute Details
- (Object) creation_time
Returns the value of attribute creation_time
1342 1343 1344 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1342 def creation_time @creation_time end |
- (Object) mode (readonly)
Returns the value of attribute mode
1340 1341 1342 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1340 def mode @mode end |
- (Object) name (readonly) Also known as: to_s
Returns the value of attribute name
1340 1341 1342 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1340 def name @name end |
- (Object) topic (readonly)
Returns the value of attribute topic
1340 1341 1342 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1340 def topic @topic end |
- (Object) url
Returns the value of attribute url
1342 1343 1344 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1342 def url @url end |
- (Object) users (readonly)
Returns the value of attribute users
1340 1341 1342 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1340 def users @users end |
Class Method Details
+ (Object) npname(str)
Return the non-prefixed part of a channel name. Also works with ## channels found on some networks (e.g. FreeNode)
1335 1336 1337 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1335 def self.npname(str) return str.to_s.sub(/^[&#+!]+/,'') end |
Instance Method Details
- (Object) add_user(user, opts = {})
Adds a user to the channel
1380 1381 1382 1383 1384 1385 1386 1387 |
# File '/home/apoc/projects/ruby/rbot/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 |
- (Object) create_mode(sym, kl)
Create a new mode
1463 1464 1465 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1463 def create_mode(sym, kl) @mode[sym.to_sym] = kl.new(self) end |
- (Object) delete_user(user)
Removes a user from the channel
1424 1425 1426 1427 1428 1429 |
# File '/home/apoc/projects/ruby/rbot/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 |
- (Object) get_user(nick)
Returns the user with nick nick, if available
1373 1374 1375 1376 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1373 def get_user(nick) idx = has_user?(nick) @users[idx] if idx end |
- (Boolean) has_op?(user)
1475 1476 1477 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1475 def has_op?(user) @mode.has_key?(:o) and @mode[:o].list[user] end |
- (Boolean) has_user?(nick)
Checks if the receiver already has a user with the given nick
1367 1368 1369 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1367 def has_user?(nick) @users.index(nick.to_irc_user(server_and_casemap)) end |
- (Boolean) has_voice?(user)
1479 1480 1481 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1479 def has_voice?(user) @mode.has_key?(:v) and @mode[:v].list[user] end |
- (Object) inspect
1344 1345 1346 1347 1348 1349 1350 1351 1352 |
# File '/home/apoc/projects/ruby/rbot/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 |
- (Boolean) local?
A channel is local to a server if it has the '&' prefix
1439 1440 1441 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1439 def local? name[0,1] == '&' end |
- (Boolean) modeless?
A channel is modeless if it has the '+' prefix
1445 1446 1447 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1445 def modeless? name[0,1] == '+' end |
- (Object) modes_of(user)
1467 1468 1469 1470 1471 1472 1473 |
# File '/home/apoc/projects/ruby/rbot/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 |
- (Boolean) normal?
A channel is normal if it has the '#' prefix
1457 1458 1459 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1457 def normal? name[0,1] == '#' end |
- (Object) prefix
The channel prefix
1433 1434 1435 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1433 def prefix name[0,1] end |
- (Boolean) safe?
A channel is safe if it has the '!' prefix
1451 1452 1453 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1451 def safe? name[0,1] == '!' end |
- (Object) to_irc_channel
Returns self
1356 1357 1358 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1356 def to_irc_channel self end |
- (Object) user_nicks
TODO Ho
1361 1362 1363 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/irc.rb', line 1361 def user_nicks @users.map { |u| u.downcase } end |