From beb1cf7bdc91d188e4d13a507ca3cf35f4668dc0 Mon Sep 17 00:00:00 2001 From: Norbert Maciaszek Date: Sat, 15 Nov 2025 20:06:29 +0100 Subject: [PATCH] Add sendMessage function for Discord notifications --- index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index df925e7..32057e5 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,12 @@ const priceSelectors = { const excludePage = ["allegro", "homla.com.pl", "home-you.com"]; +function sendMessage(message) { + axios.post(discordWebhook, { + content: message, + }); +} + async function compareAndSave(productsPrice) { const productsPriceJson = fs.readFileSync("productsPrice.json", "utf8") || "[]"; @@ -41,15 +47,13 @@ async function compareAndSave(productsPrice) { } for (const product of diffProducts) { - await axios.post(discordWebhook, { - content: `Zmiana ceny **${product.name}**:\nCena: ${product.oldPrice} -> ${product.newPrice}\nLink: ${product.link}`, - }); + sendMessage( + `Zmiana ceny **${product.name}**:\nCena: ${product.oldPrice} -> ${product.newPrice}\nLink: ${product.link}` + ); } if (diffProducts.length === 0) { - await axios.post(discordWebhook, { - content: "Brak zmian w cenach", - }); + sendMessage("Brak zmian w cenach"); } fs.writeFileSync( @@ -137,6 +141,7 @@ async function init() { console.log("Done! Check productsPrice.json"); } +sendMessage("Zaczynam monitoring cen"); cron.schedule("* */3 * * *", async () => { await init(); });