Class Irc::Channel
In: lib/rbot/irc.rb
Parent: Object
BasicUserMessage JoinMessage NamesMessage WhoisMessage ModeChangeMessage KickMessage MotdMessage QuitMessage BanlistMessage UserMessage NoSuchTargetMessage TopicMessage NickMessage WelcomeMessage UnknownMessage InviteMessage PartMessage NetmaskList UserList ArrayOf ChannelList Netmask User\n[lib/rbot/botuser.rb\nlib/rbot/irc.rb] Channel Singleton RfcCasemap StrictRfcCasemap AsciiCasemap Casemap PrivMessage NoticeMessage TokyoCabinet::BDB CIBDB Btree CIBtree Socket MessageQueue QueueRing Client DBHash\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] DBTree\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] Server NetmaskDb Bot\n[lib/rbot/botuser.rb\nlib/rbot/config.rb\nlib/rbot/ircbot.rb\nlib/rbot/language.rb\nlib/rbot/message.rb\nlib/rbot/messagemapper.rb\nlib/rbot/plugins.rb\nlib/rbot/rbotconfig.rb\nlib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] lib/rbot/ircsocket.rb lib/rbot/rfc2812.rb lib/rbot/registry/tc.rb lib/rbot/irc.rb lib/rbot/maskdb.rb lib/rbot/message.rb lib/rbot/messagemapper.rb lib/rbot/botuser.rb lib/rbot/registry/tc.rb (null) BotConfig PKGConfig ServerOrCasemap Irc dot/m_35_0.png

Here we start with the actual Channel class

Methods

Included Modules

ServerOrCasemap

Classes and Modules

Class Irc::Channel::Mode
Class Irc::Channel::ModeHash
Class Irc::Channel::ModeTypeA
Class Irc::Channel::ModeTypeB
Class Irc::Channel::ModeTypeC
Class Irc::Channel::ModeTypeD
Class Irc::Channel::Topic
Class Irc::Channel::UserMode

External Aliases

name -> to_s

Attributes

creation_time  [RW] 
mode  [R] 
name  [R] 
topic  [R] 
url  [RW] 
users  [R] 

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.

[Source]

      # File lib/rbot/irc.rb, line 1395
1395:     def initialize(name, topic=nil, users=[], opts={})
1396:       raise ArgumentError, "Channel name cannot be empty" if name.to_s.empty?
1397:       warn "Unknown channel prefix #{name[0,1]}" if name !~ /^[&#+!]/
1398:       raise ArgumentError, "Invalid character in #{name.inspect}" if name =~ /[ \x07,]/
1399: 
1400:       init_server_or_casemap(opts)
1401: 
1402:       @name = name
1403: 
1404:       @topic = topic ? topic.to_irc_channel_topic : Channel::Topic.new
1405: 
1406:       @users = UserList.new
1407: 
1408:       users.each { |u|
1409:         add_user(u)
1410:       }
1411: 
1412:       # Flags
1413:       @mode = ModeHash.new
1414: 
1415:       # creation time, only on some networks
1416:       @creation_time = nil
1417: 
1418:       # URL, only on some networks
1419:       @url = nil
1420:     end

Return the non-prefixed part of a channel name. Also works with ## channels found on some networks (e.g. FreeNode)

[Source]

      # File lib/rbot/irc.rb, line 1335
1335:     def self.npname(str)
1336:       return str.to_s.sub(/^[&#+!]+/,'')
1337:     end

Public Instance methods

Adds a user to the channel

[Source]

      # File lib/rbot/irc.rb, line 1380
1380:     def add_user(user, opts={})
1381:       silent = opts.fetch(:silent, false)
1382:       if has_user?(user)
1383:         warn "Trying to add user #{user} to channel #{self} again" unless silent
1384:       else
1385:         @users << user.to_irc_user(server_and_casemap)
1386:       end
1387:     end

Create a new mode

[Source]

      # File lib/rbot/irc.rb, line 1463
1463:     def create_mode(sym, kl)
1464:       @mode[sym.to_sym] = kl.new(self)
1465:     end

Removes a user from the channel

[Source]

      # File lib/rbot/irc.rb, line 1424
1424:     def delete_user(user)
1425:       @mode.each { |sym, mode|
1426:         mode.reset(user) if mode.kind_of?(UserMode)
1427:       }
1428:       @users.delete(user)
1429:     end

Returns the user with nick nick, if available

[Source]

      # File lib/rbot/irc.rb, line 1373
1373:     def get_user(nick)
1374:       idx = has_user?(nick)
1375:       @users[idx] if idx
1376:     end

[Source]

      # File lib/rbot/irc.rb, line 1475
1475:     def has_op?(user)
1476:       @mode.has_key?(:o) and @mode[:o].list[user]
1477:     end

Checks if the receiver already has a user with the given nick

[Source]

      # File lib/rbot/irc.rb, line 1367
1367:     def has_user?(nick)
1368:       @users.index(nick.to_irc_user(server_and_casemap))
1369:     end

[Source]

      # File lib/rbot/irc.rb, line 1479
1479:     def has_voice?(user)
1480:       @mode.has_key?(:v) and @mode[:v].list[user]
1481:     end

[Source]

      # File lib/rbot/irc.rb, line 1344
1344:     def inspect
1345:       str = self.__to_s__[0..-2]
1346:       str << " on server #{server}" if server
1347:       str << " @name=#{@name.inspect} @topic=#{@topic.text.inspect}"
1348:       str << " @users=[#{user_nicks.sort.join(', ')}]"
1349:       str << " (created on #{creation_time})" if creation_time
1350:       str << " (URL #{url})" if url
1351:       str << ">"
1352:     end

A channel is local to a server if it has the ’&’ prefix

[Source]

      # File lib/rbot/irc.rb, line 1439
1439:     def local?
1440:       name[0,1] == '&'
1441:     end

A channel is modeless if it has the ’+’ prefix

[Source]

      # File lib/rbot/irc.rb, line 1445
1445:     def modeless?
1446:       name[0,1] == '+'
1447:     end

[Source]

      # File lib/rbot/irc.rb, line 1467
1467:     def modes_of(user)
1468:       l = []
1469:       @mode.map { |s, m|
1470:         l << s if (m.class <= UserMode and m.list[user])
1471:       }
1472:       l
1473:     end

A channel is normal if it has the ’#’ prefix

[Source]

      # File lib/rbot/irc.rb, line 1457
1457:     def normal?
1458:       name[0,1] == '#'
1459:     end

The channel prefix

[Source]

      # File lib/rbot/irc.rb, line 1433
1433:     def prefix
1434:       name[0,1]
1435:     end

A channel is safe if it has the ’!’ prefix

[Source]

      # File lib/rbot/irc.rb, line 1451
1451:     def safe?
1452:       name[0,1] == '!'
1453:     end

Returns self

[Source]

      # File lib/rbot/irc.rb, line 1356
1356:     def to_irc_channel
1357:       self
1358:     end

TODO Ho

[Source]

      # File lib/rbot/irc.rb, line 1361
1361:     def user_nicks
1362:       @users.map { |u| u.downcase }
1363:     end

[Validate]