fix(deps): update dependency net.dv8tion:jda to v5.4.0
This commit is contained in:
1 parent
0d735f3744
commit
8e4a6841cc
85 files changed
+564
-385
No files matched your search
@@ -48,6 +48,8 @@ test:
|
||||
reports:
|
||||
junit:
|
||||
- "**/target/*-reports/TEST-*.xml"
|
||||
codequality:
|
||||
- "target/gl-code-quality-report.json"
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == "main"'
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
||||
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||
|
||||
<module name="Checker">
|
||||
<property name="severity" value="warning"/>
|
||||
|
||||
<!-- Allows tab characters -->
|
||||
<module name="FileTabCharacter">
|
||||
<property name="eachLine" value="false"/>
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
<!-- Indentation with tabs -->
|
||||
<module name="Indentation">
|
||||
<property name="basicOffset" value="4"/>
|
||||
<property name="tabWidth" value="4"/>
|
||||
<property name="forceStrictCondition" value="false"/>
|
||||
</module>
|
||||
|
||||
<!-- Common useful checks -->
|
||||
<module name="EmptyBlock">
|
||||
<property name="option" value="text"/>
|
||||
</module>
|
||||
<module name="NeedBraces"/>
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="UnusedImports"/>
|
||||
<module name="EqualsHashCode"/>
|
||||
|
||||
<!-- Relaxed Javadoc rules -->
|
||||
<module name="JavadocMethod">
|
||||
<property name="allowMissingParamTags" value="true"/>
|
||||
<property name="allowMissingReturnTag" value="true"/>
|
||||
</module>
|
||||
</module>
|
||||
</module>
|
||||
@@ -75,6 +75,42 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>checkstyle</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<configLocation>checkstyle.xml</configLocation>
|
||||
<failOnViolation>true</failOnViolation>
|
||||
<linkXRef>false</linkXRef>
|
||||
<outputFile>target/checkstyle-result.xml</outputFile>
|
||||
<outputFormat>xml</outputFormat>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>de.chkal.maven</groupId>
|
||||
<artifactId>gitlab-code-quality-plugin</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -100,7 +136,7 @@
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>5.3.2</version>
|
||||
<version>5.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.arbjerg</groupId>
|
||||
|
||||
@@ -94,10 +94,10 @@ public class NetNeutrality {
|
||||
|
||||
try {
|
||||
jda = JDABuilder
|
||||
.createDefault(token)
|
||||
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.MESSAGE_CONTENT)
|
||||
.setActivity(Activity.watching("me load..."))
|
||||
.build();
|
||||
.createDefault(token)
|
||||
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.MESSAGE_CONTENT)
|
||||
.setActivity(Activity.watching("me load..."))
|
||||
.build();
|
||||
jda.awaitReady();
|
||||
} catch (InvalidTokenException | IllegalArgumentException | InterruptedException e) {
|
||||
LogHandler.log(e);
|
||||
|
||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.admin;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.AdminCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.AdminCommand;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.db.entities.OBlacklist;
|
||||
import me.bobert.netneutrality.db.service.BlacklistService;
|
||||
@@ -43,11 +43,11 @@ public class BlacklistCommand extends AdminCommand {
|
||||
@Override
|
||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||
builder.addSubcommands(
|
||||
new SubcommandData("get", "Get all blacklisted words for this guild"),
|
||||
new SubcommandData("add", "Add a word to the blacklist")
|
||||
.addOption(OptionType.STRING, "word", "Word to add", true),
|
||||
new SubcommandData("remove", "Remove a word from the blacklist")
|
||||
.addOption(OptionType.STRING, "word", "Word to remove", true)
|
||||
new SubcommandData("get", "Get all blacklisted words for this guild"),
|
||||
new SubcommandData("add", "Add a word to the blacklist")
|
||||
.addOption(OptionType.STRING, "word", "Word to add", true),
|
||||
new SubcommandData("remove", "Remove a word from the blacklist")
|
||||
.addOption(OptionType.STRING, "word", "Word to remove", true)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.admin;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.AdminCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.AdminCommand;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||
import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask;
|
||||
@@ -49,30 +49,30 @@ public class ReactionCommand extends AdminCommand {
|
||||
@Override
|
||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||
builder.addSubcommandGroups(
|
||||
new SubcommandGroupData("emoji", "Give roles to users using emojis").addSubcommands(
|
||||
new SubcommandData("list", "Lists all registered tasks for this guild"),
|
||||
new SubcommandData("setup", "Add a role to a message").addOptions(
|
||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||
.setRequiredLength(19, 19),
|
||||
new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true),
|
||||
new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true)
|
||||
),
|
||||
new SubcommandData("add", "Add a role to an existing message").addOptions(
|
||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||
.setRequiredLength(19, 19),
|
||||
new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true),
|
||||
new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true)
|
||||
),
|
||||
new SubcommandData("remove", "Remove a role from a message").addOptions(
|
||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||
.setRequiredLength(19, 19),
|
||||
new OptionData(OptionType.STRING, "emoji", "Emoji to remove from the message", true)
|
||||
),
|
||||
new SubcommandData("delete", "Remove all roles from a message").addOptions(
|
||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||
.setRequiredLength(19, 19)
|
||||
)
|
||||
new SubcommandGroupData("emoji", "Give roles to users using emojis").addSubcommands(
|
||||
new SubcommandData("list", "Lists all registered tasks for this guild"),
|
||||
new SubcommandData("setup", "Add a role to a message").addOptions(
|
||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||
.setRequiredLength(19, 19),
|
||||
new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true),
|
||||
new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true)
|
||||
),
|
||||
new SubcommandData("add", "Add a role to an existing message").addOptions(
|
||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||
.setRequiredLength(19, 19),
|
||||
new OptionData(OptionType.STRING, "emoji", "Emoji associated with the role", true),
|
||||
new OptionData(OptionType.ROLE, "role", "Role to add to the emoji", true)
|
||||
),
|
||||
new SubcommandData("remove", "Remove a role from a message").addOptions(
|
||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||
.setRequiredLength(19, 19),
|
||||
new OptionData(OptionType.STRING, "emoji", "Emoji to remove from the message", true)
|
||||
),
|
||||
new SubcommandData("delete", "Remove all roles from a message").addOptions(
|
||||
new OptionData(OptionType.STRING, "messageid", "The ID of the message", true)
|
||||
.setRequiredLength(19, 19)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -107,24 +107,24 @@ public class ReactionCommand extends AdminCommand {
|
||||
|
||||
for (EmojiReactionRoleTask item : tasks) {
|
||||
Map<String, String> mapping = item.getEmojiMapping().entrySet().stream()
|
||||
.map(entry -> {
|
||||
Role role = context.getGuild().getRoleById(entry.getValue());
|
||||
return role != null ? Map.entry(entry.getKey(), role.getAsMention()) : null;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
.map(entry -> {
|
||||
Role role = context.getGuild().getRoleById(entry.getValue());
|
||||
return role != null ? Map.entry(entry.getKey(), role.getAsMention()) : null;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
builder.append("\n- Task ID: ").append(item.getId()).append("\n")
|
||||
.append(" Message: ")
|
||||
.append(String.format(Message.JUMP_URL, item.getGuildId(), item.getChannelId(), item.getMessageId()))
|
||||
.append("\n")
|
||||
.append(" Emoji Mappings:\n");
|
||||
.append(" Message: ")
|
||||
.append(String.format(Message.JUMP_URL, item.getGuildId(), item.getChannelId(), item.getMessageId()))
|
||||
.append("\n")
|
||||
.append(" Emoji Mappings:\n");
|
||||
|
||||
if (mapping.isEmpty()) {
|
||||
builder.append(" No emoji mappings found\n");
|
||||
} else {
|
||||
mapping.forEach((emoji, roleMention) ->
|
||||
builder.append(" - ").append(emoji).append(" → ").append(roleMention).append("\n")
|
||||
builder.append(" - ").append(emoji).append(" → ").append(roleMention).append("\n")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,13 @@ package me.bobert.netneutrality.command.basic;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.*;
|
||||
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||
import me.bobert.netneutrality.core.command.CommandContainer;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandManager;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.core.tasks.BuiltInTask;
|
||||
import me.bobert.netneutrality.tasks.help.BotInfo;
|
||||
|
||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.basic;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
|
||||
public class PingCommand extends AbstractCommand {
|
||||
|
||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.bot;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.AdminCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.AdminCommand;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.db.GSettings;
|
||||
import me.bobert.netneutrality.db.service.GuildService;
|
||||
@@ -48,15 +48,15 @@ public class ConfigureCommand extends AdminCommand {
|
||||
@Override
|
||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||
builder.addSubcommands(
|
||||
new SubcommandData("music-volume", "Volume for the music player")
|
||||
.addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for every session", true)
|
||||
.setRequiredRange(0, 100)),
|
||||
new SubcommandData("error-logging", "Send errors to #error and/or #log channel")
|
||||
.addOption(OptionType.BOOLEAN, "debug", "Enable or disable the fonctionnality", true),
|
||||
new SubcommandData("music-role", "Role needed to use music commands")
|
||||
.addOption(OptionType.ROLE, "role", "Name of role", true),
|
||||
new SubcommandData("music-channel", "Only allow music commands on this channel")
|
||||
.addOption(OptionType.CHANNEL, "channel", "Leave empty to allow everywhere")
|
||||
new SubcommandData("music-volume", "Volume for the music player")
|
||||
.addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for every session", true)
|
||||
.setRequiredRange(0, 100)),
|
||||
new SubcommandData("error-logging", "Send errors to #error and/or #log channel")
|
||||
.addOption(OptionType.BOOLEAN, "debug", "Enable or disable the fonctionnality", true),
|
||||
new SubcommandData("music-role", "Role needed to use music commands")
|
||||
.addOption(OptionType.ROLE, "role", "Name of role", true),
|
||||
new SubcommandData("music-channel", "Only allow music commands on this channel")
|
||||
.addOption(OptionType.CHANNEL, "channel", "Leave empty to allow everywhere")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ package me.bobert.netneutrality.command.crypto;
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.LogHandler;
|
||||
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.http.WebModule;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
@@ -56,9 +56,9 @@ public class CryptoPriceCommand extends AbstractCommand {
|
||||
@Override
|
||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||
builder.addOptions(
|
||||
new OptionData(OptionType.STRING, "symbol", "The crypto symbol to fetch price for", true),
|
||||
new OptionData(OptionType.STRING, "currency", "In which currency should the price be displayed")
|
||||
.setRequiredLength(3, 3)
|
||||
new OptionData(OptionType.STRING, "symbol", "The crypto symbol to fetch price for", true),
|
||||
new OptionData(OptionType.STRING, "currency", "In which currency should the price be displayed")
|
||||
.setRequiredLength(3, 3)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -118,9 +118,9 @@ public class CryptoPriceCommand extends AbstractCommand {
|
||||
JSONObject json = http.getAsObject();
|
||||
|
||||
JSONObject pairs = json.getJSONObject("Data")
|
||||
.getJSONObject("exchanges")
|
||||
.getJSONObject(exchange)
|
||||
.getJSONObject("pairs");
|
||||
.getJSONObject("exchanges")
|
||||
.getJSONObject(exchange)
|
||||
.getJSONObject("pairs");
|
||||
|
||||
return pairs.has(symbol);
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.git;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.AbstractCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.http.WebModule;
|
||||
import me.bobert.netneutrality.tasks.git.ReportIssueTask;
|
||||
|
||||
@@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandCategory;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
|
||||
@@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MessageFunction;
|
||||
|
||||
@@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
|
||||
@@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
||||
@@ -5,10 +5,10 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MessageFunction;
|
||||
@@ -43,16 +43,16 @@ public class QueueCommand extends MusicCommand {
|
||||
@Override
|
||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||
builder.addSubcommands(
|
||||
new SubcommandData("clear-all", "Clear all queued tracks"),
|
||||
new SubcommandData("delete-track", "Remove a single track from the queue")
|
||||
.addOptions(new OptionData(OptionType.INTEGER, "position", "Position of track", true)
|
||||
.setMinValue(1)),
|
||||
new SubcommandData("show-queue", "Display current queue"),
|
||||
new SubcommandData("shuffle", "Shuffle the queue"),
|
||||
new SubcommandData("from-user", "View tracks added by a user")
|
||||
.addOption(OptionType.USER, "user", "Which user?", true),
|
||||
new SubcommandData("remove-from-user", "Remove all tracks added by a user")
|
||||
.addOption(OptionType.USER, "user", "Which user?", true)
|
||||
new SubcommandData("clear-all", "Clear all queued tracks"),
|
||||
new SubcommandData("delete-track", "Remove a single track from the queue")
|
||||
.addOptions(new OptionData(OptionType.INTEGER, "position", "Position of track", true)
|
||||
.setMinValue(1)),
|
||||
new SubcommandData("show-queue", "Display current queue"),
|
||||
new SubcommandData("shuffle", "Shuffle the queue"),
|
||||
new SubcommandData("from-user", "View tracks added by a user")
|
||||
.addOption(OptionType.USER, "user", "Which user?", true),
|
||||
new SubcommandData("remove-from-user", "Remove all tracks added by a user")
|
||||
.addOption(OptionType.USER, "user", "Which user?", true)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ package me.bobert.netneutrality.command.music;/*
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
|
||||
@@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
|
||||
@@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
@@ -37,7 +37,7 @@ public class SkipCommand extends MusicCommand {
|
||||
@Override
|
||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||
builder.addOptions(new OptionData(OptionType.INTEGER, "skip", "Number of tracks to skip")
|
||||
.setMinValue(1));
|
||||
.setMinValue(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,9 +6,9 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
|
||||
@@ -5,9 +5,9 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MessageFunction;
|
||||
|
||||
@@ -6,10 +6,10 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.options.CommandOption;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
@@ -37,7 +37,7 @@ public class VolumeCommand extends MusicCommand {
|
||||
@Override
|
||||
public void registerCommandOptions(CommandOptionsBuilder builder) {
|
||||
builder.addOptions(new OptionData(OptionType.INTEGER, "volume", "Playback volume for this session", true)
|
||||
.setRequiredRange(0, 100));
|
||||
.setRequiredRange(0, 100));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,9 +5,9 @@ package me.bobert.netneutrality.command.music;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.CommandOptionsBuilder;
|
||||
import me.bobert.netneutrality.core.command.impl.MusicCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.music.MusicManager;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
|
||||
@@ -6,8 +6,8 @@ package me.bobert.netneutrality.command.react;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MessageMenuCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.impl.MessageMenuCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||
import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask;
|
||||
|
||||
@@ -6,8 +6,8 @@ package me.bobert.netneutrality.command.react;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import me.bobert.netneutrality.core.command.impl.MessageMenuCommand;
|
||||
import me.bobert.netneutrality.core.command.CommandExecutionResult;
|
||||
import me.bobert.netneutrality.core.command.impl.MessageMenuCommand;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||
import me.bobert.netneutrality.tasks.emoji.EmojiReactionRoleTask;
|
||||
|
||||
@@ -10,7 +10,10 @@ import me.bobert.netneutrality.core.command.options.MessageCommandOption;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.core.context.MessageContext;
|
||||
import me.bobert.netneutrality.utils.Settings;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Mentions;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
@@ -41,10 +44,10 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
||||
@Override
|
||||
public String getId() {
|
||||
return String.format("%s:%s:%s:%s",
|
||||
getGuild() == null ? "PrivateMessage" : getGuild().getId(),
|
||||
getChannel().getId(),
|
||||
getDiscordUser().getId(),
|
||||
message.getId());
|
||||
getGuild() == null ? "PrivateMessage" : getGuild().getId(),
|
||||
getChannel().getId(),
|
||||
getDiscordUser().getId(),
|
||||
message.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,7 +211,7 @@ public class MessageCommandContext extends CommandContext implements MessageCont
|
||||
|
||||
if (!requiredChannelTypes.contains(channel.getType())) {
|
||||
invalidateContext(data, "not a valid channel type at index " + (index + 1) +
|
||||
" , valid types are: " + validTypes(requiredChannelTypes));
|
||||
" , valid types are: " + validTypes(requiredChannelTypes));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,8 @@ package me.bobert.netneutrality.context.tasks;
|
||||
import me.bobert.netneutrality.context.AsyncContext;
|
||||
import me.bobert.netneutrality.core.context.NoMessageContext;
|
||||
import me.bobert.netneutrality.core.context.TaskContext;
|
||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
|
||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
|
||||
import net.dv8tion.jda.api.interactions.modals.Modal;
|
||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -51,10 +51,10 @@ public class LogHandler {
|
||||
|
||||
public static void sendMessageToDebugChannel(Guild guild, String message) {
|
||||
guild.getTextChannels()
|
||||
.stream()
|
||||
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
|
||||
.filter(TextChannel::canTalk)
|
||||
.forEach(textChannel -> textChannel.sendMessage(message).queue());
|
||||
.stream()
|
||||
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
|
||||
.filter(TextChannel::canTalk)
|
||||
.forEach(textChannel -> textChannel.sendMessage(message).queue());
|
||||
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ public class LogHandler {
|
||||
String guildId = context.getGuild() == null ? "PrivateMessage" : context.getGuild().getId();
|
||||
|
||||
logger.error("Exception thrown from context (guild: {}, user: {}): {}", guildId,
|
||||
context.getDiscordUser().getId(),
|
||||
exception.getMessage()
|
||||
context.getDiscordUser().getId(),
|
||||
exception.getMessage()
|
||||
);
|
||||
|
||||
if (context instanceof CommandContext commandContext) {
|
||||
@@ -82,11 +82,11 @@ public class LogHandler {
|
||||
if (context.getGuild() != null) {
|
||||
if (GuildService.get(context.getGuild()).isDebugEnabled()) {
|
||||
context.getGuild()
|
||||
.getTextChannels()
|
||||
.stream()
|
||||
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
|
||||
.filter(TextChannel::canTalk)
|
||||
.forEach(textChannel -> textChannel.sendMessageEmbeds(MessageFunction.buildDebugMessage(exception)).queue());
|
||||
.getTextChannels()
|
||||
.stream()
|
||||
.filter(textChannel -> textChannel.getName().equals("debug") || textChannel.getName().equals("log"))
|
||||
.filter(TextChannel::canTalk)
|
||||
.forEach(textChannel -> textChannel.sendMessageEmbeds(MessageFunction.buildDebugMessage(exception)).queue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,14 +94,14 @@ public class CommandContainer {
|
||||
if (!subcommandGroups.isEmpty()) {
|
||||
for (SubcommandGroupData subcommandGroup : subcommandGroups) {
|
||||
usage.append("- Subcommand: /").append(command.getCommandName())
|
||||
.append(" ").append(subcommandGroup.getName())
|
||||
.append(" (").append(subcommandGroup.getDescription()).append(")")
|
||||
.append("\n");
|
||||
.append(" ").append(subcommandGroup.getName())
|
||||
.append(" (").append(subcommandGroup.getDescription()).append(")")
|
||||
.append("\n");
|
||||
|
||||
for (SubcommandData subcommand : subcommandGroup.getSubcommands()) {
|
||||
usage.append(" - Usage: /").append(command.getCommandName())
|
||||
.append(" ").append(subcommandGroup.getName())
|
||||
.append(" ").append(subcommand.getName());
|
||||
.append(" ").append(subcommandGroup.getName())
|
||||
.append(" ").append(subcommand.getName());
|
||||
|
||||
for (OptionData option : subcommand.getOptions()) {
|
||||
usage.append(" <").append(option.getName()).append(">");
|
||||
@@ -130,7 +130,10 @@ public class CommandContainer {
|
||||
|
||||
for (OptionData option : options) {
|
||||
usage.append("\n");
|
||||
if (group) usage.append(" ");
|
||||
if (group) {
|
||||
usage.append(" ");
|
||||
}
|
||||
|
||||
usage.append(" - ");
|
||||
if (option.isRequired()) {
|
||||
usage.append("*");
|
||||
|
||||
@@ -9,7 +9,11 @@ import net.dv8tion.jda.api.interactions.DiscordLocale;
|
||||
import net.dv8tion.jda.api.interactions.IntegrationType;
|
||||
import net.dv8tion.jda.api.interactions.InteractionContextType;
|
||||
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.*;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
||||
import net.dv8tion.jda.api.interactions.commands.localization.LocalizationFunction;
|
||||
import net.dv8tion.jda.api.interactions.commands.localization.LocalizationMap;
|
||||
import net.dv8tion.jda.api.utils.data.DataObject;
|
||||
|
||||
@@ -27,7 +27,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.function.Predicate.not;
|
||||
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.*;
|
||||
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.ERROR;
|
||||
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.NOACTION;
|
||||
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.TASK;
|
||||
import static me.bobert.netneutrality.core.command.CommandExecutionResult.Result.WARN;
|
||||
|
||||
public class CommandProcessor {
|
||||
|
||||
@@ -239,7 +242,7 @@ public class CommandProcessor {
|
||||
|
||||
private String invalidUsage(String message) {
|
||||
return String.format("Invalid usage for command: %s\n" +
|
||||
"Use **/help %s** for information on how to use this command", message, context.getCommand().getCommandName());
|
||||
"Use **/help %s** for information on how to use this command", message, context.getCommand().getCommandName());
|
||||
}
|
||||
|
||||
private void configureSentry(Command command) {
|
||||
|
||||
@@ -64,8 +64,9 @@ public abstract class MusicCommand extends AbstractCommand {
|
||||
@Override
|
||||
public boolean canBeExecutedFrom(MessageChannel channel) {
|
||||
if (channel instanceof GuildMessageChannel guildMessageChannel) {
|
||||
if (channel.getType() != ChannelType.TEXT)
|
||||
if (channel.getType() != ChannelType.TEXT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String channelDb = GuildService.get(guildMessageChannel.getGuild()).getGuildSettingService().getSetting(GSettings.MUSIC_CHANNEL);
|
||||
if (channelDb != null && !channelDb.isEmpty()) {
|
||||
|
||||
@@ -5,7 +5,11 @@ package me.bobert.netneutrality.core.command.options;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.IMentionable;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
@@ -29,10 +33,8 @@ public interface CommandOption {
|
||||
* <br>This is represented as an {@link Message.Attachment#isEphemeral() ephemeral} attachment which will only be hosted for up to 2 weeks.
|
||||
* If you want a permanent reference, you must download it.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option {@link #getType() type} is not {@link OptionType#ATTACHMENT}
|
||||
*
|
||||
* @return {@link net.dv8tion.jda.api.entities.Message.Attachment Attachment}
|
||||
* @throws IllegalStateException If this option {@link #getType() type} is not {@link OptionType#ATTACHMENT}
|
||||
*/
|
||||
Message.Attachment getAsAttachment();
|
||||
|
||||
@@ -48,10 +50,8 @@ public interface CommandOption {
|
||||
/**
|
||||
* The boolean value.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option is not of type {@link OptionType#BOOLEAN BOOLEAN}
|
||||
*
|
||||
* @return The boolean value
|
||||
* @throws IllegalStateException If this option is not of type {@link OptionType#BOOLEAN BOOLEAN}
|
||||
*/
|
||||
boolean getAsBoolean();
|
||||
|
||||
@@ -59,12 +59,9 @@ public interface CommandOption {
|
||||
* The long value for this option.
|
||||
* <br>This will be the ID of any resolved entity such as {@link Role} or {@link Member}.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option {@link #getType() type} cannot be converted to a long
|
||||
* @throws NumberFormatException
|
||||
* If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value
|
||||
*
|
||||
* @return The long value
|
||||
* @throws IllegalStateException If this option {@link #getType() type} cannot be converted to a long
|
||||
* @throws NumberFormatException If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value
|
||||
*/
|
||||
long getAsLong();
|
||||
|
||||
@@ -74,36 +71,27 @@ public interface CommandOption {
|
||||
*
|
||||
* <p><b>It is highly recommended to assert int values by using {@link OptionData#setRequiredRange(long, long)}</b>
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option {@link #getType() type} cannot be converted to a long
|
||||
* @throws NumberFormatException
|
||||
* If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value
|
||||
* @throws ArithmeticException
|
||||
* If the provided integer value cannot fit into a 32bit signed int
|
||||
*
|
||||
* @return The int value
|
||||
* @throws IllegalStateException If this option {@link #getType() type} cannot be converted to a long
|
||||
* @throws NumberFormatException If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid long value
|
||||
* @throws ArithmeticException If the provided integer value cannot fit into a 32bit signed int
|
||||
*/
|
||||
int getAsInt();
|
||||
|
||||
/**
|
||||
* The double value for this option.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option {@link #getType() type} cannot be converted to a double
|
||||
* @throws NumberFormatException
|
||||
* If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid double value
|
||||
*
|
||||
* @return The double value
|
||||
* @throws IllegalStateException If this option {@link #getType() type} cannot be converted to a double
|
||||
* @throws NumberFormatException If this option is of type {@link OptionType#STRING STRING} and could not be parsed to a valid double value
|
||||
*/
|
||||
double getAsDouble();
|
||||
|
||||
/**
|
||||
* The resolved {@link IMentionable} instance for this option value.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If the mentioned entity is not resolvable
|
||||
*
|
||||
* @return The resolved {@link IMentionable}
|
||||
* @throws IllegalStateException If the mentioned entity is not resolvable
|
||||
*/
|
||||
IMentionable getAsMentionable();
|
||||
|
||||
@@ -111,42 +99,34 @@ public interface CommandOption {
|
||||
* The resolved {@link Member} for this option value.
|
||||
* <br>Note that {@link OptionType#USER OptionType.USER} can also accept users that are not members of a guild, in which case this will be null!
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option is not of type {@link OptionType#USER USER} or {@link OptionType#MENTIONABLE MENTIONABLE}
|
||||
*
|
||||
* @return The resolved {@link Member}, or null
|
||||
* @throws IllegalStateException If this option is not of type {@link OptionType#USER USER} or {@link OptionType#MENTIONABLE MENTIONABLE}
|
||||
*/
|
||||
Member getAsMember();
|
||||
|
||||
/**
|
||||
* The resolved {@link User} for this option value.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option is not of type {@link OptionType#USER USER} or
|
||||
* {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved user
|
||||
*
|
||||
* @return The resolved {@link User}
|
||||
* @throws IllegalStateException If this option is not of type {@link OptionType#USER USER} or
|
||||
* {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved user
|
||||
*/
|
||||
User getAsUser();
|
||||
|
||||
/**
|
||||
* The resolved {@link Role} for this option value.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option is not of type {@link OptionType#ROLE ROLE} or
|
||||
* {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved role
|
||||
*
|
||||
* @return The resolved {@link Role}
|
||||
* @throws IllegalStateException If this option is not of type {@link OptionType#ROLE ROLE} or
|
||||
* {@link OptionType#MENTIONABLE MENTIONABLE} without a resolved role
|
||||
*/
|
||||
Role getAsRole();
|
||||
|
||||
/**
|
||||
* The {@link ChannelType} for the resolved channel.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option is not of type {@link OptionType#CHANNEL CHANNEL}
|
||||
*
|
||||
* @return The {@link ChannelType}
|
||||
* @throws IllegalStateException If this option is not of type {@link OptionType#CHANNEL CHANNEL}
|
||||
*/
|
||||
ChannelType getChannelType();
|
||||
|
||||
@@ -154,11 +134,9 @@ public interface CommandOption {
|
||||
* The resolved {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel} for this option value.
|
||||
* <br>Note that {@link OptionType#CHANNEL OptionType.CHANNEL} can accept channels of any type!
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* If this option is not of type {@link OptionType#CHANNEL CHANNEL}
|
||||
* or could not be resolved for unexpected reasons
|
||||
*
|
||||
* @return The resolved {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel}
|
||||
* @throws IllegalStateException If this option is not of type {@link OptionType#CHANNEL CHANNEL}
|
||||
* or could not be resolved for unexpected reasons
|
||||
*/
|
||||
GuildChannelUnion getAsChannel();
|
||||
}
|
||||
+9
-5
@@ -5,7 +5,11 @@ package me.bobert.netneutrality.core.command.options;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.IMentionable;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
@@ -149,9 +153,9 @@ public class MessageCommandOption implements CommandOption {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MessageCommandOption{" +
|
||||
"name=" + data.getName() +
|
||||
", type=" + type +
|
||||
", value=" + value +
|
||||
'}';
|
||||
"name=" + data.getName() +
|
||||
", type=" + type +
|
||||
", value=" + value +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,11 @@ package me.bobert.netneutrality.core.command.options;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.IMentionable;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||
|
||||
@@ -6,7 +6,6 @@ package me.bobert.netneutrality.core.context;
|
||||
*/
|
||||
|
||||
import io.sentry.Sentry;
|
||||
import me.bobert.netneutrality.context.command.SlashCommandContext;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
||||
@@ -17,7 +17,12 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -26,7 +31,7 @@ public abstract class CommandContext extends AbstractContext {
|
||||
private Command command;
|
||||
private SubcommandGroupData subcommandGroup;
|
||||
private SubcommandData subcommand;
|
||||
private final Map <OptionData, String> invalidOptions = new HashMap<>();
|
||||
private final Map<OptionData, String> invalidOptions = new HashMap<>();
|
||||
private final List<CommandOption> options;
|
||||
|
||||
public CommandContext(JDA jda, Guild guild, MessageChannel channel, Member member, User user) {
|
||||
@@ -70,16 +75,20 @@ public abstract class CommandContext extends AbstractContext {
|
||||
public <T> T getOption(String name, Supplier<? extends T> fallback, Function<? super CommandOption, ? extends T> resolver) {
|
||||
Objects.requireNonNull(resolver, "resolver cannot be null");
|
||||
CommandOption mapping = getOption(name);
|
||||
if (mapping != null)
|
||||
if (mapping != null) {
|
||||
return resolver.apply(mapping);
|
||||
}
|
||||
|
||||
return fallback == null ? null : fallback.get();
|
||||
}
|
||||
|
||||
public <T> T getOption(String name, T fallback, Function<? super CommandOption, ? extends T> resolver) {
|
||||
Objects.requireNonNull(resolver, "resolver cannot be null");
|
||||
CommandOption mapping = getOption(name);
|
||||
if (mapping != null)
|
||||
if (mapping != null) {
|
||||
return resolver.apply(mapping);
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
@@ -132,7 +141,4 @@ public abstract class CommandContext extends AbstractContext {
|
||||
public abstract String parseCommandName();
|
||||
|
||||
public abstract String getFullCommand();
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -8,7 +8,11 @@ package me.bobert.netneutrality.core.context;
|
||||
import me.bobert.netneutrality.context.AsyncContext;
|
||||
import me.bobert.netneutrality.utils.ContextUtils;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||
import net.dv8tion.jda.api.events.Event;
|
||||
@@ -159,8 +163,8 @@ public interface Context {
|
||||
User user = getDiscordUser();
|
||||
if (user != null) {
|
||||
user.openPrivateChannel()
|
||||
.flatMap(channel -> channel.sendMessage(messageCreateData).setComponents(components))
|
||||
.queue(message -> consumer.accept(new AsyncContext(message)));
|
||||
.flatMap(channel -> channel.sendMessage(messageCreateData).setComponents(components))
|
||||
.queue(message -> consumer.accept(new AsyncContext(message)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ public class DatabaseMigration {
|
||||
|
||||
try {
|
||||
Flyway flyway = Flyway.configure()
|
||||
.dataSource(String.format("jdbc:mysql://%s:3306/%s", dbHost, dbName), dbUser, dbPass)
|
||||
.baselineOnMigrate(true)
|
||||
.load();
|
||||
.dataSource(String.format("jdbc:mysql://%s:3306/%s", dbHost, dbName), dbUser, dbPass)
|
||||
.baselineOnMigrate(true)
|
||||
.load();
|
||||
|
||||
flyway.migrate();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -29,8 +29,12 @@ public abstract class AbstractTask implements Task {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractTask that = (AbstractTask) o;
|
||||
return Objects.equals(getId(), that.getId());
|
||||
|
||||
@@ -20,12 +20,13 @@ public interface Task {
|
||||
REMOVE_SELF,
|
||||
REMOVE_SELF_AND_CHILDREN
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should generate a unique ID to differentiate it from other tasks.
|
||||
* <p>
|
||||
* This determines what triggers a task to be executed.
|
||||
* For example, a modal or button would use the component id.
|
||||
* For an emoji reaction, the guild and message id would be combined.
|
||||
* This determines what triggers a task to be executed.
|
||||
* For example, a modal or button would use the component id.
|
||||
* For an emoji reaction, the guild and message id would be combined.
|
||||
* </p>
|
||||
*
|
||||
* @return a unique ID for this task
|
||||
@@ -44,6 +45,7 @@ public interface Task {
|
||||
|
||||
/**
|
||||
* This is only used for debugging purpose.
|
||||
*
|
||||
* @return Name of the task
|
||||
*/
|
||||
String getName();
|
||||
@@ -55,6 +57,7 @@ public interface Task {
|
||||
|
||||
/**
|
||||
* When this returns true, the task will get removed by the cleanup thread.
|
||||
*
|
||||
* @return If the task is expired
|
||||
*/
|
||||
boolean isExpired();
|
||||
@@ -71,6 +74,7 @@ public interface Task {
|
||||
|
||||
/**
|
||||
* Executes the task.
|
||||
*
|
||||
* @param context The context for this task.
|
||||
*/
|
||||
Lifecycle execute(TaskContext context);
|
||||
|
||||
@@ -25,7 +25,11 @@ import org.reflections.Reflections;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -125,7 +129,7 @@ public class TaskManager {
|
||||
if (pendingTasks.remove(task)) {
|
||||
tasks.put(task.getId(), task);
|
||||
logger.info("Updating task {} with new id: {} (was: {})",
|
||||
task.getName(), task.getId(), oldId);
|
||||
task.getName(), task.getId(), oldId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,18 +210,18 @@ public class TaskManager {
|
||||
|
||||
public <E extends Task> List<E> findTasksByPartialId(Class<E> clazz, String partialId) {
|
||||
return tasks.values().stream()
|
||||
.filter(clazz::isInstance)
|
||||
.map(clazz::cast)
|
||||
.filter(task -> task.getId().contains(partialId))
|
||||
.collect(Collectors.toList());
|
||||
.filter(clazz::isInstance)
|
||||
.map(clazz::cast)
|
||||
.filter(task -> task.getId().contains(partialId))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public BuiltInTask findBuiltInTaskByClass(Class<? extends BuiltInTask> clazz) {
|
||||
return tasks.values().stream()
|
||||
.filter(clazz::isInstance)
|
||||
.map(task -> (BuiltInTask) task)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
.filter(clazz::isInstance)
|
||||
.map(task -> (BuiltInTask) task)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public void insertPersistableTask(PersistableTask task) {
|
||||
|
||||
@@ -22,9 +22,9 @@ public abstract class ModalTask extends GenericRandomIdTask {
|
||||
public ModalMapping getValue(String key, TaskContext context) {
|
||||
List<?> mappings = (List<?>) context.getContextData("values");
|
||||
return mappings.stream()
|
||||
.filter(o -> o instanceof ModalMapping)
|
||||
.map(o -> (ModalMapping) o)
|
||||
.filter(mapping -> mapping.getId().equals(key))
|
||||
.findFirst().orElse(null);
|
||||
.filter(o -> o instanceof ModalMapping)
|
||||
.map(o -> (ModalMapping) o)
|
||||
.filter(mapping -> mapping.getId().equals(key))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -63,9 +63,9 @@ public abstract class StepTask extends AbstractTask implements IStepTask {
|
||||
|
||||
context.replyEphemeral("Please follow the instructions sent in DM.");
|
||||
context.sendMessageInPrivate(getStepDescription() + "\n\n" + getStepQuestion(),
|
||||
asyncContext -> assignId(asyncContext.getMessageId()));
|
||||
asyncContext -> assignId(asyncContext.getMessageId()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Lifecycle execute(TaskContext context) {
|
||||
synchronized (stepLock) {
|
||||
|
||||
@@ -6,7 +6,11 @@ package me.bobert.netneutrality.core.thread;
|
||||
*/
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ThreadManager {
|
||||
|
||||
@@ -14,11 +18,11 @@ public class ThreadManager {
|
||||
|
||||
public static ScheduledExecutorService getScheduledExecutor() {
|
||||
return (ScheduledExecutorService) executors.computeIfAbsent(
|
||||
"scheduled-executor",
|
||||
s -> Executors.newScheduledThreadPool(
|
||||
Runtime.getRuntime().availableProcessors(),
|
||||
new BaseThreadFactory(s)
|
||||
)
|
||||
"scheduled-executor",
|
||||
s -> Executors.newScheduledThreadPool(
|
||||
Runtime.getRuntime().availableProcessors(),
|
||||
new BaseThreadFactory(s)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,11 +42,9 @@ public class ThreadManager {
|
||||
ex.shutdown();
|
||||
ex.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
System.err.println("[Executor] Running tasks interrupted");
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
executors.forEach((name, ex) -> {
|
||||
if (!ex.isTerminated()) {
|
||||
System.err.println("[Executor: " + name + "] Forcing shutdown of running tasks..");
|
||||
|
||||
@@ -24,7 +24,7 @@ public interface Repository<O> {
|
||||
default void save(O entity) {
|
||||
Transaction transaction = null;
|
||||
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
transaction = session.beginTransaction();
|
||||
session.merge(entity);
|
||||
transaction.commit();
|
||||
|
||||
@@ -6,7 +6,15 @@ package me.bobert.netneutrality.db.entities;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "blacklist")
|
||||
|
||||
@@ -6,7 +6,11 @@ package me.bobert.netneutrality.db.entities;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Optional;
|
||||
@@ -108,9 +112,9 @@ public class OGuild {
|
||||
|
||||
public OGuildSetting getSettingByName(String name) {
|
||||
Optional<OGuildSetting> setting = getGuildSettings()
|
||||
.stream()
|
||||
.filter(setting1 -> setting1.getName().equalsIgnoreCase(name))
|
||||
.findFirst();
|
||||
.stream()
|
||||
.filter(setting1 -> setting1.getName().equalsIgnoreCase(name))
|
||||
.findFirst();
|
||||
|
||||
return setting.orElse(null);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,23 @@ package me.bobert.netneutrality.db.entities;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.Lob;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.NamedQueries;
|
||||
import jakarta.persistence.NamedQuery;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "guild_settings")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "settings_findByName", query = "select o from OGuildSetting o where o.guild.id = :id and upper(o.name) = upper(:name)")
|
||||
@NamedQuery(name = "settings_findByName", query = "select o from OGuildSetting o where o.guild.id = :id and upper(o.name) = upper(:name)")
|
||||
})
|
||||
public class OGuildSetting {
|
||||
@Id
|
||||
|
||||
@@ -6,7 +6,16 @@ package me.bobert.netneutrality.db.entities;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Convert;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
|
||||
@@ -6,7 +6,14 @@ package me.bobert.netneutrality.db.entities;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.MapsId;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "logging")
|
||||
|
||||
@@ -46,10 +46,14 @@ public class OLoggingId implements Serializable {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
|
||||
return false;
|
||||
}
|
||||
OLoggingId entity = (OLoggingId) o;
|
||||
return Objects.equals(this.guildId, entity.guildId) &&
|
||||
Objects.equals(this.channelId, entity.channelId);
|
||||
Objects.equals(this.channelId, entity.channelId);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,14 @@ package me.bobert.netneutrality.db.entities;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Lob;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
|
||||
@Entity
|
||||
@Table(name = "tasks", uniqueConstraints = {@UniqueConstraint(columnNames = {"task_id"})})
|
||||
|
||||
@@ -6,7 +6,11 @@ package me.bobert.netneutrality.db.entities;
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Lob;
|
||||
import jakarta.persistence.Table;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class BlacklistRepository implements Repository<OBlacklist> {
|
||||
}
|
||||
|
||||
private OBlacklist getWordFromDb(String guildId, String word) {
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
Query<OBlacklist> query = session.createQuery("SELECT o FROM OBlacklist o WHERE upper(o.word) = upper(:word) AND o.guild.guildId = :guildId", OBlacklist.class);
|
||||
query.setParameter("guildId", guildId);
|
||||
query.setParameter("word", word);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class GuildRepository implements Repository<OGuild> {
|
||||
|
||||
@Override
|
||||
public OGuild findById(String id) {
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
Query<OGuild> query = session.createQuery("SELECT o FROM OGuild o WHERE o.guildId = :guildId", OGuild.class);
|
||||
query.setParameter("guildId", id);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class GuildSettingRepository implements Repository<OGuildSetting> {
|
||||
|
||||
@Override
|
||||
public OGuildSetting findById(String id) {
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
Query<OGuildSetting> query = session.createQuery("SELECT o FROM OGuildSetting o WHERE o.id = :id", OGuildSetting.class);
|
||||
query.setParameter("id", id);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class MessageRepository implements Repository<OLogMessage> {
|
||||
|
||||
@Override
|
||||
public OLogMessage findById(String id) {
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
Query<OLogMessage> query = session.createQuery("SELECT o FROM OLogMessage o WHERE o.messageId = :messageId", OLogMessage.class);
|
||||
query.setParameter("messageId", id);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TaskRepository implements Repository<OTask> {
|
||||
|
||||
@Override
|
||||
public OTask findById(String id) {
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
Query<OTask> query = session.createQuery("SELECT o FROM OTask o WHERE o.taskId = :taskId", OTask.class);
|
||||
query.setParameter("taskId", id);
|
||||
|
||||
|
||||
@@ -44,9 +44,9 @@ public class BlacklistService {
|
||||
|
||||
JpaUtils.getWithSession(oGuild, oGuild.getGuildId(), session -> {
|
||||
Set<String> blacklistWords = oGuild.getBlacklists().stream()
|
||||
.filter(OBlacklist::getEnabled)
|
||||
.map(OBlacklist::getWord)
|
||||
.collect(Collectors.toSet());
|
||||
.filter(OBlacklist::getEnabled)
|
||||
.map(OBlacklist::getWord)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
blacklistCache.put(oGuild.getGuildId(), blacklistWords);
|
||||
});
|
||||
|
||||
@@ -53,8 +53,12 @@ public class EventsHandler implements EventListener {
|
||||
|
||||
static {
|
||||
addListener(MessageReceivedEvent.class, event -> {
|
||||
if (event.getAuthor().isBot()) return null;
|
||||
if (event.isWebhookMessage()) return null;
|
||||
if (event.getAuthor().isBot()) {
|
||||
return null;
|
||||
}
|
||||
if (event.isWebhookMessage()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Message message = event.getMessage();
|
||||
String rawMessage = message.getContentDisplay().trim();
|
||||
|
||||
@@ -10,14 +10,23 @@ import com.google.gson.Gson;
|
||||
import io.sentry.Breadcrumb;
|
||||
import io.sentry.Sentry;
|
||||
import me.bobert.netneutrality.utils.Settings;
|
||||
import okhttp3.*;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WebModule {
|
||||
@@ -28,12 +37,12 @@ public class WebModule {
|
||||
private static final String USER_AGENT = "Net Neutrality/%s (Discord bot, discord.gg/trAqhQ5Wsr)";
|
||||
private static final Logger log = LoggerFactory.getLogger(WebModule.class);
|
||||
private static final Map<String, CachedResponse> cache = Collections.synchronizedMap(
|
||||
new LinkedHashMap<>(100, 0.75f, true) {
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String, CachedResponse> eldest) {
|
||||
return size() > 50; // Limit cache to 50 entries
|
||||
}
|
||||
new LinkedHashMap<>(100, 0.75f, true) {
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String, CachedResponse> eldest) {
|
||||
return size() > 50; // Limit cache to 50 entries
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
private final Method method;
|
||||
@@ -95,12 +104,12 @@ public class WebModule {
|
||||
String body = response.body() != null ? response.body().string() : null;
|
||||
|
||||
this.cachedResponse = new CachedResponse(
|
||||
response.code(),
|
||||
response.headers(),
|
||||
elapsedTime,
|
||||
body,
|
||||
System.currentTimeMillis() + cacheExpirationMillis,
|
||||
null
|
||||
response.code(),
|
||||
response.headers(),
|
||||
elapsedTime,
|
||||
body,
|
||||
System.currentTimeMillis() + cacheExpirationMillis,
|
||||
null
|
||||
);
|
||||
} catch (IOException e) {
|
||||
long elapsedTime = System.currentTimeMillis() - startTime;
|
||||
@@ -108,12 +117,12 @@ public class WebModule {
|
||||
Sentry.captureException(e);
|
||||
|
||||
this.cachedResponse = new CachedResponse(
|
||||
0, // Status code 0 indicates a failure
|
||||
new Headers.Builder().build(),
|
||||
elapsedTime,
|
||||
null,
|
||||
System.currentTimeMillis() + cacheExpirationMillis,
|
||||
e.getMessage()
|
||||
0, // Status code 0 indicates a failure
|
||||
new Headers.Builder().build(),
|
||||
elapsedTime,
|
||||
null,
|
||||
System.currentTimeMillis() + cacheExpirationMillis,
|
||||
e.getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -132,22 +141,22 @@ public class WebModule {
|
||||
StringBuilder keyBuilder = new StringBuilder(method.name()).append(":").append(url);
|
||||
if (headers != null) {
|
||||
headers.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.forEach(entry -> keyBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append(";"));
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.forEach(entry -> keyBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append(";"));
|
||||
}
|
||||
return keyBuilder.toString();
|
||||
}
|
||||
|
||||
public JSONObject getAsObject() {
|
||||
return cachedResponse.getBody()
|
||||
.map(JSONObject::new)
|
||||
.orElseThrow(() -> new IllegalStateException("No body available for this response"));
|
||||
.map(JSONObject::new)
|
||||
.orElseThrow(() -> new IllegalStateException("No body available for this response"));
|
||||
}
|
||||
|
||||
public JSONArray getAsArray() {
|
||||
return cachedResponse.getBody()
|
||||
.map(JSONArray::new)
|
||||
.orElseThrow(() -> new IllegalStateException("No body available for this response"));
|
||||
.map(JSONArray::new)
|
||||
.orElseThrow(() -> new IllegalStateException("No body available for this response"));
|
||||
}
|
||||
|
||||
public String getRawData() {
|
||||
@@ -303,10 +312,10 @@ public class WebModule {
|
||||
*/
|
||||
public WebModule build() {
|
||||
this.client = new OkHttpClient.Builder()
|
||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
||||
.writeTimeout(writeTimeout, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
||||
.writeTimeout(writeTimeout, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
this.request = createRequest();
|
||||
|
||||
return new WebModule(this);
|
||||
|
||||
@@ -204,8 +204,8 @@ public class MusicManager {
|
||||
}
|
||||
|
||||
return CommandExecutionResult.success(String.format("Adding your vote to skip the current track. Current votes: %d/%d",
|
||||
info.getSkips().size(),
|
||||
(int) Math.ceil(needed))
|
||||
info.getSkips().size(),
|
||||
(int) Math.ceil(needed))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,10 @@ import net.dv8tion.jda.api.entities.Member;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
|
||||
@@ -37,23 +37,29 @@ public class SourceFinder {
|
||||
Matcher udioMatcher = udioPattern.matcher(url);
|
||||
Matcher mp3Matcher = mp3Pattern.matcher(url);
|
||||
|
||||
if (youtubeMatcher.find())
|
||||
if (youtubeMatcher.find()) {
|
||||
return AudioSourceType.Youtube;
|
||||
}
|
||||
|
||||
if (youtubeMusicMatcher.find())
|
||||
if (youtubeMusicMatcher.find()) {
|
||||
return AudioSourceType.YTMusic;
|
||||
}
|
||||
|
||||
if (soundcloudMatcher.find())
|
||||
if (soundcloudMatcher.find()) {
|
||||
return AudioSourceType.Soundcloud;
|
||||
}
|
||||
|
||||
if (udioMatcher.find())
|
||||
if (udioMatcher.find()) {
|
||||
return AudioSourceType.Udio;
|
||||
}
|
||||
|
||||
if (mp3Matcher.find())
|
||||
if (mp3Matcher.find()) {
|
||||
return AudioSourceType.DirectLinkMp3;
|
||||
}
|
||||
|
||||
if (!(url.startsWith("http://") || url.startsWith("https://")))
|
||||
if (!(url.startsWith("http://") || url.startsWith("https://"))) {
|
||||
return AudioSourceType.YTSearch;
|
||||
}
|
||||
|
||||
return AudioSourceType.Nothing;
|
||||
}
|
||||
|
||||
@@ -50,8 +50,12 @@ public class TrackInfo {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TrackInfo trackInfo = (TrackInfo) o;
|
||||
return track.equals(trackInfo.track);
|
||||
}
|
||||
@@ -64,9 +68,9 @@ public class TrackInfo {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TrackInfo{" +
|
||||
"track=" + track.getInfo().title +
|
||||
", member=" + member.getEffectiveName() +
|
||||
", skips=" + skips +
|
||||
'}';
|
||||
"track=" + track.getInfo().title +
|
||||
", member=" + member.getEffectiveName() +
|
||||
", skips=" + skips +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import me.bobert.netneutrality.core.LogHandler;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.core.tasks.TaskManager;
|
||||
import me.bobert.netneutrality.tasks.music.LoadPlaylistTask;
|
||||
import me.bobert.netneutrality.utils.MessageFunction;
|
||||
import me.bobert.netneutrality.utils.MusicUtils;
|
||||
@@ -64,8 +63,9 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
|
||||
public void noMatches() {
|
||||
logger.debug("Guild {}: no matches for identifier {}", guild.getId(), identifier);
|
||||
|
||||
if (!silent)
|
||||
if (!silent) {
|
||||
context.reply("No matches found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,7 +76,8 @@ public class TrackLoadingHandler implements AudioLoadResultHandler {
|
||||
RuntimeException exception = new RuntimeException("Failed to load track: " + e.getMessage(), e);
|
||||
LogHandler.log(exception);
|
||||
|
||||
if (!silent)
|
||||
if (!silent) {
|
||||
context.reply(MessageFunction.buildSentryErrorMessage(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,13 +35,9 @@ import java.util.regex.Pattern;
|
||||
import static com.sedmelluq.discord.lavaplayer.tools.FriendlyException.Severity.SUSPICIOUS;
|
||||
|
||||
public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
|
||||
private static final Logger log = LogManager.getLogger(UdioAudioSourceManager.class);
|
||||
|
||||
|
||||
private static final String TRACK_URL_REGEX = "^https://www.udio.com/songs/[0-9A-Za-z]+$";
|
||||
private static final Pattern trackUrlPattern = Pattern.compile(TRACK_URL_REGEX);
|
||||
|
||||
private final HttpInterfaceManager httpInterfaceManager;
|
||||
|
||||
public UdioAudioSourceManager() {
|
||||
@@ -64,11 +60,8 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
} catch (IOException e) {
|
||||
throw new FriendlyException("Loading Udio track information failed.", SUSPICIOUS, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isTrackEncodable(AudioTrack track) {
|
||||
return true;
|
||||
@@ -94,7 +87,6 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
}
|
||||
|
||||
private AudioItem loadFromTrackPage(HttpInterface httpInterface, String trackUrl) throws IOException {
|
||||
|
||||
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(trackUrl))) {
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
|
||||
@@ -102,7 +94,7 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
return AudioReference.NO_TRACK;
|
||||
} else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
|
||||
throw new FriendlyException("Server responded with an error.", SUSPICIOUS,
|
||||
new IllegalStateException("Response code is " + statusCode));
|
||||
new IllegalStateException("Response code is " + statusCode));
|
||||
}
|
||||
|
||||
return loadTrackFromPageContent(trackUrl, IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8));
|
||||
@@ -124,7 +116,6 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
String artworkUrl = getArtworkUrlFromImagePath(trackInfo);
|
||||
|
||||
AudioTrackInfo audioTrackInfo = new AudioTrackInfo(title, artist, duration, trackUrl, false, playbackUrl, artworkUrl, null);
|
||||
|
||||
return new UdioAudioTrack(audioTrackInfo, this);
|
||||
}
|
||||
|
||||
@@ -155,5 +146,4 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
|
||||
return imagePath.replace("public", artworkOptions);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class UdioAudioTrack extends DelegatedAudioTrack {
|
||||
|
||||
if (!HttpClientTools.isSuccessWithContent(statusCode)) {
|
||||
throw new FriendlyException("Server responded with an error.", SUSPICIOUS,
|
||||
new IllegalStateException("Response code for player config is " + statusCode));
|
||||
new IllegalStateException("Response code for player config is " + statusCode));
|
||||
}
|
||||
|
||||
return sourceManager.loadTrackInfoFromPageContent(IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8));
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A generic button task that represents a button to accept a choice.
|
||||
*
|
||||
* @param <P> the type of the parent task, which must implement WithChildren
|
||||
*/
|
||||
public class AcceptButton<P extends WithChildren> extends ButtonTask implements WithParent<P>, NotAcknowledgeable {
|
||||
|
||||
@@ -45,20 +45,20 @@ public class ReportIssueTask extends ModalTask {
|
||||
@Override
|
||||
public void replyToInteraction(CommandContext context) {
|
||||
TextInput title = TextInput.create("title", "Title", TextInputStyle.SHORT)
|
||||
.setPlaceholder("Brief description of the issue.")
|
||||
.setMinLength(10)
|
||||
.setMaxLength(100)
|
||||
.build();
|
||||
.setPlaceholder("Brief description of the issue.")
|
||||
.setMinLength(10)
|
||||
.setMaxLength(100)
|
||||
.build();
|
||||
|
||||
TextInput body = TextInput.create("description", "Description", TextInputStyle.PARAGRAPH)
|
||||
.setPlaceholder("And I scream from the top of my lungs What's going on?")
|
||||
.setMinLength(30)
|
||||
.setMaxLength(1000)
|
||||
.build();
|
||||
.setPlaceholder("And I scream from the top of my lungs What's going on?")
|
||||
.setMinLength(30)
|
||||
.setMaxLength(1000)
|
||||
.build();
|
||||
|
||||
Modal modal = Modal.create(getId(), "Report a bug")
|
||||
.addComponents(ActionRow.of(title), ActionRow.of(body))
|
||||
.build();
|
||||
.addComponents(ActionRow.of(title), ActionRow.of(body))
|
||||
.build();
|
||||
|
||||
context.reply(modal);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@ public class BotInfo extends AbstractBuiltInTask {
|
||||
@Override
|
||||
public void executeTask(TaskContext context) {
|
||||
context.sendMessageInPrivate("For information about the bot and to follow the development, " +
|
||||
"you can join the discord here: https://discord.gg/udVJwTgV");
|
||||
"you can join the discord here: https://discord.gg/udVJwTgV");
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,6 @@ public class ReportBug extends AbstractBuiltInTask {
|
||||
@Override
|
||||
public void executeTask(TaskContext context) {
|
||||
context.sendMessageInPrivate("To report a bug with the bot, you can either use the /report-bug command " +
|
||||
"or join the discord here: https://discord.gg/udVJwTgV");
|
||||
"or join the discord here: https://discord.gg/udVJwTgV");
|
||||
}
|
||||
}
|
||||
@@ -58,8 +58,8 @@ public class LoadPlaylistTask extends ButtonTask implements WithChildren, Deleta
|
||||
|
||||
int searchResultsLimit = 5; // Max number of buttons per row
|
||||
int maxPlaylistSizeBeforeAsking = Integer.parseInt(GuildService.get(context.getGuild())
|
||||
.getGuildSettingService()
|
||||
.getSetting(GSettings.MUSIC_MAXPLAYLISTSIZE));
|
||||
.getGuildSettingService()
|
||||
.getSetting(GSettings.MUSIC_MAXPLAYLISTSIZE));
|
||||
|
||||
// Search results
|
||||
if (playlist.isSearchResult()) {
|
||||
@@ -115,8 +115,8 @@ public class LoadPlaylistTask extends ButtonTask implements WithChildren, Deleta
|
||||
addChild(accept, cancel);
|
||||
|
||||
return ActionRow.of(
|
||||
accept.createButton().withEmoji(Emoji.fromFormatted("U+1F60E")),
|
||||
cancel.createButton().withEmoji(Emoji.fromFormatted("U+1F92E"))
|
||||
accept.createButton().withEmoji(Emoji.fromFormatted("U+1F60E")),
|
||||
cancel.createButton().withEmoji(Emoji.fromFormatted("U+1F92E"))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ public class EmojiRoleFirstStep extends StepTask {
|
||||
@Override
|
||||
public String getStepDescription() {
|
||||
return String.format("Creating a new emoji role mapping in guild %s for message %s",
|
||||
getGuild().getId(),
|
||||
target.getJumpUrl());
|
||||
getGuild().getId(),
|
||||
target.getJumpUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,9 +32,9 @@ public class EmojiRoleSecondStep extends StepTask {
|
||||
@Override
|
||||
public String getStepDescription() {
|
||||
return String.format("Creating a new emoji role mapping in guild %s for message %s and role %s",
|
||||
getGuild().getId(),
|
||||
target.getJumpUrl(),
|
||||
role.getName());
|
||||
getGuild().getId(),
|
||||
target.getJumpUrl(),
|
||||
role.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,9 +46,9 @@ public class EmojiRoleSecondStep extends StepTask {
|
||||
public StepResult executeStep(Object answer) {
|
||||
String emoji = (String) answer;
|
||||
Task emojiTask = new EmojiReactionRoleTask(target.getGuildId(),
|
||||
target.getChannelId(),
|
||||
target.getId(),
|
||||
Map.of(emoji, role.getId()));
|
||||
target.getChannelId(),
|
||||
target.getId(),
|
||||
Map.of(emoji, role.getId()));
|
||||
|
||||
if (TaskManager.getInstance().hasTask(emojiTask.getId())) {
|
||||
return StepResult.failure("The message ID is already registered with the bot, please use the modify mapping command instead");
|
||||
|
||||
@@ -21,11 +21,11 @@ public class CleanupTaskThread implements Runnable {
|
||||
TaskManager manager = TaskManager.getInstance();
|
||||
|
||||
List<Task> expiredTasks = manager.getTasks()
|
||||
.stream()
|
||||
.filter(task -> !(task instanceof PersistableTask))
|
||||
.filter(task -> !(task instanceof BuiltInTask))
|
||||
.filter(Task::isExpired)
|
||||
.toList();
|
||||
.stream()
|
||||
.filter(task -> !(task instanceof PersistableTask))
|
||||
.filter(task -> !(task instanceof BuiltInTask))
|
||||
.filter(Task::isExpired)
|
||||
.toList();
|
||||
|
||||
if (!expiredTasks.isEmpty()) {
|
||||
logger.info("Cleaning up {} expired tasks..", expiredTasks.size());
|
||||
|
||||
@@ -40,8 +40,9 @@ public class ChannelMessagePurger {
|
||||
|
||||
public boolean canLockBeAcquired() {
|
||||
boolean acquired = lock.tryLock();
|
||||
if (acquired)
|
||||
if (acquired) {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
return acquired;
|
||||
}
|
||||
@@ -126,9 +127,9 @@ public class ChannelMessagePurger {
|
||||
}
|
||||
|
||||
MessageCreateBuilder builder = new MessageCreateBuilder()
|
||||
.addContent("Finished purging ")
|
||||
.addContent(String.valueOf(toPurge))
|
||||
.addContent(" messages.");
|
||||
.addContent("Finished purging ")
|
||||
.addContent(String.valueOf(toPurge))
|
||||
.addContent(" messages.");
|
||||
|
||||
if (olderThan2Weeks) {
|
||||
builder.addContent("\n").addContent("Messages older than two weeks weren't deleted.");
|
||||
|
||||
@@ -58,8 +58,8 @@ public class ContextUtils {
|
||||
private static int findLastBoundary(String chunk) {
|
||||
// Find the last sentence-ending punctuation or space within the chunk
|
||||
int lastSentenceBoundary = Math.max(
|
||||
Math.max(chunk.lastIndexOf("."), Math.max(chunk.lastIndexOf("!"), chunk.lastIndexOf("?"))),
|
||||
chunk.lastIndexOf("\n")
|
||||
Math.max(chunk.lastIndexOf("."), Math.max(chunk.lastIndexOf("!"), chunk.lastIndexOf("?"))),
|
||||
chunk.lastIndexOf("\n")
|
||||
);
|
||||
int lastSpace = chunk.lastIndexOf(" ");
|
||||
return Math.max(lastSentenceBoundary, lastSpace);
|
||||
|
||||
@@ -32,8 +32,8 @@ public class JpaUtils {
|
||||
* <p>
|
||||
*
|
||||
* @param session The session in which to load the persistent object
|
||||
* @param object The persistent object
|
||||
* @param id Identifier
|
||||
* @param object The persistent object
|
||||
* @param id Identifier
|
||||
*/
|
||||
public static void tryLoad(Session session, Object object, Serializable id) {
|
||||
try {
|
||||
@@ -57,13 +57,13 @@ public class JpaUtils {
|
||||
}
|
||||
|
||||
public static void runWithSession(Consumer<Session> consumer) {
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
consumer.accept(session);
|
||||
}
|
||||
}
|
||||
|
||||
public static void runWithTransaction(Consumer<Session> consumer) {
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
session.beginTransaction();
|
||||
consumer.accept(session);
|
||||
session.getTransaction().commit();
|
||||
@@ -71,7 +71,7 @@ public class JpaUtils {
|
||||
}
|
||||
|
||||
public static void updateWithTransaction(Object persistantEntity, Runnable runnable) {
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
Transaction transaction = session.beginTransaction();
|
||||
|
||||
try {
|
||||
@@ -94,11 +94,11 @@ public class JpaUtils {
|
||||
* This will load all Lazy relationships defined in the entity.
|
||||
*
|
||||
* @param persistantEntity The entity to load
|
||||
* @param id The identifier for the entity
|
||||
* @param consumer The comsumer, which exposes the session
|
||||
* @param id The identifier for the entity
|
||||
* @param consumer The comsumer, which exposes the session
|
||||
*/
|
||||
public static void getWithSession(Object persistantEntity, Serializable id, Consumer<Session> consumer) {
|
||||
try(Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
try (Session session = SessionManager.getSessionFactory().openSession()) {
|
||||
tryLoad(session, persistantEntity, id);
|
||||
consumer.accept(session);
|
||||
}
|
||||
|
||||
@@ -29,10 +29,11 @@ import org.apache.commons.lang3.time.DurationFormatUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
|
||||
public class MessageFunction {
|
||||
|
||||
@@ -119,11 +120,11 @@ public class MessageFunction {
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append("Here is the current queue of the bot ")
|
||||
.append("(showing ")
|
||||
.append(numberofTracksShown)
|
||||
.append(" out of ")
|
||||
.append(tracks.size())
|
||||
.append(" items):\n");
|
||||
.append("(showing ")
|
||||
.append(numberofTracksShown)
|
||||
.append(" out of ")
|
||||
.append(tracks.size())
|
||||
.append(" items):\n");
|
||||
|
||||
int index = 0;
|
||||
for (AudioTrack track : tracks) {
|
||||
@@ -137,7 +138,9 @@ public class MessageFunction {
|
||||
message.append("- ").append(info.title);
|
||||
}
|
||||
|
||||
if (index == limit) break;
|
||||
if (index == limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return message.toString();
|
||||
@@ -162,7 +165,9 @@ public class MessageFunction {
|
||||
message.addField("Track #" + ++index, info.title, false);
|
||||
}
|
||||
|
||||
if (index == 10) break;
|
||||
if (index == 10) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
message.setTimestamp(OffsetDateTime.now());
|
||||
|
||||
@@ -233,9 +238,9 @@ public class MessageFunction {
|
||||
}
|
||||
|
||||
String subtext = "\n\n" +
|
||||
"-# The bot supports both types of commands: slash (/) and message ($), " +
|
||||
"however not all slash commands might have a corresponding message command.\n" +
|
||||
"-# To get help for a specific command, please use /help <command> ";
|
||||
"-# The bot supports both types of commands: slash (/) and message ($), " +
|
||||
"however not all slash commands might have a corresponding message command.\n" +
|
||||
"-# To get help for a specific command, please use /help <command> ";
|
||||
|
||||
return String.join("\n", help.values()) + subtext;
|
||||
}
|
||||
|
||||
@@ -71,8 +71,9 @@ public class Settings {
|
||||
public String get(String key, String def) {
|
||||
String property = get(key);
|
||||
|
||||
if (property == null || property.isEmpty())
|
||||
if (property == null || property.isEmpty()) {
|
||||
return def;
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
@@ -91,7 +92,8 @@ public class Settings {
|
||||
p.load(is);
|
||||
version = p.getProperty("app.version", "");
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
if (version == null) {
|
||||
version = "0.0.0";
|
||||
|
||||
@@ -14,22 +14,23 @@ import net.dv8tion.jda.api.entities.Role;
|
||||
|
||||
public class UserFunction {
|
||||
|
||||
public static boolean isAdmin(Context context) {
|
||||
if (context instanceof SlashCommandContext) {
|
||||
return true;
|
||||
}
|
||||
public static boolean isAdmin(Context context) {
|
||||
if (context instanceof SlashCommandContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isAdmin(context.getGuildUser());
|
||||
}
|
||||
return isAdmin(context.getGuildUser());
|
||||
}
|
||||
|
||||
public static boolean isAdmin(Member user) {
|
||||
boolean isAdmin = false;
|
||||
for(Role role : user.getRoles()) {
|
||||
if (role.getPermissions().contains(Permission.MANAGE_SERVER) || role.getPermissions().contains(Permission.ADMINISTRATOR))
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
return isAdmin;
|
||||
}
|
||||
public static boolean isAdmin(Member user) {
|
||||
boolean isAdmin = false;
|
||||
for (Role role : user.getRoles()) {
|
||||
if (role.getPermissions().contains(Permission.MANAGE_SERVER) || role.getPermissions().contains(Permission.ADMINISTRATOR)) {
|
||||
isAdmin = true;
|
||||
}
|
||||
}
|
||||
|
||||
return isAdmin;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user