https://github.com/zignis/emoji-parser-legacy
Webhook parser for Discord custom emojis
https://github.com/zignis/emoji-parser-legacy
discord
Last synced: about 2 months ago
JSON representation
Webhook parser for Discord custom emojis
- Host: GitHub
- URL: https://github.com/zignis/emoji-parser-legacy
- Owner: zignis
- Created: 2021-08-30T09:19:02.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-01-06T03:33:49.000Z (over 4 years ago)
- Last Synced: 2025-03-03T05:11:58.362Z (over 1 year ago)
- Topics: discord
- Language: JavaScript
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# emojiParser-legacy
This parser was used in the legacy `v3` series of Comio, until it was finally deprecated in the `v4` series due to Discord's terms of use violation.
## Terminology
```js
let substringArray = get_substrings_between(message.content, ":", ":");
let msg = message.content;
if (!substringArray.length) return;
substringArray.forEach(m => {
let emoji = client.emojis.cache.find(x => x.name === m);
var replace = `:${m}:`;
var regReplace = new RegExp(replace, 'g');
const replaceInteger = msg.replace(/[0-9]/g, '');
const emojiInteger = replace.replace(/[0-9]/g, '');
if (replaceInteger.includes(`<${emojiInteger}>`) || replaceInteger.includes(``)) return;
if(emoji && !msg.split(" ").find(x => x === emoji.toString()) && !msg.includes(`<${replace}${emoji.id}>`) && !msg.includes(``)) {
msg = msg.replace(regReplace, emoji.toString());
};
});
```
Message content is breaked into chunks having custom emojis or unicode emojis (:), and each chunk is checked if it's a valid custom emoji and the client can access it. A new Regex is built which replaces all the chunks matching the custom emoji.
```js
let webhook = await message.channel.fetchWebhooks();
webhook = webhook.find(x => x.name === "Webhook Emojis");
if (!webhook) {
webhook = await message.channel.createWebhook(`Webhook Emojis`, {
avatar: client.user.displayAvatarURL({ dynamic: true })
});
};
await webhook.edit({
name: message.member.nickname ? message.member.nickname : message.author.username,
avatar: message.author.displayAvatarURL({ dynamic: true })
});
message.delete()
.catch(console.error);
webhook.send({ content: msg })
.catch(console.error);
await webhook.edit({
name: `Webhook Emojis`,
avatar: client.user.displayAvatarURL({ dynamic: true })
});
```
A webhook named as `Webhook Emojis` is resolved, then its name and avatar is replaced by the message author's name and avatar to replicate the author. Finally the original message is deleted and a new webhook message is sent in the message's channel having the custom emojis.