Skip to content

Commit

Permalink
3rd time lucky
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipperooni committed Nov 26, 2023
1 parent 3c00e96 commit c1ca61f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
12 changes: 1 addition & 11 deletions src/discord/commands/guild/d.profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,22 +443,12 @@ export const dProfile: SlashCommand = {
// WIP: Check to see if a user has bought a title in the shop
// If so, move Username Text up so the title can fit underneath

// Username Text Resize to fit
const applyUsername = (canvas:Canvas.Canvas, text:string) => {
const usernameContext = canvas.getContext('2d');
do {
fontSize -= 1;
usernameContext.font = `${fontSize}px ${userFont}`;
} while (usernameContext.measureText(text).width > 508);
return usernameContext.font;
};

// Username Text
const filteredDisplayName = await deFuckifyText(target.displayName);
context.font = `50px ${userFont}`;
context.fillStyle = textColor;
context.textBaseline = 'middle';
let fontSize = 50;
const fontSize = 50;
const maxLength = 508;
context.font = resizeText(canvasObj, filteredDisplayName, fontSize, userFont, maxLength);
context.fillText(`${filteredDisplayName}`, 146, 76);
Expand Down
29 changes: 12 additions & 17 deletions src/discord/utils/canvasUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,20 @@ const fancyAlphabets = [
];

export function deFuckifyText(text: string): string {
let normalText = '';
const normalAlphabetArray = Array.from(normalAlphabet);
for (const char of Array.from(text)) {
return Array.from(text).map(char => {
if (/^[\x20-\x7E]$/g.test(char)) {
normalText += char;
} else {
let found = false;
for (const fancyAlphabet of fancyAlphabets) {
const index = fancyAlphabet.indexOf(char);
if (index !== -1) {
normalText += normalAlphabetArray[index];
found = true;
break;
}
}
if (!found && normalAlphabet.includes(char)) {
normalText += char;
return char;
}
for (let i = 0; i < fancyAlphabets.length; i += 1) {
const index = fancyAlphabets[i].indexOf(char);
if (index !== -1) {
return normalAlphabetArray[index];
}
}
}
return normalText;
if (normalAlphabet.includes(char)) {
return char;
}
return '';
}).join('');
}

0 comments on commit c1ca61f

Please sign in to comment.