add discord bot + request handler on server side
All checks were successful
/ Build BaseBand Server (push) Successful in 3m37s
All checks were successful
/ Build BaseBand Server (push) Successful in 3m37s
This commit is contained in:
parent
655f4072fe
commit
97c8035165
10 changed files with 300 additions and 16 deletions
46
Discord/build.gradle
Normal file
46
Discord/build.gradle
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.baseband.bot'
|
||||||
|
version = '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
jarLibs
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
|
||||||
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
|
||||||
|
|
||||||
|
jarLibs("net.dv8tion:JDA:5.0.0-beta.24")
|
||||||
|
jarLibs(files('libs/TuddyLIB.jar'))
|
||||||
|
|
||||||
|
implementation configurations.jarLibs
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
jar {
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
|
|
||||||
|
from {
|
||||||
|
configurations.jarLibs.collect {
|
||||||
|
it.isDirectory() ? it : zipTree(it)
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
exclude "LICENSE.txt", "META-INF/MANIFSET.MF", "META-INF/maven/**", "META-INF/*.RSA", "META-INF/*.SF"
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest.attributes(
|
||||||
|
'Main-Class': 'com.baseband.bot.Main',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
BIN
Discord/build/classes/java/main/com/baseband/bot/Main.class
Normal file
BIN
Discord/build/classes/java/main/com/baseband/bot/Main.class
Normal file
Binary file not shown.
BIN
Discord/build/tmp/compileJava/previous-compilation-data.bin
Normal file
BIN
Discord/build/tmp/compileJava/previous-compilation-data.bin
Normal file
Binary file not shown.
BIN
Discord/libs/TuddyLIB-javadoc.zip
Normal file
BIN
Discord/libs/TuddyLIB-javadoc.zip
Normal file
Binary file not shown.
BIN
Discord/libs/TuddyLIB.jar
Normal file
BIN
Discord/libs/TuddyLIB.jar
Normal file
Binary file not shown.
163
Discord/src/main/java/com/baseband/bot/Main.java
Normal file
163
Discord/src/main/java/com/baseband/bot/Main.java
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
package com.baseband.bot;
|
||||||
|
|
||||||
|
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||||
|
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||||
|
|
||||||
|
import de.tudbut.net.ws.Client;
|
||||||
|
import de.tudbut.parsing.TCN;
|
||||||
|
import de.tudbut.tools.Hasher;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||||
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||||
|
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static de.tudbut.net.http.HTTPContentType.TCN;
|
||||||
|
import static net.dv8tion.jda.api.interactions.commands.OptionType.STRING;
|
||||||
|
import static net.dv8tion.jda.api.interactions.commands.OptionType.USER;
|
||||||
|
|
||||||
|
public class Main extends ListenerAdapter {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JDA jda = JDABuilder.createLight("MTI0OTU0Nzg4Mzc1ODM1NDQ2Nw.GKWKLI.QeS4zbIn2q3Yl9KSZ-8z_8izFsspHiLYlIMIpY", GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES)
|
||||||
|
.addEventListeners(new Main())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
jda.getPresence().setActivity(Activity.customStatus("Amazing, Kamerad!"));
|
||||||
|
CommandListUpdateAction commands = jda.updateCommands();
|
||||||
|
|
||||||
|
commands.addCommands(
|
||||||
|
Commands.slash("test", "Test command.")
|
||||||
|
.setGuildOnly(true)
|
||||||
|
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
|
||||||
|
);
|
||||||
|
|
||||||
|
commands.addCommands(
|
||||||
|
Commands.slash("reset", "Reset HWID of a given user.")
|
||||||
|
.addOptions(new OptionData(USER, "user", "The user who's HWID we should reset.")
|
||||||
|
.setRequired(true)).setGuildOnly(true)
|
||||||
|
.addOptions(new OptionData(STRING, "password", "The admin password.")
|
||||||
|
.setRequired(true)).setGuildOnly(true)
|
||||||
|
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
|
||||||
|
);
|
||||||
|
|
||||||
|
commands.addCommands(
|
||||||
|
Commands.slash("add", "Add a user.")
|
||||||
|
.addOptions(new OptionData(USER, "user", "The user who's HWID we should reset.")
|
||||||
|
.setRequired(true)).setGuildOnly(true)
|
||||||
|
.addOptions(new OptionData(STRING, "password", "The admin password.")
|
||||||
|
.setRequired(true)).setGuildOnly(true)
|
||||||
|
.addOptions(new OptionData(STRING, "username", "The username of the user to create.")
|
||||||
|
.setRequired(true)).setGuildOnly(true)
|
||||||
|
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
commands.queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
|
||||||
|
if (event.getGuild() == null)
|
||||||
|
return;
|
||||||
|
switch (event.getName()) {
|
||||||
|
case "reset" : {
|
||||||
|
User user = event.getOption("user").getAsUser();
|
||||||
|
String password = event.getOption("password").getAsString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Client client = new Client("127.0.0.1", 40001);
|
||||||
|
TCN tcn = new TCN();
|
||||||
|
tcn.set("action", "reset");
|
||||||
|
tcn.set("authorisation", Hasher.sha512hex(password));
|
||||||
|
tcn.set("discord-id", user.getIdLong());
|
||||||
|
client.send(tcn.toString());
|
||||||
|
|
||||||
|
switch (client.receive()) {
|
||||||
|
case "200": {
|
||||||
|
event.reply("`Reset the HWID of "+user.getName()+".`").queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "403": {
|
||||||
|
event.reply("`Incorrect Admin Password.`").setEphemeral(true).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
case "503": {
|
||||||
|
event.reply("`Error! TCN Exception.`").setEphemeral(true).queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "404": {
|
||||||
|
event.reply("`User Not Found, Do they have BaseBand?`").setEphemeral(true).queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
event.reply("Exception occurred pushing data to server.").setEphemeral(true).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "add" : {
|
||||||
|
User user = event.getOption("user").getAsUser();
|
||||||
|
String password = event.getOption("password").getAsString();
|
||||||
|
String username = event.getOption("username").getAsString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Client client = new Client("127.0.0.1", 40001);
|
||||||
|
TCN tcn = new TCN();
|
||||||
|
tcn.set("action", "create");
|
||||||
|
tcn.set("authorisation", Hasher.sha512hex(password));
|
||||||
|
tcn.set("discord-id", user.getIdLong());
|
||||||
|
client.send(tcn.toString());
|
||||||
|
|
||||||
|
switch (client.receive()) {
|
||||||
|
case "200": {
|
||||||
|
event.reply("`Created user with username "+username+". ("+ user.getName() +")`").queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "403": {
|
||||||
|
event.reply("`Incorrect Admin Password.`").setEphemeral(true).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
case "400": {
|
||||||
|
event.reply("`User already exists!`").setEphemeral(true).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
case "503": {
|
||||||
|
event.reply("`Error! TCN Exception.`").setEphemeral(true).queue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
event.reply("Exception occurred pushing data to server.").setEphemeral(true).queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
event.reply("I can't handle that command right now :(").setEphemeral(true).queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void say(SlashCommandInteractionEvent event, String content) {
|
||||||
|
event.reply(content).queue(); // This requires no permissions!
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
package com.baseband.server;
|
||||||
|
|
||||||
|
import at.favre.lib.crypto.bcrypt.BCrypt;
|
||||||
|
import de.tudbut.net.ws.Connection;
|
||||||
|
import de.tudbut.net.ws.ConnectionHandler;
|
||||||
|
import de.tudbut.parsing.TCN;
|
||||||
|
import de.tudbut.tools.Hasher;
|
||||||
|
import de.tudbut.tools.StringTools;
|
||||||
|
import de.tudbut.tools.encryption.Key;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
|
public class BotServiceHandler implements ConnectionHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(Connection connection) throws IOException {
|
||||||
|
try {
|
||||||
|
TCN tcn = TCN.read(connection.receive());
|
||||||
|
|
||||||
|
String password = "1ee7a143df6e0d2f3d2b86b3e5c098c06a07d7c8eb01d629f51712b6bba3a468dc96ef9729d586007ca71383b1c203f6f996bdce3972772d0e5351364eba0d1e";
|
||||||
|
|
||||||
|
if(!tcn.getString("authorisation").equals(password)) {
|
||||||
|
connection.send("403");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String action = tcn.getString("action");
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case "reset" : {
|
||||||
|
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("hardware-id-reset", true);
|
||||||
|
connection.send("200");
|
||||||
|
} else {
|
||||||
|
connection.send("404");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "add" : {
|
||||||
|
long discord_id = tcn.getLong("discord-id");
|
||||||
|
String username = tcn.getString("username");
|
||||||
|
|
||||||
|
|
||||||
|
TCN userToAdd = new TCN();
|
||||||
|
|
||||||
|
tcn.set("username", username);
|
||||||
|
tcn.set("password", BCrypt.withDefaults().hashToString(4, new String(SecureRandom.getSeed(64)).toCharArray()));
|
||||||
|
tcn.set("hardware-id", Hasher.sha512hex(new String(SecureRandom.getSeed(512))));
|
||||||
|
tcn.set("hardware-id-reset", true);
|
||||||
|
tcn.set("disabled", false);
|
||||||
|
tcn.set("discord-id", discord_id);
|
||||||
|
|
||||||
|
TCN user = (TCN) UserHandler.users.stream() //checking if it already exists LOL
|
||||||
|
.filter(
|
||||||
|
a -> ((TCN) a).getLong("discord-id").equals(tcn.getLong("discord-id"))
|
||||||
|
).findFirst().orElse(null);
|
||||||
|
|
||||||
|
if(user == null) {
|
||||||
|
UserHandler.users.add(userToAdd);
|
||||||
|
connection.send("200");
|
||||||
|
} else {
|
||||||
|
connection.send("400");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (TCN.TCNException e) {
|
||||||
|
connection.send("503");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ import de.tudbut.parsing.JSON;
|
||||||
import de.tudbut.parsing.TCN;
|
import de.tudbut.parsing.TCN;
|
||||||
import de.tudbut.parsing.TCNArray;
|
import de.tudbut.parsing.TCNArray;
|
||||||
import de.tudbut.tools.Hasher;
|
import de.tudbut.tools.Hasher;
|
||||||
|
import de.tudbut.net.ws.Server;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -65,6 +66,7 @@ public class Main {
|
||||||
tcn.set("hardware-id", Hasher.sha512hex("hardware-id"));
|
tcn.set("hardware-id", Hasher.sha512hex("hardware-id"));
|
||||||
tcn.set("hardware-id-reset", true);
|
tcn.set("hardware-id-reset", true);
|
||||||
tcn.set("disabled", false);
|
tcn.set("disabled", false);
|
||||||
|
tcn.set("discord_id", 631459372576407593L);
|
||||||
|
|
||||||
UserHandler.users.add(tcn);
|
UserHandler.users.add(tcn);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +84,7 @@ public class Main {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
System.out.println("Indexing...");
|
System.out.println("Indexing Jar...");
|
||||||
classes = new HashMap<>();
|
classes = new HashMap<>();
|
||||||
ZipInputStream jar = new ZipInputStream(new FileInputStream("BaseBand-Broadway.jar"));
|
ZipInputStream jar = new ZipInputStream(new FileInputStream("BaseBand-Broadway.jar"));
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
|
@ -92,6 +94,12 @@ public class Main {
|
||||||
System.out.println(entry.getName() + ": " + bytes.length);
|
System.out.println(entry.getName() + ": " + bytes.length);
|
||||||
jar.closeEntry();
|
jar.closeEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("Enabling Service Handler for Remote Actioning...");
|
||||||
|
Server botServiceServer = new Server(40001);
|
||||||
|
botServiceServer.addHandler(new BotServiceHandler());
|
||||||
|
botServiceServer.run();
|
||||||
System.out.println("Listening!");
|
System.out.println("Listening!");
|
||||||
|
|
||||||
ServerSocket server = new ServerSocket(40000);
|
ServerSocket server = new ServerSocket(40000);
|
||||||
|
@ -109,9 +117,7 @@ public class Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
//WebServices
|
//WebServices
|
||||||
//Server webServiceServer = new Server(40001);
|
|
||||||
//webServiceServer.addHandler(new WebServiceHandler());
|
|
||||||
//webServiceServer.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.baseband.server;
|
|
||||||
|
|
||||||
import de.tudbut.net.ws.Connection;
|
|
||||||
import de.tudbut.net.ws.ConnectionHandler;
|
|
||||||
|
|
||||||
public class WebServiceHandler implements ConnectionHandler {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run(Connection connection) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,4 +3,5 @@ include 'Loader'
|
||||||
include 'Installer'
|
include 'Installer'
|
||||||
include 'Client'
|
include 'Client'
|
||||||
include 'Server'
|
include 'Server'
|
||||||
|
include 'Discord'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue