Class | Irc::Channel |
In: |
lib/rbot/irc.rb
|
Parent: | Object |
Here we start with the actual Channel class
name | -> | to_s |
creation_time | [RW] | |
mode | [R] | |
name | [R] | |
topic | [R] | |
url | [RW] | |
users | [R] |
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 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)
# File lib/rbot/irc.rb, line 1335 1335: def self.npname(str) 1336: return str.to_s.sub(/^[&#+!]+/,'') 1337: end
Adds a user to the channel
# 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
Removes a user from the channel
# 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
# File lib/rbot/irc.rb, line 1373 1373: def get_user(nick) 1374: idx = has_user?(nick) 1375: @users[idx] if idx 1376: end
# 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
# File lib/rbot/irc.rb, line 1367 1367: def has_user?(nick) 1368: @users.index(nick.to_irc_user(server_and_casemap)) 1369: end
# File lib/rbot/irc.rb, line 1479 1479: def has_voice?(user) 1480: @mode.has_key?(:v) and @mode[:v].list[user] 1481: end
# 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
# 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