class Irc::User
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:
-
see if it’s worth to add the other USER data
-
see if it’s worth to add NICKSERV status
Attributes
Public Class Methods
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.
Irc::Netmask::new
# File lib/rbot/irc.rb, line 953 def initialize(str="", opts={}) super raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if nick.has_irc_glob? && nick != "*" raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if user.has_irc_glob? && user != "*" raise ArgumentError, "#{str.inspect} must not have globs (unescaped * or ?)" if host.has_irc_glob? && host != "*" @away = false @real_name = String.new @idle_since = nil @signon = nil end
Public Instance Methods
Set the away status of the user. Use away=(nil) or away=(false) to unset away
# File lib/rbot/irc.rb, line 1004 def away=(msg="") if msg @away = msg else @away = false end end
Is the user away?
# File lib/rbot/irc.rb, line 997 def away? return @away end
Retrive Bot
data associated with the receiver. This method is intended for data retrieval only. See set_bot_data() if you need to alter User
data.
# File lib/rbot/core/userdata.rb, line 14 def botdata(key=nil) Irc::Utils.bot.plugins['userdata'].get_data(self,key) end
A convenience method to automatically found the botuser associated with the receiver
# File lib/rbot/botuser.rb, line 935 def botuser Irc::Bot::Auth.manager.irc_to_botuser(self) end
# File lib/rbot/irc.rb, line 1068 def channels if @server @server.channels.select { |ch| ch.has_user?(self) } else Array.new end end
This method removes the data associated with the key, returning the value of the deleted key.
# File lib/rbot/core/userdata.rb, line 44 def delete_botdata(*keys) Irc::Utils.bot.plugins['userdata'].delete_data(self, *keys) 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.
Irc::Netmask#host=
# File lib/rbot/irc.rb, line 984 def host=(newhost) raise "Can't change the hostname to #{newhost}" if defined?(@host) and newhost.has_irc_glob? super end
# File lib/rbot/irc.rb, line 1048 def is_op?(channel) case channel when Channel channel.has_op?(self) else return @server.channel(channel).has_op?(self) if @server raise "Can't resolve channel #{channel}" end end
# File lib/rbot/irc.rb, line 1058 def is_voice?(channel) case channel when Channel channel.has_voice?(self) else return @server.channel(channel).has_voice?(self) if @server raise "Can't resolve channel #{channel}" end end
Checks if a User
is well-known or not by looking at the hostname and user
# File lib/rbot/irc.rb, line 991 def known? return nick != "*" && user != "*" && host != "*" end
# File lib/rbot/irc.rb, line 1038 def modes_on(channel) case channel when Channel channel.modes_of(self) else return @server.channel(channel).modes_of(self) if @server raise "Can't resolve channel #{channel}" end end
The nick of a User
may be changed freely, but it must not contain glob patterns.
Irc::Netmask#nick=
# File lib/rbot/irc.rb, line 966 def nick=(newnick) raise "Can't change the nick to #{newnick}" if defined?(@nick) and newnick.has_irc_glob? super end
We can replace everything at once with data from another User
# File lib/rbot/irc.rb, line 1024 def replace(other) case other when User self.nick = other.nick self.user = other.user self.host = other.host @server = other.server @casemap = other.casemap unless @server @away = other.away? else self.replace(other.to_irc_user(server_and_casemap)) end end
This method is used to store Bot
data associated with the receiver. If no block is passed, value is stored for the key key; if a block is passed, it will be called with the previous key value as parameter, and its return value will be stored as the new value. If value is present in the block form, it will be used to initialize key if it’s missing.
If you have to do large-scale editing of the Bot
data Hash, please use with_botdata.
# File lib/rbot/core/userdata.rb, line 29 def set_botdata(key, value=nil, &block) Irc::Utils.bot.plugins['userdata'].set_data(self, key, value, &block) 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 def to_irc_user(opts={}) return self if fits_with_server_and_casemap?(opts) return self.full_downcase.to_irc_user(opts) 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.
Irc::Netmask#user=
# File lib/rbot/irc.rb, line 975 def user=(newuser) raise "Can't change the username to #{newuser}" if defined?(@user) and newuser.has_irc_glob? super end
This method yields the entire Bot
data Hash to the block, and stores any changes done to it, returning a copy of the (changed) Hash.
# File lib/rbot/core/userdata.rb, line 37 def with_botdata(&block) Irc::Utils.bot.plugins['userdata'].with_data(self, &block) end