bot works now
Some checks failed
/ Build BaseBand Server (push) Failing after 4m11s

This commit is contained in:
Daniella / Tove 2024-06-10 18:17:54 +02:00
parent 20635084f8
commit 8371ae8216
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
5 changed files with 37 additions and 29 deletions

View file

@ -4,6 +4,7 @@ on:
paths: paths:
- ".forgejo/workflows/build-server.yml" - ".forgejo/workflows/build-server.yml"
- "Server/**" - "Server/**"
- "Discord/**"
jobs: jobs:
@ -23,15 +24,17 @@ jobs:
- name: Initialize Gradle - name: Initialize Gradle
uses: https://github.com/gradle/actions/setup-gradle@v3 uses: https://github.com/gradle/actions/setup-gradle@v3
- name: Build - name: Build
run: | run: ./gradlew --no-daemon Server:build Discord:build
cd Server
../gradlew --no-daemon build
cd ..
- name: Upload Server - name: Upload Server
uses: forgejo/upload-artifact@v4 uses: forgejo/upload-artifact@v4
with: with:
name: BaseBand-Server.jar name: BaseBand-Server.jar
path: Server/build/libs/BaseBand-Server.jar path: Server/build/libs/BaseBand-Server.jar
- name: Upload Bot
uses: forgejo/upload-artifact@v4
with:
name: BaseBand-Discord.jar
path: Discord/build/libs/BaseBand-Discord.jar
- name: Release to server - name: Release to server
if: github.ref == 'refs/heads/release' if: github.ref == 'refs/heads/release'
env: env:
@ -40,4 +43,6 @@ jobs:
BB_HOST: ${{ vars.BB_HOST }} BB_HOST: ${{ vars.BB_HOST }}
BB_PORT: ${{ vars.BB_PORT }} BB_PORT: ${{ vars.BB_PORT }}
BB_PATH: ${{ vars.BB_PATH }} BB_PATH: ${{ vars.BB_PATH }}
run: bash push_file.sh Server/build/libs/BaseBand-Server.jar 3847 run: |
bash push_file.sh Server/build/libs/BaseBand-Server.jar
bash push_file.sh Discord/build/libs/BaseBand-Discord.jar

View file

@ -39,6 +39,8 @@ jar {
manifest.attributes( manifest.attributes(
'Main-Class': 'com.baseband.bot.Main', 'Main-Class': 'com.baseband.bot.Main',
) )
archiveFileName = "BaseBand-Discord.jar"
} }
test { test {

View file

@ -19,6 +19,7 @@ import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction; import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
import org.jetbrains.annotations.NotNull;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
@ -45,38 +46,39 @@ public class Main extends ListenerAdapter {
commands.addCommands( commands.addCommands(
Commands.slash("reset", "Reset HWID of a given user.") Commands.slash("reset", "Reset HWID of a given user.")
.addOptions(new OptionData(USER, "user", "The user who's HWID we should reset.") .addOptions(new OptionData(USER, "user", "The user who's HWID we should reset.")
.setRequired(true)).setGuildOnly(true) .setRequired(true))
.addOptions(new OptionData(STRING, "password", "The admin password.") .addOptions(new OptionData(STRING, "password", "The admin password.")
.setRequired(true)).setGuildOnly(true) .setRequired(true))
.setDefaultPermissions(DefaultMemberPermissions.DISABLED) .setGuildOnly(true)
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
); );
commands.addCommands( commands.addCommands(
Commands.slash("add", "Add a user.") Commands.slash("add", "Add a user.")
.addOptions(new OptionData(USER, "user", "The user who's HWID we should reset.") .addOptions(new OptionData(USER, "user", "The user who's HWID we should reset.")
.setRequired(true)).setGuildOnly(true) .setRequired(true))
.addOptions(new OptionData(STRING, "password", "The admin password.") .addOptions(new OptionData(STRING, "password", "The admin password.")
.setRequired(true)).setGuildOnly(true) .setRequired(true))
.addOptions(new OptionData(STRING, "username", "The username of the user to create.") .addOptions(new OptionData(STRING, "username", "The username of the user to create.")
.setRequired(true)).setGuildOnly(true) .setRequired(true))
.setGuildOnly(true)
.setDefaultPermissions(DefaultMemberPermissions.DISABLED) .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.")
.setRequired(true)).setGuildOnly(true) .setRequired(true))
.setDefaultPermissions(DefaultMemberPermissions.ENABLED) .setDefaultPermissions(DefaultMemberPermissions.ENABLED)
); );
commands.queue(); commands.complete();
System.out.println("INIT COMPLETE");
} }
@Override @Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
if (event.getGuild() == null)
return;
TypedInputStream tis; TypedInputStream tis;
TypedOutputStream tos; TypedOutputStream tos;
@ -100,7 +102,6 @@ public class Main extends ListenerAdapter {
tcn.set("action", "reset"); tcn.set("action", "reset");
tcn.set("authorisation", Hasher.sha512hex(password)); tcn.set("authorisation", Hasher.sha512hex(password));
tcn.set("discord-id", user.getIdLong()); tcn.set("discord-id", user.getIdLong());
event.reply("Contacting server...").setEphemeral(true).queue();
tos.writeString(tcn.toString()); tos.writeString(tcn.toString());
switch (tis.readInt()) { switch (tis.readInt()) {
@ -146,7 +147,6 @@ public class Main extends ListenerAdapter {
tcn.set("action", "add"); tcn.set("action", "add");
tcn.set("authorisation", Hasher.sha512hex(password)); tcn.set("authorisation", Hasher.sha512hex(password));
tcn.set("discord-id", user.getIdLong()); tcn.set("discord-id", user.getIdLong());
event.reply("Contacting server...").setEphemeral(true).queue();
tos.writeString(tcn.toString()); tos.writeString(tcn.toString());
switch (tis.readInt()) { switch (tis.readInt()) {
@ -192,7 +192,6 @@ public class Main extends ListenerAdapter {
tcn.set("authorisation", "1ee7a143df6e0d2f3d2b86b3e5c098c06a07d7c8eb01d629f51712b6bba3a468dc96ef9729d586007ca71383b1c203f6f996bdce3972772d0e5351364eba0d1e"); tcn.set("authorisation", "1ee7a143df6e0d2f3d2b86b3e5c098c06a07d7c8eb01d629f51712b6bba3a468dc96ef9729d586007ca71383b1c203f6f996bdce3972772d0e5351364eba0d1e");
tcn.set("password", password); tcn.set("password", password);
tcn.set("discord-id", user.getIdLong()); tcn.set("discord-id", user.getIdLong());
event.reply("Contacting server...").setEphemeral(true).queue();
tos.writeString(tcn.toString()); tos.writeString(tcn.toString());
switch (tis.readInt()) { switch (tis.readInt()) {

View file

@ -16,6 +16,7 @@ public class BotServiceHandler {
public static void handle(Socket connection) throws IOException { public static void handle(Socket connection) throws IOException {
TypedInputStream tis = new TypedInputStream(connection.getInputStream()); TypedInputStream tis = new TypedInputStream(connection.getInputStream());
TypedOutputStream tos = new TypedOutputStream(connection.getOutputStream()); TypedOutputStream tos = new TypedOutputStream(connection.getOutputStream());
String action = "UNINIT";
try { try {
TCN tcn = TCN.read(tis.readString()); TCN tcn = TCN.read(tis.readString());
@ -26,7 +27,7 @@ public class BotServiceHandler {
return; return;
} }
String action = tcn.getString("action"); action = tcn.getString("action");
System.out.println("Bot processing " + action); System.out.println("Bot processing " + action);
@ -68,12 +69,12 @@ public class BotServiceHandler {
TCN userToAdd = new TCN(); TCN userToAdd = new TCN();
tcn.set("username", username); userToAdd.set("username", username);
tcn.set("password", BCrypt.withDefaults().hashToString(4, new String(SecureRandom.getSeed(32), StandardCharsets.ISO_8859_1).toCharArray())); userToAdd.set("password", "");
tcn.set("hardware-id", Hasher.sha512hex(new String(SecureRandom.getSeed(512)))); userToAdd.set("hardware-id", "");
tcn.set("hardware-id-reset", true); userToAdd.set("hardware-id-reset", true);
tcn.set("disabled", false); userToAdd.set("disabled", false);
tcn.set("discord-id", discord_id); userToAdd.set("discord-id", discord_id);
TCN user = (TCN) UserHandler.users.stream() //checking if it already exists LOL TCN user = (TCN) UserHandler.users.stream() //checking if it already exists LOL
.filter( .filter(
@ -90,13 +91,14 @@ public class BotServiceHandler {
} }
} }
System.out.println("Bot processed " + action);
Main.save(); Main.save();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
tos.writeInt(400); tos.writeInt(400);
} }
finally { finally {
System.out.println("Bot processed " + action);
tos.getStream().close(); tos.getStream().close();
} }
} }

View file

@ -81,7 +81,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); tcn.set("discord-id", 0);
UserHandler.users.add(tcn); UserHandler.users.add(tcn);
} }