Skip to content

Commit

Permalink
Add AccountManager#setBanner
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 authored and MrPowerGamerBR committed Mar 20, 2024
1 parent 59db7c7 commit ea9f508
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/net/dv8tion/jda/api/managers/AccountManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public interface AccountManager extends Manager<AccountManager>
long NAME = 1;
/** Used to reset the avatar field */
long AVATAR = 1 << 1;
/** Used to reset the banner field */
long BANNER = 1 << 2;

/**
* The {@link net.dv8tion.jda.api.entities.SelfUser SelfUser} that will be
Expand Down Expand Up @@ -137,4 +139,17 @@ public interface AccountManager extends Manager<AccountManager>
@Nonnull
@CheckReturnValue
AccountManager setAvatar(@Nullable Icon avatar);

/**
* Sets the banner for the currently logged in account
*
* @param banner
* An {@link net.dv8tion.jda.api.entities.Icon Icon} instance representing
* the new banner for the current account, {@code null} to reset the banner to the default banner.
*
* @return AccountManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
AccountManager setBanner(@Nullable Icon banner);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class AccountManagerImpl extends ManagerBase<AccountManager> implements A

protected String name;
protected Icon avatar;
protected Icon banner;

/**
* Creates a new AccountManager instance
Expand Down Expand Up @@ -63,6 +64,8 @@ public AccountManagerImpl reset(long fields)
super.reset(fields);
if ((fields & AVATAR) == AVATAR)
avatar = null;
if ((fields & BANNER) == BANNER)
banner = null;
return this;
}

Expand Down Expand Up @@ -110,6 +113,16 @@ public AccountManagerImpl setAvatar(Icon avatar)
return this;
}

@Nonnull
@Override
@CheckReturnValue
public AccountManager setBanner(Icon banner)
{
this.banner = banner;
set |= BANNER;
return this;
}

@Override
protected RequestBody finalizeData()
{
Expand All @@ -123,6 +136,8 @@ protected RequestBody finalizeData()
body.put("username", name);
if (shouldUpdate(AVATAR))
body.put("avatar", avatar == null ? null : avatar.getEncoding());
if (shouldUpdate(BANNER))
body.put("banner", banner == null ? null : banner.getEncoding());

reset();
return getRequestBody(body);
Expand Down

0 comments on commit ea9f508

Please sign in to comment.