add ban command

This commit is contained in:
Jess H 2024-06-14 00:12:55 +01:00
parent fb7e002056
commit 756a93f0ba
Signed by: UnixSystemV
GPG key ID: 9B21C50B68D67F19
2 changed files with 49 additions and 0 deletions

View file

@ -48,6 +48,16 @@ public class Main extends ListenerAdapter {
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
);
commands.addCommands(
Commands.slash("ban", "Ban the given user.")
.addOptions(new OptionData(USER, "user", "The user who's HWID we should reset.")
.setRequired(true))
.addOptions(new OptionData(STRING, "password", "The admin password.")
.setRequired(true))
.setGuildOnly(true)
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
);
commands.addCommands(
Commands.slash("branch", "Set branch of a given user.")
.addOptions(new OptionData(USER, "user", "The user who's branch we should change.")
@ -127,6 +137,29 @@ public class Main extends ListenerAdapter {
break;
}
case "ban": {
User user = event.getOption("user").getAsUser();
String password = event.getOption("password").getAsString();
TCN tcn = new TCN();
tcn.set("action", "ban");
tcn.set("authorisation", Hasher.sha512hex(password));
tcn.set("discord-id", user.getIdLong());
tos.writeString(tcn.toString());
if(processReply(event, tis)) {
if(tis.readBoolean()) {
event.getChannel().sendMessage("Successfully banned **`" + user.getName() + "`**.").queue();
} else {
event.getChannel().sendMessage("Successfully unbanned **`" + user.getName() + "`**.").queue();
}
event.reply("`Success.`").setEphemeral(true).queue();
}
break;
}
case "list-data": {
User user = event.getOption("user").getAsUser();
String password = event.getOption("password").getAsString();

View file

@ -60,6 +60,22 @@ public class BotServiceHandler {
break;
}
case "ban": {
TCN user = (TCN) UserHandler.users.stream()
.filter(
a -> ((TCN) a).getLong("discord-id").equals(tcn.getLong("discord-id"))
).findFirst().orElse(null);
if(user != null) {
user.set("disabled", !user.getBoolean("disabled"));
tos.writeInt(201);
tos.writeBoolean(user.getBoolean("disabled"));
} else {
tos.writeInt(404);
}
break;
}
case "list-data": {
TCN user = (TCN) UserHandler.users.stream()
.filter(