From 24daf66a5ac9979812635a1ad6609f8e37d17aa4 Mon Sep 17 00:00:00 2001 From: test Date: Wed, 22 May 2024 19:26:09 +1000 Subject: [PATCH] Command behavior options to templates --- .../v2/impl/pw/commands/EmbedCommands.java | 42 +++++++++---------- .../v2/impl/pw/commands/IACommands.java | 2 +- .../link/locutus/discord/db/NationDB.java | 12 +++++- .../locutus/wiki/pages/WikiWarAlertsPage.java | 6 ++- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java index e66abeeb..a00d3670 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java @@ -427,7 +427,8 @@ public void raid(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default Mess */ @Command(desc="Blockader Target & Requests discord embed template") @RolePermission(Roles.ADMIN) - public void unblockadeRequests(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default MessageChannel outputChannel) { + public void unblockadeRequests(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default MessageChannel outputChannel, @Default CommandBehavior behavior) { + if (behavior == null) behavior = CommandBehavior.UNPRESS; if (db.getCoalition(Coalition.ALLIES).isEmpty()) { throw new IllegalArgumentException("No `" + Coalition.ALLIES.name() + "` coalition. See " + CM.coalition.create.cmd.toSlashMention()); } @@ -461,7 +462,6 @@ public void unblockadeRequests(@Me User user, @Me GuildDB db, @Me IMessageIO io, CM.war.blockade.find breakCmd = CM.war.blockade.find.cmd.create("~allies,#active_m<2880", null, null, "10"); CM.war.blockade.find breakUnpowered = CM.war.blockade.find.cmd.create("~allies,#ispowered=0,#active_m<2880", null, null, "10"); - CommandBehavior behavior = CommandBehavior.UNPRESS; io.create().embed(title, body) .commandButton(behavior, channelId, low, "low") .commandButton(behavior, channelId, deposit, "deposit") @@ -473,7 +473,8 @@ public void unblockadeRequests(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Command(desc="Econ panel for members") @RolePermission(Roles.ADMIN) - public void memberEconPanel(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default MessageChannel outputChannel, @Switch("d") boolean showDepositsInDms) { + public void memberEconPanel(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default MessageChannel outputChannel, @Default CommandBehavior behavior, @Switch("d") boolean showDepositsInDms) { + if (behavior == null) behavior = CommandBehavior.UNPRESS; Long channelId = outputChannel == null ? null : outputChannel.getIdLong(); String title = "Econ Panel"; String body = """ @@ -502,7 +503,6 @@ public void memberEconPanel(@Me User user, @Me GuildDB db, @Me IMessageIO io, @D CM.trade.margin trademargin = CM.trade.margin.cmd.create(null); CM.trade.profit tradeprofit = CM.trade.profit.cmd.create("{nation_id}", "7d"); - CommandBehavior behavior = CommandBehavior.UNPRESS; io.create().embed(title, body) .commandButton(behavior, channelId, send, "offshore") .commandButton(behavior, channelId, deposits, "balance") @@ -552,7 +552,8 @@ public void memberEconPanel(@Me User user, @Me GuildDB db, @Me IMessageIO io, @D @Command(desc="High infra targets where you are losing\n" + "To find contestable range, see: strengthTierGraph") @RolePermission(Roles.ADMIN) - public void warGuerilla(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default MessageChannel outputChannel) { + public void warGuerilla(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default MessageChannel outputChannel, @Default CommandBehavior behavior) { + if (behavior == null) behavior = CommandBehavior.UNPRESS; if (db.getCoalition(Coalition.ENEMIES).isEmpty()) { throw new IllegalArgumentException("No `" + Coalition.ENEMIES.name() + "` coalition. See " + CM.coalition.create.cmd.toSlashMention()); } @@ -572,8 +573,6 @@ public void warGuerilla(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Defau body += "\n\n> Results in <#" + channelId + ">"; } - CommandBehavior behavior = CommandBehavior.UNPRESS; - CM.war.find.damage damage = CM.war.find.damage.cmd.create( "~enemies", null, null, null, null, null, null, null, null, null, null); CM.war.find.damage damageWeak = CM.war.find.damage.cmd.create( @@ -616,7 +615,8 @@ public void warGuerilla(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Defau public void warContestedRange(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Arg("If the cutoff is greater or less than the score") Operation greaterOrLess, @Arg("The score at which the conflict is not contestable") - double score, @Default MessageChannel outputChannel, @Switch("d") boolean resultsInDm) { + double score, @Default MessageChannel outputChannel, @Default CommandBehavior behavior, @Switch("d") boolean resultsInDm) { + if (behavior == null) behavior = CommandBehavior.UNPRESS; if (greaterOrLess == Operation.EQUAL || greaterOrLess == Operation.NOT_EQUAL) { if (db.getCoalition(Coalition.ENEMIES).isEmpty()) { throw new IllegalArgumentException("No " + Coalition.ENEMIES.name() + " coalition found. See: " + CM.coalition.create.cmd.toSlashMention()); @@ -674,7 +674,6 @@ public void warContestedRange(@Me User user, @Me GuildDB db, @Me IMessageIO io, CM.war.find.damage infra = CM.war.find.damage.cmd.create( "~enemies,#active_m>2880|~enemies,#score" + greaterOrLess + scoreMax +"|~enemies,#barracks=0,#off=0", "true", "true", null, null, null, null, null, dmStr, null, null); - CommandBehavior behavior = CommandBehavior.UNPRESS; io.create().embed(title, body) .commandButton(behavior, channelId, easy, "easy") .commandButton(behavior, channelId, high, "high") @@ -687,7 +686,8 @@ public void warContestedRange(@Me User user, @Me GuildDB db, @Me IMessageIO io, // Spy embed with spy - airplane - tank - ship spying - auto @Command(desc="Enemy espionage finder discord embed template") @RolePermission(Roles.ADMIN) - public void spyEnemy(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default @GuildCoalition String coalition, @Default MessageChannel outputChannel) { + public void spyEnemy(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default @GuildCoalition String coalition, @Default MessageChannel outputChannel, @Default CommandBehavior behavior) { + if (behavior == null) behavior = CommandBehavior.UNPRESS; if (coalition == null) coalition = Coalition.ENEMIES.name(); if (db.getCoalition(coalition).isEmpty()) { throw new IllegalArgumentException("No `" + coalition + "` coalition found. See: " + CM.coalition.create.cmd.toSlashMention()); @@ -728,8 +728,6 @@ public void spyEnemy(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default CM.spy.find.target kill = CM.spy.find.target.cmd.create( "~" + coalition + ",#active_m<1440", "*", null, null, "true", null); - CommandBehavior behavior = CommandBehavior.UNPRESS; - io.create().embed(title, body) .commandButton(behavior, channelId, spy, "spy") .commandButton(behavior, channelId, airplane, "airplane") @@ -759,7 +757,8 @@ public void spyEnemy(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default "Prioritizes down declares\n" + "To find contestable range, see: strengthTierGraph") @RolePermission(Roles.ADMIN) - public void warWinning(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default MessageChannel outputChannel, @Switch("d") boolean resultsInDm) { + public void warWinning(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Default MessageChannel outputChannel, @Default CommandBehavior behavior, @Switch("d") boolean resultsInDm) { + if (behavior == null) behavior = CommandBehavior.UNPRESS; if (db.getCoalition(Coalition.ENEMIES).isEmpty()) { throw new IllegalArgumentException("No " + Coalition.ENEMIES.name() + " coalition found. See: " + CM.coalition.create.cmd.toSlashMention()); } @@ -797,8 +796,6 @@ public void warWinning(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Defaul CM.war.find.enemy beige = CM.war.find.enemy.cmd.create( "~enemies,#color=beige", null, null, "true", "true", null, null, "true", null, dmStr, null); - CommandBehavior behavior = CommandBehavior.UNPRESS; - io.create().embed(title, body) .commandButton(behavior, channelId, high, "high") .commandButton(behavior, channelId, med, "med") @@ -813,7 +810,8 @@ public void warWinning(@Me User user, @Me GuildDB db, @Me IMessageIO io, @Defaul @Command(desc = "Discord embed for Econ Staff to view deposits, stockpiles, revenue, tax brackets, tax income, warchest and offshore funds") @RolePermission(Roles.ADMIN) @IsAlliance - public void econPanel(@Me GuildDB db, @Me IMessageIO io, @Switch("c") MessageChannel outputChannel, @Switch("n") DepositType useFlowNote, @Arg("Include past depositors in deposits sheet") @Switch("p") Set includePastDepositors) { + public void econPanel(@Me GuildDB db, @Me IMessageIO io, @Switch("c") MessageChannel outputChannel, @Switch("b") CommandBehavior behavior, @Switch("n") DepositType useFlowNote, @Arg("Include past depositors in deposits sheet") @Switch("p") Set includePastDepositors) { + if (behavior == null) behavior = outputChannel == null ? CommandBehavior.EPHEMERAL : CommandBehavior.UNPRESS; // useFlowNoteStr String useFlowNoteStr = useFlowNote == null ? null : useFlowNote.toString(); // pastDepositorsStr @@ -848,7 +846,7 @@ public void econPanel(@Me GuildDB db, @Me IMessageIO io, @Switch("c") MessageCha String allianceStr = db.getAllianceIds().stream().map(f -> "AA:" + f).collect(Collectors.joining(",")) + ",#position>1,#vm_turns=0"; - CommandBehavior behavior = outputChannel == null ? CommandBehavior.EPHEMERAL : CommandBehavior.UNPRESS; + IMessageBuilder msg = io.create().embed(title, body); if (offshoreBalance) { @@ -883,7 +881,8 @@ public void econPanel(@Me GuildDB db, @Me IMessageIO io, @Switch("c") MessageCha @Command(desc = "Discord embed for Internal Affairs Staff to auto-assign roles and view member activity, audit results, daychange, spy purchase, mmr") @RolePermission(Roles.ADMIN) @IsAlliance - public void iaPanel(@Me GuildDB db, @Me IMessageIO io, @Switch("c") MessageChannel outputChannel) { + public void iaPanel(@Me GuildDB db, @Me IMessageIO io, @Switch("c") MessageChannel outputChannel, @Switch("b") CommandBehavior behavior) { + if (behavior == null) behavior = outputChannel == null ? CommandBehavior.EPHEMERAL : CommandBehavior.UNPRESS; String title = "IA Panel"; String body = """ Press `audit` to view member audit sheet @@ -900,8 +899,6 @@ public void iaPanel(@Me GuildDB db, @Me IMessageIO io, @Switch("c") MessageChann body += "\n\n> Results in <#" + channelId + ">"; } - CommandBehavior behavior = outputChannel == null ? CommandBehavior.EPHEMERAL : CommandBehavior.UNPRESS; - String allianceStr = db.getAllianceIds().stream().map(f -> "AA:" + f).collect(Collectors.joining(",")) + ",#position>1,#vm_turns=0"; IMessageBuilder msg = io.create().embed(title, body); @@ -1026,7 +1023,8 @@ public void allyEnemySheets(ValueStore store, NationPlaceholders placeholders, @Default SpreadSheet allEnemiesSheet, @Default SpreadSheet priorityEnemiesSheet, @Default SpreadSheet allAlliesSheet, - @Default SpreadSheet underutilizedAlliesSheet) throws GeneralSecurityException, IOException { + @Default SpreadSheet underutilizedAlliesSheet, @Default CommandBehavior behavior) throws GeneralSecurityException, IOException { + if (behavior == null) behavior = CommandBehavior.UNPRESS; Long channelId = outputChannel == null ? null : outputChannel.getIdLong(); if (db.getCoalition(Coalition.ALLIES).isEmpty()) { throw new IllegalArgumentException("No `" + Coalition.ALLIES.name() + "` coalition found. See: " + CM.coalition.create.cmd.toSlashMention()); @@ -1166,8 +1164,6 @@ public void allyEnemySheets(ValueStore store, NationPlaceholders placeholders, footer = "\n\n> Output in " + outputChannel.getAsMention(); } - CommandBehavior behavior = CommandBehavior.UNPRESS; - io.create() .embed("All Enemies Sheet", "Press `update` to update" + footer).commandButton(behavior, channelId, CM.nation.sheet.NationSheet.cmd.create( diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java index d93c4af9..6e500317 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java @@ -769,7 +769,7 @@ public String beigeAlertOptOut(@Me Member member, @Me DBNation me, @Me Guild gui return WarCommands.beigeAlertMode(member.getUser(), me, NationMeta.BeigeAlertMode.NO_ALERTS); } RateLimitUtil.queue(guild.addRoleToMember(member, role)); - return "Opted out of beige alerts"; + return "Opted out of beige alerts (remove the " + role.getName() + " role to opt in)"; } @Command(desc = "Unassign a mentee from all mentors") diff --git a/src/main/java/link/locutus/discord/db/NationDB.java b/src/main/java/link/locutus/discord/db/NationDB.java index 23924bc4..700f384d 100644 --- a/src/main/java/link/locutus/discord/db/NationDB.java +++ b/src/main/java/link/locutus/discord/db/NationDB.java @@ -3687,6 +3687,10 @@ public Set getActivityByDay(int nationId, long minTurn) { } public Map> getActivityByDay(long minDate, long maxDate) { + return getActivityByDay(minDate, maxDate, null); + } + + public Map> getActivityByDay(long minDate, long maxDate, Predicate includeNation) { // dates are inclusive long minTurn = TimeUtil.getTurn(minDate); long maxTurn = TimeUtil.getTurn(maxDate); @@ -3695,12 +3699,18 @@ public Map> getActivityByDay(long minDate, long maxDate) { stmt.setLong(2, maxTurn); Map> result = new Int2ObjectOpenHashMap<>(); + BiConsumer applyNation = includeNation == null ? + (nation, day) -> result.computeIfAbsent(nation, f -> new LongOpenHashSet()).add(day) : (nation, day) -> { + if (includeNation.test(nation)) { + result.computeIfAbsent(nation, f -> new LongOpenHashSet()).add(day); + } + }; try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { int id = rs.getInt(1); long day = rs.getLong(2); - result.computeIfAbsent(id, f -> new LongOpenHashSet()).add(day); + applyNation.accept(id, day); } } return result; diff --git a/src/main/java/link/locutus/wiki/pages/WikiWarAlertsPage.java b/src/main/java/link/locutus/wiki/pages/WikiWarAlertsPage.java index 3609b9d0..e3bdd3d4 100644 --- a/src/main/java/link/locutus/wiki/pages/WikiWarAlertsPage.java +++ b/src/main/java/link/locutus/wiki/pages/WikiWarAlertsPage.java @@ -78,11 +78,13 @@ public String generateMarkdown() { commandMarkdownSpoiler(CM.settings_beige_alerts.ENEMY_ALERT_CHANNEL.cmd, true), commandMarkdownSpoiler(CM.settings_beige_alerts.ENEMY_ALERT_CHANNEL_MODE.cmd, true), commandMarkdownSpoiler(CM.settings_beige_alerts.ENEMY_ALERT_FILTER.cmd, true), - "To opt out of enemy alerts:", + "#### Roles", + CM.role.setAlias.cmd.create(Roles.BEIGE_ALERT.name(), "@member", null, null).toString(), + "#### Opt out of enemy alerts:", CM.alerts.enemy.optout.cmd.toString(), "## Raiding Beige Alerts (raid targets)", CM.role.setAlias.cmd.create(Roles.BEIGE_ALERT.name(), "@member", null, null).toString(), - commandMarkdownSpoiler(CM.settings_beige_alerts.BEIGE_ALERT_CHANNEL.cmd, true), + commandMarkdownSpoiler(CM.settings_beige_alerts.BEIGE_ALERT_CHANNEL.cmd, true), ///alerts beige beigeAlertMode commandMarkdownSpoiler(CM.alerts.beige.beigeAlertOptOut.cmd, true), commandMarkdownSpoiler(CM.alerts.beige.beigeAlertMode.cmd, true),