Some updates in the toggleRole manager

This commit is contained in:
Joel 2021-02-24 20:04:20 +01:00
parent ba40c09981
commit e0d93fba8b
3 changed files with 14 additions and 1 deletions

@ -7,6 +7,8 @@ import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus; import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.requests.GatewayIntent;
import zone.themcgamer.data.mysql.MySQLConstants;
import zone.themcgamer.data.mysql.MySQLController;
import zone.themcgamer.discordbot.command.impl.*; import zone.themcgamer.discordbot.command.impl.*;
import zone.themcgamer.discordbot.events.GuildsListener; import zone.themcgamer.discordbot.events.GuildsListener;
import zone.themcgamer.discordbot.events.MainGuildListener; import zone.themcgamer.discordbot.events.MainGuildListener;

@ -6,6 +6,7 @@ import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent; import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import zone.themcgamer.common.TimeUtils;
import zone.themcgamer.discordbot.BotConstants; import zone.themcgamer.discordbot.BotConstants;
import zone.themcgamer.discordbot.MGZBot; import zone.themcgamer.discordbot.MGZBot;
import zone.themcgamer.discordbot.utilities.EmbedUtils; import zone.themcgamer.discordbot.utilities.EmbedUtils;
@ -15,6 +16,7 @@ import javax.annotation.Nonnull;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
import static zone.themcgamer.discordbot.utilities.GuildUtils.toggleRole; import static zone.themcgamer.discordbot.utilities.GuildUtils.toggleRole;
@ -90,11 +92,11 @@ public class MainGuildListener extends ListenerAdapter {
MessageReaction.ReactionEmote reactionEmote = event.getReactionEmote(); MessageReaction.ReactionEmote reactionEmote = event.getReactionEmote();
for (Map.Entry<String, Long> entry : reactionRoles.entrySet()) { for (Map.Entry<String, Long> entry : reactionRoles.entrySet()) {
if (reactionEmote.getName().equals(entry.getKey())) { if (reactionEmote.getName().equals(entry.getKey())) {
event.getReaction().removeReaction(member.getUser()).queue();
Role role = guild.getRoleById(entry.getValue()); Role role = guild.getRoleById(entry.getValue());
if (role == null) if (role == null)
continue; continue;
toggleRole(guild, member, role); toggleRole(guild, member, role);
event.getReaction().removeReaction(member.getUser()).queue();
} }
} }
} }

@ -8,6 +8,8 @@ import zone.themcgamer.discordbot.BotConstants;
import zone.themcgamer.discordbot.MGZBot; import zone.themcgamer.discordbot.MGZBot;
import zone.themcgamer.discordbot.guild.Guild; import zone.themcgamer.discordbot.guild.Guild;
import java.util.concurrent.TimeUnit;
/** /**
* @author Nicholas * @author Nicholas
*/ */
@ -37,6 +39,13 @@ public class GuildUtils {
member.getUser().openPrivateChannel().queue(privateChannel -> { 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("Succesfully toggled " + role.getName() + " " + (!member.getRoles().contains(role) ? "On" : "Off")).build()).queue();
}, error -> { }, error -> {
EmbedBuilder embedBuilder = EmbedUtils.successEmbed();
embedBuilder.setTitle("Role Manager");
embedBuilder.setDescription("Succesfully toggled " + role.getName() + " " + (!member.getRoles().contains(role) ? "On" : "Off"));
TextChannel textChannelById = guild.getTextChannelById(813139125195898880L);
if (textChannelById == null)
return;
textChannelById.sendMessage(embedBuilder.build()).queue(message -> message.delete().queueAfter(2, TimeUnit.SECONDS));
}); });
TextChannel textChannelById = MGZBot.getInstance().getJda().getTextChannelById(BotConstants.HAROLD_LOG); TextChannel textChannelById = MGZBot.getInstance().getJda().getTextChannelById(BotConstants.HAROLD_LOG);