add ban command
This commit is contained in:
parent
fb7e002056
commit
756a93f0ba
2 changed files with 49 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue