NitroSpoof: Fix inbuilt sticker logic; cleanup

This commit is contained in:
Vendicated 2022-11-12 16:25:28 +01:00
parent 8380328465
commit b48c8d8a4a
No known key found for this signature in database
GPG key ID: EC781ADFB93EFFA3

View file

@ -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;
}
}