diff --git a/build.gradle b/build.gradle index 2cd3442d..65f6aaad 100644 --- a/build.gradle +++ b/build.gradle @@ -209,7 +209,7 @@ dependencies { runtimeOnly "ai.djl.pytorch:pytorch-engine:0.28.0" runtimeOnly "ai.djl.pytorch:pytorch-model-zoo:0.28.0" implementation "ai.djl.huggingface:tokenizers:0.28.0" -// runtimeOnly 'ai.djl.pytorch:pytorch-native-cu121:2.2.2:win-x86_64' + runtimeOnly 'ai.djl.pytorch:pytorch-native-cu121:2.2.2:win-x86_64' runtimeOnly 'ai.djl.pytorch:pytorch-jni:2.2.2-0.28.0' // implementation 'net.sourceforge.tess4j:tess4j:4.5.1' implementation 'org.bytedeco:javacv:1.5.6' diff --git a/src/main/java/link/locutus/discord/commands/info/optimal/OptimalBuild.java b/src/main/java/link/locutus/discord/commands/info/optimal/OptimalBuild.java index 20ffadda..a3a4d24e 100644 --- a/src/main/java/link/locutus/discord/commands/info/optimal/OptimalBuild.java +++ b/src/main/java/link/locutus/discord/commands/info/optimal/OptimalBuild.java @@ -125,6 +125,7 @@ public String onCommand(IMessageIO io, Guild guild, User author, DBNation me, Li Integer days = null; if (args.size() >= 2 && MathMan.isInteger(args.get(0))) { days = Integer.parseInt(args.get(0)); + args.remove(0); } JavaCity origin; diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/command/AMessageBuilder.java b/src/main/java/link/locutus/discord/commands/manager/v2/command/AMessageBuilder.java index cdb5cfcf..54961bca 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/command/AMessageBuilder.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/command/AMessageBuilder.java @@ -452,7 +452,7 @@ public IMessageBuilder linkButton(String url, String message) { @Override public IMessageBuilder image(String name, byte[] data) { - if (!name.endsWith(".png") || !name.endsWith(".jpg")) throw new IllegalArgumentException("Invalid image extension (only png jpg supported): `" + name + "`"); + if (!name.endsWith(".png") && !name.endsWith(".jpg")) throw new IllegalArgumentException("Invalid image extension (only png jpg supported): `" + name + "`"); images.put(name, data); return this; } diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/AdminCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/AdminCommands.java index 65a5feaf..80f07698 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/AdminCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/AdminCommands.java @@ -997,7 +997,8 @@ public String announce(@Me GuildDB db, @Me Guild guild, @Me JSONObject command, @Arg("The subject used for sending an in-game mail if a discord direct message fails") String subject, @Arg("The message you want to send") @TextArea String announcement, @Arg("Lines of replacement words or phrases, separated by `|` for each variation\n" + - "Add multiple lines for each replacement you want") @TextArea String replacements, + "Add multiple lines for each replacement you want\n" + + "You can use \\n for newline for discord slash commands") @TextArea String replacements, @Arg("The channel to post the announcement to (must be same server)") @Switch("c") MessageChannel channel, @Arg("The text to post in the channel below the hidden announcement (e.g. mentions)") @Switch("b") String bottomText, @Arg("The required number of differences between each message") @Switch("v") @Default("0") Integer requiredVariation, 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 ddb95161..96252bac 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 @@ -1046,7 +1046,7 @@ public void depositsPanel(@Me GuildDB db, @Me IMessageIO io, @Arg("Only applicab CM.deposits.check deposits = CM.deposits.check.cmd.nationOrAllianceOrGuild("nation:{nation_id}"); CM.transfer.self self = CM.transfer.self.cmd.amount(""); - CM.transfer.resources other = CM.transfer.resources.cmd.receiver("").transfer("").nationAccount("{nation_id}"); + CM.transfer.resources other = CM.transfer.resources.cmd.receiver("").transfer("").nationAccount("{nation_id}").depositType("#ignore"); CM.nation.stockpile stockpile = CM.nation.stockpile.cmd.nationOrAlliance("nation:{nation_id}"); CommandBehavior behavior = CommandBehavior.EPHEMERAL; 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 90835b8b..899092be 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 @@ -1401,12 +1401,12 @@ public static String leftAA(@Me IMessageIO io, @Me Guild guild, @Me User author, if (r.getFromId() != 0) { fromStr = PW.getMarkdownUrl(r.getFromId(), true) + "\t" + r.getFromRank().name(); } else { - fromStr = "0"; + fromStr = "0\tNONE"; } if (r.getToId() != 0) { toStr = PW.getMarkdownUrl(r.getToId(), true) + "\t" + r.getToRank().name(); } else { - toStr = "0"; + toStr = "0\tNONE"; } String diffStr = TimeUtil.secToTime(TimeUnit.MILLISECONDS, diff); response.append(diffStr + "\t" + natStr + "\t" + fromStr + "\t" + toStr + "\n"); diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UtilityCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UtilityCommands.java index 15c0f296..4a88f1f6 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UtilityCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UtilityCommands.java @@ -516,7 +516,8 @@ public String listOffshores() { return response.toString(); } - @Command(desc = "Mark an alliance as the offshore of another") + @Command(desc = "Mark an alliance as the offshore of another\n" + + "This is solely for informational purposes such as when displaying an alliance's info or militarization") public String markAsOffshore(@Me User author, @Me DBNation me, DBAlliance offshore, DBAlliance parent) { if (!Roles.ADMIN.hasOnRoot(author)) { DBAlliance expectedParent = offshore.findParentOfThisOffshore(); diff --git a/src/main/java/link/locutus/discord/db/NationDB.java b/src/main/java/link/locutus/discord/db/NationDB.java index d1e94011..54b840ca 100644 --- a/src/main/java/link/locutus/discord/db/NationDB.java +++ b/src/main/java/link/locutus/discord/db/NationDB.java @@ -4381,8 +4381,11 @@ public List getRemovesByNation(int nationId) { return getRemovesByNation(nationId, null); } public List getRemovesByNation(int nationId, Long date) { - try (PreparedStatement stmt = prepareQuery("select * FROM KICKS2 WHERE nation = ? " + (date != null ? " AND date > ? " : "") + "ORDER BY date DESC")) { + try (PreparedStatement stmt = prepareQuery("select * FROM KICKS2 WHERE nation = ? " + (date != null && date != 0 ? "AND date > ? " : "") + "ORDER BY date DESC")) { stmt.setInt(1, nationId); + if (date != null) { + stmt.setLong(2, date); + } List list = new ObjectArrayList<>(); diff --git a/src/main/java/link/locutus/discord/util/ImageUtil.java b/src/main/java/link/locutus/discord/util/ImageUtil.java index 46133bd4..44581fa8 100644 --- a/src/main/java/link/locutus/discord/util/ImageUtil.java +++ b/src/main/java/link/locutus/discord/util/ImageUtil.java @@ -258,11 +258,25 @@ public static String getTextLocal(String imageUrl, ImageType type) { } File fileAbs = fileTmp.getAbsoluteFile(); String result = ocr.discernAndAutoCleanImage(fileAbs, type); - result = result.replace("|", "I"); + result = fixEncodingIssues(result.replace("|", "I")); fileTmp.delete(); return result; } + private static String fixEncodingIssues(String text) { + return text.replaceAll("\u00e2\u20ac\u2122", "\u2019") + .replaceAll("\u00e2\u20ac\u0153", "\u201C") + .replaceAll("\u00e2\u20ac\u017d", "\u201D") + .replaceAll("\u00e2\u20ac\u201c", "\u2013") + .replaceAll("\u00e2\u20ac\u201d", "\u2014") + .replaceAll("\u00e2\u20ac\u02dc", "\u2018") + .replaceAll("\u00e2\u20ac\u00a2", "\u2022") + .replaceAll("\u00e2\u20ac\u00a6", "\u2026") + .replaceAll("\u00e2\u20ac", "\u2020") + .replaceAll("\u00e2\u201e\u00a2", "\u2122") + .replaceAll("\u00c2", ""); + } + public static File downloadImageWithSizeLimit(String imageUrl, long maxSizeBytes) throws IOException { if (!isDiscordImage(imageUrl)) { throw new IllegalArgumentException("URL is not from cdn.discordapp.com"); diff --git a/src/main/java/link/locutus/discord/util/StringMan.java b/src/main/java/link/locutus/discord/util/StringMan.java index 6a7e33bc..0cfac333 100644 --- a/src/main/java/link/locutus/discord/util/StringMan.java +++ b/src/main/java/link/locutus/discord/util/StringMan.java @@ -640,10 +640,9 @@ public static List split(String input, BiFunction> getTargetsDTC(SpreadSheet sheet, boolea // Att Safety int AttSafety2Index = -1; + int rowsWithValues = 0; int nationIndex = 0; int headerIndex = -1; + String lastRowValue = ""; outer: for (int i = 0; i < rows.size(); i++) { List row = rows.get(i); @@ -461,15 +463,20 @@ public static Map> getTargetsDTC(SpreadSheet sheet, boolea if (row.isEmpty()) continue; // Leader / Nation for (int column = 0; column < row.size(); column++) { - if (row.get(column) != null && row.get(column).toString().toLowerCase(Locale.ROOT).equalsIgnoreCase("Leader / Nation")) { - nationIndex = column; - headerIndex = i; - break outer; + Object value = row.get(column); + if (value != null && !value.toString().isEmpty()) { + rowsWithValues++; + lastRowValue = value.toString(); + if (lastRowValue.toLowerCase(Locale.ROOT).equalsIgnoreCase("Leader / Nation")) { + nationIndex = column; + headerIndex = i; + break outer; + } } } } if (headerIndex == -1) { - throw new IllegalArgumentException("No header found containing `Leader / Nation`"); + throw new IllegalArgumentException("No header found containing `Leader / Nation`. Found " + rowsWithValues + " rows with values (out of " + rows.size() + ") / " + lastRowValue); } List header = rows.get(headerIndex); diff --git a/src/main/java/link/locutus/discord/web/jooby/AwsManager.java b/src/main/java/link/locutus/discord/web/jooby/AwsManager.java index a3532ed5..482d2f6f 100644 --- a/src/main/java/link/locutus/discord/web/jooby/AwsManager.java +++ b/src/main/java/link/locutus/discord/web/jooby/AwsManager.java @@ -46,7 +46,6 @@ public void putObject(String key, byte[] data, long maxAge) { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(data.length); - System.out.println("Max age " + maxAge); metadata.setCacheControl("max-age=" + maxAge); ByteArrayInputStream inputStream = new ByteArrayInputStream(data);