Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into fixes
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java
#	src/main/java/com/diamondfire/helpbot/sys/rolereact/RoleReactListener.java
  • Loading branch information
Reasonlesss committed Jul 3, 2024
2 parents 3584b1d + 9f4435c commit df4e9e8
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 32 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ build
/src/main/resources/swear_filter.json

*.json
*.png
*.txt
3 changes: 0 additions & 3 deletions src/main/java/com/diamondfire/helpbot/HelpBot.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.diamondfire.helpbot;


import com.diamondfire.helpbot.bot.HelpBotInstance;
import com.diamondfire.helpbot.df.codeinfo.codedatabase.changelog.CodeDifferenceHandler;
import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase;
import com.diamondfire.helpbot.sys.tag.TagHandler;

import javax.security.auth.login.LoginException;
import java.io.IOException;

public class HelpBot {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public void enable(Command command) {
}

public void disable(Command command) {
if (command == null) {
return;
}
// Prevents tricky people using eval.
if (command instanceof CommandDisableFlag) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.diamondfire.helpbot.util.*;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.interactions.components.buttons.Button;

Expand All @@ -24,7 +25,7 @@

public abstract class AbstractSingleQueryCommand extends Command {

public static void sendMultipleMessage(List<CodeObject> actions, TextChannel channel, long userToWait, BiConsumer<CodeObject, TextChannel> onChosen) {
public static void sendMultipleMessage(List<CodeObject> actions, GuildMessageChannel channel, long userToWait, BiConsumer<CodeObject, GuildMessageChannel> onChosen) {
// This here is to determine if all the duplicate types are the same. If not, we need to make sure that we filter those out first..
CodeObject referenceData = actions.get(0);
Class<? extends CodeObject> classReference = referenceData.getClass();
Expand Down Expand Up @@ -67,7 +68,7 @@ public static void sendMultipleMessage(List<CodeObject> actions, TextChannel cha

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

Expand All @@ -85,9 +86,9 @@ public void run(CommandEvent event) {
getData(event, onDataReceived());
}

public abstract BiConsumer<CodeObject, TextChannel> onDataReceived();
public abstract BiConsumer<CodeObject, GuildMessageChannel> onDataReceived();

protected void getData(CommandEvent event, BiConsumer<CodeObject, TextChannel> onChosen) {
protected void getData(CommandEvent event, BiConsumer<CodeObject, GuildMessageChannel> onChosen) {
String name = event.getArgument("name");
PresetBuilder preset = new PresetBuilder();

Expand Down Expand Up @@ -120,9 +121,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().asTextChannel());
onChosen.accept(sameActions.get(0), event.getChannel().asGuildMessageChannel());
} else if (sameActions.size() > 1) {
sendMultipleMessage(sameActions, event.getChannel().asTextChannel(), event.getMember().getIdLong(), onChosen);
sendMultipleMessage(sameActions, event.getChannel().asGuildMessageChannel(), event.getMember().getIdLong(), onChosen);
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.diamondfire.helpbot.util.Util;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.utils.FileUpload;

import java.io.File;
Expand All @@ -15,7 +16,7 @@

public class CodeCommand extends AbstractSingleQueryCommand {

public static <T extends CodeObject> void sendHelpMessage(T data, TextChannel channel) {
public static <T extends CodeObject> void sendHelpMessage(T data, GuildMessageChannel channel) {
EmbedBuilder builder = data.getEnum().getEmbedBuilder().generateEmbed(data);
String customHead = data.getItem().getHead();

Expand Down Expand Up @@ -57,7 +58,7 @@ public void run(CommandEvent event) {
}

@Override
public BiConsumer<CodeObject, TextChannel> onDataReceived() {
public BiConsumer<CodeObject, GuildMessageChannel> onDataReceived() {
return CodeCommand::sendHelpMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import com.diamondfire.helpbot.util.StringUtil;
import com.google.gson.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;

import java.util.function.BiConsumer;


public class RawCommand extends AbstractSingleQueryCommand {

private static void sendRawMessage(CodeObject data, TextChannel channel) {
private static void sendRawMessage(CodeObject data, GuildMessageChannel channel) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(data.getJson());

Expand Down Expand Up @@ -55,7 +56,7 @@ public void run(CommandEvent event) {
}

@Override
public BiConsumer<CodeObject, TextChannel> onDataReceived() {
public BiConsumer<CodeObject, GuildMessageChannel> onDataReceived() {
return RawCommand::sendRawMessage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.diamondfire.helpbot.util.Util;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.utils.FileUpload;

import java.io.File;
Expand All @@ -15,7 +16,7 @@

public class TagsCommand extends AbstractSingleQueryCommand {

private static void sendTagMessage(CodeObject data, TextChannel channel) {
private static void sendTagMessage(CodeObject data, GuildMessageChannel channel) {
EmbedBuilder builder = new EmbedBuilder();
ActionData actionData;

Expand Down Expand Up @@ -92,7 +93,7 @@ public void run(CommandEvent event) {
}

@Override
public BiConsumer<CodeObject, TextChannel> onDataReceived() {
public BiConsumer<CodeObject, GuildMessageChannel> onDataReceived() {
return TagsCommand::sendTagMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@
import javax.script.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;


public class EvalCommand extends Command {

// Moderators can just give themselves bot dev role apparently...
private static final Set<Long> BOT_DEVELOPERS = Set.of(
511653192942092289L, // Reasonless
248855041803288576L, // Tomoli75
945012492030074900L // Owen1212055
);

private static final List<String> IMPORTS = List.of(
"net.dv8tion.jda.core",
"net.dv8tion.jda.core.managers",
Expand Down Expand Up @@ -68,6 +76,17 @@ public void run(CommandEvent event) {
return;
}

boolean hasManual = BOT_DEVELOPERS.contains(event.getMember().getIdLong());
boolean hasRole = Permission.DEVELOPER.hasPermission(event.getMember());
if (!hasManual && !hasRole) {
EmbedBuilder builder = new EmbedBuilder();
builder.setTitle("No.");
builder.setColor(Color.red);

event.getChannel().sendMessageEmbeds(builder.build()).queue();
return;
}


ScriptEngine engine = new ScriptEngineManager().getEngineByName("groovy");
engine.put("jda", event.getJDA());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.utils.FileUpload;

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

public void setup(TextChannel channel) {
public void setup(GuildMessageChannel channel) {
setup(channel, false, true);
}

public void setup(TextChannel channel, boolean includeColors, boolean updateDb) {
public void setup(GuildMessageChannel channel, boolean includeColors, boolean updateDb) {
EmbedBuilder builder = new EmbedBuilder();

builder.setTitle("Fetching Code Database...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.utils.FileUpload;

import java.awt.*;
Expand Down Expand Up @@ -44,7 +45,7 @@ public Permission getPermission() {

@Override
public void run(CommandEvent event) {
TextChannel channel = event.getChannel().asTextChannel();
GuildMessageChannel channel = event.getChannel().asGuildMessageChannel();
PresetBuilder attachNbsMsg = new PresetBuilder().withPreset(new InformativeReply(InformativeReplyType.ERROR,"You need to attach an nbs file!"));
PresetBuilder errorMsg = new PresetBuilder().withPreset(new InformativeReply(InformativeReplyType.ERROR,"Something went wrong while generating!"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.utils.FileUpload;

import java.io.File;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void run(CommandEvent event) {
);
event.reply(builder);
} else {
TextChannel channel = event.getChannel().asTextChannel();
GuildMessageChannel channel = event.getChannel().asGuildMessageChannel();
channel.getHistory().retrievePast(messagesToRemove).queue((messages) -> {
// Adds the messages to the messageBuilder object
StringBuilder stringBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.util.stream.Collectors;

public enum Permission {
BOT_DEVELOPER(999),
DEVELOPER(999),
BOT_DEVELOPER(998),
// Ask DragonSlasher, not me.
ADMINISTRATOR(666),
MODERATION(5),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
import net.dv8tion.jda.api.utils.messages.MessageRequest;

public class ReplyHandler {

private final TextChannel channel;
private final GuildMessageChannel channel;

public ReplyHandler(TextChannel channel) {
public ReplyHandler(GuildMessageChannel channel) {
this.channel = channel;
}

public TextChannel getChannel() {
public GuildMessageChannel getChannel() {
return channel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class CommandEvent extends MessageReceivedEvent {

private Command command;
private final ReplyHandler replyHandler = new ReplyHandler(getChannel().asTextChannel());
private final ReplyHandler replyHandler = new ReplyHandler(getChannel().asGuildMessageChannel());
//TODO Cleanup and refactor this.
// I'd like to see stuff like replying be put into it's whole own section and refactored as well.
private ParsedArgumentSet parsedArgumentSet = null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public enum Rank {
this.rankName = rankName;
this.number = number;
this.category = category;
this.emote = HelpBotInstance.getJda().getGuildById(615846886414483465L).getEmojisByName(emote, true).get(0);
this.emote = HelpBotInstance.getJda().getGuildById(615846886414483465L).getEmojisByName(emote, false).get(0);
}

public String getRankName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public interface ExternalFiles {
.setFileType("json")
.buildFile();

File VIP_ROLES = new ExternalFileBuilder()
.isDirectory(false)
.setName("vip_roles")
.setFileType("json")
.buildFile();

File SAM_QUOTES = new ExternalFileBuilder()
.isDirectory(false)
.setName("samquotes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public boolean accept(Message message) {
try {
// Get Tag and send response
TagHandler.getTag(parsedText)
.sendResponse(message.getChannel().asTextChannel(), message.getAuthor());
.sendResponse(message.getChannel().asGuildMessageChannel(), message.getAuthor());

} catch (TagDoesNotExistException | IOException ignored) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public RoleReactListener() {
}

msg.editMessage("__**Reaction Roles**__ \nClick to add/remove roles from yourself")
.setComponents(Util.of(buttons)).queue();
.setComponents(Util.of(buttons))
.queue();
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void setImage(String image) {
this.image = image;
}

public void sendResponse(TextChannel channel, @NotNull User requester) {
public void sendResponse(GuildMessageChannel channel, @NotNull User requester) {

EmbedBuilder embed = new EmbedBuilder()
.setTitle(getTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public void initialize() {
new GraphChannelTask(),
//new RefreshCreditsTask(),
new SupporterClassTask(),
new NameUpdateTask()
new NameUpdateTask(),
new VIPStarTask()
);

SupportUnexcuseTask.prepare();
Expand Down
Loading

0 comments on commit df4e9e8

Please sign in to comment.