Class: Blur::User

Inherits:
Object
  • Object
show all
Defined in:
library/blur/user.rb

Overview

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.

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 ISupport-compliant yet.

Constant Summary collapse

COMMON_SYMBOL_MODES =

Returns a map of symbols to channel user modes.

Returns:

  • (Hash<String, String>)

    a map of symbols to channel user modes.

{
  '@' => 'o',
  '+' => 'v',
  '%' => 'h',
  '&' => 'a',
  '~' => 'q'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nick, network = nil) ⇒ User

Instantiate a user with a nickname.



62
63
64
65
66
67
68
69
70
71
72
# File 'library/blur/user.rb', line 62

def initialize nick, network = nil
  @nick  = nick
  @modes = String.new
  @channels = []
  @network = network

  return unless (modes = prefix_to_mode(nick[0]))

  @nick  = nick[1..]
  @modes = modes
end

Instance Attribute Details

#channelsObject

Returns the value of attribute channels.



25
26
27
# File 'library/blur/user.rb', line 25

def channels
  @channels
end

#hostString

Returns the users hostname.

Returns:

  • (String)

    the users hostname.



20
21
22
# File 'library/blur/user.rb', line 20

def host
  @host
end

#modesString

Returns all the modes set on the user.

Returns:

  • (String)

    all the modes set on the user.



22
23
24
# File 'library/blur/user.rb', line 22

def modes
  @modes
end

#nameString

Returns the users username.

Returns:

  • (String)

    the users username.



18
19
20
# File 'library/blur/user.rb', line 18

def name
  @name
end

#networkNetwork

Returns a reference to the network.

Returns:

  • (Network)

    a reference to the network.



24
25
26
# File 'library/blur/user.rb', line 24

def network
  @network
end

#nickString

Returns the users nickname.

Returns:

  • (String)

    the users nickname.



16
17
18
# File 'library/blur/user.rb', line 16

def nick
  @nick
end

Instance Method Details

#admin?Boolean

Check to see if the user is an admin (+a)

Returns:

  • (Boolean)


37
38
39
# File 'library/blur/user.rb', line 37

def admin?
  @modes.include? 'a'
end

#half_operator?Boolean

Check to see if the user is an half-operator (+h)

Returns:

  • (Boolean)


57
58
59
# File 'library/blur/user.rb', line 57

def half_operator?
  @modes.include? 'h'
end

#inspectObject

Convert it to a debug-friendly format.



100
101
102
# File 'library/blur/user.rb', line 100

def inspect
  %(#<#{self.class.name}:0x#{object_id.to_s 16} @nick=#{@nick.inspect}>)
end

#merge_modes(modes) ⇒ Object

Merge the users mode corresponding to the leading character (+ or -).

Parameters:

  • modes (String)

    the modes to merge with.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'library/blur/user.rb', line 77

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

#operator?Boolean

Check to see if the user is an operator (+o)

Returns:

  • (Boolean)


52
53
54
# File 'library/blur/user.rb', line 52

def operator?
  @modes.include? 'o'
end

#owner?Boolean

Check to see if the user is the owner (+q)

Returns:

  • (Boolean)


47
48
49
# File 'library/blur/user.rb', line 47

def owner?
  @modes.include? 'q'
end

#say(message) ⇒ Object

Send a private message to the user.

Parameters:

  • message (String)

    the message to send.



95
96
97
# File 'library/blur/user.rb', line 95

def say message
  @network.say self, message
end

#to_sObject

Get the users nickname.



111
112
113
# File 'library/blur/user.rb', line 111

def to_s
  @nick
end

#to_yaml(options = {}) ⇒ Object

Called when YAML attempts to save the object, which happens when a scripts cache contains this user and the script is unloaded.



106
107
108
# File 'library/blur/user.rb', line 106

def to_yaml options = {}
  @nick.to_yaml options
end

#voice?Boolean

Check to see if the user has voice (+v)

Returns:

  • (Boolean)


42
43
44
# File 'library/blur/user.rb', line 42

def voice?
  @modes.include? 'v'
end