From 9ddc4f77e41ee3632fed598ab12855efff632e08 Mon Sep 17 00:00:00 2001 From: xdnw Date: Thu, 30 May 2024 09:08:31 +0100 Subject: [PATCH] Add beige alert auto test command --- .../v2/impl/pw/commands/WarCommands.java | 33 +++++++++++++++++++ .../locutus/discord/db/guild/GuildKey.java | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/WarCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/WarCommands.java index 90d876aa..d2790a7d 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/WarCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/WarCommands.java @@ -165,6 +165,38 @@ public static String beigeAlertMode(@Me User user, @Me DBNation me, NationMeta.B return response.toString(); } + @Command(desc = "Set the types of nations to receive automatic beige alerts for", aliases = {"beigeAlertMode", "setBeigeAlertMode"}) + @WhitelistPermission + @RolePermission(value = {Roles.BEIGE_ALERT, Roles.BEIGE_ALERT_OPT_OUT}, any = true) + @CoalitionPermission(Coalition.RAIDPERMS) + public String testBeigeAlertAuto(@Me GuildDB db, @Me DBNation me, @Me Member member) { + NationMeta.BeigeAlertMode mode = me.getBeigeAlertMode(NationMeta.BeigeAlertMode.NO_ALERTS); + if (mode == NationMeta.BeigeAlertMode.NO_ALERTS) { + return "Please enable via: " + CM.alerts.beige.beigeAlertMode.cmd.toSlashMention(); + } + NationMeta.BeigeAlertRequiredStatus requiredStatus = me.getBeigeRequiredStatus(NationMeta.BeigeAlertRequiredStatus.ONLINE); + if (!requiredStatus.getApplies().test(member)) { + return "You are not online on discord. You can change this via: " + CM.alerts.beige.beigeAlertRequiredStatus.cmd.toSlashMention(); + } + Role role = Roles.BEIGE_ALERT.toRole(db); + Role optOut = Roles.BEIGE_ALERT_OPT_OUT.toRole(db); + Set allianceIds = db.getAllianceIds(); + try { + LeavingBeigeAlert.testBeigeAlertAuto(db, member, role, optOut, allianceIds, true, false); + } catch (IllegalArgumentException e) { + return e.getMessage(); + } + StringBuilder result = new StringBuilder(); + result.append("**Result: Success**\n"); + result.append("- require-role:").append(role == null ? "N/A" : role.getName()).append("=").append(member.getRoles().contains(role)).append("\n"); + result.append("- optout:").append(optOut == null ? "N/A" : optOut.getName()).append("=").append(member.getRoles().contains(optOut)).append("\n"); + result.append("- mode:").append(me.getBeigeAlertMode(null)).append(" (default:`NO_ALERTS`)\n"); + result.append("- score-leway:").append(me.getMeta(NationMeta.BEIGE_ALERT_SCORE_LEEWAY)).append(" (default:`0ns`)\n"); + result.append("- required-loot:").append(me.getMeta(NationMeta.BEIGE_ALERT_REQUIRED_LOOT)).append(" (default:`$15m`)\n"); + result.append("- required-status:").append(requiredStatus.name()).append("(default:`ONLINE`)\n"); + return result.toString(); + } + @Command(desc = "Only get the automatic beige alerts if you have the online status on discord\n" + "Note: You will still receive alerts for targets you have subscribed to via `{prefix}alerts beige beigereminders`", aliases = {"beigeAlertRequiredStatus", "setBeigeAlertRequiredStatus"}) @@ -172,6 +204,7 @@ public static String beigeAlertMode(@Me User user, @Me DBNation me, NationMeta.B @CoalitionPermission(Coalition.RAIDPERMS) public String beigeAlertRequiredStatus(@Me DBNation me, NationMeta.BeigeAlertRequiredStatus status) { me.setMeta(NationMeta.BEIGE_ALERT_REQUIRED_STATUS, (byte) status.ordinal()); + NationMeta.BeigeAlertMode mode = me.getBeigeAlertMode(NationMeta.BeigeAlertMode.NO_ALERTS); return "Set beige alert required status to " + status; } diff --git a/src/main/java/link/locutus/discord/db/guild/GuildKey.java b/src/main/java/link/locutus/discord/db/guild/GuildKey.java index c38cf417..d5fbcdeb 100644 --- a/src/main/java/link/locutus/discord/db/guild/GuildKey.java +++ b/src/main/java/link/locutus/discord/db/guild/GuildKey.java @@ -1823,7 +1823,7 @@ public String help() { "- active in the past 24h" + "- Have a free offensive war slot\n" + "- Have at least 70% of the target's military\n" + - "- Are online, away, or DND on discord"; + "- Are online, away, or DND on discord, or have the `" + Roles.ENEMY_ALERT_OFFLINE.name() + "` role"; } }.setupRequirements(f -> f.requires(ALLIANCE_ID).requiresCoalition(Coalition.ENEMIES).requireValidAlliance().requireActiveGuild()); public static GuildSetting ENEMY_ALERT_CHANNEL_MODE = new GuildEnumSetting(GuildSettingCategory.BEIGE_ALERTS, EnemyAlertChannelMode.class) {