SteamWar/BungeeCore
Archiviert
13
2

Add BanCommand and MuteCommand

Dieser Commit ist enthalten in:
yoyosource 2021-07-29 22:20:15 +02:00
Ursprung 10cc652c39
Commit 850a0d212e
6 geänderte Dateien mit 52 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -36,6 +36,7 @@ import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
@ -99,6 +100,10 @@ public class SteamwarDiscordBot {
serverTeamChatListener = new ServerTeamChatListener();
new SlashCommandListener();
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).complete());
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
guild.retrieveCommands().complete().forEach(command -> guild.deleteCommandById(command.getId()).complete());
CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands();
commands.addCommands(new MuteCommand());
commands.addCommands(new BanCommand());

Datei anzeigen

@ -28,7 +28,7 @@ public class BanCommand extends CommandData {
super("ban", "Ban a user. Requires permission to ban users.");
addOption(OptionType.STRING, "user", "The user to bam", true);
addOption(OptionType.STRING, "duration", "The time to ban until", true);
addOption(OptionType.STRING, "time", "The time to ban until", true);
addOption(OptionType.STRING, "reason", "The reason to ban", true);
}
}

Datei anzeigen

@ -28,7 +28,7 @@ public class MuteCommand extends CommandData {
super("mute", "Mute a user. Requires permission to mute users.");
addOption(OptionType.STRING, "user", "The user to mute", true);
addOption(OptionType.STRING, "duration", "The time to mute until", true);
addOption(OptionType.STRING, "time", "The time to mute until", true);
addOption(OptionType.STRING, "reason", "The reason to mute", true);
}
}

Datei anzeigen

@ -19,6 +19,8 @@
package de.steamwar.bungeecore.bot.listeners;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.commands.BanCommand;
import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team;
@ -53,7 +55,30 @@ public class SlashCommandListener extends BasicDiscordListener {
return;
}
System.out.println(event.getName() + " " + event.getOptions());
SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong());
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
if (target == null) {
event.reply("Angegebener User invalide").setEphemeral(true).complete();
return;
}
Timestamp time = BanCommand.parseTime(null, event.getOption("time").getAsString());
if (time == null) {
event.reply("Angegebene Zeit invalide").setEphemeral(true).complete();
return;
}
String msg = event.getOption("reason").getAsString();
boolean isPerma = event.getOption("time").getAsString().equals("perma");
if (event.getName().equals("ban")) {
target.ban(time, msg, sender.getId(), isPerma);
Message.team("BAN_TEAM_BANNED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg);
} else {
target.mute(time, msg, sender.getId(), isPerma);
Message.team("MUTE_TEAM_MUTED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg);
}
event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + (event.getName().equals("ban") ? " gebannt" : " gemutet")).setEphemeral(true).complete();
}
private void whois(SlashCommandEvent event) {
@ -72,6 +97,14 @@ public class SlashCommandListener extends BasicDiscordListener {
// Ignored
}
}
if (user == null) {
try {
long id = Long.parseLong(s);
user = SteamwarUser.get(id);
} catch (NumberFormatException ignored) {
// Ignored
}
}
if (user == null) {
event.reply("Der angegebene Spieler ist unbekannt").setEphemeral(true).complete();

Datei anzeigen

@ -74,7 +74,9 @@ public class BanCommand extends BasicCommand {
Date parsedDate = dateFormat.parse(arg.split("_")[0]);
return new java.sql.Timestamp(parsedDate.getTime());
}catch(ParseException exception){
Message.send("INVALID_TIME", sender);
if (sender != null) {
Message.send("INVALID_TIME", sender);
}
return null;
}
}

Datei anzeigen

@ -54,6 +54,14 @@ public class WhoisCommand extends BasicCommand {
user = SteamwarUser.get(id);
}catch (NumberFormatException ignored) {}
}
if (user == null) {
try {
long id = Long.parseLong(args[0]);
user = SteamwarUser.get(id);
} catch (NumberFormatException ignored) {
// Ignored
}
}
if(user == null) {
Message.send("UNKNOWN_PLAYER", player);