Class: Discordrb::Profile

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

Overview

This class is a special variant of User that represents the bot's user profile (things like email addresses and the avatar). It can be accessed using Bot#profile.

Instance Attribute Summary

Attributes inherited from User

#game, #status

Attributes included from UserAttributes

#avatar_id, #bot_account, #discriminator, #username

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods inherited from User

#await, #on, #pm

Methods included from UserAttributes

#avatar_url, #distinct, #mention

Methods included from IDObject

#==, #creation_time

Constructor Details

#initialize(data, bot, email, password) ⇒ Profile

Returns a new instance of Profile.



403
404
405
406
407
# File 'lib/discordrb/data.rb', line 403

def initialize(data, bot, email, password)
  super(data, bot)
  @email = email
  @password = password
end

Instance Method Details

#avatar=(avatar) ⇒ Object

Changes the bot's avatar.

Parameters:

  • avatar (String, #read)

    A JPG file to be used as the avatar, either something readable (e. g. File) or as a data URL.



437
438
439
440
441
442
443
444
445
# File 'lib/discordrb/data.rb', line 437

def avatar=(avatar)
  if avatar.respond_to? :read
    avatar_string = 'data:image/jpg;base64,'
    avatar_string += Base64.strict_encode64(avatar.read)
    update_profile_data(avatar: avatar_string)
  else
    update_profile_data(avatar: avatar)
  end
end

#current_bot?true

Whether or not the user is the bot. The Profile can only ever be the bot user, so this always returns true.

Returns:

  • (true)


411
412
413
# File 'lib/discordrb/data.rb', line 411

def current_bot?
  true
end

#email=(email) ⇒ Object

Sets the bot's email address. If you use this method, make sure that the login email in the script matches this one afterwards, so the bot doesn't have any trouble logging in in the future.

Parameters:

  • email (String)

    The new email address.



424
425
426
# File 'lib/discordrb/data.rb', line 424

def email=(email)
  update_profile_data(email: email)
end

#inspectObject

The inspect method is overwritten to give more useful output



458
459
460
# File 'lib/discordrb/data.rb', line 458

def inspect
  "<Profile email=#{@email} user=#{super}>"
end

#password=(password) ⇒ Object

Changes the bot's password. This will invalidate all tokens so you will have to relog the bot.

Parameters:

  • password (String)

    The new password.



430
431
432
# File 'lib/discordrb/data.rb', line 430

def password=(password)
  update_profile_data(new_password: password)
end

#username=(username) ⇒ Object

Sets the bot's username.

Parameters:

  • username (String)

    The new username.



417
418
419
# File 'lib/discordrb/data.rb', line 417

def username=(username)
  update_profile_data(username: username)
end