commit 1aba2be02625bc7d72df2d0f290c61b372030697 Author: GameKuchen <49527417+GameKuchen@users.noreply.github.com> Date: Fri Jan 13 18:16:05 2023 +0100 Initial commit diff --git a/.env b/.env new file mode 100644 index 0000000..22e0de1 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +WEBHOOK=[YourWebhook] \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..748b458 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Project exclude paths +/node_modules/ \ No newline at end of file diff --git a/app.js b/app.js new file mode 100644 index 0000000..2607e4d --- /dev/null +++ b/app.js @@ -0,0 +1,38 @@ +const { Webhook } = require('discord-webhook-node'); +const rp = require('request-promise'); +require('dotenv').config() + +const hook = new Webhook(`${process.env.WEBHOOK}`); +const IMAGE_URL = 'https://tun-chemnitz.de/media/images/IMG_20220827_135030.max-640x480.jpg'; + +hook.setUsername('ChChHook'); +hook.setAvatar(IMAGE_URL); + +let currentStatus = false; + +function currentStatusRead(currentStatus) { + if (currentStatus === false) { + return 'geschlossen'; + } else { + return 'offen'; + } +} + +const options = { + url: 'https://chch.it/chch.json', +}; + +setInterval(function() { + rp(options) + .then((body) => { + const json = JSON.parse(body); + if (currentStatus !== json.state.open) { + currentStatus = json.state.open; + hook.send(`<@286015596875874305> ChCh ist jetzt ${currentStatusRead(currentStatus)}`); + console.log(json.state.open); + } + }) + .catch((err) => { + console.log(err); + }); +}, 60 * 1000); diff --git a/package.json b/package.json new file mode 100644 index 0000000..76c98e2 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "chchbot", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "discord-webhook-node": "^1.1.8", + "dotenv": "^16.0.3", + "request": "^2.88.2", + "request-promise": "^4.2.6" + } +}