add list-data bot command
Signed-off-by: TudbuT <tudbut@tudbut.de> Original-Message: tud you'll probably get what i mean by this commit, fix it if it's broken :)
This commit is contained in:
parent
f7737de145
commit
7a834559bc
2 changed files with 113 additions and 123 deletions
|
@ -72,6 +72,16 @@ public class Main extends ListenerAdapter {
|
||||||
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
|
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
commands.addCommands(
|
||||||
|
Commands.slash("list-data", "List data of 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.addCommands(
|
||||||
Commands.slash("password", "Set your password.")
|
Commands.slash("password", "Set your password.")
|
||||||
.addOptions(new OptionData(STRING, "password", "Your new password.")
|
.addOptions(new OptionData(STRING, "password", "Your new password.")
|
||||||
|
@ -98,12 +108,11 @@ public class Main extends ListenerAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Got event " + event.getName());
|
System.out.println("Got event " + event.getName());
|
||||||
switch (event.getName()) {
|
try {
|
||||||
case "reset": {
|
switch (event.getName()) {
|
||||||
User user = event.getOption("user").getAsUser();
|
case "reset": {
|
||||||
String password = event.getOption("password").getAsString();
|
User user = event.getOption("user").getAsUser();
|
||||||
|
String password = event.getOption("password").getAsString();
|
||||||
try {
|
|
||||||
|
|
||||||
TCN tcn = new TCN();
|
TCN tcn = new TCN();
|
||||||
tcn.set("action", "reset");
|
tcn.set("action", "reset");
|
||||||
|
@ -111,46 +120,32 @@ public class Main extends ListenerAdapter {
|
||||||
tcn.set("discord-id", user.getIdLong());
|
tcn.set("discord-id", user.getIdLong());
|
||||||
tos.writeString(tcn.toString());
|
tos.writeString(tcn.toString());
|
||||||
|
|
||||||
switch (tis.readInt()) {
|
if(processReply(event, tis)) {
|
||||||
case 201: {
|
event.getChannel().sendMessage("Reset the HWID of **`" + user.getName() + "`**.").queue();
|
||||||
event.getChannel().sendMessage("Reset the HWID of **`" + user.getName() + "`**.").queue();
|
event.reply("`Success.`").setEphemeral(true).queue();
|
||||||
event.reply("`Success.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 403: {
|
|
||||||
event.reply("`Incorrect Admin Password.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 400: {
|
|
||||||
event.reply("`Error! I sent malformed data somehow.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 404: {
|
|
||||||
event.reply("`User Not Found, Do they have BaseBand?`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
event.reply("Error! I am out of sync with the server.").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
break;
|
||||||
event.reply("Exception occurred pushing data to server.").setEphemeral(true).queue();
|
|
||||||
}
|
}
|
||||||
|
case "list-data": {
|
||||||
|
User user = event.getOption("user").getAsUser();
|
||||||
|
String password = event.getOption("password").getAsString();
|
||||||
|
|
||||||
break;
|
TCN tcn = new TCN();
|
||||||
}
|
tcn.set("action", "list-data");
|
||||||
case "branch": {
|
tcn.set("authorisation", Hasher.sha512hex(password));
|
||||||
User user = event.getOption("user").getAsUser();
|
tcn.set("discord-id", user.getIdLong());
|
||||||
String branch = event.getOption("branch").getAsString();
|
tos.writeString(tcn.toString());
|
||||||
String password = event.getOption("password").getAsString();
|
|
||||||
|
|
||||||
try {
|
if(processReply(event, tis)) {
|
||||||
|
event.reply("Success! ```json\n" + tis.readString() + "\n```").setEphemeral(true).queue();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "branch": {
|
||||||
|
User user = event.getOption("user").getAsUser();
|
||||||
|
String branch = event.getOption("branch").getAsString();
|
||||||
|
String password = event.getOption("password").getAsString();
|
||||||
|
|
||||||
TCN tcn = new TCN();
|
TCN tcn = new TCN();
|
||||||
tcn.set("action", "branch");
|
tcn.set("action", "branch");
|
||||||
|
@ -159,92 +154,36 @@ public class Main extends ListenerAdapter {
|
||||||
tcn.set("branch", branch);
|
tcn.set("branch", branch);
|
||||||
tos.writeString(tcn.toString());
|
tos.writeString(tcn.toString());
|
||||||
|
|
||||||
switch (tis.readInt()) {
|
if (processReply(event, tis)) {
|
||||||
case 201: {
|
event.getChannel().sendMessage("Branch of **`" + user.getName() + "`** has been set.").queue();
|
||||||
event.getChannel().sendMessage("Branch of **`" + user.getName() + "`** has been set.").queue();
|
event.reply("`Success.`").setEphemeral(true).queue();
|
||||||
event.reply("`Success.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 403: {
|
|
||||||
event.reply("`Incorrect Admin Password.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 400: {
|
|
||||||
event.reply("`Error! I sent malformed data somehow.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 404: {
|
|
||||||
event.reply("`User Not Found, Do they have BaseBand?`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
event.reply("Error! I am out of sync with the server.").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
break;
|
||||||
event.reply("Exception occurred pushing data to server.").setEphemeral(true).queue();
|
|
||||||
}
|
}
|
||||||
|
case "add": {
|
||||||
|
User user = event.getOption("user").getAsUser();
|
||||||
|
String password = event.getOption("password").getAsString();
|
||||||
|
String username = event.getOption("username").getAsString();
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "add": {
|
|
||||||
User user = event.getOption("user").getAsUser();
|
|
||||||
String password = event.getOption("password").getAsString();
|
|
||||||
String username = event.getOption("username").getAsString();
|
|
||||||
|
|
||||||
try {
|
|
||||||
TCN tcn = new TCN();
|
TCN tcn = new TCN();
|
||||||
tcn.set("action", "add");
|
tcn.set("action", "add");
|
||||||
tcn.set("username", username); //wow yes don't give the username to the server-side great job
|
tcn.set("username", username);
|
||||||
tcn.set("authorisation", Hasher.sha512hex(password));
|
tcn.set("authorisation", Hasher.sha512hex(password));
|
||||||
tcn.set("discord-id", user.getIdLong());
|
tcn.set("discord-id", user.getIdLong());
|
||||||
tos.writeString(tcn.toString());
|
tos.writeString(tcn.toString());
|
||||||
|
|
||||||
switch (tis.readInt()) {
|
if(processReply(event, tis)) {
|
||||||
case 201: {
|
event.getChannel().sendMessage("Created user with username **`" + username + "`**. (`" + user.getName() + "`)").queue();
|
||||||
event.getChannel().sendMessage("Created user with username **`" + username + "`**. (`" + user.getName() + "`)").queue();
|
event.reply("`Success.`").setEphemeral(true).queue();
|
||||||
event.reply("`Success.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 403: {
|
|
||||||
event.reply("`Incorrect Admin Password.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 409: {
|
|
||||||
event.reply("`User already exists!`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 400: {
|
|
||||||
event.reply("`Error! I sent malformed data somehow.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
event.reply("`Error! I am out of sync with the server.`").setEphemeral(true).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
break;
|
||||||
event.reply("Exception occurred pushing data to server.").setEphemeral(true).queue();
|
|
||||||
}
|
}
|
||||||
|
case "password": {
|
||||||
|
User user = event.getUser();
|
||||||
|
String password = event.getOption("password").getAsString();
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "password": {
|
|
||||||
User user = event.getUser();
|
|
||||||
String password = event.getOption("password").getAsString();
|
|
||||||
|
|
||||||
try {
|
|
||||||
TCN tcn = new TCN();
|
TCN tcn = new TCN();
|
||||||
tcn.set("action", "password");
|
tcn.set("action", "password");
|
||||||
tcn.set("authorisation", "1ee7a143df6e0d2f3d2b86b3e5c098c06a07d7c8eb01d629f51712b6bba3a468dc96ef9729d586007ca71383b1c203f6f996bdce3972772d0e5351364eba0d1e");
|
tcn.set("authorisation", "1ee7a143df6e0d2f3d2b86b3e5c098c06a07d7c8eb01d629f51712b6bba3a468dc96ef9729d586007ca71383b1c203f6f996bdce3972772d0e5351364eba0d1e");
|
||||||
|
@ -278,15 +217,49 @@ public class Main extends ListenerAdapter {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
event.reply("Exception occurred pushing data to server.").setEphemeral(true).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
event.reply("I can't handle that command right now :(").setEphemeral(true).queue();
|
||||||
}
|
}
|
||||||
default:
|
} catch (IOException e) {
|
||||||
event.reply("I can't handle that command right now :(").setEphemeral(true).queue();
|
e.printStackTrace();
|
||||||
|
event.reply("Exception occurred pushing data to server.").setEphemeral(true).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean processReply(@NotNull SlashCommandInteractionEvent event, TypedInputStream tis) throws IOException {
|
||||||
|
switch (tis.readInt()) {
|
||||||
|
case 201: {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 403: {
|
||||||
|
event.reply("Incorrect Admin Password.").setEphemeral(true).queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 400: {
|
||||||
|
event.reply("Error! I sent malformed data somehow.").setEphemeral(true).queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 409: {
|
||||||
|
event.reply("Already exists!").setEphemeral(true).queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 404: {
|
||||||
|
event.reply("User Not Found, Do they have BaseBand?").setEphemeral(true).queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
event.reply("Error! I am out of sync with the server.").setEphemeral(true).queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ package de.com.baseband.server;
|
||||||
import at.favre.lib.crypto.bcrypt.BCrypt;
|
import at.favre.lib.crypto.bcrypt.BCrypt;
|
||||||
import de.tudbut.io.TypedInputStream;
|
import de.tudbut.io.TypedInputStream;
|
||||||
import de.tudbut.io.TypedOutputStream;
|
import de.tudbut.io.TypedOutputStream;
|
||||||
|
import de.tudbut.parsing.JSON;
|
||||||
import de.tudbut.parsing.TCN;
|
import de.tudbut.parsing.TCN;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -59,6 +60,22 @@ public class BotServiceHandler {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "list-data": {
|
||||||
|
TCN user = (TCN) UserHandler.users.stream()
|
||||||
|
.filter(
|
||||||
|
a -> ((TCN) a).getLong("discord-id").equals(tcn.getLong("discord-id"))
|
||||||
|
).findFirst().orElse(null);
|
||||||
|
|
||||||
|
if(user != null) {
|
||||||
|
tos.writeInt(201);
|
||||||
|
tos.writeString(JSON.writeReadable(user, 4));
|
||||||
|
} else {
|
||||||
|
tos.writeInt(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case "branch": {
|
case "branch": {
|
||||||
TCN user = (TCN) UserHandler.users.stream()
|
TCN user = (TCN) UserHandler.users.stream()
|
||||||
.filter(
|
.filter(
|
||||||
|
|
Loading…
Add table
Reference in a new issue