This repository has been archived by the owner on Oct 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.js
52 lines (42 loc) · 1.97 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { findByProps } from '@goosemod/webpack';
const { getCustomEmojiById } = findByProps('getCustomEmojiById');
const { getLastSelectedGuildId } = findByProps('getLastSelectedGuildId');
function handleEscapedEmojis(content) {
return content.replaceAll(/\\(<a?:(\w+):(\d+)>)/ig, '$1');
}
function extractNonUsableEmojis(messageString, size, extension) {
let emojiStrings = messageString.matchAll(/(?<!\\)<a?:(\w+):(\d+)>/ig);
let emojiUrls = [];
for (let emojiString of emojiStrings) {
//fetch required info about the emoji
let emoji = getCustomEmojiById(emojiString[2]);
//check emoji usability
if (emoji["guildId"] != getLastSelectedGuildId() || emoji["animated"] || isInDms()) {
messageString = messageString.replace(emojiString[0], '');
const initialUrl = emoji["url"].split("?")[0];
emojiUrls.push((initialUrl.endsWith(".gif") ? initialUrl : initialUrl.replace(/\.(\w*)$/,"."+extension||"webp")) + `?size=${size}&quality=lossless`);
}
}
return { content: messageString.trim(), emojis: emojiUrls };
}
//returns true if the home button is selected
function isInDms() {
return Array.from(document
.querySelector('[data-list-item-id="guildsnav___home"]')
.classList)
.some(v => v.indexOf("selected-") == 0)
}
function getEmojiLinks(size, args, extension) {
//find all emojis from the captured message string and return object with emojiURLS and content
let processedData = extractNonUsableEmojis(args[1].content, size, extension);
processedData.content = handleEscapedEmojis(processedData.content);
args[1].content = processedData.content;
if (processedData.emojis.length > 0) {
args[1].content += "\n" + processedData.emojis.join("\n");
}
//set invalidEmojis to empty to prevent discord yelling to you about you not having nitro
args[1].invalidEmojis = [];
//send modified message
return args;
}
export default getEmojiLinks;