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:
parent
1706be9cf9
commit
eec98d7e5c
3 changed files with 25 additions and 6 deletions
|
@ -8,7 +8,8 @@ module.exports = {
|
|||
"TWITCH_BOT_KEY": "",
|
||||
"TWITCH_BOT_USERNAME": "",
|
||||
"TWITCH_BOT_COLOR_MODE": "loop",
|
||||
"TWITCH_BOT_INTERVAL": 10
|
||||
"TWITCH_BOT_INTERVAL": 10,
|
||||
"TWITCH_BOT_DEFAULT_COLOR": "F1C40F"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
24
index.js
24
index.js
|
@ -4,9 +4,8 @@ const chalk = require("chalk");
|
|||
|
||||
const sleep = (waitTimeInMs) => new Promise(resolve => setTimeout(resolve, waitTimeInMs));
|
||||
|
||||
let hue = 48;
|
||||
let sat = 89;
|
||||
let light = 50;
|
||||
let defaultcolor = process.env.TWITCH_BOT_DEFAULT_COLOR || "F1C40F";
|
||||
let [ hue, sat, light ] = convert.rgb.hsl(convert.hex.rgb(defaultcolor));
|
||||
|
||||
let connected = false;
|
||||
|
||||
|
@ -88,3 +87,22 @@ const intervalTime = process.env.TWITCH_BOT_INTERVAL * 1000 || 10000;
|
|||
interval = setInterval(function () {
|
||||
updateColor();
|
||||
}, 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "colorbot-twitch",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"main": "index.js",
|
||||
"author": "Manuel Hüsers",
|
||||
"license": "MIT",
|
||||
|
|
Loading…
Reference in a new issue