Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIP Role Star #100

Merged
merged 13 commits into from
Jun 14, 2024
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 @@ -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 @@ -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).getEmojiById(emote);
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 @@ -35,7 +35,9 @@ public RoleReactListener() {
roleMap.put(button.getId(), role.getRoleID());
}

msg.editMessage("__**Reaction Roles**__ \nClick to add/remove roles from yourself").setActionRow(buttons).queue();
msg.editMessage("__**Reaction Roles**__ \nClick to add/remove roles from yourself")
.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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.diamondfire.helpbot.sys.tasks.impl;

import com.diamondfire.helpbot.bot.HelpBotInstance;
import com.diamondfire.helpbot.sys.tasks.LoopingTask;
import com.diamondfire.helpbot.sys.vip.VIPRoleHandler;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;

import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

public class VIPStarTask implements LoopingTask {

@Override
public long getInitialStart() {
return 0;
}

@Override
public long getNextLoop() {
return TimeUnit.MINUTES.toMillis(30L);
}

@Override
public void run() {
Guild guild = HelpBotInstance.getJda().getGuildById(HelpBotInstance.DF_GUILD);
Set<Long> vipIds = VIPRoleHandler.retrieveVIPs();

guild.loadMembers((member) -> {
Role role = VIPRoleHandler.getRole(member.getColorRaw());
if (role == null) {
return;
}
if (vipIds.contains(member.getIdLong()) && !member.getRoles().contains(role)) {
guild.addRoleToMember(member, role)
.reason("User has VIP Pass")
.queue();
return;
}
if (!vipIds.contains(member.getIdLong()) && member.getRoles().contains(role)) {
guild.removeRoleFromMember(member, role)
.reason("User's VIP Pass has expired")
.queue();
}
});

}

}
Loading
Loading