mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +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,32 +365,40 @@ 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(
|
||||||
switch (type) {
|
/* eslint-disable max-len */
|
||||||
case '@':
|
/<(?:(?<type>@[!&]?|#)|(?:\/(?<commandName>[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai} ]+):)|(?:a?:(?<emojiName>[\w]+):))(?<id>\d{17,19})>/gu,
|
||||||
case '@!': {
|
(match, type, commandName, emojiName, id) => {
|
||||||
const member = channel.guild?.members.cache.get(id);
|
if (commandName) return `/${commandName}`;
|
||||||
if (member) {
|
|
||||||
return `@${member.displayName}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = channel.client.users.cache.get(id);
|
if (emojiName) return `:${emojiName}:`;
|
||||||
return user ? `@${user.username}` : match;
|
|
||||||
|
switch (type) {
|
||||||
|
case '@':
|
||||||
|
case '@!': {
|
||||||
|
const member = channel.guild?.members.cache.get(id);
|
||||||
|
if (member) {
|
||||||
|
return `@${member.displayName}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = channel.client.users.cache.get(id);
|
||||||
|
return user ? `@${user.displayName}` : match;
|
||||||
|
}
|
||||||
|
case '@&': {
|
||||||
|
if (channel.type === ChannelType.DM) return match;
|
||||||
|
const role = channel.guild.roles.cache.get(id);
|
||||||
|
return role ? `@${role.name}` : match;
|
||||||
|
}
|
||||||
|
case '#': {
|
||||||
|
const mentionedChannel = channel.client.channels.cache.get(id);
|
||||||
|
return mentionedChannel ? `#${mentionedChannel.name}` : match;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return match;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case '@&': {
|
},
|
||||||
if (channel.type === ChannelType.DM) return match;
|
);
|
||||||
const role = channel.guild.roles.cache.get(id);
|
|
||||||
return role ? `@${role.name}` : match;
|
|
||||||
}
|
|
||||||
case '#': {
|
|
||||||
const mentionedChannel = channel.client.channels.cache.get(id);
|
|
||||||
return mentionedChannel ? `#${mentionedChannel.name}` : match;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user