aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/nitroBypass.ts
blob: 25c1aa66e77d933a14fb824a2082fb9eda789ebb (plain)
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
53
54
55
56
57
58
import { addPreSendListener, addPreEditListener } from "../api/MessageEvents";
import { findByProps } from "../utils/webpack";
import definePlugin from "../utils/types"

export default definePlugin({
    name: "Nitro Bypass",
    author: "ArjixWasTaken",
    description: "Allows you to stream in nitro quality and send fake emojis.",
    patches: [
        {
            find: `canUseAnimatedEmojis:function`,
            replacement: [
                "canUseAnimatedEmojis",
                "canUseEmojisEverywhere",
                "canUseHigherFramerate"
            ].map(func => {
                return {
                    match: new RegExp(`${func}:function\\(.+?}`),
                    replace: `${func}:function (e) { return true; }`
                }
            })
        },
    ],
    start() {
        const { getCustomEmojiById } = findByProps("getCustomEmojiById");

        // Remove any nitro requirements for any of the streaming settings.
        findByProps("ApplicationStreamPresets")
          .ApplicationStreamSettingRequirements
          .forEach(x => {
            delete x.userPremiumType;
            delete x.guildPremiumTier
        });

        addPreSendListener((_, messageObj) => {
            const guildId = window.location.href.split("channels/")[1].split("/")[0];
            for (const emoji of messageObj.validNonShortcutEmojis) {
                if (!emoji.require_colons) continue;
                if (emoji.guildId === guildId && !emoji.animated) continue;

                const emojiString = `<${emoji.animated ? 'a' : ''}:${emoji.originalName || emoji.name}:${emoji.id}>`;
                const url = emoji.url.replace(/\?size=[0-9]+/, `?size=48`);
                messageObj.content = messageObj.content.replace(emojiString, ` ${url} `);
            }
        })
        addPreEditListener((_, __, messageObj) => {
            const guildId = window.location.href.split("channels/")[1].split("/")[0];

            for (const [emojiStr, _, emojiId] of messageObj.content.matchAll(/(?<!\\)<a?:(\w+):(\d+)>/ig)) {
                const emoji = getCustomEmojiById(emojiId);
                if (emoji == null || (emoji.guildId === guildId && !emoji.animated)) continue;

                const url = emoji.url.replace(/\?size=[0-9]+/, `?size=48`);
                messageObj.content = messageObj.content.replace(emojiStr, ` ${url} `);
            }
        })
    },
})