Skip to content
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: 9 additions & 6 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ default String getOwnerId()
* @return The Member object of the currently logged in account.
*/
@Nonnull
Member getSelfMember();
SelfMember getSelfMember();

/**
* Returns the NSFW Level that this guild is classified with.
Expand Down Expand Up @@ -3916,13 +3916,16 @@ default RestAction<Void> kickVoiceMember(@Nonnull UserSnowflake user)
* @param member
* The {@link Member Member} for which the nickname should be changed.
* @param nickname
* The new nickname of the {@link Member Member}, provide {@code null} or an
* empty String to reset the nickname
* The new nickname of the {@link Member Member}, max {@value Member#MAX_NICKNAME_LENGTH} characters in length,
* provide {@code null} or an empty String to reset the nickname
*
* @throws IllegalArgumentException
* If the specified {@link Member Member}
* is not from the same {@link net.dv8tion.jda.api.entities.Guild Guild}.
* Or if the provided member is {@code null}
* <ul>
* <li>If the specified {@link Member} is {@code null}</li>
* <li>If the specified {@link Member} is not from the same {@link Guild}</li>
* <li>If the new nickname is more than {@value Member#MAX_NICKNAME_LENGTH} characters in length</li>
* </ul>
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* <ul>
* <li>If attempting to set nickname for self and the logged in account has neither {@link net.dv8tion.jda.api.Permission#NICKNAME_CHANGE}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public interface Member extends IMentionable, IPermissionHolder, IDetachableEnti
String AVATAR_URL = "https://cdn.discordapp.com/guilds/%s/users/%s/avatars/%s.%s";
/** Maximum number of days a Member can be timed out for */
int MAX_TIME_OUT_LENGTH = 28;
/** Max length of a member nickname */
int MAX_NICKNAME_LENGTH = 32;

/**
* The user wrapped by this Entity.
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/SelfMember.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.entities;

import net.dv8tion.jda.api.managers.SelfMemberManager;
import net.dv8tion.jda.api.requests.RestAction;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;

/**
* Represents a Guild-specific {@link SelfUser}.
*
* @see Member
*/
public interface SelfMember extends Member
{
/** Max length of a member bio */
int MAX_BIO_LENGTH = 190;

@Nonnull
@Override
SelfUser getUser();

/**
* Returns the {@link SelfMemberManager} for this SelfMember,
* used to modify some properties of the currently logged in guild member.
*
* <p>If you wish to modify multiple fields,
* do it in one request by chaining setters before calling {@link RestAction#queue()}.
*
* @return The manager of this SelfMember
*/
@Nonnull
@CheckReturnValue
SelfMemberManager getManager();
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public interface AccountManager extends Manager<AccountManager>
* <ul>
* <li>{@link #NAME}</li>
* <li>{@link #AVATAR}</li>
* <li>{@link #BANNER}</li>
* </ul>
*
* @param fields
Expand All @@ -87,6 +88,7 @@ public interface AccountManager extends Manager<AccountManager>
* <ul>
* <li>{@link #NAME}</li>
* <li>{@link #AVATAR}</li>
* <li>{@link #BANNER}</li>
* </ul>
*
* @param fields
Expand Down
165 changes: 165 additions & 0 deletions src/main/java/net/dv8tion/jda/api/managers/SelfMemberManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.managers;

import net.dv8tion.jda.api.entities.*;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Manager providing functionality to update one or more fields for the logged in account.
*
* @see Guild#getSelfMember()
* @see SelfUser#getManager()
*/
public interface SelfMemberManager extends Manager<SelfMemberManager>
{
/** Used to reset the name field */
long NICKNAME = 1;
/** Used to reset the avatar field */
long AVATAR = 1 << 1;
/** Used to reset the banner field */
long BANNER = 1 << 2;
/** Used to reset the bio field */
long BIO = 1 << 3;

/**
* The {@link SelfMember} that will be modified by this SelfMemberManager.
*
* @return The corresponding member
*/
@Nonnull
SelfMember getMember();

/**
* Resets the fields specified by the provided bit-flag pattern.
* You can specify a combination by using a bitwise OR concat of the flag constants.
* <br>Example: {@code manager.reset(SelfMemberManager.NAME | SelfMemberManager.AVATAR);}
*
* <p><b>Flag Constants:</b>
* <ul>
* <li>{@link #NICKNAME}</li>
* <li>{@link #AVATAR}</li>
* <li>{@link #BANNER}</li>
* <li>{@link #BIO}</li>
* </ul>
*
* @param fields
* Integer value containing the flags to reset.
*
* @return SelfMemberManager for chaining convenience
*/
@Nonnull
@Override
@CheckReturnValue
SelfMemberManager reset(long fields);

/**
* Resets the fields specified by the provided bit-flag patterns.
* <br>Example: {@code manager.reset(SelfMemberManager.NAME, SelfMemberManager.AVATAR);}
*
* <p><b>Flag Constants:</b>
* <ul>
* <li>{@link #NICKNAME}</li>
* <li>{@link #AVATAR}</li>
* <li>{@link #BANNER}</li>
* <li>{@link #BIO}</li>
* </ul>
*
* @param fields
* Integer values containing the flags to reset.
*
* @return SelfMemberManager for chaining convenience
*/
@Nonnull
@Override
@CheckReturnValue
SelfMemberManager reset(@Nonnull long... fields);

/**
* Sets the nickname for the guild member of the currently logged in account.
*
* <p>The nickname is a name specific to the guild, when not set, your user's name will display.
*
* @param nickname
* The new nickname, max {@value Member#MAX_NICKNAME_LENGTH} characters in length,
* {@code null} to remove the nickname
*
* @throws IllegalArgumentException
* <ul>
* <li>
* If the provided nickname is non-null
* and is blank or more than {@value Member#MAX_NICKNAME_LENGTH} characters in length
* </li>
* <li>
* If the guild member of the current logged in account does not have
* the {@link net.dv8tion.jda.api.Permission#NICKNAME_CHANGE NICKNAME_CHANGE} permission
* </li>
* </ul>
*
*
* @return SelfMemberManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
SelfMemberManager setNickname(@Nullable String nickname);

/**
* Sets the avatar for the guild member of the currently logged in account.
*
* @param avatar
* An {@link Icon} instance representing the new Avatar,
* {@code null} to reset the avatar to the user avatar.
*
* @return SelfMemberManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
SelfMemberManager setAvatar(@Nullable Icon avatar);

/**
* Sets the banner for the guild member of the currently logged in account.
*
* @param banner
* An {@link Icon} instance representing the new banner,
* {@code null} to reset the banner to the user banner.
*
* @return SelfMemberManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
SelfMemberManager setBanner(@Nullable Icon banner);

/**
* Sets the bio for the guild member of the currently logged in account.
*
* @param bio
* The new bio,
* {@code null} to remove the bio
*
* @throws IllegalArgumentException
* If the provided bio is non-null
* and is blank or more than {@value SelfMember#MAX_BIO_LENGTH} characters in length
*
* @return SelfMemberManager for chaining convenience
*/
@Nonnull
@CheckReturnValue
SelfMemberManager setBio(@Nullable String bio);
}
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,10 @@ public MemberImpl createMember(GuildImpl guild, DataObject memberJson, DataObjec
if (member == null)
{
// Create a brand new member
member = new MemberImpl(guild, user);
if (user.getIdLong() == getJDA().getSelfUser().getIdLong())
member = new SelfMemberImpl(guild, ((SelfUser) user));
else
member = new MemberImpl(guild, user);
configureMember(memberJson, member);
Set<Role> roles = member.getRoleSet();
for (int i = 0; i < roleArray.length(); i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,12 +743,12 @@ public boolean isMember(@Nonnull UserSnowflake user)

@Nonnull
@Override
public Member getSelfMember()
public SelfMember getSelfMember()
{
Member member = getMember(getJDA().getSelfUser());
if (member == null)
throw new IllegalStateException("Guild does not have a self member");
return member;
return (SelfMember) member;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.internal.entities;

import net.dv8tion.jda.api.entities.SelfMember;
import net.dv8tion.jda.api.entities.SelfUser;
import net.dv8tion.jda.api.managers.SelfMemberManager;
import net.dv8tion.jda.internal.managers.SelfMemberManagerImpl;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;

public class SelfMemberImpl extends MemberImpl implements SelfMember
{
public SelfMemberImpl(GuildImpl guild, SelfUser user)
{
super(guild, user);
}

@Nonnull
@Override
public SelfUser getUser()
{
return (SelfUser) super.getUser();
}

@Nonnull
@Override
@CheckReturnValue
public SelfMemberManager getManager()
{
return new SelfMemberManagerImpl(this);
}

// Inherit equals/hashCode/toString
}
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public boolean isMember(@Nonnull UserSnowflake user)

@Nonnull
@Override
public Member getSelfMember()
public SelfMember getSelfMember()
{
throw detachedException();
}
Expand Down
Loading