file_name
stringlengths 6
86
| file_path
stringlengths 45
249
| content
stringlengths 47
6.26M
| file_size
int64 47
6.26M
| language
stringclasses 1
value | extension
stringclasses 1
value | repo_name
stringclasses 767
values | repo_stars
int64 8
14.4k
| repo_forks
int64 0
1.17k
| repo_open_issues
int64 0
788
| repo_created_at
stringclasses 767
values | repo_pushed_at
stringclasses 767
values |
---|---|---|---|---|---|---|---|---|---|---|---|
LogLevel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/common/api/src/main/java/com/discordsrv/common/logging/LogLevel.java | /*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.logging;
import java.util.Locale;
public interface LogLevel {
LogLevel INFO = StandardLogLevel.INFO;
LogLevel WARNING = StandardLogLevel.WARNING;
LogLevel ERROR = StandardLogLevel.ERROR;
LogLevel DEBUG = StandardLogLevel.DEBUG;
LogLevel TRACE = StandardLogLevel.TRACE;
static LogLevel of(String name) {
try {
return StandardLogLevel.valueOf(name.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException ignored) {
return new CustomLogLevel(name);
}
}
String name();
enum StandardLogLevel implements LogLevel {
INFO,
WARNING,
ERROR,
DEBUG,
TRACE
}
class CustomLogLevel implements LogLevel {
private final String name;
public CustomLogLevel(String name) {
this.name = name;
}
@Override
public String name() {
return name;
}
}
}
| 1,809 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
LogAppender.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/common/api/src/main/java/com/discordsrv/common/logging/LogAppender.java | /*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.logging;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@FunctionalInterface
public interface LogAppender {
void append(@Nullable String loggerName, @NotNull LogLevel logLevel, @Nullable String message, @Nullable Throwable throwable);
}
| 1,142 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DependencyLoggerAdapter.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/common/api/src/main/java/com/discordsrv/common/logging/adapter/DependencyLoggerAdapter.java | /*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.logging.adapter;
import com.discordsrv.common.logging.LogAppender;
import com.discordsrv.common.logging.LogLevel;
import org.slf4j.Marker;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.spi.LocationAwareLogger;
import java.util.ArrayList;
import java.util.List;
public class DependencyLoggerAdapter extends MarkerIgnoringBase implements LocationAwareLogger {
private static LogAppender APPENDER;
public static void setAppender(LogAppender appender) {
APPENDER = appender;
}
private final String name;
public DependencyLoggerAdapter(String name) {
this.name = name;
}
private String format(String message, Object[] arguments) {
return MessageFormatter.arrayFormat(message, arguments).getMessage();
}
private LogLevel getLevel(int level) {
switch (level) {
case LocationAwareLogger.TRACE_INT:
return LogLevel.TRACE;
case LocationAwareLogger.DEBUG_INT:
return LogLevel.DEBUG;
case LocationAwareLogger.INFO_INT:
return LogLevel.INFO;
case LocationAwareLogger.WARN_INT:
return LogLevel.WARNING;
case LocationAwareLogger.ERROR_INT:
return LogLevel.ERROR;
default:
throw new IllegalStateException("Level number " + level + " is not recognized.");
}
}
private void doLog(LogLevel logLevel, String message, Object[] args) {
List<Object> arguments = new ArrayList<>(args.length);
Throwable throwable = null;
for (Object arg : args) {
if (arg instanceof Throwable) {
throwable = (Throwable) arg;
continue;
}
arguments.add(arg);
}
doLog(logLevel, format(message, arguments.toArray(new Object[0])), throwable);
}
private void doLog(LogLevel logLevel, String message, Throwable throwable) {
if (APPENDER == null) {
// Adapter isn't set, do nothing
return;
}
APPENDER.append(name, logLevel, message, throwable);
}
@Override
public void log(Marker marker, String fqcn, int level, String message, Object[] argArray, Throwable t) {
doLog(getLevel(level), format(message, argArray), t);
}
@Override
public boolean isTraceEnabled() {
return true;
}
@Override
public void trace(String msg) {
trace(msg, (Throwable) null);
}
@Override
public void trace(String format, Object arg) {
doLog(LogLevel.TRACE, format, new Object[] {arg});
}
@Override
public void trace(String format, Object arg1, Object arg2) {
doLog(LogLevel.TRACE, format, new Object[] {arg1, arg2});
}
@Override
public void trace(String format, Object... arguments) {
doLog(LogLevel.TRACE, format, arguments);
}
@Override
public void trace(String msg, Throwable t) {
doLog(LogLevel.TRACE, msg, t);
}
@Override
public boolean isDebugEnabled() {
return true;
}
@Override
public void debug(String msg) {
debug(msg, (Throwable) null);
}
@Override
public void debug(String format, Object arg) {
doLog(LogLevel.DEBUG, format, new Object[] {arg});
}
@Override
public void debug(String format, Object arg1, Object arg2) {
doLog(LogLevel.DEBUG, format, new Object[] {arg1, arg2});
}
@Override
public void debug(String format, Object... arguments) {
doLog(LogLevel.DEBUG, format, arguments);
}
@Override
public void debug(String msg, Throwable t) {
doLog(LogLevel.DEBUG, msg, t);
}
@Override
public boolean isInfoEnabled() {
return true;
}
@Override
public void info(String msg) {
info(msg, (Throwable) null);
}
@Override
public void info(String format, Object arg) {
doLog(LogLevel.INFO, format, new Object[] {arg});
}
@Override
public void info(String format, Object arg1, Object arg2) {
doLog(LogLevel.INFO, format, new Object[] {arg1, arg2});
}
@Override
public void info(String format, Object... arguments) {
doLog(LogLevel.INFO, format, arguments);
}
@Override
public void info(String msg, Throwable t) {
doLog(LogLevel.INFO, msg, t);
}
@Override
public boolean isWarnEnabled() {
return true;
}
@Override
public void warn(String msg) {
warn(msg, (Throwable) null);
}
@Override
public void warn(String format, Object arg) {
doLog(LogLevel.WARNING, format, new Object[] {arg});
}
@Override
public void warn(String format, Object... arguments) {
doLog(LogLevel.WARNING, format, arguments);
}
@Override
public void warn(String format, Object arg1, Object arg2) {
doLog(LogLevel.WARNING, format, new Object[] {arg1, arg2});
}
@Override
public void warn(String msg, Throwable t) {
doLog(LogLevel.WARNING, msg, t);
}
@Override
public boolean isErrorEnabled() {
return true;
}
@Override
public void error(String msg) {
error(msg, (Throwable) null);
}
@Override
public void error(String format, Object arg) {
doLog(LogLevel.ERROR, format, new Object[] {arg});
}
@Override
public void error(String format, Object arg1, Object arg2) {
doLog(LogLevel.ERROR, format, new Object[] {arg1, arg2});
}
@Override
public void error(String format, Object... arguments) {
doLog(LogLevel.ERROR, format, arguments);
}
@Override
public void error(String msg, Throwable t) {
doLog(LogLevel.ERROR, msg, t);
}
}
| 6,722 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Logger.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/common/unrelocate/src/main/java/com/discordsrv/unrelocate/org/slf4j/Logger.java | /*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.unrelocate.org.slf4j;
/**
* A fake org.slf4j.Logger that is compileOnly scoped and relocated back to the real org.slf4j package.
* This is required as we want to relocate 'org.slf4j'
* but we also need the non-relocated version for Velocity's logging.
*
* Could be fixed by https://github.com/johnrengelman/shadow/issues/727
*/
public interface Logger extends org.slf4j.Logger {}
| 1,240 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Component.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/common/unrelocate/src/main/java/com/discordsrv/unrelocate/net/kyori/adventure/text/Component.java | package com.discordsrv.unrelocate.net.kyori.adventure.text;
@SuppressWarnings("NonExtendableApiUsage")
public interface Component extends net.kyori.adventure.text.Component {
}
| 178 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlaceholdersTest.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/test/java/com/discordsrv/api/placeholder/util/PlaceholdersTest.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.placeholder.util;
import org.junit.jupiter.api.Test;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class PlaceholdersTest {
@Test
public void orderTest() {
Placeholders placeholders = new Placeholders("a");
placeholders.replace("b", "c");
placeholders.replace("a", "b");
assertEquals("b", placeholders.toString());
}
@Test
public void uselessContentTest() {
Placeholders placeholders = new Placeholders("stuff a stuff");
placeholders.replace("a", "b");
assertEquals("stuff b stuff", placeholders.toString());
}
@Test
public void multipleTest() {
Placeholders placeholders = new Placeholders("a b");
placeholders.replace("a", "c");
placeholders.replace("b", "d");
assertEquals("c d", placeholders.toString());
}
@Test
public void multipleSamePatternTest() {
Placeholders placeholders = new Placeholders("a a");
AtomicBoolean used = new AtomicBoolean(false);
placeholders.replace("a", matcher -> {
if (used.get()) {
return "c";
} else {
used.set(true);
return "b";
}
});
assertEquals("b c", placeholders.toString());
}
}
| 2,655 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordSRVApi.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/DiscordSRVApi.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api;
import com.discordsrv.api.component.MinecraftComponentFactory;
import com.discordsrv.api.discord.DiscordAPI;
import com.discordsrv.api.discord.connection.details.DiscordConnectionDetails;
import com.discordsrv.api.event.bus.EventBus;
import com.discordsrv.api.placeholder.PlaceholderService;
import com.discordsrv.api.placeholder.PlainPlaceholderFormat;
import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.api.player.IPlayerProvider;
import com.discordsrv.api.profile.IProfileManager;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDAInfo;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Predicate;
/**
* The DiscordSRV API.
*
* Use your platform's service provider or {@link #get()} / {@link #optional()} to get the instance.
*/
@SuppressWarnings("unused") // API
public interface DiscordSRVApi {
/**
* Gets the instance of {@link DiscordSRVApi}.
* @return the DiscordSRV api, or {@code null} if not available
* @see #isAvailable()
*/
@Nullable
static DiscordSRVApi get() {
return InstanceHolder.API;
}
/**
* Returns a {@link Optional} of {@link DiscordSRVApi}.
* @return the DiscordSRV api in an optional
* @see #isAvailable()
*/
@NotNull
static Optional<DiscordSRVApi> optional() {
return Optional.ofNullable(InstanceHolder.API);
}
/**
* Checks if the API instance is available.
* @return true if {@link #get()} and {@link #optional()} will return the API instance
*/
static boolean isAvailable() {
return InstanceHolder.API != null;
}
/**
* The status of this DiscordSRV instance.
* @return the current status of this DiscordSRV instance
*/
@NotNull
Status status();
/**
* The event bus, can be used for listening to DiscordSRV and JDA events.
* @return the event bus
*/
@NotNull
EventBus eventBus();
/**
* The profile manager, access the profiles of players and/or users.
* @return the instance of {@link IProfileManager}
*/
@NotNull
IProfileManager profileManager();
/**
* DiscordSRV's own placeholder service.
* @return the {@link PlaceholderService} instance.
*/
@NotNull
PlaceholderService placeholderService();
/**
* Provides the {@link PlainPlaceholderFormat} instance.
* @return the {@link PlainPlaceholderFormat} instance
*/
@NotNull
PlainPlaceholderFormat discordPlaceholders();
/**
* A provider for {@link com.discordsrv.api.component.MinecraftComponent}s.
* @return the {@link com.discordsrv.api.component.MinecraftComponentFactory} instance.
*/
@NotNull
MinecraftComponentFactory componentFactory();
/**
* A provider for {@link DiscordSRVPlayer} instances.
* @return the {@link IPlayerProvider} instance
*/
@NotNull
IPlayerProvider playerProvider();
/**
* Gets DiscordSRV's first party API wrapper for Discord. This contains limited methods but is less likely to break compared to {@link #jda()}.
* @return the {@link DiscordAPI} instance
* @see #isReady()
*/
@NotNull
DiscordAPI discordAPI();
/**
* The current JDA version being used by DiscordSRV.
* @return the JDA version
* @see #jda()
*/
@NotNull
default String jdaVersion() {
return JDAInfo.VERSION;
}
/**
* Access to {@link JDA}, the Discord library used by DiscordSRV.
* @return the JDA instance, if available
*
* <p>
* JDA is an external library and comes with its own versioning and deprecation policies, using DiscordSRV's own APIs where possible is recommended.
* DiscordSRV will upgrade JDA as needed, including breaking changes and major version upgrades.
*
* <a href="https://github.com/DV8FromTheWorld/JDA#deprecation-policy">JDA's deprecation policy</a>
*
* @see #discordAPI() discordAPI() for the first party api
* @see #discordConnectionDetails() discordConnectionDetails() to use specific GatewayIntents and CacheFlags
* @see #jdaVersion() jdaVersion() to get the current jda version being used
*/
@Nullable
JDA jda();
/**
* Discord connection detail manager, specify {@link net.dv8tion.jda.api.requests.GatewayIntent}s and {@link net.dv8tion.jda.api.utils.cache.CacheFlag}s you need here.
* @return the {@link DiscordConnectionDetails} instance
*/
@NotNull
DiscordConnectionDetails discordConnectionDetails();
/**
* Checks if {@link #status()} is {@link Status#CONNECTED}.
* @return if DiscordSRV is ready
*/
@ApiStatus.NonExtendable
default boolean isReady() {
return status().isReady();
}
/**
* Checks if {@link #status()} is {@link Status#SHUTTING_DOWN} or {@link Status#SHUTDOWN}.
* @return if DiscordSRV is shutting down or has shutdown
*/
@ApiStatus.NonExtendable
default boolean isShutdown() {
return status().isShutdown();
}
enum Status {
/**
* DiscordSRV has not yet started.
*/
INITIALIZED,
/**
* DiscordSRV is attempting to connect to Discord.
*/
ATTEMPTING_TO_CONNECT,
/**
* DiscordSRV is connected to Discord and is ready.
* @see #isReady()
*/
CONNECTED,
/**
* DiscordSRV failed to load its configuration.
* @see #isError()
* @see #isStartupError()
*/
FAILED_TO_LOAD_CONFIG(true),
/**
* DiscordSRV failed to start, unless the configuration failed to load, in that case the status will be {@link #FAILED_TO_LOAD_CONFIG}.
* @see #isError()
* @see #isStartupError()
*/
FAILED_TO_START(true),
/**
* DiscordSRV failed to connect to Discord.
* @see #isError()
*/
FAILED_TO_CONNECT(true),
/**
* DiscordSRV is shutting down.
* @see #isShutdown()
*/
SHUTTING_DOWN,
/**
* DiscordSRV has shutdown.
* @see #isShutdown()
*/
SHUTDOWN,
;
private final boolean error;
Status() {
this(false);
}
Status(boolean error) {
this.error = error;
}
public boolean isError() {
return error;
}
public boolean isShutdown() {
return this == SHUTDOWN || this == SHUTTING_DOWN;
}
public boolean isStartupError() {
return this == FAILED_TO_START || this == FAILED_TO_LOAD_CONFIG;
}
public boolean isReady() {
return this == CONNECTED;
}
}
enum ReloadFlag {
CONFIG(false),
LINKED_ACCOUNT_PROVIDER(false),
STORAGE(true),
DISCORD_CONNECTION(DiscordSRVApi::isReady),
MODULES(false),
DISCORD_COMMANDS(false),
// Bukkit only
TRANSLATIONS(false)
;
public static final Set<ReloadFlag> ALL = Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(values())));
public static final Set<ReloadFlag> DEFAULT_FLAGS = Collections.unmodifiableSet(new LinkedHashSet<>(Arrays.asList(CONFIG, MODULES)));
private final Predicate<DiscordSRVApi> requiresConfirm;
ReloadFlag(boolean requiresConfirm) {
this(__ -> requiresConfirm);
}
ReloadFlag(Predicate<DiscordSRVApi> requiresConfirm) {
this.requiresConfirm = requiresConfirm;
}
public boolean requiresConfirm(DiscordSRVApi discordSRV) {
return requiresConfirm.test(discordSRV);
}
}
interface ReloadResult {
ReloadResult RESTART_REQUIRED = DefaultConstants.RESTART_REQUIRED;
String name();
enum DefaultConstants implements ReloadResult {
RESTART_REQUIRED
}
}
@ApiStatus.Internal
@SuppressWarnings("unused") // API, Reflection
final class InstanceHolder {
static DiscordSRVApi API;
private InstanceHolder() {}
private static void provide(DiscordSRVApi api) {
InstanceHolder.API = api;
}
}
}
| 9,709 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
FormattedText.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/FormattedText.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.placeholder;
import org.jetbrains.annotations.NotNull;
/**
* Represents content that doesn't need to be processed for the purposes of DiscordSRV's processing.
*/
public class FormattedText implements CharSequence {
private final CharSequence text;
public FormattedText(CharSequence text) {
this.text = text;
}
@Override
public int length() {
return text.length();
}
@Override
public char charAt(int index) {
return text.charAt(index);
}
@Override
public @NotNull CharSequence subSequence(int start, int end) {
return text.subSequence(start, end);
}
@Override
public @NotNull String toString() {
return text.toString();
}
}
| 2,021 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlaceholderLookupResult.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/PlaceholderLookupResult.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.placeholder;
import java.util.Set;
public class PlaceholderLookupResult {
public static final PlaceholderLookupResult DATA_NOT_AVAILABLE = new PlaceholderLookupResult(Type.DATA_NOT_AVAILABLE);
public static final PlaceholderLookupResult UNKNOWN_PLACEHOLDER = new PlaceholderLookupResult(Type.UNKNOWN_PLACEHOLDER);
public static PlaceholderLookupResult success(Object result) {
return new PlaceholderLookupResult(result);
}
public static PlaceholderLookupResult newLookup(String placeholder, Set<Object> extras) {
return new PlaceholderLookupResult(placeholder, extras);
}
public static PlaceholderLookupResult lookupFailed(Throwable error) {
return new PlaceholderLookupResult(error);
}
private final Type type;
private final Object value;
private final Throwable error;
private final Set<Object> extras;
protected PlaceholderLookupResult(Type type) {
this.type = type;
this.value = null;
this.error = null;
this.extras = null;
}
protected PlaceholderLookupResult(Object value) {
this.type = Type.SUCCESS;
this.value = value;
this.error = null;
this.extras = null;
}
protected PlaceholderLookupResult(Throwable error) {
this.type = Type.LOOKUP_FAILED;
this.value = null;
this.error = error;
this.extras = null;
}
protected PlaceholderLookupResult(String placeholder, Set<Object> extras) {
this.type = Type.NEW_LOOKUP;
this.value = placeholder;
this.error = null;
this.extras = extras;
}
public Type getType() {
return type;
}
public Object getValue() {
return value;
}
public Throwable getError() {
return error;
}
public Set<Object> getExtras() {
return extras;
}
public enum Type {
SUCCESS,
NEW_LOOKUP,
LOOKUP_FAILED,
DATA_NOT_AVAILABLE,
UNKNOWN_PLACEHOLDER
}
}
| 3,314 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlainPlaceholderFormat.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/PlainPlaceholderFormat.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.placeholder;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* A helper class to handle replacing placeholders with Discord code blocks.
*/
public interface PlainPlaceholderFormat {
ThreadLocal<Formatting> FORMATTING = ThreadLocal.withInitial(() -> Formatting.PLAIN);
static void with(Formatting formatting, Runnable runnable) {
supplyWith(formatting, () -> {
runnable.run();
return null;
});
}
static <T> T supplyWith(Formatting formatting, Supplier<T> supplier) {
Formatting before = FORMATTING.get();
FORMATTING.set(formatting);
T value = supplier.get();
FORMATTING.set(before);
return value;
}
enum Formatting {
PLAIN,
DISCORD,
ANSI,
LEGACY
}
String map(String input, Function<String, String> placeholders);
}
| 2,183 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlaceholderService.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/PlaceholderService.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.placeholder;
import com.discordsrv.api.placeholder.mapper.PlaceholderResultMapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public interface PlaceholderService {
/**
* The primary pattern used by DiscordSRV to find placeholders.
*/
Pattern PATTERN = Pattern.compile("(%)((?:[^%]|(?<=\\\\)%)+)(%)");
/**
* The pattern DiscordSRV uses to find recursive placeholders.
*/
Pattern RECURSIVE_PATTERN = Pattern.compile("(\\{)((?:[^{}]|(?<=\\\\)[{}])+)(})");
void addResultMapper(@NotNull PlaceholderResultMapper resultMapper);
void removeResultMapper(@NotNull PlaceholderResultMapper resultMapper);
String replacePlaceholders(@NotNull String placeholder, @NotNull Set<Object> context);
String replacePlaceholders(@NotNull String placeholder, @NotNull Object... context);
PlaceholderLookupResult lookupPlaceholder(@NotNull String placeholder, @NotNull Set<Object> context);
PlaceholderLookupResult lookupPlaceholder(@NotNull String placeholder, @NotNull Object... context);
Object getResult(@NotNull Matcher matcher, @NotNull Set<Object> context);
@NotNull
CharSequence getResultAsPlain(@NotNull Matcher matcher, @NotNull Set<Object> context);
@NotNull
CharSequence getResultAsPlain(@Nullable Object result);
}
| 2,711 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlaceholderResultMapper.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/mapper/PlaceholderResultMapper.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.placeholder.mapper;
import org.jetbrains.annotations.NotNull;
@FunctionalInterface
public interface PlaceholderResultMapper {
/**
* Converts a successful placeholder lookup result into an object that is better suited to be used in place of the result.
* @param result the result
* @return the result in the form that should be used for converting to a {@link String} or used directly by placeholder service users
* or {@code null} if this mapper doesn't know what to do with this result
*/
Object convertResult(@NotNull Object result);
}
| 1,872 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlaceholderRemainder.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/annotation/PlaceholderRemainder.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.placeholder.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface PlaceholderRemainder {
}
| 1,585 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Placeholder.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/annotation/Placeholder.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.placeholder.annotation;
import com.discordsrv.api.placeholder.PlaceholderService;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicates a Placeholder for DiscordSRV's {@link PlaceholderService}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface Placeholder {
/**
* The name of the Placeholder.
* @return the placeholder's name, may contain any character besides {@code %}.
*/
String value();
/**
* Creates a new lookup with {@link #value()} replaced with this, if the placeholder is longer than the given {@link #value()}.
* The object returned by the {@link Placeholder} method/field will be added as context.
* @return the prefix used for the next lookup
*/
String relookup() default "";
}
| 2,217 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlaceholderPrefix.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/annotation/PlaceholderPrefix.java | package com.discordsrv.api.placeholder.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Specifies a prefix for all placeholders declared in this type.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface PlaceholderPrefix {
/**
* The prefix for all placeholders in this type
* @return the prefix
*/
String value();
/**
* If this prefix should not follow {@link PlaceholderPrefix} of classes that are using this class/interface as a superclass.
* @return {@code true} to not allow overwriting this prefix
*/
boolean ignoreParents() default false;
}
| 761 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Placeholders.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/util/Placeholders.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.placeholder.util;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Placeholders {
private final String inputText;
private final Map<Pattern, Function<Matcher, Object>> replacements = new LinkedHashMap<>();
public Placeholders(String inputText) {
this.inputText = inputText;
}
@NotNull
public Placeholders addAll(Map<Pattern, Function<Matcher, Object>> replacements) {
this.replacements.putAll(replacements);
return this;
}
@NotNull
public Placeholders replace(String target, Object replacement) {
return replace(target, matcher -> replacement);
}
@NotNull
public Placeholders replaceAll(Pattern pattern, Object replacement) {
return replaceAll(pattern, matcher -> replacement);
}
@NotNull
public Placeholders replace(String target, Supplier<Object> replacement) {
return replaceAll(Pattern.compile(target, Pattern.LITERAL), matcher -> replacement);
}
@NotNull
public Placeholders replaceAll(Pattern pattern, Supplier<Object> replacement) {
return replaceAll(pattern, matcher -> replacement);
}
@NotNull
public Placeholders replace(String target, Function<Matcher, Object> replacement) {
return replaceAll(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
public Placeholders replaceAll(Pattern pattern, Function<Matcher, Object> replacement) {
this.replacements.put(pattern, replacement);
return this;
}
@Override
@NotNull
public String toString() {
String input = inputText;
for (Map.Entry<Pattern, Function<Matcher, Object>> entry : replacements.entrySet()) {
Pattern pattern = entry.getKey();
Matcher matcher = pattern.matcher(input);
StringBuffer buffer = new StringBuffer();
int lastEnd = -1;
while (matcher.find()) {
lastEnd = matcher.end();
Function<Matcher, Object> replacement = entry.getValue();
Object value = replacement.apply(matcher);
matcher.appendReplacement(buffer, Matcher.quoteReplacement(String.valueOf(value)));
}
if (lastEnd == -1) {
continue;
}
buffer.append(input.substring(lastEnd));
input = buffer.toString();
}
return input;
}
}
| 3,899 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
SinglePlaceholder.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/provider/SinglePlaceholder.java | package com.discordsrv.api.placeholder.provider;
import com.discordsrv.api.placeholder.PlaceholderLookupResult;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
import java.util.function.Supplier;
public class SinglePlaceholder implements PlaceholderProvider {
private final String matchPlaceholder;
private final Supplier<Object> resultProvider;
public SinglePlaceholder(String placeholder, Object result) {
this(placeholder, () -> result);
}
public SinglePlaceholder(String placeholder, Supplier<Object> resultProvider) {
this.matchPlaceholder = placeholder;
this.resultProvider = resultProvider;
}
@Override
public @NotNull PlaceholderLookupResult lookup(@NotNull String placeholder, @NotNull Set<Object> context) {
if (!placeholder.equals(matchPlaceholder)) {
return PlaceholderLookupResult.UNKNOWN_PLACEHOLDER;
}
try {
return PlaceholderLookupResult.success(
resultProvider.get()
);
} catch (Throwable t) {
return PlaceholderLookupResult.lookupFailed(t);
}
}
}
| 1,157 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlaceholderProvider.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/placeholder/provider/PlaceholderProvider.java | /*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.api.placeholder.provider;
import com.discordsrv.api.placeholder.PlaceholderLookupResult;
import com.discordsrv.api.placeholder.annotation.Placeholder;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
/**
* A placeholder provider used internally by DiscordSRV for {@link Placeholder}.
* API users should use the {@link com.discordsrv.api.event.events.placeholder.PlaceholderLookupEvent} instead.
*/
public interface PlaceholderProvider {
@NotNull
PlaceholderLookupResult lookup(@NotNull String placeholder, @NotNull Set<Object> context);
}
| 1,422 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordAPI.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/DiscordAPI.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord;
import com.discordsrv.api.discord.entity.DiscordUser;
import com.discordsrv.api.discord.entity.channel.*;
import com.discordsrv.api.discord.entity.guild.DiscordCustomEmoji;
import com.discordsrv.api.discord.entity.guild.DiscordGuild;
import com.discordsrv.api.discord.entity.guild.DiscordRole;
import com.discordsrv.api.discord.entity.interaction.command.DiscordCommand;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.concurrent.CompletableFuture;
/**
* A basic Discord API wrapper for a limited amount of functions, with a minimal amount of breaking changes.
*/
public interface DiscordAPI {
/**
* Gets a Discord message channel by id, the provided entity should not be stored for long periods of time.
* @param id the id for the message channel
* @return the message channel
*/
@Nullable
DiscordMessageChannel getMessageChannelById(long id);
/**
* Gets a Discord direct message channel by id, the provided entity should not be stored for long periods of time.
* @param id the id for the direct message channel
* @return the direct message channel
*/
@Nullable
DiscordDMChannel getDirectMessageChannelById(long id);
/**
* Gets a Discord news channel by id, the provided entity should not be stored for long periods of time.
* @param id the id for the news channel
* @return the news channel
*/
@Nullable
DiscordNewsChannel getNewsChannelById(long id);
/**
* Gets a Discord text channel by id, the provided entity should not be stored for long periods of time.
* @param id the id for the text channel
* @return the text channel
*/
@Nullable
DiscordTextChannel getTextChannelById(long id);
/**
* Gets a Discord forum channel by id, the provided entity should not be stored for long periods of time.
* @param id the id for the text channel
* @return the forum channel
*/
@Nullable
DiscordForumChannel getForumChannelById(long id);
/**
* Gets a Discord voice channel by id, the provided entity should be stored for long periods of time.
* @param id the id for the voice channel
* @return the voice channel
*/
@Nullable
DiscordVoiceChannel getVoiceChannelById(long id);
/**
* Gets a Discord stage channel by id, the provided entity should be stored for long periods of time.
* @param id the id for the voice channel
* @return the voice channel
*/
@Nullable
DiscordStageChannel getStageChannelById(long id);
/**
* Gets a Discord thread channel by id from the cache, the provided entity should not be stored for long periods of time.
* @param id the id for the thread channel
* @return the thread channel
*/
@Nullable
DiscordThreadChannel getCachedThreadChannelById(long id);
/**
* Gets a Discord server by id, the provided entity should not be stored for long periods of time.
* @param id the id for the Discord server
* @return the Discord server
*/
@Nullable
DiscordGuild getGuildById(long id);
/**
* Gets a Discord user by id, the provided entity should not be stored for long periods of time.
* This will always return {@code null} if {@link #isUserCachingEnabled()} returns {@code false}.
* @param id the id for the Discord user
* @return the Discord user
* @see #isUserCachingEnabled()
*/
@Nullable
DiscordUser getUserById(long id);
/**
* Looks up a Discord user by id from Discord, the provided entity should not be stored for long periods of time.
* @param id the id for the Discord user
* @return a future that will result in a {@link DiscordUser} for the id or throw a
*/
@NotNull
CompletableFuture<DiscordUser> retrieveUserById(long id);
/**
* Gets if user caching is enabled.
* @return {@code true} if user caching is enabled.
*/
boolean isUserCachingEnabled();
/**
* Gets a Discord role by id, the provided entity should not be stored for long periods of time.
* @param id the id for the Discord role
* @return the Discord role
*/
@Nullable
DiscordRole getRoleById(long id);
/**
* Gets a custom emoji for a Discord server by id, the provided entity should not be stored for long periods of time.
* @param id the id for the custom emoji
* @return the Discord custom emoji
*/
DiscordCustomEmoji getEmojiById(long id);
/**
* Registers a Discord command.
* @param command the command to register
*/
DiscordCommand.RegistrationResult registerCommand(DiscordCommand command);
/**
* Unregisters a Discord command.
* @param command the command to unregister
*/
void unregisterCommand(DiscordCommand command);
}
| 6,176 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordCacheFlag.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/connection/details/DiscordCacheFlag.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.connection.details;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
public enum DiscordCacheFlag implements JDAEntity<CacheFlag> {
ACTIVITY(CacheFlag.ACTIVITY),
VOICE_STATE(CacheFlag.VOICE_STATE),
EMOJI(CacheFlag.EMOJI),
STICKER(CacheFlag.STICKER),
CLIENT_STATUS(CacheFlag.CLIENT_STATUS),
MEMBER_OVERRIDES(CacheFlag.MEMBER_OVERRIDES),
ROLE_TAGS(CacheFlag.ROLE_TAGS),
FORUM_TAGS(CacheFlag.FORUM_TAGS),
ONLINE_STATUS(CacheFlag.ONLINE_STATUS),
SCHEDULED_EVENTS(CacheFlag.SCHEDULED_EVENTS),
;
private final CacheFlag jda;
DiscordCacheFlag(CacheFlag jda) {
this.jda = jda;
}
public DiscordGatewayIntent requiredIntent() {
GatewayIntent intent = jda.getRequiredIntent();
if (intent == null) {
return null;
}
return DiscordGatewayIntent.getByJda(intent);
}
@Override
public CacheFlag asJDA() {
return jda;
}
}
| 2,349 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordConnectionDetails.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/connection/details/DiscordConnectionDetails.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.connection.details;
import com.discordsrv.api.DiscordSRVApi;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.jetbrains.annotations.NotNull;
/**
* A helper class to provide {@link DiscordGatewayIntent}s and {@link DiscordCacheFlag}s for the Discord connection.
* @see DiscordSRVApi#discordConnectionDetails()
*/
@SuppressWarnings("unused") // API
public interface DiscordConnectionDetails {
/**
* Requests that the provided {@link DiscordGatewayIntent}s be passed to the Discord connection.
*
* @param gatewayIntent the first gateway intent to add
* @param gatewayIntents more gateway intents
* @return {@code true} if the Discord connection is yet to be created and the intent will become active once it is
*/
boolean requestGatewayIntent(@NotNull DiscordGatewayIntent gatewayIntent, @NotNull DiscordGatewayIntent... gatewayIntents);
/**
* Requests that the provided {@link DiscordCacheFlag}s be passed to the Discord connection.
*
* @param cacheFlag the first cache flag
* @param cacheFlags more cache flags
* @return {@code true} if the Discord connection is yet to be created and the intent will become active once it is
* @throws IllegalArgumentException if one of the requested {@link CacheFlag}s requires a {@link GatewayIntent} that hasn't been requested
*/
boolean requestCacheFlag(@NotNull DiscordCacheFlag cacheFlag, @NotNull DiscordCacheFlag... cacheFlags);
/**
* Requests that the provided {@link DiscordMemberCachePolicy}s be passed to the Discord connection.
*
* @param memberCachePolicy the first member cache policy
* @param memberCachePolicies more member cache policies
* @return {@code true} if the Discord connection is yet to be created and the intent will become active once it is
*/
boolean requestMemberCachePolicy(@NotNull DiscordMemberCachePolicy memberCachePolicy, @NotNull DiscordMemberCachePolicy... memberCachePolicies);
}
| 3,341 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordGatewayIntent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/connection/details/DiscordGatewayIntent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.connection.details;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.requests.GatewayIntent;
public enum DiscordGatewayIntent implements JDAEntity<GatewayIntent> {
GUILD_MEMBERS(GatewayIntent.GUILD_MEMBERS, "Server Members Intent"),
GUILD_MODERATION(GatewayIntent.GUILD_MODERATION),
GUILD_EMOJIS_AND_STICKERS(GatewayIntent.GUILD_EMOJIS_AND_STICKERS),
GUILD_WEBHOOKS(GatewayIntent.GUILD_WEBHOOKS),
GUILD_INVITES(GatewayIntent.GUILD_INVITES),
GUILD_VOICE_STATES(GatewayIntent.GUILD_VOICE_STATES),
GUILD_PRESENCES(GatewayIntent.GUILD_PRESENCES, "Presence Intent"),
GUILD_MESSAGES(GatewayIntent.GUILD_MESSAGES),
GUILD_MESSAGE_REACTIONS(GatewayIntent.GUILD_MESSAGE_REACTIONS),
GUILD_MESSAGE_TYPING(GatewayIntent.GUILD_MESSAGE_TYPING),
DIRECT_MESSAGES(GatewayIntent.DIRECT_MESSAGES),
DIRECT_MESSAGE_REACTIONS(GatewayIntent.DIRECT_MESSAGE_REACTIONS),
DIRECT_MESSAGE_TYPING(GatewayIntent.DIRECT_MESSAGE_TYPING),
MESSAGE_CONTENT(GatewayIntent.MESSAGE_CONTENT, "Message Content Intent"),
SCHEDULED_EVENTS(GatewayIntent.SCHEDULED_EVENTS),
;
static DiscordGatewayIntent getByJda(GatewayIntent jda) {
for (DiscordGatewayIntent value : values()) {
if (value.asJDA() == jda) {
return value;
}
}
throw new IllegalArgumentException("This intent does not have a ");
}
private final GatewayIntent jda;
private final String portalName;
private final boolean privileged;
DiscordGatewayIntent(GatewayIntent jda) {
this(jda, null, false);
}
DiscordGatewayIntent(GatewayIntent jda, String portalName) {
this(jda, portalName, true);
}
DiscordGatewayIntent(GatewayIntent jda, String portalName, boolean privileged) {
this.jda = jda;
this.portalName = portalName;
this.privileged = privileged;
}
public String portalName() {
return portalName;
}
public boolean privileged() {
return privileged;
}
@Override
public GatewayIntent asJDA() {
return jda;
}
}
| 3,429 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordMemberCachePolicy.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/connection/details/DiscordMemberCachePolicy.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.connection.details;
import com.discordsrv.api.DiscordSRVApi;
import com.discordsrv.api.discord.entity.guild.DiscordGuildMember;
import com.discordsrv.api.profile.IProfile;
/**
* Represents a Discord member caching policy, a function which dictates if a given {@link DiscordGuildMember} should be cached.
*/
@FunctionalInterface
public interface DiscordMemberCachePolicy {
DiscordMemberCachePolicy ALL = member -> true;
DiscordMemberCachePolicy LINKED = member -> DiscordSRVApi.optional()
.map(api -> api.profileManager().getProfile(member.getUser().getId()))
.map(IProfile::isLinked).orElse(false);
DiscordMemberCachePolicy VOICE = member -> member.asJDA().getVoiceState() != null;
DiscordMemberCachePolicy OWNER = DiscordGuildMember::isOwner;
boolean isCached(DiscordGuildMember member);
}
| 2,137 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
ErrorCallbackContext.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/connection/jda/errorresponse/ErrorCallbackContext.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.connection.jda.errorresponse;
import net.dv8tion.jda.api.requests.RestAction;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
/**
* Helper class to specify extra context to log with error responses.
*/
public final class ErrorCallbackContext {
private ErrorCallbackContext() {}
/**
* Creates a failure callback that specifies additional context.
* @param context the context of the request
* @return the failure callback
*/
@NotNull
public static Consumer<? super Throwable> context(@NotNull String context) {
return throwable -> RestAction.getDefaultFailure().accept(new Exception(context, throwable));
}
public static class Exception extends java.lang.Exception {
public Exception(String context, Throwable ex) {
super(context, ex);
}
}
}
| 2,161 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Snowflake.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/Snowflake.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity;
import com.discordsrv.api.placeholder.annotation.Placeholder;
/**
* A snowflake identifier.
*/
public interface Snowflake {
/**
* Gets the id of this entity.
* @return the id of this entity
*/
@Placeholder("id")
long getId();
}
| 1,564 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Mentionable.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/Mentionable.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity;
public interface Mentionable {
String getAsMention();
}
| 1,366 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordUser.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/DiscordUser.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity;
import com.discordsrv.api.discord.entity.channel.DiscordDMChannel;
import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import net.dv8tion.jda.api.entities.User;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.concurrent.CompletableFuture;
/**
* A Discord user.
*/
@PlaceholderPrefix("user_")
public interface DiscordUser extends JDAEntity<User>, Snowflake, Mentionable {
/**
* Gets if this user is the bot this DiscordSRV instance is connected.
* @return true if this user is the bot connected to this DiscordSRV instance
*/
boolean isSelf();
/**
* Gets if this user is a bot (or webhook).
* @return true if this user is a bot or webhook
*/
boolean isBot();
/**
* Gets the username of the Discord user.
* @return the user's username
*/
@Placeholder("name")
@NotNull
String getUsername();
/**
* Gets the effective display name of the Discord user.
* @return the user's effective display name
*/
@Placeholder("effective_name")
@NotNull
String getEffectiveName();
/**
* Gets the Discord user's discriminator.
* @return the user's discriminator
*/
@Placeholder("discriminator")
@NotNull
String getDiscriminator();
/**
* Gets the Discord user's avatar url, if an avatar is set.
* @return the user's avatar url or {@code null}
*/
@Placeholder("avatar_url")
@Nullable
String getAvatarUrl();
/**
* Gets the Discord user's avatar that is currently active,
* if an avatar isn't set it'll be the url to the default avatar provided by Discord.
* @return the user's avatar url
*/
@Placeholder("effective_avatar_url")
@NotNull
String getEffectiveAvatarUrl();
/**
* Gets the Discord user's username, including discriminator if any.
* @return the Discord user's username
*/
@Placeholder("tag")
default String getAsTag() {
String username = getUsername();
String discriminator = getDiscriminator();
if (!discriminator.replace("0", "").isEmpty()) {
username = username + "#" + discriminator;
}
return username;
}
/**
* Opens a private channel with the user or instantly returns the already cached private channel for this user.
* @return a future for the private channel with this Discord user
*/
CompletableFuture<DiscordDMChannel> openPrivateChannel();
}
| 3,902 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
JDAEntity.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/JDAEntity.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity;
import com.discordsrv.api.DiscordSRVApi;
import org.jetbrains.annotations.ApiStatus;
/**
* An entity that wraps a JDA entity.
* @param <T> the JDA type
*/
public interface JDAEntity<T> {
/**
* Gets the JDA entity this API object wraps.
*
* <p>
* Please read {@link DiscordSRVApi#jda()} before using.
*
* @return the JDA representation of this object.
*/
@ApiStatus.Experimental
T asJDA();
}
| 1,748 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordGuildMember.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/guild/DiscordGuildMember.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.guild;
import com.discordsrv.api.color.Color;
import com.discordsrv.api.discord.entity.DiscordUser;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.discord.entity.Mentionable;
import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import net.dv8tion.jda.api.entities.Member;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* A Discord server member.
*/
@PlaceholderPrefix("user_")
public interface DiscordGuildMember extends JDAEntity<Member>, Mentionable {
/**
* Gets the user for this member.
* @return the Discord user
*/
@NotNull
DiscordUser getUser();
/**
* Gets the Discord server this member is from.
* @return the Discord server this member is from.
*/
@Placeholder(value = "server", relookup = "server")
@NotNull
DiscordGuild getGuild();
/**
* If this Discord server member is the owner of the Discord server.
* @return {@code true} if this member is the server owner
*/
boolean isOwner();
/**
* Gets the nickname of the Discord server member.
* @return the nickname server member
*/
@Nullable
String getNickname();
/**
* Gets the roles of this Discord server member.
* @return the server member's roles in order from highest to lowest, this does not include the "@everyone" role
*/
@NotNull
List<DiscordRole> getRoles();
/**
* Checks if the member has the given role.
* @param role the role to check for
* @return {@code true} if the member has the role
*/
boolean hasRole(@NotNull DiscordRole role);
/**
* If this member can interact (edit, add/take from members) with the specified role.
* @param role the role
* @return {@code true} if the member has a role above the specified role or is the server owner
*/
boolean canInteract(@NotNull DiscordRole role);
/**
* Gives the given role to this member.
* @param role the role to give
* @return a future
*/
CompletableFuture<Void> addRole(@NotNull DiscordRole role);
/**
* Takes the given role from this member.
* @param role the role to take
* @return a future
*/
CompletableFuture<Void> removeRole(@NotNull DiscordRole role);
/**
* Gets the effective name of this Discord server member.
* @return the Discord server member's effective name
*/
@Placeholder("effective_server_name")
@NotNull
default String getEffectiveServerName() {
String nickname = getNickname();
return nickname != null ? nickname : getUser().getEffectiveName();
}
/**
* Gets the avatar url that is active for this user in this server.
* @return the user's avatar url in this server
*/
@Placeholder("effective_server_avatar_url")
@NotNull
String getEffectiveServerAvatarUrl();
/**
* Gets the color of this user's highest role that has a color.
* @return the color that will be used for this user
*/
@Placeholder(value = "color", relookup = "color")
Color getColor();
/**
* Gets the time the member joined the server.
* @return the time the member joined the server
*/
@Placeholder(value = "time_joined", relookup = "date")
@NotNull
OffsetDateTime getTimeJoined();
/**
* Time the member started boosting.
* @return the time the member started boosting or {@code null}
*/
@Placeholder(value = "time_boosted", relookup = "date")
@Nullable
OffsetDateTime getTimeBoosted();
/**
* If the Discord server member is boosted.
* @return {@code true} if this Discord server member is boosting
*/
@Placeholder("isboosting")
default boolean isBoosting() {
return getTimeBoosted() != null;
}
}
| 5,339 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordRole.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/guild/DiscordRole.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.guild;
import com.discordsrv.api.color.Color;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.discord.entity.Mentionable;
import com.discordsrv.api.discord.entity.Snowflake;
import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import net.dv8tion.jda.api.entities.Role;
import org.jetbrains.annotations.NotNull;
/**
* A Discord server role.
*/
@PlaceholderPrefix("role_")
public interface DiscordRole extends JDAEntity<Role>, Snowflake, Mentionable {
/**
* The default {@link DiscordRole} color.
*/
Color DEFAULT_COLOR = new Color(0xFFFFFF);
/**
* The Discord server this role is from.
* @return the Discord server
*/
@Placeholder(value = "server", relookup = "server")
@NotNull
DiscordGuild getGuild();
/**
* Gets the name of the Discord role.
* @return the role name
*/
@Placeholder("name")
@NotNull
String getName();
/**
* Does this role have a color.
* @return true if this role has a set color
*/
default boolean hasColor() {
return !DEFAULT_COLOR.equals(getColor());
}
/**
* The color of this rule.
* @return the color of this role, or {@link #DEFAULT_COLOR} if there is no color set
* @see #hasColor()
*/
@Placeholder(value = "color", relookup = "color")
@NotNull
Color getColor();
/**
* Is this role hoisted.
* @return true if this role is displayed separately in the member list
*/
boolean isHoisted();
}
| 2,908 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordGuild.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/guild/DiscordGuild.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.guild;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.discord.entity.Snowflake;
import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import net.dv8tion.jda.api.entities.Guild;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
/**
* A Discord server.
*/
@PlaceholderPrefix("server_")
public interface DiscordGuild extends JDAEntity<Guild>, Snowflake {
/**
* Gets the name of this Discord guild.
* @return the guild's name
*/
@Placeholder("name")
@NotNull
String getName();
/**
* Gets the member count of the guild.
* @return the guild's member count
*/
@Placeholder("member_count")
int getMemberCount();
/**
* Gets the bot's membership in the server.
* @return the connected bot's member
*/
@NotNull
DiscordGuildMember getSelfMember();
/**
* Retrieves a Discord guild member from Discord by id.
* @param id the id for the Discord guild member
* @return a future for the Discord guild member
*/
@NotNull
CompletableFuture<DiscordGuildMember> retrieveMemberById(long id);
/**
* Gets a Discord guild member by id from the cache, the provided entity can be cached and will not update if it changes on Discord.
* @param id the id for the Discord guild member
* @return the Discord guild member from the cache
*/
@Nullable
DiscordGuildMember getMemberById(long id);
/**
* Gets the members of this server that are in the cache.
* @return the Discord server members that are currently cached
*/
@NotNull
Set<DiscordGuildMember> getCachedMembers();
/**
* Gets a Discord role by id from the cache, the provided entity can be cached and will not update if it changes on Discord.
* @param id the id for the Discord role
* @return the Discord role from the cache
*/
@Nullable
DiscordRole getRoleById(long id);
/**
* Gets the roles in this Discord server.
* @return an ordered list of the roles in this Discord server
*/
@NotNull
List<DiscordRole> getRoles();
}
| 3,634 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordCustomEmoji.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/guild/DiscordCustomEmoji.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.guild;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.discord.entity.Snowflake;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
@PlaceholderPrefix("emoji_")
public interface DiscordCustomEmoji extends JDAEntity<CustomEmoji>, Snowflake {
String getName();
}
| 1,674 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
ReceivedDiscordMessage.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/message/ReceivedDiscordMessage.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.message;
import com.discordsrv.api.discord.entity.DiscordUser;
import com.discordsrv.api.discord.entity.Snowflake;
import com.discordsrv.api.discord.entity.channel.DiscordDMChannel;
import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel;
import com.discordsrv.api.discord.entity.channel.DiscordTextChannel;
import com.discordsrv.api.discord.entity.guild.DiscordGuild;
import com.discordsrv.api.discord.entity.guild.DiscordGuildMember;
import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* A message received from Discord.
*/
@PlaceholderPrefix("message_")
public interface ReceivedDiscordMessage extends Snowflake {
/**
* Gets the content of this message. This will return {@code null} if the bot doesn't have the MESSAGE_CONTENT intent,
* and this message was not from the bot, did not mention the bot and was not a direct message.
* @return the message content or {@code null}
*/
@Nullable
@Placeholder("content")
String getContent();
/**
* Gets the embeds of this message.
* @return the message embeds
*/
@NotNull
@Unmodifiable
List<DiscordMessageEmbed> getEmbeds();
/**
* Returns {@code true} if this is a webhook message, {@link #getAuthor()} to get webhook username or avatar url.
* @return {@code true} if this is a webhook message
*/
boolean isWebhookMessage();
/**
* Gets the URL to jump to this message.
* @return the jump url
*/
@NotNull
@Placeholder("jump_url")
String getJumpUrl();
/**
* Gets the attachments of this message.
* @return this message's attachments
*/
@NotNull
List<Attachment> getAttachments();
/**
* Determines if this message was sent by this DiscordSRV instance's Discord bot,
* or a webhook being used by this DiscordSRV instance.
* @return true if this message was sent by this DiscordSRV instance
*/
boolean isFromSelf();
/**
* Gets the user that sent the message.
* @return the user that sent the message
*/
@NotNull
@Placeholder(value = "user", relookup = "user")
DiscordUser getAuthor();
/**
* Gets the channel the message was sent in.
* @return the channel the message was sent in
*/
@NotNull
@Placeholder(value = "channel", relookup = "channel")
DiscordMessageChannel getChannel();
/**
* Gets the messages this message is replying to.
* @return the messages this message is replying to or a empty optional
*/
@Nullable
ReceivedDiscordMessage getReplyingTo();
/**
* Gets the text channel the message was sent in. Not present if this message is a dm.
* @return an optional potentially containing the text channel the message was sent in
*/
@Nullable
DiscordTextChannel getTextChannel();
/**
* Gets the dm channel the message was sent in. Not present if this message was sent in a server.
* @return an optional potentially containing the dm channel the message was sent in
*/
@Nullable
DiscordDMChannel getDMChannel();
/**
* Gets the Discord server member that sent this message.
* This is not present if the message was sent by a webhook.
* @return an optional potentially containing the Discord server member that sent this message
*/
@Nullable
DiscordGuildMember getMember();
/**
* Gets the Discord server the message was posted in. This is not present if the message was a dm.
* @return an optional potentially containing the Discord server the message was posted in
*/
@Nullable
@Placeholder(value = "server", relookup = "server")
default DiscordGuild getGuild() {
DiscordTextChannel textChannel = getTextChannel();
return textChannel != null ? textChannel.getGuild() : null;
}
/**
* Deletes this message.
*
* @return a future that will fail if the request fails
*/
@NotNull
CompletableFuture<Void> delete();
/**
* Edits this message to the provided message.
*
* @param message the new message
* @return a future that will fail if the request fails, otherwise the new message provided by the request response
* @throws IllegalArgumentException if the message is not a webhook message,
* but the provided {@link SendableDiscordMessage} specifies a webhook username.
*/
CompletableFuture<ReceivedDiscordMessage> edit(@NotNull SendableDiscordMessage message);
/**
* Send the provided message in the channel this message was sent in, replying to this message.
*
* @param message the message
* @return a future that will fail if the request fails, otherwise the new message provided by the request response
* @throws IllegalArgumentException if the provided message is a webhook message
*/
CompletableFuture<ReceivedDiscordMessage> reply(@NotNull SendableDiscordMessage message);
class Attachment {
private final String fileName;
private final String url;
private final String proxyUrl;
private final int sizeBytes;
public Attachment(String fileName, String url, String proxyUrl, int sizeBytes) {
this.fileName = fileName;
this.url = url;
this.proxyUrl = proxyUrl;
this.sizeBytes = sizeBytes;
}
public String fileName() {
return fileName;
}
public String url() {
return url;
}
public String proxyUrl() {
return proxyUrl;
}
public int sizeBytes() {
return sizeBytes;
}
}
}
| 7,271 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
SendableDiscordMessage.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/message/SendableDiscordMessage.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.message;
import com.discordsrv.api.component.GameTextBuilder;
import com.discordsrv.api.discord.entity.interaction.component.actionrow.MessageActionRow;
import com.discordsrv.api.discord.entity.message.impl.SendableDiscordMessageImpl;
import com.discordsrv.api.placeholder.provider.SinglePlaceholder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.io.InputStream;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A message that can be sent to Discord.
*/
@SuppressWarnings("unused") // API
public interface SendableDiscordMessage {
/**
* Creates a new builder for {@link SendableDiscordMessage}.
* @return a new builder
*/
@NotNull
static Builder builder() {
return new SendableDiscordMessageImpl.BuilderImpl();
}
/**
* The raw content of the message.
* @return the unmodified content of the message
*/
@Nullable
String getContent();
/**
* Gets the embeds of the message.
* @return the unmodifiable list of embeds in this message
*/
@NotNull
@Unmodifiable
List<DiscordMessageEmbed> getEmbeds();
/**
* Gets the action rows.
* @return an unmodifiable list of action rows in this message
*/
@NotNull
@Unmodifiable
List<MessageActionRow> getActionRows();
/**
* Gets the allowed mentions of the message.
* @return the unmodifiable list of allowed mentions in this message
*/
@NotNull
@Unmodifiable
Set<AllowedMention> getAllowedMentions();
/**
* Gets the webhook username.
* @return the webhook username or {@code null} if this isn't a webhook message
*/
@Nullable
String getWebhookUsername();
/**
* Gets the webhook avatar url.
* @return the webhook avatar url or {@code null} if no webhook avatar url is specified
*/
@Nullable
String getWebhookAvatarUrl();
/**
* Returns true if the {@link #getWebhookUsername() webhook username} is specified.
* @return true if this is a webhook message
*/
default boolean isWebhookMessage() {
return getWebhookUsername() != null;
}
/**
* Gets the raw inputs streams and file names for attachments, for this message.
* @return the map of input streams to file names
*/
Map<InputStream, String> getAttachments();
/**
* If notifications for this message are suppressed.
* @return if sending this message doesn't cause a notification
*/
boolean isSuppressedNotifications();
/**
* If embeds for this message are suppressed.
* @return if embeds for this message are suppressed
*/
boolean isSuppressedEmbeds();
/**
* Gets the id for the message this message is in reply to
* @return the message id
*/
Long getMessageIdToReplyTo();
/**
* Creates a copy of this {@link SendableDiscordMessage} with the specified reply message id.
*
* @param replyingToMessageId the reply message id
* @return a new {@link SendableDiscordMessage} identical to the current instance except for the reply message id
*/
SendableDiscordMessage withReplyingToMessageId(Long replyingToMessageId);
/**
* Checks if this message has any sendable content.
* @return {@code true} if there is no sendable content
*/
boolean isEmpty();
@SuppressWarnings("UnusedReturnValue") // API
interface Builder {
/**
* Gets the current content of this message in this builder.
* @return the content
*/
@Nullable
String getContent();
/**
* Changes the content of this builder.
* @param content the new content
* @return the builder, useful for chaining
*/
@NotNull
Builder setContent(String content);
/**
* Gets the embeds that are currently in this builder.
* @return this builder's current embeds
*/
@NotNull
List<DiscordMessageEmbed> getEmbeds();
/**
* Adds an embed to this builder.
* @param embed the embed to add
* @return the builder, useful for chaining
*/
@NotNull
Builder addEmbed(DiscordMessageEmbed embed);
/**
* Removes an embed from this builder.
* @param embed the embed to remove
* @return the builder, useful for chaining
*/
@NotNull
Builder removeEmbed(DiscordMessageEmbed embed);
/**
* Gets the action rows for this builder.
* @return the action rows
*/
List<MessageActionRow> getActionRows();
/**
* Sets the action rows for this builder.
* @param rows the action rows
* @return the builder, useful for chaining
*/
Builder setActionRows(MessageActionRow... rows);
/**
* Adds an action row to this builder.
* @param row the action row
* @return the builder, useful for chaining
*/
Builder addActionRow(MessageActionRow row);
/**
* Removes an action row from this builder.
* @param row the action row
* @return the builder, useful for chaining
*/
Builder removeActionRow(MessageActionRow row);
/**
* Gets the allowed mentions in this builder.
* @return the builder's current allowed mentions
*/
@NotNull
Set<AllowedMention> getAllowedMentions();
/**
* Sets the allowed mentions in for this builder.
*
* @param allowedMentions the allowed mentions
* @return the builder, useful for chaining
*/
@NotNull
Builder setAllowedMentions(@NotNull Collection<AllowedMention> allowedMentions);
/**
* Adds an allowed mention to this builder.
* @param allowedMention the allowed mention to add
* @return the builder, useful for chaining
*/
@NotNull
Builder addAllowedMention(AllowedMention allowedMention);
/**
* Removes an allowed mention from this builder.
* @param allowedMention the allowed mention to remove
* @return the builder, useful for chaining
*/
@NotNull
Builder removeAllowedMention(AllowedMention allowedMention);
/**
* Gets the webhook username for this builder or {@code null} if webhooks are not being used.
* @return the webhook username
*/
@Nullable
String getWebhookUsername();
/**
* Sets the webhook username, setting this enabled webhooks for this message.
* @param webhookUsername the new webhook username
* @return the builder, useful for chaining
*/
@NotNull
Builder setWebhookUsername(String webhookUsername);
/**
* Gets the webhook avatar url for this builder.
* @return the webhook avatar url
*/
@Nullable
String getWebhookAvatarUrl();
/**
* Sets the webhook avatar url for this builder.
* @param webhookAvatarUrl the new webhook avatar url
* @throws IllegalStateException if there is no webhook username set
* @return the builder, useful for chaining
*/
@NotNull
Builder setWebhookAvatarUrl(String webhookAvatarUrl);
/**
* Adds an attachment to this builder.
* @param inputStream an input stream containing the file contents
* @param fileName the name of the file
* @return the builder, useful for chaining
*/
Builder addAttachment(InputStream inputStream, String fileName);
/**
* Sets if this message's notifications will be suppressed.
* @param suppressedNotifications if notifications should be suppressed
* @return this builder, useful for chaining
*/
Builder setSuppressedNotifications(boolean suppressedNotifications);
/**
* Checks if this builder has notifications suppressed.
* @return {@code true} if notifications should be suppressed for this message
*/
boolean isSuppressedNotifications();
/**
* Sets if this message's embeds will be suppressed.
* @param suppressedEmbeds if embeds should be suppressed
* @return this builder, useful for chaining
*/
Builder setSuppressedEmbeds(boolean suppressedEmbeds);
/**
* Checks if this builder has embeds suppressed.
* @return {@code true} if embeds should be suppressed for this message
*/
boolean isSuppressedEmbeds();
/**
* Sets the message this message should be in reply to.
* @param messageId the id for the message this is in reply to
* @return this builder, useful for chaining
*/
Builder setMessageIdToReplyTo(Long messageId);
/**
* Sets the message this message should be in reply to.
* @param message the message this is in reply to
* @return this builder, useful for chaining
*/
default Builder setMessageToReplyTo(@NotNull ReceivedDiscordMessage message) {
return setMessageIdToReplyTo(message.getId());
}
/**
* Gets the id for the message this message is in reply to
* @return the message id
*/
Long getMessageIdToReplyTo();
/**
* Checks if this builder has any sendable content.
* @return {@code true} if there is no sendable content
*/
boolean isEmpty();
/**
* Builds a {@link SendableDiscordMessage} from this builder.
* @return the new {@link SendableDiscordMessage}
*/
@NotNull
SendableDiscordMessage build();
/**
* Creates a new formatter with a clone of this {@link Builder}.
* @return the new {@link Formatter}
*/
Formatter toFormatter();
/**
* Creates a copy of this {@link Builder}.
* @return a copy of this builder
*/
Builder clone();
}
/**
* Discord equivalent for {@link GameTextBuilder}.
*/
interface Formatter {
/**
* Adds context for replacing placeholders via DiscordSRV's {@link com.discordsrv.api.placeholder.PlaceholderService}.
* @param context the context to add
* @return the formatted, useful for chaining
*/
@NotNull
Formatter addContext(Object... context);
default Formatter addPlaceholder(String placeholder, Object replacement) {
return addContext(new SinglePlaceholder(placeholder, replacement));
}
default Formatter addPlaceholder(String placeholder, Supplier<Object> replacementSupplier) {
return addContext(new SinglePlaceholder(placeholder, replacementSupplier));
}
@NotNull
default Formatter addReplacement(String target, Object replacement) {
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
default Formatter addReplacement(Pattern target, Object replacement) {
return addReplacement(target, matcher -> replacement);
}
@NotNull
default Formatter addReplacement(String target, Supplier<Object> replacement) {
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
default Formatter addReplacement(Pattern target, Supplier<Object> replacement) {
return addReplacement(target, matcher -> replacement.get());
}
@NotNull
default Formatter addReplacement(String target, Function<Matcher, Object> replacement) {
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
Formatter addReplacement(Pattern target, Function<Matcher, Object> replacement);
@NotNull
Formatter applyPlaceholderService();
@NotNull
SendableDiscordMessage build();
}
}
| 13,830 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
AllowedMention.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/message/AllowedMention.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.message;
import net.dv8tion.jda.api.entities.Message;
/**
* An allowed mention that can be used with {@link com.discordsrv.api.discord.entity.message.SendableDiscordMessage.Builder#addAllowedMention(AllowedMention)}.
*/
@SuppressWarnings("unused") // API
public interface AllowedMention {
/**
* Permits the @everyone and @here mentions.
*/
AllowedMention EVERYONE = Standard.EVERYONE;
/**
* Permits all role mentions, unless at least one specific role is specified.
*/
AllowedMention ALL_ROLES = Standard.ROLE;
/**
* Permits all user mentions, unless at least one specific user is specified.
*/
AllowedMention ALL_USERS = Standard.USER;
/**
* Permits the role identified by the id to be mentioned.
* @param id the id of the role
* @return a {@link AllowedMention} object
*/
static AllowedMention role(long id) {
return new Snowflake(id, false);
}
/**
* Permits the user identified by the id to be mentioned.
* @param id the id of the user
* @return a {@link AllowedMention} object
*/
static AllowedMention user(long id) {
return new Snowflake(id, true);
}
enum Standard implements AllowedMention {
EVERYONE(Message.MentionType.EVERYONE),
ROLE(Message.MentionType.ROLE),
USER(Message.MentionType.USER),
;
private final Message.MentionType mentionType;
Standard(Message.MentionType mentionType) {
this.mentionType = mentionType;
}
public Message.MentionType getMentionType() {
return mentionType;
}
}
class Snowflake implements AllowedMention {
private final long id;
private final boolean user;
public Snowflake(long id, boolean user) {
this.id = id;
this.user = user;
}
public long getId() {
return id;
}
public boolean isUser() {
return user;
}
}
}
| 3,330 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
ReceivedDiscordMessageCluster.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/message/ReceivedDiscordMessageCluster.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.message;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
/**
* A cluster of Discord messages, or just a single message.
*/
public interface ReceivedDiscordMessageCluster {
/**
* Gets the messages in this cluster.
* @return the messages in this cluster
*/
@NotNull
Set<? extends ReceivedDiscordMessage> getMessages();
/**
* Deletes all the messages from this cluster, one request per message.
* @return a future that fails if any of the requests fail.
*/
@NotNull
CompletableFuture<Void> deleteAll();
/**
* Edits all the messages in this cluster, one request per edit.
* @param newMessage the new content of the messages
* @return a future that fails if any of the requests fail.
*/
@NotNull
CompletableFuture<ReceivedDiscordMessageCluster> editAll(SendableDiscordMessage newMessage);
}
| 2,247 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordMessageEmbed.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/message/DiscordMessageEmbed.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.message;
import com.discordsrv.api.color.Color;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
/**
* A Discord embed.
*/
@SuppressWarnings("unused") // API
public class DiscordMessageEmbed {
/**
* Create a new builder for {@link DiscordMessageEmbed}s.
* @return a new builder
*/
public static Builder builder() {
return new Builder();
}
private final Color color;
private final String authorName, authorUrl, authorImageUrl;
private final String title, titleUrl;
private final String description;
private final List<Field> fields;
private final String thumbnailUrl;
private final String imageUrl;
private final OffsetDateTime timestamp;
private final String footer, footerImageUrl;
public DiscordMessageEmbed(MessageEmbed embed) {
MessageEmbed.AuthorInfo author = embed.getAuthor();
MessageEmbed.Thumbnail thumbnail = embed.getThumbnail();
MessageEmbed.ImageInfo image = embed.getImage();
MessageEmbed.Footer footer = embed.getFooter();
List<Field> fields = new ArrayList<>();
for (MessageEmbed.Field field : embed.getFields()) {
fields.add(new Field(field.getName(), field.getValue(), field.isInline()));
}
this.color = new Color(embed.getColorRaw());
this.authorName = author != null ? author.getName(): null;
this.authorUrl = author != null ? author.getUrl() : null;
this.authorImageUrl = author != null ? author.getIconUrl() : null;
this.title = embed.getTitle();
this.titleUrl = embed.getUrl();
this.description = embed.getDescription();
this.fields = fields;
this.thumbnailUrl = thumbnail != null ? thumbnail.getUrl() : null;
this.imageUrl = image != null ? image.getUrl() : null;
this.timestamp = embed.getTimestamp();
this.footer = footer != null ? footer.getText() : null;
this.footerImageUrl = footer != null ? footer.getIconUrl() : null;
}
public DiscordMessageEmbed(Color color, String authorName, String authorUrl, String authorAvatarUrl, String title,
String titleUrl, String description, List<Field> fields, String thumbnailUrl,
String imageUrl, OffsetDateTime timestamp, String footer, String footerImageUrl) {
this.color = color;
this.authorName = authorName;
this.authorUrl = authorUrl;
this.authorImageUrl = authorAvatarUrl;
this.title = title;
this.titleUrl = titleUrl;
this.description = description;
this.fields = fields;
this.thumbnailUrl = thumbnailUrl;
this.imageUrl = imageUrl;
this.timestamp = timestamp;
this.footer = footer;
this.footerImageUrl = footerImageUrl;
}
@Nullable
public Color getColor() {
return color;
}
@Nullable
public String getAuthorName() {
return authorName;
}
@Nullable
public String getAuthorUrl() {
return authorUrl;
}
@Nullable
public String getAuthorImageUrl() {
return authorImageUrl;
}
@Nullable
public String getTitle() {
return title;
}
@Nullable
public String getTitleUrl() {
return titleUrl;
}
@Nullable
public String getDescription() {
return description;
}
@NotNull
public List<Field> getFields() {
return fields;
}
@Nullable
public String getThumbnailUrl() {
return thumbnailUrl;
}
@Nullable
public String getImageUrl() {
return imageUrl;
}
@Nullable
public OffsetDateTime getTimestamp() {
return timestamp;
}
@Nullable
public String getFooter() {
return footer;
}
@Nullable
public String getFooterImageUrl() {
return footerImageUrl;
}
@NotNull
public Builder toBuilder() {
return new Builder(this);
}
@NotNull
public MessageEmbed toJDA() {
EmbedBuilder embedBuilder = new EmbedBuilder();
if (color != null) {
embedBuilder.setColor(color.rgb());
}
embedBuilder.setAuthor(authorName, authorUrl, authorImageUrl);
embedBuilder.setTitle(title, titleUrl);
embedBuilder.setDescription(description);
for (Field field : fields) {
embedBuilder.addField(new MessageEmbed.Field(field.getTitle(), field.getValue(), field.isInline(), false));
}
embedBuilder.setThumbnail(thumbnailUrl);
embedBuilder.setImage(imageUrl);
embedBuilder.setTimestamp(timestamp);
embedBuilder.setFooter(footer, footerImageUrl);
return embedBuilder.build();
}
public static class Field {
private final String title;
private final String value;
private final boolean inline;
public Field(@Nullable CharSequence title, @Nullable CharSequence value, boolean inline) {
this.title = title != null ? title.toString() : null;
this.value = value != null ? value.toString() : null;
this.inline = inline;
}
@NotNull
public String getTitle() {
return title;
}
@NotNull
public String getValue() {
return value;
}
public boolean isInline() {
return inline;
}
}
@SuppressWarnings("UnusedReturnValue") // API
public static class Builder {
private Color color;
private String authorName, authorUrl, authorImageUrl;
private String title, titleUrl;
private String description;
private final List<Field> fields;
private String thumbnailUrl;
private String imageUrl;
private OffsetDateTime timestamp;
private String footer, footerImageUrl;
protected Builder() {
this.fields = new ArrayList<>();
}
protected Builder(Color color, String authorName, String authorUrl, String authorImageUrl, String title,
String titleUrl, String description, List<Field> fields, String thumbnailUrl, String imageUrl,
OffsetDateTime timestamp, String footer, String footerImageUrl) {
this.color = color;
this.authorName = authorName;
this.authorUrl = authorUrl;
this.authorImageUrl = authorImageUrl;
this.title = title;
this.titleUrl = titleUrl;
this.description = description;
this.fields = new ArrayList<>(fields);
this.thumbnailUrl = thumbnailUrl;
this.imageUrl = imageUrl;
this.timestamp = timestamp;
this.footer = footer;
this.footerImageUrl = footerImageUrl;
}
protected Builder(DiscordMessageEmbed embed) {
this.color = embed.getColor();
this.authorName = embed.getAuthorName();
this.authorUrl = embed.getAuthorUrl();
this.authorImageUrl = embed.getAuthorImageUrl();
this.title = embed.getTitle();
this.titleUrl = embed.getTitleUrl();
this.description = embed.getDescription();
this.fields = new ArrayList<>(embed.getFields());
this.thumbnailUrl = embed.getThumbnailUrl();
this.imageUrl = embed.getImageUrl();
this.timestamp = embed.getTimestamp();
this.footer = embed.getFooter();
this.footerImageUrl = embed.getFooterImageUrl();
}
@Nullable
public Color getColor() {
return color;
}
@NotNull
public Builder setColor(@Nullable Color color) {
this.color = color;
return this;
}
@NotNull
public Builder setColor(int rgb) {
return setColor(new Color(rgb));
}
@NotNull
public Builder setAuthor(@Nullable CharSequence authorName, @Nullable CharSequence authorUrl) {
return setAuthor(authorName, authorUrl, null);
}
@NotNull
public Builder setAuthor(@Nullable CharSequence authorName, @Nullable CharSequence authorUrl, @Nullable CharSequence authorImageUrl) {
this.authorName = authorName != null ? authorName.toString() : null;
this.authorUrl = authorUrl != null ? authorUrl.toString() : null;
this.authorImageUrl = authorImageUrl != null ? authorImageUrl.toString() : null;
return this;
}
@Nullable
public String getAuthorName() {
return authorName;
}
@NotNull
public Builder setAuthorName(@Nullable CharSequence authorName) {
this.authorName = authorName != null ? authorName.toString() : null;
return this;
}
@Nullable
public String getAuthorUrl() {
return authorUrl;
}
@NotNull
public Builder setAuthorUrl(@Nullable CharSequence authorUrl) {
this.authorUrl = authorUrl != null ? authorUrl.toString() : null;
return this;
}
@Nullable
public String getAuthorImageUrl() {
return authorImageUrl;
}
@NotNull
public Builder setAuthorImageUrl(@Nullable CharSequence authorImageUrl) {
this.authorImageUrl = authorImageUrl != null ? authorImageUrl.toString() : null;
return this;
}
@NotNull
public Builder setTitle(@Nullable CharSequence title, @Nullable CharSequence titleUrl) {
this.title = title != null ? title.toString() : null;
this.titleUrl = titleUrl != null ? titleUrl.toString() : null;
return this;
}
@Nullable
public String getTitle() {
return title;
}
@NotNull
public Builder setTitle(@Nullable CharSequence title) {
this.title = title != null ? title.toString() : null;
return this;
}
@Nullable
public String getTitleUrl() {
return titleUrl;
}
@NotNull
public Builder setTitleUrl(@Nullable CharSequence titleUrl) {
this.titleUrl = titleUrl != null ? titleUrl.toString() : null;
return this;
}
@Nullable
public String getDescription() {
return description;
}
@NotNull
public Builder setDescription(@Nullable CharSequence description) {
this.description = description != null ? description.toString() : null;
return this;
}
@NotNull
public List<Field> getFields() {
return fields;
}
@NotNull
public Builder addField(@NotNull CharSequence title, @NotNull CharSequence value, boolean inline) {
return addField(new Field(title, value, inline));
}
@NotNull
public Builder addField(@NotNull Field field) {
this.fields.add(field);
return this;
}
@NotNull
public Builder removeField(@NotNull Field field) {
this.fields.remove(field);
return this;
}
@Nullable
public String getThumbnailUrl() {
return thumbnailUrl;
}
@NotNull
public Builder setThumbnailUrl(@Nullable CharSequence thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl != null ? thumbnailUrl.toString() : null;
return this;
}
@Nullable
public String getImageUrl() {
return imageUrl;
}
@NotNull
public Builder setImageUrl(@Nullable CharSequence imageUrl) {
this.imageUrl = imageUrl != null ? imageUrl.toString() : null;
return this;
}
@Nullable
public OffsetDateTime getTimestamp() {
return timestamp;
}
@NotNull
public Builder setTimestamp(@Nullable OffsetDateTime timestamp) {
this.timestamp = timestamp;
return this;
}
@NotNull
public Builder setFooter(@Nullable CharSequence footer, @Nullable CharSequence footerImageUrl) {
this.footer = footer != null ? footer.toString() : null;
this.footerImageUrl = footerImageUrl != null && footerImageUrl.length() != 0 ? footerImageUrl.toString() : null;
return this;
}
@Nullable
public String getFooter() {
return footer;
}
@NotNull
public Builder setFooter(@Nullable CharSequence footer) {
this.footer = footer != null ? footer.toString() : null;
return this;
}
@Nullable
public String getFooterImageUrl() {
return footerImageUrl;
}
@NotNull
public Builder setFooterImageUrl(@Nullable CharSequence footerImageUrl) {
this.footerImageUrl = footerImageUrl != null ? footerImageUrl.toString() : null;
return this;
}
@NotNull
public DiscordMessageEmbed build() {
return new DiscordMessageEmbed(color, authorName, authorUrl, authorImageUrl, title, titleUrl, description,
fields, thumbnailUrl, imageUrl, timestamp, footer, footerImageUrl);
}
@SuppressWarnings({"MethodDoesntCallSuperMethod"})
@Override
@NotNull
public Builder clone() {
return new Builder(color, authorName, authorUrl, authorImageUrl, title, titleUrl, description,
fields, thumbnailUrl, imageUrl, timestamp, footer, footerImageUrl);
}
}
}
| 15,275 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
SendableDiscordMessageImpl.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/message/impl/SendableDiscordMessageImpl.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.message.impl;
import com.discordsrv.api.DiscordSRVApi;
import com.discordsrv.api.discord.entity.interaction.component.actionrow.MessageActionRow;
import com.discordsrv.api.discord.entity.message.AllowedMention;
import com.discordsrv.api.discord.entity.message.DiscordMessageEmbed;
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
import com.discordsrv.api.discord.util.DiscordFormattingUtil;
import com.discordsrv.api.placeholder.FormattedText;
import com.discordsrv.api.placeholder.PlaceholderService;
import com.discordsrv.api.placeholder.PlainPlaceholderFormat;
import com.discordsrv.api.placeholder.util.Placeholders;
import net.dv8tion.jda.api.entities.MessageEmbed;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.InputStream;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SendableDiscordMessageImpl implements SendableDiscordMessage {
private final String content;
private final List<DiscordMessageEmbed> embeds;
private final List<MessageActionRow> actionRows;
private final Set<AllowedMention> allowedMentions;
private final String webhookUsername;
private final String webhookAvatarUrl;
private final Map<InputStream, String> attachments;
private final boolean suppressedNotifications;
private final boolean suppressedEmbeds;
private final Long replyingToMessageId;
protected SendableDiscordMessageImpl(
String content,
List<DiscordMessageEmbed> embeds,
List<MessageActionRow> actionRows,
Set<AllowedMention> allowedMentions,
String webhookUsername,
String webhookAvatarUrl,
Map<InputStream, String> attachments,
boolean suppressedNotifications,
boolean suppressedEmbeds,
Long replyingToMessageId
) {
this.content = content;
this.embeds = Collections.unmodifiableList(embeds);
this.actionRows = Collections.unmodifiableList(actionRows);
this.allowedMentions = Collections.unmodifiableSet(allowedMentions);
this.webhookUsername = webhookUsername;
this.webhookAvatarUrl = webhookAvatarUrl;
this.attachments = Collections.unmodifiableMap(attachments);
this.suppressedNotifications = suppressedNotifications;
this.suppressedEmbeds = suppressedEmbeds;
this.replyingToMessageId = replyingToMessageId;
}
public SendableDiscordMessageImpl withReplyingToMessageId(Long replyingToMessageId) {
return new SendableDiscordMessageImpl(
content,
embeds,
actionRows,
allowedMentions,
webhookUsername,
webhookAvatarUrl,
attachments,
suppressedNotifications,
suppressedEmbeds,
replyingToMessageId
);
}
@Override
public boolean isEmpty() {
return (content == null || content.isEmpty()) && embeds.isEmpty() && attachments.isEmpty() && actionRows.isEmpty();
}
@Override
public @Nullable String getContent() {
return content;
}
@Override
public @NotNull List<DiscordMessageEmbed> getEmbeds() {
return embeds;
}
@NotNull
@Override
public List<MessageActionRow> getActionRows() {
return actionRows;
}
@Override
public @NotNull Set<AllowedMention> getAllowedMentions() {
return allowedMentions;
}
@Override
public @Nullable String getWebhookUsername() {
return webhookUsername;
}
@Override
public @Nullable String getWebhookAvatarUrl() {
return webhookAvatarUrl;
}
@Override
public boolean isSuppressedNotifications() {
return suppressedNotifications;
}
@Override
public boolean isSuppressedEmbeds() {
return suppressedEmbeds;
}
@Override
public Long getMessageIdToReplyTo() {
return replyingToMessageId;
}
@Override
public Map<InputStream, String> getAttachments() {
return attachments;
}
public static class BuilderImpl implements SendableDiscordMessage.Builder {
private String content;
private final List<DiscordMessageEmbed> embeds = new ArrayList<>();
private final List<MessageActionRow> actionRows = new ArrayList<>();
private final Set<AllowedMention> allowedMentions = new LinkedHashSet<>();
private String webhookUsername;
private String webhookAvatarUrl;
private final Map<InputStream, String> attachments = new LinkedHashMap<>();
private boolean suppressedNotifications;
private boolean suppressedEmbeds;
private Long replyingToMessageId;
@Override
public String getContent() {
return content;
}
@Override
public @NotNull BuilderImpl setContent(String content) {
this.content = content;
return this;
}
@Override
public @NotNull List<DiscordMessageEmbed> getEmbeds() {
return Collections.unmodifiableList(embeds);
}
@Override
public @NotNull Builder addEmbed(DiscordMessageEmbed embed) {
this.embeds.add(embed);
return this;
}
@Override
public @NotNull Builder removeEmbed(DiscordMessageEmbed embed) {
this.embeds.remove(embed);
return this;
}
@Override
public List<MessageActionRow> getActionRows() {
return actionRows;
}
@Override
public Builder setActionRows(MessageActionRow... rows) {
this.actionRows.clear();
this.actionRows.addAll(Arrays.asList(rows));
return this;
}
@Override
public Builder addActionRow(MessageActionRow row) {
this.actionRows.add(row);
return this;
}
@Override
public Builder removeActionRow(MessageActionRow row) {
this.actionRows.remove(row);
return this;
}
@Override
public @NotNull Set<AllowedMention> getAllowedMentions() {
return allowedMentions;
}
@Override
public @NotNull Builder setAllowedMentions(@NotNull Collection<AllowedMention> allowedMentions) {
this.allowedMentions.clear();
this.allowedMentions.addAll(allowedMentions);
return this;
}
@Override
public @NotNull Builder addAllowedMention(AllowedMention allowedMention) {
this.allowedMentions.add(allowedMention);
return this;
}
@Override
public @NotNull Builder removeAllowedMention(AllowedMention allowedMention) {
this.allowedMentions.remove(allowedMention);
return this;
}
@Override
public String getWebhookUsername() {
return webhookUsername;
}
@Override
public @NotNull BuilderImpl setWebhookUsername(String webhookUsername) {
this.webhookUsername = webhookUsername;
return this;
}
@Override
public String getWebhookAvatarUrl() {
return webhookAvatarUrl;
}
@Override
public @NotNull BuilderImpl setWebhookAvatarUrl(String webhookAvatarUrl) {
this.webhookAvatarUrl = webhookAvatarUrl;
return this;
}
@Override
public Builder addAttachment(InputStream inputStream, String fileName) {
this.attachments.put(inputStream, fileName);
return this;
}
@Override
public boolean isEmpty() {
return (content == null || content.isEmpty()) && embeds.isEmpty() && attachments.isEmpty() && actionRows.isEmpty();
}
@Override
public Builder setSuppressedNotifications(boolean suppressedNotifications) {
this.suppressedNotifications = suppressedNotifications;
return this;
}
@Override
public boolean isSuppressedEmbeds() {
return suppressedEmbeds;
}
@Override
public Builder setMessageIdToReplyTo(Long messageId) {
replyingToMessageId = messageId;
return this;
}
@Override
public Long getMessageIdToReplyTo() {
return replyingToMessageId;
}
@Override
public Builder setSuppressedEmbeds(boolean suppressedEmbeds) {
this.suppressedEmbeds = suppressedEmbeds;
return this;
}
@Override
public boolean isSuppressedNotifications() {
return suppressedNotifications;
}
@Override
public @NotNull SendableDiscordMessage build() {
return new SendableDiscordMessageImpl(content, embeds, actionRows, allowedMentions, webhookUsername, webhookAvatarUrl, attachments, suppressedNotifications, suppressedEmbeds, replyingToMessageId);
}
@Override
public Formatter toFormatter() {
return new FormatterImpl(clone());
}
@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public Builder clone() {
BuilderImpl clone = new BuilderImpl();
clone.setContent(content);
embeds.forEach(clone::addEmbed);
allowedMentions.forEach(clone::addAllowedMention);
clone.setWebhookUsername(webhookUsername);
clone.setWebhookAvatarUrl(webhookAvatarUrl);
return clone;
}
}
public static class FormatterImpl implements Formatter {
private final Set<Object> context = new HashSet<>();
private final Map<Pattern, Function<Matcher, Object>> replacements = new LinkedHashMap<>();
private final SendableDiscordMessage.Builder builder;
public FormatterImpl(SendableDiscordMessage.Builder builder) {
this.builder = builder;
}
@Override
public SendableDiscordMessage.@NotNull Formatter addContext(Object... context) {
this.context.addAll(Arrays.asList(context));
return this;
}
@Override
public SendableDiscordMessage.@NotNull Formatter addReplacement(Pattern target, Function<Matcher, Object> replacement) {
this.replacements.put(target, wrapFunction(replacement));
return this;
}
@Override
public @NotNull Formatter applyPlaceholderService() {
DiscordSRVApi api = DiscordSRVApi.get();
if (api == null) {
throw new IllegalStateException("DiscordSRVApi not available");
}
this.replacements.put(
PlaceholderService.PATTERN,
wrapFunction(matcher -> api.placeholderService().getResultAsPlain(matcher, context))
);
return this;
}
private Function<Matcher, Object> wrapFunction(Function<Matcher, Object> function) {
return matcher -> {
Object result = function.apply(matcher);
if (result instanceof FormattedText || PlainPlaceholderFormat.FORMATTING.get() != PlainPlaceholderFormat.Formatting.DISCORD) {
// Process as regular text
return result.toString();
} else if (result instanceof CharSequence) {
// Escape content
return DiscordFormattingUtil.escapeContent(
result.toString());
}
// Use default behaviour for everything else
return result;
};
}
@Override
public @NotNull SendableDiscordMessage build() {
DiscordSRVApi api = DiscordSRVApi.get();
if (api == null) {
throw new IllegalStateException("DiscordSRVApi not available");
}
Function<String, String> placeholders = input -> {
if (input == null) {
return null;
}
Placeholders placeholderUtil = new Placeholders(input)
.addAll(replacements);
// Empty string -> null (so we don't provide empty strings to random fields)
String output = placeholderUtil.toString();
return output.isEmpty() ? null : output;
};
Function<String, String> discordPlaceholders = input -> {
if (input == null) {
return null;
}
// Empty string -> null (so we don't provide empty strings to random fields)
String output = api.discordPlaceholders().map(input, in -> {
// Since this will be processed in parts, we don't want parts to return null, only the full output
String out = placeholders.apply(in);
return out == null ? "" : out;
});
return output.isEmpty() ? null : output;
};
PlainPlaceholderFormat.with(
PlainPlaceholderFormat.Formatting.DISCORD,
() -> builder.setContent(discordPlaceholders.apply(builder.getContent()))
);
List<DiscordMessageEmbed> embeds = new ArrayList<>(builder.getEmbeds());
embeds.forEach(builder::removeEmbed);
for (DiscordMessageEmbed embed : embeds) {
DiscordMessageEmbed.Builder embedBuilder = embed.toBuilder();
embedBuilder.setAuthor(
cutToLength(
placeholders.apply(embedBuilder.getAuthorName()),
MessageEmbed.AUTHOR_MAX_LENGTH
),
placeholders.apply(embedBuilder.getAuthorUrl()),
placeholders.apply(embedBuilder.getAuthorImageUrl()));
embedBuilder.setTitle(
cutToLength(
placeholders.apply(embedBuilder.getTitle()),
MessageEmbed.TITLE_MAX_LENGTH
),
placeholders.apply(embedBuilder.getTitleUrl())
);
embedBuilder.setThumbnailUrl(
placeholders.apply(embedBuilder.getThumbnailUrl())
);
embedBuilder.setImageUrl(
placeholders.apply(embedBuilder.getImageUrl())
);
embedBuilder.setFooter(
cutToLength(
placeholders.apply(embedBuilder.getFooter()),
MessageEmbed.TEXT_MAX_LENGTH
),
placeholders.apply(embedBuilder.getFooterImageUrl())
);
PlainPlaceholderFormat.with(PlainPlaceholderFormat.Formatting.DISCORD, () -> embedBuilder.setDescription(
cutToLength(
discordPlaceholders.apply(embedBuilder.getDescription()),
MessageEmbed.DESCRIPTION_MAX_LENGTH
)
));
List<DiscordMessageEmbed.Field> fields = new ArrayList<>(embedBuilder.getFields());
embedBuilder.getFields().clear();
PlainPlaceholderFormat.with(PlainPlaceholderFormat.Formatting.DISCORD, () ->
fields.forEach(field -> embedBuilder.addField(
cutToLength(
placeholders.apply(field.getTitle()),
MessageEmbed.TITLE_MAX_LENGTH
),
cutToLength(
placeholders.apply(field.getValue()),
MessageEmbed.VALUE_MAX_LENGTH
),
field.isInline()
))
);
builder.addEmbed(embedBuilder.build());
}
builder.setWebhookUsername(placeholders.apply(builder.getWebhookUsername()));
builder.setWebhookAvatarUrl(placeholders.apply(builder.getWebhookAvatarUrl()));
return builder.build();
}
private String cutToLength(String input, int maxLength) {
if (input == null) {
return null;
}
if (input.length() > maxLength) {
return input.substring(0, maxLength);
}
return input;
}
}
}
| 18,255 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordInteractionHook.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/DiscordInteractionHook.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessage;
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
import net.dv8tion.jda.api.interactions.InteractionHook;
import java.util.concurrent.CompletableFuture;
public interface DiscordInteractionHook extends JDAEntity<InteractionHook> {
long getExpiryTime();
boolean isExpired();
CompletableFuture<ReceivedDiscordMessage> editOriginal(SendableDiscordMessage message);
CompletableFuture<ReceivedDiscordMessage> sendMessage(SendableDiscordMessage message, boolean ephemeral);
default CompletableFuture<ReceivedDiscordMessage> sendMessage(SendableDiscordMessage message) {
return sendMessage(message, false);
}
}
| 2,105 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
CommandType.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/command/CommandType.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.command;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
public enum CommandType implements JDAEntity<Command.Type> {
CHAT_INPUT(Command.Type.SLASH, Commands.MAX_SLASH_COMMANDS),
USER(Command.Type.USER, Commands.MAX_USER_COMMANDS),
MESSAGE(Command.Type.MESSAGE, Commands.MAX_MESSAGE_COMMANDS);
private final Command.Type jda;
private final int maximumCount;
CommandType(Command.Type jda, int maximumCount) {
this.jda = jda;
this.maximumCount = maximumCount;
}
@Override
public Command.Type asJDA() {
return jda;
}
public int getMaximumCount() {
return maximumCount;
}
}
| 2,099 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordCommand.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/command/DiscordCommand.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.command;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.discord.entity.interaction.component.ComponentIdentifier;
import com.discordsrv.api.event.events.discord.interaction.command.*;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.build.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.util.*;
import java.util.function.Consumer;
import java.util.regex.Pattern;
/**
* A Discord command.
*/
public class DiscordCommand implements JDAEntity<CommandData> {
private static final String CHAT_INPUT_NAME_REGEX = "(?U)[\\w-]{1,32}";
public static final Pattern CHAT_INPUT_NAME_PATTERN = Pattern.compile(CHAT_INPUT_NAME_REGEX);
/**
* Creates a chat input or slash command builder.
*
* @param id a unique identifier for this interaction, used to check if a given event was for this interaction
* @param name the name of the command, 1-32 characters alphanumeric and dashes
* @param description the description of the command
* @return a new chat input command builder
* @see com.discordsrv.api.event.events.discord.interaction.command.DiscordChatInputInteractionEvent
*/
public static ChatInputBuilder chatInput(
ComponentIdentifier id,
@org.intellij.lang.annotations.Pattern(CHAT_INPUT_NAME_REGEX) String name,
String description
) {
if (!CHAT_INPUT_NAME_PATTERN.matcher(name).matches()) {
throw new IllegalArgumentException("Name must be alphanumeric (dashes allowed), 1 and 32 characters");
}
return new ChatInputBuilder(id, name, description);
}
/**
* Creates a new user context menu command.
*
* @param id a unique identifier for this interaction, used to check if a given event was for this interaction
* @param name the name of the command, 1-32 characters
* @return a new command builder
* @see com.discordsrv.api.event.events.discord.interaction.command.DiscordUserContextInteractionEvent
*/
public static Builder<DiscordUserContextInteractionEvent> user(
ComponentIdentifier id,
@org.intellij.lang.annotations.Pattern(".{1,32}") String name
) {
return new Builder<>(id, CommandType.USER, name);
}
/**
* Creates a new message context menu command.
*
* @param id a unique identifier for this interaction, used to check if a given event was for this interaction
* @param name the name of the command, 1-32 characters
* @return a new command builder
* @see com.discordsrv.api.event.events.discord.interaction.command.DiscordMessageContextInteractionEvent
*/
public static Builder<DiscordMessageContextInteractionEvent> message(
ComponentIdentifier id,
@org.intellij.lang.annotations.Pattern(".{1,32}") String name
) {
return new Builder<>(id, CommandType.MESSAGE, name);
}
private final ComponentIdentifier id;
private final CommandType type;
private final Map<Locale, String> nameTranslations;
private final Map<Locale, String> descriptionTranslations;
private final List<SubCommandGroup> subCommandGroups;
private final List<DiscordCommand> subCommands;
private final List<CommandOption> options;
private final Long guildId;
private final boolean guildOnly;
private final DefaultPermission defaultPermission;
private final Consumer<? extends AbstractCommandInteractionEvent<?>> eventHandler;
private final AutoCompleteHandler autoCompleteHandler;
private DiscordCommand(
ComponentIdentifier id,
CommandType type,
Map<Locale, String> nameTranslations,
Map<Locale, String> descriptionTranslations,
List<SubCommandGroup> subCommandGroups,
List<DiscordCommand> subCommands,
List<CommandOption> options,
Long guildId,
boolean guildOnly,
DefaultPermission defaultPermission,
Consumer<? extends AbstractCommandInteractionEvent<?>> eventHandler,
AutoCompleteHandler autoCompleteHandler
) {
this.id = id;
this.type = type;
this.nameTranslations = nameTranslations;
this.descriptionTranslations = descriptionTranslations;
this.subCommandGroups = subCommandGroups;
this.subCommands = subCommands;
this.options = options;
this.guildId = guildId;
this.guildOnly = guildOnly;
this.defaultPermission = defaultPermission;
this.eventHandler = eventHandler;
this.autoCompleteHandler = autoCompleteHandler;
}
@NotNull
public ComponentIdentifier getId() {
return id;
}
@Nullable
public Long getGuildId() {
return guildId;
}
@NotNull
public CommandType getType() {
return type;
}
@NotNull
public String getName() {
return nameTranslations.get(Locale.ROOT);
}
@NotNull
@Unmodifiable
public Map<Locale, String> getNameTranslations() {
return Collections.unmodifiableMap(nameTranslations);
}
@Nullable
public String getDescription() {
return descriptionTranslations.get(Locale.ROOT);
}
@NotNull
@Unmodifiable
public Map<Locale, String> getDescriptionTranslations() {
return Collections.unmodifiableMap(descriptionTranslations);
}
@NotNull
@Unmodifiable
public List<SubCommandGroup> getSubCommandGroups() {
return Collections.unmodifiableList(subCommandGroups);
}
@NotNull
@Unmodifiable
public List<DiscordCommand> getSubCommands() {
return Collections.unmodifiableList(subCommands);
}
@NotNull
@Unmodifiable
public List<CommandOption> getOptions() {
return Collections.unmodifiableList(options);
}
public boolean isGuildOnly() {
return guildOnly;
}
@NotNull
public DefaultPermission getDefaultPermission() {
return defaultPermission;
}
@Nullable
@SuppressWarnings("unchecked")
public <T extends AbstractCommandInteractionEvent<?>> Consumer<T> getEventHandler() {
if (eventHandler == null) {
return null;
}
return (Consumer<T>) eventHandler;
}
@Nullable
public AutoCompleteHandler getAutoCompleteHandler() {
return autoCompleteHandler;
}
@Override
public CommandData asJDA() {
CommandData commandData;
switch (type) {
case USER:
commandData = Commands.user(getName());
break;
case MESSAGE:
commandData = Commands.message(getName());
break;
case CHAT_INPUT:
SlashCommandData slashCommandData = Commands.slash(getName(), Objects.requireNonNull(getDescription()));
slashCommandData.addSubcommandGroups(subCommandGroups.stream().map(JDAEntity::asJDA).toArray(SubcommandGroupData[]::new));
slashCommandData.addSubcommands(subCommands.stream().map(
DiscordCommand::asJDASubcommand).toArray(SubcommandData[]::new));
slashCommandData.addOptions(options.stream().map(JDAEntity::asJDA).toArray(OptionData[]::new));
commandData = slashCommandData;
break;
default:
throw new IllegalStateException("Missing switch case");
}
commandData.setGuildOnly(guildOnly);
commandData.setDefaultPermissions(defaultPermission.asJDA());
return commandData;
}
public SubcommandData asJDASubcommand() {
SubcommandData data = new SubcommandData(nameTranslations.get(Locale.ROOT), descriptionTranslations.get(Locale.ROOT));
data.addOptions(options.stream().map(JDAEntity::asJDA).toArray(OptionData[]::new));
return data;
}
public static class ChatInputBuilder extends Builder<DiscordChatInputInteractionEvent> {
private final Map<Locale, String> descriptionTranslations = new LinkedHashMap<>();
private final List<SubCommandGroup> subCommandGroups = new ArrayList<>();
private final List<DiscordCommand> subCommands = new ArrayList<>();
private final List<CommandOption> options = new ArrayList<>();
private AutoCompleteHandler autoCompleteHandler;
private ChatInputBuilder(ComponentIdentifier id, String name, String description) {
super(id, CommandType.CHAT_INPUT, name);
this.descriptionTranslations.put(Locale.ROOT, description);
}
/**
* Adds a description translation for this command.
* @param locale the language
* @param translation the translation
* @return this builder, useful for chaining
* @throws IllegalStateException if this isn't a {@link CommandType#CHAT_INPUT} command
*/
@NotNull
public ChatInputBuilder addDescriptionTranslation(@NotNull Locale locale, @NotNull String translation) {
if (type != CommandType.CHAT_INPUT) {
throw new IllegalStateException("Descriptions are only available for CHAT_INPUT commands");
}
this.descriptionTranslations.put(locale, translation);
return this;
}
/**
* Adds a sub command group to this command.
*
* @param subCommandGroup the sub command group
* @return this builder, useful for chaining
*/
@NotNull
public ChatInputBuilder addSubCommandGroup(@NotNull SubCommandGroup subCommandGroup) {
this.subCommandGroups.add(subCommandGroup);
return this;
}
/**
* Adds a sub command to this command.
*
* @param command the sub command
* @return this builder, useful for chaining
*/
@NotNull
public ChatInputBuilder addSubCommand(@NotNull DiscordCommand command) {
this.subCommands.add(command);
return this;
}
/**
* Adds an option to this command.
*
* @param option the option
* @return this builder, useful for chaining
*/
@NotNull
public ChatInputBuilder addOption(@NotNull CommandOption option) {
this.options.add(option);
return this;
}
/**
* Sets the auto complete handler for this command, this can be used instead of listening to the {@link DiscordCommandAutoCompleteInteractionEvent}.
* @param autoCompleteHandler the auto complete handler, only receives events for this command
* @return this builder, useful for chaining
*/
@NotNull
public ChatInputBuilder setAutoCompleteHandler(AutoCompleteHandler autoCompleteHandler) {
this.autoCompleteHandler = autoCompleteHandler;
return this;
}
@Override
public DiscordCommand build() {
return new DiscordCommand(
id,
type,
nameTranslations,
descriptionTranslations,
subCommandGroups,
subCommands,
options,
guildId,
guildOnly,
defaultPermission,
eventHandler,
autoCompleteHandler
);
}
}
@FunctionalInterface
public interface AutoCompleteHandler {
void autoComplete(DiscordCommandAutoCompleteInteractionEvent event);
}
public static class Builder<E extends AbstractCommandInteractionEvent<?>> {
protected final ComponentIdentifier id;
protected final CommandType type;
protected final Map<Locale, String> nameTranslations = new LinkedHashMap<>();
protected Long guildId = null;
protected boolean guildOnly = true;
protected DefaultPermission defaultPermission = DefaultPermission.EVERYONE;
protected Consumer<? extends AbstractCommandInteractionEvent<?>> eventHandler;
private Builder(ComponentIdentifier id, CommandType type, String name) {
this.id = id;
this.type = type;
this.nameTranslations.put(Locale.ROOT, name);
}
/**
* Adds a name translation for this command.
* @param locale the language
* @param translation the translation
* @return this builder, useful for chaining
*/
@NotNull
public Builder<E> addNameTranslation(@NotNull Locale locale, @NotNull String translation) {
this.nameTranslations.put(locale, translation);
return this;
}
/**
* Sets the id of the guild this command should be registered to, or {@code null} to register the command globally.
* @param guildId the guild id
* @return this builder, useful for chaining
*/
public Builder<E> setGuildId(Long guildId) {
this.guildId = guildId;
return this;
}
/**
* Sets if this command is limited to Discord servers.
* @param guildOnly if this command is limited to Discord servers
* @return this builder, useful for chaining
*/
@NotNull
public Builder<E> setGuildOnly(boolean guildOnly) {
this.guildOnly = guildOnly;
return this;
}
/**
* Sets the permission level required to use the command by default.
* @param defaultPermission the permission level
* @return this builder, useful for chaining
*/
@NotNull
public Builder<E> setDefaultPermission(@NotNull DefaultPermission defaultPermission) {
this.defaultPermission = defaultPermission;
return this;
}
/**
* Sets the event handler for this command, this can be used instead of listening to the specific interaction event.
* @param eventHandler the event handler, only receives events for this command
* @return this builder, useful for chaining
*/
@NotNull
public Builder<E> setEventHandler(Consumer<E> eventHandler) {
this.eventHandler = eventHandler;
return this;
}
public DiscordCommand build() {
return new DiscordCommand(
id,
type,
nameTranslations,
Collections.emptyMap(),
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
guildId,
guildOnly,
defaultPermission,
eventHandler,
null
);
}
}
public interface DefaultPermission extends JDAEntity<DefaultMemberPermissions> {
DefaultPermission EVERYONE = new Simple(true);
DefaultPermission ADMINISTRATOR = new Simple(false);
DefaultPermission BAN_MEMBERS = Permissions.fromJDA(Permission.BAN_MEMBERS);
DefaultPermission MODERATE_MEMBERS = Permissions.fromJDA(Permission.MODERATE_MEMBERS);
DefaultPermission MANAGE_PERMISSIONS = Permissions.fromJDA(Permission.MANAGE_PERMISSIONS);
DefaultPermission MESSAGE_MANAGE = Permissions.fromJDA(Permission.MESSAGE_MANAGE);
class Simple implements DefaultPermission {
private final boolean value;
private Simple(boolean value) {
this.value = value;
}
@Override
public DefaultMemberPermissions asJDA() {
return value ? DefaultMemberPermissions.ENABLED : DefaultMemberPermissions.DISABLED;
}
}
class Permissions implements DefaultPermission {
public static Permissions fromJDA(Permission... permissions) {
return new Permissions(Permission.getRaw(permissions));
}
private final long permissions;
public Permissions(long permissions) {
this.permissions = permissions;
}
@Override
public DefaultMemberPermissions asJDA() {
return DefaultMemberPermissions.enabledFor(permissions);
}
}
}
public enum RegistrationResult {
/**
* Indicates that the command was successfully added to the registry, and will be registered.
*/
REGISTERED,
/**
* Command is already registered, and was ignored.
*/
ALREADY_REGISTERED,
/**
* There was already a command with the same name,
* therefor the command won't be registered unless other commands with the same name are unregistered.
*/
NAME_ALREADY_IN_USE,
/**
* There are too many commands of the same type,
* therefore the command won't be registered unless other commands of the same type are unregistered.
*/
TOO_MANY_COMMANDS
}
}
| 18,733 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
CommandOption.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/command/CommandOption.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.command;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.discord.entity.channel.DiscordChannelType;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.util.*;
public class CommandOption implements JDAEntity<OptionData> {
/**
* Creates a new command option builder.
*
* @param type the type of the command option
* @param name the name of the command option
* @param description the description of the command option
* @return the new command option builder
*/
@NotNull
public static Builder builder(@NotNull Type type, @NotNull String name, @NotNull String description) {
return new Builder(type, name, description);
}
private final Type type;
private final String name;
private final String description;
private final Map<String, Object> choices;
private final boolean required;
private final boolean autoComplete;
private final Set<DiscordChannelType> channelTypes;
private final Number minValue;
private final Number maxValue;
public CommandOption(
Type type,
String name,
String description,
Map<String, Object> choices,
boolean required,
boolean autoComplete,
Set<DiscordChannelType> channelTypes,
Number minValue,
Number maxValue
) {
this.type = type;
this.name = name;
this.description = description;
this.choices = choices;
this.required = required;
this.autoComplete = autoComplete;
this.channelTypes = channelTypes;
this.minValue = minValue;
this.maxValue = maxValue;
}
@NotNull
public Type getType() {
return type;
}
@NotNull
public String getName() {
return name;
}
@NotNull
public String getDescription() {
return description;
}
@NotNull
@Unmodifiable
public Map<String, Object> getChoices() {
return Collections.unmodifiableMap(choices);
}
public boolean isRequired() {
return required;
}
public boolean isAutoComplete() {
return autoComplete;
}
@NotNull
@Unmodifiable
public Set<DiscordChannelType> getChannelTypes() {
return channelTypes;
}
@Nullable
public Number getMinValue() {
return minValue;
}
@Nullable
public Number getMaxValue() {
return maxValue;
}
@Override
public OptionData asJDA() {
OptionData data = new OptionData(type.asJDA(), name, description)
.setRequired(required)
.setAutoComplete(autoComplete);
if (type == Type.LONG) {
Number min = getMinValue();
if (min != null) {
data.setMinValue(min.longValue());
}
Number max = getMaxValue();
if (max != null) {
data.setMinValue(max.longValue());
}
}
if (type == Type.DOUBLE) {
Number min = getMinValue();
if (min != null) {
data.setMinValue(min.doubleValue());
}
Number max = getMaxValue();
if (max != null) {
data.setMinValue(max.doubleValue());
}
}
for (Map.Entry<String, Object> entry : choices.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String) {
data.addChoice(key, (String) value);
} else if (value instanceof Number && type == Type.LONG) {
data.addChoice(key, ((Number) value).longValue());
} else if (value instanceof Number && type == Type.DOUBLE) {
data.addChoice(key, ((Number) value).doubleValue());
} else {
throw new IllegalStateException("Not a String, Integer or Double choice value");
}
}
return data;
}
public static class Builder {
private final Type type;
private final String name;
private final String description;
private final Map<String, Object> choices = new LinkedHashMap<>();
private boolean required = false;
private boolean autoComplete = false;
private final Set<DiscordChannelType> channelTypes = new LinkedHashSet<>();
private Number minValue;
private Number maxValue;
private Builder(Type type, String name, String description) {
this.type = type;
this.name = name;
this.description = description;
}
/**
* Adds a String choice, type must be {@link Type#STRING}.
*
* @param name the name of the choice, this will be returned via the event
* @param stringValue the choice
* @return this builder, useful for chaining
*/
@NotNull
public Builder addChoice(String name, String stringValue) {
if (type != Type.STRING) {
throw new IllegalStateException("Must be of type STRING to specify a text choice");
}
this.choices.put(name, stringValue);
return this;
}
/**
* Adds a String choice, type must be {@link Type#LONG} or {@link Type#DOUBLE}.
*
* @param name the name of the choice, this will be returned via the event
* @param value the choice
* @return this builder, useful for chaining
*/
@NotNull
public Builder addChoice(String name, Number value) {
if (type != Type.LONG && type != Type.DOUBLE) {
throw new IllegalStateException("Must be of type INTEGER or DOUBLE to specify a numeric choice");
}
this.choices.put(name, value);
return this;
}
/**
* Sets if this choice is required.
*
* @param required is this choice required
* @return this builder, useful for chaining
*/
@NotNull
public Builder setRequired(boolean required) {
this.required = required;
return this;
}
/**
* Sets if this option is auto completed. See {@link com.discordsrv.api.event.events.discord.interaction.command.DiscordCommandAutoCompleteInteractionEvent}.
*
* @param autoComplete is this choice auto completing
* @return this builder, useful for chaining
* @see com.discordsrv.api.event.events.discord.interaction.command.DiscordCommandAutoCompleteInteractionEvent
*/
@NotNull
public Builder setAutoComplete(boolean autoComplete) {
this.autoComplete = autoComplete;
return this;
}
/**
* Sets the accepted channel types for this option. The type must be {@link Type#CHANNEL} or {@link Type#MENTIONABLE}.
*
* @param types the channel types
* @return this builder, useful for chaining
*/
@NotNull
public Builder setChannelTypes(@NotNull DiscordChannelType... types) {
if (type != Type.CHANNEL && type != Type.MENTIONABLE) {
throw new IllegalStateException("Must be of type CHANNEL or MENTIONABLE to specify channel types");
}
this.channelTypes.clear();
this.channelTypes.addAll(Arrays.asList(types));
return this;
}
/**
* Sets the minimum value for this command option. The type must be {@link Type#LONG} or {@link Type#DOUBLE}.
* @param minValue the minimum value
* @return this builder, useful for chaining
*/
@NotNull
public Builder setMinValue(@Nullable Number minValue) {
if (type != Type.LONG && type != Type.DOUBLE) {
throw new IllegalStateException("Must be of type INTEGER or DOUBLE to specify minimum value");
}
this.minValue = minValue;
return this;
}
/**
* Sets the maximum value for this command option. The type must be {@link Type#LONG} or {@link Type#DOUBLE}.
* @param maxValue the minimum value
* @return this builder, useful for chaining
*/
@NotNull
public Builder setMaxValue(@Nullable Number maxValue) {
if (type != Type.LONG && type != Type.DOUBLE) {
throw new IllegalStateException("Must be of type INTEGER or DOUBLE to specify maximum value");
}
this.maxValue = maxValue;
return this;
}
@NotNull
public CommandOption build() {
if (minValue != null && maxValue != null && minValue.doubleValue() >= maxValue.doubleValue()) {
throw new IllegalStateException("Minimum value cannot be greater than or equal to maximum value");
}
if (!choices.isEmpty() && autoComplete) {
throw new IllegalStateException("Cannot use auto complete and specify choices at the same time");
}
return new CommandOption(type, name, description, choices, required, autoComplete, channelTypes, minValue, maxValue);
}
}
public enum Type implements JDAEntity<OptionType> {
STRING(OptionType.STRING),
LONG(OptionType.INTEGER),
DOUBLE(OptionType.NUMBER),
BOOLEAN(OptionType.BOOLEAN),
USER(OptionType.USER),
CHANNEL(OptionType.CHANNEL),
ROLE(OptionType.ROLE),
MENTIONABLE(OptionType.MENTIONABLE),
ATTACHMENT(OptionType.ATTACHMENT);
private final OptionType optionType;
Type(OptionType optionType) {
this.optionType = optionType;
}
public boolean isSupportsChoices() {
return optionType.canSupportChoices();
}
@Override
public OptionType asJDA() {
return optionType;
}
}
}
| 11,582 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
SubCommandGroup.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/command/SubCommandGroup.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.command;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import java.util.Arrays;
import java.util.List;
public class SubCommandGroup implements JDAEntity<SubcommandGroupData> {
/**
* Creates a sub command group.
*
* @param name the sub command group name
* @param description the sub command group description
* @param commands the commands within the sub command group
* @return a new sub command group
*/
@NotNull
public static SubCommandGroup of(@NotNull String name, @NotNull String description, @NotNull DiscordCommand... commands) {
return new SubCommandGroup(name, description, Arrays.asList(commands));
}
private final String name;
private final String description;
private final List<DiscordCommand> commands;
private SubCommandGroup(String name, String description, List<DiscordCommand> commands) {
this.name = name;
this.description = description;
this.commands = commands;
}
@NotNull
public String getName() {
return name;
}
@NotNull
public String getDescription() {
return description;
}
@NotNull
@Unmodifiable
public List<DiscordCommand> getCommands() {
return commands;
}
@Override
public SubcommandGroupData asJDA() {
return new SubcommandGroupData(name, description)
.addSubcommands(commands.stream().map(DiscordCommand::asJDASubcommand).toArray(SubcommandData[]::new));
}
}
| 3,061 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
ComponentIdentifier.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/ComponentIdentifier.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component;
import org.intellij.lang.annotations.Subst;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
import java.util.regex.Pattern;
/**
* An identifier for commands and components to match up with interaction events, and to avoid conflicts between extensions.
*/
public class ComponentIdentifier {
private static final String ID_PREFIX = "DiscordSRV/";
private static final char PART_SEPARATOR = ':';
private static final String REGEX = "[\\w\\d-_]{1,40}";
private static final Pattern PATTERN = java.util.regex.Pattern.compile(REGEX);
/**
* Creates a new {@link ComponentIdentifier}.
*
* @param extensionName the name of the plugin or mod that owns this identifier (1-40 characters, a-z, A-Z, 0-9, -, _)
* @param identifier the identifier of this component (1-40 characters, a-z, A-Z, 0-9, -, _)
* @return a new {@link ComponentIdentifier}
* @throws IllegalArgumentException if the extension name or identifier does not match the required constraints
*/
@NotNull
public static ComponentIdentifier of(
@NotNull @org.intellij.lang.annotations.Pattern(REGEX) String extensionName,
@NotNull @org.intellij.lang.annotations.Pattern(REGEX) String identifier
) {
if (!PATTERN.matcher(extensionName).matches()) {
throw new IllegalArgumentException("Extension name does not match the required pattern");
} else if (!PATTERN.matcher(identifier).matches()) {
throw new IllegalArgumentException("Identifier does not match the required pattern");
}
return new ComponentIdentifier(extensionName, identifier);
}
@Nullable
public static ComponentIdentifier parseFromDiscord(@NotNull String discordIdentifier) {
if (!discordIdentifier.startsWith(ID_PREFIX)) {
return null;
}
discordIdentifier = discordIdentifier.substring(ID_PREFIX.length());
@Subst("Example:Test")
String[] parts = discordIdentifier.split(Pattern.quote(ID_PREFIX));
if (parts.length != 2) {
return null;
}
try {
return of(parts[0], parts[1]);
} catch (IllegalStateException ignored) {
return null;
}
}
private final String extensionName;
private final String identifier;
private ComponentIdentifier(String extensionName, String identifier) {
this.extensionName = extensionName;
this.identifier = identifier;
}
public String getExtensionName() {
return extensionName;
}
public String getIdentifier() {
return identifier;
}
public String getDiscordIdentifier() {
return ID_PREFIX + getExtensionName() + PART_SEPARATOR + getIdentifier();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ComponentIdentifier that = (ComponentIdentifier) o;
return Objects.equals(extensionName, that.extensionName) && Objects.equals(identifier, that.identifier);
}
@Override
public int hashCode() {
return Objects.hash(extensionName, identifier);
}
@Override
public String toString() {
return "ComponentIdentifier{" +
"extensionName='" + extensionName + '\'' +
", identifier='" + identifier + '\'' +
'}';
}
}
| 4,826 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordComponent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/DiscordComponent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
public interface DiscordComponent<T extends ItemComponent> extends JDAEntity<T> {}
| 1,529 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
MessageComponent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/MessageComponent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
public interface MessageComponent extends DiscordComponent<ItemComponent> {
}
| 1,472 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
ModalComponent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/ModalComponent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
public interface ModalComponent extends DiscordComponent<ItemComponent> {
}
| 1,470 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
ActionRow.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/actionrow/ActionRow.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component.actionrow;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.discord.entity.interaction.component.DiscordComponent;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
import java.util.List;
import java.util.stream.Collectors;
public interface ActionRow<T extends DiscordComponent<? extends ItemComponent>> extends JDAEntity<net.dv8tion.jda.api.interactions.components.ActionRow> {
List<T> components();
@Override
default net.dv8tion.jda.api.interactions.components.ActionRow asJDA() {
return net.dv8tion.jda.api.interactions.components.ActionRow.of(
components().stream().map(DiscordComponent::asJDA).collect(Collectors.toList())
);
}
}
| 2,058 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
ModalActionRow.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/actionrow/ModalActionRow.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component.actionrow;
import com.discordsrv.api.discord.entity.interaction.component.ModalComponent;
import java.util.Arrays;
import java.util.List;
public class ModalActionRow implements ActionRow<ModalComponent> {
public static ModalActionRow of(ModalComponent... components) {
if (components.length == 0) {
throw new IllegalArgumentException("Must include at least one component");
}
return new ModalActionRow(Arrays.asList(components));
}
private final List<ModalComponent> components;
private ModalActionRow(List<ModalComponent> components) {
this.components = components;
}
@Override
public List<ModalComponent> components() {
return components;
}
}
| 2,061 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
MessageActionRow.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/actionrow/MessageActionRow.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component.actionrow;
import com.discordsrv.api.discord.entity.interaction.component.MessageComponent;
import java.util.Arrays;
import java.util.List;
public class MessageActionRow implements ActionRow<MessageComponent> {
public static MessageActionRow of(MessageComponent... components) {
if (components.length == 0) {
throw new IllegalArgumentException("Must include at least one component");
}
return new MessageActionRow(Arrays.asList(components));
}
private final List<MessageComponent> components;
private MessageActionRow(List<MessageComponent> components) {
this.components = components;
}
@Override
public List<MessageComponent> components() {
return components;
}
}
| 2,081 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
SelectMenu.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/impl/SelectMenu.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component.impl;
import com.discordsrv.api.discord.entity.guild.DiscordCustomEmoji;
import com.discordsrv.api.discord.entity.interaction.component.ComponentIdentifier;
import com.discordsrv.api.discord.entity.interaction.component.MessageComponent;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
import org.jetbrains.annotations.NotNull;
import javax.annotation.CheckReturnValue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A Discord selection menu.
* @see #builder(ComponentIdentifier)
* @see com.discordsrv.api.event.events.discord.interaction.component.DiscordSelectMenuInteractionEvent
*/
// TODO: newest changes
public class SelectMenu implements MessageComponent {
/**
* Creates a selection menu builder.
*
* @param id a unique identifier for this interaction, used to check if a given event was for this interaction
* @return a new builder
*/
public static Builder builder(@NotNull ComponentIdentifier id) {
return new Builder(id.getDiscordIdentifier());
}
private final String id;
private final List<Option> options;
private final boolean disabled;
private final String placeholder;
private final int minValues;
private final int maxValues;
private SelectMenu(String id, List<Option> options, boolean disabled, String placeholder, int minValues, int maxValues) {
this.id = id;
this.options = options;
this.disabled = disabled;
this.placeholder = placeholder;
this.minValues = minValues;
this.maxValues = maxValues;
}
@Override
public ItemComponent asJDA() {
return null;
// net.dv8tion.jda.api.interactions.components.selections.SelectMenu.Builder<?, ?> builder =
// new net.dv8tion.jda.api.interactions.components.selections.SelectMenu.Builder<>(id)
// .setDisabled(disabled)
// .setPlaceholder(placeholder)
// .setMinValues(minValues)
// .setMaxValues(maxValues);
//
// Set<SelectOption> defaultOptions = new HashSet<>();
// for (Option option : options) {
// SelectOption selectOption = SelectOption.of(option.getLabel(), option.getValue())
// .withEmoji(option.getEmoji())
// .withDescription(option.getDescription());
//
// builder.addOptions(selectOption);
// if (option.isDefault()) {
// defaultOptions.add(selectOption);
// }
// }
// builder.setDefaultOptions(defaultOptions);
//
// return builder.build();
}
/**
* A selection menu option.
* @see #of(String, String)
*/
public static class Option {
/**
* Creates a new selection menu option.
* @param label the label for the option
* @param value the value of the option, this is sent back to you when a selection is made
* @return a new option
*/
public static Option of(String label, String value) {
return new Option(label, value, null, null, false);
}
private final String label;
private final String value;
private final String description;
private final Emoji emoji;
private final boolean defaultSelected;
private Option(String label, String value, String description, Emoji emoji, boolean defaultSelected) {
this.label = label;
this.value = value;
this.description = description;
this.emoji = emoji;
this.defaultSelected = defaultSelected;
}
public String getLabel() {
return label;
}
public String getValue() {
return value;
}
public String getDescription() {
return description;
}
public Emoji getEmoji() {
return emoji;
}
public boolean isDefault() {
return defaultSelected;
}
/**
* Creates a new option with the provided description.
* @param description the new description
* @return a new option
*/
@CheckReturnValue
public Option withDescription(String description) {
return new Option(label, value, description, emoji, defaultSelected);
}
/**
* Creates a new option with the provided emoji.
* @param unicodeEmoji the unicode codepoint for the emoji
* @return a new option
*/
@CheckReturnValue
public Option withEmoji(String unicodeEmoji) {
return new Option(label, value, description, Emoji.fromUnicode(unicodeEmoji), defaultSelected);
}
/**
* Creates a new option with the provided emote.
* @param emote the Discord server/guild emote
* @return a new option
*/
@CheckReturnValue
public Option withEmoji(DiscordCustomEmoji emote) {
return new Option(label, value, description, Emoji.fromCustom(emote.asJDA()), defaultSelected);
}
/**
* Creates a new option with the provided default selection state.
* @param defaultSelected if the option should be selected by default
* @return a new option
*/
@CheckReturnValue
public Option withDefaultSelected(boolean defaultSelected) {
return new Option(label, value, description, emoji, defaultSelected);
}
}
private static class Builder {
private final String id;
private final List<Option> options = new ArrayList<>();
private boolean disabled = false;
private String placeholder;
private int minValues = 0;
private int maxValues = 1;
public Builder(String id) {
this.id = id;
}
/**
* Adds an option to this selection menu.
* @param option the option to add
* @return this builder, useful for chaining
* @see Option#of(String, String)
*/
@NotNull
public Builder addOption(Option option) {
this.options.add(option);
return this;
}
/**
* Adds multiple options to this selection menu.
* @param options the options to add
* @return this builder, useful for chaining
*/
@NotNull
public Builder addOptions(Option... options) {
this.options.addAll(Arrays.asList(options));
return this;
}
/**
* Sets if this selection menu should be disabled. Default is {@code false}.
* @param disabled if this selection menu should be disabled
* @return this builder, useful for chaining
*/
@NotNull
public Builder setDisabled(boolean disabled) {
this.disabled = disabled;
return this;
}
/**
* Sets the placeholder text for this selection menu.
* @param placeholder the placeholder text
* @return this builder, useful for chaining
*/
public Builder setPlaceholder(String placeholder) {
this.placeholder = placeholder;
return this;
}
/**
* Sets the minimum amount of values to select. The default is {@code 0}.
* @param minValues the minimum value amount
* @return this builder, useful for chaining
*/
public Builder setMinValues(int minValues) {
this.minValues = minValues;
return this;
}
/**
* Sets the maximum amount of values to select. The default is {@code 1}.
* @param maxValues the maximum value amount
* @return this builder, useful for chaining
*/
public Builder setMaxValues(int maxValues) {
this.maxValues = maxValues;
return this;
}
/**
* Builds the selection menu.
* @return a new selection menu
*/
public SelectMenu build() {
return new SelectMenu(id, options, disabled, placeholder, minValues, maxValues);
}
}
}
| 9,639 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Button.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/impl/Button.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component.impl;
import com.discordsrv.api.discord.entity.guild.DiscordCustomEmoji;
import com.discordsrv.api.discord.entity.interaction.component.ComponentIdentifier;
import com.discordsrv.api.discord.entity.interaction.component.MessageComponent;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
/**
* A Discord button.
* @see #builder(ComponentIdentifier, Style)
* @see #urlBuilder(String)
* @see com.discordsrv.api.event.events.discord.interaction.component.DiscordButtonInteractionEvent
*/
public class Button implements MessageComponent {
/**
* Creates a new Button builder.
*
* @param id a unique identifier for this interaction, used to check if a given event was for this interaction
* @param style the style of the button
* @return a new button builder
*/
@NotNull
public static Builder builder(@NotNull ComponentIdentifier id, @NotNull Button.Style style) {
return new Builder(id.getDiscordIdentifier(), style);
}
/**
* Creates a new Link button builder.
*
* @param url the link the button leads to
* @return a new button builder
*/
@NotNull
public static Builder urlBuilder(@NotNull String url) {
return new Builder(null, Style.LINK).setUrl(url);
}
private final Style buttonStyle;
private final String idOrUrl;
private final String label;
private final Emoji emoji;
private final boolean disabled;
private Button(
String id,
Style buttonStyle,
String url,
String label,
Emoji emoji,
boolean disabled
) {
this.buttonStyle = buttonStyle;
this.idOrUrl = buttonStyle == Style.LINK ? url : id;
this.label = label;
this.emoji = emoji;
this.disabled = disabled;
}
@NotNull
public Style getButtonStyle() {
return buttonStyle;
}
@Nullable
public String getUrl() {
return buttonStyle == Style.LINK ? idOrUrl : null;
}
@NotNull
public String getLabel() {
return label;
}
@Nullable
public Emoji getJDAEmoji() {
return emoji;
}
public boolean isDisabled() {
return disabled;
}
@Override
public ItemComponent asJDA() {
return net.dv8tion.jda.api.interactions.components.buttons.Button.of(
buttonStyle.getJDA(),
idOrUrl,
label,
emoji
).withDisabled(disabled);
}
private static class Builder {
private final String id;
private final Style style;
private String url;
private String label;
private Emoji emoji;
private boolean disabled;
private Builder(String id, Style style) {
this.id = id;
this.style = style;
}
/**
* Sets the url for this button, only works if the style is {@link Style#LINK}.
*
* @param url the url for this button
* @return this builder, useful for chaining
*/
@NotNull
public Builder setUrl(@NotNull String url) {
if (style != Style.LINK) {
throw new IllegalStateException("Style must be LINK to set a url");
}
this.url = url;
return this;
}
/**
* Sets the text shown on this button.
* @param label the text
* @return this builder, useful for chaining
*/
@NotNull
public Builder setLabel(String label) {
this.label = label;
return this;
}
/**
* Sets the emoji to show on this button.
* @param unicodeEmoji the unicode code point for the emoji
* @return this builder, useful for chaining
*/
@NotNull
public Builder setEmoji(String unicodeEmoji) {
this.emoji = Emoji.fromUnicode(unicodeEmoji);
return this;
}
/**
* Sets the emoji to show on this button.
* @param emote the Discord server/guild emote
* @return this builder, useful for chaining
*/
@NotNull
public Builder setEmoji(DiscordCustomEmoji emote) {
this.emoji = Emoji.fromCustom(emote.asJDA());
return this;
}
/**
* Set if this button is disabled or not. Default is {@code false}.
* @param disabled if this button should be disabled
* @return this builder, useful for chaining
*/
@NotNull
public Builder setDisabled(boolean disabled) {
this.disabled = disabled;
return this;
}
/**
* Creates the button.
* @return a new button
*/
public Button build() {
if (style == null) {
throw new IllegalStateException("No style set");
}
return new Button(
id,
style,
style == Style.LINK ? url : UUID.randomUUID().toString(),
label,
emoji,
disabled
);
}
}
public enum Style {
PRIMARY(ButtonStyle.PRIMARY),
SECONDARY(ButtonStyle.SECONDARY),
SUCCESS(ButtonStyle.SUCCESS),
DANGER(ButtonStyle.DANGER),
LINK(ButtonStyle.LINK);
private final ButtonStyle style;
Style(ButtonStyle style) {
this.style = style;
}
public ButtonStyle getJDA() {
return style;
}
}
}
| 7,195 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
TextInput.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/impl/TextInput.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component.impl;
import com.discordsrv.api.discord.entity.interaction.component.ComponentIdentifier;
import com.discordsrv.api.discord.entity.interaction.component.ModalComponent;
import net.dv8tion.jda.api.interactions.components.ItemComponent;
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
import org.jetbrains.annotations.NotNull;
/**
* A Discord text input, a modal component.
* @see #builder(ComponentIdentifier, String, Style)
*/
public class TextInput implements ModalComponent {
/**
* Creates a new text input builder with the given label and style.
*
* @param id a unique identifier for this component, used to check for the value of the input
* @param label the label shown above the text input
* @param style the style of the text input
* @return a new text input builder
*/
@NotNull
public static Builder builder(@NotNull ComponentIdentifier id, @NotNull String label, @NotNull Style style) {
return new Builder(id.getDiscordIdentifier(), label, style);
}
private final String id;
private final String label;
private final Style style;
private final int minLength;
private final int maxLength;
private final String placeholder;
private final boolean required;
private final String defaultValue;
public TextInput(
String id,
String label,
Style style,
int minLength,
int maxLength,
String placeholder,
boolean required,
String defaultValue
) {
this.id = id;
this.label = label;
this.style = style;
this.minLength = minLength;
this.maxLength = maxLength;
this.placeholder = placeholder;
this.required = required;
this.defaultValue = defaultValue;
}
public String getLabel() {
return label;
}
public Style getStyle() {
return style;
}
public int getMinLength() {
return minLength;
}
public int getMaxLength() {
return maxLength;
}
public String getPlaceholder() {
return placeholder;
}
public boolean isRequired() {
return required;
}
public String getDefaultValue() {
return defaultValue;
}
@Override
public ItemComponent asJDA() {
net.dv8tion.jda.api.interactions.components.text.TextInput.Builder builder =
net.dv8tion.jda.api.interactions.components.text.TextInput.create(id, label, style.getJda())
.setMinLength(minLength)
.setMaxLength(maxLength)
.setPlaceholder(placeholder)
.setRequired(required)
.setValue(defaultValue);
return builder.build();
}
public static class Builder {
private final String id;
private final String label;
private final Style style;
private int minLength = 0;
private int maxLength = Integer.MAX_VALUE;
private String placeholder;
private boolean required = true;
private String defaultValue;
private Builder(String id, String label, Style style) {
this.id = id;
this.label = label;
this.style = style;
}
public Builder setMinLength(int minLength) {
this.minLength = minLength;
return this;
}
public Builder setMaxLength(int maxLength) {
this.maxLength = maxLength;
return this;
}
public Builder setPlaceholder(String placeholder) {
this.placeholder = placeholder;
return this;
}
public Builder setRequired(boolean required) {
this.required = required;
return this;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public TextInput build() {
return new TextInput(
id,
label,
style,
minLength,
maxLength,
placeholder,
required,
defaultValue
);
}
}
public enum Style {
PARAGRAPH(TextInputStyle.PARAGRAPH),
SHORT(TextInputStyle.SHORT);
private final TextInputStyle jda;
Style(TextInputStyle jda) {
this.jda = jda;
}
public TextInputStyle getJda() {
return jda;
}
}
}
| 5,955 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Modal.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/impl/Modal.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.interaction.component.impl;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.discord.entity.interaction.component.ComponentIdentifier;
import com.discordsrv.api.discord.entity.interaction.component.actionrow.ActionRow;
import com.discordsrv.api.discord.entity.interaction.component.actionrow.ModalActionRow;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* A Discord modal.
* @see #builder(ComponentIdentifier, String)
* @see com.discordsrv.api.event.events.discord.interaction.DiscordModalInteractionEvent
*/
public class Modal implements JDAEntity<net.dv8tion.jda.api.interactions.modals.Modal> {
/**
* Creates a new modal builder.
*
* @param id a unique identifier for this interaction, used to check if a given event was for this interaction
* @param title the title of the modal
* @return a new modal builder
*/
@NotNull
public static Builder builder(@NotNull ComponentIdentifier id, @NotNull String title) {
return new Builder(id.getDiscordIdentifier(), title);
}
private final String id;
private final String title;
private final List<ModalActionRow> rows;
private Modal(String id, String title, List<ModalActionRow> rows) {
this.id = id;
this.title = title;
this.rows = rows;
}
public String getTitle() {
return title;
}
public List<ModalActionRow> getRows() {
return rows;
}
public Modal addRow(ModalActionRow row) {
this.rows.add(row);
return this;
}
@Override
public net.dv8tion.jda.api.interactions.modals.Modal asJDA() {
return net.dv8tion.jda.api.interactions.modals.Modal.create(id, title)
.addComponents(rows.stream().map(ActionRow::asJDA).collect(Collectors.toList()))
.build();
}
private static class Builder {
private final String id;
private final String title;
private final List<ModalActionRow> rows = new ArrayList<>();
public Builder(String id, String title) {
this.id = id;
this.title = title;
}
/**
* Adds an action row to this modal.
* @param row the row to add
* @return this builder, useful for chaining
*/
@NotNull
public Builder addRow(ModalActionRow row) {
this.rows.add(row);
return this;
}
/**
* Adds multiple action rows to this modal.
* @param rows the rows to add
* @return this builder, useful for chaining
*/
@NotNull
public Builder addRows(ModalActionRow... rows) {
this.rows.addAll(Arrays.asList(rows));
return this;
}
/**
* Builds the modal.
* @return a new modal
*/
public Modal build() {
return new Modal(id, title, rows);
}
}
}
| 4,361 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordChannel.java | package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.Snowflake;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
@PlaceholderPrefix("channel_")
public interface DiscordChannel extends Snowflake {
/**
* Returns the type of channel this is.
* @return the type of the channel
*/
DiscordChannelType getType();
}
| 392 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordVoiceChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordVoiceChannel.java | package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
public interface DiscordVoiceChannel extends DiscordGuildMessageChannel, JDAEntity<VoiceChannel> {
@Override
default DiscordChannelType getType() {
return DiscordChannelType.VOICE;
}
}
| 378 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordGuildMessageChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordGuildMessageChannel.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.Mentionable;
/**
* A regular Discord channel that messages can be sent to.
*/
public interface DiscordGuildMessageChannel extends DiscordMessageChannel, DiscordGuildChannel, Mentionable {}
| 1,546 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordChannelType.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordChannelType.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.entities.channel.ChannelType;
/**
* Represents a Discord channel type.
*/
public enum DiscordChannelType implements JDAEntity<ChannelType> {
TEXT(ChannelType.TEXT),
PRIVATE(ChannelType.PRIVATE),
VOICE(ChannelType.VOICE),
GROUP(ChannelType.GROUP),
CATEGORY(ChannelType.CATEGORY),
FORUM(ChannelType.FORUM),
NEWS(ChannelType.NEWS),
STAGE(ChannelType.STAGE),
GUILD_NEWS_THREAD(ChannelType.GUILD_NEWS_THREAD),
GUILD_PUBLIC_THREAD(ChannelType.GUILD_PUBLIC_THREAD),
GUILD_PRIVATE_THREAD(ChannelType.GUILD_PRIVATE_THREAD),
;
private final ChannelType jda;
DiscordChannelType(ChannelType jda) {
this.jda = jda;
}
@Override
public ChannelType asJDA() {
return jda;
}
}
| 2,146 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordMessageChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordMessageChannel.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.DiscordSRVApi;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessage;
import com.discordsrv.api.discord.entity.message.SendableDiscordMessage;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
/**
* A Discord channel that can send/receive messages.
*/
public interface DiscordMessageChannel extends DiscordChannel {
/**
* Sends the provided message to the channel.
*
* @param message the message to send to the channel
* @return a future returning the message after being sent
*/
@NotNull
CompletableFuture<ReceivedDiscordMessage> sendMessage(@NotNull SendableDiscordMessage message);
/**
* Deletes the message identified by the id.
*
* @param id the id of the message to delete
* @param webhookMessage if the message is a webhook message or not
* @return a future that will fail if the request fails
*/
CompletableFuture<Void> deleteMessageById(long id, boolean webhookMessage);
/**
* Edits the message identified by the id.
*
* @param id the id of the message to edit
* @param message the new message content
* @return a future returning the message after being edited
*/
@NotNull
CompletableFuture<ReceivedDiscordMessage> editMessageById(long id, @NotNull SendableDiscordMessage message);
/**
* Returns the JDA representation of this object. This should not be used if it can be avoided.
* @return the JDA representation of this object
* @see DiscordSRVApi#jda()
*/
MessageChannel getAsJDAMessageChannel();
}
| 3,031 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordNewsChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordNewsChannel.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.entities.channel.concrete.NewsChannel;
public interface DiscordNewsChannel extends DiscordGuildMessageChannel, DiscordThreadContainer, JDAEntity<NewsChannel> {
@Override
default DiscordChannelType getType() {
return DiscordChannelType.NEWS;
}
}
| 1,660 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordStageChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordStageChannel.java | package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.entities.channel.concrete.StageChannel;
public interface DiscordStageChannel extends DiscordGuildMessageChannel, JDAEntity<StageChannel> {
@Override
default DiscordChannelType getType() {
return DiscordChannelType.STAGE;
}
}
| 378 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordThreadContainer.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordThreadContainer.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.channel;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* A Discord channel that contains threads.
*/
public interface DiscordThreadContainer extends DiscordGuildChannel {
@NotNull
List<DiscordThreadChannel> getActiveThreads();
CompletableFuture<List<DiscordThreadChannel>> retrieveArchivedPrivateThreads();
CompletableFuture<List<DiscordThreadChannel>> retrieveArchivedJoinedPrivateThreads();
CompletableFuture<List<DiscordThreadChannel>> retrieveArchivedPublicThreads();
CompletableFuture<DiscordThreadChannel> createThread(String name, boolean privateThread);
CompletableFuture<DiscordThreadChannel> createThread(String name, long messageId);
}
| 2,056 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordForumChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordForumChannel.java | package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.entities.channel.concrete.ForumChannel;
public interface DiscordForumChannel extends DiscordChannel, DiscordThreadContainer, JDAEntity<ForumChannel> {
}
| 285 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordDMChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordDMChannel.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.DiscordUser;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
import org.jetbrains.annotations.Nullable;
/**
* A Discord direct message channel.
*/
public interface DiscordDMChannel extends DiscordMessageChannel, JDAEntity<PrivateChannel> {
/**
* Gets the {@link DiscordUser} that is associated with this direct message channel.
* @return the user this direct message is with
*/
@Nullable
DiscordUser getUser();
@Override
default DiscordChannelType getType() {
return DiscordChannelType.PRIVATE;
}
}
| 1,978 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordTextChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordTextChannel.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import org.jetbrains.annotations.Nullable;
/**
* A Discord text channel.
*/
public interface DiscordTextChannel extends DiscordGuildMessageChannel, DiscordThreadContainer, JDAEntity<TextChannel> {
/**
* Gets the topic of the text channel.
* @return the topic of the channel
*/
@Nullable
String getTopic();
@Override
default DiscordChannelType getType() {
return DiscordChannelType.TEXT;
}
}
| 1,874 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordGuildChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordGuildChannel.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.Snowflake;
import com.discordsrv.api.discord.entity.guild.DiscordGuild;
import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import org.jetbrains.annotations.NotNull;
@PlaceholderPrefix("channel_")
public interface DiscordGuildChannel extends Snowflake {
/**
* Gets the name of the channel.
* @return the name of the channel
*/
@NotNull
@Placeholder("name")
String getName();
/**
* Gets the Discord server that this channel is in.
* @return the Discord server that contains this channel
*/
@Placeholder(value = "server", relookup = "server")
@NotNull
DiscordGuild getGuild();
/**
* Gets the jump url for this channel
* @return the https url to go to this channel
*/
@NotNull
@Placeholder("jump_url")
String getJumpUrl();
}
| 2,251 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordThreadChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/entity/channel/DiscordThreadChannel.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.entity.channel;
import com.discordsrv.api.discord.entity.JDAEntity;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import org.jetbrains.annotations.NotNull;
public interface DiscordThreadChannel extends DiscordGuildMessageChannel, JDAEntity<ThreadChannel> {
@NotNull
DiscordThreadContainer getParentChannel();
/**
* Is this thread archived.
* @return {@code true} if the thread is archived
*/
boolean isArchived();
/**
* Is this thread locked from replies by non-moderators.
* @return {@code true} if the thread is locked
*/
boolean isLocked();
/**
* Is the self user (bot) joined in this thread.
* @return {@code true} if the self user is current a part of this thread
*/
boolean isJoined();
/**
* Is this thread invitable, meaning non-moderators can invite non-moderators to the thread.
* @return {@code true} if the thread is invitable
*/
boolean isInvitable();
/**
* Is the self user (bot) the owner of this thread.
* @return {@code true} if the self user is the owner of this thread
*/
boolean isOwnedBySelfUser();
/**
* Is this thread public, meaning anybody can read and join it if they can see its parent channel.
* @return {@code true} if this thread is public
*/
boolean isPublic();
}
| 2,668 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
RestErrorResponseException.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/exception/RestErrorResponseException.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.exception;
import net.dv8tion.jda.api.requests.ErrorResponse;
public class RestErrorResponseException extends RuntimeException {
private final int errorCode;
public RestErrorResponseException(ErrorResponse response) {
this(response.getCode(), response.getMeaning(), new EntityNoLongerAvailableException());
}
public RestErrorResponseException(int errorCode, String message, Throwable cause) {
super(message + " (" + errorCode + ")", cause);
this.errorCode = errorCode;
}
/**
* The error code if available, otherwise {@code -1}.
* @return the Discord error code or {@code -1}
*/
public int getErrorCode() {
return errorCode;
}
}
| 2,009 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
EntityNoLongerAvailableException.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/exception/EntityNoLongerAvailableException.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.exception;
public class EntityNoLongerAvailableException extends Exception {}
| 1,375 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
NotReadyException.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/exception/NotReadyException.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.exception;
public class NotReadyException extends RuntimeException {}
| 1,367 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordFormattingUtil.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/discord/util/DiscordFormattingUtil.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.discord.util;
import java.util.regex.Matcher;
public final class DiscordFormattingUtil {
private DiscordFormattingUtil() {}
public static String escapeContent(String content) {
content = escapeFormatting(content);
content = escapeQuotes(content);
content = escapeMentions(content);
return content;
}
public static String escapeFormatting(String content) {
return escapeChars(content, '*', '_', '|', '`', '~', ':', '[');
}
private static String escapeChars(String input, char... characters) {
for (char character : characters) {
input = input.replace(
String.valueOf(character),
"\\" + character);
}
return input;
}
public static String escapeQuotes(String input) {
return input.replaceAll("^>", Matcher.quoteReplacement("\\>"));
}
public static String escapeMentions(String input) {
return input.replaceAll("<([@#])", Matcher.quoteReplacement("\\<") + "$1");
}
}
| 2,335 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Color.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/color/Color.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.color;
import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import java.util.Objects;
/**
* Simple helper class for handling rgb colors, that is compatible with headless java installations.
*/
@PlaceholderPrefix("color_")
public class Color {
/**
* Discord's blurple color (<a href="https://discord.com/branding">Discord branding</a>).
*/
public static final Color BLURPLE = new Color(0x5865F2);
public static final Color WHITE = new Color(0xFFFFFF);
public static final Color BLACK = new Color(0);
private final int rgb;
/**
* Accepts any integer, but will only account for the first 24 bits.
* @param rgb the rgb value
*/
public Color(int rgb) {
this.rgb = rgb & 0xFFFFFF;
}
public Color(int red, int green, int blue) {
if (red < 0 || red > 255) {
throw new IllegalArgumentException("Red is out of range");
} else if (green < 0 || green > 255) {
throw new IllegalArgumentException("Green is out of range");
} else if (blue < 0 || blue > 255) {
throw new IllegalArgumentException("Blue is out of range");
}
this.rgb = ((red & 0xFF) << 16)
+ ((green & 0xFF) << 8)
+ (blue & 0xFF);
}
public Color(String hex) {
if (hex.length() != 6) {
throw new IllegalArgumentException("Input hex must be exactly 6 characters long");
}
this.rgb = Integer.parseInt(hex, 16);
}
@Placeholder("rgb")
public int rgb() {
return rgb;
}
@Placeholder("hex")
public String hex() {
return Integer.toHexString(0xF000000 | rgb).substring(1);
}
@Placeholder("red")
public int red() {
return (rgb & 0xFF0000) >> 16;
}
@Placeholder("green")
public int green() {
return (rgb & 0x00FF00) >> 8;
}
@Placeholder("blue")
public int blue() {
return rgb & 0x0000FF;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Color color = (Color) o;
return rgb == color.rgb;
}
@Override
public int hashCode() {
return Objects.hash(rgb);
}
@Override
public String toString() {
return "Color{#" + hex() + "}";
}
}
| 3,742 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
GameChannel.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/channel/GameChannel.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.channel;
import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
/**
* An in-game channel for sending Minecraft messages to.
*/
public interface GameChannel {
String DEFAULT_NAME = "global";
/**
* Gets the name of the plugin/mod/extension that 'owns' this game channel.
* @return the name of the owner of this game channel
*/
@NotNull
String getOwnerName();
/**
* Gets the name of this channel.
* @return the channel name
*/
@NotNull
String getChannelName();
/**
* Determines if this channel is a two-way chat channel.
* @return if this is a two-way chat channel
*/
boolean isChat();
/**
* Players that will receive messages for this channel, these players must not be included in {@link #sendMessage(MinecraftComponent)}.
* @return the recipients for this channel
* @see #sendMessage(MinecraftComponent)
*/
@NotNull
Collection<? extends DiscordSRVPlayer> getRecipients();
/**
* Send a message to this {@link GameChannel}'s participants which are not included in {@link #getRecipients()}.
* @param component the message
* @see #getRecipients()
*/
default void sendMessage(@NotNull MinecraftComponent component) {}
/**
* Sends the given message to the given player, used with {@link #getRecipients()}. May be used to apply personalized filters.
* @param player the player
* @param component the message
* @see #getRecipients()
*/
default void sendMessageToPlayer(@NotNull DiscordSRVPlayer player, @NotNull MinecraftComponent component) {
player.sendMessage(component);
}
}
| 3,080 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Module.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/module/Module.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.module;
import com.discordsrv.api.DiscordSRVApi;
import com.discordsrv.api.discord.connection.details.DiscordCacheFlag;
import com.discordsrv.api.discord.connection.details.DiscordGatewayIntent;
import com.discordsrv.api.discord.connection.details.DiscordMemberCachePolicy;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Consumer;
public interface Module {
/**
* Determines if this {@link Module} should be enabled at the instant this method is called, this will be used
* to determine when modules should be enabled or disabled when DiscordSRV enabled, disables and reloads.
* @return the current enabled status the module should be in currently
*/
default boolean isEnabled() {
return true;
}
/**
* Provides a {@link Collection} of {@link DiscordGatewayIntent}s that are required for this {@link Module}.
* @return the collection of gateway intents required by this module at the time this method is called
*/
@NotNull
default Collection<DiscordGatewayIntent> requiredIntents() {
return Collections.emptyList();
}
/**
* Provides a {@link Collection} of {@link DiscordCacheFlag}s that are required for this {@link Module}.
* {@link DiscordGatewayIntent}s required by the cache flags will be required automatically.
* @return the collection of cache flags required by this module at the time this method is called
*/
@NotNull
default Collection<DiscordCacheFlag> requiredCacheFlags() {
return Collections.emptyList();
}
/**
* Provides a {@link Collection} of {@link DiscordMemberCachePolicy DiscordMemberCachePolicies} that are required for this {@link Module},
* if a policy other than {@link DiscordMemberCachePolicy#OWNER} or {@link DiscordMemberCachePolicy#VOICE} is provided the {@link DiscordGatewayIntent#GUILD_MEMBERS} intent will be required automatically.
* @return the collection of member caching policies required by this module at the time this method is called
*/
@NotNull
default Collection<DiscordMemberCachePolicy> requiredMemberCachingPolicies() {
return Collections.emptyList();
}
/**
* Returns the priority of this Module given the lookup type.
* @param type the type being looked up this could be an interface
* @return the priority of this module, higher is more important. Default is 0
*/
@SuppressWarnings("unused") // API
default int priority(Class<?> type) {
return 0;
}
/**
* Determines the order which this module should shut down in compared to other modules.
* @return the shutdown order of this module, higher values will be shut down first. The default is the same as {@link #priority(Class)} with the type of the class.
*/
default int shutdownOrder() {
return priority(getClass());
}
/**
* Called by DiscordSRV to enable this module.
*/
default void enable() {}
/**
* Called by DiscordSRV to disable this module.
*/
default void disable() {}
/**
* Called by DiscordSRV to reload this module. This is called when the module is enabled as well.
* @param resultConsumer a consumer to supply results to, if any apply
*/
default void reload(Consumer<DiscordSRVApi.ReloadResult> resultConsumer) {}
}
| 4,713 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PunishmentModule.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/module/type/PunishmentModule.java | package com.discordsrv.api.module.type;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface PunishmentModule {
interface Bans extends PunishmentModule {
@Nullable
CompletableFuture<Punishment> getBan(@NotNull UUID playerUUID);
CompletableFuture<Void> addBan(@NotNull UUID playerUUID, @Nullable Instant until, @Nullable String reason, @NotNull String punisher);
CompletableFuture<Void> removeBan(@NotNull UUID playerUUID);
}
interface Mutes extends PunishmentModule {
@Nullable
CompletableFuture<Punishment> getMute(@NotNull UUID playerUUID);
CompletableFuture<Void> addMute(@NotNull UUID playerUUID, @Nullable Instant until, @Nullable String reason, @NotNull String punisher);
CompletableFuture<Void> removeMute(@NotNull UUID playerUUID);
}
class Punishment {
private final Instant until;
private final String reason;
private final String punisher;
public Punishment(@Nullable Instant until, @Nullable String reason, @Nullable String punisher) {
this.until = until;
this.reason = reason;
this.punisher = punisher;
}
public Instant until() {
return until;
}
public String reason() {
return reason;
}
public String punisher() {
return punisher;
}
}
}
| 1,554 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PermissionModule.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/module/type/PermissionModule.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.module.type;
import com.discordsrv.api.module.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface PermissionModule extends Module {
boolean supportsOffline();
interface Basic extends Groups, Permissions, PrefixAndSuffix {}
interface All extends Basic, Meta, GroupsContext {}
interface Groups extends PermissionModule {
List<String> getGroups();
CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited);
CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName);
CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName);
}
interface Permissions extends PermissionModule {
CompletableFuture<Boolean> hasPermission(@NotNull UUID player, @NotNull String permission);
}
interface PrefixAndSuffix extends PermissionModule {
CompletableFuture<String> getPrefix(@NotNull UUID player);
CompletableFuture<String> getSuffix(@NotNull UUID player);
}
interface Meta extends PermissionModule {
CompletableFuture<String> getMeta(@NotNull UUID player, @NotNull String key);
}
interface GroupsContext extends Groups {
Set<String> getDefaultServerContext();
CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited, @Nullable Set<String> serverContext);
CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName, @Nullable Set<String> serverContext);
CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName, @Nullable Set<String> serverContext);
@Override
default CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited) {
return hasGroup(player, groupName, includeInherited, null);
}
@Override
default CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName) {
return addGroup(player, groupName, null);
}
@Override
default CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName) {
return removeGroup(player, groupName, null);
}
}
}
| 3,765 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
NicknameModule.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/module/type/NicknameModule.java | package com.discordsrv.api.module.type;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface NicknameModule {
CompletableFuture<String> getNickname(UUID playerUUID);
CompletableFuture<Void> setNickname(UUID playerUUID, String nickname);
}
| 285 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
IProfileManager.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/profile/IProfileManager.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.profile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface IProfileManager {
@NotNull
CompletableFuture<? extends IProfile> lookupProfile(UUID playerUUID);
@Nullable
IProfile getProfile(UUID playerUUID);
@NotNull
CompletableFuture<? extends IProfile> lookupProfile(long userId);
@Nullable
IProfile getProfile(long userId);
}
| 1,774 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
IProfile.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/profile/IProfile.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.profile;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
/**
* A profile for a Minecraft player, Discord user or linked pair.
*/
public interface IProfile {
@Nullable
UUID playerUUID();
@Nullable
Long userId();
/**
* If this profile belongs to a linked Player and User pair.
* @return {@code true} if this profile is for a linked player/user
*/
default boolean isLinked() {
return playerUUID() != null && userId() != null;
}
}
| 1,793 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
MinecraftComponent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/component/MinecraftComponent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.component;
import com.discordsrv.api.DiscordSRVApi;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* A Minecraft json text component. Use {@link DiscordSRVApi#componentFactory()} to get an instance.<br/>
* <br/>
* This is designed to work with Adventure, see {@link #adventureAdapter(Class, Class)} and {@link #adventureAdapter(MinecraftComponentAdapter)}
* but is compatible with anything able to handle Minecraft's json format.
* Legacy is <b>not supported</b>.
*/
@SuppressWarnings("unused") // API
@ApiStatus.NonExtendable
public interface MinecraftComponent {
/**
* Gets this component as json.
* @return json of this component
*/
@NotNull
String asJson();
/**
* Sets this component from json.
* @param json valid Minecraft message component json
* @throws IllegalArgumentException if the provided json is not valid
*/
void setJson(@NotNull String json);
/**
* Gets this message as a plain {@link String} losing any coloring, click and hover components it may have had.
* Use for reference only, <b>this is not a substitute for legacy</b>.
* @return the plain message
*/
@NotNull
String asPlainString();
/**
* Creates an Adventure adapter for convenience.
*
* @param gsonSerializerClass the gson serializer class
* @return an adapter that will convert to/from relocated or unrelocated adventure classes to/from json
* @throws IllegalArgumentException if the provided class is not an Adventure GsonComponentSerializer
* @see #adventureAdapter(Class, Class)
*/
@NotNull
default Adapter<Object> adventureAdapter(@NotNull Class<?> gsonSerializerClass) {
return adventureAdapter(gsonSerializerClass, null);
}
/**
* Creates an Adventure adapter for convenience.
*
* @param gsonSerializerClass the {@code GsonComponentSerializer} class
* @param componentClass the {@code Component} class that's returned by the given gson component serializer
* @return an adapter that will convert to/from relocated or unrelocated adventure classes to/from json
* @throws IllegalArgumentException if the provided class is not an Adventure {@code GsonComponentSerializer}
* or if the provided {@code Component} class isn't the one returned by the serializer
*/
@NotNull
<T> Adapter<T> adventureAdapter(@NotNull Class<?> gsonSerializerClass, Class<T> componentClass);
/**
* Creates an Adventure adapter from a {@link MinecraftComponentAdapter} for convenience.
*
* @param adapter the pre-made {@link MinecraftComponentAdapter}
* @return a {@link Adapter} for this component using the given {@link MinecraftComponentAdapter}
*/
@NotNull
<T> Adapter<T> adventureAdapter(@NotNull MinecraftComponentAdapter<T> adapter);
/**
* Creates an Adventure adapter for the unrelocated adventure.
*
* @return a {@link Adapter} for this component using the unrelocated adventure, {@code null} if not available
*/
@Nullable
@ApiStatus.NonExtendable
default Adapter<Object> unrelocatedAdapter() {
MinecraftComponentAdapter<Object> adapter = MinecraftComponentAdapter.UNRELOCATED;
if (adapter == null) {
return null;
}
return adventureAdapter(adapter);
}
/**
* An Adventure adapter, converts from/to given adventure components from/to json.
*/
interface Adapter<Component> {
/**
* Returns the Adventure Component returned by the gson serializer of this adapter.
* @return the {@code net.kyori.adventure.text.Component} (or relocated), cast this to your end class
*/
@NotNull
Component getComponent();
/**
* Sets the component to the component that can be serialized by the gson serializer for this class.
* @param adventureComponent the component
* @throws IllegalArgumentException if the provided component cannot be processed by the gson serializer of this adapter
*/
void setComponent(@NotNull Component adventureComponent);
}
}
| 5,530 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
MinecraftComponentFactory.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/component/MinecraftComponentFactory.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.component;
import com.discordsrv.api.DiscordSRVApi;
import org.jetbrains.annotations.NotNull;
/**
* A factory for creating {@link MinecraftComponent}s.
* @see DiscordSRVApi#componentFactory()
*/
public interface MinecraftComponentFactory {
/**
* Creates an empty {@link MinecraftComponent}.
*
* @return a new {@link MinecraftComponent}
*/
@NotNull
MinecraftComponent empty();
/**
* Creates a EnhancedLegacyText {@link GameTextBuilder} based on the given input.
* @param enhancedLegacyText the format
* @return the new builder
*/
@NotNull
GameTextBuilder textBuilder(@NotNull String enhancedLegacyText);
}
| 1,965 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
GameTextBuilder.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/component/GameTextBuilder.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.component;
import com.discordsrv.api.placeholder.provider.SinglePlaceholder;
import org.jetbrains.annotations.NotNull;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Minecraft equivalent for {@link com.discordsrv.api.discord.entity.message.SendableDiscordMessage.Formatter}.
*/
public interface GameTextBuilder {
@NotNull
GameTextBuilder addContext(Object... context);
default GameTextBuilder addPlaceholder(String placeholder, Object replacement) {
return addContext(new SinglePlaceholder(placeholder, replacement));
}
default GameTextBuilder addPlaceholder(String placeholder, Supplier<Object> replacementSupplier) {
return addContext(new SinglePlaceholder(placeholder, replacementSupplier));
}
@NotNull
default GameTextBuilder addReplacement(String target, Object replacement) {
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
default GameTextBuilder addReplacement(Pattern target, Object replacement) {
return addReplacement(target, matcher -> replacement);
}
@NotNull
default GameTextBuilder addReplacement(String target, Supplier<Object> replacement) {
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
default GameTextBuilder addReplacement(Pattern target, Supplier<Object> replacement) {
return addReplacement(target, matcher -> replacement.get());
}
@NotNull
default GameTextBuilder addReplacement(String target, Function<Matcher, Object> replacement) {
return addReplacement(Pattern.compile(target, Pattern.LITERAL), replacement);
}
@NotNull
GameTextBuilder addReplacement(Pattern target, Function<Matcher, Object> replacement);
@NotNull
GameTextBuilder applyPlaceholderService();
@NotNull
MinecraftComponent build();
}
| 3,273 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
MinecraftComponentAdapter.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/component/MinecraftComponentAdapter.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.component;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* A persistent Adventure adapter for {@link MinecraftComponent}s, this is more efficient than using {@link MinecraftComponent#adventureAdapter(Class)}.
* @see MinecraftComponent#adventureAdapter(MinecraftComponentAdapter)
*/
public class MinecraftComponentAdapter<Component> {
public static final MinecraftComponentAdapter<Object> UNRELOCATED;
static {
MinecraftComponentAdapter<Object> unrelocated = null;
try {
unrelocated = MinecraftComponentAdapter.create(
Class.forName("net.ky".concat("ori.adventure.text.serializer.gson.GsonComponentSerializer"))
);
} catch (ClassNotFoundException ignored) {}
UNRELOCATED = unrelocated;
}
/**
* Creates a new {@link MinecraftComponentAdapter} that can be used with {@link MinecraftComponent}s.
*
* @param gsonSerializerClass a GsonComponentSerializer class
* @return a new {@link MinecraftComponentAdapter} with the provided GsonComponentSerializer
* @throws IllegalArgumentException if the provided argument is not a GsonComponentSerialize class
*/
public static MinecraftComponentAdapter<Object> create(Class<?> gsonSerializerClass) {
return new MinecraftComponentAdapter<>(gsonSerializerClass, null);
}
/**
* Creates a new {@link MinecraftComponentAdapter} that can be used with {@link MinecraftComponent}s.
*
* @param gsonSerializerClass a GsonComponentSerializer class
* @param componentClass the Component class returned by the GsonComponentSerializer
* @return a new {@link MinecraftComponentAdapter} with the provided GsonComponentSerializer
* @throws IllegalArgumentException if the provided argument is not a GsonComponentSerialize class
*/
public static <Component> MinecraftComponentAdapter<Component> create(Class<?> gsonSerializerClass, Class<Component> componentClass) {
return new MinecraftComponentAdapter<>(gsonSerializerClass, componentClass);
}
private final Class<?> gsonSerializerClass;
private final Object instance;
private final Method deserialize;
private final Method serialize;
private MinecraftComponentAdapter(Class<?> gsonSerializerClass, Class<Component> providedComponentClass) {
try {
this.gsonSerializerClass = gsonSerializerClass;
this.instance = gsonSerializerClass.getDeclaredMethod("gson").invoke(null);
this.deserialize = gsonSerializerClass.getMethod("deserialize", Object.class);
Class<?> componentClass = deserialize.getReturnType();
checkComponentClass(providedComponentClass, componentClass);
this.serialize = gsonSerializerClass.getMethod("serialize", componentClass);
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
throw new IllegalArgumentException("The provided class is not a GsonComponentSerializer", e);
}
}
private static void checkComponentClass(Class<?> provided, Class<?> actual) {
if (provided == null) {
// Ignore null
return;
}
String providedName = provided.getName();
String actualName = actual.getName();
if (!providedName.equals(actualName)) {
throw new IllegalArgumentException(
"The provided Component class (" + providedName
+ ") does not match the one returned by the serializer: " + actualName
);
}
}
public Class<?> serializerClass() {
return gsonSerializerClass;
}
public Object serializerInstance() {
return instance;
}
public Method deserializeMethod() {
return deserialize;
}
public Method serializeMethod() {
return serialize;
}
}
| 5,234 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
IPlayerProvider.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/player/IPlayerProvider.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
/**
* A provider for {@link DiscordSRVPlayer} instances.
*/
public interface IPlayerProvider {
/**
* Gets a player from the cache of online players.
* @param player the uuid for the player
* @return the {@link DiscordSRVPlayer} instance for the player, if available
*/
@Nullable
DiscordSRVPlayer player(@NotNull UUID player);
/**
* Gets a player from the cache of online players.
* @param username case-insensitive username for the player
* @return the {@link DiscordSRVPlayer} instance for the player, if available
*/
@Nullable
DiscordSRVPlayer player(@NotNull String username);
}
| 2,058 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordSRVPlayer.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/player/DiscordSRVPlayer.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.player;
import com.discordsrv.api.component.MinecraftComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
import java.util.UUID;
/**
* A DiscordSRV player.
*/
public interface DiscordSRVPlayer {
/**
* The username of the player.
* @return the player's username
*/
@NotNull
String username();
/**
* The {@link UUID} of the player.
* @return the player's unique id
*/
@NotNull
UUID uniqueId();
/**
* Gets the locale of the player.
* @return the player's locale, or {@code null} if it isn't known
*/
@Nullable
Locale locale();
/**
* Sends the provided message to the player.
* @param component the message
*/
void sendMessage(@NotNull MinecraftComponent component);
}
| 2,135 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
EventListener.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/bus/EventListener.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.bus;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Method;
/**
* A event listener.
*/
@SuppressWarnings("unused") // API
public interface EventListener {
/**
* The full name of the class for this event listener.
* @return the event listener class name
* @see Class#getName()
*/
@NotNull
String className();
/**
* The name of the method for this event listener.
* @return the method name for this event listener
* @see Method#getName()
*/
@NotNull
String methodName();
}
| 1,857 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Subscribe.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/bus/Subscribe.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.bus;
import com.discordsrv.api.DiscordSRVApi;
import com.discordsrv.api.event.events.Cancellable;
import com.discordsrv.api.event.events.Event;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Placed on a public non-abstract non-static method that has only 1 parameters,
* being an event extending {@link Event} or {@link net.dv8tion.jda.api.events.GenericEvent}.
*
* You can register a listener through {@link EventBus#subscribe(Object)}, {@link DiscordSRVApi#eventBus()} to get the event bus.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Subscribe {
/**
* If this listener ignores events that are cancelled via {@link Cancellable}.
* @return if cancelled events are ignored
* @see Cancellable
*/
boolean ignoreCancelled() default false;
/**
* The priority for this event listener, this determines the order that event listeners receive events.
* @return the priority of this event listener
*/
EventPriority priority() default EventPriority.DEFAULT;
}
| 2,467 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
EventPriority.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/bus/EventPriority.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.bus;
/**
* A simple enum to dictate the order that event listeners will be executed, going from {@link #POST} to {@link #POST}.
*/
public enum EventPriority {
/**
* This is the first in the priority order, this should be used to observe the event before any processing.
*/
PRE,
/**
* This is the earliest in the processing. This should be used to cancel events.
*/
EARLIEST,
/**
* This should be used to modify events.
*/
EARLY,
/**
* The default priority, right in the middle of the priority order. Use this if you need to override
* one of DiscordSRV's implementations for {@link com.discordsrv.api.event.events.Processable}s.
*/
DEFAULT,
/**
* This is where DiscordSRV's integrations for other plugins will process {@link com.discordsrv.api.event.events.Processable}'s.
*/
LATE,
/**
* This is where DiscordSRV's default implementations for {@link com.discordsrv.api.event.events.Processable}'s will run.
*/
LAST,
/**
* This is the last in the priority order, this should be used to observe the event after all processing is complete.
*/
POST
}
| 2,483 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
EventBus.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/bus/EventBus.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.bus;
import com.discordsrv.api.event.events.Event;
import net.dv8tion.jda.api.events.GenericEvent;
import org.jetbrains.annotations.Blocking;
import org.jetbrains.annotations.NotNull;
/**
* DiscordSRV's event bus, handling all events extending {@link Event}s and {@link GenericEvent}s.
*/
@SuppressWarnings("unused") // API
public interface EventBus {
/**
* Subscribes the provided event listener to this {@link EventBus}.
* @param eventListener an event listener with at least one valid {@link Subscribe} method.
*
* @throws IllegalArgumentException if the given listener does not contain any valid listeners
*/
void subscribe(@NotNull Object eventListener);
/**
* Unsubscribes a listener that was registered before.
* @param eventListener an event listener that was subscribed with {@link #subscribe(Object)} before
*/
void unsubscribe(@NotNull Object eventListener);
/**
* Publishes a DiscordSRV {@link Event} to this {@link EventBus}.
*
* @param event the event
*/
@Blocking
void publish(@NotNull Event event);
/**
* Publishes a JDA {@link GenericEvent} to this {@link EventBus}.
*
* @param event the event
*/
@Blocking
void publish(@NotNull GenericEvent event);
}
| 2,592 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
EventStateHolder.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/bus/internal/EventStateHolder.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.bus.internal;
import com.discordsrv.api.event.bus.EventListener;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@ApiStatus.Internal
public final class EventStateHolder {
public static final ThreadLocal<EventListener> CANCELLED = new ThreadLocal<>();
public static final ThreadLocal<EventListener> PROCESSED = new ThreadLocal<>();
/**
* Used to indicate an unknown event listener.
*/
public static final EventListener UNKNOWN_LISTENER = new FakeListener();
@SuppressWarnings("ConstantConditions")
private static class FakeListener implements EventListener {
@Override
public @NotNull String className() {
return null;
}
@Override
public @NotNull String methodName() {
return null;
}
}
}
| 2,136 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Event.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/Event.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events;
/**
* A DiscordSRV event.
*/
public interface Event {}
| 1,360 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Cancellable.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/Cancellable.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events;
import com.discordsrv.api.event.bus.EventListener;
import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.bus.internal.EventStateHolder;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
/**
* A {@link Event} that can be cancelled.
*/
@SuppressWarnings("unused") // API
public interface Cancellable extends Event {
/**
* If this event is cancelled.
* @return true if this event is cancelled
*/
boolean isCancelled();
/**
* Sets the cancelled state of this event, which may or may not be followed by event listeners.
* @param cancelled the new cancelled state of this event
* @see Subscribe#ignoreCancelled()
*/
void setCancelled(boolean cancelled);
/**
* Returns the {@link EventListener} that cancelled this event.
* This is changed every time the event goes from not being cancelled to being cancelled.
*
* @return the event listener that cancelled this event or {@code null} if it was cancelled before being passed to the {@link com.discordsrv.api.event.bus.EventBus}
* @throws IllegalStateException if the event isn't cancelled
*/
@ApiStatus.NonExtendable
@Nullable
default EventListener whoCancelled() {
EventListener listener = EventStateHolder.CANCELLED.get();
if (listener == null) {
throw new IllegalStateException("Event is not cancelled");
} else if (listener == EventStateHolder.UNKNOWN_LISTENER) {
return null;
}
return listener;
}
}
| 2,883 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlayerEvent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/PlayerEvent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events;
import com.discordsrv.api.player.DiscordSRVPlayer;
/**
* An event that is related to a {@link DiscordSRVPlayer}.
*/
public interface PlayerEvent extends Event {
/**
* The player that this event is related to.
* @return the player
*/
DiscordSRVPlayer getPlayer();
}
| 1,595 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Processable.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/Processable.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events;
import com.discordsrv.api.event.bus.EventListener;
import com.discordsrv.api.event.bus.internal.EventStateHolder;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
/**
* A {@link Event} that can be processed.
*/
@SuppressWarnings("unused") // API
public interface Processable extends Event {
/**
* Has this event has been processed.
* @return true if this event has been processed
*/
boolean isProcessed();
/**
* Returns the {@link EventListener} that processed this event.
*
* @return the event listener that processed this event or {@code null} if it was processed before being passed to the {@link com.discordsrv.api.event.bus.EventBus}
* @throws IllegalStateException if the event has not been processed
*/
@ApiStatus.NonExtendable
@Nullable
default EventListener whoProcessed() {
EventListener listener = EventStateHolder.PROCESSED.get();
if (listener == null) {
throw new IllegalStateException("Event has not been processed");
} else if (listener == EventStateHolder.UNKNOWN_LISTENER) {
return null;
}
return listener;
}
interface NoArgument extends Processable {
/**
* Marks this event as processed. This cannot be reversed.
* @see #isProcessed()
*/
void markAsProcessed();
}
interface Argument<T> extends Processable {
/**
* Marks this event as processed with the given argument. This cannot be reversed.
* @param input the argument for processing the event
* @see #isProcessed()
*/
void process(T input);
}
}
| 3,011 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
PlaceholderLookupEvent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/placeholder/PlaceholderLookupEvent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events.placeholder;
import com.discordsrv.api.event.events.Event;
import com.discordsrv.api.event.events.Processable;
import com.discordsrv.api.placeholder.PlaceholderLookupResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
/**
* An event for converting a placeholder's name and context into a {@link PlaceholderLookupResult}.
*/
public class PlaceholderLookupEvent implements Event, Processable.Argument<PlaceholderLookupResult> {
private final String placeholder;
private final Set<Object> contexts;
private boolean processed;
private PlaceholderLookupResult result;
public PlaceholderLookupEvent(String placeholder, Set<Object> contexts) {
this.placeholder = placeholder;
this.contexts = contexts;
}
/**
* The placeholders that was requested.
* @return the placeholder
*/
public String getPlaceholder() {
return placeholder;
}
/**
* Gets all contexts provided for this lookup, this may be things like {@link com.discordsrv.api.player.DiscordSRVPlayer} or {@link com.discordsrv.api.discord.entity.DiscordUser}.
* @return all contexts for this request
*/
public Set<Object> getContexts() {
return contexts;
}
/**
* Returns the context of the given type if provided.
* @param type the type of context to look for
* @return the given context if provided, otherwise {@code null}
* @param <T> the type of the context to lookup
*/
@SuppressWarnings("unchecked")
public <T> @Nullable T getContext(Class<T> type) {
for (Object o : contexts) {
if (type.isAssignableFrom(o.getClass())) {
return (T) o;
}
}
return null;
}
@Override
public boolean isProcessed() {
return processed;
}
/**
* Returns the {@link PlaceholderLookupResult} from a {@link #process(PlaceholderLookupResult)} matching required criteria.
* @return the placeholder lookup result provided by a listener
* @throws IllegalStateException if {@link #isProcessed()} doesn't return true
*/
@NotNull
public PlaceholderLookupResult getResultFromProcessing() {
if (!processed) {
throw new IllegalStateException("This event has not been successfully processed yet, no result is available");
}
return result;
}
/**
* Provides a {@link PlaceholderLookupResult} for the provided {@link #getPlaceholder()} and {@link #getContexts()}.
* @param result the result
* @throws IllegalStateException if the event is already processed
*/
public void process(@NotNull PlaceholderLookupResult result) {
if (processed) {
throw new IllegalStateException("Already processed");
}
if (result.getType() == PlaceholderLookupResult.Type.UNKNOWN_PLACEHOLDER) {
// Ignore unknown
return;
}
this.result = result;
this.processed = true;
}
}
| 4,362 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordEvent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/discord/DiscordEvent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events.discord;
import com.discordsrv.api.discord.entity.JDAEntity;
import com.discordsrv.api.event.events.Event;
import net.dv8tion.jda.api.events.GenericEvent;
public interface DiscordEvent<T extends GenericEvent> extends Event, JDAEntity<T> {
}
| 1,544 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
AbstractDiscordEvent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/discord/AbstractDiscordEvent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events.discord;
import net.dv8tion.jda.api.events.GenericEvent;
public abstract class AbstractDiscordEvent<T extends GenericEvent> implements DiscordEvent<T> {
protected final T jdaEvent;
public AbstractDiscordEvent(T jdaEvent) {
this.jdaEvent = jdaEvent;
}
@Override
public T asJDA() {
return jdaEvent;
}
}
| 1,647 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordMessageDeleteEvent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/discord/message/DiscordMessageDeleteEvent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events.discord.message;
import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel;
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
public class DiscordMessageDeleteEvent extends AbstractDiscordMessageEvent<MessageDeleteEvent> {
private final long messageId;
public DiscordMessageDeleteEvent(MessageDeleteEvent jdaEvent, DiscordMessageChannel channel, long messageId) {
super(jdaEvent, channel);
this.messageId = messageId;
}
public long getMessageId() {
return messageId;
}
}
| 1,846 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
DiscordMessageReceiveEvent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/discord/message/DiscordMessageReceiveEvent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events.discord.message;
import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel;
import com.discordsrv.api.discord.entity.message.ReceivedDiscordMessage;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
public class DiscordMessageReceiveEvent extends AbstractDiscordMessageEvent<MessageReceivedEvent> {
private final ReceivedDiscordMessage message;
public DiscordMessageReceiveEvent(MessageReceivedEvent jdaEvent, DiscordMessageChannel channel, ReceivedDiscordMessage message) {
super(jdaEvent, channel);
this.message = message;
}
public ReceivedDiscordMessage getMessage() {
return message;
}
}
| 1,969 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
AbstractDiscordMessageEvent.java | /FileExtraction/Java_unseen/DiscordSRV_Ascension/api/src/main/java/com/discordsrv/api/event/events/discord/message/AbstractDiscordMessageEvent.java | /*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.discordsrv.api.event.events.discord.message;
import com.discordsrv.api.discord.entity.channel.DiscordDMChannel;
import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel;
import com.discordsrv.api.discord.entity.channel.DiscordTextChannel;
import com.discordsrv.api.discord.entity.channel.DiscordThreadChannel;
import com.discordsrv.api.event.events.discord.AbstractDiscordEvent;
import net.dv8tion.jda.api.events.message.GenericMessageEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class AbstractDiscordMessageEvent<T extends GenericMessageEvent> extends AbstractDiscordEvent<T> {
private final DiscordMessageChannel channel;
public AbstractDiscordMessageEvent(T jdaEvent, DiscordMessageChannel channel) {
super(jdaEvent);
this.channel = channel;
}
public boolean isGuildMessage() {
return getDMChannel() == null;
}
/**
* The Discord text channel if this event originated from a message sent in a text channel.
* This will not be present on messages from threads (see {@link #getThreadChannel()}).
* @return an optional potentially containing a {@link DiscordTextChannel}
*/
@Nullable
public DiscordTextChannel getTextChannel() {
return channel instanceof DiscordTextChannel
? (DiscordTextChannel) channel
: null;
}
@Nullable
public DiscordThreadChannel getThreadChannel() {
return channel instanceof DiscordThreadChannel
? (DiscordThreadChannel) channel
: null;
}
@Nullable
public DiscordDMChannel getDMChannel() {
return channel instanceof DiscordDMChannel
? (DiscordDMChannel) channel
: null;
}
@NotNull
public DiscordMessageChannel getChannel() {
return channel;
}
}
| 3,167 | Java | .java | DiscordSRV/Ascension | 17 | 3 | 1 | 2021-07-29T01:14:02Z | 2024-05-08T00:28:36Z |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.