From c44fc8ca6a6c92003dec1ee854d55d8dcacdc93f Mon Sep 17 00:00:00 2001 From: Hipperooni Date: Wed, 17 Jan 2024 20:48:12 +1100 Subject: [PATCH] Add preview image for flair --- src/discord/commands/guild/d.profile.ts | 38 +++++++++++++++---------- src/discord/commands/guild/d.rpg.ts | 19 +++++++++++++ 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/discord/commands/guild/d.profile.ts b/src/discord/commands/guild/d.profile.ts index 4310fe973..2d38b12ad 100644 --- a/src/discord/commands/guild/d.profile.ts +++ b/src/discord/commands/guild/d.profile.ts @@ -605,26 +605,34 @@ export async function getProfilePreview(target: GuildMember, option: string, ima userFont = fontName; } // Username Text - const filteredDisplayName = await deFuckifyText(target.displayName); - context.font = `50px ${userFont}`; + let filteredDisplayName = await deFuckifyText(target.displayName); + // If the filteredDisplayName is much shorter than what was input, display their username as a fallback + if (filteredDisplayName.length < target.displayName.length / 2) { + filteredDisplayName = target.user.username.charAt(0).toUpperCase() + target.user.username.slice(1); + } + context.fillStyle = textColor; - context.textBaseline = 'middle'; - const fontSize = 50; + context.font = `50px ${userFont}`; + context.textAlign = 'left'; + let usernameHeight = 76; + let fontSize = 50; const maxLength = 508; - context.font = resizeText(canvasObj, filteredDisplayName, fontSize, userFont, maxLength); - context.fillText(`${filteredDisplayName}`, 146, 76); - context.fillStyle = textColor; - if (option === 'profileTitle') { - context.textBaseline = 'bottom'; - context.fillText(`${filteredDisplayName}`, 146, 76); - context.font = '30px futura'; + const userFlair = 'Your Custom Flair Here'; + + if (option === 'userflair') { + usernameHeight = 62; + fontSize = 25; context.textBaseline = 'top'; - context.fillText('Your Custom Title Here', 146, 86); - } else { - context.textBaseline = 'middle'; - context.fillText(`${filteredDisplayName}`, 146, 76); + context.font = resizeText(canvasObj, userFlair, fontSize, userFont, maxLength); + context.fillText(`${userFlair}`, 146, 97); + context.textBaseline = 'bottom'; } + fontSize = 50; + context.textBaseline = 'middle'; + context.font = resizeText(canvasObj, filteredDisplayName, fontSize, userFont, maxLength); + context.fillText(`${filteredDisplayName}`, 146, usernameHeight); + /* User Timezone context.font = '25px futura'; context.textAlign = 'right'; diff --git a/src/discord/commands/guild/d.rpg.ts b/src/discord/commands/guild/d.rpg.ts index 59243ea2d..ddf8f175a 100644 --- a/src/discord/commands/guild/d.rpg.ts +++ b/src/discord/commands/guild/d.rpg.ts @@ -1849,6 +1849,15 @@ export async function rpgMarketChange( imageFiles.push(attachment); embed.setImage(tripSitProfileImageAttachment); } + // if the option is a userflair, run profile preview as the embed image + if (itemData && itemData.effect === 'userflair') { + const target = interaction.member as GuildMember; + const option = 'userflair'; + const previewImage = await getProfilePreview(target, option); + const attachment = new AttachmentBuilder(previewImage, { name: tripSitProfileImage }); + imageFiles.push(attachment); + embed.setImage(tripSitProfileImageAttachment); + } return { embeds: [embed], @@ -2973,6 +2982,16 @@ export async function rpgHome( log.debug(F, `font: ${fontName}`); } + // If the select item has the 'userflair' effect, add the image to the embed + if (interaction.isStringSelectMenu() && backgroundData && backgroundData.effect === 'userflair') { + const target = interaction.member as GuildMember; + const option = 'userflair'; + const previewImage = await getProfilePreview(target, option); + const attachment = new AttachmentBuilder(previewImage, { name: tripSitProfileImage }); + files.push(attachment); + embed.setImage(tripSitProfileImageAttachment); + } + // Build out the home navigation buttons const rowHome = new ActionRowBuilder() .addComponents(