Skip to content

Commit

Permalink
petpet: fix guild pfps
Browse files Browse the repository at this point in the history
  • Loading branch information
Vendicated committed Oct 12, 2022
1 parent 9b7ebe4 commit 8dff79d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/plugins/petpet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function loadImage(source: File | string) {
});
}

async function resolveImage(options: Argument[], ctx: CommandContext): Promise<File | string | null> {
async function resolveImage(options: Argument[], ctx: CommandContext, noServerPfp: boolean): Promise<File | string | null> {
for (const opt of options) {
switch (opt.name) {
case "image":
Expand All @@ -57,7 +57,7 @@ async function resolveImage(options: Argument[], ctx: CommandContext): Promise<F
case "user":
try {
const user = await fetchUser(opt.value);
return user.getAvatarURL(ctx.guild, 2048).replace(/\?size=\d+$/, "?size=2048");
return user.getAvatarURL(noServerPfp ? void 0 : ctx.guild?.id, 2048).replace(/\?size=\d+$/, "?size=2048");
} catch (err) {
console.error("[petpet] Failed to fetch user\n", err);
throw "Failed to fetch user. Check the console for more info.";
Expand Down Expand Up @@ -102,14 +102,20 @@ export default definePlugin({
name: "user",
description: "User whose avatar to use as image",
type: ApplicationCommandOptionType.USER
},
{
name: "no-server-pfp",
description: "Use the normal avatar instead of the server specific one when using the 'user' option",
type: ApplicationCommandOptionType.BOOLEAN
}
],
execute: suppressErrors("petpetExecute", async (opts, cmdCtx) => {
const { GIFEncoder, quantize, applyPalette } = await getGifEncoder();
const frames = await getFrames();

const noServerPfp = findOption(opts, "no-server-pfp", false);
try {
var url = await resolveImage(opts, cmdCtx);
var url = await resolveImage(opts, cmdCtx, noServerPfp);
if (!url) throw "No Image specified!";
} catch (err) {
// Todo make this send a clyde message once that PR is done
Expand Down

0 comments on commit 8dff79d

Please sign in to comment.