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.



8
9
10
11
12
13
14
# File 'lib/discordrb/data.rb', line 8

def initialize(data, bot)
  @bot = bot
  @username = data['username']
  @id = data['id'].to_i
  @discriminator = data['discriminator']
  @avatar = data['avatar']
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

#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



17
18
19
# File 'lib/discordrb/data.rb', line 17

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

#pm(content = nil) ⇒ Object

Utility function to send a PM



22
23
24
25
26
27
28
29
30
31
# File 'lib/discordrb/data.rb', line 22

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