mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
feat(cleanContent): add slash commands and emojis (#9809)
* feat(cleanContent): add missing commands and emojis Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> * fix: check for every possible name * fix: use non capturing group --------- Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -365,7 +365,14 @@ function basename(path, ext) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function cleanContent(str, channel) {
|
function cleanContent(str, channel) {
|
||||||
return str.replaceAll(/<(@[!&]?|#)(\d{17,19})>/g, (match, type, id) => {
|
return str.replaceAll(
|
||||||
|
/* eslint-disable max-len */
|
||||||
|
/<(?:(?<type>@[!&]?|#)|(?:\/(?<commandName>[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai} ]+):)|(?:a?:(?<emojiName>[\w]+):))(?<id>\d{17,19})>/gu,
|
||||||
|
(match, type, commandName, emojiName, id) => {
|
||||||
|
if (commandName) return `/${commandName}`;
|
||||||
|
|
||||||
|
if (emojiName) return `:${emojiName}:`;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case '@':
|
case '@':
|
||||||
case '@!': {
|
case '@!': {
|
||||||
@@ -375,7 +382,7 @@ function cleanContent(str, channel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = channel.client.users.cache.get(id);
|
const user = channel.client.users.cache.get(id);
|
||||||
return user ? `@${user.username}` : match;
|
return user ? `@${user.displayName}` : match;
|
||||||
}
|
}
|
||||||
case '@&': {
|
case '@&': {
|
||||||
if (channel.type === ChannelType.DM) return match;
|
if (channel.type === ChannelType.DM) return match;
|
||||||
@@ -390,7 +397,8 @@ function cleanContent(str, channel) {
|
|||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user