Vencord/src/plugins/nitroBypass.ts

92 lines
3.4 KiB
TypeScript
Raw Normal View History

import { addPreSendListener, addPreEditListener, removePreSendListener, removePreEditListener } from "../api/MessageEvents";
2022-08-31 18:55:58 +00:00
import { findByProps } from "../webpack";
import definePlugin from "../utils/types";
import { Devs } from "../utils/constants";
import { UserStore } from "../webpack/common";
2022-08-31 18:53:36 +00:00
export default definePlugin({
2022-10-01 15:04:57 +00:00
name: "NitroBypass",
2022-10-01 00:27:28 +00:00
authors: [Devs.Arjix],
2022-08-31 18:53:36 +00:00
description: "Allows you to stream in nitro quality and send fake emojis.",
2022-08-31 18:58:21 +00:00
dependencies: ["MessageEventsAPI"],
2022-08-31 18:53:36 +00:00
patches: [
{
find: "canUseAnimatedEmojis:function",
2022-08-31 18:53:36 +00:00
replacement: [
"canUseAnimatedEmojis",
"canUseEmojisEverywhere",
"canUseHighVideoQuality",
"canStreamHighQuality",
"canStreamMidQuality"
2022-08-31 18:53:36 +00:00
].map(func => {
return {
match: new RegExp(`${func}:function\\(.+?}`),
replace: `${func}:function (e) { return true; }`
2022-08-31 18:55:58 +00:00
};
2022-08-31 18:53:36 +00:00
})
},
2022-10-01 15:04:57 +00:00
{
find: "STREAM_FPS_OPTION.format",
replacement: {
match: /(userPremiumType|guildPremiumTier):.{0,10}TIER_\d,?/g,
replace: ""
}
}
2022-08-31 18:53:36 +00:00
],
2022-10-01 15:04:57 +00:00
get guildId() {
return window.location.href.split("channels/")[1].split("/")[0];
},
get canUseEmotes() {
return Boolean(UserStore.getCurrentUser().premiumType);
},
2022-08-31 18:53:36 +00:00
start() {
2022-10-01 15:04:57 +00:00
if (this.canUseEmotes) {
console.info("[NitroBypass] Skipping start because you have nitro");
return;
}
2022-08-31 18:53:36 +00:00
2022-10-01 15:04:57 +00:00
const { getCustomEmojiById } = findByProps("getCustomEmojiById");
2022-08-31 18:53:36 +00:00
function getWordBoundary(origStr, offset) {
return (!origStr[offset] || /\s/.test(origStr[offset])) ? "" : " ";
}
this.preSend = addPreSendListener((_, messageObj) => {
2022-10-01 15:04:57 +00:00
const guildId = this.guildId;
2022-08-31 18:53:36 +00:00
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, (match, offset, origStr) => {
2022-10-05 22:11:32 +00:00
return `${getWordBoundary(origStr, offset - 1)}${url}${getWordBoundary(origStr, offset + match.length)}`;
});
2022-08-31 18:53:36 +00:00
}
2022-08-31 18:55:58 +00:00
});
2022-10-01 15:04:57 +00:00
this.preEdit = addPreEditListener((_, __, messageObj) => {
2022-10-01 15:04:57 +00:00
const guildId = this.guildId;
2022-08-31 18:53:36 +00:00
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;
if (!emoji.require_colons) continue;
2022-08-31 18:53:36 +00:00
const url = emoji.url.replace(/\?size=[0-9]+/, "?size=48");
messageObj.content = messageObj.content.replace(emojiStr, (match, offset, origStr) => {
2022-10-05 22:11:32 +00:00
return `${getWordBoundary(origStr, offset - 1)}${url}${getWordBoundary(origStr, offset + match.length)}`;
});
2022-08-31 18:53:36 +00:00
}
2022-08-31 18:55:58 +00:00
});
2022-08-31 18:53:36 +00:00
},
stop() {
removePreSendListener(this.preSend);
removePreEditListener(this.preEdit);
}
2022-08-31 18:55:58 +00:00
});