Skip to content

Commit

Permalink
Fix item updater stalling after sending Discord webhook message
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Dec 13, 2024
1 parent 0d6bebc commit d8f1030
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions updater/update_items.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FormData from "form-data";
import fs from "fs/promises";
import jsonDiff from "json-diff";
import { colorize, diff } from "json-diff";
import lua from "lua-json";
import fetch from "node-fetch";
import { JSDOM } from "jsdom";
Expand Down Expand Up @@ -448,33 +448,30 @@ class ItemUpdater {
const updater = new ItemUpdater(OVERWRITES, BLACKLIST);
await updater.run();

const difference = jsonDiff.diffString(existingItems, updater.processedItems);
const difference = diff(existingItems, updater.processedItems);
if (difference || process.env.FORCE_UPLOAD === "true") {
await fs.writeFile("items.json", JSON.stringify(updater.processedItems));
console.log(difference);
console.log(colorize(difference));
console.log(
`File size: ${((await fs.stat("items.json")).size / 1024).toFixed(3)}KB`
);

if (process.env.DISCORD_WEBHOOK && process.env.DISCORD_ADMIN_IDS) {
const colorlessDifference = difference.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
""
);
const form = new FormData();
form.append(
"content",
process.env.DISCORD_ADMIN_IDS.split(",")
.map(id => `<@${id}>`)
.join(" ")
);
form.append("file", colorlessDifference, "items.diff");
form.submit(process.env.DISCORD_WEBHOOK, (err) => {
form.append("file", colorize(difference, { color: false }), "items.diff");
form.submit(process.env.DISCORD_WEBHOOK, (err, res) => {
if (err) {
console.log("Discord webhook error: " + err);
return;
}
console.log("Discord webhook message sent");
res.resume();
});
}
}
Expand Down

0 comments on commit d8f1030

Please sign in to comment.