Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/xdnw/locutus
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Aug 11, 2024
2 parents 07cf7c4 + f13d88b commit c7b69b7
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/link/locutus/discord/db/NationDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -4381,8 +4381,11 @@ public List<AllianceChange> getRemovesByNation(int nationId) {
return getRemovesByNation(nationId, null);
}
public List<AllianceChange> 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<AllianceChange> list = new ObjectArrayList<>();

Expand Down
16 changes: 15 additions & 1 deletion src/main/java/link/locutus/discord/util/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/link/locutus/discord/util/StringMan.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,9 @@ public static List<String> split(String input, BiFunction<String, Integer, Integ
toAdd = toAdd.substring(1, toAdd.length() - 1);
}
if (!toAdd.trim().isEmpty()) result.add(toAdd);
} else if (inQuotes) {
result.add("");
}
start = current + foundLen;
current = start - 1;
if (--limit <= 1) {
startsWith = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,24 +452,31 @@ public static Map<DBNation, List<Spyop>> 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<Object> row = rows.get(i);
System.out.println("Row " + i + " | " + StringMan.getString(row));
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<Object> header = rows.get(headerIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c7b69b7

Please sign in to comment.