Simplified MainGuildListener#onGuildMessageReactionAdd

This commit is contained in:
Joel 2021-02-21 23:22:16 +01:00
parent df6576ad10
commit 549ca47d61

@ -13,12 +13,23 @@ import zone.themcgamer.discordbot.utilities.GuildUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
import static zone.themcgamer.discordbot.utilities.GuildUtils.toggleRole; import static zone.themcgamer.discordbot.utilities.GuildUtils.toggleRole;
@RequiredArgsConstructor @RequiredArgsConstructor
public class MainGuildListener extends ListenerAdapter { public class MainGuildListener extends ListenerAdapter {
private final MGZBot mgzBot; private final MGZBot mgzBot;
private static final HashMap<String, Long> reactionRoles = new HashMap<>();
static {
reactionRoles.put("🗞️", 812440883898875914L);
reactionRoles.put("📊", 813139198428839976L);
reactionRoles.put("🥁", 813140631705878549L);
}
@Override @Override
public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) { public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) {
Member member = event.getMember(); Member member = event.getMember();
@ -70,29 +81,20 @@ public class MainGuildListener extends ListenerAdapter {
public void onGuildMessageReactionAdd(@Nonnull GuildMessageReactionAddEvent event) { public void onGuildMessageReactionAdd(@Nonnull GuildMessageReactionAddEvent event) {
Guild guild = event.getGuild(); Guild guild = event.getGuild();
Member member = event.getMember(); Member member = event.getMember();
if (!guild.getId().equals(BotConstants.MAIN_GUILD_ID)) if (!guild.getId().equals(BotConstants.MAIN_GUILD_ID))
return; return;
if (event.getChannel().getId().equals("813139125195898880") && event.getMessageId().equals("813143359249842186")) { if (event.getChannel().getId().equals("813139125195898880") && event.getMessageId().equals("813143359249842186")) {
MessageReaction.ReactionEmote reactionEmote = event.getReactionEmote(); MessageReaction.ReactionEmote reactionEmote = event.getReactionEmote();
if (reactionEmote.getName().equals("🗞️")) { for (Map.Entry<String, Long> entry : reactionRoles.entrySet()) {
Role role = guild.getRoleById(812440883898875914L); // News role if (reactionEmote.getName().equals(entry.getKey())) {
Role role = guild.getRoleById(entry.getValue());
if (role == null) if (role == null)
return; continue;
toggleRole(guild, member, role); toggleRole(guild, member, role);
} else if (reactionEmote.getName().equals("📊")) {
Role role = guild.getRoleById(813139198428839976L); // Polls role
if (role == null)
return;
toggleRole(guild, member, role);
} else if (reactionEmote.getName().equals("🥁")) {
Role role = guild.getRoleById(813140631705878549L); // Events role
if (role == null)
return;
toggleRole(guild, member, role);
}
event.getReaction().removeReaction(member.getUser()).queue(); event.getReaction().removeReaction(member.getUser()).queue();
} }
} }
}
}
} }