From b48c8d8a4a003ffe4bdee4c3ba3ae6f54ce1f317 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 12 Nov 2022 16:25:28 +0100 Subject: [PATCH] NitroSpoof: Fix inbuilt sticker logic; cleanup --- src/plugins/nitroBypass.ts | 76 ++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/src/plugins/nitroBypass.ts b/src/plugins/nitroBypass.ts index dfdfe9d27..e455ab6af 100644 --- a/src/plugins/nitroBypass.ts +++ b/src/plugins/nitroBypass.ts @@ -28,17 +28,22 @@ import { ChannelStore, UserStore } from "../webpack/common"; const DRAFT_TYPE = 0; const promptToUpload = lazyWebpack(filters.byCode("UPLOAD_FILE_LIMIT_ERROR")); -interface Sticker { +interface BaseSticker { available: boolean; description: string; format_type: number; - guild_id: string; id: string; name: string; tags: string; type: number; - _notAvailable?: boolean; } +interface GuildSticker extends BaseSticker { + guild_id: string; +} +interface DiscordSticker extends BaseSticker { + pack_id: string; +} +type Sticker = GuildSticker | DiscordSticker; interface StickerPack { id: string; @@ -144,7 +149,7 @@ export default definePlugin({ return (UserStore.getCurrentUser().premiumType ?? 0) > 0; }, - get canUseSticker() { + get canUseStickers() { return (UserStore.getCurrentUser().premiumType ?? 0) > 1; }, @@ -224,51 +229,34 @@ export default definePlugin({ this.preSend = addPreSendListener((channelId, messageObj, extra) => { const { guildId } = this; - if (settings.enableStickerBypass) { - const stickerId = extra?.stickerIds?.[0]; + stickerBypass: { + if (!settings.enableStickerBypass) + break stickerBypass; - if (stickerId) { - let stickerLink = this.getStickerLink(stickerId); - let sticker: Sticker | undefined; + const sticker = StickerStore.getStickerById(extra?.stickerIds?.[0]!); + if (!sticker) + break stickerBypass; - const discordStickerPack = StickerStore.getPremiumPacks().find(pack => { - const discordSticker = pack.stickers.find(sticker => sticker.id === stickerId); - if (discordSticker) { - sticker = discordSticker; - } - return discordSticker; - }); + if (sticker.available !== false && (this.canUseStickers || (sticker as GuildSticker)?.guild_id === guildId)) + break stickerBypass; - if (discordStickerPack) { - // discord stickers provided by the Distok project - stickerLink = `https://distok.top/stickers/${discordStickerPack.id}/${stickerId}.gif`; - } else { - // guild stickers - sticker = StickerStore.getStickerById(stickerId); + let link = this.getStickerLink(sticker.id); + if (sticker.format_type === 2) { + this.sendAnimatedSticker(this.getStickerLink(sticker.id), sticker.id, channelId); + return { cancel: true }; + } else { + if ("pack_id" in sticker) { + const packId = sticker.pack_id === "847199849233514549" + // Discord moved these stickers into a different pack at some point, but + // Distok still uses the old id + ? "749043879713701898" + : sticker.pack_id; + + link = `https://distok.top/stickers/${packId}/${sticker.id}.gif`; } - if (sticker) { - // when the user has Nitro and the sticker is available, send the sticker normally - if (this.canUseSticker && sticker.available) { - return { cancel: false }; - } - - // only modify if sticker is not from current guild - if (sticker.guild_id !== guildId) { - // if it's an animated guild sticker, download it, convert to gif and send it - const isAnimated = sticker.format_type === 2; - if (!discordStickerPack && isAnimated) { - this.sendAnimatedSticker(stickerLink, stickerId, channelId); - return { cancel: true }; - } - - if (messageObj.content) - messageObj.content += " "; - messageObj.content += stickerLink; - - delete extra.stickerIds; - } - } + delete extra.stickerIds; + messageObj.content += " " + link; } }