diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java index 6f9bae3..7c5f1db 100644 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java @@ -113,6 +113,7 @@ public class SteamwarDiscordBot { addCommand(commands, new WhoisCommand()); addCommand(commands, new TeamCommand()); addCommand(commands, new ListCommand()); + addCommand(commands, new UnbanCommand()); commands.complete(); } diff --git a/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java b/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java new file mode 100644 index 0000000..7147108 --- /dev/null +++ b/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java @@ -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 . + */ + +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(); + } +}