Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/discord-jda/JDA
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Nov 13, 2024
2 parents 236acbf + 39e1a6e commit 3e89d41
Show file tree
Hide file tree
Showing 75 changed files with 2,258 additions and 316 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ plugins {


val javaVersion = JavaVersion.current()
val versionObj = Version(major = "5", minor = "1", revision = "2", classifier = null)
val versionObj = Version(major = "5", minor = "2", revision = "1", classifier = null)
val isGithubAction = System.getProperty("GITHUB_ACTION") != null || System.getenv("GITHUB_ACTION") != null
val isCI = System.getProperty("BUILD_NUMBER") != null // jenkins
|| System.getenv("BUILD_NUMBER") != null
Expand Down
16 changes: 16 additions & 0 deletions src/examples/java/LocalizationExample.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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.
*/

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.interactions.DiscordLocale;
Expand Down
62 changes: 61 additions & 1 deletion src/main/java/net/dv8tion/jda/api/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import net.dv8tion.jda.api.entities.sticker.*;
import net.dv8tion.jda.api.events.GenericEvent;
Expand Down Expand Up @@ -1750,6 +1752,64 @@ default List<RichCustomEmoji> getEmojisByName(@Nonnull String name, boolean igno
return getEmojiCache().getElementsByName(name, ignoreCase);
}

/**
* Creates a new {@link ApplicationEmoji} for this bot.
*
* <p>Note that the bot is limited to {@value ApplicationEmoji#APPLICATION_EMOJI_CAP} Application Emojis (normal and animated).
*
* @param name
* The name for the new emoji (2-{@value CustomEmoji#EMOJI_NAME_MAX_LENGTH} characters)
* @param icon
* The {@link Icon} for the new emoji
*
* @throws IllegalArgumentException
* If null is provided or the name is not alphanumeric or not between 2 and {@value CustomEmoji#EMOJI_NAME_MAX_LENGTH} characters long
*
* @return {@link RestAction} - Type: {@link ApplicationEmoji}
*/
@Nonnull
@CheckReturnValue
RestAction<ApplicationEmoji> createApplicationEmoji(@Nonnull String name, @Nonnull Icon icon);

/**
* Retrieves a list of Application Emojis together with their respective creators.
*
* @return {@link RestAction RestAction} - Type: List of {@link ApplicationEmoji}
*/
@Nonnull
@CheckReturnValue
RestAction<List<ApplicationEmoji>> retrieveApplicationEmojis();

/**
* Retrieves an application emoji together with its respective creator.
*
* @param emojiId
* The emoji id
*
* @return {@link RestAction RestAction} - Type: {@link ApplicationEmoji}
*/
@Nonnull
@CheckReturnValue
default RestAction<ApplicationEmoji> retrieveApplicationEmojiById(long emojiId)
{
return retrieveApplicationEmojiById(Long.toUnsignedString(emojiId));
}

/**
* Retrieves an application emoji together with its respective creator.
*
* @param emojiId
* The emoji id
*
* @throws IllegalArgumentException
* If the provided id is not a valid snowflake
*
* @return {@link RestAction RestAction} - Type: {@link ApplicationEmoji}
*/
@Nonnull
@CheckReturnValue
RestAction<ApplicationEmoji> retrieveApplicationEmojiById(@Nonnull String emojiId);

/**
* Attempts to retrieve a {@link Sticker} object based on the provided snowflake reference.
* <br>This works for both {@link StandardSticker} and {@link GuildSticker}, and you can resolve them using the provided {@link StickerUnion}.
Expand Down Expand Up @@ -1873,7 +1933,7 @@ default AccountType getAccountType() {
void setRequestTimeoutRetry(boolean retryOnTimeout);

/**
* USed to determine whether or not autoReconnect is enabled for JDA.
* Used to determine whether or not autoReconnect is enabled for JDA.
*
* @return True if JDA will attempt to automatically reconnect when a connection-error is encountered.
*/
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/net/dv8tion/jda/api/JDABuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ public class JDABuilder
protected GatewayEncoding encoding = GatewayEncoding.JSON;
protected RestConfig restConfig = new RestConfig();

private JDABuilder(@Nullable AccountType accountType, @Nullable String token, int intents)
protected JDABuilder(@Nullable String token, int intents)
{
this(AccountType.BOT, token, intents);
}

protected JDABuilder(@Nullable AccountType accountType, @Nullable String token, int intents)
{
this.accountType = accountType;
this.token = token;
Expand Down Expand Up @@ -224,7 +229,7 @@ public static JDABuilder createDefault(@Nullable String token, @Nonnull Collecti
return create(token, intents).applyDefault();
}

private JDABuilder applyDefault()
protected JDABuilder applyDefault()
{
return this.setMemberCachePolicy(MemberCachePolicy.DEFAULT)
.setChunkingFilter(ChunkingFilter.NONE)
Expand Down Expand Up @@ -344,7 +349,7 @@ public static JDABuilder createLight(@Nullable String token, @Nonnull Collection
return create(token, intents).applyLight();
}

private JDABuilder applyLight()
protected JDABuilder applyLight()
{
return this.setMemberCachePolicy(MemberCachePolicy.NONE)
.setChunkingFilter(ChunkingFilter.NONE)
Expand Down Expand Up @@ -506,7 +511,7 @@ public static JDABuilder create(@Nonnull AccountType type, @Nullable String toke
return new JDABuilder(type, token, GatewayIntent.getRaw(intents)).applyIntents();
}

private JDABuilder applyIntents()
protected JDABuilder applyIntents()
{
EnumSet<CacheFlag> disabledCache = EnumSet.allOf(CacheFlag.class);
for (CacheFlag flag : CacheFlag.values())
Expand Down Expand Up @@ -1596,7 +1601,7 @@ public JDABuilder setDisabledIntents(@Nullable Collection<GatewayIntent> intents
{
this.intents = GatewayIntent.ALL_INTENTS;
if (intents != null)
this.intents &= ~GatewayIntent.getRaw(intents);
this.intents = 1 | (GatewayIntent.ALL_INTENTS & ~GatewayIntent.getRaw(intents));
return this;
}

Expand Down Expand Up @@ -1688,7 +1693,7 @@ public JDABuilder setEnabledIntents(@Nonnull GatewayIntent intent, @Nonnull Gate
Checks.notNull(intent, "Intents");
Checks.noneNull(intents, "Intents");
EnumSet<GatewayIntent> set = EnumSet.of(intent, intents);
return setDisabledIntents(EnumSet.complementOf(set));
return setEnabledIntents(set);
}

/**
Expand All @@ -1715,11 +1720,9 @@ public JDABuilder setEnabledIntents(@Nonnull GatewayIntent intent, @Nonnull Gate
public JDABuilder setEnabledIntents(@Nullable Collection<GatewayIntent> intents)
{
if (intents == null || intents.isEmpty())
setDisabledIntents(EnumSet.allOf(GatewayIntent.class));
else if (intents instanceof EnumSet)
setDisabledIntents(EnumSet.complementOf((EnumSet<GatewayIntent>) intents));
this.intents = 1;
else
setDisabledIntents(EnumSet.complementOf(EnumSet.copyOf(intents)));
this.intents = 1 | GatewayIntent.getRaw(intents);
return this;
}

Expand Down Expand Up @@ -1901,7 +1904,7 @@ private JDABuilder setFlag(ConfigFlag flag, boolean enable)
return this;
}

private void checkIntents()
protected void checkIntents()
{
boolean membersIntent = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0;
if (!membersIntent && memberCachePolicy == MemberCachePolicy.ALL)
Expand Down
93 changes: 0 additions & 93 deletions src/main/java/net/dv8tion/jda/api/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
*/
package net.dv8tion.jda.api;

import net.dv8tion.jda.annotations.ForRemoval;
import net.dv8tion.jda.annotations.ReplaceWith;
import net.dv8tion.jda.internal.utils.Checks;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.stream.Collectors;

/**
* Represents the bit offsets used by Discord for Permissions.
Expand Down Expand Up @@ -85,10 +81,6 @@ public enum Permission
VOICE_DEAF_OTHERS( 23, true, true, "Deafen Members"),
VOICE_MOVE_OTHERS( 24, true, true, "Move Members"),
VOICE_USE_VAD( 25, true, true, "Use Voice Activity"),
@Deprecated
@ForRemoval(deadline="5.1.0")
@ReplaceWith("USE_EMBEDDED_ACTIVITIES")
VOICE_START_ACTIVITIES( 39, true, true, "Use Activities"),
VOICE_USE_SOUNDBOARD( 42, true, true, "Use Soundboard"),
VOICE_USE_EXTERNAL_SOUNDS(45, true, true, "Use External Sounds"),
VOICE_SET_STATUS( 48, true, true, "Set Voice Channel Status"),
Expand All @@ -108,63 +100,6 @@ public enum Permission
// This is an optimization suggested by Effective Java 3rd Edition - Item 54
public static final Permission[] EMPTY_PERMISSIONS = new Permission[0];

/**
* Represents a raw set of all permissions
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_PERMISSIONS = Permission.getRaw(Permission.values());

/**
* All permissions that apply to a channel
*
* @deprecated To be removed in 5.1.0 (use {@link Permission#isChannel()} instead)
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_CHANNEL_PERMISSIONS = Permission.getRaw(Arrays.stream(values())
.filter(Permission::isChannel).collect(Collectors.toSet()));

/**
* All Guild specific permissions which are only available to roles
*
* @deprecated To be removed in 5.1.0 (use {@link Permission#isGuild()} instead)
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_GUILD_PERMISSIONS = Permission.getRaw(Arrays.stream(values())
.filter(Permission::isGuild).collect(Collectors.toSet()));

/**
* All text channel specific permissions which are only available in text channel permission overrides
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_TEXT_PERMISSIONS
= Permission.getRaw(MESSAGE_ADD_REACTION, MESSAGE_SEND, MESSAGE_TTS, MESSAGE_MANAGE,
MESSAGE_EMBED_LINKS, MESSAGE_ATTACH_FILES, MESSAGE_EXT_EMOJI, MESSAGE_EXT_STICKER,
MESSAGE_HISTORY, MESSAGE_MENTION_EVERYONE,
USE_APPLICATION_COMMANDS, USE_EXTERNAL_APPLICATIONS, USE_EMBEDDED_ACTIVITIES,
MANAGE_THREADS, CREATE_PUBLIC_THREADS, CREATE_PRIVATE_THREADS,
MESSAGE_SEND_IN_THREADS, MESSAGE_ATTACH_VOICE_MESSAGE, MESSAGE_SEND_POLLS);

/**
* All voice channel specific permissions which are only available in voice channel permission overrides
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public static final long ALL_VOICE_PERMISSIONS
= Permission.getRaw(VOICE_STREAM, VOICE_CONNECT, VOICE_SPEAK, VOICE_MUTE_OTHERS,
VOICE_DEAF_OTHERS, VOICE_MOVE_OTHERS, VOICE_USE_VAD,
PRIORITY_SPEAKER, REQUEST_TO_SPEAK, USE_EMBEDDED_ACTIVITIES,
VOICE_USE_SOUNDBOARD, VOICE_USE_EXTERNAL_SOUNDS, VOICE_SET_STATUS);

private final int offset;
private final long raw;
private final boolean isGuild, isChannel;
Expand Down Expand Up @@ -235,34 +170,6 @@ public boolean isChannel()
return isChannel;
}

/**
* Whether this permission is specifically for {@link net.dv8tion.jda.api.entities.channel.concrete.TextChannel TextChannels}
*
* @return True, if and only if this permission can only be applied to text channels
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public boolean isText()
{
return (raw & ALL_TEXT_PERMISSIONS) == raw;
}

/**
* Whether this permission is specifically for {@link net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel VoiceChannels}
*
* @return True, if and only if this permission can only be applied to voice channels
*
* @deprecated To be removed in 5.1.0
*/
@Deprecated
@ForRemoval(deadline = "5.1.0")
public boolean isVoice()
{
return (raw & ALL_VOICE_PERMISSIONS) == raw;
}

/**
* Gets the first {@link net.dv8tion.jda.api.Permission Permission} relating to the provided offset.
* <br>If there is no {@link net.dv8tion.jda.api.Permission Permssions} that matches the provided
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/SkuSnowflake.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.utils.MiscUtil;
import net.dv8tion.jda.internal.entities.SkuSnowflakeImpl;

import javax.annotation.Nonnull;

/**
* Represents an abstract SKU reference by only the SKU ID.
*
* <p>This is used for methods which only need a SKU ID to function, you cannot use this for getting any properties.
*/
public interface SkuSnowflake extends ISnowflake
{
/**
* Creates a SKU instance which only wraps an ID.
*
* @param id
* The SKU id
*
* @return A SKU snowflake instance
*/
@Nonnull
static SkuSnowflake fromId(long id)
{
return new SkuSnowflakeImpl(id);
}

/**
* Creates a SKU instance which only wraps an ID.
*
* @param id
* The SKU id
*
* @throws IllegalArgumentException
* If the provided ID is not a valid snowflake
*
* @return A SKU snowflake instance
*/
@Nonnull
static SkuSnowflake fromId(@Nonnull String id)
{
return fromId(MiscUtil.parseSnowflake(id));
}
}
Loading

0 comments on commit 3e89d41

Please sign in to comment.