Eliminated guild identifiers from BotConstants as they are now stored in the actual Guild enum.

This commit is contained in:
Nicholas Rees 2021-05-01 01:43:31 -05:00
parent 8ceb57aee1
commit d19afbb5be
6 changed files with 32 additions and 37 deletions

@ -12,14 +12,8 @@ public class BotConstants {
public static final String OWNER_ID = "504069946528104471"; // Joel
public static final String[] BOT_ADMINS = new String[] {
"758733013579595836", // Nicholas
"504147739131641857" // Braydon
};
// Guilds
public static final String MAIN_GUILD_ID = "764609803459756093";
public static final String TEAM_GUILD_ID = "796582717956423760";
public static final String TEST_GUILD_ID = "811044415211700234";
// Default Lines
public static final String COPYRIGHT = "© McGamerZone - " + Calendar.getInstance().get(Calendar.YEAR);

@ -19,7 +19,7 @@ public abstract class BaseCommand extends Command {
@Override
protected void execute(CommandEvent event) {
if (!guilds.contains(GuildUtils.getGuildFromId(event.getGuild().getId())))
if (!guilds.contains(GuildUtils.matchGuild(event.getGuild().getId())))
return;
List<String> args = new ArrayList<>();
if (event.getArgs() != null && event.getArgs().length() > 0) {

@ -6,7 +6,6 @@ import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import zone.themcgamer.discordbot.BotConstants;
import zone.themcgamer.discordbot.MGZBot;
import zone.themcgamer.discordbot.utilities.EmbedUtils;
import zone.themcgamer.discordbot.utilities.GuildUtils;
@ -36,10 +35,8 @@ public class MainGuildListener extends ListenerAdapter {
Guild guild = event.getGuild();
if (user.isBot())
return;
if (!guild.getId().equals(BotConstants.MAIN_GUILD_ID))
if (!guild.getId().equals(zone.themcgamer.discordbot.guild.Guild.MAIN.getGuildId()))
return;
Role memberRole = guild.getRoleById(793672609395900446L);
GuildUtils.toggleRole(guild, member, memberRole);
Role newsRole = guild.getRoleById(812440883898875914L);
@ -52,12 +49,14 @@ public class MainGuildListener extends ListenerAdapter {
user.openPrivateChannel().queue(privateChannel -> {
EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed();
embedBuilder.setThumbnail(mgzBot.getJda().getSelfUser().getAvatarUrl());
embedBuilder.setDescription("Welcome to **McGamerZone**! You have have the default roles applied your account.\nYou can toggle them in #roles channel!");
embedBuilder.setDescription("Welcome to **McGamerZone**! The default roles have been applied to your account, " +
"and you can toggle them at any time in the <#813139125195898880> channel!");
privateChannel.sendMessage(embedBuilder.build()).queue();
}, error -> {
TextChannel textChannelById = guild.getTextChannelById(767396615299923998L);
if (textChannelById != null)
textChannelById.sendMessage(user.getAsMention() + ", I could not sent a message to you due you have private messages disabled!").queue();
textChannelById.sendMessage(user.getAsMention() + ", I could not send you a message due to you having " +
"private messages disabled!").queue();
});
TextChannel textChannelById = guild.getTextChannelById(812453030405996564L);
@ -65,13 +64,13 @@ public class MainGuildListener extends ListenerAdapter {
return;
EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed();
embedBuilder.setTitle("Welcome to McGamerZone, " + user.getAsTag());
embedBuilder.setTitle("Welcome to McGamerZone, " + user.getAsTag() + "!");
embedBuilder.setThumbnail(user.getAvatarUrl());
embedBuilder.setDescription("This is the official Discord server for McGamerZone Minecraft server." +
" We are a fun Server that is focused on creativity, community-building, and keeping to the" +
" core of the game itself. Our goal here; is to maintain a friendly, fun, " +
"and equal community for anyone and everyone that joins in and " +
"give the og players of MGZ the nostalgia feeling back!");
embedBuilder.setDescription("This is the official Discord server for the McGamerZone Minecraft server network." +
" We are a fun server that is focused on creativity, community-building, and keeping to the" +
" core of the game itself. Our goal is to maintain a friendly, fun, " +
"and equal community for anyone and everyone that joins in, and to " +
"give the OG players of MGZ that nostalgia feeling back!");
embedBuilder.setTimestamp(event.getMember().getTimeJoined());
embedBuilder.setFooter("Joined at » ");
textChannelById.sendMessage(user.getAsMention()).queue(message -> message.delete().queue());
@ -86,9 +85,8 @@ public class MainGuildListener extends ListenerAdapter {
Member member = event.getMember();
if (event.getUser().isBot())
return;
if (!guild.getId().equals(BotConstants.MAIN_GUILD_ID))
if (!guild.getId().equals(zone.themcgamer.discordbot.guild.Guild.MAIN.getGuildId()))
return;
if (event.getChannel().getId().equals("813139125195898880") && event.getMessageId().equals("813143359249842186")) {
MessageReaction.ReactionEmote reactionEmote = event.getReactionEmote();
for (Map.Entry<String, Long> entry : reactionRoles.entrySet()) {
@ -102,4 +100,4 @@ public class MainGuildListener extends ListenerAdapter {
}
}
}
}
}

@ -1,8 +1,16 @@
package zone.themcgamer.discordbot.guild;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author Nicholas
*/
@AllArgsConstructor @Getter
public enum Guild {
MAIN, TEAM, TEST
MAIN("764609803459756093"),
TEAM("796582717956423760"),
TEST("811044415211700234");
private final String guildId;
}

@ -4,26 +4,18 @@ import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel;
import zone.themcgamer.discordbot.BotConstants;
import zone.themcgamer.discordbot.MGZBot;
import zone.themcgamer.discordbot.guild.Guild;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
/**
* @author Nicholas
*/
public class GuildUtils {
public static Guild getGuildFromId(String id) {
switch (id) {
case BotConstants.MAIN_GUILD_ID:
return Guild.MAIN;
case BotConstants.TEAM_GUILD_ID:
return Guild.TEAM;
case BotConstants.TEST_GUILD_ID:
return Guild.TEST;
}
return null;
public static Guild matchGuild(String guildId) {
return Arrays.stream(Guild.values()).filter(guild -> guild.getGuildId().equals(guildId)).findFirst().orElse(null);
}
public static void toggleRole(net.dv8tion.jda.api.entities.Guild guild, Member member, Role role) {
@ -37,11 +29,13 @@ public class GuildUtils {
return;
member.getUser().openPrivateChannel().queue(privateChannel -> {
privateChannel.sendMessage(EmbedUtils.successEmbed().setDescription("Succesfully toggled " + role.getName() + " " + (!member.getRoles().contains(role) ? "On" : "Off")).build()).queue();
privateChannel.sendMessage(EmbedUtils.successEmbed().setDescription("Successfully toggled " + role.getName() +
" " + (!member.getRoles().contains(role) ? "On" : "Off")).build()).queue();
}, error -> {
EmbedBuilder embedBuilder = EmbedUtils.successEmbed();
embedBuilder.setTitle("Role Manager");
embedBuilder.setDescription("Successfully toggled " + role.getName() + " " + (!member.getRoles().contains(role) ? "On" : "Off"));
embedBuilder.setDescription("Successfully toggled " + role.getName() + " " +
(!member.getRoles().contains(role) ? "On" : "Off"));
TextChannel textChannelById = guild.getTextChannelById(813139125195898880L);
if (textChannelById == null)
return;

@ -30,7 +30,8 @@ public class MessageUtils {
if (logChannel == null) {
Objects.requireNonNull(MGZBot.getInstance().getJda().getUserById("504069946528104471"))
.openPrivateChannel().queue(privateChannel ->
privateChannel.sendMessage("There was an error while sending a log message, the channel id is invalid or does not exist.").queue());
privateChannel.sendMessage("There was an error while sending a log message, the channel id is " +
"invalid or does not exist.").queue());
return null;
}
return logChannel;