feat(plugin) FakeNitro: Allow customising hyperlink text (#2192)

Co-authored-by: Vendicated <vendicated@riseup.net>
This commit is contained in:
Lualt 2024-02-27 13:27:37 +01:00 committed by GitHub
parent ed5e1be7a4
commit 76de8c424e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -161,6 +161,11 @@ const settings = definePluginSettings({
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,
default: true default: true
}, },
hyperLinkText: {
description: "What text the hyperlink should use. {{NAME}} will be replaced with the emoji name.",
type: OptionType.STRING,
default: "{{NAME}}"
}
}).withPrivateSettings<{ }).withPrivateSettings<{
disableEmbedPermissionCheck: boolean; disableEmbedPermissionCheck: boolean;
}>(); }>();
@ -880,8 +885,10 @@ export default definePlugin({
url.searchParams.set("size", s.emojiSize.toString()); url.searchParams.set("size", s.emojiSize.toString());
url.searchParams.set("name", emoji.name); url.searchParams.set("name", emoji.name);
const linkText = s.hyperLinkText.replaceAll("{{NAME}}", emoji.name);
messageObj.content = messageObj.content.replace(emojiString, (match, offset, origStr) => { messageObj.content = messageObj.content.replace(emojiString, (match, offset, origStr) => {
return `${getWordBoundary(origStr, offset - 1)}${s.useHyperLinks ? `[${emoji.name}](${url})` : url}${getWordBoundary(origStr, offset + match.length)}`; return `${getWordBoundary(origStr, offset - 1)}${s.useHyperLinks ? `[${linkText}](${url})` : url}${getWordBoundary(origStr, offset + match.length)}`;
}); });
} }
} }
@ -917,7 +924,9 @@ export default definePlugin({
url.searchParams.set("size", s.emojiSize.toString()); url.searchParams.set("size", s.emojiSize.toString());
url.searchParams.set("name", emoji.name); url.searchParams.set("name", emoji.name);
return `${getWordBoundary(origStr, offset - 1)}${s.useHyperLinks ? `[${emoji.name}](${url})` : url}${getWordBoundary(origStr, offset + emojiStr.length)}`; const linkText = s.hyperLinkText.replaceAll("{{NAME}}", emoji.name);
return `${getWordBoundary(origStr, offset - 1)}${s.useHyperLinks ? `[${linkText}](${url})` : url}${getWordBoundary(origStr, offset + emojiStr.length)}`;
}); });
if (hasBypass && !s.disableEmbedPermissionCheck && !hasEmbedPerms(channelId)) { if (hasBypass && !s.disableEmbedPermissionCheck && !hasEmbedPerms(channelId)) {