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 own username and the avatar). It can be accessed using Bot#profile.

Instance Attribute Summary

Attributes inherited from User

#game, #status, #stream_type, #stream_url

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, #send_file, #webhook?

Methods included from UserAttributes

#avatar_url, #distinct, #mention

Methods included from IDObject

#==, #creation_time, synthesise

Constructor Details

#initialize(data, bot) ⇒ Profile

Returns a new instance of Profile.



682
683
684
# File 'lib/discordrb/data.rb', line 682

def initialize(data, bot)
  super(data, bot)
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 Object) or as a data URL.



703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/discordrb/data.rb', line 703

def avatar=(avatar)
  if avatar.respond_to? :read
    # Set the file to binary mode if supported, so we don't get problems with Windows
    avatar.binmode if avatar.respond_to?(:binmode)

    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)


688
689
690
# File 'lib/discordrb/data.rb', line 688

def current_bot?
  true
end

#dndObject Also known as: busy

Note:

Only usable on User accounts.

Sets the user status setting to Do Not Disturb.



738
739
740
# File 'lib/discordrb/data.rb', line 738

def dnd
  update_profile_status_setting('dnd')
end

#idleObject

Note:

Only usable on User accounts.

Sets the user status setting to Idle.



732
733
734
# File 'lib/discordrb/data.rb', line 732

def idle
  update_profile_status_setting('idle')
end

#inspectObject

The inspect method is overwritten to give more useful output



751
752
753
# File 'lib/discordrb/data.rb', line 751

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

#invisibleObject

Note:

Only usable on User accounts.

Sets the user status setting to Invisible.



746
747
748
# File 'lib/discordrb/data.rb', line 746

def invisible
  update_profile_status_setting('invisible')
end

#onlineObject

Note:

Only usable on User accounts.

Sets the user status setting to Online.



726
727
728
# File 'lib/discordrb/data.rb', line 726

def online
  update_profile_status_setting('online')
end

#username=(username) ⇒ Object Also known as: name=

Sets the bot's username.

Parameters:

  • username (String)

    The new username.



694
695
696
# File 'lib/discordrb/data.rb', line 694

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