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
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
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
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
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
The inspect method is overwritten to give more useful output
# File lib/discordrb/data/profile.rb, line 72 def inspect "<Profile user=#{super}>" end
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
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
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
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
Private Instance Methods
# 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
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