Files
discordeno/plugins/bot/util/hash.ts
Skillz4Killz ffe7cdbc6f feat: base plugin lib idea (#2308)
* feat: base plugin lib idea

* fix: stuff

* fmt

* fix: imports and exports

* fix: errors & tests

* fix: remove logs
2022-06-18 18:46:37 -04:00

20 lines
686 B
TypeScript

export function iconHashToBigInt(hash: string) {
// The icon is animated so it needs special handling
if (hash.startsWith("a_")) {
// Change the `a_` to just be `a`
hash = `a${hash.substring(2)}`;
} else {
// The icon is not animated but it could be that it starts with a 0 so we just put a `b` in front so nothing breaks
hash = `b${hash}`;
}
return BigInt(`0x${hash}`);
}
export function iconBigintToHash(icon: bigint) {
// Convert the bigint back to a hash
const hash = icon.toString(16);
// Hashes starting with a are animated and with b are not so need to handle that
return hash.startsWith("a") ? `a_${hash.substring(1)}` : hash.substring(1);
}