class Discordrb::Profile

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}.

Public Instance Methods

avatar=(avatar) click to toggle source

Changes the bot’s avatar. @param avatar [String, read] A JPG file to be used as the avatar, either

something readable (e.g. File Object) or as a data URL.
# File lib/discordrb/data/profile.rb, line 24
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
busy()
Alias for: dnd
current_bot?() click to toggle source

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

# File lib/discordrb/data/profile.rb, line 9
def current_bot?
  true
end
dnd() click to toggle source

Sets the user status setting to Do Not Disturb. @note Only usable on User accounts.

# File lib/discordrb/data/profile.rb, line 59
def dnd
  update_profile_status_setting('dnd')
end
Also aliased as: busy
idle() click to toggle source

Sets the user status setting to Idle. @note Only usable on User accounts.

# File lib/discordrb/data/profile.rb, line 53
def idle
  update_profile_status_setting('idle')
end
inspect() click to toggle source

The inspect method is overwritten to give more useful output

# File lib/discordrb/data/profile.rb, line 72
def inspect
  "<Profile user=#{super}>"
end
invisible() click to toggle source

Sets the user status setting to Invisible. @note Only usable on User accounts.

# File lib/discordrb/data/profile.rb, line 67
def invisible
  update_profile_status_setting('invisible')
end
name=(username)
Alias for: username=
online() click to toggle source

Sets the user status setting to Online. @note Only usable on User accounts.

# File lib/discordrb/data/profile.rb, line 47
def online
  update_profile_status_setting('online')
end
update_data(new_data) click to toggle source

Updates the cached profile data with the new one. @note For internal use only. @!visibility private

# File lib/discordrb/data/profile.rb, line 40
def update_data(new_data)
  @username = new_data[:username] || @username
  @avatar_id = new_data[:avatar_id] || @avatar_id
end
username=(username) click to toggle source

Sets the bot’s username. @param username [String] The new username.

# File lib/discordrb/data/profile.rb, line 15
def username=(username)
  update_profile_data(username: username)
end
Also aliased as: name=

Private Instance Methods

update_profile_data(new_data) click to toggle source
# File lib/discordrb/data/profile.rb, line 83
def update_profile_data(new_data)
  API::User.update_profile(@bot.token,
                           nil, nil,
                           new_data[:username] || @username,
                           new_data.key?(:avatar) ? new_data[:avatar] : @avatar_id)
  update_data(new_data)
end
update_profile_status_setting(status) click to toggle source

Internal handler for updating the user’s status setting

# File lib/discordrb/data/profile.rb, line 79
def update_profile_status_setting(status)
  API::User.change_status_setting(@bot.token, status)
end