Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to set the bot banner #2629

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading