Skip to content

Commit

Permalink
5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen1212055 committed Apr 16, 2024
1 parent f22a43f commit 8783ab4
Show file tree
Hide file tree
Showing 57 changed files with 242 additions and 259 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ repositories {
}

dependencies {
implementation("net.dv8tion:JDA:4.4.0_350") {
implementation ("net.dv8tion:JDA:5.0.0-beta.20") {
exclude(module = "opus-java")
}

implementation("club.minnced:discord-webhooks:0.5.8")
implementation("ch.qos.logback:logback-classic:1.2.5")
implementation("com.google.code.gson:gson:2.8.6")
implementation("com.github.Steveice10:MCProtocolLib:c5e4b66")
implementation ("com.github.Steveice10:MCProtocolLib:c5e4b66")
implementation("mysql:mysql-connector-java:5.1.13")
implementation("org.codehaus.groovy:groovy-jsr223:3.0.8")
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public static void initialize() throws LoginException {
new SearchCommand(),
new TagsCommand(),
// others
new CowsayCommand(),
//new CowsayCommand(),
new MimicCommand(),
new FetchDataCommand(),
//new FetchDataCommand(),
new InfoCommand(),
new EvalCommand(),
new GarfieldCommand(),
//new GarfieldCommand(),
new HelpCommand(),
new RestartCommand(),
new ActionDumpCommand(),
Expand All @@ -79,7 +79,7 @@ public static void initialize() throws LoginException {
new VerifyCommand(),
// new PollCommand(), - Unused
new IdeaCommand(),
new StoreCommand(),
// new StoreCommand(),
// new ChannelMuteCommand(), - not finished
// statsbot
new StatsCommand(),
Expand Down Expand Up @@ -134,7 +134,7 @@ public static void initialize() throws LoginException {
);

JDABuilder builder = JDABuilder.createDefault(config.getToken())
.enableIntents(GatewayIntent.GUILD_MEMBERS)
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.MESSAGE_CONTENT, GatewayIntent.DIRECT_MESSAGES, GatewayIntent.DIRECT_MESSAGE_REACTIONS)
.setStatus(OnlineStatus.ONLINE)
.setMemberCachePolicy(MemberCachePolicy.NONE)
.setActivity(Activity.watching("for " + getConfig().getPrefix() + "help"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import com.diamondfire.helpbot.sys.interaction.button.ButtonHandler;
import com.diamondfire.helpbot.util.*;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.interactions.components.Button;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.buttons.Button;

import java.util.*;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -46,26 +48,26 @@ public static void sendMultipleMessage(List<CodeObject> actions, TextChannel cha
for (Map.Entry<BasicReaction, CodeObject> reaction : referenceData.getEnum().getEmbedBuilder().generateDupeEmojis(actions).entrySet()) {
Button button = Button.secondary(reaction.getKey().toString(), reaction.getValue().getName());

buttons.add(button.withEmoji(Emoji.fromEmote(reaction.getKey().getEmote())));
buttons.add(button.withEmoji(Emoji.fromCustom(reaction.getKey().getEmote())));
buttonMap.put(button.getId(), reaction.getValue());
}
} else {
for (CodeObject data : actions) {
long emoji = data.getEnum().getEmoji();
Button button = Button.secondary(String.valueOf(data.getEnum().getEmoji()), data.getName());

buttons.add(button.withEmoji(Emoji.fromEmote(HelpBotInstance.getJda().getEmoteById(emoji))));
buttons.add(button.withEmoji(HelpBotInstance.getJda().getEmojiById(emoji)));
buttonMap.put(button.getId(), data);
}
}

channel.sendMessageEmbeds(preset.getEmbed().build()).setActionRows(Util.of(buttons)).queue((message) -> {
channel.sendMessageEmbeds(preset.getEmbed().build()).setActionRow(buttons).queue((message) -> {
ButtonHandler.addListener(userToWait, message, (event) -> {
message.delete().queue();

// when msg is deleted causes nullpointer when tries to remove reactions! FIX
CodeObject object = buttonMap.get(event.getComponentId());
onChosen.accept(object, message.getTextChannel());
onChosen.accept(object, message.getChannel().asTextChannel());
});
});

Expand Down Expand Up @@ -118,9 +120,9 @@ protected void getData(CommandEvent event, BiConsumer<CodeObject, TextChannel> o

// If none, proceed. Else we need to special case that.
if (sameActions.size() == 1) {
onChosen.accept(sameActions.get(0), event.getChannel());
onChosen.accept(sameActions.get(0), event.getChannel().asTextChannel());
} else if (sameActions.size() > 1) {
sendMultipleMessage(sameActions, event.getChannel(), event.getMember().getIdLong(), onChosen);
sendMultipleMessage(sameActions, event.getChannel().asTextChannel(), event.getMember().getIdLong(), onChosen);
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject;
import com.diamondfire.helpbot.util.Util;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.FileUpload;

import java.io.File;
import java.util.function.BiConsumer;
Expand All @@ -21,7 +22,7 @@ public static <T extends CodeObject> void sendHelpMessage(T data, TextChannel ch
if (customHead == null) {
File actionIcon = Util.fetchMinecraftTextureFile(data.getItem().getMaterial().toUpperCase());
builder.setThumbnail("attachment://" + actionIcon.getName());
channel.sendMessageEmbeds(builder.build()).addFile(actionIcon).queue();
channel.sendMessageEmbeds(builder.build()).addFiles(FileUpload.fromData(actionIcon)).queue();
} else {
builder.setThumbnail(customHead);
channel.sendMessageEmbeds(builder.build()).queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject;
import com.diamondfire.helpbot.util.StringUtil;
import com.google.gson.*;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;

import java.util.function.BiConsumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.*;
import com.diamondfire.helpbot.util.Util;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.FileUpload;

import java.io.File;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -52,7 +53,7 @@ private static void sendTagMessage(CodeObject data, TextChannel channel) {
if (customHead == null) {
File actionIcon = Util.fetchMinecraftTextureFile(data.getItem().getMaterial().toUpperCase());
builder.setThumbnail("attachment://" + actionIcon.getName());
channel.sendMessageEmbeds(builder.build()).addFile(actionIcon).queue();
channel.sendMessageEmbeds(builder.build()).addFiles(FileUpload.fromData(actionIcon)).queue();
} else {
builder.setThumbnail(customHead);
channel.sendMessageEmbeds(builder.build()).queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,15 @@
import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase;
import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil;
import com.diamondfire.helpbot.sys.externalfile.ExternalFiles;
import com.diamondfire.helpbot.util.PlainComponentSerializer;
import com.github.steveice10.mc.auth.exception.request.RequestException;
import com.github.steveice10.mc.auth.service.AuthenticationService;
import com.github.steveice10.mc.protocol.MinecraftProtocol;
import com.github.steveice10.mc.protocol.data.game.MessageType;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.tcp.TcpClientSession;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.FileUpload;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.CompletableFuture;


Expand Down Expand Up @@ -74,7 +61,7 @@ public Permission getPermission() {
public void run(CommandEvent event) {
List<String> flags = event.getArgument("flag");
if (flags == null) {
setup(event.getChannel());
setup(event.getChannel().asTextChannel());
} else {
boolean includeColors = false;
boolean updateDb = true;
Expand All @@ -85,7 +72,7 @@ public void run(CommandEvent event) {
updateDb = false;
}
}
setup(event.getChannel(), includeColors, updateDb);
setup(event.getChannel().asTextChannel(), includeColors, updateDb);
}
}

Expand All @@ -100,7 +87,6 @@ public void setup(TextChannel channel, boolean includeColors, boolean updateDb)
builder.setDescription("Please wait a moment!");

Message sentMessage = channel.sendMessageEmbeds(builder.build()).complete();

fetchData(sentMessage, includeColors).thenAccept((queue) -> {
status(sentMessage, String.format("Data has been received, parsing %s lines...", queue.size()));

Expand Down Expand Up @@ -134,7 +120,7 @@ public void setup(TextChannel channel, boolean includeColors, boolean updateDb)
status(sentMessage, "Finished!");
} else {
status(sentMessage, "Finished!");
sentMessage.getChannel().sendFile(file).queue();
sentMessage.getChannel().sendFiles(FileUpload.fromData(file)).queue();
}
}).exceptionally((exception) -> {
error(sentMessage, exception);
Expand All @@ -145,77 +131,69 @@ public void setup(TextChannel channel, boolean includeColors, boolean updateDb)

private CompletableFuture<List<String>> fetchData(Message message, boolean includeColors) {
CompletableFuture<List<String>> completableFuture = new CompletableFuture<>();

AuthenticationService authService = new AuthenticationService();
authService.setUsername(USERNAME);
authService.setPassword(PASSWORD);
try {
authService.login();
} catch (RequestException e) {
e.printStackTrace();
}

MinecraftProtocol protocol = new MinecraftProtocol(authService.getSelectedProfile(), authService.getAccessToken());
TcpClientSession client = new TcpClientSession("beta.mcdiamondfire.com", 25565, protocol);

status(message, "Connecting to DiamondFire...");

client.connect();

client.addListener(new SessionAdapter() {

boolean ready = false;
List<String> queue = new ArrayList<>();

@Override
public void packetReceived(PacketReceivedEvent event) {
Packet packet = event.getPacket();

if (packet instanceof ServerJoinGamePacket) {
status(message, "Joined server!");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
event.getSession().send(new ClientChatPacket("/chat none"));
event.getSession().send(new ClientChatPacket(includeColors ? "/dumpactioninfo -c" : "/dumpactioninfo"));
}

if (packet instanceof ServerChatPacket) {
ServerChatPacket chatPacket = event.getPacket();
String text = PlainComponentSerializer.INSTANCE.serialize(chatPacket.getMessage());

if (chatPacket.getType() == MessageType.NOTIFICATION) return;

if (text.contains("Unknown command!")) {
completableFuture.completeExceptionally(new IllegalStateException("Command not found!"));
}

if (text.startsWith("{")) {
status(message, "Receiving data...");
ready = true;
} else if (text.startsWith("}")) {
client.disconnect("HelpBot data collection has concluded. ");

if (queue.isEmpty()) {
completableFuture.completeExceptionally(new IllegalStateException("Failed to retrieve data"));
return;
}

queue.add("}");
completableFuture.complete(queue);
return;
}

if (ready) {
queue.add(new String(text.getBytes(StandardCharsets.UTF_8)));
}

}
}
});


// System.out.println("Logging in...");
//
//
//
// TcpClientSession client = new TcpClientSession("beta.mcdiamondfire.com", 25565, new MinecraftProtocol(MinecraftCodec.CODEC, auth.getSelectedProfile(), auth.getAccessToken()));
//
// status(message, "Connecting to DiamondFire...");
//
// client.connect();
//
// client.addListener(new SessionAdapter() {
//
// boolean ready = false;
// List<String> queue = new ArrayList<>();
//
// @Override
// public void packetReceived(Session session, Packet packet) {
// if (packet instanceof ClientboundLoginPacket) {
// status(message, "Joined server!");
// try {
// Thread.sleep(2000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// session.send(new ServerboundChatCommandPacket("/chat none", System.currentTimeMillis(), System.currentTimeMillis(), List.of(), 0, new BitSet()));
// session.send(new ServerboundChatCommandPacket(includeColors ? "/dumpactioninfo -c" : "/dumpactioninfo", System.currentTimeMillis(), System.currentTimeMillis(), List.of(), 0, new BitSet()));
// }
//
// if (packet instanceof ClientboundSystemChatPacket chatPacket) {
// String text = PlainComponentSerializer.INSTANCE.serialize(chatPacket.getContent());
//
// if (chatPacket.isOverlay()) return;
//
// if (text.contains("Unknown command!")) {
// completableFuture.completeExceptionally(new IllegalStateException("Command not found!"));
// }
//
// if (text.startsWith("{")) {
// status(message, "Receiving data...");
// ready = true;
// } else if (text.startsWith("}")) {
// client.disconnect("HelpBot data collection has concluded. ");
//
// if (queue.isEmpty()) {
// completableFuture.completeExceptionally(new IllegalStateException("Failed to retrieve data"));
// return;
// }
//
// queue.add("}");
// completableFuture.complete(queue);
// return;
// }
//
// if (ready) {
// queue.add(new String(text.getBytes(StandardCharsets.UTF_8)));
// }
//
// }
// }
//
// });

return completableFuture;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.diamondfire.helpbot.bot.command.permissions.Permission;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import com.diamondfire.helpbot.sys.externalfile.ExternalFiles;
import net.dv8tion.jda.api.utils.FileUpload;

public class ActionDumpCommand extends Command {

Expand Down Expand Up @@ -33,7 +34,7 @@ public Permission getPermission() {

@Override
public void run(CommandEvent event) {
event.getChannel().sendFile(ExternalFiles.DB).queue();
event.getChannel().sendFiles(FileUpload.fromData(ExternalFiles.DB)).queue();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.diamondfire.helpbot.bot.events.CommandEvent;
import com.diamondfire.helpbot.sys.externalfile.ExternalFiles;
import com.diamondfire.helpbot.util.IOUtil;
import net.dv8tion.jda.api.utils.FileUpload;

import java.io.*;

Expand Down Expand Up @@ -44,7 +45,7 @@ public void run(CommandEvent event) {
event.getReplyHandler().replyA(builder).queue((msg) -> {
try {
File zip = IOUtil.zipFile(images.toPath(), "images.zip");
event.getChannel().sendFile(zip).queue((fileMsg) -> {
event.getChannel().sendFiles(FileUpload.fromData(zip)).queue((fileMsg) -> {
msg.delete().queue();
});
} catch (IOException e) {
Expand Down
Loading

0 comments on commit 8783ab4

Please sign in to comment.