Utsuho Lights
This commit is contained in:
parent
24f18d44ad
commit
0276b3ff64
1 changed files with 50 additions and 0 deletions
50
src/modules/utsuholights.js
Normal file
50
src/modules/utsuholights.js
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
const Command = require("../lib/command.js");
|
||||||
|
const CATEGORY = "misc";
|
||||||
|
|
||||||
|
const fetch = require("node-fetch");
|
||||||
|
const colorcolor = require("colorcolor");
|
||||||
|
|
||||||
|
// taken from rot13.com
|
||||||
|
function rot(s, i) {
|
||||||
|
return s.replace(/[a-zA-Z]/g, function (c) {
|
||||||
|
return String.fromCharCode(
|
||||||
|
(c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + i) ? c : c - 26
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// im making it "hard" to get cause im bored :^)
|
||||||
|
const LIGHTS_URL = "nUE0pUZ6Yl9hqJAfMJSlYaI0p3Ibol5lo2Aepl9fnJqbqN==";
|
||||||
|
const HEX_REGEX = /^#?([0-9a-fA-F]{1,2})([0-9a-fA-F]{1,2})([0-9a-fA-F]{1,2})$/;
|
||||||
|
|
||||||
|
let cachedLightsURL; // saving compute time :^)
|
||||||
|
|
||||||
|
const utsuholights = new Command("utsuholights");
|
||||||
|
utsuholights.category = CATEGORY;
|
||||||
|
utsuholights.helpText = "Utsuho Lights";
|
||||||
|
utsuholights.usage = "<hex> [brightness]";
|
||||||
|
utsuholights.callback = async function (msg, line, hex, bri) {
|
||||||
|
if (!hex) {
|
||||||
|
return "Hex color required.";
|
||||||
|
}
|
||||||
|
if (!HEX_REGEX.test(hex)) {
|
||||||
|
return "Could not determine hex color.";
|
||||||
|
}
|
||||||
|
|
||||||
|
const [_, r, g, b] = colorcolor(hex, "rgb").match(/rgb\((\d+),(\d+),(\d+)\)/);
|
||||||
|
|
||||||
|
if (!cachedLightsURL) {
|
||||||
|
cachedLightsURL = Buffer.from(rot(LIGHTS_URL, 13), "base64").toString(); // Wow! It's That Easy!
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
`${cachedLightsURL}?r=${r}&g=${g}&b=${b}${bri ? `&bri=${bri}` : ""}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.status == 200) {
|
||||||
|
return {reaction: "\uD83D\uDC4C"};
|
||||||
|
} else {
|
||||||
|
return `:warning: An error occurred: \`${await response.text()}\``;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
hf.registerCommand(utsuholights);
|
Loading…
Reference in a new issue