sxcybot

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

commit 52ffdb7dec1fdf59f0a075bc6769479b134fe768
parent 37d6ce1d4b7d5bed254ae29fb9c5d3da71f61fb5
Author: Wim Dupont <wim@wimdupont.com>
Date:   Tue, 28 Feb 2023 20:13:51 +0100

de-lombok and cleanup

Diffstat:
Mpom.xml | 13+++----------
Msrc/main/java/com/sxcy/sxcybot/SxcyBotApplication.java | 61+++++++++++++++++++++++++++++++++++--------------------------
Msrc/main/java/com/sxcy/sxcybot/client/ClientErrorHandler.java | 6++++--
Msrc/main/java/com/sxcy/sxcybot/client/GrandExchangeClient.java | 9++++++---
Msrc/main/java/com/sxcy/sxcybot/client/HiScoreClient.java | 23+++++++++++++----------
Msrc/main/java/com/sxcy/sxcybot/config/PersistenceConfig.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/listeners/AdminCommandListener.java | 26++++++++++++++++----------
Msrc/main/java/com/sxcy/sxcybot/listeners/CommandListener.java | 58+++++++++++++++++++++++++++++++++++++---------------------
Msrc/main/java/com/sxcy/sxcybot/listeners/EventWaiterUtil.java | 2--
Msrc/main/java/com/sxcy/sxcybot/listeners/GuildMemberEventListener.java | 15++++++++-------
Msrc/main/java/com/sxcy/sxcybot/listeners/PollReactionListener.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/listeners/TimeOutRunner.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/BanlistListener.java | 15++++++++-------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/EditBanlistListener.java | 26+++++++++++++++-----------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/EditPvmListener.java | 26+++++++++++++++-----------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/EditRoleListener.java | 29+++++++++++++++--------------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/EditRuleListener.java | 26+++++++++++++++-----------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/RoleAssignListener.java | 23++++++++++++-----------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/banlist/AddBanlistUserListener.java | 13+++++++------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/banlist/DeleteBanlistUserListener.java | 11++++++-----
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/banlist/UpdateBanlistUserListener.java | 18+++++++++---------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/pvmrole/AddPvmListener.java | 19+++++++++++--------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/pvmrole/DeletePvmListener.java | 14++++++++------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/pvmrole/UpdatePvmListener.java | 25++++++++++++-------------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/role/AddRoleListener.java | 13+++++++------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/role/DeleteRoleListener.java | 18+++++++++++-------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/role/UpdateRoleListener.java | 19++++++++++---------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/rule/AddRuleListener.java | 13+++++++------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/rule/DeleteRuleListener.java | 16++++++++++------
Msrc/main/java/com/sxcy/sxcybot/listeners/admin/rule/UpdateRuleListener.java | 18+++++++++---------
Msrc/main/java/com/sxcy/sxcybot/listeners/member/CombatStatsListener.java | 15++++++++-------
Msrc/main/java/com/sxcy/sxcybot/listeners/member/CustomPollListener.java | 16+++++++++-------
Msrc/main/java/com/sxcy/sxcybot/listeners/member/EventListener.java | 17+++++++++--------
Msrc/main/java/com/sxcy/sxcybot/listeners/member/ForumListener.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/listeners/member/HiscoreBossListener.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/listeners/member/KillCountListener.java | 13+++++++------
Msrc/main/java/com/sxcy/sxcybot/listeners/member/PollListener.java | 10+++++-----
Msrc/main/java/com/sxcy/sxcybot/listeners/member/PriceListener.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/listeners/member/PvmListListener.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/listeners/member/PvmRoleCheckListener.java | 13++++++++-----
Msrc/main/java/com/sxcy/sxcybot/listeners/member/PvmRolePollListener.java | 13++++++++-----
Msrc/main/java/com/sxcy/sxcybot/listeners/member/RuleListener.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/listeners/member/RulesListener.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/listeners/member/StatsListener.java | 16++++++++--------
Msrc/main/java/com/sxcy/sxcybot/model/CombatDto.java | 131++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
Msrc/main/java/com/sxcy/sxcybot/model/EditListenerDto.java | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Msrc/main/java/com/sxcy/sxcybot/model/OsrsBossKc.java | 58++++++++++++++++++++++++++++++++++++++++++++++++++--------
Msrc/main/java/com/sxcy/sxcybot/model/OsrsItem.java | 78+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
Msrc/main/java/com/sxcy/sxcybot/model/OsrsStat.java | 69++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Msrc/main/java/com/sxcy/sxcybot/repository/guild/dao/ChannelDetail.java | 146++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/main/java/com/sxcy/sxcybot/repository/guild/dao/Event.java | 83++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Msrc/main/java/com/sxcy/sxcybot/repository/guild/dao/GuildEventDmer.java | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Msrc/main/java/com/sxcy/sxcybot/repository/guild/dao/GuildRole.java | 98++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Msrc/main/java/com/sxcy/sxcybot/repository/guild/dao/Poll.java | 97++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Msrc/main/java/com/sxcy/sxcybot/repository/guild/dao/Rule.java | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Msrc/main/java/com/sxcy/sxcybot/repository/guild/dao/User.java | 164++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/main/java/com/sxcy/sxcybot/repository/guild/pvmrole/dao/PvmKcSnapshot.java | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Msrc/main/java/com/sxcy/sxcybot/repository/guild/pvmrole/dao/PvmRoleUser.java | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Msrc/main/java/com/sxcy/sxcybot/repository/guild/pvmrole/dao/PvmUserKc.java | 147++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/main/java/com/sxcy/sxcybot/repository/osrs/dao/OsrsHiscoreBoss.java | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Msrc/main/java/com/sxcy/sxcybot/repository/osrs/dao/OsrsHiscoreStat.java | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Asrc/main/java/com/sxcy/sxcybot/services/CleanupScheduler.java | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/main/java/com/sxcy/sxcybot/services/CleanuperScheduler.java | 62--------------------------------------------------------------
Msrc/main/java/com/sxcy/sxcybot/services/OsrsMonitoringService.java | 40+++++++++++++++++++++++-----------------
Msrc/main/java/com/sxcy/sxcybot/services/PvMRoleResolver.java | 24++++++++++++++----------
Msrc/main/java/com/sxcy/sxcybot/services/guild/ChannelDetailService.java | 28++++++++++++++++++++++++----
Msrc/main/java/com/sxcy/sxcybot/services/guild/GuildEventDmerService.java | 16++++++++++++++--
Msrc/main/java/com/sxcy/sxcybot/services/guild/GuildRoleService.java | 37++++++++++++++++++++++++++++++-------
Msrc/main/java/com/sxcy/sxcybot/services/guild/PollService.java | 29++++++++++++++++++++++++-----
Msrc/main/java/com/sxcy/sxcybot/services/guild/RuleService.java | 30+++++++++++++++++++++++++-----
Msrc/main/java/com/sxcy/sxcybot/services/guild/UserService.java | 31++++++++++++++++++++++++++-----
Dsrc/main/java/com/sxcy/sxcybot/services/guild/impl/ChannelDetailServiceImpl.java | 32--------------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/guild/impl/GuildEventDmerServiceImpl.java | 25-------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/guild/impl/GuildGuildRoleServiceImpl.java | 52----------------------------------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/guild/impl/PollServiceImpl.java | 41-----------------------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/guild/impl/RuleServiceImpl.java | 42------------------------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/guild/impl/UserServiceImpl.java | 43-------------------------------------------
Msrc/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmKcSnapshotService.java | 29++++++++++++++++++++++++-----
Msrc/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmRoleAssignerService.java | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmRoleSnapshotComparatorService.java | 86++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmRoleUserService.java | 31++++++++++++++++++++++++++-----
Dsrc/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmKcSnapshotServiceImpl.java | 39---------------------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmRoleAssignerServiceImpl.java | 96-------------------------------------------------------------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmRoleSnapshotComparatorServiceImpl.java | 100-------------------------------------------------------------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmRoleUserServiceImpl.java | 44--------------------------------------------
Msrc/main/java/com/sxcy/sxcybot/services/osrs/CombatCalculatorService.java | 25+++++++++++++++++++++++--
Msrc/main/java/com/sxcy/sxcybot/services/osrs/OsrsHiscoreBossService.java | 23++++++++++++++++++++---
Msrc/main/java/com/sxcy/sxcybot/services/osrs/OsrsHiscoreStatService.java | 18++++++++++++++++--
Msrc/main/java/com/sxcy/sxcybot/services/osrs/StatMessageSender.java | 38++++++++++++++++++++++++++++++++++++--
Dsrc/main/java/com/sxcy/sxcybot/services/osrs/impl/CombatCalculatorServiceImpl.java | 31-------------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/osrs/impl/OsrsHiscoreBossServiceImpl.java | 33---------------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/osrs/impl/OsrsHiscoreStatServiceImpl.java | 26--------------------------
Dsrc/main/java/com/sxcy/sxcybot/services/osrs/impl/StatMessageSenderImpl.java | 50--------------------------------------------------
Msrc/main/java/com/sxcy/sxcybot/util/Constants.java | 16++++++++++------
Msrc/main/java/com/sxcy/sxcybot/util/CustomPollFiller.java | 17+++++++++--------
Msrc/main/java/com/sxcy/sxcybot/util/DiscordMemberFinderUtil.java | 8++++----
Msrc/main/java/com/sxcy/sxcybot/util/EditListenerUtil.java | 30+++++++++++++++---------------
Msrc/main/java/com/sxcy/sxcybot/util/ReleaseNotesUtil.java | 15++++++++-------
Msrc/main/java/com/sxcy/sxcybot/util/SpringSecurityAuditorAware.java | 1+
Msrc/test/java/com/sxcy/sxcybot/client/HiScoreClientTest.java | 24++++++++++++------------
100 files changed, 2619 insertions(+), 1369 deletions(-)

diff --git a/pom.xml b/pom.xml @@ -28,11 +28,6 @@ <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <optional>true</optional> - </dependency> - <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> @@ -70,11 +65,6 @@ <plugin> <groupId>org.flywaydb</groupId> <artifactId>flyway-maven-plugin</artifactId> - <configuration> - <url>jdbc:mariadb://localhost:3306/sxcybot</url> - <user>test</user> - <password>test</password> - </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> @@ -111,18 +101,21 @@ </activation> <properties> <spring.profiles.active>dev</spring.profiles.active> + <flyway.configFiles>src/main/resources/application-dev.properties</flyway.configFiles> </properties> </profile> <profile> <id>test</id> <properties> <spring.profiles.active>test</spring.profiles.active> + <flyway.configFiles>src/main/resources/application-test.properties</flyway.configFiles> </properties> </profile> <profile> <id>prod</id> <properties> <spring.profiles.active>prod</spring.profiles.active> + <flyway.configFiles>src/main/resources/application-prod.properties</flyway.configFiles> </properties> </profile> </profiles> diff --git a/src/main/java/com/sxcy/sxcybot/SxcyBotApplication.java b/src/main/java/com/sxcy/sxcybot/SxcyBotApplication.java @@ -10,12 +10,12 @@ import com.sxcy.sxcybot.services.PvMRoleResolver; import com.sxcy.sxcybot.services.guild.ChannelDetailService; import com.sxcy.sxcybot.util.Constants.Commands; import com.sxcy.sxcybot.util.ReleaseNotesUtil; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.requests.GatewayIntent; -import org.springframework.beans.factory.annotation.Autowired; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -26,32 +26,41 @@ import org.springframework.scheduling.annotation.EnableScheduling; import javax.security.auth.login.LoginException; import java.util.Arrays; -@Slf4j @SpringBootApplication @EnableScheduling @ComponentScan public class SxcyBotApplication implements CommandLineRunner { - @Autowired - private CommandListener commandListener; - @Autowired - private AdminCommandListener adminCommandListener; - @Autowired - private EventWaiterUtil eventWaiterUtil; - @Autowired - private PollReactionListener pollReactionListener; - @Autowired - private GuildMemberEventListener guildMemberEventListener; - @Autowired - private ReleaseNotesUtil releaseNotesUtil; - @Autowired - private ChannelDetailService channelDetailService; - @Autowired - private PvMRoleResolver pvMRoleResolver; + private static final Logger LOGGER = LoggerFactory.getLogger(SxcyBotApplication.class); + private final CommandListener commandListener; + private final AdminCommandListener adminCommandListener; + private final EventWaiterUtil eventWaiterUtil; + private final PollReactionListener pollReactionListener; + private final GuildMemberEventListener guildMemberEventListener; + private final ReleaseNotesUtil releaseNotesUtil; + private final ChannelDetailService channelDetailService; + private final PvMRoleResolver pvMRoleResolver; + private final String token; - @SuppressWarnings("unused") - @Value("${discord.bot.token}") - private String token; + public SxcyBotApplication(CommandListener commandListener, + AdminCommandListener adminCommandListener, + EventWaiterUtil eventWaiterUtil, + PollReactionListener pollReactionListener, + GuildMemberEventListener guildMemberEventListener, + ReleaseNotesUtil releaseNotesUtil, + ChannelDetailService channelDetailService, + PvMRoleResolver pvMRoleResolver, + @Value("${discord.bot.token}") String token) { + this.commandListener = commandListener; + this.adminCommandListener = adminCommandListener; + this.eventWaiterUtil = eventWaiterUtil; + this.pollReactionListener = pollReactionListener; + this.guildMemberEventListener = guildMemberEventListener; + this.releaseNotesUtil = releaseNotesUtil; + this.channelDetailService = channelDetailService; + this.pvMRoleResolver = pvMRoleResolver; + this.token = token; + } public static void main(String[] args) { SpringApplication.run(SxcyBotApplication.class, args); @@ -59,7 +68,7 @@ public class SxcyBotApplication implements CommandLineRunner { @Override public void run(String[] args) throws LoginException { - log.debug("Jda to be created"); + LOGGER.debug("Jda to be created"); JDA jda = JDABuilder.createLight(token, GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES, @@ -71,13 +80,13 @@ public class SxcyBotApplication implements CommandLineRunner { .setActivity(Activity.listening(Commands.COMMAND_PREFIX + Command.HELP.name().toLowerCase())) .build(); try { - log.debug("Awaiting jda " + jda); + LOGGER.debug("Awaiting jda " + jda); jda.awaitReady(); - log.debug("Jda " + jda + " ready"); + LOGGER.debug("Jda " + jda + " ready"); channelDetailService.setJda(jda); processArgs(jda, args); } catch (InterruptedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } diff --git a/src/main/java/com/sxcy/sxcybot/client/ClientErrorHandler.java b/src/main/java/com/sxcy/sxcybot/client/ClientErrorHandler.java @@ -1,17 +1,19 @@ package com.sxcy.sxcybot.client; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.MessageChannel; import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.DefaultResponseErrorHandler; import java.io.IOException; -@RequiredArgsConstructor public class ClientErrorHandler extends DefaultResponseErrorHandler { private final MessageChannel channel; + public ClientErrorHandler(MessageChannel channel) { + this.channel = channel; + } + @Override public void handleError(ClientHttpResponse response) throws IOException { String errorMsg = String.format("No results found. (%s)", response.getStatusText()); diff --git a/src/main/java/com/sxcy/sxcybot/client/GrandExchangeClient.java b/src/main/java/com/sxcy/sxcybot/client/GrandExchangeClient.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.sxcy.sxcybot.exceptions.EntityNotFoundException; import com.sxcy.sxcybot.model.OsrsItem; import com.sxcy.sxcybot.util.NumberFormatter; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.MessageChannel; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.stereotype.Component; @@ -14,12 +13,15 @@ import java.time.Duration; import java.util.Map; @Component -@RequiredArgsConstructor public class GrandExchangeClient { private static final String URL = "https://api.weirdgloop.org/exchange/history/osrs/latest?name=%s&lang=en"; private final ObjectMapper objectMapper; + public GrandExchangeClient(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + @SuppressWarnings("unchecked") public String getPrice(String itemName, MessageChannel channel) throws EntityNotFoundException { RestTemplate restTemplate = new RestTemplateBuilder() @@ -29,7 +31,8 @@ public class GrandExchangeClient { Object result = restTemplate.getForEntity(String.format(URL, itemName), Object.class).getBody(); if (result != null) { try { - return NumberFormatter.format(objectMapper.convertValue(((Map<String, Object>) result).values().iterator().next(), OsrsItem.class).getPrice()); + return NumberFormatter.format(objectMapper + .convertValue(((Map<String, Object>) result).values().iterator().next(), OsrsItem.class).price()); } catch (IllegalArgumentException e) { throw new EntityNotFoundException(String.format("Item with name %s not found.", itemName)); } diff --git a/src/main/java/com/sxcy/sxcybot/client/HiScoreClient.java b/src/main/java/com/sxcy/sxcybot/client/HiScoreClient.java @@ -9,10 +9,9 @@ import com.sxcy.sxcybot.repository.osrs.dao.OsrsHiscoreStat; import com.sxcy.sxcybot.services.osrs.OsrsHiscoreBossService; import com.sxcy.sxcybot.services.osrs.OsrsHiscoreStatService; import com.sxcy.sxcybot.util.NumberFormatter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.MessageChannel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; @@ -23,25 +22,29 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; -@Slf4j @Component -@RequiredArgsConstructor public class HiScoreClient { + private static final String URL = "https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=%s"; + private static final Logger LOGGER = LoggerFactory.getLogger(HiScoreClient.class); private static final int STATS_START = 0; private static final int STATS_END = 23; private static final int BOSS_START = 38; private static final int BOSS_END = 88; - @NonNull private final OsrsHiscoreBossService osrsHiscoreBossService; - @NonNull private final OsrsHiscoreStatService osrsHiscoreStatService; + public HiScoreClient(OsrsHiscoreBossService osrsHiscoreBossService, + OsrsHiscoreStatService osrsHiscoreStatService) { + this.osrsHiscoreBossService = osrsHiscoreBossService; + this.osrsHiscoreStatService = osrsHiscoreStatService; + } + public Optional<List<OsrsStat>> getHiScoreStats(String playername, MessageChannel channel) { List<OsrsHiscoreStat> hiscoreStats = osrsHiscoreStatService.findAll(); - return getHiScores(playername, channel, (osrsStat, hiScoreStatValues, i) -> OsrsStat.builder() + return getHiScores(playername, channel, (osrsStat, hiScoreStatValues, i) -> OsrsStat.Builder.newBuilder() .name(hiscoreStats.stream().filter(f -> f.getOrderValue() == i).findFirst().orElseThrow(() -> new EntityNotFoundException(String.format("OsrsStatName for order %s not found!", i))) .getName()) @@ -53,7 +56,7 @@ public class HiScoreClient { public Optional<List<OsrsBossKc>> getHiScoreBossKc(String playername, MessageChannel channel) { List<OsrsHiscoreBoss> hiscoreBosses = osrsHiscoreBossService.findAll(); - return getHiScores(playername, channel, (osrsKc, hiScoreKcValues, i) -> OsrsBossKc.builder() + return getHiScores(playername, channel, (osrsKc, hiScoreKcValues, i) -> OsrsBossKc.Builder.newBuilder() .name(hiscoreBosses.stream().filter(f -> f.getOrderValue() == i).findFirst().orElseThrow(() -> new EntityNotFoundException(String.format("OsrsBoss for order %s not found!", i))) .getName()) @@ -78,7 +81,7 @@ public class HiScoreClient { try { hiScoreList.add(hiScoreBuilder.accept(osrsHiScoresStats, hiScoreStatValues, i)); } catch (EntityNotFoundException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } i++; } diff --git a/src/main/java/com/sxcy/sxcybot/config/PersistenceConfig.java b/src/main/java/com/sxcy/sxcybot/config/PersistenceConfig.java @@ -1,8 +1,6 @@ package com.sxcy.sxcybot.config; import com.sxcy.sxcybot.util.SpringSecurityAuditorAware; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.domain.AuditorAware; @@ -10,12 +8,14 @@ import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @Configuration @EnableJpaAuditing(auditorAwareRef = "auditorProvider") -@RequiredArgsConstructor public class PersistenceConfig { - @NonNull private final SpringSecurityAuditorAware springSecurityAuditorAware; + public PersistenceConfig(SpringSecurityAuditorAware springSecurityAuditorAware) { + this.springSecurityAuditorAware = springSecurityAuditorAware; + } + @Bean public AuditorAware<String> auditorProvider() { return springSecurityAuditorAware; diff --git a/src/main/java/com/sxcy/sxcybot/listeners/AdminCommandListener.java b/src/main/java/com/sxcy/sxcybot/listeners/AdminCommandListener.java @@ -12,8 +12,6 @@ import com.sxcy.sxcybot.listeners.admin.RoleAssignListener; import com.sxcy.sxcybot.repository.guild.dao.GuildRole; import com.sxcy.sxcybot.services.guild.GuildRoleService; import com.sxcy.sxcybot.util.Constants.Commands; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -27,7 +25,6 @@ import java.util.function.Predicate; import java.util.stream.Stream; @Component -@RequiredArgsConstructor public class AdminCommandListener extends ListenerAdapter { private static final int GOD = 0; @@ -35,21 +32,30 @@ public class AdminCommandListener extends ListenerAdapter { private static final int SUB_ADMIN = 5; private static final int STAFF_ROLE = 10; - @NonNull private final EditRuleListener editRuleListener; - @NonNull private final EditBanlistListener editBanlistListener; - @NonNull private final RoleAssignListener roleAssignListener; - @NonNull private final BanlistListener banlistListener; - @NonNull private final EditRoleListener editRoleListener; - @NonNull private final EditPvmListener editPvmListener; - @NonNull private final GuildRoleService guildRoleService; + public AdminCommandListener(EditRuleListener editRuleListener, + EditBanlistListener editBanlistListener, + RoleAssignListener roleAssignListener, + BanlistListener banlistListener, + EditRoleListener editRoleListener, + EditPvmListener editPvmListener, + GuildRoleService guildRoleService) { + this.editRuleListener = editRuleListener; + this.editBanlistListener = editBanlistListener; + this.roleAssignListener = roleAssignListener; + this.banlistListener = banlistListener; + this.editRoleListener = editRoleListener; + this.editPvmListener = editPvmListener; + this.guildRoleService = guildRoleService; + } + @Override public void onMessageReceived(@Nonnull MessageReceivedEvent event) { if (event.getChannelType().isGuild()) { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/CommandListener.java b/src/main/java/com/sxcy/sxcybot/listeners/CommandListener.java @@ -13,14 +13,12 @@ import com.sxcy.sxcybot.listeners.member.PingListener; import com.sxcy.sxcybot.listeners.member.PollListener; import com.sxcy.sxcybot.listeners.member.PriceListener; import com.sxcy.sxcybot.listeners.member.PvmListListener; -import com.sxcy.sxcybot.listeners.member.PvmRolePollListener; import com.sxcy.sxcybot.listeners.member.PvmRoleCheckListener; +import com.sxcy.sxcybot.listeners.member.PvmRolePollListener; import com.sxcy.sxcybot.listeners.member.RuleListener; import com.sxcy.sxcybot.listeners.member.RulesListener; import com.sxcy.sxcybot.listeners.member.StatsListener; import com.sxcy.sxcybot.util.Constants.Commands; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.springframework.stereotype.Component; @@ -29,44 +27,62 @@ import javax.annotation.Nonnull; import java.util.Optional; @Component -@RequiredArgsConstructor public class CommandListener extends ListenerAdapter { - @NonNull private final BB8Listener bb8Listener; - @NonNull private final RuleListener ruleListener; - @NonNull private final RulesListener rulesListener; - @NonNull private final PingListener pingListener; - @NonNull private final EventListener eventListener; - @NonNull private final ForumListener forumListener; - @NonNull private final PollListener pollListener; - @NonNull private final CustomPollListener customPollListener; - @NonNull private final HelpListener helpListener; - @Nonnull private final StatsListener statsListener; - @NonNull private final CombatStatsListener combatStatsListener; - @NonNull private final PriceListener priceListener; - @NonNull private final KillCountListener killCountListener; - @NonNull private final PvmListListener pvmListListener; - @NonNull private final HiscoreBossListener hiscoreBossListener; - @NonNull private final PvmRoleCheckListener pvmRoleCheckListener; - @NonNull private final PvmRolePollListener pvmRolePollListener; + public CommandListener(BB8Listener bb8Listener, + RuleListener ruleListener, + RulesListener rulesListener, + PingListener pingListener, + EventListener eventListener, + ForumListener forumListener, + PollListener pollListener, + CustomPollListener customPollListener, + HelpListener helpListener, + StatsListener statsListener, + CombatStatsListener combatStatsListener, + PriceListener priceListener, + KillCountListener killCountListener, + PvmListListener pvmListListener, + HiscoreBossListener hiscoreBossListener, + PvmRoleCheckListener pvmRoleCheckListener, + PvmRolePollListener pvmRolePollListener) { + this.bb8Listener = bb8Listener; + this.ruleListener = ruleListener; + this.rulesListener = rulesListener; + this.pingListener = pingListener; + this.eventListener = eventListener; + this.forumListener = forumListener; + this.pollListener = pollListener; + this.customPollListener = customPollListener; + this.helpListener = helpListener; + this.statsListener = statsListener; + this.combatStatsListener = combatStatsListener; + this.priceListener = priceListener; + this.killCountListener = killCountListener; + this.pvmListListener = pvmListListener; + this.hiscoreBossListener = hiscoreBossListener; + this.pvmRoleCheckListener = pvmRoleCheckListener; + this.pvmRolePollListener = pvmRolePollListener; + } + @Override public void onMessageReceived(@Nonnull MessageReceivedEvent event) { if (event.getChannelType().isGuild()) { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/EventWaiterUtil.java b/src/main/java/com/sxcy/sxcybot/listeners/EventWaiterUtil.java @@ -1,7 +1,6 @@ package com.sxcy.sxcybot.listeners; import com.jagrosh.jdautilities.commons.waiter.EventWaiter; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; @@ -12,7 +11,6 @@ import java.util.function.Consumer; import java.util.function.Predicate; @Component -@RequiredArgsConstructor public class EventWaiterUtil extends EventWaiter { private static final int TIMEOUT = 1; diff --git a/src/main/java/com/sxcy/sxcybot/listeners/GuildMemberEventListener.java b/src/main/java/com/sxcy/sxcybot/listeners/GuildMemberEventListener.java @@ -1,27 +1,28 @@ package com.sxcy.sxcybot.listeners; import com.sxcy.sxcybot.services.guild.GuildEventDmerService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import javax.annotation.Nonnull; import java.util.Optional; -@Slf4j @Component -@RequiredArgsConstructor public class GuildMemberEventListener extends ListenerAdapter { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(GuildMemberEventListener.class); private final GuildEventDmerService guildEventDmerService; + public GuildMemberEventListener(GuildEventDmerService guildEventDmerService) { + this.guildEventDmerService = guildEventDmerService; + } + @Override public void onGuildMemberRemove(@Nonnull GuildMemberRemoveEvent event) { guildEventDmerService.findAll().forEach(guildEventDmer -> @@ -33,7 +34,7 @@ public class GuildMemberEventListener extends ListenerAdapter { PrivateChannel privateChannel = member.get().getUser().openPrivateChannel().complete(true); privateChannel.sendMessage(String.format("**%s** has been removed from channel _%s_", event.getUser().getName(), event.getGuild().getName())).queue(); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/PollReactionListener.java b/src/main/java/com/sxcy/sxcybot/listeners/PollReactionListener.java @@ -2,8 +2,6 @@ package com.sxcy.sxcybot.listeners; import com.sxcy.sxcybot.services.guild.PollService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.MessageEmbed.Field; @@ -19,12 +17,14 @@ import java.util.Arrays; import java.util.List; @Component -@RequiredArgsConstructor public class PollReactionListener extends ListenerAdapter { - @NonNull private final PollService pollService; + public PollReactionListener(PollService pollService) { + this.pollService = pollService; + } + @Override public void onMessageReactionAdd(@Nonnull MessageReactionAddEvent event) { if (isPoll(event)) { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/TimeOutRunner.java b/src/main/java/com/sxcy/sxcybot/listeners/TimeOutRunner.java @@ -1,15 +1,15 @@ package com.sxcy.sxcybot.listeners; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.MessageChannel; -@RequiredArgsConstructor public class TimeOutRunner implements Runnable { - @NonNull private final MessageChannel messageChannel; + public TimeOutRunner(MessageChannel messageChannel) { + this.messageChannel = messageChannel; + } + /** * When an object implementing interface {@code Runnable} is used * to create a thread, starting the thread causes the object's diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/BanlistListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/BanlistListener.java @@ -4,27 +4,28 @@ import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.repository.guild.dao.User; import com.sxcy.sxcybot.services.guild.UserService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.awt.Color; import java.util.List; -@Slf4j @Component -@RequiredArgsConstructor public class BanlistListener implements Listener { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(BanlistListener.class); private final UserService userService; + public BanlistListener(UserService userService) { + this.userService = userService; + } + @Override public void proces(MessageReceivedEvent event) { if (event.getMember() != null) { @@ -49,7 +50,7 @@ public class BanlistListener implements Listener { i++; } } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/EditBanlistListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/EditBanlistListener.java @@ -6,34 +6,38 @@ import com.sxcy.sxcybot.listeners.admin.banlist.DeleteBanlistUserListener; import com.sxcy.sxcybot.listeners.admin.banlist.UpdateBanlistUserListener; import com.sxcy.sxcybot.model.EditListenerDto; import com.sxcy.sxcybot.util.EditListenerUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -@Slf4j @Component -@RequiredArgsConstructor public class EditBanlistListener implements Listener { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(EditBanlistListener.class); private final AddBanlistUserListener addBanlistUserListener; - @NonNull private final UpdateBanlistUserListener updateBanlistListener; - @NonNull private final DeleteBanlistUserListener deleteBanlistListener; - @NonNull private final EditListenerUtil editListenerUtil; + public EditBanlistListener(AddBanlistUserListener addBanlistUserListener, + UpdateBanlistUserListener updateBanlistListener, + DeleteBanlistUserListener deleteBanlistListener, + EditListenerUtil editListenerUtil) { + this.addBanlistUserListener = addBanlistUserListener; + this.updateBanlistListener = updateBanlistListener; + this.deleteBanlistListener = deleteBanlistListener; + this.editListenerUtil = editListenerUtil; + } + @Override public void proces(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); - EditListenerDto editListenerDto = EditListenerDto.builder() + EditListenerDto editListenerDto = EditListenerDto.Builder.newBuilder() .addListener(addBanlistUserListener) .updateListener(updateBanlistListener) .deleteListener(deleteBanlistListener) @@ -43,7 +47,7 @@ public class EditBanlistListener implements Listener { .build(); editListenerUtil.procesEditEvent(editListenerDto); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/EditPvmListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/EditPvmListener.java @@ -6,34 +6,38 @@ import com.sxcy.sxcybot.listeners.admin.pvmrole.DeletePvmListener; import com.sxcy.sxcybot.listeners.admin.pvmrole.UpdatePvmListener; import com.sxcy.sxcybot.model.EditListenerDto; import com.sxcy.sxcybot.util.EditListenerUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -@Slf4j @Component -@RequiredArgsConstructor public class EditPvmListener implements Listener { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(EditPvmListener.class); private final EditListenerUtil editListenerUtil; - @NonNull private final AddPvmListener addPvmListener; - @NonNull private final UpdatePvmListener updatePvmListener; - @NonNull private final DeletePvmListener deletePvmListener; + public EditPvmListener(EditListenerUtil editListenerUtil, + AddPvmListener addPvmListener, + UpdatePvmListener updatePvmListener, + DeletePvmListener deletePvmListener) { + this.editListenerUtil = editListenerUtil; + this.addPvmListener = addPvmListener; + this.updatePvmListener = updatePvmListener; + this.deletePvmListener = deletePvmListener; + } + @Override public void proces(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); - EditListenerDto editListenerDto = EditListenerDto.builder() + EditListenerDto editListenerDto = EditListenerDto.Builder.newBuilder() .addListener(addPvmListener) .updateListener(updatePvmListener) .deleteListener(deletePvmListener) @@ -43,7 +47,7 @@ public class EditPvmListener implements Listener { .build(); editListenerUtil.procesEditEvent(editListenerDto); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/EditRoleListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/EditRoleListener.java @@ -6,37 +6,38 @@ import com.sxcy.sxcybot.listeners.admin.role.DeleteRoleListener; import com.sxcy.sxcybot.listeners.admin.role.UpdateRoleListener; import com.sxcy.sxcybot.model.EditListenerDto; import com.sxcy.sxcybot.util.EditListenerUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -@Slf4j @Component -@RequiredArgsConstructor public class EditRoleListener implements Listener { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(EditRoleListener.class); private final AddRoleListener addRoleListener; - - @NonNull private final UpdateRoleListener updateRoleListener; - - @NonNull private final DeleteRoleListener deleteRoleListener; - - @NonNull private final EditListenerUtil editListenerUtil; + public EditRoleListener(AddRoleListener addRoleListener, + UpdateRoleListener updateRoleListener, + DeleteRoleListener deleteRoleListener, + EditListenerUtil editListenerUtil) { + this.addRoleListener = addRoleListener; + this.updateRoleListener = updateRoleListener; + this.deleteRoleListener = deleteRoleListener; + this.editListenerUtil = editListenerUtil; + } + @Override public void proces(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); - EditListenerDto editListenerDto = EditListenerDto.builder() + EditListenerDto editListenerDto = EditListenerDto.Builder.newBuilder() .addListener(addRoleListener) .deleteListener(deleteRoleListener) //TODO why not implemented? @@ -47,7 +48,7 @@ public class EditRoleListener implements Listener { .build(); editListenerUtil.procesEditEvent(editListenerDto); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/EditRuleListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/EditRuleListener.java @@ -6,34 +6,38 @@ import com.sxcy.sxcybot.listeners.admin.rule.DeleteRuleListener; import com.sxcy.sxcybot.listeners.admin.rule.UpdateRuleListener; import com.sxcy.sxcybot.model.EditListenerDto; import com.sxcy.sxcybot.util.EditListenerUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -@Slf4j @Component -@RequiredArgsConstructor public class EditRuleListener implements Listener { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(EditRuleListener.class); private final AddRuleListener addRuleListener; - @NonNull private final UpdateRuleListener updateRuleListener; - @NonNull private final DeleteRuleListener deleteRuleListener; - @NonNull private final EditListenerUtil editListenerUtil; + public EditRuleListener(AddRuleListener addRuleListener, + UpdateRuleListener updateRuleListener, + DeleteRuleListener deleteRuleListener, + EditListenerUtil editListenerUtil) { + this.addRuleListener = addRuleListener; + this.updateRuleListener = updateRuleListener; + this.deleteRuleListener = deleteRuleListener; + this.editListenerUtil = editListenerUtil; + } + @Override public void proces(MessageReceivedEvent event) { if (event.getMember() != null) { try { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); - EditListenerDto editListenerDto = EditListenerDto.builder() + EditListenerDto editListenerDto = EditListenerDto.Builder.newBuilder() .addListener(addRuleListener) .updateListener(updateRuleListener) .deleteListener(deleteRuleListener) @@ -43,7 +47,7 @@ public class EditRuleListener implements Listener { .build(); editListenerUtil.procesEditEvent(editListenerDto); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/RoleAssignListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/RoleAssignListener.java @@ -5,14 +5,13 @@ import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.repository.guild.dao.GuildRole; import com.sxcy.sxcybot.services.guild.GuildRoleService; import com.sxcy.sxcybot.util.DiscordMemberFinderUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.awt.Color; @@ -22,20 +21,22 @@ import java.util.Optional; import static com.sxcy.sxcybot.util.Constants.ADDED_ROLE_ELEVATION; -@Slf4j @Component -@RequiredArgsConstructor public class RoleAssignListener implements Listener { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(RoleAssignListener.class); private final EventWaiterUtil eventWaiterUtil; - - @NonNull private final GuildRoleService guildRoleService; - - @NonNull private final DiscordMemberFinderUtil discordMemberFinderUtil; + public RoleAssignListener(EventWaiterUtil eventWaiterUtil, + GuildRoleService guildRoleService, + DiscordMemberFinderUtil discordMemberFinderUtil) { + this.eventWaiterUtil = eventWaiterUtil; + this.guildRoleService = guildRoleService; + this.discordMemberFinderUtil = discordMemberFinderUtil; + } + @Override public void proces(MessageReceivedEvent event) { if (event.getMember() != null) { @@ -92,7 +93,7 @@ public class RoleAssignListener implements Listener { }, event, privateChannel); }); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/banlist/AddBanlistUserListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/banlist/AddBanlistUserListener.java @@ -5,22 +5,23 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.dao.User; import com.sxcy.sxcybot.services.guild.UserService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; import org.springframework.stereotype.Component; @Component -@RequiredArgsConstructor public class AddBanlistUserListener implements PrivateListener { - @NonNull private final EventWaiterUtil eventWaiterUtil; - @NonNull private final UserService userService; + public AddBanlistUserListener(EventWaiterUtil eventWaiterUtil, + UserService userService) { + this.eventWaiterUtil = eventWaiterUtil; + this.userService = userService; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); @@ -28,7 +29,7 @@ public class AddBanlistUserListener implements PrivateListener { eventWaiterUtil.waitForPrivateChannelEvent(nameReceiver -> { privateChannel.sendMessage("Description?").queue(); eventWaiterUtil.waitForPrivateChannelEvent(descriptionReceiver -> { - User userToBan = User.builder() + User userToBan = User.Builder.newBuilder() .name(nameReceiver.getMessage().getContentRaw()) .description(descriptionReceiver.getMessage().getContentRaw()) .banned(true) diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/banlist/DeleteBanlistUserListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/banlist/DeleteBanlistUserListener.java @@ -6,22 +6,23 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.dao.User; import com.sxcy.sxcybot.services.guild.UserService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; import org.springframework.stereotype.Component; @Component -@RequiredArgsConstructor public class DeleteBanlistUserListener implements PrivateListener { - @NonNull private final UserService userService; - @NonNull private final EventWaiterUtil eventWaiterUtil; + public DeleteBanlistUserListener(UserService userService, + EventWaiterUtil eventWaiterUtil) { + this.userService = userService; + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(PrivateMessageReceivedEvent privateEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateEvent.getChannel(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/banlist/UpdateBanlistUserListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/banlist/UpdateBanlistUserListener.java @@ -6,8 +6,6 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.dao.User; import com.sxcy.sxcybot.services.guild.UserService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -17,14 +15,17 @@ import org.springframework.stereotype.Component; import java.awt.Color; @Component -@RequiredArgsConstructor public class UpdateBanlistUserListener implements PrivateListener { - @NonNull private final EventWaiterUtil eventWaiterUtil; - @NonNull private final UserService userService; + public UpdateBanlistUserListener(EventWaiterUtil eventWaiterUtil, + UserService userService) { + this.eventWaiterUtil = eventWaiterUtil; + this.userService = userService; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); @@ -44,10 +45,9 @@ public class UpdateBanlistUserListener implements PrivateListener { User userToUpdate = userService.findByName(nameReceiver.getMessage().getContentRaw()); privateChannel.sendMessage(String.format("Type the new description for the ban of %s.", nameReceiver.getMessage().getContentRaw())).queue(); eventWaiterUtil.waitForPrivateChannelEvent(descriptionReceiver -> { - User saved = userService.save(userToUpdate.toBuilder() - .description(descriptionReceiver.getMessage().getContentRaw()) - .lastModifiedBy(JdaUtil.getName(event)) - .build()); + userToUpdate.setDescription(descriptionReceiver.getMessage().getContentRaw()); + userToUpdate.setLastModifiedBy(JdaUtil.getName(event)); + User saved = userService.save(userToUpdate); privateChannel.sendMessage(saved + " edited.").queue(); event.getChannel().sendMessage(String.format("Banned user %s has been edited by %s.", saved.getName(), JdaUtil.getUser(event))).queue(); }, privateMessageReceivedEvent, privateChannel); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/pvmrole/AddPvmListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/pvmrole/AddPvmListener.java @@ -8,8 +8,6 @@ import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleSnapshotComparatorService; import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleUserService; import com.sxcy.sxcybot.util.DiscordMemberFinderUtil; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -20,18 +18,23 @@ import org.springframework.stereotype.Component; import java.awt.Color; @Component -@RequiredArgsConstructor public class AddPvmListener implements PrivateListener { - @NonNull private final EventWaiterUtil eventWaiterUtil; - @NonNull private final DiscordMemberFinderUtil discordMemberFinderUtil; - @NonNull private final PvmRoleUserService pvmRoleUserService; - @NonNull private final PvmRoleSnapshotComparatorService pvmRoleSnapshotComparatorService; + public AddPvmListener(EventWaiterUtil eventWaiterUtil, + DiscordMemberFinderUtil discordMemberFinderUtil, + PvmRoleUserService pvmRoleUserService, + PvmRoleSnapshotComparatorService pvmRoleSnapshotComparatorService) { + this.eventWaiterUtil = eventWaiterUtil; + this.discordMemberFinderUtil = discordMemberFinderUtil; + this.pvmRoleUserService = pvmRoleUserService; + this.pvmRoleSnapshotComparatorService = pvmRoleSnapshotComparatorService; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); @@ -45,7 +48,7 @@ public class AddPvmListener implements PrivateListener { eventWaiterUtil.waitForPrivateChannelEvent((rsnReceiver) -> { String creator = JdaUtil.getName(event); try { - PvmRoleUser pvmRoleUser = pvmRoleUserService.save(PvmRoleUser.builder() + PvmRoleUser pvmRoleUser = pvmRoleUserService.save(PvmRoleUser.Builder.newBuilder() .rsn(rsnReceiver.getMessage().getContentRaw()) .discordName(member.getEffectiveName()) .createdBy(creator) diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/pvmrole/DeletePvmListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/pvmrole/DeletePvmListener.java @@ -7,24 +7,26 @@ import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; import com.sxcy.sxcybot.services.guild.pvmrole.PvmKcSnapshotService; import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleUserService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; import org.springframework.stereotype.Component; @Component -@RequiredArgsConstructor public class DeletePvmListener implements PrivateListener { - @NonNull private final PvmRoleUserService pvmRoleUserService; - @NonNull private final PvmKcSnapshotService pvmKcSnapshotService; - @NonNull private final EventWaiterUtil eventWaiterUtil; + public DeletePvmListener(PvmRoleUserService pvmRoleUserService, + PvmKcSnapshotService pvmKcSnapshotService, + EventWaiterUtil eventWaiterUtil) { + this.pvmRoleUserService = pvmRoleUserService; + this.pvmKcSnapshotService = pvmKcSnapshotService; + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/pvmrole/UpdatePvmListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/pvmrole/UpdatePvmListener.java @@ -6,8 +6,6 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleUserService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -21,14 +19,17 @@ import static com.sxcy.sxcybot.enums.Command.PVMLIST; import static com.sxcy.sxcybot.util.Constants.Commands.COMMAND_PREFIX; @Component -@RequiredArgsConstructor public class UpdatePvmListener implements PrivateListener { - @NonNull private final PvmRoleUserService pvmRoleUserService; - @NonNull private final EventWaiterUtil eventWaiterUtil; + public UpdatePvmListener(PvmRoleUserService pvmRoleUserService, + EventWaiterUtil eventWaiterUtil) { + this.pvmRoleUserService = pvmRoleUserService; + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); @@ -41,10 +42,10 @@ public class UpdatePvmListener implements PrivateListener { eventWaiterUtil.waitForPrivateChannelEvent(discordNameReceiver -> { String discordName = discordNameReceiver.getMessage().getContentRaw(); try { - PvmRoleUser oldPvmRoleUser = pvmRoleUserService.findByDiscordName(discordName); + PvmRoleUser pvmRoleUserToUpdate = pvmRoleUserService.findByDiscordName(discordName); embedBuilder.addField("Confirm by typing ``yes or y``.", String.format("Is " + System.lineSeparator() + "Discord: %s | RSN: %s " + System.lineSeparator() + "the correct member?" - , oldPvmRoleUser.getDiscordName(), oldPvmRoleUser.getRsn()), false); + , pvmRoleUserToUpdate.getDiscordName(), pvmRoleUserToUpdate.getRsn()), false); privateChannel.sendMessageEmbeds(embedBuilder.build()).queue(); embedBuilder.clearFields(); eventWaiterUtil.waitForPrivateChannelEvent(memberVerifyReceiver -> { @@ -55,13 +56,11 @@ public class UpdatePvmListener implements PrivateListener { embedBuilder.clearFields(); eventWaiterUtil.waitForPrivateChannelEvent(newRsnReceiver -> { String newRsn = newRsnReceiver.getMessage().getContentRaw(); - PvmRoleUser pvmRoleUser = oldPvmRoleUser.toBuilder() - .rsn(newRsn) - .lastModifiedBy(JdaUtil.getName(event)) - .build(); + pvmRoleUserToUpdate.setRsn(newRsn); + pvmRoleUserToUpdate.setLastModifiedBy(JdaUtil.getName(event)); try { - pvmRoleUser = pvmRoleUserService.save(pvmRoleUser); - newRsnReceiver.getChannel().sendMessage(pvmRoleUser + " edited").queue(); + PvmRoleUser savedPvmRoleUser = pvmRoleUserService.save(pvmRoleUserToUpdate); + newRsnReceiver.getChannel().sendMessage(savedPvmRoleUser + " edited").queue(); event.getChannel().sendMessage(String.format("RSN for PvM competitor %s has been changed to %s by %s", discordName, newRsn, JdaUtil.getUser(event))).queue(); } catch (DataIntegrityViolationException e) { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/role/AddRoleListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/role/AddRoleListener.java @@ -5,8 +5,6 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.dao.GuildRole; import com.sxcy.sxcybot.services.guild.GuildRoleService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -19,14 +17,17 @@ import java.util.Optional; import static com.sxcy.sxcybot.util.Constants.ADDED_ROLE_ELEVATION; @Component -@RequiredArgsConstructor public class AddRoleListener implements PrivateListener { - @NonNull private final GuildRoleService guildRoleService; - @NonNull private final EventWaiterUtil eventWaiterUtil; + public AddRoleListener(GuildRoleService guildRoleService, + EventWaiterUtil eventWaiterUtil) { + this.guildRoleService = guildRoleService; + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); @@ -36,7 +37,7 @@ public class AddRoleListener implements PrivateListener { Optional<Role> role = event.getGuild().getRoles().stream().filter(f -> roleName.equalsIgnoreCase(f.getName())).findFirst(); if (role.isPresent()) { int orderValue = guildRoleService.findAll().stream().filter(f -> f.getOrderValue() != null).max(Comparator.comparing(GuildRole::getOrderValue)).map(GuildRole::getOrderValue).orElse(0) + 1; - GuildRole roleToAdd = GuildRole.builder() + GuildRole roleToAdd = GuildRole.Builder.newBuilder() .name(roleName) .orderValue(orderValue) .elevation(ADDED_ROLE_ELEVATION) diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/role/DeleteRoleListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/role/DeleteRoleListener.java @@ -6,8 +6,6 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.dao.GuildRole; import com.sxcy.sxcybot.services.guild.GuildRoleService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; @@ -17,14 +15,17 @@ import static com.sxcy.sxcybot.util.Constants.ADDED_ROLE_ELEVATION; import static com.sxcy.sxcybot.util.Constants.Commands.COMMAND_PREFIX; @Component -@RequiredArgsConstructor public class DeleteRoleListener implements PrivateListener { - @NonNull private final GuildRoleService guildRoleService; - @NonNull private final EventWaiterUtil eventWaiterUtil; + public DeleteRoleListener(GuildRoleService guildRoleService, + EventWaiterUtil eventWaiterUtil) { + this.guildRoleService = guildRoleService; + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); @@ -32,10 +33,13 @@ public class DeleteRoleListener implements PrivateListener { eventWaiterUtil.waitForPrivateChannelEvent(nameReceiver -> { try { GuildRole guildRole = guildRoleService.findByName(nameReceiver.getMessage().getContentRaw()); - if (guildRole.getElevation() == ADDED_ROLE_ELEVATION){ + if (guildRole.getElevation() == ADDED_ROLE_ELEVATION) { guildRoleService.delete(guildRole); guildRoleService.findAll().stream().filter(f -> f.getOrderValue() != null && f.getOrderValue() > guildRole.getOrderValue()).toList() - .forEach(f -> guildRoleService.save(f.toBuilder().orderValue(f.getOrderValue() - 1).build())); + .forEach(role -> { + role.setOrderValue(role.getOrderValue() - 1); + guildRoleService.save(role); + }); privateChannel.sendMessage(String.format("%s succesfully deleted.", guildRole)).queue(); event.getChannel().sendMessage(String.format("Role %s has been deleted by %s", guildRole, JdaUtil.getUser(event))).queue(); } else { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/role/UpdateRoleListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/role/UpdateRoleListener.java @@ -6,8 +6,6 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.dao.GuildRole; import com.sxcy.sxcybot.services.guild.GuildRoleService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; @@ -17,14 +15,17 @@ import static com.sxcy.sxcybot.util.Constants.ADDED_ROLE_ELEVATION; import static com.sxcy.sxcybot.util.Constants.Commands.COMMAND_PREFIX; @Component -@RequiredArgsConstructor public class UpdateRoleListener implements PrivateListener { - @NonNull private final GuildRoleService guildRoleService; - @NonNull private final EventWaiterUtil eventWaiterUtil; + public UpdateRoleListener(GuildRoleService guildRoleService, + EventWaiterUtil eventWaiterUtil) { + this.guildRoleService = guildRoleService; + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); @@ -36,10 +37,10 @@ public class UpdateRoleListener implements PrivateListener { try { GuildRole oldRole = guildRoleService.findByName(roleName); if (oldRole.getElevation() == ADDED_ROLE_ELEVATION) { - GuildRole guildRole = guildRoleService.save(guildRoleService.findByName(roleName) - .toBuilder() - .name(newRoleNameReceiver.getMessage().getContentRaw()) - .build()); + GuildRole guildRoleToUpdate = guildRoleService.findByName(roleName); + guildRoleToUpdate.setName(newRoleNameReceiver.getMessage().getContentRaw()); + + GuildRole guildRole = guildRoleService.save(guildRoleToUpdate); newRoleNameReceiver.getChannel().sendMessage(guildRole + " edited").queue(); event.getChannel().sendMessage(String.format("Role %s has been changed to %s by %s", roleName, newRoleNameReceiver.getMessage().getContentRaw(), JdaUtil.getUser(event))).queue(); } else { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/rule/AddRuleListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/rule/AddRuleListener.java @@ -5,8 +5,6 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.dao.Rule; import com.sxcy.sxcybot.services.guild.RuleService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; import org.springframework.stereotype.Component; @@ -14,21 +12,24 @@ import org.springframework.stereotype.Component; import java.util.Comparator; @Component -@RequiredArgsConstructor public class AddRuleListener implements PrivateListener { - @NonNull private final RuleService ruleService; - @NonNull private final EventWaiterUtil eventWaiterUtil; + public AddRuleListener(RuleService ruleService, + EventWaiterUtil eventWaiterUtil) { + this.ruleService = ruleService; + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { privateMessageReceivedEvent.getChannel().sendMessage("Type rule description please").queue(); eventWaiterUtil.waitForPrivateChannelEvent(e -> { String msg = e.getMessage().getContentRaw(); int number = ruleService.findAll().stream().max(Comparator.comparing(Rule::getNumber)).map(Rule::getNumber).orElse(0) + 1; - Rule rule = ruleService.save(Rule.builder() + Rule rule = ruleService.save(Rule.Builder.newBuilder() .number(number) .description(msg) .build()); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/rule/DeleteRuleListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/rule/DeleteRuleListener.java @@ -6,8 +6,6 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.dao.Rule; import com.sxcy.sxcybot.services.guild.RuleService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; @@ -15,14 +13,17 @@ import org.springframework.stereotype.Component; @Component -@RequiredArgsConstructor public class DeleteRuleListener implements PrivateListener { - @NonNull private final RuleService ruleService; - @NonNull private final EventWaiterUtil eventWaiterUtil; + public DeleteRuleListener(RuleService ruleService, + EventWaiterUtil eventWaiterUtil) { + this.ruleService = ruleService; + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); @@ -33,7 +34,10 @@ public class DeleteRuleListener implements PrivateListener { Rule rule = ruleService.findByNumber(ruleNumber); ruleService.delete(rule); ruleService.findAll().stream().filter(f -> f.getNumber() > ruleNumber).toList() - .forEach(f -> ruleService.save(f.toBuilder().number(f.getNumber() - 1).build())); + .forEach(ruleToUpdate -> { + ruleToUpdate.setNumber(ruleToUpdate.getNumber() - 1); + ruleService.save(ruleToUpdate); + }); privateChannel.sendMessage(String.format("%s has been succesfully deleted.", rule)).queue(); event.getChannel().sendMessage(String.format("Rule %s has been deleted by %s", rule, JdaUtil.getUser(event))).queue(); } catch (NumberFormatException e) { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/admin/rule/UpdateRuleListener.java b/src/main/java/com/sxcy/sxcybot/listeners/admin/rule/UpdateRuleListener.java @@ -6,8 +6,6 @@ import com.sxcy.sxcybot.listeners.PrivateListener; import com.sxcy.sxcybot.repository.guild.dao.Rule; import com.sxcy.sxcybot.services.guild.RuleService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; @@ -15,14 +13,17 @@ import org.springframework.stereotype.Component; @Component -@RequiredArgsConstructor public class UpdateRuleListener implements PrivateListener { - @NonNull private final RuleService ruleService; - @NonNull private final EventWaiterUtil eventWaiterUtil; + public UpdateRuleListener(RuleService ruleService, + EventWaiterUtil eventWaiterUtil) { + this.ruleService = ruleService; + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(PrivateMessageReceivedEvent privateMessageReceivedEvent, MessageReceivedEvent event) { PrivateChannel privateChannel = privateMessageReceivedEvent.getChannel(); @@ -33,10 +34,9 @@ public class UpdateRuleListener implements PrivateListener { privateChannel.sendMessage(String.format("Type the new rule description for rule %s.", ruleNumber)).queue(); eventWaiterUtil.waitForPrivateChannelEvent(descriptionReceiver -> { try { - Rule rule = ruleService.save(ruleService.findByNumber(ruleNumber) - .toBuilder() - .description(descriptionReceiver.getMessage().getContentRaw()) - .build()); + Rule ruleToUpdate = ruleService.findByNumber(ruleNumber); + ruleToUpdate.setDescription(descriptionReceiver.getMessage().getContentRaw()); + Rule rule = ruleService.save(ruleToUpdate); descriptionReceiver.getChannel().sendMessage(rule + " edited").queue(); event.getChannel().sendMessage(String.format("Rule #%s has been edited by %s", ruleNumber, JdaUtil.getUser(event))).queue(); } catch (EntityNotFoundException exc) { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/CombatStatsListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/CombatStatsListener.java @@ -5,8 +5,6 @@ import com.sxcy.sxcybot.model.CombatDto; import com.sxcy.sxcybot.model.OsrsStat; import com.sxcy.sxcybot.services.osrs.CombatCalculatorService; import com.sxcy.sxcybot.services.osrs.StatMessageSender; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.springframework.stereotype.Component; @@ -22,29 +20,32 @@ import static com.sxcy.sxcybot.enums.OsrsCombatStat.RANGED; import static com.sxcy.sxcybot.enums.OsrsCombatStat.STRENGTH; @Component -@RequiredArgsConstructor public class CombatStatsListener implements Listener { - @NonNull private final StatMessageSender statMessageSender; - @NonNull private final CombatCalculatorService combatCalculatorService; private static final List<String> COMBAT_STAT_LIST = List.of(ATTACK.value, STRENGTH.value, DEFENCE.value, HITPOINTS.value, RANGED.value, PRAYER.value, MAGIC.value); + public CombatStatsListener(StatMessageSender statMessageSender, + CombatCalculatorService combatCalculatorService) { + this.statMessageSender = statMessageSender; + this.combatCalculatorService = combatCalculatorService; + } + @Override public void proces(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); event.getChannel().sendTyping().queue(e -> statMessageSender.sendStatMessage(event, embedBuilder, this::isCombatStat, - f -> embedBuilder.addField(f.getName(), "Level " + f.getLevel(), true) + f -> embedBuilder.addField(f.name(), "Level " + f.level(), true) , osrsStatList -> embedBuilder.addField("COMBAT", String.valueOf(combatCalculatorService.getCombatLevel(CombatDto.build(osrsStatList))), false) ) ); } private boolean isCombatStat(OsrsStat osrsStat) { - return COMBAT_STAT_LIST.contains(osrsStat.getName()); + return COMBAT_STAT_LIST.contains(osrsStat.name()); } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/CustomPollListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/CustomPollListener.java @@ -2,13 +2,12 @@ package com.sxcy.sxcybot.listeners.member; import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.util.CustomPollFiller; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -16,14 +15,17 @@ import org.springframework.stereotype.Component; import java.awt.Color; import java.util.LinkedHashSet; -@Slf4j @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -@RequiredArgsConstructor public class CustomPollListener implements Listener { - @NonNull + + private static final Logger LOGGER = LoggerFactory.getLogger(CustomPollListener.class); private final CustomPollFiller customPollFiller; + public CustomPollListener(CustomPollFiller customPollFiller) { + this.customPollFiller = customPollFiller; + } + @Override public void proces(MessageReceivedEvent event) { String msg = event.getMessage().getContentRaw(); @@ -39,7 +41,7 @@ public class CustomPollListener implements Listener { customPollFiller.fillPoll(privateChannel, event, embedBuilder, new LinkedHashSet<>()); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } catch (StringIndexOutOfBoundsException e) { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/EventListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/EventListener.java @@ -3,23 +3,24 @@ package com.sxcy.sxcybot.listeners.member; import com.sxcy.sxcybot.listeners.EventWaiterUtil; import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.repository.guild.dao.Event; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -@Slf4j @Component -@RequiredArgsConstructor public class EventListener implements Listener { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(EventListener.class); private final EventWaiterUtil eventWaiterUtil; + public EventListener(EventWaiterUtil eventWaiterUtil) { + this.eventWaiterUtil = eventWaiterUtil; + } + @Override public void proces(MessageReceivedEvent event) { if (!event.getAuthor().isBot() && event.getMember() != null) { @@ -38,7 +39,7 @@ public class EventListener implements Listener { }, event, privateChannel); }, event, privateChannel); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } @@ -48,7 +49,7 @@ public class EventListener implements Listener { PrivateMessageReceivedEvent timeZoneReceiver, PrivateMessageReceivedEvent dateReceiver, MessageReceivedEvent event) { - Event createdEvent = Event.builder() + Event createdEvent = Event.Builder.newBuilder() .name(nameReceiver.getMessage().getContentRaw()) .description(descriptionReceiver.getMessage().getContentRaw()) .build(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/ForumListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/ForumListener.java @@ -2,8 +2,6 @@ package com.sxcy.sxcybot.listeners.member; import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.services.guild.ChannelDetailService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -12,12 +10,14 @@ import org.springframework.stereotype.Component; import java.awt.Color; @Component -@RequiredArgsConstructor public class ForumListener implements Listener { - @NonNull private final ChannelDetailService channelDetailService; + public ForumListener(ChannelDetailService channelDetailService) { + this.channelDetailService = channelDetailService; + } + @Override public void proces(MessageReceivedEvent event) { channelDetailService.findAll().stream().findAny().ifPresent(channelDetail -> { diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/HiscoreBossListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/HiscoreBossListener.java @@ -5,8 +5,6 @@ import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.repository.osrs.dao.OsrsHiscoreBoss; import com.sxcy.sxcybot.services.osrs.OsrsHiscoreBossService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.springframework.stereotype.Component; @@ -15,12 +13,14 @@ import java.awt.Color; import java.util.List; @Component -@RequiredArgsConstructor public class HiscoreBossListener implements Listener { - @NonNull private final OsrsHiscoreBossService osrsHiscoreBossService; + public HiscoreBossListener(OsrsHiscoreBossService osrsHiscoreBossService) { + this.osrsHiscoreBossService = osrsHiscoreBossService; + } + @Override public void proces(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/KillCountListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/KillCountListener.java @@ -5,8 +5,6 @@ import com.sxcy.sxcybot.exceptions.EntityNotFoundException; import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.model.OsrsBossKc; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.springframework.stereotype.Component; @@ -15,11 +13,14 @@ import java.awt.Color; import java.util.List; @Component -@RequiredArgsConstructor public class KillCountListener implements Listener { - @NonNull + private final HiScoreClient hiScoreClient; + public KillCountListener(HiScoreClient hiScoreClient) { + this.hiScoreClient = hiScoreClient; + } + @Override public void proces(MessageReceivedEvent event) { String msg = event.getMessage().getContentRaw(); @@ -33,8 +34,8 @@ public class KillCountListener implements Listener { embedBuilder.setTitle(String.format("Killcount for %s", player)); embedBuilder.setColor(Color.RED); int i = 1; - bossKcList.stream().filter(f -> !"-1".equals(f.getKc())).forEach(f -> { - embedBuilder.addField(f.getName(), String.format("Kc: %s%sRank: %s", f.getKc(), System.lineSeparator(), f.getRank()), true); + bossKcList.stream().filter(f -> !"-1".equals(f.kc())).forEach(f -> { + embedBuilder.addField(f.name(), String.format("Kc: %s%sRank: %s", f.kc(), System.lineSeparator(), f.rank()), true); if (JdaUtil.requiresBuild(embedBuilder, bossKcList.size(), i)) { event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); embedBuilder.clearFields(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/PollListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/PollListener.java @@ -4,8 +4,6 @@ import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.repository.guild.dao.Poll; import com.sxcy.sxcybot.services.guild.PollService; import com.sxcy.sxcybot.util.Constants.Reaction; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.springframework.stereotype.Component; @@ -13,12 +11,14 @@ import org.springframework.stereotype.Component; import java.awt.Color; @Component -@RequiredArgsConstructor public class PollListener implements Listener { - @NonNull private final PollService pollService; + public PollListener(PollService pollService) { + this.pollService = pollService; + } + @Override public void proces(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); @@ -39,7 +39,7 @@ public class PollListener implements Listener { .and(message.addReaction(Reaction.CROSS_MARK_BUTTON)) .and(message.addReaction(Reaction.QUESTION_MARK)) .queue(); - pollService.save(Poll.builder().messageId(message.getId()).build()); + pollService.save(Poll.Builder.newBuilder().messageId(message.getId()).build()); })); } catch (StringIndexOutOfBoundsException e) { event.getChannel().sendMessage("Please enter a descriptive title for the poll after the command, separated by space.").queue(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/PriceListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/PriceListener.java @@ -3,8 +3,6 @@ package com.sxcy.sxcybot.listeners.member; import com.sxcy.sxcybot.client.GrandExchangeClient; import com.sxcy.sxcybot.exceptions.EntityNotFoundException; import com.sxcy.sxcybot.listeners.Listener; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.springframework.stereotype.Component; @@ -12,12 +10,14 @@ import org.springframework.stereotype.Component; import java.awt.Color; @Component -@RequiredArgsConstructor public class PriceListener implements Listener { - @NonNull private final GrandExchangeClient grandExchangeClient; + public PriceListener(GrandExchangeClient grandExchangeClient) { + this.grandExchangeClient = grandExchangeClient; + } + @Override public void proces(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/PvmListListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/PvmListListener.java @@ -4,8 +4,6 @@ import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleUserService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.springframework.stereotype.Component; @@ -14,12 +12,14 @@ import java.awt.Color; import java.util.List; @Component -@RequiredArgsConstructor public class PvmListListener implements Listener { - @NonNull private final PvmRoleUserService pvmRoleUserService; + public PvmListListener(PvmRoleUserService pvmRoleUserService) { + this.pvmRoleUserService = pvmRoleUserService; + } + @Override public void proces(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/PvmRoleCheckListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/PvmRoleCheckListener.java @@ -2,20 +2,23 @@ package com.sxcy.sxcybot.listeners.member; import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.services.OsrsMonitoringService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -@Slf4j @Component -@RequiredArgsConstructor public class PvmRoleCheckListener implements Listener { + private static final Logger LOGGER = LoggerFactory.getLogger(PvmRoleCheckListener.class); private final OsrsMonitoringService osrsMonitoringService; + public PvmRoleCheckListener(OsrsMonitoringService osrsMonitoringService) { + this.osrsMonitoringService = osrsMonitoringService; + } + @Override public void proces(MessageReceivedEvent event) { if (event.getMember() != null) { @@ -23,7 +26,7 @@ public class PvmRoleCheckListener implements Listener { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); osrsMonitoringService.monitorPvmRoleUserHiscores(privateChannel); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/PvmRolePollListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/PvmRolePollListener.java @@ -2,20 +2,23 @@ package com.sxcy.sxcybot.listeners.member; import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.services.PvMRoleResolver; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -@Slf4j @Component -@RequiredArgsConstructor public class PvmRolePollListener implements Listener { + private static final Logger LOGGER = LoggerFactory.getLogger(PvmRolePollListener.class); private final PvMRoleResolver pvMRoleResolver; + public PvmRolePollListener(PvMRoleResolver pvMRoleResolver) { + this.pvMRoleResolver = pvMRoleResolver; + } + @Override public void proces(MessageReceivedEvent event) { if (event.getMember() != null) { @@ -23,7 +26,7 @@ public class PvmRolePollListener implements Listener { PrivateChannel privateChannel = event.getMember().getUser().openPrivateChannel().complete(true); pvMRoleResolver.resolvePvMRoles(false, privateChannel); } catch (RateLimitedException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } } } diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/RuleListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/RuleListener.java @@ -6,8 +6,6 @@ import com.sxcy.sxcybot.exceptions.EntityNotFoundException; import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.services.guild.RuleService; import com.sxcy.sxcybot.util.Constants.Commands; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -17,12 +15,14 @@ import java.awt.Color; @Component -@RequiredArgsConstructor public class RuleListener implements Listener { - @NonNull private final RuleService ruleService; + public RuleListener(RuleService ruleService) { + this.ruleService = ruleService; + } + @Override public void proces(MessageReceivedEvent event) { MessageChannel channel = event.getChannel(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/RulesListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/RulesListener.java @@ -4,8 +4,6 @@ import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.repository.guild.dao.Rule; import com.sxcy.sxcybot.services.guild.RuleService; import com.sxcy.sxcybot.util.JdaUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.springframework.stereotype.Component; @@ -15,12 +13,14 @@ import java.util.Comparator; import java.util.List; @Component -@RequiredArgsConstructor public class RulesListener implements Listener { - @NonNull private final RuleService ruleService; + public RulesListener(RuleService ruleService) { + this.ruleService = ruleService; + } + @Override public void proces(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); diff --git a/src/main/java/com/sxcy/sxcybot/listeners/member/StatsListener.java b/src/main/java/com/sxcy/sxcybot/listeners/member/StatsListener.java @@ -2,30 +2,30 @@ package com.sxcy.sxcybot.listeners.member; import com.sxcy.sxcybot.listeners.Listener; import com.sxcy.sxcybot.services.osrs.StatMessageSender; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.springframework.stereotype.Component; -import javax.annotation.Nonnull; import java.util.Objects; @Component -@RequiredArgsConstructor public class StatsListener implements Listener { - @Nonnull private final StatMessageSender statMessageSender; + public StatsListener(StatMessageSender statMessageSender) { + this.statMessageSender = statMessageSender; + } + @Override public void proces(MessageReceivedEvent event) { EmbedBuilder embedBuilder = new EmbedBuilder(); event.getChannel().sendTyping().queue(e -> statMessageSender.sendStatMessage(event, embedBuilder, Objects::nonNull, - f -> embedBuilder.addField(f.getName(), - "Level " + f.getLevel() + System.lineSeparator() + - "Rank " + f.getRank() + System.lineSeparator() + - "Exp " + f.getExperience(), true), null + f -> embedBuilder.addField(f.name(), + "Level " + f.level() + System.lineSeparator() + + "Rank " + f.rank() + System.lineSeparator() + + "Exp " + f.experience(), true), null )); } } diff --git a/src/main/java/com/sxcy/sxcybot/model/CombatDto.java b/src/main/java/com/sxcy/sxcybot/model/CombatDto.java @@ -1,8 +1,5 @@ package com.sxcy.sxcybot.model; -import lombok.Builder; -import lombok.Value; - import java.util.List; import static com.sxcy.sxcybot.enums.OsrsCombatStat.ATTACK; @@ -13,43 +10,121 @@ import static com.sxcy.sxcybot.enums.OsrsCombatStat.PRAYER; import static com.sxcy.sxcybot.enums.OsrsCombatStat.RANGED; import static com.sxcy.sxcybot.enums.OsrsCombatStat.STRENGTH; -@Value -@Builder(toBuilder = true) -public class CombatDto { +public record CombatDto( + int attackLevel, + int strengthLevel, + int defenceLevel, + int hitpointsLevel, + int magicLevel, + int rangeLevel, + int prayerLevel +) { + - int attackLevel; - int strengthLevel; - int defenceLevel; - int hitpointsLevel; - int magicLevel; - int rangeLevel; - int prayerLevel; + private CombatDto(Builder builder) { + this(builder.attackLevel, + builder.strengthLevel, + builder.defenceLevel, + builder.hitpointsLevel, + builder.magicLevel, + builder.rangeLevel, + builder.prayerLevel); + } public static CombatDto build(List<OsrsStat> osrsStatList) { - CombatDto.CombatDtoBuilder builder = CombatDto.builder(); + CombatDto.Builder builder = CombatDto.Builder.newBuilder(); for (OsrsStat osrsStat : osrsStatList) { - if (ATTACK.value.equalsIgnoreCase(osrsStat.getName())) { - builder.attackLevel(Integer.parseInt(osrsStat.getLevel())); + if (ATTACK.value.equalsIgnoreCase(osrsStat.name())) { + builder.attackLevel(Integer.parseInt(osrsStat.level())); } - if (STRENGTH.value.equalsIgnoreCase(osrsStat.getName())) { - builder.strengthLevel(Integer.parseInt(osrsStat.getLevel())); + if (STRENGTH.value.equalsIgnoreCase(osrsStat.name())) { + builder.strengthLevel(Integer.parseInt(osrsStat.level())); } - if (DEFENCE.value.equalsIgnoreCase(osrsStat.getName())) { - builder.defenceLevel(Integer.parseInt(osrsStat.getLevel())); + if (DEFENCE.value.equalsIgnoreCase(osrsStat.name())) { + builder.defenceLevel(Integer.parseInt(osrsStat.level())); } - if (HITPOINTS.value.equalsIgnoreCase(osrsStat.getName())) { - builder.hitpointsLevel(Integer.parseInt(osrsStat.getLevel())); + if (HITPOINTS.value.equalsIgnoreCase(osrsStat.name())) { + builder.hitpointsLevel(Integer.parseInt(osrsStat.level())); } - if (MAGIC.value.equalsIgnoreCase(osrsStat.getName())) { - builder.magicLevel(Integer.parseInt(osrsStat.getLevel())); + if (MAGIC.value.equalsIgnoreCase(osrsStat.name())) { + builder.magicLevel(Integer.parseInt(osrsStat.level())); } - if (RANGED.value.equalsIgnoreCase(osrsStat.getName())) { - builder.rangeLevel(Integer.parseInt(osrsStat.getLevel())); + if (RANGED.value.equalsIgnoreCase(osrsStat.name())) { + builder.rangeLevel(Integer.parseInt(osrsStat.level())); } - if (PRAYER.value.equalsIgnoreCase(osrsStat.getName())) { - builder.prayerLevel(Integer.parseInt(osrsStat.getLevel())); + if (PRAYER.value.equalsIgnoreCase(osrsStat.name())) { + builder.prayerLevel(Integer.parseInt(osrsStat.level())); } } return builder.build(); } + + public static final class Builder { + private int attackLevel; + private int strengthLevel; + private int defenceLevel; + private int hitpointsLevel; + private int magicLevel; + private int rangeLevel; + private int prayerLevel; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder attackLevel(int val) { + attackLevel = val; + return this; + } + + public Builder strengthLevel(int val) { + strengthLevel = val; + return this; + } + + public Builder defenceLevel(int val) { + defenceLevel = val; + return this; + } + + public Builder hitpointsLevel(int val) { + hitpointsLevel = val; + return this; + } + + public Builder magicLevel(int val) { + magicLevel = val; + return this; + } + + public Builder rangeLevel(int val) { + rangeLevel = val; + return this; + } + + public Builder prayerLevel(int val) { + prayerLevel = val; + return this; + } + + public CombatDto build() { + return new CombatDto(this); + } + } + + @Override + public String toString() { + return "CombatDto{" + + "attackLevel=" + attackLevel + + ", strengthLevel=" + strengthLevel + + ", defenceLevel=" + defenceLevel + + ", hitpointsLevel=" + hitpointsLevel + + ", magicLevel=" + magicLevel + + ", rangeLevel=" + rangeLevel + + ", prayerLevel=" + prayerLevel + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/model/EditListenerDto.java b/src/main/java/com/sxcy/sxcybot/model/EditListenerDto.java @@ -1,25 +1,93 @@ package com.sxcy.sxcybot.model; import com.sxcy.sxcybot.listeners.PrivateListener; -import lombok.Builder; -import lombok.NonNull; -import lombok.Value; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import org.jetbrains.annotations.NotNull; -@Value -@Builder(toBuilder = true) -public class EditListenerDto { - - @NonNull - PrivateListener addListener; - PrivateListener updateListener; - @NonNull - PrivateListener deleteListener; - @NonNull - MessageReceivedEvent event; - @NonNull - PrivateChannel privateChannel; - @NonNull - String entityName; +public record EditListenerDto( + @NotNull + PrivateListener addListener, + PrivateListener updateListener, + @NotNull + PrivateListener deleteListener, + @NotNull + MessageReceivedEvent event, + @NotNull + PrivateChannel privateChannel, + @NotNull + String entityName +) { + + + private EditListenerDto(Builder builder) { + this(builder.addListener, + builder.updateListener, + builder.deleteListener, + builder.event, + builder.privateChannel, + builder.entityName); + } + + public static final class Builder { + private @NotNull PrivateListener addListener; + private PrivateListener updateListener; + private @NotNull PrivateListener deleteListener; + private @NotNull MessageReceivedEvent event; + private @NotNull PrivateChannel privateChannel; + private @NotNull String entityName; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder addListener(@NotNull PrivateListener val) { + addListener = val; + return this; + } + + public Builder updateListener(PrivateListener val) { + updateListener = val; + return this; + } + + public Builder deleteListener(@NotNull PrivateListener val) { + deleteListener = val; + return this; + } + + public Builder event(@NotNull MessageReceivedEvent val) { + event = val; + return this; + } + + public Builder privateChannel(@NotNull PrivateChannel val) { + privateChannel = val; + return this; + } + + public Builder entityName(@NotNull String val) { + entityName = val; + return this; + } + + public EditListenerDto build() { + return new EditListenerDto(this); + } + } + + @Override + public String toString() { + return "EditListenerDto{" + + "addListener=" + addListener + + ", updateListener=" + updateListener + + ", deleteListener=" + deleteListener + + ", event=" + event + + ", privateChannel=" + privateChannel + + ", entityName='" + entityName + '\'' + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/model/OsrsBossKc.java b/src/main/java/com/sxcy/sxcybot/model/OsrsBossKc.java @@ -1,14 +1,56 @@ package com.sxcy.sxcybot.model; -import lombok.Builder; -import lombok.Value; +public record OsrsBossKc( + String name, + String rank, + String kc -@Value -@Builder(toBuilder = true) -public class OsrsBossKc { +) { - String name; - String rank; - String kc; + private OsrsBossKc(Builder builder) { + this(builder.name, + builder.rank, + builder.kc); + } + public static final class Builder { + private String name; + private String rank; + private String kc; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder name(String val) { + name = val; + return this; + } + + public Builder rank(String val) { + rank = val; + return this; + } + + public Builder kc(String val) { + kc = val; + return this; + } + + public OsrsBossKc build() { + return new OsrsBossKc(this); + } + } + + @Override + public String toString() { + return "OsrsBossKc{" + + "name='" + name + '\'' + + ", rank='" + rank + '\'' + + ", kc='" + kc + '\'' + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/model/OsrsItem.java b/src/main/java/com/sxcy/sxcybot/model/OsrsItem.java @@ -1,20 +1,64 @@ package com.sxcy.sxcybot.model; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@JsonDeserialize -@Builder(toBuilder = true) -@Data -@AllArgsConstructor -@NoArgsConstructor -public class OsrsItem { - - private String id; - private String timestamp; - private Integer price; - private String volume; +public record OsrsItem( + String id, + String timestamp, + Integer price, + String volume +) { + + private OsrsItem(Builder builder) { + this(builder.id, + builder.timestamp, + builder.price, + builder.volume); + } + + public static final class Builder { + private String id; + private String timestamp; + private Integer price; + private String volume; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder timestamp(String val) { + timestamp = val; + return this; + } + + public Builder price(Integer val) { + price = val; + return this; + } + + public Builder volume(String val) { + volume = val; + return this; + } + + public OsrsItem build() { + return new OsrsItem(this); + } + } + + @Override + public String toString() { + return "OsrsItem{" + + "id='" + id + '\'' + + ", timestamp='" + timestamp + '\'' + + ", price=" + price + + ", volume='" + volume + '\'' + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/model/OsrsStat.java b/src/main/java/com/sxcy/sxcybot/model/OsrsStat.java @@ -1,14 +1,65 @@ package com.sxcy.sxcybot.model; -import lombok.Builder; -import lombok.Value; +public record OsrsStat( + String name, + String experience, + String rank, + String level +) { -@Value -@Builder(toBuilder = true) -public class OsrsStat { - String name; - String experience; - String rank; - String level; + private OsrsStat(Builder builder) { + this(builder.name, + builder.experience, + builder.rank, + builder.level); + } + + public static final class Builder { + private String name; + private String experience; + private String rank; + private String level; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder name(String val) { + name = val; + return this; + } + + public Builder experience(String val) { + experience = val; + return this; + } + + public Builder rank(String val) { + rank = val; + return this; + } + + public Builder level(String val) { + level = val; + return this; + } + + public OsrsStat build() { + return new OsrsStat(this); + } + } + + @Override + public String toString() { + return "OsrsStat{" + + "name='" + name + '\'' + + ", experience='" + experience + '\'' + + ", rank='" + rank + '\'' + + ", level='" + level + '\'' + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/dao/ChannelDetail.java b/src/main/java/com/sxcy/sxcybot/repository/guild/dao/ChannelDetail.java @@ -3,17 +3,9 @@ package com.sxcy.sxcybot.repository.guild.dao; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor public class ChannelDetail { @Id @GeneratedValue(generator = "uuid") @@ -25,4 +17,142 @@ public class ChannelDetail { private String pvmRoleGeneral; private String pvmRoleRaids; private String pvmRoleWilderness; + + protected ChannelDetail() { + } + + private ChannelDetail(Builder builder) { + setId(builder.id); + setForumUrl(builder.forumUrl); + setBotUpdateChannel(builder.botUpdateChannel); + setPvmRoleChannel(builder.pvmRoleChannel); + setPvmRoleGeneral(builder.pvmRoleGeneral); + setPvmRoleRaids(builder.pvmRoleRaids); + setPvmRoleWilderness(builder.pvmRoleWilderness); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getForumUrl() { + return forumUrl; + } + + public void setForumUrl(String forumUrl) { + this.forumUrl = forumUrl; + } + + public String getBotUpdateChannel() { + return botUpdateChannel; + } + + public void setBotUpdateChannel(String botUpdateChannel) { + this.botUpdateChannel = botUpdateChannel; + } + + public String getPvmRoleChannel() { + return pvmRoleChannel; + } + + public void setPvmRoleChannel(String pvmRoleChannel) { + this.pvmRoleChannel = pvmRoleChannel; + } + + public String getPvmRoleGeneral() { + return pvmRoleGeneral; + } + + public void setPvmRoleGeneral(String pvmRoleGeneral) { + this.pvmRoleGeneral = pvmRoleGeneral; + } + + public String getPvmRoleRaids() { + return pvmRoleRaids; + } + + public void setPvmRoleRaids(String pvmRoleRaids) { + this.pvmRoleRaids = pvmRoleRaids; + } + + public String getPvmRoleWilderness() { + return pvmRoleWilderness; + } + + public void setPvmRoleWilderness(String pvmRoleWilderness) { + this.pvmRoleWilderness = pvmRoleWilderness; + } + + public static final class Builder { + private String id; + private String forumUrl; + private String botUpdateChannel; + private String pvmRoleChannel; + private String pvmRoleGeneral; + private String pvmRoleRaids; + private String pvmRoleWilderness; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder forumUrl(String val) { + forumUrl = val; + return this; + } + + public Builder botUpdateChannel(String val) { + botUpdateChannel = val; + return this; + } + + public Builder pvmRoleChannel(String val) { + pvmRoleChannel = val; + return this; + } + + public Builder pvmRoleGeneral(String val) { + pvmRoleGeneral = val; + return this; + } + + public Builder pvmRoleRaids(String val) { + pvmRoleRaids = val; + return this; + } + + public Builder pvmRoleWilderness(String val) { + pvmRoleWilderness = val; + return this; + } + + public ChannelDetail build() { + return new ChannelDetail(this); + } + } + + @Override + public String toString() { + return "ChannelDetail{" + + "id='" + id + '\'' + + ", forumUrl='" + forumUrl + '\'' + + ", botUpdateChannel='" + botUpdateChannel + '\'' + + ", pvmRoleChannel='" + pvmRoleChannel + '\'' + + ", pvmRoleGeneral='" + pvmRoleGeneral + '\'' + + ", pvmRoleRaids='" + pvmRoleRaids + '\'' + + ", pvmRoleWilderness='" + pvmRoleWilderness + '\'' + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/dao/Event.java b/src/main/java/com/sxcy/sxcybot/repository/guild/dao/Event.java @@ -1,20 +1,85 @@ package com.sxcy.sxcybot.repository.guild.dao; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - import java.time.LocalDate; -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor public class Event { private String name; private String description; private LocalDate time; + protected Event() { + + } + + private Event(Builder builder) { + setName(builder.name); + setDescription(builder.description); + setTime(builder.time); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public LocalDate getTime() { + return time; + } + + public void setTime(LocalDate time) { + this.time = time; + } + + public static final class Builder { + private String name; + private String description; + private LocalDate time; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder name(String val) { + name = val; + return this; + } + + public Builder description(String val) { + description = val; + return this; + } + + public Builder time(LocalDate val) { + time = val; + return this; + } + + public Event build() { + return new Event(this); + } + } + + @Override + public String toString() { + return "Event{" + + "name='" + name + '\'' + + ", description='" + description + '\'' + + ", time=" + time + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/dao/GuildEventDmer.java b/src/main/java/com/sxcy/sxcybot/repository/guild/dao/GuildEventDmer.java @@ -3,25 +3,73 @@ package com.sxcy.sxcybot.repository.guild.dao; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.ToString.Exclude; import org.hibernate.annotations.GenericGenerator; -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor @Entity public class GuildEventDmer { @Id @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid") - @Exclude private String id; private String name; + + private GuildEventDmer(Builder builder) { + setId(builder.id); + setName(builder.name); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + protected GuildEventDmer() { + } + + public static final class Builder { + private String id; + private String name; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder name(String val) { + name = val; + return this; + } + + public GuildEventDmer build() { + return new GuildEventDmer(this); + } + } + + @Override + public String toString() { + return "GuildEventDmer{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/dao/GuildRole.java b/src/main/java/com/sxcy/sxcybot/repository/guild/dao/GuildRole.java @@ -3,18 +3,10 @@ package com.sxcy.sxcybot.repository.guild.dao; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor public class GuildRole { @Id @@ -24,4 +16,94 @@ public class GuildRole { private String name; private Integer orderValue; private int elevation; + + protected GuildRole() { + } + + private GuildRole(Builder builder) { + setId(builder.id); + setName(builder.name); + setOrderValue(builder.orderValue); + setElevation(builder.elevation); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getOrderValue() { + return orderValue; + } + + public void setOrderValue(Integer orderValue) { + this.orderValue = orderValue; + } + + public int getElevation() { + return elevation; + } + + public void setElevation(int elevation) { + this.elevation = elevation; + } + + public static final class Builder { + private String id; + private String name; + private Integer orderValue; + private int elevation; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder name(String val) { + name = val; + return this; + } + + public Builder orderValue(Integer val) { + orderValue = val; + return this; + } + + public Builder elevation(int val) { + elevation = val; + return this; + } + + public GuildRole build() { + return new GuildRole(this); + } + } + + @Override + public String toString() { + return "GuildRole{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", orderValue=" + orderValue + + ", elevation=" + elevation + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/dao/Poll.java b/src/main/java/com/sxcy/sxcybot/repository/guild/dao/Poll.java @@ -4,10 +4,6 @@ import jakarta.persistence.Entity; import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -16,10 +12,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor @EntityListeners(AuditingEntityListener.class) public class Poll { @@ -34,4 +26,93 @@ public class Poll { @LastModifiedDate private LocalDateTime lastModifiedDate; + protected Poll() { + } + + private Poll(Builder builder) { + setId(builder.id); + setMessageId(builder.messageId); + setCreatedDate(builder.createdDate); + setLastModifiedDate(builder.lastModifiedDate); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public LocalDateTime getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(LocalDateTime createdDate) { + this.createdDate = createdDate; + } + + public LocalDateTime getLastModifiedDate() { + return lastModifiedDate; + } + + public void setLastModifiedDate(LocalDateTime lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } + + public static final class Builder { + private String id; + private String messageId; + private LocalDateTime createdDate; + private LocalDateTime lastModifiedDate; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder messageId(String val) { + messageId = val; + return this; + } + + public Builder createdDate(LocalDateTime val) { + createdDate = val; + return this; + } + + public Builder lastModifiedDate(LocalDateTime val) { + lastModifiedDate = val; + return this; + } + + public Poll build() { + return new Poll(this); + } + } + + @Override + public String toString() { + return "Poll{" + + "id='" + id + '\'' + + ", messageId='" + messageId + '\'' + + ", createdDate=" + createdDate + + ", lastModifiedDate=" + lastModifiedDate + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/dao/Rule.java b/src/main/java/com/sxcy/sxcybot/repository/guild/dao/Rule.java @@ -3,27 +3,91 @@ package com.sxcy.sxcybot.repository.guild.dao; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.ToString.Exclude; import org.hibernate.annotations.GenericGenerator; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor public class Rule { @Id @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid") - @Exclude private String id; private int number; private String description; + + protected Rule() { + } + + private Rule(Builder builder) { + setId(builder.id); + setNumber(builder.number); + setDescription(builder.description); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public static final class Builder { + private String id; + private int number; + private String description; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder number(int val) { + number = val; + return this; + } + + public Builder description(String val) { + description = val; + return this; + } + + public Rule build() { + return new Rule(this); + } + } + + @Override + public String toString() { + return "Rule{" + + "id='" + id + '\'' + + ", number=" + number + + ", description='" + description + '\'' + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/dao/User.java b/src/main/java/com/sxcy/sxcybot/repository/guild/dao/User.java @@ -4,11 +4,6 @@ import jakarta.persistence.Entity; import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.ToString.Exclude; import org.hibernate.annotations.GenericGenerator; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -17,17 +12,12 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDate; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor @EntityListeners(AuditingEntityListener.class) public class User { @Id @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid") - @Exclude private String id; private String name; private String description; @@ -38,4 +28,158 @@ public class User { @LastModifiedDate private LocalDate lastModifiedDate; private String lastModifiedBy; + + protected User() { + } + + private User(Builder builder) { + setId(builder.id); + setName(builder.name); + setDescription(builder.description); + setBanned(builder.banned); + setCreatedDate(builder.createdDate); + setCreatedBy(builder.createdBy); + setLastModifiedDate(builder.lastModifiedDate); + setLastModifiedBy(builder.lastModifiedBy); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isBanned() { + return banned; + } + + public void setBanned(boolean banned) { + this.banned = banned; + } + + public LocalDate getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(LocalDate createdDate) { + this.createdDate = createdDate; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public LocalDate getLastModifiedDate() { + return lastModifiedDate; + } + + public void setLastModifiedDate(LocalDate lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } + + public String getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public static final class Builder { + private String id; + private String name; + private String description; + private boolean banned; + private LocalDate createdDate; + private String createdBy; + private LocalDate lastModifiedDate; + private String lastModifiedBy; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder name(String val) { + name = val; + return this; + } + + public Builder description(String val) { + description = val; + return this; + } + + public Builder banned(boolean val) { + banned = val; + return this; + } + + public Builder createdDate(LocalDate val) { + createdDate = val; + return this; + } + + public Builder createdBy(String val) { + createdBy = val; + return this; + } + + public Builder lastModifiedDate(LocalDate val) { + lastModifiedDate = val; + return this; + } + + public Builder lastModifiedBy(String val) { + lastModifiedBy = val; + return this; + } + + public User build() { + return new User(this); + } + } + + @Override + public String toString() { + return "User{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", description='" + description + '\'' + + ", banned=" + banned + + ", createdDate=" + createdDate + + ", createdBy='" + createdBy + '\'' + + ", lastModifiedDate=" + lastModifiedDate + + ", lastModifiedBy='" + lastModifiedBy + '\'' + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/pvmrole/dao/PvmKcSnapshot.java b/src/main/java/com/sxcy/sxcybot/repository/guild/pvmrole/dao/PvmKcSnapshot.java @@ -8,12 +8,6 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.ToString; import org.hibernate.annotations.GenericGenerator; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -24,10 +18,6 @@ import java.util.ArrayList; import java.util.List; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor @EntityListeners(AuditingEntityListener.class) public class PvmKcSnapshot { @@ -41,12 +31,118 @@ public class PvmKcSnapshot { private PvmRoleUser pvmRoleUser; @OneToMany(mappedBy = "pvmKcSnapshot", cascade = CascadeType.ALL, orphanRemoval = true) - @ToString.Exclude - @EqualsAndHashCode.Exclude private List<PvmUserKc> pvmUserKcList = new ArrayList<>(); @CreatedDate private LocalDateTime createdDate; @LastModifiedDate private LocalDateTime lastModifiedDate; + + protected PvmKcSnapshot() { + + } + + private PvmKcSnapshot(Builder builder) { + setId(builder.id); + setPvmRoleUser(builder.pvmRoleUser); + setPvmUserKcList(builder.pvmUserKcList); + setCreatedDate(builder.createdDate); + setLastModifiedDate(builder.lastModifiedDate); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public PvmRoleUser getPvmRoleUser() { + return pvmRoleUser; + } + + public void setPvmRoleUser(PvmRoleUser pvmRoleUser) { + this.pvmRoleUser = pvmRoleUser; + } + + public List<PvmUserKc> getPvmUserKcList() { + return pvmUserKcList; + } + + public void setPvmUserKcList(List<PvmUserKc> pvmUserKcList) { + this.pvmUserKcList = pvmUserKcList; + } + + public LocalDateTime getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(LocalDateTime createdDate) { + this.createdDate = createdDate; + } + + public LocalDateTime getLastModifiedDate() { + return lastModifiedDate; + } + + public void setLastModifiedDate(LocalDateTime lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } + + + public static final class Builder { + private String id; + private PvmRoleUser pvmRoleUser; + private List<PvmUserKc> pvmUserKcList; + private LocalDateTime createdDate; + private LocalDateTime lastModifiedDate; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder pvmRoleUser(PvmRoleUser val) { + pvmRoleUser = val; + return this; + } + + public Builder pvmUserKcList(List<PvmUserKc> val) { + pvmUserKcList = val; + return this; + } + + public Builder createdDate(LocalDateTime val) { + createdDate = val; + return this; + } + + public Builder lastModifiedDate(LocalDateTime val) { + lastModifiedDate = val; + return this; + } + + public PvmKcSnapshot build() { + return new PvmKcSnapshot(this); + } + } + + @Override + public String toString() { + return "PvmKcSnapshot{" + + "id='" + id + '\'' + + ", pvmRoleUser=" + pvmRoleUser + + ", pvmUserKcList=" + pvmUserKcList + + ", createdDate=" + createdDate + + ", lastModifiedDate=" + lastModifiedDate + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/pvmrole/dao/PvmRoleUser.java b/src/main/java/com/sxcy/sxcybot/repository/guild/pvmrole/dao/PvmRoleUser.java @@ -4,11 +4,6 @@ import jakarta.persistence.Entity; import jakarta.persistence.EntityListeners; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.ToString; import org.hibernate.annotations.GenericGenerator; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -17,17 +12,12 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor @EntityListeners(AuditingEntityListener.class) public class PvmRoleUser { @Id @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid") - @ToString.Exclude private String id; private String discordName; private String rsn; @@ -37,4 +27,143 @@ public class PvmRoleUser { @LastModifiedDate private LocalDateTime lastModifiedDate; private String lastModifiedBy; + + protected PvmRoleUser() { + + } + + private PvmRoleUser(Builder builder) { + setId(builder.id); + setDiscordName(builder.discordName); + setRsn(builder.rsn); + setCreatedDate(builder.createdDate); + setCreatedBy(builder.createdBy); + setLastModifiedDate(builder.lastModifiedDate); + setLastModifiedBy(builder.lastModifiedBy); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDiscordName() { + return discordName; + } + + public void setDiscordName(String discordName) { + this.discordName = discordName; + } + + public String getRsn() { + return rsn; + } + + public void setRsn(String rsn) { + this.rsn = rsn; + } + + public LocalDateTime getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(LocalDateTime createdDate) { + this.createdDate = createdDate; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public LocalDateTime getLastModifiedDate() { + return lastModifiedDate; + } + + public void setLastModifiedDate(LocalDateTime lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } + + public String getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public static final class Builder { + private String id; + private String discordName; + private String rsn; + private LocalDateTime createdDate; + private String createdBy; + private LocalDateTime lastModifiedDate; + private String lastModifiedBy; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder discordName(String val) { + discordName = val; + return this; + } + + public Builder rsn(String val) { + rsn = val; + return this; + } + + public Builder createdDate(LocalDateTime val) { + createdDate = val; + return this; + } + + public Builder createdBy(String val) { + createdBy = val; + return this; + } + + public Builder lastModifiedDate(LocalDateTime val) { + lastModifiedDate = val; + return this; + } + + public Builder lastModifiedBy(String val) { + lastModifiedBy = val; + return this; + } + + public PvmRoleUser build() { + return new PvmRoleUser(this); + } + } + + @Override + public String toString() { + return "PvmRoleUser{" + + "id='" + id + '\'' + + ", discordName='" + discordName + '\'' + + ", rsn='" + rsn + '\'' + + ", createdDate=" + createdDate + + ", createdBy='" + createdBy + '\'' + + ", lastModifiedDate=" + lastModifiedDate + + ", lastModifiedBy='" + lastModifiedBy + '\'' + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/guild/pvmrole/dao/PvmUserKc.java b/src/main/java/com/sxcy/sxcybot/repository/guild/pvmrole/dao/PvmUserKc.java @@ -8,10 +8,6 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToOne; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -20,10 +16,6 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor @EntityListeners(AuditingEntityListener.class) public class PvmUserKc { @@ -50,4 +42,143 @@ public class PvmUserKc { private LocalDateTime createdDate; @LastModifiedDate private LocalDateTime lastModifiedDate; + + protected PvmUserKc() { + + } + + private PvmUserKc(Builder builder) { + setId(builder.id); + setPvmRoleUser(builder.pvmRoleUser); + setOsrsHiscoreBoss(builder.osrsHiscoreBoss); + setKc(builder.kc); + setPvmKcSnapshot(builder.pvmKcSnapshot); + setCreatedDate(builder.createdDate); + setLastModifiedDate(builder.lastModifiedDate); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public PvmRoleUser getPvmRoleUser() { + return pvmRoleUser; + } + + public void setPvmRoleUser(PvmRoleUser pvmRoleUser) { + this.pvmRoleUser = pvmRoleUser; + } + + public OsrsHiscoreBoss getOsrsHiscoreBoss() { + return osrsHiscoreBoss; + } + + public void setOsrsHiscoreBoss(OsrsHiscoreBoss osrsHiscoreBoss) { + this.osrsHiscoreBoss = osrsHiscoreBoss; + } + + public Integer getKc() { + return kc; + } + + public void setKc(Integer kc) { + this.kc = kc; + } + + public PvmKcSnapshot getPvmKcSnapshot() { + return pvmKcSnapshot; + } + + public void setPvmKcSnapshot(PvmKcSnapshot pvmKcSnapshot) { + this.pvmKcSnapshot = pvmKcSnapshot; + } + + public LocalDateTime getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(LocalDateTime createdDate) { + this.createdDate = createdDate; + } + + public LocalDateTime getLastModifiedDate() { + return lastModifiedDate; + } + + public void setLastModifiedDate(LocalDateTime lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } + + public static final class Builder { + private String id; + private PvmRoleUser pvmRoleUser; + private OsrsHiscoreBoss osrsHiscoreBoss; + private Integer kc; + private PvmKcSnapshot pvmKcSnapshot; + private LocalDateTime createdDate; + private LocalDateTime lastModifiedDate; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder pvmRoleUser(PvmRoleUser val) { + pvmRoleUser = val; + return this; + } + + public Builder osrsHiscoreBoss(OsrsHiscoreBoss val) { + osrsHiscoreBoss = val; + return this; + } + + public Builder kc(Integer val) { + kc = val; + return this; + } + + public Builder pvmKcSnapshot(PvmKcSnapshot val) { + pvmKcSnapshot = val; + return this; + } + + public Builder createdDate(LocalDateTime val) { + createdDate = val; + return this; + } + + public Builder lastModifiedDate(LocalDateTime val) { + lastModifiedDate = val; + return this; + } + + public PvmUserKc build() { + return new PvmUserKc(this); + } + } + + @Override + public String toString() { + return "PvmUserKc{" + + "id='" + id + '\'' + + ", pvmRoleUser=" + pvmRoleUser + + ", osrsHiscoreBoss=" + osrsHiscoreBoss + + ", kc=" + kc + + ", pvmKcSnapshot=" + pvmKcSnapshot + + ", createdDate=" + createdDate + + ", lastModifiedDate=" + lastModifiedDate + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/osrs/dao/OsrsHiscoreBoss.java b/src/main/java/com/sxcy/sxcybot/repository/osrs/dao/OsrsHiscoreBoss.java @@ -3,18 +3,10 @@ package com.sxcy.sxcybot.repository.osrs.dao; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor public class OsrsHiscoreBoss { @Id @GeneratedValue(generator = "uuid") @@ -24,4 +16,111 @@ public class OsrsHiscoreBoss { private int orderValue; private double multiplier; private int pvmRole; + + protected OsrsHiscoreBoss() { + + } + + private OsrsHiscoreBoss(Builder builder) { + setId(builder.id); + setName(builder.name); + setOrderValue(builder.orderValue); + setMultiplier(builder.multiplier); + setPvmRole(builder.pvmRole); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getOrderValue() { + return orderValue; + } + + public void setOrderValue(int orderValue) { + this.orderValue = orderValue; + } + + public double getMultiplier() { + return multiplier; + } + + public void setMultiplier(double multiplier) { + this.multiplier = multiplier; + } + + public int getPvmRole() { + return pvmRole; + } + + public void setPvmRole(int pvmRole) { + this.pvmRole = pvmRole; + } + + public static final class Builder { + private String id; + private String name; + private int orderValue; + private double multiplier; + private int pvmRole; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder name(String val) { + name = val; + return this; + } + + public Builder orderValue(int val) { + orderValue = val; + return this; + } + + public Builder multiplier(double val) { + multiplier = val; + return this; + } + + public Builder pvmRole(int val) { + pvmRole = val; + return this; + } + + public OsrsHiscoreBoss build() { + return new OsrsHiscoreBoss(this); + } + } + + @Override + public String toString() { + return "OsrsHiscoreBoss{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", orderValue=" + orderValue + + ", multiplier=" + multiplier + + ", pvmRole=" + pvmRole + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/repository/osrs/dao/OsrsHiscoreStat.java b/src/main/java/com/sxcy/sxcybot/repository/osrs/dao/OsrsHiscoreStat.java @@ -3,18 +3,10 @@ package com.sxcy.sxcybot.repository.osrs.dao; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; @Entity -@Builder(toBuilder = true) -@Data -@NoArgsConstructor -@AllArgsConstructor public class OsrsHiscoreStat { @Id @GeneratedValue(generator = "uuid") @@ -22,4 +14,80 @@ public class OsrsHiscoreStat { private String id; private String name; private int orderValue; + + protected OsrsHiscoreStat() { + + } + + private OsrsHiscoreStat(Builder builder) { + setId(builder.id); + setName(builder.name); + setOrderValue(builder.orderValue); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getOrderValue() { + return orderValue; + } + + public void setOrderValue(int orderValue) { + this.orderValue = orderValue; + } + + + public static final class Builder { + private String id; + private String name; + private int orderValue; + + private Builder() { + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder id(String val) { + id = val; + return this; + } + + public Builder name(String val) { + name = val; + return this; + } + + public Builder orderValue(int val) { + orderValue = val; + return this; + } + + public OsrsHiscoreStat build() { + return new OsrsHiscoreStat(this); + } + } + + @Override + public String toString() { + return "OsrsHiscoreStat{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", orderValue=" + orderValue + + '}'; + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/CleanupScheduler.java b/src/main/java/com/sxcy/sxcybot/services/CleanupScheduler.java @@ -0,0 +1,62 @@ +package com.sxcy.sxcybot.services; + +import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmKcSnapshot; +import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; +import com.sxcy.sxcybot.services.guild.PollService; +import com.sxcy.sxcybot.services.guild.pvmrole.PvmKcSnapshotService; +import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleUserService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Comparator; +import java.util.List; + +@Component +public class CleanupScheduler { + + private static final Logger LOGGER = LoggerFactory.getLogger(CleanupScheduler.class); + private static final int POLL_DAYS_VALID = 60; + private final PvmKcSnapshotService pvmKcSnapshotService; + private final PvmRoleUserService pvmRoleUserService; + private final PollService pollService; + + public CleanupScheduler(PvmKcSnapshotService pvmKcSnapshotService, + PvmRoleUserService pvmRoleUserService, + PollService pollService) { + this.pvmKcSnapshotService = pvmKcSnapshotService; + this.pvmRoleUserService = pvmRoleUserService; + this.pollService = pollService; + } + + @Scheduled(cron = "${db.cleanup.schedule}") + @SuppressWarnings("unused") + public void cleanup() { + cleanupPvmKcSnapshots(); + cleanupPolls(); + } + + private void cleanupPvmKcSnapshots() { + List<PvmKcSnapshot> pvmKcSnapshotList; + for (PvmRoleUser pvmRoleUser : pvmRoleUserService.findAll()) { + pvmKcSnapshotList = pvmKcSnapshotService.findAllByPvmRoleUser(pvmRoleUser); + if (pvmKcSnapshotList.size() > 3) { + pvmKcSnapshotList = pvmKcSnapshotList.stream() + .sorted(Comparator.comparing(PvmKcSnapshot::getCreatedDate).reversed()) + .skip(2) + .toList(); + LOGGER.info("deleted {} from {}", pvmKcSnapshotList.size(), pvmRoleUser.getDiscordName()); + pvmKcSnapshotService.deleteAll(pvmKcSnapshotList); + } + } + } + + private void cleanupPolls() { + pollService.findAll().stream().filter(f -> ChronoUnit.DAYS.between(f.getCreatedDate(), LocalDateTime.now()) > POLL_DAYS_VALID) + .peek(f -> LOGGER.info("removed poll {} from {}", f.getMessageId(), f.getCreatedDate())) + .forEach(pollService::delete); + } +} diff --git a/src/main/java/com/sxcy/sxcybot/services/CleanuperScheduler.java b/src/main/java/com/sxcy/sxcybot/services/CleanuperScheduler.java @@ -1,62 +0,0 @@ -package com.sxcy.sxcybot.services; - -import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmKcSnapshot; -import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; -import com.sxcy.sxcybot.services.guild.PollService; -import com.sxcy.sxcybot.services.guild.pvmrole.PvmKcSnapshotService; -import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleUserService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.Comparator; -import java.util.List; - -@Component -@RequiredArgsConstructor -@Slf4j -public class CleanuperScheduler { - - private static final int POLL_DAYS_VALID = 60; - - @NonNull - private final PvmKcSnapshotService pvmKcSnapshotService; - - @NonNull - private final PvmRoleUserService pvmRoleUserService; - - @NonNull - private final PollService pollService; - - @Scheduled(cron = "${db.cleanup.schedule}") - @SuppressWarnings("unused") - public void cleanup() { - cleanupPvmKcSnapshots(); - cleanupPolls(); - } - - private void cleanupPvmKcSnapshots() { - List<PvmKcSnapshot> pvmKcSnapshotList; - for (PvmRoleUser pvmRoleUser : pvmRoleUserService.findAll()) { - pvmKcSnapshotList = pvmKcSnapshotService.findAllByPvmRoleUser(pvmRoleUser); - if (pvmKcSnapshotList.size() > 3) { - pvmKcSnapshotList = pvmKcSnapshotList.stream() - .sorted(Comparator.comparing(PvmKcSnapshot::getCreatedDate).reversed()) - .skip(2) - .toList(); - log.info("deleted {} from {}", pvmKcSnapshotList.size(), pvmRoleUser.getDiscordName()); - pvmKcSnapshotService.deleteAll(pvmKcSnapshotList); - } - } - } - - private void cleanupPolls() { - pollService.findAll().stream().filter(f -> ChronoUnit.DAYS.between(f.getCreatedDate(), LocalDateTime.now()) > POLL_DAYS_VALID) - .peek(f -> log.info("removed poll {} from {}", f.getMessageId(), f.getCreatedDate())) - .forEach(pollService::delete); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/OsrsMonitoringService.java b/src/main/java/com/sxcy/sxcybot/services/OsrsMonitoringService.java @@ -5,7 +5,6 @@ import com.sxcy.sxcybot.exceptions.EntityNotFoundException; import com.sxcy.sxcybot.model.OsrsBossKc; import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleUserService; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.PrivateChannel; import org.slf4j.Logger; @@ -19,19 +18,26 @@ import java.util.ArrayList; import java.util.List; @Service -@RequiredArgsConstructor public class OsrsMonitoringService { - private final Logger logger = LoggerFactory.getLogger("monitor"); + private final Logger LOGGER = LoggerFactory.getLogger("monitor"); private final HiScoreClient hiScoreClient; private final PvmRoleUserService pvmRoleUserService; + private final String monitorUserName; + private final String monitorBossName; + private final String monitorBossKc; - @Value("${monitor.user.name}") - private String monitorUserName; - @Value("${monitor.boss.name}") - private String monitorBossName; - @Value("${monitor.boss.kc}") - private String monitorBossKc; + public OsrsMonitoringService(HiScoreClient hiScoreClient, + PvmRoleUserService pvmRoleUserService, + @Value("${monitor.user.name}") String monitorUserName, + @Value("${monitor.boss.name}") String monitorBossName, + @Value("${monitor.boss.kc}") String monitorBossKc) { + this.hiScoreClient = hiScoreClient; + this.pvmRoleUserService = pvmRoleUserService; + this.monitorUserName = monitorUserName; + this.monitorBossName = monitorBossName; + this.monitorBossKc = monitorBossKc; + } @Scheduled(cron = "${monitor.schedule}") @SuppressWarnings("unused") @@ -40,7 +46,7 @@ public class OsrsMonitoringService { monitorHiscores(); monitorPvmRoleUserHiscores(null); } catch (Exception e) { - logger.error(e.getMessage()); + LOGGER.error(e.getMessage()); } } @@ -60,9 +66,9 @@ public class OsrsMonitoringService { private void messageUnfoundResults(List<PvmRoleUser> unfound, PrivateChannel privateChannel) { if (privateChannel == null) { if (!unfound.isEmpty()) { - logger.error("No hiScores found for: {}", unfound.stream().map(PvmRoleUser::getRsn).toList()); + LOGGER.error("No hiScores found for: {}", unfound.stream().map(PvmRoleUser::getRsn).toList()); } else { - logger.info("All PvM Role competitors have been found in the hiscores."); + LOGGER.info("All PvM Role competitors have been found in the hiscores."); } } else { EmbedBuilder embedBuilder = new EmbedBuilder(); @@ -83,15 +89,15 @@ public class OsrsMonitoringService { List<OsrsBossKc> osrsBossKcs = hiScoreClient.getHiScoreBossKc(monitorUserName, null) .orElseThrow(() -> new EntityNotFoundException(String.format("No hiscores available for %s.", monitorUserName))); OsrsBossKc wintertodtBossKc = osrsBossKcs.stream() - .filter(f -> f.getName().equals(monitorBossName)) + .filter(f -> f.name().equals(monitorBossName)) .findAny() .orElseThrow(() -> new EntityNotFoundException(String.format("No \"%s\" hiscores found.", monitorBossName))); - if (wintertodtBossKc.getKc().equals(monitorBossKc)) { - logger.info(String.format("Hiscores check is OK. (%s has %s kc on %s)", monitorUserName, monitorBossKc, monitorBossName)); + if (wintertodtBossKc.kc().equals(monitorBossKc)) { + LOGGER.info(String.format("Hiscores check is OK. (%s has %s kc on %s)", monitorUserName, monitorBossKc, monitorBossName)); } else { - logger.error(String.format("Hiscores check not OK: %s kc for user %s is not %s, but is %s", - monitorBossName, monitorUserName, monitorBossKc, wintertodtBossKc.getKc())); + LOGGER.error(String.format("Hiscores check not OK: %s kc for user %s is not %s, but is %s", + monitorBossName, monitorUserName, monitorBossKc, wintertodtBossKc.kc())); } } } diff --git a/src/main/java/com/sxcy/sxcybot/services/PvMRoleResolver.java b/src/main/java/com/sxcy/sxcybot/services/PvMRoleResolver.java @@ -8,10 +8,9 @@ import com.sxcy.sxcybot.services.guild.ChannelDetailService; import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleAssignerService; import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleSnapshotComparatorService; import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleUserService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.entities.PrivateChannel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -22,24 +21,29 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -@Slf4j @Component -@RequiredArgsConstructor public class PvMRoleResolver { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(PvMRoleResolver.class); private final PvmRoleUserService pvmRoleUserService; - @NonNull private final ChannelDetailService channelDetailService; - @NonNull private final PvmRoleSnapshotComparatorService pvmRoleSnapshotComparatorService; - @NonNull private final PvmRoleAssignerService pvmRoleAssignerService; + public PvMRoleResolver(PvmRoleUserService pvmRoleUserService, + ChannelDetailService channelDetailService, + PvmRoleSnapshotComparatorService pvmRoleSnapshotComparatorService, + PvmRoleAssignerService pvmRoleAssignerService) { + this.pvmRoleUserService = pvmRoleUserService; + this.channelDetailService = channelDetailService; + this.pvmRoleSnapshotComparatorService = pvmRoleSnapshotComparatorService; + this.pvmRoleAssignerService = pvmRoleAssignerService; + } + @Scheduled(cron = "${pvm.role.schedule}") @SuppressWarnings("unused") public void resolvePvMRoles() { - log.info("Running scheduled pvmRoleResolver."); + LOGGER.info("Running scheduled pvmRoleResolver."); resolvePvMRoles(true, null); } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/ChannelDetailService.java b/src/main/java/com/sxcy/sxcybot/services/guild/ChannelDetailService.java @@ -1,14 +1,34 @@ package com.sxcy.sxcybot.services.guild; +import com.sxcy.sxcybot.repository.guild.ChannelDetailRepository; import com.sxcy.sxcybot.repository.guild.dao.ChannelDetail; import net.dv8tion.jda.api.JDA; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; -public interface ChannelDetailService { +@Service +@Transactional +public class ChannelDetailService { - List<ChannelDetail> findAll(); + private final ChannelDetailRepository channelDetailRepository; - void setJda(JDA jda); - JDA getJda(); + private JDA jda; + + public JDA getJda() { + return jda; + } + + public void setJda(JDA jda) { + this.jda = jda; + } + + public ChannelDetailService(ChannelDetailRepository channelDetailRepository) { + this.channelDetailRepository = channelDetailRepository; + } + + public List<ChannelDetail> findAll() { + return channelDetailRepository.findAll(); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/GuildEventDmerService.java b/src/main/java/com/sxcy/sxcybot/services/guild/GuildEventDmerService.java @@ -1,11 +1,23 @@ package com.sxcy.sxcybot.services.guild; +import com.sxcy.sxcybot.repository.guild.GuildEventDmerRepository; import com.sxcy.sxcybot.repository.guild.dao.GuildEventDmer; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; -public interface GuildEventDmerService { +@Service +@Transactional +public class GuildEventDmerService { - List<GuildEventDmer> findAll(); + private final GuildEventDmerRepository guildEventDmerRepository; + public GuildEventDmerService(GuildEventDmerRepository guildEventDmerRepository) { + this.guildEventDmerRepository = guildEventDmerRepository; + } + + public List<GuildEventDmer> findAll() { + return guildEventDmerRepository.findAll(); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/GuildRoleService.java b/src/main/java/com/sxcy/sxcybot/services/guild/GuildRoleService.java @@ -1,22 +1,45 @@ package com.sxcy.sxcybot.services.guild; import com.sxcy.sxcybot.exceptions.EntityNotFoundException; +import com.sxcy.sxcybot.repository.guild.GuildRoleRepository; import com.sxcy.sxcybot.repository.guild.dao.GuildRole; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; -public interface GuildRoleService { +@Service +@Transactional +public class GuildRoleService { - List<GuildRole> findAllByElevationLessThanEqual(int elevation); + private final GuildRoleRepository guildRoleRepository; - List<GuildRole> findAllByElevationGreaterThanEqual(int elevation); + public GuildRoleService(GuildRoleRepository guildRoleRepository) { + this.guildRoleRepository = guildRoleRepository; + } - GuildRole findByName(String name) throws EntityNotFoundException; + public List<GuildRole> findAllByElevationLessThanEqual(int elevation) { + return guildRoleRepository.findByElevationLessThanEqual(elevation); + } - GuildRole save(GuildRole guildRole); + public List<GuildRole> findAllByElevationGreaterThanEqual(int elevation) { + return guildRoleRepository.findByElevationGreaterThanEqual(elevation); + } - void delete(GuildRole guildRole); + public GuildRole findByName(String name) throws EntityNotFoundException { + return guildRoleRepository.findByName(name).orElseThrow( + () -> new EntityNotFoundException(String.format("No role found with name %s.", name))); + } - List<GuildRole> findAll(); + public GuildRole save(GuildRole guildRole) { + return guildRoleRepository.save(guildRole); + } + public void delete(GuildRole guildRole) { + guildRoleRepository.delete(guildRole); + } + + public List<GuildRole> findAll() { + return guildRoleRepository.findAll(); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/PollService.java b/src/main/java/com/sxcy/sxcybot/services/guild/PollService.java @@ -1,17 +1,36 @@ package com.sxcy.sxcybot.services.guild; +import com.sxcy.sxcybot.repository.guild.PollRepository; import com.sxcy.sxcybot.repository.guild.dao.Poll; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Optional; -public interface PollService { +@Service +@Transactional +public class PollService { - List<Poll> findAll(); + private final PollRepository pollRepository; - Optional<Poll> findByMessageId(String messageId); + public PollService(PollRepository pollRepository) { + this.pollRepository = pollRepository; + } - Poll save(Poll poll); + public List<Poll> findAll() { + return pollRepository.findAll(); + } - void delete(Poll poll); + public Optional<Poll> findByMessageId(String messageId) { + return pollRepository.findByMessageId(messageId); + } + + public Poll save(Poll poll) { + return pollRepository.save(poll); + } + + public void delete(Poll poll) { + pollRepository.delete(poll); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/RuleService.java b/src/main/java/com/sxcy/sxcybot/services/guild/RuleService.java @@ -1,17 +1,37 @@ package com.sxcy.sxcybot.services.guild; import com.sxcy.sxcybot.exceptions.EntityNotFoundException; +import com.sxcy.sxcybot.repository.guild.RuleRepository; import com.sxcy.sxcybot.repository.guild.dao.Rule; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; -public interface RuleService { +@Service +@Transactional +public class RuleService { - List<Rule> findAll(); + private final RuleRepository ruleRepository; - Rule findByNumber(int number) throws EntityNotFoundException; + public RuleService(RuleRepository ruleRepository) { + this.ruleRepository = ruleRepository; + } - Rule save(Rule rule); + public List<Rule> findAll() { + return ruleRepository.findAll(); + } - void delete(Rule rule); + public Rule findByNumber(int number) throws EntityNotFoundException { + return ruleRepository.findByNumber(number).orElseThrow( + () -> new EntityNotFoundException(String.format("Rule with number %s not found.", number))); + } + + public Rule save(Rule rule) { + return ruleRepository.save(rule); + } + + public void delete(Rule rule) { + ruleRepository.delete(rule); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/UserService.java b/src/main/java/com/sxcy/sxcybot/services/guild/UserService.java @@ -1,17 +1,38 @@ package com.sxcy.sxcybot.services.guild; import com.sxcy.sxcybot.exceptions.EntityNotFoundException; +import com.sxcy.sxcybot.repository.guild.UserRepository; import com.sxcy.sxcybot.repository.guild.dao.User; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; -public interface UserService { +@Service +@Transactional +public class UserService { - List<User> findAllBanned(); + private final UserRepository userRepository; - User save(User user); + public UserService(UserRepository userRepository) { + this.userRepository = userRepository; + } - void delete(User user) throws EntityNotFoundException; + public List<User> findAllBanned() { + return userRepository.findAllByBannedTrue(); + } - User findByName(String name) throws EntityNotFoundException; + public User save(User user) { + return userRepository.save(user); + } + + public void delete(User user) throws EntityNotFoundException { + findByName(user.getName()); + userRepository.delete(user); + } + + public User findByName(String name) throws EntityNotFoundException { + return userRepository.findByName(name).orElseThrow( + () -> new EntityNotFoundException(String.format("No user found with name %s.", name))); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/impl/ChannelDetailServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/impl/ChannelDetailServiceImpl.java @@ -1,32 +0,0 @@ -package com.sxcy.sxcybot.services.guild.impl; - -import com.sxcy.sxcybot.repository.guild.ChannelDetailRepository; -import com.sxcy.sxcybot.repository.guild.dao.ChannelDetail; -import com.sxcy.sxcybot.services.guild.ChannelDetailService; -import lombok.Getter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import net.dv8tion.jda.api.JDA; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -@RequiredArgsConstructor -public class ChannelDetailServiceImpl implements ChannelDetailService { - - @NonNull - private final ChannelDetailRepository channelDetailRepository; - - @Setter - @Getter - private JDA jda; - - @Override - public List<ChannelDetail> findAll() { - return channelDetailRepository.findAll(); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/impl/GuildEventDmerServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/impl/GuildEventDmerServiceImpl.java @@ -1,25 +0,0 @@ -package com.sxcy.sxcybot.services.guild.impl; - -import com.sxcy.sxcybot.repository.guild.GuildEventDmerRepository; -import com.sxcy.sxcybot.repository.guild.dao.GuildEventDmer; -import com.sxcy.sxcybot.services.guild.GuildEventDmerService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -@RequiredArgsConstructor -public class GuildEventDmerServiceImpl implements GuildEventDmerService { - - @NonNull - private final GuildEventDmerRepository guildEventDmerRepository; - - @Override - public List<GuildEventDmer> findAll() { - return guildEventDmerRepository.findAll(); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/impl/GuildGuildRoleServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/impl/GuildGuildRoleServiceImpl.java @@ -1,52 +0,0 @@ -package com.sxcy.sxcybot.services.guild.impl; - -import com.sxcy.sxcybot.exceptions.EntityNotFoundException; -import com.sxcy.sxcybot.repository.guild.GuildRoleRepository; -import com.sxcy.sxcybot.repository.guild.dao.GuildRole; -import com.sxcy.sxcybot.services.guild.GuildRoleService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -@RequiredArgsConstructor -public class GuildGuildRoleServiceImpl implements GuildRoleService { - - @NonNull - private final GuildRoleRepository guildRoleRepository; - - @Override - public List<GuildRole> findAllByElevationLessThanEqual(int elevation) { - return guildRoleRepository.findByElevationLessThanEqual(elevation); - } - - @Override - public List<GuildRole> findAllByElevationGreaterThanEqual(int elevation) { - return guildRoleRepository.findByElevationGreaterThanEqual(elevation); - } - - @Override - public GuildRole findByName(String name) throws EntityNotFoundException { - return guildRoleRepository.findByName(name).orElseThrow( - () -> new EntityNotFoundException(String.format("No role found with name %s.", name))); - } - - @Override - public GuildRole save(GuildRole guildRole) { - return guildRoleRepository.save(guildRole); - } - - @Override - public void delete(GuildRole guildRole) { - guildRoleRepository.delete(guildRole); - } - - @Override - public List<GuildRole> findAll() { - return guildRoleRepository.findAll(); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/impl/PollServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/impl/PollServiceImpl.java @@ -1,41 +0,0 @@ -package com.sxcy.sxcybot.services.guild.impl; - -import com.sxcy.sxcybot.repository.guild.PollRepository; -import com.sxcy.sxcybot.repository.guild.dao.Poll; -import com.sxcy.sxcybot.services.guild.PollService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Optional; - -@Service -@RequiredArgsConstructor -@Transactional -public class PollServiceImpl implements PollService { - - @NonNull - private final PollRepository pollRepository; - - @Override - public List<Poll> findAll() { - return pollRepository.findAll(); - } - - @Override - public Optional<Poll> findByMessageId(String messageId) { - return pollRepository.findByMessageId(messageId); - } - - @Override - public Poll save(Poll poll) { - return pollRepository.save(poll); - } - - @Override - public void delete(Poll poll) { - pollRepository.delete(poll); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/impl/RuleServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/impl/RuleServiceImpl.java @@ -1,42 +0,0 @@ -package com.sxcy.sxcybot.services.guild.impl; - -import com.sxcy.sxcybot.exceptions.EntityNotFoundException; -import com.sxcy.sxcybot.repository.guild.RuleRepository; -import com.sxcy.sxcybot.repository.guild.dao.Rule; -import com.sxcy.sxcybot.services.guild.RuleService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@RequiredArgsConstructor -@Transactional -public class RuleServiceImpl implements RuleService { - - @NonNull - private final RuleRepository ruleRepository; - - @Override - public List<Rule> findAll() { - return ruleRepository.findAll(); - } - - @Override - public Rule findByNumber(int number) throws EntityNotFoundException { - return ruleRepository.findByNumber(number).orElseThrow( - () -> new EntityNotFoundException(String.format("Rule with number %s not found.", number))); - } - - @Override - public Rule save(Rule rule) { - return ruleRepository.save(rule); - } - - @Override - public void delete(Rule rule) { - ruleRepository.delete(rule); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/impl/UserServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/impl/UserServiceImpl.java @@ -1,43 +0,0 @@ -package com.sxcy.sxcybot.services.guild.impl; - -import com.sxcy.sxcybot.exceptions.EntityNotFoundException; -import com.sxcy.sxcybot.repository.guild.UserRepository; -import com.sxcy.sxcybot.repository.guild.dao.User; -import com.sxcy.sxcybot.services.guild.UserService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@RequiredArgsConstructor -@Transactional -public class UserServiceImpl implements UserService { - - @NonNull - private final UserRepository userRepository; - - @Override - public List<User> findAllBanned() { - return userRepository.findAllByBannedTrue(); - } - - @Override - public User save(User user) { - return userRepository.save(user); - } - - @Override - public void delete(User user) throws EntityNotFoundException { - findByName(user.getName()); - userRepository.delete(user); - } - - @Override - public User findByName(String name) throws EntityNotFoundException { - return userRepository.findByName(name).orElseThrow( - () -> new EntityNotFoundException(String.format("No user found with name %s.", name))); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmKcSnapshotService.java b/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmKcSnapshotService.java @@ -1,17 +1,36 @@ package com.sxcy.sxcybot.services.guild.pvmrole; +import com.sxcy.sxcybot.repository.guild.pvmrole.PvmKcSnapshotRepository; import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmKcSnapshot; import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; -public interface PvmKcSnapshotService { +@Service +@Transactional +public class PvmKcSnapshotService { - List<PvmKcSnapshot> findAll(); + private final PvmKcSnapshotRepository pvmKcSnapshotRepository; - List<PvmKcSnapshot> findAllByPvmRoleUser(PvmRoleUser pvmRoleUser); + public PvmKcSnapshotService(PvmKcSnapshotRepository pvmKcSnapshotRepository) { + this.pvmKcSnapshotRepository = pvmKcSnapshotRepository; + } - PvmKcSnapshot save(PvmKcSnapshot pvmKcSnapshot); + public List<PvmKcSnapshot> findAll() { + return pvmKcSnapshotRepository.findAll(); + } - void deleteAll(List<PvmKcSnapshot> pvmKcSnapshots); + public List<PvmKcSnapshot> findAllByPvmRoleUser(PvmRoleUser pvmRoleUser) { + return pvmKcSnapshotRepository.findAllByPvmRoleUserId(pvmRoleUser.getId()); + } + + public PvmKcSnapshot save(PvmKcSnapshot pvmKcSnapshot) { + return pvmKcSnapshotRepository.save(pvmKcSnapshot); + } + + public void deleteAll(List<PvmKcSnapshot> pvmKcSnapshots) { + pvmKcSnapshotRepository.deleteAll(pvmKcSnapshots); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmRoleAssignerService.java b/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmRoleAssignerService.java @@ -3,15 +3,90 @@ package com.sxcy.sxcybot.services.guild.pvmrole; import com.sxcy.sxcybot.enums.PvmRole; import com.sxcy.sxcybot.repository.guild.dao.ChannelDetail; import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.entities.Role; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.awt.Color; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Comparator; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import java.util.Optional; -public interface PvmRoleAssignerService { +@Service +@Transactional +public class PvmRoleAssignerService { - void postScoreboardAndAssignRoles(Guild guild, MessageChannel textChannel, Map<PvmRole, LinkedHashMap<PvmRoleUser, BigDecimal>> scoreBoard, ChannelDetail channelDetail, boolean persist); + public void postScoreboardAndAssignRoles(Guild guild, MessageChannel textChannel, Map<PvmRole, LinkedHashMap<PvmRoleUser, BigDecimal>> scoreBoard, ChannelDetail channelDetail, boolean persist) { + for (PvmRole pvmRole : scoreBoard.keySet()) { + String rolename = getRolename(pvmRole, channelDetail); + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setColor(Color.red); + embedBuilder.setTitle(String.format("**%s** Scoreboard results:", rolename)); + if (scoreBoard.get(pvmRole).isEmpty()) { + embedBuilder.addField(String.format("No KC gains detected for %s", pvmRole.name().toLowerCase()), "No increase in KC found for participants, role will remain unchanged.", false); + textChannel.sendMessageEmbeds(embedBuilder.build()).queue(); + continue; + } + List<Map.Entry<PvmRoleUser, BigDecimal>> entries = new ArrayList<>(scoreBoard.get(pvmRole).entrySet()); + entries.sort(Map.Entry.comparingByValue(Comparator.reverseOrder())); + scoreBoard.get(pvmRole).clear(); + entries.forEach(f -> scoreBoard.get(pvmRole).put(f.getKey(), f.getValue())); + guild.loadMembers().onSuccess(memberlist -> { + long limit = 5; + int i = 1; + int winningRank = 1; + for (Map.Entry<PvmRoleUser, BigDecimal> entry : scoreBoard.get(pvmRole).entrySet()) { + if (limit-- == 0) break; + Optional<Member> member = memberlist.stream().filter(f -> entry.getKey().getDiscordName().equalsIgnoreCase(f.getUser().getName()) || entry.getKey().getDiscordName().equalsIgnoreCase(f.getNickname())).findFirst(); + if (member.isPresent()) { + embedBuilder.addField(String.format("#%s %s", i, entry.getKey().getRsn()), String.format("%s with a score of %s!", member.get(), entry.getValue()), false); + if (i == winningRank && persist) { + Optional<Role> role = guild.getRoles().stream().filter(f -> rolename.equalsIgnoreCase(f.getName())).findFirst(); + if (role.isPresent()) { + guild.findMembersWithRoles(role.get()) + .onSuccess(oldWinners -> { + if (oldWinners.isEmpty()) { + addRoleToWinner(guild, member.get(), role.get(), textChannel, entry.getKey().getRsn()); + } else { + oldWinners.forEach(f -> guild.removeRoleFromMember(f, role.get()).queue(complete -> + addRoleToWinner(guild, member.get(), role.get(), textChannel, entry.getKey().getRsn()))); + } + }); + } else { + textChannel.sendMessage(String.format("No role %s found in the channel, role could not get assigned.", rolename)).queue(); + } + } + } else { + if (i == winningRank) winningRank++; + embedBuilder.addField(String.format("#%s %s", i, entry.getKey().getRsn()), String.format("%s with a score of %s!", entry.getKey().getDiscordName(), entry.getValue()), false); + textChannel.sendMessage(String.format("No guildmember found for discordname %s. User did not receive any awards.", entry.getKey().getDiscordName())).queue(); + } + i++; + } + textChannel.sendMessageEmbeds(embedBuilder.build()).queue(); + }); + } + } + private String getRolename(PvmRole pvmRole, ChannelDetail channelDetail) { + return switch (pvmRole) { + case GENERAL -> channelDetail.getPvmRoleGeneral(); + case RAIDS -> channelDetail.getPvmRoleRaids(); + case WILDERNESS -> channelDetail.getPvmRoleWilderness(); + default -> "Something went wrong."; + }; + } + + private void addRoleToWinner(Guild guild, Member member, Role role, MessageChannel textChannel, String rsn) { + guild.addRoleToMember(member, role).queue(ok -> + textChannel.sendMessage(String.format("%s is our new %s!", rsn, role)).queue()); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmRoleSnapshotComparatorService.java b/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmRoleSnapshotComparatorService.java @@ -1,19 +1,99 @@ package com.sxcy.sxcybot.services.guild.pvmrole; +import com.sxcy.sxcybot.client.HiScoreClient; import com.sxcy.sxcybot.enums.PvmRole; import com.sxcy.sxcybot.exceptions.EntityNotFoundException; +import com.sxcy.sxcybot.model.OsrsBossKc; import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmKcSnapshot; import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; +import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmUserKc; +import com.sxcy.sxcybot.services.osrs.OsrsHiscoreBossService; import net.dv8tion.jda.api.entities.MessageChannel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -public interface PvmRoleSnapshotComparatorService { +@Service +@Transactional +public class PvmRoleSnapshotComparatorService { - void updateScoreboard(PvmRoleUser pvmRoleUser, Map<PvmRole, LinkedHashMap<PvmRoleUser, BigDecimal>> scoreBoard, List<PvmKcSnapshot> unpersisted); + private static final Logger LOGGER = LoggerFactory.getLogger(PvmRoleSnapshotComparatorService.class); + private final OsrsHiscoreBossService osrsHiscoreBossService; + private final PvmKcSnapshotService pvmKcSnapshotService; + private final HiScoreClient hiScoreClient; - PvmKcSnapshot takeSnapshot(MessageChannel textChannel, PvmRoleUser pvmRoleUser, boolean notify, boolean persist) throws EntityNotFoundException; + public PvmRoleSnapshotComparatorService(OsrsHiscoreBossService osrsHiscoreBossService, + PvmKcSnapshotService pvmKcSnapshotService, + HiScoreClient hiScoreClient) { + this.osrsHiscoreBossService = osrsHiscoreBossService; + this.pvmKcSnapshotService = pvmKcSnapshotService; + this.hiScoreClient = hiScoreClient; + } + + 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))) { + pvmKcSnapshots = pvmKcSnapshots.stream() + .sorted(Comparator.comparing(PvmKcSnapshot::getCreatedDate) + .reversed()) + .limit(persisted ? 2 : 1) + .toList(); + for (PvmRole pvmRole : scoreBoard.keySet()) { + BigDecimal points1 = calculatePoints(pvmRole, persisted ? pvmKcSnapshots.get(0) : unpersistedSnapshots.get(0)); + BigDecimal points2 = calculatePoints(pvmRole, pvmKcSnapshots.get(persisted ? 1 : 0)); + BigDecimal result = points1.subtract(points2); + if (BigDecimal.ZERO.compareTo(result) < 0) + scoreBoard.get(pvmRole).put(pvmRoleUser, result); + } + } + } + + private BigDecimal calculatePoints(PvmRole pvmRole, PvmKcSnapshot pvmKcSnapshot) { + BigDecimal points = BigDecimal.ZERO; + for (PvmUserKc pvmUserKc : pvmKcSnapshot.getPvmUserKcList().stream().filter(f -> pvmRole.value == f.getOsrsHiscoreBoss().getPvmRole()).toList()) { + points = points.add(BigDecimal.valueOf(pvmUserKc.getOsrsHiscoreBoss().getMultiplier()).multiply(BigDecimal.valueOf(pvmUserKc.getKc()))); + } + return points; + } + + public PvmKcSnapshot takeSnapshot(MessageChannel textChannel, PvmRoleUser pvmRoleUser, boolean notify, boolean persist) throws EntityNotFoundException { + PvmKcSnapshot pvmKcSnapshot = PvmKcSnapshot.Builder.newBuilder() + .pvmRoleUser(pvmRoleUser) + .build(); + List<OsrsBossKc> osrsBossKcList = hiScoreClient.getHiScoreBossKc(pvmRoleUser.getRsn(), textChannel).orElseThrow( + () -> new EntityNotFoundException(String.format("No hiScores found for %s", pvmRoleUser.getRsn())) + ); + List<PvmUserKc> pvmUserKcList = new ArrayList<>(); + for (OsrsBossKc osrsBossKc : osrsBossKcList.stream().filter(r -> Integer.parseInt(r.kc()) > 0).toList()) { + try { + PvmUserKc pvmUserKc = PvmUserKc.Builder.newBuilder() + .pvmRoleUser(pvmRoleUser) + .osrsHiscoreBoss(osrsHiscoreBossService.findByName(osrsBossKc.name())) + .pvmKcSnapshot(pvmKcSnapshot) + .kc(Integer.valueOf(osrsBossKc.kc())) + .build(); + pvmUserKcList.add(pvmUserKc); + } catch (EntityNotFoundException e) { + LOGGER.error(e.getMessage(), e); + } + } + pvmKcSnapshot.setPvmUserKcList(pvmUserKcList); + + if (persist) { + pvmKcSnapshot = pvmKcSnapshotService.save(pvmKcSnapshot); + if (notify) + textChannel.sendMessage(String.format("KC snapshot saved for %s.%n", pvmRoleUser.getRsn())).queue(); + } + + return pvmKcSnapshot; + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmRoleUserService.java b/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/PvmRoleUserService.java @@ -1,18 +1,39 @@ package com.sxcy.sxcybot.services.guild.pvmrole; import com.sxcy.sxcybot.exceptions.EntityNotFoundException; +import com.sxcy.sxcybot.repository.guild.pvmrole.PvmRoleUserRepository; import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; +import org.springframework.stereotype.Service; import java.util.List; -public interface PvmRoleUserService { +import static com.sxcy.sxcybot.enums.Command.PVMLIST; +import static com.sxcy.sxcybot.util.Constants.Commands.COMMAND_PREFIX; - List<PvmRoleUser> findAll(); +@Service +public class PvmRoleUserService { - PvmRoleUser save(PvmRoleUser pvmRoleUser); + private final PvmRoleUserRepository pvmRoleUserRepository; - PvmRoleUser findByDiscordName(String discordName) throws EntityNotFoundException; + public PvmRoleUserService(PvmRoleUserRepository pvmRoleUserRepository) { + this.pvmRoleUserRepository = pvmRoleUserRepository; + } - void delete(PvmRoleUser pvmRoleUser); + public List<PvmRoleUser> findAll() { + return pvmRoleUserRepository.findAll(); + } + public PvmRoleUser save(PvmRoleUser pvmRoleUser) { + return pvmRoleUserRepository.save(pvmRoleUser); + } + + public PvmRoleUser findByDiscordName(String discordName) throws EntityNotFoundException { + return pvmRoleUserRepository.findByDiscordName(discordName).orElseThrow(() + -> new EntityNotFoundException(String.format("No discord user found with name %s in the PvM competition.%sYou can check all competitors with the \"%s\" command." + , discordName, System.lineSeparator(), COMMAND_PREFIX + PVMLIST.name().toLowerCase()))); + } + + public void delete(PvmRoleUser pvmRoleUser) { + pvmRoleUserRepository.delete(pvmRoleUser); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmKcSnapshotServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmKcSnapshotServiceImpl.java @@ -1,39 +0,0 @@ -package com.sxcy.sxcybot.services.guild.pvmrole.impl; - -import com.sxcy.sxcybot.repository.guild.pvmrole.PvmKcSnapshotRepository; -import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmKcSnapshot; -import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; -import com.sxcy.sxcybot.services.guild.pvmrole.PvmKcSnapshotService; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -@RequiredArgsConstructor -public class PvmKcSnapshotServiceImpl implements PvmKcSnapshotService { - - private final PvmKcSnapshotRepository pvmKcSnapshotRepository; - - @Override - public List<PvmKcSnapshot> findAll() { - return pvmKcSnapshotRepository.findAll(); - } - - @Override - public List<PvmKcSnapshot> findAllByPvmRoleUser(PvmRoleUser pvmRoleUser) { - return pvmKcSnapshotRepository.findAllByPvmRoleUserId(pvmRoleUser.getId()); - } - - @Override - public PvmKcSnapshot save(PvmKcSnapshot pvmKcSnapshot) { - return pvmKcSnapshotRepository.save(pvmKcSnapshot); - } - - @Override - public void deleteAll(List<PvmKcSnapshot> pvmKcSnapshots) { - pvmKcSnapshotRepository.deleteAll(pvmKcSnapshots); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmRoleAssignerServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmRoleAssignerServiceImpl.java @@ -1,96 +0,0 @@ -package com.sxcy.sxcybot.services.guild.pvmrole.impl; - -import com.sxcy.sxcybot.enums.PvmRole; -import com.sxcy.sxcybot.repository.guild.dao.ChannelDetail; -import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; -import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleAssignerService; -import lombok.RequiredArgsConstructor; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.MessageChannel; -import net.dv8tion.jda.api.entities.Role; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.awt.Color; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -@Service -@Transactional -@RequiredArgsConstructor -public class PvmRoleAssignerServiceImpl implements PvmRoleAssignerService { - - @Override - public void postScoreboardAndAssignRoles(Guild guild, MessageChannel textChannel, Map<PvmRole, LinkedHashMap<PvmRoleUser, BigDecimal>> scoreBoard, ChannelDetail channelDetail, boolean persist) { - for (PvmRole pvmRole : scoreBoard.keySet()) { - String rolename = getRolename(pvmRole, channelDetail); - EmbedBuilder embedBuilder = new EmbedBuilder(); - embedBuilder.setColor(Color.red); - embedBuilder.setTitle(String.format("**%s** Scoreboard results:", rolename)); - if (scoreBoard.get(pvmRole).isEmpty()) { - embedBuilder.addField(String.format("No KC gains detected for %s", pvmRole.name().toLowerCase()), "No increase in KC found for participants, role will remain unchanged.", false); - textChannel.sendMessageEmbeds(embedBuilder.build()).queue(); - continue; - } - List<Map.Entry<PvmRoleUser, BigDecimal>> entries = new ArrayList<>(scoreBoard.get(pvmRole).entrySet()); - entries.sort(Map.Entry.comparingByValue(Comparator.reverseOrder())); - scoreBoard.get(pvmRole).clear(); - entries.forEach(f -> scoreBoard.get(pvmRole).put(f.getKey(), f.getValue())); - guild.loadMembers().onSuccess(memberlist -> { - long limit = 5; - int i = 1; - int winningRank = 1; - for (Map.Entry<PvmRoleUser, BigDecimal> entry : scoreBoard.get(pvmRole).entrySet()) { - if (limit-- == 0) break; - Optional<Member> member = memberlist.stream().filter(f -> entry.getKey().getDiscordName().equalsIgnoreCase(f.getUser().getName()) || entry.getKey().getDiscordName().equalsIgnoreCase(f.getNickname())).findFirst(); - if (member.isPresent()) { - embedBuilder.addField(String.format("#%s %s", i, entry.getKey().getRsn()), String.format("%s with a score of %s!", member.get(), entry.getValue()), false); - if (i == winningRank && persist) { - Optional<Role> role = guild.getRoles().stream().filter(f -> rolename.equalsIgnoreCase(f.getName())).findFirst(); - if (role.isPresent()) { - guild.findMembersWithRoles(role.get()) - .onSuccess(oldWinners -> { - if (oldWinners.isEmpty()) { - addRoleToWinner(guild, member.get(), role.get(), textChannel, entry.getKey().getRsn()); - } else { - oldWinners.forEach(f -> guild.removeRoleFromMember(f, role.get()).queue(complete -> - addRoleToWinner(guild, member.get(), role.get(), textChannel, entry.getKey().getRsn()))); - } - }); - } else { - textChannel.sendMessage(String.format("No role %s found in the channel, role could not get assigned.", rolename)).queue(); - } - } - } else { - if (i == winningRank) winningRank++; - embedBuilder.addField(String.format("#%s %s", i, entry.getKey().getRsn()), String.format("%s with a score of %s!", entry.getKey().getDiscordName(), entry.getValue()), false); - textChannel.sendMessage(String.format("No guildmember found for discordname %s. User did not receive any awards.", entry.getKey().getDiscordName())).queue(); - } - i++; - } - textChannel.sendMessageEmbeds(embedBuilder.build()).queue(); - }); - } - } - - private String getRolename(PvmRole pvmRole, ChannelDetail channelDetail) { - return switch (pvmRole) { - case GENERAL -> channelDetail.getPvmRoleGeneral(); - case RAIDS -> channelDetail.getPvmRoleRaids(); - case WILDERNESS -> channelDetail.getPvmRoleWilderness(); - default -> "Something went wrong."; - }; - } - - private void addRoleToWinner(Guild guild, Member member, Role role, MessageChannel textChannel, String rsn) { - guild.addRoleToMember(member, role).queue(ok -> - textChannel.sendMessage(String.format("%s is our new %s!", rsn, role)).queue()); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmRoleSnapshotComparatorServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmRoleSnapshotComparatorServiceImpl.java @@ -1,100 +0,0 @@ -package com.sxcy.sxcybot.services.guild.pvmrole.impl; - -import com.sxcy.sxcybot.client.HiScoreClient; -import com.sxcy.sxcybot.enums.PvmRole; -import com.sxcy.sxcybot.exceptions.EntityNotFoundException; -import com.sxcy.sxcybot.model.OsrsBossKc; -import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmKcSnapshot; -import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; -import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmUserKc; -import com.sxcy.sxcybot.services.guild.pvmrole.PvmKcSnapshotService; -import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleSnapshotComparatorService; -import com.sxcy.sxcybot.services.osrs.OsrsHiscoreBossService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import net.dv8tion.jda.api.entities.MessageChannel; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -@Slf4j -@Service -@Transactional -@RequiredArgsConstructor -public class PvmRoleSnapshotComparatorServiceImpl implements PvmRoleSnapshotComparatorService { - - @NonNull - private final OsrsHiscoreBossService osrsHiscoreBossService; - @NonNull - private final PvmKcSnapshotService pvmKcSnapshotService; - @NonNull - private final HiScoreClient hiScoreClient; - - @Override - 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))) { - pvmKcSnapshots = pvmKcSnapshots.stream() - .sorted(Comparator.comparing(PvmKcSnapshot::getCreatedDate) - .reversed()) - .limit(persisted ? 2 : 1) - .toList(); - for (PvmRole pvmRole : scoreBoard.keySet()) { - BigDecimal points1 = calculatePoints(pvmRole, persisted ? pvmKcSnapshots.get(0) : unpersistedSnapshots.get(0)); - BigDecimal points2 = calculatePoints(pvmRole, pvmKcSnapshots.get(persisted ? 1 : 0)); - BigDecimal result = points1.subtract(points2); - if (BigDecimal.ZERO.compareTo(result) < 0) - scoreBoard.get(pvmRole).put(pvmRoleUser, result); - } - } - } - - private BigDecimal calculatePoints(PvmRole pvmRole, PvmKcSnapshot pvmKcSnapshot) { - BigDecimal points = BigDecimal.ZERO; - for (PvmUserKc pvmUserKc : pvmKcSnapshot.getPvmUserKcList().stream().filter(f -> pvmRole.value == f.getOsrsHiscoreBoss().getPvmRole()).toList()) { - points = points.add(BigDecimal.valueOf(pvmUserKc.getOsrsHiscoreBoss().getMultiplier()).multiply(BigDecimal.valueOf(pvmUserKc.getKc()))); - } - return points; - } - - @Override - public PvmKcSnapshot takeSnapshot(MessageChannel textChannel, PvmRoleUser pvmRoleUser, boolean notify, boolean persist) throws EntityNotFoundException { - PvmKcSnapshot pvmKcSnapshot = PvmKcSnapshot.builder() - .pvmRoleUser(pvmRoleUser) - .build(); - List<OsrsBossKc> osrsBossKcList = hiScoreClient.getHiScoreBossKc(pvmRoleUser.getRsn(), textChannel).orElseThrow( - () -> new EntityNotFoundException(String.format("No hiScores found for %s", pvmRoleUser.getRsn())) - ); - List<PvmUserKc> pvmUserKcList = new ArrayList<>(); - for (OsrsBossKc osrsBossKc : osrsBossKcList.stream().filter(r -> Integer.parseInt(r.getKc()) > 0).toList()) { - try { - PvmUserKc pvmUserKc = PvmUserKc.builder() - .pvmRoleUser(pvmRoleUser) - .osrsHiscoreBoss(osrsHiscoreBossService.findByName(osrsBossKc.getName())) - .pvmKcSnapshot(pvmKcSnapshot) - .kc(Integer.valueOf(osrsBossKc.getKc())) - .build(); - pvmUserKcList.add(pvmUserKc); - } catch (EntityNotFoundException e) { - log.error(e.getMessage(), e); - } - } - pvmKcSnapshot.setPvmUserKcList(pvmUserKcList); - - if (persist) { - pvmKcSnapshot = pvmKcSnapshotService.save(pvmKcSnapshot); - if (notify) - textChannel.sendMessage(String.format("KC snapshot saved for %s.%n", pvmRoleUser.getRsn())).queue(); - } - - return pvmKcSnapshot; - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmRoleUserServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/guild/pvmrole/impl/PvmRoleUserServiceImpl.java @@ -1,44 +0,0 @@ -package com.sxcy.sxcybot.services.guild.pvmrole.impl; - -import com.sxcy.sxcybot.exceptions.EntityNotFoundException; -import com.sxcy.sxcybot.repository.guild.pvmrole.PvmRoleUserRepository; -import com.sxcy.sxcybot.repository.guild.pvmrole.dao.PvmRoleUser; -import com.sxcy.sxcybot.services.guild.pvmrole.PvmRoleUserService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.List; - -import static com.sxcy.sxcybot.enums.Command.PVMLIST; -import static com.sxcy.sxcybot.util.Constants.Commands.COMMAND_PREFIX; - -@Service -@RequiredArgsConstructor -public class PvmRoleUserServiceImpl implements PvmRoleUserService { - - @NonNull - private final PvmRoleUserRepository pvmRoleUserRepository; - - @Override - public List<PvmRoleUser> findAll() { - return pvmRoleUserRepository.findAll(); - } - - @Override - public PvmRoleUser save(PvmRoleUser pvmRoleUser) { - return pvmRoleUserRepository.save(pvmRoleUser); - } - - @Override - public PvmRoleUser findByDiscordName(String discordName) throws EntityNotFoundException { - return pvmRoleUserRepository.findByDiscordName(discordName).orElseThrow(() - -> new EntityNotFoundException(String.format("No discord user found with name %s in the PvM competition.%sYou can check all competitors with the \"%s\" command." - , discordName, System.lineSeparator(), COMMAND_PREFIX + PVMLIST.name().toLowerCase()))); - } - - @Override - public void delete(PvmRoleUser pvmRoleUser) { - pvmRoleUserRepository.delete(pvmRoleUser); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/osrs/CombatCalculatorService.java b/src/main/java/com/sxcy/sxcybot/services/osrs/CombatCalculatorService.java @@ -1,8 +1,29 @@ package com.sxcy.sxcybot.services.osrs; import com.sxcy.sxcybot.model.CombatDto; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; -public interface CombatCalculatorService { +import java.math.BigDecimal; +import java.math.RoundingMode; - double getCombatLevel(CombatDto combatDto); +@Service +@Transactional +public class CombatCalculatorService { + + public double getCombatLevel(CombatDto combatDto) { + double base = 0.25 * (combatDto.defenceLevel() + combatDto.hitpointsLevel() + (combatDto.prayerLevel() / 2)); + + double typeContribution = getMeleeRangeOrMagicCombatLevelContribution(combatDto.attackLevel(), combatDto.strengthLevel(), combatDto.magicLevel(), combatDto.rangeLevel()); + + return BigDecimal.valueOf(base + typeContribution).setScale(3, RoundingMode.HALF_UP).doubleValue(); + } + + 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); + + return Math.max(melee, Math.max(range, magic)); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/osrs/OsrsHiscoreBossService.java b/src/main/java/com/sxcy/sxcybot/services/osrs/OsrsHiscoreBossService.java @@ -1,13 +1,30 @@ package com.sxcy.sxcybot.services.osrs; import com.sxcy.sxcybot.exceptions.EntityNotFoundException; +import com.sxcy.sxcybot.repository.osrs.OsrsHiscoreBossRepository; import com.sxcy.sxcybot.repository.osrs.dao.OsrsHiscoreBoss; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; -public interface OsrsHiscoreBossService { +@Service +@Transactional +public class OsrsHiscoreBossService { - List<OsrsHiscoreBoss> findAll(); + private final OsrsHiscoreBossRepository osrsHiscoreBossRepository; - OsrsHiscoreBoss findByName(String name) throws EntityNotFoundException; + public OsrsHiscoreBossService(OsrsHiscoreBossRepository osrsHiscoreBossRepository) { + this.osrsHiscoreBossRepository = osrsHiscoreBossRepository; + } + + public List<OsrsHiscoreBoss> findAll() { + return osrsHiscoreBossRepository.findAll(Sort.by("orderValue").ascending()); + } + + public OsrsHiscoreBoss findByName(String name) throws EntityNotFoundException { + return osrsHiscoreBossRepository.findByName(name).orElseThrow( + () -> new EntityNotFoundException(String.format("No hiscoreBoss found with name %s.", name))); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/osrs/OsrsHiscoreStatService.java b/src/main/java/com/sxcy/sxcybot/services/osrs/OsrsHiscoreStatService.java @@ -1,10 +1,24 @@ package com.sxcy.sxcybot.services.osrs; +import com.sxcy.sxcybot.repository.osrs.OsrsHiscoreStatRepository; import com.sxcy.sxcybot.repository.osrs.dao.OsrsHiscoreStat; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; -public interface OsrsHiscoreStatService { +@Service +@Transactional +public class OsrsHiscoreStatService { - List<OsrsHiscoreStat> findAll(); + private final OsrsHiscoreStatRepository osrsHiscoreStatRepository; + + public OsrsHiscoreStatService(OsrsHiscoreStatRepository osrsHiscoreStatRepository) { + this.osrsHiscoreStatRepository = osrsHiscoreStatRepository; + } + + public List<OsrsHiscoreStat> findAll() { + return osrsHiscoreStatRepository.findAll(Sort.by("orderValue").ascending()); + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/osrs/StatMessageSender.java b/src/main/java/com/sxcy/sxcybot/services/osrs/StatMessageSender.java @@ -1,15 +1,49 @@ package com.sxcy.sxcybot.services.osrs; +import com.sxcy.sxcybot.client.HiScoreClient; +import com.sxcy.sxcybot.exceptions.EntityNotFoundException; import com.sxcy.sxcybot.model.OsrsStat; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.awt.Color; import java.util.List; import java.util.function.Consumer; import java.util.function.Predicate; -public interface StatMessageSender { +@Service +@Transactional +public class StatMessageSender { - void sendStatMessage(MessageReceivedEvent event, EmbedBuilder embedBuilder, Predicate<OsrsStat> predicate, Consumer<OsrsStat> consumer, Consumer<List<OsrsStat>> calcCombatLevel); + private final HiScoreClient hiScoreClient; + public StatMessageSender(HiScoreClient hiScoreClient) { + this.hiScoreClient = hiScoreClient; + } + + public void sendStatMessage(MessageReceivedEvent event, EmbedBuilder embedBuilder, + Predicate<OsrsStat> predicate, Consumer<OsrsStat> consumer + , Consumer<List<OsrsStat>> calcCombatLevel) { + String msg = event.getMessage().getContentRaw(); + try { + String player = msg.substring(msg.indexOf(" ")).trim(); + try { + embedBuilder.setColor(Color.RED); + embedBuilder.setTitle(String.format("Stats of %s", player)); + List<OsrsStat> osrsStatList = hiScoreClient.getHiScoreStats(player, event.getChannel()).orElseThrow(() + -> new EntityNotFoundException(String.format("No HiScores found for %s.", player))); + osrsStatList.stream().filter(predicate).forEach(consumer); + if (calcCombatLevel != null) { + calcCombatLevel.accept(osrsStatList); + } + event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); + } catch (EntityNotFoundException entityNotFoundException) { + event.getChannel().sendMessage(entityNotFoundException.getMessage()).queue(); + } + } catch (StringIndexOutOfBoundsException e) { + event.getChannel().sendMessage("Please enter a player name after the command, separated by space.").queue(); + } + } } diff --git a/src/main/java/com/sxcy/sxcybot/services/osrs/impl/CombatCalculatorServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/osrs/impl/CombatCalculatorServiceImpl.java @@ -1,31 +0,0 @@ -package com.sxcy.sxcybot.services.osrs.impl; - -import com.sxcy.sxcybot.model.CombatDto; -import com.sxcy.sxcybot.services.osrs.CombatCalculatorService; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -@Service -@Transactional -public class CombatCalculatorServiceImpl implements CombatCalculatorService { - - @Override - public double getCombatLevel(CombatDto combatDto) { - double base = 0.25 * (combatDto.getDefenceLevel() + combatDto.getHitpointsLevel() + (combatDto.getPrayerLevel() / 2)); - - double typeContribution = getMeleeRangeOrMagicCombatLevelContribution(combatDto.getAttackLevel(), combatDto.getStrengthLevel(), combatDto.getMagicLevel(), combatDto.getRangeLevel()); - - return BigDecimal.valueOf(base + typeContribution).setScale(3, RoundingMode.HALF_UP).doubleValue(); - } - - 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); - - return Math.max(melee, Math.max(range, magic)); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/osrs/impl/OsrsHiscoreBossServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/osrs/impl/OsrsHiscoreBossServiceImpl.java @@ -1,33 +0,0 @@ -package com.sxcy.sxcybot.services.osrs.impl; - -import com.sxcy.sxcybot.exceptions.EntityNotFoundException; -import com.sxcy.sxcybot.repository.osrs.OsrsHiscoreBossRepository; -import com.sxcy.sxcybot.repository.osrs.dao.OsrsHiscoreBoss; -import com.sxcy.sxcybot.services.osrs.OsrsHiscoreBossService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Sort; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -@RequiredArgsConstructor -public class OsrsHiscoreBossServiceImpl implements OsrsHiscoreBossService { - - @NonNull - private final OsrsHiscoreBossRepository osrsHiscoreBossRepository; - - @Override - public List<OsrsHiscoreBoss> findAll() { - return osrsHiscoreBossRepository.findAll(Sort.by("orderValue").ascending()); - } - - @Override - public OsrsHiscoreBoss findByName(String name) throws EntityNotFoundException { - return osrsHiscoreBossRepository.findByName(name).orElseThrow( - () -> new EntityNotFoundException(String.format("No hiscoreBoss found with name %s.", name))); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/osrs/impl/OsrsHiscoreStatServiceImpl.java b/src/main/java/com/sxcy/sxcybot/services/osrs/impl/OsrsHiscoreStatServiceImpl.java @@ -1,26 +0,0 @@ -package com.sxcy.sxcybot.services.osrs.impl; - -import com.sxcy.sxcybot.repository.osrs.OsrsHiscoreStatRepository; -import com.sxcy.sxcybot.repository.osrs.dao.OsrsHiscoreStat; -import com.sxcy.sxcybot.services.osrs.OsrsHiscoreStatService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Sort; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -@RequiredArgsConstructor -public class OsrsHiscoreStatServiceImpl implements OsrsHiscoreStatService { - - @NonNull - private final OsrsHiscoreStatRepository osrsHiscoreStatRepository; - - @Override - public List<OsrsHiscoreStat> findAll() { - return osrsHiscoreStatRepository.findAll(Sort.by("orderValue").ascending()); - } -} diff --git a/src/main/java/com/sxcy/sxcybot/services/osrs/impl/StatMessageSenderImpl.java b/src/main/java/com/sxcy/sxcybot/services/osrs/impl/StatMessageSenderImpl.java @@ -1,50 +0,0 @@ -package com.sxcy.sxcybot.services.osrs.impl; - -import com.sxcy.sxcybot.client.HiScoreClient; -import com.sxcy.sxcybot.exceptions.EntityNotFoundException; -import com.sxcy.sxcybot.model.OsrsStat; -import com.sxcy.sxcybot.services.osrs.StatMessageSender; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.awt.Color; -import java.util.List; -import java.util.function.Consumer; -import java.util.function.Predicate; - -@Service -@RequiredArgsConstructor -@Transactional -public class StatMessageSenderImpl implements StatMessageSender { - - @NonNull - private final HiScoreClient hiScoreClient; - - public void sendStatMessage(MessageReceivedEvent event, EmbedBuilder embedBuilder, - Predicate<OsrsStat> predicate, Consumer<OsrsStat> consumer - , Consumer<List<OsrsStat>> calcCombatLevel) { - String msg = event.getMessage().getContentRaw(); - try { - String player = msg.substring(msg.indexOf(" ")).trim(); - try { - embedBuilder.setColor(Color.RED); - embedBuilder.setTitle(String.format("Stats of %s", player)); - List<OsrsStat> osrsStatList = hiScoreClient.getHiScoreStats(player, event.getChannel()).orElseThrow(() - -> new EntityNotFoundException(String.format("No HiScores found for %s.", player))); - osrsStatList.stream().filter(predicate).forEach(consumer); - if (calcCombatLevel != null) { - calcCombatLevel.accept(osrsStatList); - } - event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); - } catch (EntityNotFoundException entityNotFoundException) { - event.getChannel().sendMessage(entityNotFoundException.getMessage()).queue(); - } - } catch (StringIndexOutOfBoundsException e) { - event.getChannel().sendMessage("Please enter a player name after the command, separated by space.").queue(); - } - } -} diff --git a/src/main/java/com/sxcy/sxcybot/util/Constants.java b/src/main/java/com/sxcy/sxcybot/util/Constants.java @@ -1,29 +1,33 @@ package com.sxcy.sxcybot.util; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -@NoArgsConstructor(access = AccessLevel.PRIVATE) public class Constants { + private Constants() { + } + public static final int ADDED_ROLE_ELEVATION = 100; - @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class Commands { + private Commands() { + } public static final String COMMAND_PREFIX = "sb-"; public static final String BB8 = COMMAND_PREFIX + "8"; } - @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class Emoji { + private Emoji() { + } + public static final String THUMBS_UP = ":+1:"; public static final String FLAMES = ":flame:"; } - @NoArgsConstructor(access = AccessLevel.PRIVATE) public static class Reaction { + private Reaction() { + } public static final String CHECK_MARK = "U+2714"; public static final String CROSS_MARK = "U+274C"; diff --git a/src/main/java/com/sxcy/sxcybot/util/CustomPollFiller.java b/src/main/java/com/sxcy/sxcybot/util/CustomPollFiller.java @@ -3,8 +3,6 @@ package com.sxcy.sxcybot.util; import com.sxcy.sxcybot.listeners.EventWaiterUtil; import com.sxcy.sxcybot.repository.guild.dao.Poll; import com.sxcy.sxcybot.services.guild.PollService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -18,15 +16,18 @@ import java.util.Set; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -@RequiredArgsConstructor public class CustomPollFiller { - @NonNull private final EventWaiterUtil eventWaiterUtil; - @NonNull private final PollService pollService; private static final String STOP_WORD = "stop"; + public CustomPollFiller(EventWaiterUtil eventWaiterUtil, + PollService pollService) { + this.eventWaiterUtil = eventWaiterUtil; + this.pollService = pollService; + } + // private static final String EMOJI_REGEX = "([\\u20a0-\\u32ff\\ud83c\\udc00-\\ud83d\\udeff\\udbb9\\udce5-\\udbb9\\udcee])"; public void fillPoll(PrivateChannel privateChannel, MessageReceivedEvent event, EmbedBuilder embedBuilder, Set<String> emojiList) { @@ -39,9 +40,9 @@ public class CustomPollFiller { if (isReadyToStop(optionReceiver)) { event.getChannel().sendTyping().queue(typing -> event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(message -> { - emojiList.forEach(emoji -> message.addReaction(emoji).queue()); - pollService.save(Poll.builder().messageId(message.getId()).build()); - })); + emojiList.forEach(emoji -> message.addReaction(emoji).queue()); + pollService.save(Poll.Builder.newBuilder().messageId(message.getId()).build()); + })); return; } embeddedOption.setColor(Color.RED); diff --git a/src/main/java/com/sxcy/sxcybot/util/DiscordMemberFinderUtil.java b/src/main/java/com/sxcy/sxcybot/util/DiscordMemberFinderUtil.java @@ -1,8 +1,6 @@ package com.sxcy.sxcybot.util; import com.sxcy.sxcybot.listeners.EventWaiterUtil; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.PrivateChannel; @@ -13,12 +11,14 @@ import java.util.Optional; import java.util.function.Consumer; @Component -@RequiredArgsConstructor public class DiscordMemberFinderUtil { - @NonNull private final EventWaiterUtil eventWaiterUtil; + public DiscordMemberFinderUtil(EventWaiterUtil eventWaiterUtil) { + this.eventWaiterUtil = eventWaiterUtil; + } + public void onMemberFoundVerification(MessageReceivedEvent event, EmbedBuilder embedBuilder, PrivateChannel privateChannel, Consumer<Member> memberConsumer) { embedBuilder.addField("Type the name of the user.", "Discord username will be looked up first, if no match is found it will search on nickname.", false); privateChannel.sendMessageEmbeds(embedBuilder.build()).queue(); diff --git a/src/main/java/com/sxcy/sxcybot/util/EditListenerUtil.java b/src/main/java/com/sxcy/sxcybot/util/EditListenerUtil.java @@ -2,41 +2,41 @@ package com.sxcy.sxcybot.util; import com.sxcy.sxcybot.listeners.EventWaiterUtil; import com.sxcy.sxcybot.model.EditListenerDto; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.dv8tion.jda.api.EmbedBuilder; import org.springframework.stereotype.Component; import java.awt.Color; @Component -@RequiredArgsConstructor public class EditListenerUtil { - @NonNull private final EventWaiterUtil eventWaiterUtil; + public EditListenerUtil(EventWaiterUtil eventWaiterUtil) { + this.eventWaiterUtil = eventWaiterUtil; + } + 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.getEntityName()), false); - embedBuilder.addField("2", String.format("Delete an existing %s.", editListenerDto.getEntityName()), false); - if (editListenerDto.getUpdateListener() != null) - embedBuilder.addField("3", String.format("Update an existing %s.", editListenerDto.getEntityName()), false); - editListenerDto.getPrivateChannel().sendMessageEmbeds(embedBuilder.build()).queue(); + 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); + editListenerDto.privateChannel().sendMessageEmbeds(embedBuilder.build()).queue(); eventWaiterUtil.waitForPrivateChannelEvent(commandReceiver -> { switch (commandReceiver.getMessage().getContentRaw()) { - case "1" -> editListenerDto.getAddListener().proces(commandReceiver, editListenerDto.getEvent()); - case "2" -> editListenerDto.getDeleteListener().proces(commandReceiver, editListenerDto.getEvent()); + case "1" -> editListenerDto.addListener().proces(commandReceiver, editListenerDto.event()); + case "2" -> editListenerDto.deleteListener().proces(commandReceiver, editListenerDto.event()); case "3" -> { - if (editListenerDto.getUpdateListener() != null) - editListenerDto.getUpdateListener().proces(commandReceiver, editListenerDto.getEvent()); + if (editListenerDto.updateListener() != null) + editListenerDto.updateListener().proces(commandReceiver, editListenerDto.event()); } default -> - editListenerDto.getPrivateChannel().sendMessage("Unknown command, please try again.").queue(); + editListenerDto.privateChannel().sendMessage("Unknown command, please try again.").queue(); } - }, editListenerDto.getEvent(), editListenerDto.getPrivateChannel()); + }, editListenerDto.event(), editListenerDto.privateChannel()); } } diff --git a/src/main/java/com/sxcy/sxcybot/util/ReleaseNotesUtil.java b/src/main/java/com/sxcy/sxcybot/util/ReleaseNotesUtil.java @@ -2,11 +2,10 @@ package com.sxcy.sxcybot.util; import com.sxcy.sxcybot.services.guild.ChannelDetailService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.awt.Color; @@ -20,16 +19,18 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Optional; -@Slf4j @Component -@RequiredArgsConstructor public class ReleaseNotesUtil { - @NonNull + private static final Logger LOGGER = LoggerFactory.getLogger(ReleaseNotesUtil.class); private final ChannelDetailService channelDetailService; private static final String GITLAB_URL = "https://gitlab.com/WimDupont/sxcybot"; + public ReleaseNotesUtil(ChannelDetailService channelDetailService) { + this.channelDetailService = channelDetailService; + } + public void showReleaseNotes(JDA jda) { Map<String, String> releaseNotes = ReleaseNotesUtil.getReleaseNotes(); if (!releaseNotes.isEmpty()) { @@ -57,7 +58,7 @@ public class ReleaseNotesUtil { releaseNotes.put(line.split(";")[0], line.split(";")[1].trim()); }); } catch (IOException e) { - log.error(e.getMessage(), e); + LOGGER.error(e.getMessage(), e); } return releaseNotes; } diff --git a/src/main/java/com/sxcy/sxcybot/util/SpringSecurityAuditorAware.java b/src/main/java/com/sxcy/sxcybot/util/SpringSecurityAuditorAware.java @@ -8,6 +8,7 @@ import java.util.Optional; @Component public class SpringSecurityAuditorAware implements AuditorAware<String> { + /** * Returns the current auditor of the application. * diff --git a/src/test/java/com/sxcy/sxcybot/client/HiScoreClientTest.java b/src/test/java/com/sxcy/sxcybot/client/HiScoreClientTest.java @@ -44,11 +44,11 @@ class HiScoreClientTest { @Test void getHiScoreStatsValid() { String playerName = "Zxxy"; - List<OsrsHiscoreStat> osrsHiscoreStats = List.of(OsrsHiscoreStat.builder() + List<OsrsHiscoreStat> osrsHiscoreStats = List.of(OsrsHiscoreStat.Builder.newBuilder() .name("Overall") .orderValue(0) .build(), - OsrsHiscoreStat.builder() + OsrsHiscoreStat.Builder.newBuilder() .name("Construction") .orderValue(23) .build()); @@ -59,11 +59,11 @@ class HiScoreClientTest { assertFalse(result.isEmpty()); assertEquals(2, result.get().size()); - assertEquals("Overall", result.get().get(0).getName()); - assertTrue(1939 <= Integer.parseInt(result.get().get(0).getLevel())); + assertEquals("Overall", result.get().get(0).name()); + assertTrue(1939 <= Integer.parseInt(result.get().get(0).level())); - assertEquals("Construction", result.get().get(1).getName()); - assertTrue(90 <= Integer.parseInt(result.get().get(1).getLevel())); + assertEquals("Construction", result.get().get(1).name()); + assertTrue(90 <= Integer.parseInt(result.get().get(1).level())); } @Test @@ -78,11 +78,11 @@ class HiScoreClientTest { @Test void getHiscoreBossKcValidKbdKc() { String playerName = "Zxxy"; - List<OsrsHiscoreBoss> hiscoreBosses = List.of(OsrsHiscoreBoss.builder() + List<OsrsHiscoreBoss> hiscoreBosses = List.of(OsrsHiscoreBoss.Builder.newBuilder() .name("KBD") .orderValue(60) .build(), - OsrsHiscoreBoss.builder() + OsrsHiscoreBoss.Builder.newBuilder() .name("Wintertodt") .orderValue(86) .build() @@ -94,11 +94,11 @@ class HiScoreClientTest { assertFalse(result.isEmpty()); assertEquals(2, result.get().size()); - assertEquals("KBD", result.get().get(0).getName()); - assertTrue(723 <= Integer.parseInt(result.get().get(0).getKc())); + assertEquals("KBD", result.get().get(0).name()); + assertTrue(723 <= Integer.parseInt(result.get().get(0).kc())); - assertEquals("Wintertodt", result.get().get(1).getName()); - assertTrue(87 <= Integer.parseInt(result.get().get(1).getKc())); + assertEquals("Wintertodt", result.get().get(1).name()); + assertTrue(87 <= Integer.parseInt(result.get().get(1).kc())); } @Test