utility: add decoration, fix snowflake parsing for appinfo/guildinfo

This commit is contained in:
Cynthia Foxwell 2023-11-20 12:07:35 -07:00
parent 43fac0f1de
commit 5fdcb094c6

View file

@ -38,6 +38,7 @@ const CHANNEL_ICON_BASE = CDN + "channel-icons/";
const APP_ICON_BASE = CDN + "app-icons/";
const APP_ASSET_BASE = CDN + "app-assets/";
const DISCOVERY_SPLASH_BASE = CDN + "discovery-splashes/";
const AVATAR_DECORATION_BASE = CDN + "avatar-decoration-presets/";
const DEFAULT_GROUP_DM_AVATARS = [
"/assets/ee9275c5a437f7dc7f9430ba95f12ebd.png",
@ -52,7 +53,7 @@ const DEFAULT_GROUP_DM_AVATARS = [
const CUSTOM_EMOTE_REGEX = /<(?:\u200b|&)?(a)?:(\w+):(\d+)>/;
const POMELO_REGEX = /^[a-z0-9._]{1,32}$/;
const SNOWFLAKE_REGEX = /[0-9]{17,21}/;
const SNOWFLAKE_REGEX = /([0-9]{17,21})/;
const NOWPLAYING_BAR_LENGTH = 30;
@ -667,11 +668,93 @@ banner.callback = async function (msg, line, [user], {server, guild}) {
};
hf.registerCommand(banner);
const decoration = new Command("decoration");
decoration.category = CATEGORY;
decoration.helpText = "Get decoration of a user";
decoration.usage = "<user>";
decoration.addAlias("decor");
decoration.callback = async function (msg, line, [user]) {
let id = msg.author.id;
if (user) {
const lookup = await lookupUser(msg, user);
if (
lookup == "No results" ||
lookup == "Canceled" ||
lookup == "Request timed out"
) {
return lookup;
} else {
id = lookup.id;
}
}
const userObj = await hf.bot.requestHandler.request(
"GET",
"/users/" + id,
true
);
let decor;
try {
const decorRes = await fetch(
`https://decor.fieryflames.dev/api/users/${id}/decoration`,
{
headers: {
"User-Agent":
"HiddenPhox/decoration (https://gitdab.com/Cynosphere/HiddenPhox)",
},
}
).then((res) => res.json());
decor = `https://decorcdn.fieryflames.dev/${decorRes.animated ? "a_" : ""}${
decorRes.hash
}.png`;
} catch {
// noop
}
if (!userObj.avatar_decoration_data && !decor)
return "This user does not have a decoration.";
const normalUrl =
userObj.avatar_decoration_data &&
`${AVATAR_DECORATION_BASE}${userObj.avatar_decoration_data.asset}.png?size=4096&passthrough=true`;
const baseEmbed = {
title: `Decoration for \`${formatUsername(userObj)}\``,
};
baseEmbed.description = (
(normalUrl ? `[Normal decoration](${normalUrl})` : "") +
(decor ? `\n[Decor decoration](${decor})` : "")
).trim();
if (
userObj.avatar_decoration_data?.asset.startsWith("a_") ||
decor?.indexOf("/a_") > -1
) {
baseEmbed.description += "\n(Animated decoration, open in browser to view)";
baseEmbed.description = baseEmbed.description.trim();
}
baseEmbed.url = normalUrl || decor;
const decorEmbed = {...baseEmbed};
baseEmbed.image = {url: normalUrl || decor};
decorEmbed.image = {url: decor};
return {
embeds: [baseEmbed, decor && decorEmbed].filter((x) => x != null),
};
};
hf.registerCommand(decoration);
const lookupinvite = new Command("lookupinvite");
lookupinvite.category = CATEGORY;
lookupinvite.helpText = "Lookup an invite";
lookupinvite.usage = "<invite code>";
lookupinvite.addAlias("linvite");
lookupinvite.addAlias("inviteinfo");
lookupinvite.addAlias("iinfo");
lookupinvite.addAlias("ii");
lookupinvite.callback = async function (msg, line) {
@ -1445,10 +1528,12 @@ appinfo.callback = async function (msg, line) {
if (!line || line === "") return "Arguments required.";
if (!SNOWFLAKE_REGEX.test(line)) return "Not a snowflake.";
const snowflake = line.match(SNOWFLAKE_REGEX)[1];
try {
const _app = await hf.bot.requestHandler.request(
"GET",
`/applications/${line}/rpc`,
`/applications/${snowflake}/rpc`,
false
);
@ -1765,9 +1850,11 @@ const guildinfo = new Command("guildinfo");
guildinfo.category = CATEGORY;
guildinfo.helpText = "Get information on a guild";
guildinfo.usage = "<guild id>";
guildinfo.addAlias("guild");
guildinfo.addAlias("ginfo");
guildinfo.addAlias("gi");
guildinfo.addAlias("serverinfo");
guildinfo.addAlias("server");
guildinfo.addAlias("sinfo");
guildinfo.addAlias("si");
guildinfo.callback = async function (msg, line) {
@ -1777,7 +1864,8 @@ guildinfo.callback = async function (msg, line) {
_guild = {source: "local", data: msg.channel.guild};
} else {
if (!SNOWFLAKE_REGEX.test(line)) return "Not a snowflake.";
_guild = await getGuild(line);
const snowflake = line.match(SNOWFLAKE_REGEX)[1];
_guild = await getGuild(snowflake);
}
if (!_guild) return "Guild not found.";