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