MCPcopy Create free account
hub / github.com/esmBot/esmBot / cleanMessage

Function cleanMessage

src/utils/misc.ts:200–235  ·  view source on GitHub ↗
(message: Message, content: string)

Source from the content-addressed store, hash-verified

198
199// copied from eris
200export function cleanMessage(message: Message, content: string) {
201 let cleanContent = content?.replace(/<a?(:\w+:)[0-9]+>/g, "$1") || "";
202
203 const author = message.author;
204 let authorName = author.username;
205 if (message.member?.nick) {
206 authorName = message.member.nick;
207 }
208 cleanContent = cleanContent.replace(new RegExp(`<@!?${author.id}>`, "g"), `@${authorName}`);
209
210 if (message.mentions) {
211 for (const mention of message.mentions.members) {
212 if (mention.nick) {
213 cleanContent = cleanContent.replace(new RegExp(`<@!?${mention.id}>`, "g"), `@${mention.nick}`);
214 }
215 cleanContent = cleanContent.replace(new RegExp(`<@!?${mention.id}>`, "g"), `@${mention.username}`);
216 }
217
218 if (message.guildID && message.mentions.roles) {
219 for (const roleID of message.mentions.roles) {
220 const role = message.guild?.roles.get(roleID);
221 const roleName = role ? role.name : "deleted-role";
222 cleanContent = cleanContent.replace(new RegExp(`<@&${roleID}>`, "g"), `@${roleName}`);
223 }
224 }
225
226 for (const id of message.mentions.channels) {
227 const channel = message.client.getChannel<Exclude<AnyChannel, AnyPrivateChannel>>(id);
228 if (channel?.name && channel.mention) {
229 cleanContent = cleanContent.replace(channel.mention, `#${channel.name}`);
230 }
231 }
232 }
233
234 return textEncode(cleanContent);
235}
236
237export function cleanInteraction(interaction: CommandInteraction, content: string) {
238 let cleanContent = content?.replace(/<a?(:\w+:)[0-9]+>/g, "$1") || "";

Callers 1

cleanMethod · 0.85

Calls 1

textEncodeFunction · 0.85

Tested by

no test coverage detected