Class: IRC::StatefulUser

Inherits:
Object
  • Object
show all
Defined in:
lib/rhuidean/stateful_user.rb

Overview

Represents a user on IRC. Each nickname should only have one of these objects, no matter how many channels they’re in. If we can’t see them in any channels they disappear.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nickname, client) ⇒ StatefulUser

Creates a new StatefulUser.


nickname

the user’s nickname, as a string

client

the IRC::Client that sees us

returns::+ self+



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rhuidean/stateful_user.rb', line 32

def initialize(nickname, client)
    # The Client we belong to
    @client = client

    # StatefulChannels we're on, keyed by name
    @channels = IRCHash.new(@client.casemapping)

    # Status modes on channels, keyed by channel name (:oper, :voice)
    @modes = {}

    # The user's nickname
    @nickname = nickname
end

Instance Attribute Details

#channelsObject (readonly)

instance attributes



22
23
24
# File 'lib/rhuidean/stateful_user.rb', line 22

def channels
  @channels
end

#modesObject (readonly)

instance attributes



22
23
24
# File 'lib/rhuidean/stateful_user.rb', line 22

def modes
  @modes
end

#nicknameObject

Returns the value of attribute nickname.



23
24
25
# File 'lib/rhuidean/stateful_user.rb', line 23

def nickname
  @nickname
end

Instance Method Details

#add_status_mode(flag, channel) ⇒ Object

Give us a status mode on a channel.


flag

Symbol representing a mode flag

channel

either a StatefulChannel or the name of one

returns

self



92
93
94
95
96
97
# File 'lib/rhuidean/stateful_user.rb', line 92

def add_status_mode(flag, channel)
    if channel.class == StatefulChannel then channel = channel.name end
    (@modes[channel] ||= []) << flag

    self
end

#delete_status_mode(flag, channel) ⇒ Object

Take away a status mode on a channel.


flag

Symbol representing a mode flag

channel

either a StatefulChannel or the name of one

returns

self



106
107
108
109
110
111
112
113
# File 'lib/rhuidean/stateful_user.rb', line 106

def delete_status_mode(flag, channel)
    if channel.class == StatefulChannel then channel = channel.name end
    return unless @modes[channel]

    @modes[channel].delete(flag)

    self
end

#join_channel(channel) ⇒ Object

Add a channel to our joined-list.


channel

the StatefulChannel to add

returns

self



65
66
67
68
69
# File 'lib/rhuidean/stateful_user.rb', line 65

def join_channel(channel)
    @channels[channel.name] = channel

    self
end

#part_channel(channel) ⇒ Object

Remove a channel from our joined-list. Also clears our status modes for that channel.


channel

the StatefulChannel to remove

returns

self



78
79
80
81
82
83
# File 'lib/rhuidean/stateful_user.rb', line 78

def part_channel(channel)
    @modes.delete(channel.name)
    @channels.delete(channel.name)

    self
end

#to_sObject

Represent ourselves in a string.


returns

our nickname



55
56
57
# File 'lib/rhuidean/stateful_user.rb', line 55

def to_s
    @nickname
end