sxcybot

Discord bot for OSRS based channels
git clone git://git.wimdupont.com/sxcybot.git
Log | Files | Refs | README | LICENSE

commit f5ee49aeeb3acb7789993af7c5f8fcf2a95523af
parent c9668ef65ac6489c37949c0f2842924c99f639b9
Author: Wim Dupont <wim@wimdupont.com>
Date:   Fri,  1 Dec 2023 19:00:05 +0100

java 21 upgrade

Diffstat:
Mpom.xml | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/AdminCommandListener.java | 16++++++++--------
Msrc/main/java/com/wimdupont/sxcybot/listeners/CommandListener.java | 33+++++++++++++++++----------------
Msrc/main/java/com/wimdupont/sxcybot/listeners/Listener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/PollReactionListener.java | 29+++++++++++++++++++++--------
Msrc/main/java/com/wimdupont/sxcybot/listeners/PrivateListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/BanlistListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/EditBanlistListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/EditPvmListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/EditRoleListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/EditRuleListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/RoleAssignListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/banlist/AddBanlistUserListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/banlist/DeleteBanlistUserListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/banlist/UpdateBanlistUserListener.java | 4++--
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/pvmrole/AddPvmListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/pvmrole/DeletePvmListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/pvmrole/UpdatePvmListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/role/AddRoleListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/role/DeleteRoleListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/role/UpdateRoleListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/rule/AddRuleListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/rule/DeleteRuleListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/admin/rule/UpdateRuleListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/BB8Listener.java | 8+++++---
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/CombatStatsListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/CustomPollListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/EventListener.java | 3++-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/ForumListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/HelpListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/HiscoreBossListener.java | 4++--
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/KillCountListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/PingListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/PollListener.java | 3++-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/PriceListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/PvmListListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/PvmRoleCheckListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/PvmRolePollListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/RuleListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/RulesListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/listeners/member/StatsListener.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/model/EditListenerDto.java | 10+++++-----
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/dao/ChannelDetail.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/dao/Event.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/dao/GuildEventDmer.java | 2++
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/dao/GuildRole.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/dao/Poll.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/dao/Rule.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/dao/User.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/pvmrole/dao/PvmKcSnapshot.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/pvmrole/dao/PvmRoleUser.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/repository/guild/pvmrole/dao/PvmUserKc.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/repository/osrs/dao/OsrsHiscoreBoss.java | 4++--
Msrc/main/java/com/wimdupont/sxcybot/repository/osrs/dao/OsrsHiscoreStat.java | 2++
Msrc/main/java/com/wimdupont/sxcybot/services/guild/pvmrole/PvmRoleSnapshotComparatorService.java | 2+-
Msrc/main/java/com/wimdupont/sxcybot/services/osrs/CombatCalculatorService.java | 6+++---
Msrc/main/java/com/wimdupont/sxcybot/util/Constants.java | 1+
Msrc/main/java/com/wimdupont/sxcybot/util/EditListenerUtil.java | 28++++++++++++++++------------
58 files changed, 133 insertions(+), 97 deletions(-)

diff --git a/pom.xml b/pom.xml @@ -15,7 +15,7 @@ <description>OSRS oriented Discord Bot</description> <properties> - <java.version>17</java.version> + <java.version>21</java.version> </properties> <dependencies> diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/AdminCommandListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/AdminCommandListener.java @@ -68,27 +68,27 @@ public class AdminCommandListener extends ListenerAdapter { switch (adminCommand.get()) { case EDITRULE -> { isPrivileged(roleStream, event, ADMIN_ROLE); - editRuleListener.proces(event); + editRuleListener.process(event); } case EDITBANLIST -> { isPrivileged(roleStream, event, ADMIN_ROLE); - editBanlistListener.proces(event); + editBanlistListener.process(event); } case ROLE -> { isPrivileged(roleStream, event, SUB_ADMIN); - roleAssignListener.proces(event); + roleAssignListener.process(event); } case BANLIST -> { isPrivileged(roleStream, event, STAFF_ROLE); - banlistListener.proces(event); + banlistListener.process(event); } case EDITROLE -> { isPrivileged(roleStream, event, GOD); - editRoleListener.proces(event); + editRoleListener.process(event); } case EDITPVM -> { isPrivileged(roleStream, event, STAFF_ROLE); - editPvmListener.proces(event); + editPvmListener.process(event); } default -> { } @@ -112,11 +112,11 @@ public class AdminCommandListener extends ListenerAdapter { private void isPrivileged(Stream<Role> roleStream, MessageReceivedEvent event, int elevation) throws InsufficientPrivilegesException { List<GuildRole> guildRoles = guildRoleService.findAllByElevationLessThanEqual(elevation); - if (roleStream.noneMatch(hasPrivilage(event, guildRoles))) + if (roleStream.noneMatch(hasPrivilege(event, guildRoles))) throw new InsufficientPrivilegesException(guildRoles.stream().map(GuildRole::getName).toList()); } - private Predicate<Role> hasPrivilage(MessageReceivedEvent event, List<GuildRole> guildRoles) { + private Predicate<Role> hasPrivilege(MessageReceivedEvent event, List<GuildRole> guildRoles) { return f -> f.hasPermission(Permission.ADMINISTRATOR) || (event.getMember() != null && event.getMember().isOwner()) || guildRoles.stream().map(GuildRole::getName).anyMatch(e -> e.equalsIgnoreCase(f.getName())); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/CommandListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/CommandListener.java @@ -91,30 +91,31 @@ public class CommandListener extends ListenerAdapter { Optional<Command> command = messageToCommand(msg); if (command.isPresent()) { switch (command.get()) { - case RULE -> ruleListener.proces(event); - case RULES -> rulesListener.proces(event); - case PING -> pingListener.proces(event); + case RULE -> ruleListener.process(event); + case RULES -> rulesListener.process(event); + case PING -> pingListener.process(event); + //TODO // case EVENT: // eventListener.proces(event); // break; - case CBSTATS -> combatStatsListener.proces(event); - case STATS -> statsListener.proces(event); - case PRICE -> priceListener.proces(event); - case FORUM -> forumListener.proces(event); - case POLL -> pollListener.proces(event); - case CPOLL -> customPollListener.proces(event); - case KC -> killCountListener.proces(event); - case PVMLIST -> pvmListListener.proces(event); - case BOSSLIST -> hiscoreBossListener.proces(event); - case PVMPOLL -> pvmRolePollListener.proces(event); - case PVMCHECK -> pvmRoleCheckListener.proces(event); - case HELP -> helpListener.proces(event); + case CBSTATS -> combatStatsListener.process(event); + case STATS -> statsListener.process(event); + case PRICE -> priceListener.process(event); + case FORUM -> forumListener.process(event); + case POLL -> pollListener.process(event); + case CPOLL -> customPollListener.process(event); + case KC -> killCountListener.process(event); + case PVMLIST -> pvmListListener.process(event); + case BOSSLIST -> hiscoreBossListener.process(event); + case PVMPOLL -> pvmRolePollListener.process(event); + case PVMCHECK -> pvmRoleCheckListener.process(event); + case HELP -> helpListener.process(event); default -> { } } } else if (Commands.BB8.equals(msg)) { - bb8Listener.proces(event); + bb8Listener.process(event); } } } diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/Listener.java b/src/main/java/com/wimdupont/sxcybot/listeners/Listener.java @@ -3,5 +3,5 @@ package com.wimdupont.sxcybot.listeners; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; public interface Listener { - void proces(MessageReceivedEvent event); + void process(MessageReceivedEvent event); } diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/PollReactionListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/PollReactionListener.java @@ -15,6 +15,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; @Component public class PollReactionListener extends ListenerAdapter { @@ -37,32 +38,41 @@ public class PollReactionListener extends ListenerAdapter { embedBuilder.setFooter(String.format("Last voted on %s", LocalDate.now()), event.getGuild().getIconUrl()); String username = JdaUtil.getName(event).orElse(null); for (MessageEmbed.Field field : messageEmbed.getFields()) { - List<String> nameSplit = field.getValue() != null ? new ArrayList<>(Arrays.asList(field.getValue().split(System.lineSeparator()))) : null; + List<String> nameSplit = field.getValue() != null + ? new ArrayList<>(Arrays.asList(field.getValue().split(System.lineSeparator()))) + : new ArrayList<>(); if (field.getValue() != null && username != null && nameSplit.remove(username)) { String value = String.join(System.lineSeparator(), nameSplit); embedBuilder.addField(field); embedBuilder.getFields() .set(messageEmbed.getFields().indexOf(field), - new Field(getFieldNameWithCount(field, value), value, field.isInline())); + new Field(getFieldNameWithCount(field, value) + .orElse(null), value, field.isInline())); } else { if (field.getName() != null && field.getName().contains(event.getReactionEmote().getEmoji())) { - String value = !field.getValue().contains("‎") - ? field.getValue() + System.lineSeparator() + username : username; - embedBuilder.addField(getFieldNameWithCount(field, value), value, field.isInline()); + String value = field.getValue() != null && !field.getValue().contains("‎") + ? field.getValue() + System.lineSeparator() + username + : username; + embedBuilder.addField(getFieldNameWithCount(field, value) + .orElse(null), value, field.isInline()); } else { embedBuilder.addField(field); } } } message.editMessageEmbeds(embedBuilder.build()).queue(); - message.removeReaction(event.getReaction().getReactionEmote().getEmoji(), event.getUser()).queue(); + if (event.getUser() != null) + message.removeReaction(event.getReaction().getReactionEmote().getEmoji(), event.getUser()).queue(); } }); } } - public String getFieldNameWithCount(Field field, String updatedValue) { - return field.getName().replaceAll("\\(+\\d+\\)+", String.format("(%s)", getCount(updatedValue))); + public Optional<String> getFieldNameWithCount(Field field, String updatedValue) { + return Optional.ofNullable(field.getName()) + .map(f -> f.replaceAll( + "\\(+\\d+\\)+", + String.format("(%s)", getCount(updatedValue)))); } private long getCount(String fieldValue) { @@ -72,6 +82,9 @@ public class PollReactionListener extends ListenerAdapter { return Arrays.stream(fieldValue.split(System.lineSeparator())).count(); } + + + //TODO remove if not used // @Override // public void onMessageReactionRemove(@Nonnull MessageReactionRemoveEvent event) { // //event.user is null here! diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/PrivateListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/PrivateListener.java @@ -5,5 +5,5 @@ import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; public interface PrivateListener { - void proces(PrivateMessageReceivedEvent privateEvent, MessageReceivedEvent event); + void process(PrivateMessageReceivedEvent privateEvent, MessageReceivedEvent event); } diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/BanlistListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/BanlistListener.java @@ -27,7 +27,7 @@ public class BanlistListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/EditBanlistListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/EditBanlistListener.java @@ -33,7 +33,7 @@ public class EditBanlistListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/EditPvmListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/EditPvmListener.java @@ -33,7 +33,7 @@ public class EditPvmListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/EditRoleListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/EditRoleListener.java @@ -33,7 +33,7 @@ public class EditRoleListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/EditRuleListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/EditRuleListener.java @@ -33,7 +33,7 @@ public class EditRuleListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/RoleAssignListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/RoleAssignListener.java @@ -37,7 +37,7 @@ public class RoleAssignListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/banlist/AddBanlistUserListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/banlist/AddBanlistUserListener.java @@ -23,7 +23,7 @@ public class AddBanlistUserListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); privateChannel.sendMessage("Name of the user you want to ban?").queue(); eventWaiterUtil.waitForPrivateChannelEvent(nameReceiver -> { diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/banlist/DeleteBanlistUserListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/banlist/DeleteBanlistUserListener.java @@ -24,7 +24,7 @@ public class DeleteBanlistUserListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateEvent.getChannel(); privateChannel.sendMessage("Name of the user you want to delete?").queue(); eventWaiterUtil.waitForPrivateChannelEvent(nameReceiver -> { diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/banlist/UpdateBanlistUserListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/banlist/UpdateBanlistUserListener.java @@ -27,7 +27,7 @@ public class UpdateBanlistUserListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); privateChannel.sendMessage("Name of the user you want to update (\"showlist\" to show all names in banlist).").queue(); eventWaiterUtil.waitForPrivateChannelEvent(nameReceiver -> { @@ -38,7 +38,7 @@ public class UpdateBanlistUserListener implements PrivateListener { userService.findAllBanned().stream().map(User::getName).toList().forEach(f -> embedBuilder.addField(f, "", false)); privateChannel.sendMessageEmbeds(embedBuilder.build()).queue(); - this.proces(privateMessageReceivedEvent, event); + this.process(privateMessageReceivedEvent, event); return; } try { diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/pvmrole/AddPvmListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/pvmrole/AddPvmListener.java @@ -36,7 +36,7 @@ public class AddPvmListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setColor(Color.RED); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/pvmrole/DeletePvmListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/pvmrole/DeletePvmListener.java @@ -34,7 +34,7 @@ public class DeletePvmListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setColor(Color.RED); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/pvmrole/UpdatePvmListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/pvmrole/UpdatePvmListener.java @@ -31,7 +31,7 @@ public class UpdatePvmListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setColor(Color.RED); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/role/AddRoleListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/role/AddRoleListener.java @@ -28,7 +28,7 @@ public class AddRoleListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); privateChannel.sendMessage("Name of the role you want to add?").queue(); eventWaiterUtil.waitForPrivateChannelEvent(nameReceiver -> { diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/role/DeleteRoleListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/role/DeleteRoleListener.java @@ -26,7 +26,7 @@ public class DeleteRoleListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); privateChannel.sendMessage("Name of the role you want to delete?").queue(); eventWaiterUtil.waitForPrivateChannelEvent(nameReceiver -> { diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/role/UpdateRoleListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/role/UpdateRoleListener.java @@ -26,7 +26,7 @@ public class UpdateRoleListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); privateChannel.sendMessage("Type the name of the role you want to update.").queue(); eventWaiterUtil.waitForPrivateChannelEvent(oldRoleNameReceiver -> { diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/rule/AddRuleListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/rule/AddRuleListener.java @@ -24,7 +24,7 @@ public class AddRuleListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { privateMessageReceivedEvent.getChannel().sendMessage("Type rule description please").queue(); eventWaiterUtil.waitForPrivateChannelEvent(e -> { String msg = e.getMessage().getContentRaw(); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/rule/DeleteRuleListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/rule/DeleteRuleListener.java @@ -25,7 +25,7 @@ public class DeleteRuleListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); privateChannel.sendMessage("Type the # of the rule you wish to delete please.").queue(); eventWaiterUtil.waitForPrivateChannelEvent(ruleDeleltionReceiver -> { diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/admin/rule/UpdateRuleListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/admin/rule/UpdateRuleListener.java @@ -25,7 +25,7 @@ public class UpdateRuleListener implements PrivateListener { } @Override - public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { + public void process(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); privateChannel.sendMessage("Type the rule number you want to update.").queue(); eventWaiterUtil.waitForPrivateChannelEvent(ruleNumberReciever -> { diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/BB8Listener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/BB8Listener.java @@ -14,10 +14,12 @@ public class BB8Listener implements Listener { private static final String BB8_IMAGE = "/images/bb8.jpg"; @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { MessageChannel channel = event.getChannel(); InputStream in = getClass().getResourceAsStream(BB8_IMAGE); - channel.sendMessage("BEEP BOOP! " + Emoji.THUMBS_UP + " " + Emoji.FLAMES) - .addFile(in, "bb8.jpg").queue(); + if (in != null) + channel.sendMessage("BEEP BOOP! " + Emoji.THUMBS_UP + " " + Emoji.FLAMES) + .addFile(in, "bb8.jpg").queue(); + } } diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/CombatStatsListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/CombatStatsListener.java @@ -27,7 +27,7 @@ public class CombatStatsListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); event.getChannel().sendTyping().queue(e -> statMessageSender.sendStatMessage(event, embedBuilder, this::isCombatStat, diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/CustomPollListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/CustomPollListener.java @@ -27,7 +27,7 @@ public class CustomPollListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { String msg = event.getMessage().getContentRaw(); try { String title = msg.substring(msg.indexOf(" ")); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/EventListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/EventListener.java @@ -22,7 +22,7 @@ public class EventListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { if (!event.getAuthor().isBot() && event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); @@ -49,6 +49,7 @@ public class EventListener implements Listener { PrivateMessageReceivedEvent timeZoneReceiver, PrivateMessageReceivedEvent dateReceiver, MessageReceivedEvent event) { + //TODO finish or remove Event createdEvent = Event.Builder.newBuilder() .name(nameReceiver.getMessage().getContentRaw()) .description(descriptionReceiver.getMessage().getContentRaw()) diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/ForumListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/ForumListener.java @@ -19,7 +19,7 @@ public class ForumListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { channelDetailService.findAll().stream().findAny().ifPresent(channelDetail -> { MessageChannel channel = event.getChannel(); EmbedBuilder embedBuilder = new EmbedBuilder(); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/HelpListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/HelpListener.java @@ -14,7 +14,7 @@ import java.awt.Color; public class HelpListener implements Listener { @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { event.getChannel().sendTyping().queue(); EmbedBuilder embedBuilder = new EmbedBuilder(); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/HiscoreBossListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/HiscoreBossListener.java @@ -22,7 +22,7 @@ public class HiscoreBossListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setColor(Color.red); List<OsrsHiscoreBoss> hiscoreBossList = osrsHiscoreBossService.findAll(); @@ -42,7 +42,7 @@ public class HiscoreBossListener implements Listener { } i++; } - if (embedBuilder.getFields().size() > 0) + if (!embedBuilder.getFields().isEmpty()) event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); embedBuilder.clearFields(); } diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/KillCountListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/KillCountListener.java @@ -22,7 +22,7 @@ public class KillCountListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { String msg = event.getMessage().getContentRaw(); try { String player = msg.substring(msg.indexOf(" ")).trim(); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/PingListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/PingListener.java @@ -9,7 +9,7 @@ import org.springframework.stereotype.Component; public class PingListener implements Listener { @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { MessageChannel channel; channel = event.getChannel(); long time = System.currentTimeMillis(); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/PollListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/PollListener.java @@ -20,7 +20,7 @@ public class PollListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); String msg = event.getMessage().getContentRaw(); try { @@ -46,6 +46,7 @@ public class PollListener implements Listener { } } + //TODO fix & implement or remove // private Poll createPoll(String messageId) { // List<PollReaction> pollReactionList = newArrayList(); // Poll poll = Poll.builder() diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/PriceListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/PriceListener.java @@ -19,7 +19,7 @@ public class PriceListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); String msg = event.getMessage().getContentRaw(); try { diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/PvmListListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/PvmListListener.java @@ -21,7 +21,7 @@ public class PvmListListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setColor(Color.red); embedBuilder.setTitle("List of PvM Role competitors:"); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/PvmRoleCheckListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/PvmRoleCheckListener.java @@ -20,7 +20,7 @@ public class PvmRoleCheckListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/PvmRolePollListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/PvmRolePollListener.java @@ -20,7 +20,7 @@ public class PvmRolePollListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/RuleListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/RuleListener.java @@ -24,7 +24,7 @@ public class RuleListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { MessageChannel channel = event.getChannel(); int ruleNumber; String description; diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/RulesListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/RulesListener.java @@ -22,7 +22,7 @@ public class RulesListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setColor(Color.red); embedBuilder.setTitle(String.format("List of %s rules:", event.getGuild().getName())); diff --git a/src/main/java/com/wimdupont/sxcybot/listeners/member/StatsListener.java b/src/main/java/com/wimdupont/sxcybot/listeners/member/StatsListener.java @@ -18,7 +18,7 @@ public class StatsListener implements Listener { } @Override - public void proces(MessageReceivedEvent event) { + public void process(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); event.getChannel().sendTyping().queue(e -> statMessageSender.sendStatMessage(event, embedBuilder, Objects::nonNull, diff --git a/src/main/java/com/wimdupont/sxcybot/model/EditListenerDto.java b/src/main/java/com/wimdupont/sxcybot/model/EditListenerDto.java @@ -30,12 +30,12 @@ public record EditListenerDto( } public static final class Builder { - private @NotNull PrivateListener addListener; + private PrivateListener addListener; private PrivateListener updateListener; - private @NotNull PrivateListener deleteListener; - private @NotNull MessageReceivedEvent event; - private @NotNull PrivateChannel privateChannel; - private @NotNull String entityName; + private PrivateListener deleteListener; + private MessageReceivedEvent event; + private PrivateChannel privateChannel; + private String entityName; private Builder() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/ChannelDetail.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/ChannelDetail.java @@ -16,6 +16,7 @@ public class ChannelDetail { private String pvmRoleRaids; private String pvmRoleWilderness; + @SuppressWarnings("unused") protected ChannelDetail() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/Event.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/Event.java @@ -8,6 +8,7 @@ public class Event { private String description; private LocalDate time; + @SuppressWarnings("unused") protected Event() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/GuildEventDmer.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/GuildEventDmer.java @@ -7,6 +7,7 @@ import org.hibernate.annotations.UuidGenerator; @Entity public class GuildEventDmer { + @Id @UuidGenerator private String id; @@ -34,6 +35,7 @@ public class GuildEventDmer { this.name = name; } + @SuppressWarnings("unused") protected GuildEventDmer() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/GuildRole.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/GuildRole.java @@ -15,6 +15,7 @@ public class GuildRole { private Integer orderValue; private int elevation; + @SuppressWarnings("unused") protected GuildRole() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/Poll.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/Poll.java @@ -24,6 +24,7 @@ public class Poll { @LastModifiedDate private LocalDateTime lastModifiedDate; + @SuppressWarnings("unused") protected Poll() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/Rule.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/Rule.java @@ -15,6 +15,7 @@ public class Rule { private String description; + @SuppressWarnings("unused") protected Rule() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/User.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/dao/User.java @@ -27,6 +27,7 @@ public class User { private LocalDate lastModifiedDate; private String lastModifiedBy; + @SuppressWarnings("unused") protected User() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/pvmrole/dao/PvmKcSnapshot.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/pvmrole/dao/PvmKcSnapshot.java @@ -36,6 +36,7 @@ public class PvmKcSnapshot { @LastModifiedDate private LocalDateTime lastModifiedDate; + @SuppressWarnings("unused") protected PvmKcSnapshot() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/pvmrole/dao/PvmRoleUser.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/pvmrole/dao/PvmRoleUser.java @@ -34,6 +34,7 @@ public class PvmRoleUser { this.discordId = discordId; } + @SuppressWarnings("unused") protected PvmRoleUser() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/guild/pvmrole/dao/PvmUserKc.java b/src/main/java/com/wimdupont/sxcybot/repository/guild/pvmrole/dao/PvmUserKc.java @@ -41,6 +41,7 @@ public class PvmUserKc { @LastModifiedDate private LocalDateTime lastModifiedDate; + @SuppressWarnings("unused") protected PvmUserKc() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/osrs/dao/OsrsHiscoreBoss.java b/src/main/java/com/wimdupont/sxcybot/repository/osrs/dao/OsrsHiscoreBoss.java @@ -1,14 +1,13 @@ package com.wimdupont.sxcybot.repository.osrs.dao; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.UuidGenerator; @Entity public class OsrsHiscoreBoss { + @Id @UuidGenerator private String id; @@ -17,6 +16,7 @@ public class OsrsHiscoreBoss { private double multiplier; private int pvmRole; + @SuppressWarnings("unused") protected OsrsHiscoreBoss() { } diff --git a/src/main/java/com/wimdupont/sxcybot/repository/osrs/dao/OsrsHiscoreStat.java b/src/main/java/com/wimdupont/sxcybot/repository/osrs/dao/OsrsHiscoreStat.java @@ -7,12 +7,14 @@ import org.hibernate.annotations.UuidGenerator; @Entity public class OsrsHiscoreStat { + @Id @UuidGenerator private String id; private String name; private int orderValue; + @SuppressWarnings("unused") protected OsrsHiscoreStat() { } diff --git a/src/main/java/com/wimdupont/sxcybot/services/guild/pvmrole/PvmRoleSnapshotComparatorService.java b/src/main/java/com/wimdupont/sxcybot/services/guild/pvmrole/PvmRoleSnapshotComparatorService.java @@ -41,7 +41,7 @@ public class PvmRoleSnapshotComparatorService { public void updateScoreboard(PvmRoleUser pvmRoleUser, Map<PvmRole, LinkedHashMap<PvmRoleUser, BigDecimal>> scoreBoard, List<PvmKcSnapshot> unpersistedSnapshots) { boolean persisted = unpersistedSnapshots == null; List<PvmKcSnapshot> pvmKcSnapshots = pvmKcSnapshotService.findAllByPvmRoleUser(pvmRoleUser); - if (pvmKcSnapshots != null && (pvmKcSnapshots.size() > 1 || (!persisted && pvmKcSnapshots.size() > 0))) { + if (pvmKcSnapshots != null && (pvmKcSnapshots.size() > 1 || (!persisted && !pvmKcSnapshots.isEmpty()))) { pvmKcSnapshots = pvmKcSnapshots.stream() .sorted(Comparator.comparing(PvmKcSnapshot::getCreatedDate) .reversed()) diff --git a/src/main/java/com/wimdupont/sxcybot/services/osrs/CombatCalculatorService.java b/src/main/java/com/wimdupont/sxcybot/services/osrs/CombatCalculatorService.java @@ -12,7 +12,7 @@ import java.math.RoundingMode; public class CombatCalculatorService { public double getCombatLevel(CombatDto combatDto) { - double base = 0.25 * (combatDto.defenceLevel() + combatDto.hitpointsLevel() + (combatDto.prayerLevel() / 2)); + double base = 0.25 * (combatDto.defenceLevel() + combatDto.hitpointsLevel() + ((double) combatDto.prayerLevel() / 2)); double typeContribution = getMeleeRangeOrMagicCombatLevelContribution(combatDto.attackLevel(), combatDto.strengthLevel(), combatDto.magicLevel(), combatDto.rangeLevel()); @@ -21,8 +21,8 @@ public class CombatCalculatorService { private double getMeleeRangeOrMagicCombatLevelContribution(int attackLevel, int strengthLevel, int magicLevel, int rangeLevel) { double melee = 0.325 * (attackLevel + strengthLevel); - double range = 0.325 * (rangeLevel / 2 + rangeLevel); - double magic = 0.325 * (magicLevel / 2 + magicLevel); + double range = 0.325 * ((double) rangeLevel / 2 + rangeLevel); + double magic = 0.325 * ((double) magicLevel / 2 + magicLevel); return Math.max(melee, Math.max(range, magic)); } diff --git a/src/main/java/com/wimdupont/sxcybot/util/Constants.java b/src/main/java/com/wimdupont/sxcybot/util/Constants.java @@ -29,6 +29,7 @@ public class Constants { private Reaction() { } + //TODO remove if not needed public static final String CHECK_MARK = "U+2714"; public static final String CROSS_MARK = "U+274C"; public static final String QUESTION_MARK = "U+2753"; diff --git a/src/main/java/com/wimdupont/sxcybot/util/EditListenerUtil.java b/src/main/java/com/wimdupont/sxcybot/util/EditListenerUtil.java @@ -17,26 +17,30 @@ public class EditListenerUtil { } public void procesEditEvent(EditListenerDto editListenerDto) { - EmbedBuilder embedBuilder = new EmbedBuilder(); - embedBuilder.setColor(Color.red); - embedBuilder.setTitle("What do you want to do?"); - embedBuilder.addField("1", String.format("Add a new %s.", editListenerDto.entityName()), false); - embedBuilder.addField("2", String.format("Delete an existing %s.", editListenerDto.entityName()), false); - if (editListenerDto.updateListener() != null) - embedBuilder.addField("3", String.format("Update an existing %s.", editListenerDto.entityName()), false); + EmbedBuilder embedBuilder = getEmbedBuilder(editListenerDto); editListenerDto.privateChannel().sendMessageEmbeds(embedBuilder.build()).queue(); eventWaiterUtil.waitForPrivateChannelEvent(commandReceiver -> { switch (commandReceiver.getMessage().getContentRaw()) { - case "1" -> editListenerDto.addListener().proces(commandReceiver, editListenerDto.event()); - case "2" -> editListenerDto.deleteListener().proces(commandReceiver, editListenerDto.event()); + case "1" -> editListenerDto.addListener().process(commandReceiver, editListenerDto.event()); + case "2" -> editListenerDto.deleteListener().process(commandReceiver, editListenerDto.event()); case "3" -> { if (editListenerDto.updateListener() != null) - editListenerDto.updateListener().proces(commandReceiver, editListenerDto.event()); + editListenerDto.updateListener().process(commandReceiver, editListenerDto.event()); } - default -> - editListenerDto.privateChannel().sendMessage("Unknown command, please try again.").queue(); + default -> editListenerDto.privateChannel().sendMessage("Unknown command, please try again.").queue(); } }, editListenerDto.event(), editListenerDto.privateChannel()); } + private static EmbedBuilder getEmbedBuilder(EditListenerDto editListenerDto) { + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setColor(Color.red); + embedBuilder.setTitle("What do you want to do?"); + embedBuilder.addField("1", String.format("Add a new %s.", editListenerDto.entityName()), false); + embedBuilder.addField("2", String.format("Delete an existing %s.", editListenerDto.entityName()), false); + if (editListenerDto.updateListener() != null) + embedBuilder.addField("3", String.format("Update an existing %s.", editListenerDto.entityName()), false); + return embedBuilder; + } + }