Class Irc::User
In: lib/rbot/irc.rb
lib/rbot/botuser.rb
Parent: Netmask
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

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

Methods

away=   away?   botuser   channels   host=   is_op?   is_voice?   known?   modes_on   new   nick=   replace   to_irc_user   user=  

External Aliases

nick -> to_s

Attributes

idle_since  [RW] 
real_name  [RW] 
signon  [RW] 

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.

[Source]

     # 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

Public Instance methods

Set the away status of the user. Use away=(nil) or away=(false) to unset away

[Source]

      # File lib/rbot/irc.rb, line 1004
1004:     def away=(msg="")
1005:       if msg
1006:         @away = msg
1007:       else
1008:         @away = false
1009:       end
1010:     end

Is the user away?

[Source]

     # File lib/rbot/irc.rb, line 997
997:     def away?
998:       return @away
999:     end

A convenience method to automatically found the botuser associated with the receiver

[Source]

     # File lib/rbot/botuser.rb, line 935
935:     def botuser
936:       Irc::Bot::Auth.manager.irc_to_botuser(self)
937:     end

[Source]

      # 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.

[Source]

     # 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

[Source]

      # 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

[Source]

      # 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

Checks if a User is well-known or not by looking at the hostname and user

[Source]

     # File lib/rbot/irc.rb, line 991
991:     def known?
992:       return nick != "*" && user != "*" && host != "*"
993:     end

[Source]

      # 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

The nick of a User may be changed freely, but it must not contain glob patterns.

[Source]

     # File lib/rbot/irc.rb, line 966
966:     def nick=(newnick)
967:       raise "Can't change the nick to #{newnick}" if defined?(@nick) and newnick.has_irc_glob?
968:       super
969:     end

We can replace everything at once with data from another User

[Source]

      # 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.

[Source]

      # 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.

[Source]

     # 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

[Validate]