From d0df64b48f954e2dcf3cee64e3ab23e2726ec3aa Mon Sep 17 00:00:00 2001 From: winsdominoes Date: Thu, 30 May 2024 12:47:18 +0700 Subject: [PATCH] raindar --- config/config.json.example | 3 ++- src/index.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/config/config.json.example b/config/config.json.example index 3c56a9f..8d57eb2 100644 --- a/config/config.json.example +++ b/config/config.json.example @@ -1,5 +1,6 @@ { "room": "", - "token": "" + "history": "", + "token": "", "timezone": "", } diff --git a/src/index.js b/src/index.js index 5a70c35..3c46b42 100644 --- a/src/index.js +++ b/src/index.js @@ -60,6 +60,8 @@ const curr_image_path = path.resolve("data", "current_radar.gif"); client.on('ready', () => { (async () => { const channel = client.channels.cache.get(config.room); + const webhooks = await channel.fetchWebhooks(); + const webhook = webhooks.first(); let radar_image = await get_rain_image(); let radar_caption = await get_radar_caption(); @@ -83,6 +85,13 @@ client.on('ready', () => { let message_id = message.id; console.log(`Sent ${message.id}: ${message.content}`); + + await webhook.send({ + content: caption, + files: [curr_image_path, "https://weather.bangkok.go.th/Images/Radar/radarh.jpg"], + threadId: config.history, + }); + console.log(`Sent message to history`) setInterval(async () => { let curr_image_size = fs.statSync(curr_image_path).size; @@ -118,7 +127,13 @@ client.on('ready', () => { console.log(`Sent ${message.id}: ${message.content}`); message_id = message.id; - console.log(message_id); + + await webhook.send({ + content: caption, + files: [curr_image_path, "https://weather.bangkok.go.th/Images/Radar/radarh.jpg"], + threadId: config.history, + }); + console.log(`Sent message to history`) } else { console.log("No change in data, go on."); }