Add Kick Command To Discord Bot & Fix Type In ConfigLoader

This commit is contained in:
Dark98
2021-12-06 01:45:31 +00:00
parent d2faea6f71
commit 5c02c34569
2 changed files with 18 additions and 5 deletions
@@ -73,7 +73,7 @@ public class ConfigLoader {
}
public static void loadSecrets() throws IOException {
if (!new File("data/Secrets.json").exists()) {
if (!new File("data/secrets.json").exists()) {
initialize();
System.out.println("Please open \"data/secrets.json\" file and enter your discord token bot there!");
System.out.println("Please open \"data/secrets.json\" file and enter your Website Password there!");
@@ -1,6 +1,9 @@
package com.rs2.integrations.discord;
import com.rs2.GameConstants;
import com.rs2.game.players.Client;
import com.rs2.game.players.Player;
import com.rs2.game.players.PlayerHandler;
import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import org.javacord.api.entity.channel.TextChannel;
@@ -39,12 +42,22 @@ public class JavaCord {
}
api.addMessageCreateListener(event -> {
if (event.getMessageContent().startsWith("::w" + GameConstants.WORLD + " movehome")) {
if (event.getMessageContent().startsWith("::w" + GameConstants.WORLD + " kick")) {
if (event.getMessageAuthor().isServerAdmin()) {
System.out.println("perms");
event.getChannel().sendMessage("perms");
String playerToKick = event.getMessageContent().replace("::w" + GameConstants.WORLD + " kick ", "");
for (Player player2 : PlayerHandler.players) {
if (player2 != null) {
if (player2.playerName.equalsIgnoreCase(playerToKick)) {
Client c2 = (Client) player2;
event.getChannel().sendMessage("You have kicked " + playerToKick + ".");
c2.disconnected = true;
c2.logout(true);
break;
}
}
}
} else {
event.getChannel().sendMessage("You do not have permission to preform this command");
event.getChannel().sendMessage("You do not have permission to perform this command");
}
}
});