SteamWar/BungeeCore
Archiviert
13
2

Add SlashCommandListener

Add WhoisCommand
Dieser Commit ist enthalten in:
yoyosource 2021-07-29 20:27:43 +02:00
Ursprung df990e3bc9
Commit a0f9764a4b
7 geänderte Dateien mit 157 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.bungeecore.bot;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.bot.commands.BanCommand; import de.steamwar.bungeecore.bot.commands.BanCommand;
import de.steamwar.bungeecore.bot.commands.MuteCommand; import de.steamwar.bungeecore.bot.commands.MuteCommand;
import de.steamwar.bungeecore.bot.commands.WhoisCommand;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.bungeecore.bot.events.EventManager; import de.steamwar.bungeecore.bot.events.EventManager;
import de.steamwar.bungeecore.bot.events.SchematicsManager; import de.steamwar.bungeecore.bot.events.SchematicsManager;
@ -96,10 +97,12 @@ public class SteamwarDiscordBot {
announcementListener = new AnnouncementListener(); announcementListener = new AnnouncementListener();
ingameChatListener = new IngameChatListener(); ingameChatListener = new IngameChatListener();
serverTeamChatListener = new ServerTeamChatListener(); serverTeamChatListener = new ServerTeamChatListener();
new SlashCommandListener();
CommandListUpdateAction commands = jda.updateCommands(); CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands();
commands.addCommands(new MuteCommand()); commands.addCommands(new MuteCommand());
commands.addCommands(new BanCommand()); commands.addCommands(new BanCommand());
commands.addCommands(new WhoisCommand());
commands.complete(); commands.complete();
} }

Datei anzeigen

@ -29,5 +29,6 @@ public class BanCommand extends CommandData {
addOption(OptionType.STRING, "user", "The user to bam", true); addOption(OptionType.STRING, "user", "The user to bam", true);
addOption(OptionType.STRING, "duration", "The time to ban until", true); addOption(OptionType.STRING, "duration", "The time to ban until", true);
addOption(OptionType.STRING, "reason", "The reason to ban", true);
} }
} }

Datei anzeigen

@ -29,5 +29,6 @@ public class MuteCommand extends CommandData {
addOption(OptionType.STRING, "user", "The user to mute", true); addOption(OptionType.STRING, "user", "The user to mute", true);
addOption(OptionType.STRING, "duration", "The time to mute until", true); addOption(OptionType.STRING, "duration", "The time to mute until", true);
addOption(OptionType.STRING, "reason", "The reason to mute", true);
} }
} }

Datei anzeigen

@ -0,0 +1,32 @@
/*
* 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 net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
public class WhoisCommand extends CommandData {
public WhoisCommand() {
super("whois", "Check a users id and stuff");
addOption(OptionType.STRING, "user", "The user to get", true);
}
}

Datei anzeigen

@ -0,0 +1,115 @@
/*
* 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.listeners;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team;
import jdk.nashorn.internal.runtime.regexp.joni.constants.TargetInfo;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import org.jetbrains.annotations.NotNull;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.List;
public class SlashCommandListener extends BasicDiscordListener {
@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
switch (event.getName()) {
case "mute":
case "ban":
banAndMute(event);
break;
case "whois":
whois(event);
break;
default:
return;
}
}
private void banAndMute(SlashCommandEvent event) {
if (!testPermission(event)) {
return;
}
System.out.println(event.getName() + " " + event.getOptions());
}
private void whois(SlashCommandEvent event) {
if (!testPermission(event)) {
return;
}
String s = event.getOption("user").getAsString();
SteamwarUser user = SteamwarUser.get(s);
if (user == null) {
try {
int id = Integer.parseInt(s);
user = SteamwarUser.get(id);
} catch (NumberFormatException ignored) {
// Ignored
}
}
if (user == null) {
event.reply("Der angegebene Spieler ist unbekannt").setEphemeral(true).complete();
return;
}
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Whois: " + user.getUserName());
StringBuilder st = new StringBuilder();
st.append("UUID: ").append(user.getUuid()).append("\n");
st.append("ID: ").append(user.getId()).append("\n");
if (user.getDiscordId() != null) {
st.append("DiscordID: ").append(user.getDiscordId()).append("\n");
}
Timestamp timestamp = user.getFirstjoin();
st.append("Beigetreten am: ").append(timestamp == null ? "0000-00-00 00:00:00" : timestamp.toString()).append("\n");
st.append("Online Time: ").append(new DecimalFormat("###.##").format(user.getOnlinetime() / (double) 3600)).append("h\n");
Team team = Team.get(user.getTeam());
st.append("Team: [").append(team.getTeamKuerzel()).append("] ").append(team.getTeamName());
embedBuilder.addField("Daten:", st.toString(), false);
List<Punishment> punishmentList = Punishment.getAllPunishmentsOfPlayer(user.getId());
for (Punishment punishment : punishmentList) {
embedBuilder.addField(punishment.getType().name() + " von " + SteamwarUser.get(punishment.getPunisher()).getUserName(), "Von: " + punishment.getBantime(punishment.getStartTime(), false) + "\nBis: " + punishment.getBantime(punishment.getEndTime(), punishment.isPerma()) + "\nGrund: " + punishment.getReason(), false);
}
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
}
private boolean testPermission(SlashCommandEvent event) {
Member member = event.getMember();
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
if (steamwarUser == null || !steamwarUser.getUserGroup().isTeamGroup()) {
event.reply("Du hast für " + event.getName() + " keine Rechte oder es existiert keine Verknüpfung für dich.").setEphemeral(true).complete();
return false;
}
return true;
}
}

Datei anzeigen

@ -67,6 +67,9 @@ public class WhoisCommand extends BasicCommand {
Message.send("WHOIS_USERNAME", player, user.getUserName()); Message.send("WHOIS_USERNAME", player, user.getUserName());
Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString()); Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString());
Message.send("WHOIS_ID", player, user.getId()); Message.send("WHOIS_ID", player, user.getId());
if (user.getDiscordId() != null) {
Message.send("WHOIS_DISCORD_ID", player, user.getDiscordId());
}
Timestamp firstJoin = user.getFirstjoin(); Timestamp firstJoin = user.getFirstjoin();
if(firstJoin == null) if(firstJoin == null)
Message.send("WHOIS_JOINED_FIRST", player, "0000-00-00 00:00:00"); Message.send("WHOIS_JOINED_FIRST", player, "0000-00-00 00:00:00");

Datei anzeigen

@ -505,6 +505,7 @@ WHOIS_USERNAME=§7Username§8: §e{0}
WHOIS_UUID=§7UUID§8: §e{0} WHOIS_UUID=§7UUID§8: §e{0}
WHOIS_UUID_HOVER=§eUUID Kopieren WHOIS_UUID_HOVER=§eUUID Kopieren
WHOIS_ID=§7ID§8: §e{0} WHOIS_ID=§7ID§8: §e{0}
WHOIS_DISCORD_ID=§7Discord-D§8: §e{0}
WHOIS_JOINED_FIRST=§7Beigetreten am§8: §e{0} WHOIS_JOINED_FIRST=§7Beigetreten am§8: §e{0}
WHOIS_HOURS_PLAYED=§7Online Time§8: §e{0}h WHOIS_HOURS_PLAYED=§7Online Time§8: §e{0}h
WHOIS_TEAM=§7Team§8: §e[§{0}{1}§e] {2} WHOIS_TEAM=§7Team§8: §e[§{0}{1}§e] {2}