Skip to content

Commit

Permalink
Command behavior options to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed May 22, 2024
1 parent 2365bd1 commit 24daf66
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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")
Expand All @@ -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 = """
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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());
}
Expand All @@ -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(
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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")
Expand All @@ -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());
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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")
Expand All @@ -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<Integer> 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<Integer> includePastDepositors) {
if (behavior == null) behavior = outputChannel == null ? CommandBehavior.EPHEMERAL : CommandBehavior.UNPRESS;
// useFlowNoteStr
String useFlowNoteStr = useFlowNote == null ? null : useFlowNote.toString();
// pastDepositorsStr
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/link/locutus/discord/db/NationDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -3687,6 +3687,10 @@ public Set<Long> getActivityByDay(int nationId, long minTurn) {
}

public Map<Integer, Set<Long>> getActivityByDay(long minDate, long maxDate) {
return getActivityByDay(minDate, maxDate, null);
}

public Map<Integer, Set<Long>> getActivityByDay(long minDate, long maxDate, Predicate<Integer> includeNation) {
// dates are inclusive
long minTurn = TimeUtil.getTurn(minDate);
long maxTurn = TimeUtil.getTurn(maxDate);
Expand All @@ -3695,12 +3699,18 @@ public Map<Integer, Set<Long>> getActivityByDay(long minDate, long maxDate) {
stmt.setLong(2, maxTurn);

Map<Integer, Set<Long>> result = new Int2ObjectOpenHashMap<>();
BiConsumer<Integer, Long> 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;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/link/locutus/wiki/pages/WikiWarAlertsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 24daf66

Please sign in to comment.