Archiviert
1
0

Add UnbanCommand

Dieser Commit ist enthalten in:
yoyosource 2021-07-30 16:14:05 +02:00
Ursprung d476fd12bd
Commit 4865c2f9a6
2 geänderte Dateien mit 60 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -113,6 +113,7 @@ public class SteamwarDiscordBot {
addCommand(commands, new WhoisCommand()); addCommand(commands, new WhoisCommand());
addCommand(commands, new TeamCommand()); addCommand(commands, new TeamCommand());
addCommand(commands, new ListCommand()); addCommand(commands, new ListCommand());
addCommand(commands, new UnbanCommand());
commands.complete(); commands.complete();
} }

Datei anzeigen

@ -0,0 +1,59 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.bot.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import java.sql.Timestamp;
import java.util.Date;
public class UnbanCommand extends BasicDiscordCommand {
public UnbanCommand() {
super("unban", "Entbannt einen Nutzer, wenn du die Rechte hast.");
addOption(OptionType.STRING, "user", "Der Benutzer", true);
}
@Override
public void run(SlashCommandEvent event) {
if (!testPermission(event)) {
return;
}
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;
}
if (!target.isBanned()) {
event.reply("Angegebener User ist nicht gebannt").setEphemeral(true).complete();
return;
}
target.ban(Timestamp.from(new Date().toInstant()), "Unban", sender.getId(), false);
event.reply("Erfolgreich " + target.getUserName() + " entbannt").setEphemeral(true).complete();
}
}