Class: Discordrb::User

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, bot) ⇒ User

Returns a new instance of User.



12
13
14
15
16
17
18
19
20
21
# File 'lib/discordrb/data.rb', line 12

def initialize(data, bot)
  @bot = bot

  @username = data['username']
  @id = data['id'].to_i
  @discriminator = data['discriminator']
  @avatar = data['avatar']
  
  @status = :offline
end

Instance Attribute Details

#avatarObject (readonly)

Returns the value of attribute avatar.



5
6
7
# File 'lib/discordrb/data.rb', line 5

def avatar
  @avatar
end

#discriminatorObject (readonly)

Returns the value of attribute discriminator.



5
6
7
# File 'lib/discordrb/data.rb', line 5

def discriminator
  @discriminator
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/discordrb/data.rb', line 5

def id
  @id
end

#statusObject (readonly)

Is the user online, offline, or away?



8
9
10
# File 'lib/discordrb/data.rb', line 8

def status
  @status
end

#usernameObject (readonly) Also known as: name

Returns the value of attribute username.



5
6
7
# File 'lib/discordrb/data.rb', line 5

def username
  @username
end

Instance Method Details

#mentionObject

Utility function to mention users in messages



24
25
26
# File 'lib/discordrb/data.rb', line 24

def mention
  "<@#{@id}>"
end

#pm(content = nil) ⇒ Object

Utility function to send a PM



29
30
31
32
33
34
35
36
37
38
# File 'lib/discordrb/data.rb', line 29

def pm(content = nil)
  if content
    # Recursively call pm to get the channel, then send a message to it
    channel = pm
    channel.send_message(content)
  else
    # If no message was specified, return the PM channel
    @bot.private_channel(@id)
  end
end