Class | Irc::User |
In: |
lib/rbot/irc.rb
lib/rbot/botuser.rb |
Parent: | Netmask |
An IRC User is identified by his/her Netmask (which must not have globs). In fact, User is just a subclass of Netmask.
Ideally, the user and host information of an IRC User should never change, and it shouldn‘t contain glob patterns. However, IRC is somewhat idiosincratic and it may be possible to know the nick of a User much before its user and host are known. Moreover, some networks (namely Freenode) may change the hostname of a User when (s)he identifies with Nickserv.
As a consequence, we must allow changes to a User host and user attributes. We impose a restriction, though: they may not contain glob patterns, except for the special case of an unknown user/host which is represented by a *.
It is possible to create a totally unknown User (e.g. for initializations) by setting the nick to * too.
TODO list:
nick | -> | to_s |
idle_since | [RW] | |
real_name | [RW] | |
signon | [RW] |
Create a new IRC User from a given Netmask (or anything that can be converted into a Netmask) provided that the given Netmask does not have globs.
# File lib/rbot/irc.rb, line 953 953: def initialize(str="", opts={}) 954: super 955: raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if nick.has_irc_glob? && nick != "*" 956: raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if user.has_irc_glob? && user != "*" 957: raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if host.has_irc_glob? && host != "*" 958: @away = false 959: @real_name = String.new 960: @idle_since = nil 961: @signon = nil 962: end
# File lib/rbot/irc.rb, line 1068 1068: def channels 1069: if @server 1070: @server.channels.select { |ch| ch.has_user?(self) } 1071: else 1072: Array.new 1073: end 1074: end
We have to allow changing the host of an Irc User due to some networks (e.g. Freenode) changing hostmasks on the fly. We still check if the new host data has glob patterns though.
# File lib/rbot/irc.rb, line 984 984: def host=(newhost) 985: raise "Can't change the hostname to #{newhost}" if defined?(@host) and newhost.has_irc_glob? 986: super 987: end
# File lib/rbot/irc.rb, line 1048 1048: def is_op?(channel) 1049: case channel 1050: when Channel 1051: channel.has_op?(self) 1052: else 1053: return @server.channel(channel).has_op?(self) if @server 1054: raise "Can't resolve channel #{channel}" 1055: end 1056: end
# File lib/rbot/irc.rb, line 1058 1058: def is_voice?(channel) 1059: case channel 1060: when Channel 1061: channel.has_voice?(self) 1062: else 1063: return @server.channel(channel).has_voice?(self) if @server 1064: raise "Can't resolve channel #{channel}" 1065: end 1066: end
# File lib/rbot/irc.rb, line 1038 1038: def modes_on(channel) 1039: case channel 1040: when Channel 1041: channel.modes_of(self) 1042: else 1043: return @server.channel(channel).modes_of(self) if @server 1044: raise "Can't resolve channel #{channel}" 1045: end 1046: end
We can replace everything at once with data from another User
# File lib/rbot/irc.rb, line 1024 1024: def replace(other) 1025: case other 1026: when User 1027: self.nick = other.nick 1028: self.user = other.user 1029: self.host = other.host 1030: @server = other.server 1031: @casemap = other.casemap unless @server 1032: @away = other.away? 1033: else 1034: self.replace(other.to_irc_user(server_and_casemap)) 1035: end 1036: end
Since to_irc_user runs the same checks on server and channel as to_irc_netmask, we just try that and return self if it works.
Subclasses of User will return self if possible.
# File lib/rbot/irc.rb, line 1017 1017: def to_irc_user(opts={}) 1018: return self if fits_with_server_and_casemap?(opts) 1019: return self.full_downcase.to_irc_user(opts) 1020: end
We have to allow changing the user of an Irc User due to some networks (e.g. Freenode) changing hostmasks on the fly. We still check if the new user data has glob patterns though.
# File lib/rbot/irc.rb, line 975 975: def user=(newuser) 976: raise "Can't change the username to #{newuser}" if defined?(@user) and newuser.has_irc_glob? 977: super 978: end