misc: add color
This commit is contained in:
parent
105f5c2eee
commit
f971240c03
1 changed files with 82 additions and 0 deletions
|
@ -9,6 +9,8 @@ const {
|
|||
formatTime,
|
||||
} = require("../lib/utils.js");
|
||||
const GoogleImages = require("google-images");
|
||||
const {tinycolor, random: randomColor} = require("@ctrl/tinycolor");
|
||||
const sharp = require("sharp");
|
||||
|
||||
const imagesClient = new GoogleImages(hf.apikeys.gimg, hf.apikeys.google);
|
||||
|
||||
|
@ -595,3 +597,83 @@ search.callback = async function (msg, line, args, {results = 2}) {
|
|||
return out.trim();
|
||||
};
|
||||
hf.registerCommand(search);
|
||||
|
||||
const color = new Command("color");
|
||||
color.category = CATEGORY;
|
||||
color.helpText = "Show information on a color or get a random color";
|
||||
color.callback = async function (msg, line, args, {truerandom}) {
|
||||
let color = tinycolor(line),
|
||||
random = false;
|
||||
|
||||
if (!line || line == "" || args.length == 0) {
|
||||
color = truerandom
|
||||
? tinycolor(Math.floor(Math.random() * 0xffffff))
|
||||
: randomColor();
|
||||
random = true;
|
||||
}
|
||||
|
||||
if (!color.isValid) {
|
||||
return "Color not valid.";
|
||||
}
|
||||
|
||||
const image = await sharp({
|
||||
create: {
|
||||
width: 128,
|
||||
height: 128,
|
||||
channels: 3,
|
||||
background: {r: color.r, g: color.g, b: color.b},
|
||||
},
|
||||
})
|
||||
.png()
|
||||
.toBuffer();
|
||||
const fileName = `${color.toHex()}.png`;
|
||||
|
||||
return {
|
||||
embeds: [
|
||||
{
|
||||
title: random ? "Random Color" : "",
|
||||
color: color.toNumber(),
|
||||
thumbnail: {
|
||||
url: `attachment://${fileName}`,
|
||||
},
|
||||
fields: [
|
||||
color.toName() && {
|
||||
name: "Name",
|
||||
value: color.toName(),
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Hex",
|
||||
value: color.toHexString(),
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "RGB",
|
||||
value: color.toRgbString(),
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "HSL",
|
||||
value: color.toHslString(),
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "HSV",
|
||||
value: color.toHsvString(),
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Integer",
|
||||
value: color.toNumber(),
|
||||
inline: true,
|
||||
},
|
||||
].filter((f) => f != null),
|
||||
},
|
||||
],
|
||||
file: {
|
||||
file: image,
|
||||
name: fileName,
|
||||
},
|
||||
};
|
||||
};
|
||||
hf.registerCommand(color);
|
||||
|
|
Loading…
Reference in a new issue