Merged in bugfix/FS-34-permissions-command-fails-silently (pull request #1)
Bugfix/FS-34 permissions command fails silently
This commit is contained in:
commit
b27918f8d9
@ -26,10 +26,10 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.xerial:sqlite-jdbc:3.36.0.2'
|
||||
implementation 'org.xerial:sqlite-jdbc:3.41.2.2'
|
||||
implementation 'org.postgresql:postgresql:42.2.24'
|
||||
implementation 'com.github.Kaaz:ConfigurationBuilder:0.4'
|
||||
implementation 'org.javacord:javacord:3.7.0'
|
||||
implementation 'org.javacord:javacord:3.8.0'
|
||||
implementation 'com.vdurmont:emoji-java:5.1.1'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
||||
implementation 'ch.qos.logback:logback-classic:1.2.5'
|
||||
@ -37,7 +37,7 @@ dependencies {
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.5.4'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web:2.5.4'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.4'
|
||||
// implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.4'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.5.4'
|
||||
|
||||
implementation platform('com.google.cloud:libraries-bom:23.0.0')
|
||||
|
@ -5,7 +5,7 @@
|
||||
package dev.salmonllama.fsbot;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.config.SecretManager;
|
||||
// import dev.salmonllama.fsbot.config.SecretManager;
|
||||
import dev.salmonllama.fsbot.database.FSDB;
|
||||
import dev.salmonllama.fsbot.guthix.Guthix;
|
||||
import dev.salmonllama.fsbot.listeners.*;
|
||||
@ -25,18 +25,20 @@ public class Main {
|
||||
private final static Logger logger = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
BotConfig.initConfig(Constants.BOT_FOLDER, false); // TODO: Sunset the bot config once and for all
|
||||
BotConfig.initConfig(Constants.BOT_FOLDER, false);
|
||||
|
||||
FSDB.init();
|
||||
|
||||
String token;
|
||||
if (System.getenv("ENVIRONMENT") != null)
|
||||
{
|
||||
token = SecretManager.DISCORD_TOKEN_PROD.getPlainText();
|
||||
token = BotConfig.BOT_TOKEN_PROD;
|
||||
// token = SecretManager.DISCORD_TOKEN_PROD.getPlainText();
|
||||
}
|
||||
else
|
||||
{
|
||||
token = SecretManager.DISCORD_TOKEN.getPlainText();
|
||||
token = BotConfig.BOT_TOKEN_DEV;
|
||||
// token = SecretManager.DISCORD_TOKEN.getPlainText();
|
||||
}
|
||||
|
||||
new DiscordApiBuilder().addIntents(Intent.MESSAGE_CONTENT).setToken(token).login().thenAccept(api -> {
|
||||
|
@ -93,7 +93,7 @@ public class PermissionCommand extends Command {
|
||||
perm -> ctx.getApi().getUserById(perm.getUserId()).thenAcceptAsync(
|
||||
(discordUser) -> text.append(perm.getUserId())
|
||||
.append(" - ")
|
||||
.append(discordUser.getDiscriminatedName())
|
||||
.append(discordUser.getName())
|
||||
.append(System.lineSeparator())
|
||||
).join()
|
||||
)
|
||||
@ -116,14 +116,14 @@ public class PermissionCommand extends Command {
|
||||
}
|
||||
|
||||
private void add(CommandContext ctx) {
|
||||
String userId;
|
||||
if (ctx.getMessage().getMentionedUsers().isEmpty()) {
|
||||
System.out.println("No mentioned users");
|
||||
// If no mentioned users, improper usage
|
||||
return;
|
||||
// If no mentioned users, then the user ID = args[1]
|
||||
userId = ctx.getArgs()[1];
|
||||
} else {
|
||||
userId = ctx.getMessage().getMentionedUsers().get(0).getIdAsString();
|
||||
}
|
||||
|
||||
String userId = ctx.getMessage().getMentionedUsers().get(0).getIdAsString();
|
||||
|
||||
StaticPermission perm = new StaticPermission.StaticPermissionBuilder(userId).setPermission(ctx.getArgs()[2]).build();
|
||||
|
||||
StaticPermissionController.insert(perm).thenAcceptAsync((Void) -> {
|
||||
@ -131,19 +131,19 @@ public class PermissionCommand extends Command {
|
||||
.setTitle("Permissions Added")
|
||||
.addField("User:", userId)
|
||||
.addField("Permission:", ctx.getArgs()[2]);
|
||||
|
||||
ctx.reply(response);
|
||||
});
|
||||
}
|
||||
|
||||
private void remove(CommandContext ctx) { // TODO: Remove is not functional
|
||||
if (ctx.getMessage().getMentionedUsers().isEmpty()) {
|
||||
// If no mentioned users, improper usage
|
||||
return;
|
||||
}
|
||||
String userId = ctx.getArgs()[1];
|
||||
|
||||
String userId = ctx.getMessage().getMentionedUsers().get(0).getIdAsString();
|
||||
|
||||
StaticPermissionController.delete(userId, ctx.getArgs()[2]).thenAcceptAsync((Void) -> System.out.println("Permission removed")).exceptionally(ExceptionLogger.get());
|
||||
StaticPermissionController.delete(userId, ctx.getArgs()[2]).thenAcceptAsync((Void) -> {
|
||||
EmbedBuilder response = new EmbedBuilder()
|
||||
.setTitle("Permissions Removed")
|
||||
.addField("User:", userId)
|
||||
.addField("Permission:", ctx.getArgs()[2]);
|
||||
ctx.reply(response);
|
||||
}).exceptionally(ExceptionLogger.get());
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import com.kaaz.configuration.ConfigurationBuilder;
|
||||
import com.kaaz.configuration.ConfigurationOption;
|
||||
import dev.salmonllama.fsbot.utilities.Constants;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@ -74,6 +73,18 @@ public class BotConfig {
|
||||
@ConfigurationOption
|
||||
public static String HOME_SERVER = "Home server here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String BOT_TOKEN_DEV = "bot token here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String BOT_TOKEN_PROD = "production token here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String IMGUR_BEARER = "Bearer token here";
|
||||
|
||||
@ConfigurationOption
|
||||
public static String IMGUR_CLIENT = "client ID here";
|
||||
|
||||
public static void initConfig(Path filePath, boolean cleanfile) {
|
||||
try {
|
||||
new ConfigurationBuilder(BotConfig.class, Paths.get(filePath.toString(), Constants.CONFIG_NAME) .toFile()).build(cleanfile);
|
||||
|
@ -4,10 +4,12 @@
|
||||
|
||||
package dev.salmonllama.fsbot.endpoints.imgur;
|
||||
|
||||
import dev.salmonllama.fsbot.config.SecretManager;
|
||||
//import dev.salmonllama.fsbot.config.SecretManager;
|
||||
import okhttp3.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@ -22,8 +24,10 @@ public class ImgurAPIConnection {
|
||||
private final Request.Builder requestBuilder;
|
||||
|
||||
public ImgurAPIConnection() {
|
||||
CLIENT_ID = SecretManager.IMGUR_ID.getPlainText();
|
||||
BEARER_TOKEN = SecretManager.IMGUR_BEARER.getPlainText();
|
||||
CLIENT_ID = BotConfig.IMGUR_CLIENT;
|
||||
BEARER_TOKEN = BotConfig.IMGUR_BEARER;
|
||||
// CLIENT_ID = SecretManager.IMGUR_ID.getPlainText();
|
||||
// BEARER_TOKEN = SecretManager.IMGUR_BEARER.getPlainText();
|
||||
|
||||
client = new OkHttpClient().newBuilder().build();
|
||||
requestBuilder = new Request.Builder();
|
||||
|
Loading…
Reference in New Issue
Block a user