Class: Discordrb::User
- Inherits:
-
Object
- Object
- Discordrb::User
- Defined in:
- lib/discordrb/data.rb
Instance Attribute Summary collapse
-
#avatar ⇒ Object
readonly
Returns the value of attribute avatar.
-
#discriminator ⇒ Object
readonly
Returns the value of attribute discriminator.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#username ⇒ Object
(also: #name)
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(data, bot) ⇒ User
constructor
A new instance of User.
-
#mention ⇒ Object
Utility function to mention users in messages.
-
#pm(content = nil) ⇒ Object
Utility function to send a PM.
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
#avatar ⇒ Object (readonly)
Returns the value of attribute avatar.
5 6 7 |
# File 'lib/discordrb/data.rb', line 5 def avatar @avatar end |
#discriminator ⇒ Object (readonly)
Returns the value of attribute discriminator.
5 6 7 |
# File 'lib/discordrb/data.rb', line 5 def discriminator @discriminator end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/discordrb/data.rb', line 5 def id @id end |
#username ⇒ Object (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
#mention ⇒ Object
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.(content) else # If no message was specified, return the PM channel @bot.private_channel(@id) end end |