| 235 | } |
| 236 | |
| 237 | export function cleanInteraction(interaction: CommandInteraction, content: string) { |
| 238 | let cleanContent = content?.replace(/<a?(:\w+:)[0-9]+>/g, "$1") || ""; |
| 239 | |
| 240 | const author = interaction.user; |
| 241 | let authorName = author.username; |
| 242 | if (interaction.member?.nick) { |
| 243 | authorName = interaction.member.nick; |
| 244 | } |
| 245 | cleanContent = cleanContent.replace(new RegExp(`<@!?${author.id}>`, "g"), `@${authorName}`); |
| 246 | |
| 247 | for (const mention of interaction.data.resolved.members.values()) { |
| 248 | if (mention.nick) { |
| 249 | cleanContent = cleanContent.replace(new RegExp(`<@!?${mention.id}>`, "g"), `@${mention.nick}`); |
| 250 | } |
| 251 | cleanContent = cleanContent.replace(new RegExp(`<@!?${mention.id}>`, "g"), `@${mention.username}`); |
| 252 | } |
| 253 | |
| 254 | if (interaction.guildID && interaction.data.resolved.roles.size > 0) { |
| 255 | for (const role of interaction.data.resolved.roles.values()) { |
| 256 | const roleName = role ? role.name : "deleted-role"; |
| 257 | cleanContent = cleanContent.replace(new RegExp(`<@&${role.id}>`, "g"), `@${roleName}`); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | for (const channel of interaction.data.resolved.channels.values()) { |
| 262 | if (channel.name && channel.mention) { |
| 263 | cleanContent = cleanContent.replace(channel.mention, `#${channel.name}`); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | return textEncode(cleanContent); |
| 268 | } |
| 269 | |
| 270 | export function isEmpty(string: string) { |
| 271 | return string.length === 0 || string.replace(/[\s\u2800\p{C}]/gu, "").length === 0; |