@@ -19,8 +19,8 @@ def username=(username)
1919 alias_method :name= , :username=
2020
2121 # Changes the bot's avatar.
22- # @param avatar [String, #read] A JPG file to be used as the avatar, either
23- # something readable (e.g. File Object) or as a data URL .
22+ # @param avatar [String, File, #read, nil ] A file to be used as the avatar, either
23+ # something readable (e.g. File Object) or a data URI .
2424 def avatar = ( avatar )
2525 if avatar . respond_to? ( :read )
2626 update_profile_data ( avatar : Discordrb . encode64 ( avatar ) )
@@ -29,38 +29,24 @@ def avatar=(avatar)
2929 end
3030 end
3131
32+ # Changes the bot's banner.
33+ # @param banner [String, File, #read, nil] A file to be used as the banner, either
34+ # something readable (e.g. File Object) or a data URI.
35+ def banner = ( banner )
36+ if banner . respond_to? ( :read )
37+ update_profile_data ( banner : Discordrb . encode64 ( banner ) )
38+ else
39+ update_profile_data ( banner : banner )
40+ end
41+ end
42+
3243 # Updates the cached profile data with the new one.
3344 # @note For internal use only.
3445 # @!visibility private
3546 def update_data ( new_data )
36- @username = new_data [ :username ] || @username
37- @avatar_id = new_data [ :avatar_id ] || @avatar_id
38- end
39-
40- # Sets the user status setting to Online.
41- # @note Only usable on User accounts.
42- def online
43- update_profile_status_setting ( 'online' )
44- end
45-
46- # Sets the user status setting to Idle.
47- # @note Only usable on User accounts.
48- def idle
49- update_profile_status_setting ( 'idle' )
50- end
51-
52- # Sets the user status setting to Do Not Disturb.
53- # @note Only usable on User accounts.
54- def dnd
55- update_profile_status_setting ( 'dnd' )
56- end
57-
58- alias_method ( :busy , :dnd )
59-
60- # Sets the user status setting to Invisible.
61- # @note Only usable on User accounts.
62- def invisible
63- update_profile_status_setting ( 'invisible' )
47+ @username = new_data [ 'username' ]
48+ @avatar_id = new_data [ 'avatar' ]
49+ @banner_id = new_data [ 'banner' ]
6450 end
6551
6652 # The inspect method is overwritten to give more useful output
@@ -70,17 +56,12 @@ def inspect
7056
7157 private
7258
73- # Internal handler for updating the user's status setting
74- def update_profile_status_setting ( status )
75- API ::User . change_status_setting ( @bot . token , status )
76- end
77-
59+ # @!visibility private
7860 def update_profile_data ( new_data )
79- API ::User . update_profile ( @bot . token ,
80- nil , nil ,
81- new_data [ :username ] || @username ,
82- new_data . key? ( :avatar ) ? new_data [ :avatar ] : @avatar_id )
83- update_data ( new_data )
61+ update_data ( JSON . parse ( API ::User . update_current_user ( @bot . token ,
62+ new_data [ :username ] || :undef ,
63+ new_data . key? ( :avatar ) ? new_data [ :avatar ] : :undef ,
64+ new_data . key? ( :banner ) ? new_data [ :banner ] : :undef ) ) )
8465 end
8566 end
8667end
0 commit comments