class Blur::User
The User
class is used for encapsulating a user and its properties.
The user owns a reference to its parent channel.
Modes can be set for a user, but Blur
is not {www.irc.org/tech_docs/005.html ISupport}-compliant yet.
@todo make so that channels and users belongs to the network, and not
like now where the user belongs to the channel, resulting in multiple user instances.
Attributes
@return [String] the users hostname.
@return [String] all the modes set on the user.
@return [String] the users username.
@return [Network] a reference to the network.
@return [String] the users nickname.
Public Class Methods
Instantiate a user with a nickname.
# File library/blur/user.rb, line 39 def initialize nick, network = nil @nick = nick @modes = String.new @channels = [] @network = network if modes = prefix_to_mode(nick[0]) @nick = nick[1..-1] @modes = modes end end
Public Instance Methods
Check to see if the user is an admin (+a)
# File library/blur/user.rb, line 28 def admin?; @modes.include? "a" end
Check to see if the user is an half-operator (+h)
# File library/blur/user.rb, line 36 def half_operator?; @modes.include? "h" end
Convert it to a debug-friendly format.
# File library/blur/user.rb, line 77 def inspect %{#<#{self.class.name}:0x#{self.object_id.to_s 16} @nick=#{@nick.inspect}>} end
Merge the users mode corresponding to the leading character (+ or -).
@param [String] modes the modes to merge with.
# File library/blur/user.rb, line 54 def merge_modes modes addition = true modes.each_char do |char| case char when ?+ addition = true when ?- addition = false else addition ? @modes.concat(char) : @modes.delete!(char) end end end
Check to see if the user is an operator (+o)
# File library/blur/user.rb, line 34 def operator?; @modes.include? "o" end
Check to see if the user is the owner (+q)
# File library/blur/user.rb, line 32 def owner?; @modes.include? "q" end
Send a private message to the user.
@param [String] message the message to send.
# File library/blur/user.rb, line 72 def say message @network.say self, message end
Get the users nickname.
# File library/blur/user.rb, line 88 def to_s @nick end
Called when YAML attempts to save the object, which happens when a scripts cache contains this user and the script is unloaded.
# File library/blur/user.rb, line 83 def to_yaml options = {} @nick.to_yaml options end
Check to see if the user has voice (+v)
# File library/blur/user.rb, line 30 def voice?; @modes.include? "v" end
Private Instance Methods
Translate a nickname-prefix to a mode character.
# File library/blur/user.rb, line 95 def prefix_to_mode prefix case prefix when '@' then 'o' when '+' then 'v' when '%' then 'h' when '&' then 'a' when '~' then 'q' end end