Skip to content

Commit

Permalink
Add preview image for flair
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipperooni committed Jan 17, 2024
1 parent aff5db9 commit c44fc8c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/discord/commands/guild/d.profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
19 changes: 19 additions & 0 deletions src/discord/commands/guild/d.rpg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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<ButtonBuilder>()
.addComponents(
Expand Down

0 comments on commit c44fc8c

Please sign in to comment.