Initial commit

This commit is contained in:
GameKuchen 2023-01-13 18:16:05 +01:00
commit 1aba2be026
4 changed files with 59 additions and 0 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
WEBHOOK=[YourWebhook]

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Project exclude paths
/node_modules/

38
app.js Normal file
View File

@ -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);

18
package.json Normal file
View File

@ -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"
}
}