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