diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/nitroBypass.ts | 82 |
1 files changed, 35 insertions, 47 deletions
diff --git a/src/plugins/nitroBypass.ts b/src/plugins/nitroBypass.ts index dfdfe9d..e455ab6 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]; - - if (stickerId) { - let stickerLink = this.getStickerLink(stickerId); - let sticker: Sticker | undefined; - - const discordStickerPack = StickerStore.getPremiumPacks().find(pack => { - const discordSticker = pack.stickers.find(sticker => sticker.id === stickerId); - if (discordSticker) { - sticker = discordSticker; - } - return discordSticker; - }); - - 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); + stickerBypass: { + if (!settings.enableStickerBypass) + break stickerBypass; + + const sticker = StickerStore.getStickerById(extra?.stickerIds?.[0]!); + if (!sticker) + break stickerBypass; + + if (sticker.available !== false && (this.canUseStickers || (sticker as GuildSticker)?.guild_id === guildId)) + break stickerBypass; + + 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; } } |