2025-09-19 21:56:39 -05:00
|
|
|
import {Guild, Invite, User} from "discord.js";
|
2025-09-17 13:33:10 -05:00
|
|
|
|
2025-09-19 21:56:39 -05:00
|
|
|
//@ts-ignore
|
|
|
|
|
export async function replaceVars(text: string, user: User | undefined, guild: Guild | undefined, stats?: any, invite: Invite | undefined): Promise<string> {
|
2025-09-18 11:43:47 -05:00
|
|
|
if(!text) return '';
|
2025-09-17 13:33:10 -05:00
|
|
|
|
2025-09-19 21:56:39 -05:00
|
|
|
// Crear inviteObject solo si invite existe y tiene guild
|
|
|
|
|
const inviteObject = invite?.guild ? {
|
|
|
|
|
guild: {
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
icon: `https://cdn.discordapp.com/icons/${invite.guild.id}/${invite.guild.icon}.webp?size=256`
|
|
|
|
|
}
|
|
|
|
|
} : null;
|
|
|
|
|
|
2025-09-17 13:33:10 -05:00
|
|
|
return text
|
2025-09-18 11:43:47 -05:00
|
|
|
/**
|
|
|
|
|
* USER INFO
|
|
|
|
|
*/
|
|
|
|
|
.replace(/(user\.name)/g, user?.username ?? '')
|
|
|
|
|
.replace(/(user\.id)/g, user?.id ?? '')
|
|
|
|
|
.replace(/(user\.mention)/g, user ? `<@${user.id}>` : '')
|
|
|
|
|
.replace(/(user\.avatar)/g, user?.displayAvatarURL({ forceStatic: false }) ?? '')
|
|
|
|
|
|
2025-09-19 21:56:39 -05:00
|
|
|
/**
|
|
|
|
|
* USER STATS
|
|
|
|
|
*/
|
|
|
|
|
.replace(/(user\.pointsAll)/g, stats?.totalPoints?.toString() ?? '0')
|
|
|
|
|
.replace(/(user\.pointsWeekly)/g, stats?.weeklyPoints?.toString() ?? '0')
|
|
|
|
|
.replace(/(user\.pointsMonthly)/g, stats?.monthlyPoints?.toString() ?? '0')
|
|
|
|
|
|
2025-09-18 11:43:47 -05:00
|
|
|
/**
|
|
|
|
|
* GUILD INFO
|
|
|
|
|
*/
|
|
|
|
|
.replace(/(guild\.name)/g, guild?.name ?? '')
|
2025-09-19 21:56:39 -05:00
|
|
|
.replace(/(guild\.icon)/g, guild?.iconURL({ forceStatic: false }) ?? '')
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INVITE INFO
|
|
|
|
|
*/
|
|
|
|
|
.replace(/(invite\.name)/g, invite?.guild?.name ?? "")
|
|
|
|
|
.replace(/(invite\.icon)/g, inviteObject?.guild.icon ?? '0')
|
|
|
|
|
|
2025-09-17 13:33:10 -05:00
|
|
|
}
|