diff --git a/src/main/java/creator/loki/feature/animals/AnimalApi.java b/src/main/java/creator/loki/feature/animals/AnimalApi.java index 758106f..395cabf 100644 --- a/src/main/java/creator/loki/feature/animals/AnimalApi.java +++ b/src/main/java/creator/loki/feature/animals/AnimalApi.java @@ -105,7 +105,7 @@ public class AnimalApi { "https://shibe.online/api/shibes?count=1&urls=true&httpsUrls=true", firstArrayString()), new Endpoint("https://dog.ceo/api/breed/shiba/images/random", objectKey("message")))), - BIRB("🐦", List.of(new Endpoint("https://some-random-api.com/img/birb", objectKey("link")))), + BIRB("🐦", List.of(new Endpoint("https://api.alexflipnote.dev/birb", objectKey("file")))), NEKO("😺", List.of(new Endpoint(NEKOS_BASE + "neko", objectKey("url")))), WAIFU( "🌸", diff --git a/src/main/java/creator/loki/feature/entertainment/service/RatingService.java b/src/main/java/creator/loki/feature/entertainment/service/RatingService.java index 7400a67..cc1ecd4 100644 --- a/src/main/java/creator/loki/feature/entertainment/service/RatingService.java +++ b/src/main/java/creator/loki/feature/entertainment/service/RatingService.java @@ -27,6 +27,29 @@ public class RatingService { return new Random(seed).nextInt(max - min + 1) + min; } + /** Детерминированное значение рейтинга, совпадающее с командами (!pp, !iq, !mustache и т.д.). */ + public int getRatingValue(final String ratingType, final String userId) { + return switch (ratingType) { + case "gay" -> getDeterministicValue(userId, 456, 0, 100); + case "iq" -> + userId.equals("1414975197269987471") ? 1000 : getDeterministicValue(userId, 123, 0, 140); + case "pp" -> + userId.equals("1414975197269987471") ? 100 : getDeterministicValue(userId, 6969, 0, 30); + case "mustache" -> { + if (userId.equals("1414975197269987471")) { + yield 0; + } + if (userId.equals("678283217094180915")) { + yield 1000; + } + yield getDeterministicValue(userId, 888, 0, 100); + } + case "fat" -> getDeterministicValue(userId, 999, 0, 100); + case "boykisser" -> getDeterministicValue(userId, 777, 0, 100); + default -> throw new IllegalArgumentException("Неизвестный тип рейтинга: " + ratingType); + }; + } + public Member resolveTarget(final CommandContext context) { List mentioned = context.getMessage().getMentions().getMembers(); return mentioned.isEmpty() ? context.getAuthor() : mentioned.get(0); diff --git a/src/main/java/creator/loki/feature/rating/commands/board/RatingOverviewCommand.java b/src/main/java/creator/loki/feature/rating/commands/board/RatingOverviewCommand.java index 74a8b60..6dbe0a3 100644 --- a/src/main/java/creator/loki/feature/rating/commands/board/RatingOverviewCommand.java +++ b/src/main/java/creator/loki/feature/rating/commands/board/RatingOverviewCommand.java @@ -1,15 +1,15 @@ package creator.loki.feature.rating.commands.board; -import java.util.HashSet; +import java.util.HashMap; import java.util.List; -import java.util.Set; +import java.util.Map; import creator.loki.command.Command; import creator.loki.command.CommandCategories; import creator.loki.command.CommandContext; import creator.loki.config.BotConfig; import creator.loki.embed.EmbedFactory; -import creator.loki.feature.rating.repository.RatingsRepository; +import creator.loki.feature.entertainment.service.RatingService; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; @@ -17,13 +17,13 @@ import net.dv8tion.jda.api.entities.Member; public class RatingOverviewCommand implements Command { private static final List TYPES = - List.of("ship", "gay", "iq", "pp", "mustache", "fat", "boykisser"); + List.of("gay", "iq", "pp", "mustache", "fat", "boykisser"); - private final RatingsRepository ratingsRepository; + private final RatingService ratingService; private final BotConfig config; - public RatingOverviewCommand(RatingsRepository ratingsRepository, BotConfig config) { - this.ratingsRepository = ratingsRepository; + public RatingOverviewCommand(RatingService ratingService, BotConfig config) { + this.ratingService = ratingService; this.config = config; } @@ -62,20 +62,24 @@ public class RatingOverviewCommand implements Command { return; } - Set excluded = new HashSet<>(); - excluded.add(config.getSuperAdminId()); + Map maxByType = new HashMap<>(); + Map minByType = new HashMap<>(); for (Member member : guild.getMembers()) { - if (member.getUser().isBot()) { - excluded.add(member.getUser().getId()); + if (member.getUser().isBot() || config.getSuperAdminId().equals(member.getUser().getId())) { + continue; + } + String userId = member.getUser().getId(); + for (String type : TYPES) { + int value = ratingService.getRatingValue(type, userId); + updateExtreme(maxByType, type, userId, value, true); + updateExtreme(minByType, type, userId, value, false); } } StringBuilder description = new StringBuilder(); for (String type : TYPES) { - RatingsRepository.RatingEntry max = - ratingsRepository.getExtremeRating(guild.getId(), type, excluded, true); - RatingsRepository.RatingEntry min = - ratingsRepository.getExtremeRating(guild.getId(), type, excluded, false); + RatingEntry max = maxByType.get(type); + RatingEntry min = minByType.get(type); if (max == null || min == null) { continue; } @@ -83,21 +87,18 @@ public class RatingOverviewCommand implements Command { .append("**") .append(type) .append("**\n🏆 <@") - .append(max.userId()) + .append(max.userId) .append("> — **") - .append(max.value()) + .append(max.value) .append("**\n📉 <@") - .append(min.userId()) + .append(min.userId) .append("> — **") - .append(min.value()) + .append(min.value) .append("**\n\n"); } if (description.isEmpty()) { - context - .getChannel() - .sendMessage("❌ Пока никто не имеет рейтингов. Сначала `!generateratings`.") - .queue(); + context.getChannel().sendMessage("❌ На сервере нет участников для подсчёта.").queue(); return; } @@ -111,4 +112,20 @@ public class RatingOverviewCommand implements Command { .build()) .queue(); } + + private void updateExtreme( + final Map byType, + final String type, + final String userId, + final int value, + final boolean highest) { + RatingEntry current = byType.get(type); + if (current == null + || (highest && value > current.value) + || (!highest && value < current.value)) { + byType.put(type, new RatingEntry(userId, value)); + } + } + + private record RatingEntry(String userId, int value) {} } diff --git a/src/main/java/creator/loki/feature/rating/commands/body/FatCommand.java b/src/main/java/creator/loki/feature/rating/commands/body/FatCommand.java index 47ea8c6..56d54b6 100644 --- a/src/main/java/creator/loki/feature/rating/commands/body/FatCommand.java +++ b/src/main/java/creator/loki/feature/rating/commands/body/FatCommand.java @@ -50,7 +50,7 @@ public class FatCommand implements Command { return; } - int fatLevel = ratingService.getDeterministicValue(target.getId(), 999, 0, 100); + int fatLevel = ratingService.getRatingValue("fat", target.getId()); StringBuilder bar = new StringBuilder(); int filled = fatLevel / 10; for (int i = 0; i < filled; i++) { diff --git a/src/main/java/creator/loki/feature/rating/commands/body/MustacheCommand.java b/src/main/java/creator/loki/feature/rating/commands/body/MustacheCommand.java index d25e537..0b63398 100644 --- a/src/main/java/creator/loki/feature/rating/commands/body/MustacheCommand.java +++ b/src/main/java/creator/loki/feature/rating/commands/body/MustacheCommand.java @@ -51,12 +51,10 @@ public class MustacheCommand implements Command { } int mustacheLevel; - if (target.getUser().isBot() || target.getId().equals("1414975197269987471")) { + if (target.getUser().isBot()) { mustacheLevel = 0; - } else if (target.getId().equals("678283217094180915")) { - mustacheLevel = 1000; } else { - mustacheLevel = ratingService.getDeterministicValue(target.getId(), 888, 0, 100); + mustacheLevel = ratingService.getRatingValue("mustache", target.getId()); } StringBuilder bar = new StringBuilder(); diff --git a/src/main/java/creator/loki/feature/rating/commands/body/PpCommand.java b/src/main/java/creator/loki/feature/rating/commands/body/PpCommand.java index 46c0eac..3848faa 100644 --- a/src/main/java/creator/loki/feature/rating/commands/body/PpCommand.java +++ b/src/main/java/creator/loki/feature/rating/commands/body/PpCommand.java @@ -55,12 +55,7 @@ public class PpCommand implements Command { return; } - int size; - if (target.getId().equals("1414975197269987471")) { - size = 100; - } else { - size = ratingService.getDeterministicValue(target.getId(), 6969, 0, 30); - } + int size = ratingService.getRatingValue("pp", target.getId()); StringBuilder ppVisual = new StringBuilder("8"); for (int i = 0; i < size; i++) { diff --git a/src/main/java/creator/loki/feature/rating/commands/mind/BoykisserCommand.java b/src/main/java/creator/loki/feature/rating/commands/mind/BoykisserCommand.java index 52b6e52..4b90929 100644 --- a/src/main/java/creator/loki/feature/rating/commands/mind/BoykisserCommand.java +++ b/src/main/java/creator/loki/feature/rating/commands/mind/BoykisserCommand.java @@ -55,7 +55,7 @@ public class BoykisserCommand implements Command { return; } - int boykisserLevel = ratingService.getDeterministicValue(target.getId(), 777, 0, 100); + int boykisserLevel = ratingService.getRatingValue("boykisser", target.getId()); StringBuilder bar = new StringBuilder(); int filled = boykisserLevel / 10; for (int i = 0; i < filled; i++) { diff --git a/src/main/java/creator/loki/feature/rating/commands/mind/GayCommand.java b/src/main/java/creator/loki/feature/rating/commands/mind/GayCommand.java index 571427d..b5b161d 100644 --- a/src/main/java/creator/loki/feature/rating/commands/mind/GayCommand.java +++ b/src/main/java/creator/loki/feature/rating/commands/mind/GayCommand.java @@ -55,7 +55,7 @@ public class GayCommand implements Command { return; } - int gayLevel = ratingService.getDeterministicValue(target.getId(), 456, 0, 100); + int gayLevel = ratingService.getRatingValue("gay", target.getId()); String[] rainbow = {"🟥", "🟧", "🟨", "🟩", "🟦", "🟪"}; StringBuilder bar = new StringBuilder(); int filled = Math.min(gayLevel / 17 + 1, 6); diff --git a/src/main/java/creator/loki/feature/rating/commands/mind/IqCommand.java b/src/main/java/creator/loki/feature/rating/commands/mind/IqCommand.java index 5a6c68f..52f298b 100644 --- a/src/main/java/creator/loki/feature/rating/commands/mind/IqCommand.java +++ b/src/main/java/creator/loki/feature/rating/commands/mind/IqCommand.java @@ -53,10 +53,8 @@ public class IqCommand implements Command { int iq; if (target.getUser().isBot()) { iq = 9000; - } else if (target.getId().equals("1414975197269987471")) { - iq = 1000; } else { - iq = ratingService.getDeterministicValue(target.getId(), 123, 0, 140); + iq = ratingService.getRatingValue("iq", target.getId()); } RatingLevel level = RatingConfig.findLevel(iq, "iq"); diff --git a/src/main/java/creator/loki/feature/utility/UtilityCommandRegistrar.java b/src/main/java/creator/loki/feature/utility/UtilityCommandRegistrar.java index a877df4..2b86e35 100644 --- a/src/main/java/creator/loki/feature/utility/UtilityCommandRegistrar.java +++ b/src/main/java/creator/loki/feature/utility/UtilityCommandRegistrar.java @@ -10,6 +10,7 @@ import creator.loki.feature.config.repository.ConfigRepository; import creator.loki.feature.counter.repository.CounterStatsRepository; import creator.loki.feature.counter.service.CounterManager; import creator.loki.feature.counter.service.CounterSetupPrefixCommand; +import creator.loki.feature.entertainment.service.RatingService; import creator.loki.feature.help.commands.HelpCommand; import creator.loki.feature.info.commands.AvatarCommand; import creator.loki.feature.info.commands.InfoCommand; @@ -40,6 +41,7 @@ public class UtilityCommandRegistrar implements CommandRegistrar { private final ReputationRepository reputationRepository; private final CooldownManager cooldownManager; private final ServerStatsService serverStatsService; + private final RatingService ratingService; @Inject public UtilityCommandRegistrar( @@ -52,7 +54,8 @@ public class UtilityCommandRegistrar implements CommandRegistrar { RatingsRepository ratingsRepository, ReputationRepository reputationRepository, CooldownManager cooldownManager, - final CounterStatsRepository counterStatsRepository) { + final CounterStatsRepository counterStatsRepository, + RatingService ratingService) { this.commandRegistry = commandRegistry; this.config = config; this.metrics = metrics; @@ -63,6 +66,7 @@ public class UtilityCommandRegistrar implements CommandRegistrar { this.reputationRepository = reputationRepository; this.cooldownManager = cooldownManager; this.serverStatsService = new ServerStatsService(counterStatsRepository); + this.ratingService = ratingService; } @Override @@ -82,7 +86,7 @@ public class UtilityCommandRegistrar implements CommandRegistrar { registry.register(new GenerateRatingsCommand(ratingsRepository, config)); registry.register(new RatingBoardCommand(RatingBoardCommand.Flavor.TOP, ratingsRepository)); registry.register(new RatingBoardCommand(RatingBoardCommand.Flavor.BOTTOM, ratingsRepository)); - registry.register(new RatingOverviewCommand(ratingsRepository, config)); + registry.register(new RatingOverviewCommand(ratingService, config)); registry.register(new RepCommand(reputationRepository, cooldownManager)); registry.register(new MinusRepCommand(reputationRepository, cooldownManager)); diff --git a/src/test/java/creator/loki/core/registry/SmokeCommandRegistrationTest.java b/src/test/java/creator/loki/core/registry/SmokeCommandRegistrationTest.java index 74620cb..5e30ab1 100644 --- a/src/test/java/creator/loki/core/registry/SmokeCommandRegistrationTest.java +++ b/src/test/java/creator/loki/core/registry/SmokeCommandRegistrationTest.java @@ -130,7 +130,8 @@ class SmokeCommandRegistrationTest { mock(RatingsRepository.class), mock(ReputationRepository.class), mock(CooldownManager.class), - mock(CounterStatsRepository.class)); + mock(CounterStatsRepository.class), + mock(RatingService.class)); utilityRegistrar.register(registry); var musicRegistrar =