commit e96527b57f4f33a7308d1f1733b20ad400ae2294
parent e25d9a59e0d2047e7ad164a3a41cc71733a28e7e
Author: Wim Dupont <wim@wimdupont.com>
Date: Sun, 2 Jul 2023 10:26:44 +0200
added discord member check
Diffstat:
3 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/PvmRoleCheckListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/PvmRoleCheckListener.java
@@ -25,6 +25,7 @@ public class PvmRoleCheckListener implements Listener {
try {
PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true);
osrsMonitoringService.monitorPvmRoleUserHiscores(privateChannel);
+ osrsMonitoringService.monitorDiscordMembers(privateChannel);
} catch (RateLimitedException e) {
LOGGER.error(e.getMessage(), e);
}
diff --git a/src/main/java/com/wimdupont/sxcybot/services/OsrsMonitoringService.java b/src/main/java/com/wimdupont/sxcybot/services/OsrsMonitoringService.java
@@ -4,7 +4,9 @@ import com.wimdupont.sxcybot.client.HiScoreClient;
import com.wimdupont.sxcybot.exceptions.EntityNotFoundException;
import com.wimdupont.sxcybot.model.OsrsBossKc;
import com.wimdupont.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser;
+import com.wimdupont.sxcybot.services.guild.ChannelDetailService;
import com.wimdupont.sxcybot.services.guild.pvmrole.PvmRoleUserService;
+import com.wimdupont.sxcybot.util.JdaUtil;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.PrivateChannel;
import org.slf4j.Logger;
@@ -26,17 +28,20 @@ public class OsrsMonitoringService {
private final String monitorUserName;
private final String monitorBossName;
private final String monitorBossKc;
+ private final ChannelDetailService channelDetailService;
public OsrsMonitoringService(HiScoreClient hiScoreClient,
PvmRoleUserService pvmRoleUserService,
@Value("${monitor.user.name}") String monitorUserName,
@Value("${monitor.boss.name}") String monitorBossName,
- @Value("${monitor.boss.kc}") String monitorBossKc) {
+ @Value("${monitor.boss.kc}") String monitorBossKc,
+ ChannelDetailService channelDetailService) {
this.hiScoreClient = hiScoreClient;
this.pvmRoleUserService = pvmRoleUserService;
this.monitorUserName = monitorUserName;
this.monitorBossName = monitorBossName;
this.monitorBossKc = monitorBossKc;
+ this.channelDetailService = channelDetailService;
}
@Scheduled(cron = "${monitor.schedule}")
@@ -45,12 +50,25 @@ public class OsrsMonitoringService {
try {
monitorHiscores();
monitorPvmRoleUserHiscores(null);
+ monitorDiscordMembers(null);
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
}
+ public void monitorDiscordMembers(PrivateChannel privateChannel) {
+ List<PvmRoleUser> unfound = new ArrayList<>();
+ channelDetailService.getJda().getGuilds().forEach(guild ->
+ guild.loadMembers().onSuccess(memberlist -> {
+ pvmRoleUserService.findAll().stream()
+ .filter(pvmRoleUser -> JdaUtil.getNameById(memberlist, pvmRoleUser.getDiscordId()).isEmpty())
+ .forEach(unfound::add);
+ messageDiscordMemberResults(unfound, privateChannel);
+ })
+ );
+ }
+
public void monitorPvmRoleUserHiscores(PrivateChannel privateChannel) {
List<PvmRoleUser> unfound = new ArrayList<>();
for (PvmRoleUser pvmRoleUser : pvmRoleUserService.findAll()) {
@@ -60,10 +78,35 @@ public class OsrsMonitoringService {
unfound.add(pvmRoleUser);
}
}
- messageUnfoundResults(unfound, privateChannel);
+ messageHiScoreResults(unfound, privateChannel);
+ }
+
+ private void messageDiscordMemberResults(List<PvmRoleUser> unfound, PrivateChannel privateChannel) {
+ if (privateChannel == null) {
+ if (!unfound.isEmpty()) {
+ LOGGER.error("No Discord member found for: {}", unfound.stream()
+ .map(pvmRoleUser -> String.format("DiscordId: %s , Rsn: %s",
+ pvmRoleUser.getDiscordId(), pvmRoleUser.getRsn()))
+ .toList());
+ } else {
+ LOGGER.info("All PvM Role competitors have been found in discord.");
+ }
+ } else {
+ EmbedBuilder embedBuilder = new EmbedBuilder();
+ embedBuilder.setColor(Color.red);
+ embedBuilder.setTitle("PvM competitor Discord check");
+ if (!unfound.isEmpty()) {
+ embedBuilder.setDescription("No Discord Member found for following competitor RSN's:");
+ unfound.forEach(competitor ->
+ embedBuilder.addField(competitor.getRsn(), String.format("DiscordId: %s", competitor.getDiscordId()), true));
+ } else {
+ embedBuilder.setDescription("All PvM role competitors have been found in discord.");
+ }
+ privateChannel.sendMessageEmbeds(embedBuilder.build()).queue();
+ }
}
- private void messageUnfoundResults(List<PvmRoleUser> unfound, PrivateChannel privateChannel) {
+ private void messageHiScoreResults(List<PvmRoleUser> unfound, PrivateChannel privateChannel) {
if (privateChannel == null) {
if (!unfound.isEmpty()) {
LOGGER.error("No hiScores found for: {}", unfound.stream().map(PvmRoleUser::getRsn).toList());
@@ -73,7 +116,7 @@ public class OsrsMonitoringService {
} else {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Color.red);
- embedBuilder.setTitle("PvM competitor check");
+ embedBuilder.setTitle("PvM competitor Hiscore check");
if (!unfound.isEmpty()) {
embedBuilder.setDescription("No hiscores found for following competitor RSN's:");
unfound.forEach(competitor ->
diff --git a/src/main/java/com/wimdupont/sxcybot/services/guild/pvmrole/PvmRoleAssignerService.java b/src/main/java/com/wimdupont/sxcybot/services/guild/pvmrole/PvmRoleAssignerService.java
@@ -69,10 +69,10 @@ public class PvmRoleAssignerService {
if (i == winningRank) winningRank++;
embedBuilder.addField(String.format("#%s %s", i, entry.getKey().getRsn()), String.format("%s with a score of %s!",
JdaUtil.getNameById(memberlist, entry.getKey().getDiscordId())
- .orElse("UNKNOWN"), entry.getValue()), false);
+ .orElse(String.format("{discordId:%s}", entry.getKey().getDiscordId())), entry.getValue()), false);
textChannel.sendMessage(String.format("No guildmember found for discordname %s. User did not receive any awards.",
JdaUtil.getNameById(memberlist, entry.getKey().getDiscordId())
- .orElse("UNKNOWN"))).queue();
+ .orElse(String.format("{discordId:%s}", entry.getKey().getDiscordId())))).queue();
}
i++;
}