Properly exit program and use hex instead of hsl

* Properly exit on Ctrl+C and termination signal
* Define default username color and calculate HSL from this hex value
This commit is contained in:
Manuel 2021-01-18 23:16:34 +00:00
parent 1706be9cf9
commit eec98d7e5c
Signed by: Manuel
GPG key ID: 4085037435E1F07A
3 changed files with 25 additions and 6 deletions

View file

@ -8,8 +8,9 @@ module.exports = {
"TWITCH_BOT_KEY": "", "TWITCH_BOT_KEY": "",
"TWITCH_BOT_USERNAME": "", "TWITCH_BOT_USERNAME": "",
"TWITCH_BOT_COLOR_MODE": "loop", "TWITCH_BOT_COLOR_MODE": "loop",
"TWITCH_BOT_INTERVAL": 10 "TWITCH_BOT_INTERVAL": 10,
"TWITCH_BOT_DEFAULT_COLOR": "F1C40F"
} }
} }
] ]
} }

View file

@ -4,9 +4,8 @@ const chalk = require("chalk");
const sleep = (waitTimeInMs) => new Promise(resolve => setTimeout(resolve, waitTimeInMs)); const sleep = (waitTimeInMs) => new Promise(resolve => setTimeout(resolve, waitTimeInMs));
let hue = 48; let defaultcolor = process.env.TWITCH_BOT_DEFAULT_COLOR || "F1C40F";
let sat = 89; let [ hue, sat, light ] = convert.rgb.hsl(convert.hex.rgb(defaultcolor));
let light = 50;
let connected = false; let connected = false;
@ -88,3 +87,22 @@ const intervalTime = process.env.TWITCH_BOT_INTERVAL * 1000 || 10000;
interval = setInterval(function () { interval = setInterval(function () {
updateColor(); updateColor();
}, intervalTime); }, intervalTime);
const sigs = ['SIGINT', 'SIGTERM', 'SIGQUIT'];
sigs.forEach(sig => {
process.on(sig, () => {
console.log(sig + " received");
clearInterval(interval);
console.log(
`* Updating username color to`,
chalk.hex(`#${defaultcolor}`)(`#${defaultcolor}`)
);
client.color(`#${defaultcolor}`).then(() => client.disconnect());
console.log("Waiting 3 seconds before exiting...");
sleep(3000).then(() => {
process.exit(0);
});
});
});

View file

@ -1,6 +1,6 @@
{ {
"name": "colorbot-twitch", "name": "colorbot-twitch",
"version": "1.0.0", "version": "1.0.1",
"main": "index.js", "main": "index.js",
"author": "Manuel Hüsers", "author": "Manuel Hüsers",
"license": "MIT", "license": "MIT",