HiddenPhox/src/lib/utils.js
2021-03-14 21:18:05 -06:00

25 lines
620 B
JavaScript

const {v3} = require("murmurhash");
const colorcolor = require("colorcolor");
function pastelize(id) {
const hue = v3(id) % 360;
const hex = colorcolor(`hsl(${hue},75%,60%)`, "hex");
return parseInt(hex.substring(1), 16);
}
function getTopColor(msg, id, fallback = 0x7289da) {
if (!msg.channel.guild) return fallback;
const roles = msg.channel.guild.members
.get(id)
.roles.map((role) => msg.channel.guild.roles.get(role))
.filter((role) => role.color);
roles.sort((a, b) => b.position - a.position);
return roles[0]?.color || fallback;
}
module.exports = {
pastelize,
getTopColor,
};