diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/discord/permission/CmdAlliancePermission.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/discord/permission/CmdAlliancePermission.java new file mode 100644 index 00000000..79ef7d52 --- /dev/null +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/discord/permission/CmdAlliancePermission.java @@ -0,0 +1,19 @@ +package link.locutus.discord.commands.manager.v2.impl.discord.permission; + +import link.locutus.discord.apiv1.enums.Rank; +import link.locutus.discord.apiv3.enums.AlliancePermission; +import link.locutus.discord.commands.manager.v2.binding.annotation.Command; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.PARAMETER, ElementType.METHOD}) +public @interface CmdAlliancePermission { + @Command(desc = "The alliance permissions required") + AlliancePermission[] value() default {}; + + boolean any() default false; +} diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/binding/PermissionBinding.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/binding/PermissionBinding.java index d618e11e..1a72c674 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/binding/PermissionBinding.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/binding/PermissionBinding.java @@ -1,21 +1,12 @@ package link.locutus.discord.commands.manager.v2.impl.pw.binding; import link.locutus.discord.Locutus; +import link.locutus.discord.apiv1.enums.Rank; +import link.locutus.discord.apiv3.enums.AlliancePermission; import link.locutus.discord.commands.manager.v2.binding.BindingHelper; import link.locutus.discord.commands.manager.v2.binding.annotation.Binding; import link.locutus.discord.commands.manager.v2.binding.annotation.Me; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.ClassPermission; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.CoalitionPermission; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.DenyPermission; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.HasApi; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.HasKey; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.HasOffshore; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.IsAlliance; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.IsGuild; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.NotGuild; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.RankPermission; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.RolePermission; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.WhitelistPermission; +import link.locutus.discord.commands.manager.v2.impl.discord.permission.*; import link.locutus.discord.commands.manager.v2.impl.pw.refs.CM; import link.locutus.discord.config.Settings; import link.locutus.discord.db.GuildDB; @@ -178,13 +169,32 @@ public boolean checkWhitelistPermission(@Me GuildDB db, CoalitionPermission perm @Binding("Must be registered to a nation with an in-game rank equal to or above the provided rank\n" + "Default: MEMBER") @RankPermission - public boolean checkRank(@Me Guild guild, RankPermission perm, @Me DBNation me) { + public boolean checkRank(RankPermission perm, @Me DBNation me) { if (me.getPosition() < perm.value().id) { throw new IllegalCallerException("Your ingame alliance positions is below " + perm.value()); } return true; } + @Binding("Must have the permissions ingame with their alliance") + @CmdAlliancePermission + public boolean checkRank(CmdAlliancePermission perm, @Me DBNation me) { + if (me.getPositionEnum().id >= Rank.HEIR.id) return true; + if (me.getPositionEnum().id <= Rank.APPLICANT.id) return false; + boolean hasAny = false; + for (AlliancePermission requiredPermission : perm.value()) { + if (!me.hasPermission(requiredPermission)) { + if (!perm.any()) throw new IllegalCallerException("You do not have " + requiredPermission + " in your alliance"); + } else { + hasAny = true; + } + } + if (!hasAny) { + throw new IllegalCallerException("You do not have any of " + Arrays.toString(perm.value()) + " in your alliance"); + } + return true; + } + @Binding("Deny all use") @DenyPermission public boolean deny(DenyPermission perm, @Me DBNation nation, @Me User user) { diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/ConflictCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/ConflictCommands.java index df627a66..f77f9c45 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/ConflictCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/ConflictCommands.java @@ -2,6 +2,7 @@ import link.locutus.discord.commands.manager.v2.binding.annotation.*; import link.locutus.discord.commands.manager.v2.binding.annotation.Timestamp; +import link.locutus.discord.commands.manager.v2.command.IMessageBuilder; import link.locutus.discord.commands.manager.v2.impl.discord.permission.CoalitionPermission; import link.locutus.discord.commands.manager.v2.impl.discord.permission.IsGuild; import link.locutus.discord.commands.manager.v2.impl.discord.permission.WhitelistPermission; @@ -54,6 +55,7 @@ import java.text.Normalizer; import java.text.ParseException; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -115,8 +117,10 @@ public String setWiki(@Me GuildDB db, ConflictManager manager, Conflict conflict url = url.substring(url.lastIndexOf("/") + 1); } conflict.setWiki(url); + String importResult = importWikiPage(db, manager, conflict.getName(), url, false, true); + conflict.push(manager, null, false, false); return "Set wiki to: `" + url + "`. Attempting to load additional wiki information...\n\n" + - importWikiPage(db, manager, conflict.getName(), url, false); + importResult; } @Command(desc = "Sets the wiki page for a conflict") @@ -124,6 +128,7 @@ public String setWiki(@Me GuildDB db, ConflictManager manager, Conflict conflict @CoalitionPermission(Coalition.MANAGE_CONFLICTS) public String setStatus(ConflictManager manager, Conflict conflict, String status) throws IOException { conflict.setStatus(status); + conflict.push(manager, null, false, false); return "Done! Set the status of `" + conflict.getName() + "` to `" + status + "`"; } @@ -132,6 +137,7 @@ public String setStatus(ConflictManager manager, Conflict conflict, String statu @CoalitionPermission(Coalition.MANAGE_CONFLICTS) public String setCB(ConflictManager manager, Conflict conflict, String casus_belli) throws IOException { conflict.setCasusBelli(casus_belli); + conflict.push(manager, null, false, false); return "Done! Set the casus belli of `" + conflict.getName() + "` to `" + casus_belli + "`"; } @@ -140,30 +146,39 @@ public String setCB(ConflictManager manager, Conflict conflict, String casus_bel @CoalitionPermission(Coalition.MANAGE_CONFLICTS) public String setCategory(ConflictManager manager, Conflict conflict, ConflictCategory category) throws IOException { conflict.setCategory(category); + conflict.push(manager, null, false, true); return "Done! Set the category of `" + conflict.getName() + "` to `" + category + "`"; } @Command(desc = "Pushes conflict data to the AWS bucket for the website") @RolePermission(Roles.MILCOM) @CoalitionPermission(Coalition.MANAGE_CONFLICTS) - public String syncConflictData(ConflictManager manager, @Default Set conflicts, @Switch("u") boolean upload_graph, @Switch("w") boolean reinitialize_wars, @Switch("g") boolean reinitialize_graphs) throws IOException, ParseException { + public String syncConflictData(@Me IMessageIO io, ConflictManager manager, @Default Set conflicts, @Switch("u") boolean upload_graph, @Switch("w") boolean reinitialize_wars, @Switch("g") boolean reinitialize_graphs) throws IOException, ParseException { AwsManager aws = manager.getAws(); if (aws == null) { throw new IllegalArgumentException("AWS is not configured in `config.yaml`"); } + CompletableFuture msgFuture; if (reinitialize_wars) { + msgFuture = io.send("Initializing wars..."); manager.loadConflictWars(conflicts, true); + } else { + msgFuture = io.send("Please wait..."); } if (reinitialize_graphs) { for (Conflict conflict : conflicts) { + io.updateOptionally(msgFuture, "Initializing graphs for " + conflict.getName() + "..."); conflict.updateGraphsLegacy(manager); } } if (conflicts != null) { List urls = new ArrayList<>(); for (Conflict conflict : conflicts) { - urls.addAll(conflict.push(manager, null, upload_graph)); + io.updateOptionally(msgFuture, "Pushing " + conflict.getName() + "..."); + urls.addAll(conflict.push(manager, null, upload_graph, false)); } + io.updateOptionally(msgFuture, "Pushing index..."); + urls.add(manager.pushIndex()); return "Done! See:\n- <" + StringMan.join(urls, ">\n- <") + ">"; } else { if (!manager.pushDirtyConflicts()) { @@ -190,6 +205,7 @@ public String deleteConflict(ConflictManager manager, @Me IMessageIO io, @Me JSO return null; } manager.deleteConflict(conflict); + manager.pushIndex(); return "Deleted conflict: #" + conflict.getId() + " - `" + conflict.getName() + "`" + "\nNote: this does not push the data to the site"; } @@ -255,8 +271,9 @@ public String setConflictEnd(ConflictManager manager, @Me JSONObject command, Co return "Set `" + conflict.getName() + "` end to " + TimeUtil.DD_MM_YYYY.format(time) + " for " + alliance.getMarkdownUrl(); } conflict.setEnd(time); + conflict.push(manager, null, false, true); return "Set `" + conflict.getName() + "` end to " + TimeUtil.DD_MM_YYYY.format(time) + - "\nNote: this does not push the data to the site"; + "\nNote: this does not recalculate conflict data"; } @Command(desc = "Set the start date for a conflict\n" + @@ -281,8 +298,9 @@ public String setConflictStart(ConflictManager manager, @Me JSONObject command, return "Set `" + conflict.getName() + "` start to " + TimeUtil.DD_MM_YYYY.format(time) + " for " + alliance.getMarkdownUrl(); } conflict.setStart(time); + conflict.push(manager, null, false, true); return "Set `" + conflict.getName() + "` start to " + TimeUtil.DD_MM_YYYY.format(time) + - "\nNote: this does not push the data to the site"; + "\nNote: this does not recalculate conflict data"; } @Command(desc = "Set the name of a conflict") @@ -310,8 +328,8 @@ public String setConflictName(ConflictManager manager, Conflict conflict, String sideName = "conflict"; conflict.setName(name); } - return "Changed " + sideName + " name `" + previousName + "` => `" + name + "`" + - "\nNote: this does not push the data to the site"; + conflict.push(manager, null, false, true); + return "Changed " + sideName + " name `" + previousName + "` => `" + name + "`"; } private int getFighting(DBAlliance alliance, Set enemyCoalition) { @@ -540,7 +558,8 @@ public String importAllianceNames(ConflictManager manager) throws IOException, P public String importWikiPage(@Me GuildDB db, ConflictManager manager, String name, @Default String url, - @Default("true") boolean useCache) throws IOException { + @Default("true") boolean useCache, + @Switch("p") boolean skipPushToSite) throws IOException { if (name.contains("http")) return "Please specify the name of the wiki page, not the URL for `name`"; if (url == null) { url = Normalizer.normalize(name.replace(" ", "_"), Normalizer.Form.NFKC); @@ -635,8 +654,14 @@ public String recalculateTables(ConflictManager manager, Set conflicts "This does not push the data to the site") @RolePermission(Roles.MILCOM) @CoalitionPermission(Coalition.MANAGE_CONFLICTS) - public String recalculateGraphs(ConflictManager manager, Set conflicts) throws IOException, ParseException { + public String recalculateGraphs(@Me IMessageIO io, ConflictManager manager, Set conflicts) throws IOException, ParseException { + CompletableFuture future = io.send("Please wait..."); + return recalculateGraphs2(io, future, manager, conflicts); + } + + private String recalculateGraphs2(@Me IMessageIO io, CompletableFuture updateMsg, ConflictManager manager, Set conflicts) throws IOException, ParseException { for (Conflict conflict : conflicts) { + io.updateOptionally(updateMsg, "Updating " + conflict.getName()); conflict.updateGraphsLegacy(manager); } return "Done!\nNote: this does not push the data to the site"; @@ -647,12 +672,14 @@ public String recalculateGraphs(ConflictManager manager, Set conflicts "This does not push the data to the site") @RolePermission(Roles.MILCOM) @CoalitionPermission(Coalition.MANAGE_CONFLICTS) - public String importConflictData(@Me GuildDB db, ConflictManager manager, + public String importConflictData(@Me IMessageIO io, @Me GuildDB db, ConflictManager manager, @Switch("c") boolean ctowned, @Switch("g") Set graphData, @Switch("a") boolean allianceNames, @Switch("w") boolean wiki, @Switch("s") boolean all) throws IOException, SQLException, ClassNotFoundException, ParseException { + CompletableFuture msgFuture = io.send("Please wait..."); + boolean loadGraphData = false; if (all) { Locutus.imp().getWarDb().loadWarCityCountsLegacy(); @@ -662,22 +689,37 @@ public String importConflictData(@Me GuildDB db, ConflictManager manager, loadGraphData = true; } if (allianceNames) { + io.updateOptionally(msgFuture, "Importing alliance names"); importAllianceNames(manager); } if (ctowned) { + io.updateOptionally(msgFuture, "Importing from ctowned.net"); importCtowned(db, manager, true); } if (wiki) { + io.updateOptionally(msgFuture, "Importing from wiki"); importWikiAll(db, manager, true); } if (loadGraphData && graphData == null) { + io.updateOptionally(msgFuture, "Recaculating tables"); graphData = new LinkedHashSet<>(manager.getConflictMap().values()); recalculateTables(manager, graphData); } if (graphData != null) { - recalculateGraphs(manager, graphData); + io.updateOptionally(msgFuture, "Recaculating graphs"); + recalculateGraphs2(io, msgFuture, manager, graphData); + if (all && !graphData.isEmpty()) { + io.updateOptionally(msgFuture, "Pushing data to the site"); + for (Conflict conflict : graphData) { + conflict.push(manager, null, true, false); + } + manager.pushIndex(); + return "Done!"; + } } - return "Done!\nNote: this does not push the data to the site"; + return "Done!\n" + + "Note: this does not push the data to the site\n" + + "See: " + CM.conflict.sync.website.cmd.toSlashMention(); } @Command(desc = "Configure the guilds and conflict ids that will be featured by this guild\n" + 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 4cab95f3..affed53d 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 @@ -2300,8 +2300,8 @@ public String iachannels(@Me User author, @Me DBNation me, @Me Guild guild, @Me @Command(desc = "Set the interview message") @RolePermission(Roles.INTERNAL_AFFAIRS) public String setInterview(@Me GuildDB db, IACategory category, String message) { - db.setCopyPasta("interview", message); - return "Set `interview` to:\n```md\n" + message + "```\n\nUse ";// TODO CM REF + CM.interview.questions.view.toSlashMention() + " to view"; + db.setCopyPasta("interview", message.replace("\\n", "\n")); + return "Set `interview` to:\n```md\n" + message + "```\n\nUse " + CM.interview.questions.view.cmd.toSlashMention() + " to view"; } @Command(desc = "View the interview message") @@ -2309,8 +2309,8 @@ public String setInterview(@Me GuildDB db, IACategory category, String message) public String viewInterview(@Me GuildDB db, IACategory category) { String message = db.getCopyPasta("interview", true); if (message == null) { - return "No message set. Set one with " + "";//TODO CM REF CM.interview.questions.set.cmd.toSlashMention(); + return "No message set. Set one with " + "" + CM.interview.questions.set.cmd.toSlashMention(); } - return "Interview questions:\n```md\n" + message + "```"; + return "Interview questions:\n" + message + ""; } } \ No newline at end of file diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UnsortedCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UnsortedCommands.java index d53a2db3..761302cb 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UnsortedCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UnsortedCommands.java @@ -21,11 +21,7 @@ import link.locutus.discord.commands.manager.v2.command.IMessageIO; import link.locutus.discord.commands.manager.v2.impl.discord.DiscordChannelIO; import link.locutus.discord.commands.manager.v2.impl.discord.DiscordHookIO; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.HasApi; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.HasOffshore; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.IsAlliance; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.RankPermission; -import link.locutus.discord.commands.manager.v2.impl.discord.permission.RolePermission; +import link.locutus.discord.commands.manager.v2.impl.discord.permission.*; import link.locutus.discord.commands.manager.v2.impl.pw.refs.CM; import link.locutus.discord.commands.manager.v2.impl.pw.TaxRate; import link.locutus.discord.commands.manager.v2.impl.pw.filter.NationPlaceholders; @@ -559,7 +555,7 @@ public String addApiKey(@Me IMessageIO io, @Me JSONObject command, String apiKey @Command(desc="Login to allow the bot to run scripts through your account\n" + "(Avoid using this if possible)") - @RankPermission(Rank.OFFICER) + @CmdAlliancePermission(AlliancePermission.WITHDRAW_BANK) public static String login(@Me IMessageIO io, DiscordDB discordDB, @Me DBNation me, @Arg("Your username (i.e. email) for Politics And War") String username, @@ -568,7 +564,7 @@ public static String login(@Me IMessageIO io, DiscordDB discordDB, @Me DBNation try { if (msg != null) io.delete(msg.getId()); } catch (Throwable ignore) {}; - if (me == null || me.getPosition() < Rank.OFFICER.id) return "You are not an officer of an alliance"; + if (me == null || !me.hasAllPermission(Set.of(AlliancePermission.WITHDRAW_BANK))) return "You are not an officer of an alliance"; DBAlliance alliance = me.getAlliance(); Auth existingAuth = alliance.getAuth();; if (existingAuth != null) { diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/VirtualConflictCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/VirtualConflictCommands.java index 9d731bb9..6428e8d1 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/VirtualConflictCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/VirtualConflictCommands.java @@ -55,7 +55,7 @@ public String createTemporary(@Me Guild guild, ConflictManager manager, @Me DBNa } String id = "n/" + nation.getId() + "/" + UUID.randomUUID(); - List urls = conflict.push(manager, id, true); + List urls = conflict.push(manager, id, true, false); return Settings.INSTANCE.WEB.S3.SITE + "/conflict?id=" + id; } diff --git a/src/main/java/link/locutus/discord/config/Settings.java b/src/main/java/link/locutus/discord/config/Settings.java index 4282ce6d..31ef5397 100644 --- a/src/main/java/link/locutus/discord/config/Settings.java +++ b/src/main/java/link/locutus/discord/config/Settings.java @@ -61,8 +61,8 @@ public class Settings extends Config { @Comment("Your api key (generated if username/password is set)") public String API_KEY_PRIMARY = ""; - @Comment({"A list of api keys the bot can use for requests (optional)", - "See: `/admin validateApiKeys`"}) + @Comment({"A list of api keys the bot can use for general requests (optional)", + "To validate these keys, see: `/admin validateApiKeys`"}) public List API_KEY_POOL = Arrays.asList(); @Comment({"The discord id of the bot (generated)", diff --git a/src/main/java/link/locutus/discord/db/WarDB.java b/src/main/java/link/locutus/discord/db/WarDB.java index 99e8c1b7..b1729c56 100644 --- a/src/main/java/link/locutus/discord/db/WarDB.java +++ b/src/main/java/link/locutus/discord/db/WarDB.java @@ -501,7 +501,7 @@ public void load() { activeWars.syncBlockades(); if (conflictManager != null) { -// conflictManager.loadConflicts(); + conflictManager.loadConflicts(); } } diff --git a/src/main/java/link/locutus/discord/db/conflict/Conflict.java b/src/main/java/link/locutus/discord/db/conflict/Conflict.java index 10661fe2..9b4f32bd 100644 --- a/src/main/java/link/locutus/discord/db/conflict/Conflict.java +++ b/src/main/java/link/locutus/discord/db/conflict/Conflict.java @@ -763,7 +763,7 @@ public Map getAnnouncement() { * @param includeGraphs * @return List of URLs */ - public List push(ConflictManager manager, String webIdOrNull, boolean includeGraphs) { + public List push(ConflictManager manager, String webIdOrNull, boolean includeGraphs, boolean updateIndex) { AwsManager aws = manager.getAws(); if (webIdOrNull == null) { if (getId() == -1) throw new IllegalArgumentException("Conflict has no id"); @@ -782,6 +782,9 @@ public List push(ConflictManager manager, String webIdOrNull, boolean in aws.putObject(graphKey, graphValue); urls.add(aws.getLink(graphKey)); } + if (updateIndex) { + manager.pushIndex(); + } return urls; } diff --git a/src/main/java/link/locutus/discord/db/conflict/ConflictManager.java b/src/main/java/link/locutus/discord/db/conflict/ConflictManager.java index 801d0e34..43877298 100644 --- a/src/main/java/link/locutus/discord/db/conflict/ConflictManager.java +++ b/src/main/java/link/locutus/discord/db/conflict/ConflictManager.java @@ -103,7 +103,7 @@ public boolean pushDirtyConflicts() { boolean hasDirty = false; for (Conflict conflict : getActiveConflicts()) { if (conflict.isDirty()) { - conflict.push(this, null, false); + conflict.push(this, null, false, false); hasDirty = true; } } @@ -242,13 +242,16 @@ public void updateAttack(DBWar war, AbstractCursor attack, Predicate al public void onTurnChange(TurnChangeEvent event) { long turn = event.getCurrent(); boolean updated = false; - List conflicts = new ArrayList<>(getActiveConflicts()); - for (Conflict conflict : conflicts) { - conflict.getSide(true).updateTurnChange(this, turn, true); - conflict.getSide(false).updateTurnChange(this, turn, false); - } - for (Conflict conflict : conflicts) { - conflict.push(this, null, true); + List conflicts = getActiveConflicts(); + if (!conflicts.isEmpty()) { + for (Conflict conflict : conflicts) { + conflict.getSide(true).updateTurnChange(this, turn, true); + conflict.getSide(false).updateTurnChange(this, turn, false); + } + for (Conflict conflict : conflicts) { + conflict.push(this, null, true, false); + } + pushIndex(); } } @@ -1263,6 +1266,7 @@ public byte[] getPsonGzip() { headers.add(entry.getKey()); funcs.add(entry.getValue()); } + root.put("headers", headers); List> rows = new ObjectArrayList<>(); JteUtil.writeArray(rows, funcs, map.values()); diff --git a/src/main/java/link/locutus/discord/db/entities/DBWar.java b/src/main/java/link/locutus/discord/db/entities/DBWar.java index 0d83ec1c..b7904314 100644 --- a/src/main/java/link/locutus/discord/db/entities/DBWar.java +++ b/src/main/java/link/locutus/discord/db/entities/DBWar.java @@ -33,6 +33,8 @@ public class DBWar { private byte warStatusType; private final long date; private char attDefCities; + private byte attDefActiveFlag; + public int getTurnsLeft() { return (int) (TimeUtil.getTurn() - TimeUtil.getTurn(getDate()) + 60); } @@ -48,6 +50,22 @@ public DBWar(int warId, int attacker_id, int defender_id, int attacker_aa, int d this.attDefCities = (char) (attCities | (defCities << 8)); } + public boolean isAttActive() { + return (attDefActiveFlag & 0x01) == 1; + } + + public boolean isDefActive() { + return (attDefActiveFlag & 0x02) == 2; + } + + public void setAttActive(boolean value) { + attDefActiveFlag = (byte) (value ? attDefActiveFlag | 0x01 : attDefActiveFlag & 0xFE); + } + + public void setDefActive(boolean value) { + attDefActiveFlag = (byte) (value ? attDefActiveFlag | 0x02 : attDefActiveFlag & 0xFD); + } + public int getAttCities() { return attDefCities & 0xFF; } diff --git a/src/main/java/link/locutus/discord/gpt/GPTModerator.java b/src/main/java/link/locutus/discord/gpt/GPTModerator.java index f5d6fa7f..93f32b44 100644 --- a/src/main/java/link/locutus/discord/gpt/GPTModerator.java +++ b/src/main/java/link/locutus/discord/gpt/GPTModerator.java @@ -88,13 +88,11 @@ public List moderate(List inputs) { public void addToObject(Object classWithProperties, JSONObject categoriesObject) { for (Field field : classWithProperties.getClass().getDeclaredFields()) { - if (field.isAnnotationPresent(JsonProperty.class)) { - try { - field.setAccessible(true); - categoriesObject.put(field.getName(), field.get(classWithProperties)); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } + try { + field.setAccessible(true); + categoriesObject.put(field.getName(), field.get(classWithProperties)); + } catch (IllegalAccessException e) { + e.printStackTrace(); } } } diff --git a/src/main/java/link/locutus/wiki/game/PWWikiUtil.java b/src/main/java/link/locutus/wiki/game/PWWikiUtil.java index 6b48fd86..b7076cdd 100644 --- a/src/main/java/link/locutus/wiki/game/PWWikiUtil.java +++ b/src/main/java/link/locutus/wiki/game/PWWikiUtil.java @@ -642,7 +642,9 @@ public static List loadWikiConflicts(Map errorsByPage, String name = entry.getKey(); String urlStub = entry.getValue(); Conflict conflict = loadWikiConflict(name, urlStub, errorsByPage, allowCache); - conflicts.add(conflict); + if (conflict != null) { + conflicts.add(conflict); + } } return conflicts; }