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

@ -28,17 +28,22 @@ import { ChannelStore, UserStore } from "../webpack/common";
const DRAFT_TYPE = 0; const DRAFT_TYPE = 0;
const promptToUpload = lazyWebpack(filters.byCode("UPLOAD_FILE_LIMIT_ERROR")); const promptToUpload = lazyWebpack(filters.byCode("UPLOAD_FILE_LIMIT_ERROR"));
interface Sticker { interface BaseSticker {
available: boolean; available: boolean;
description: string; description: string;
format_type: number; format_type: number;
guild_id: string;
id: string; id: string;
name: string; name: string;
tags: string; tags: string;
type: number; type: number;
_notAvailable?: boolean;
} }
interface GuildSticker extends BaseSticker {
guild_id: string;
}
interface DiscordSticker extends BaseSticker {
pack_id: string;
}
type Sticker = GuildSticker | DiscordSticker;
interface StickerPack { interface StickerPack {
id: string; id: string;
@ -144,7 +149,7 @@ export default definePlugin({
return (UserStore.getCurrentUser().premiumType ?? 0) > 0; return (UserStore.getCurrentUser().premiumType ?? 0) > 0;
}, },
get canUseSticker() { get canUseStickers() {
return (UserStore.getCurrentUser().premiumType ?? 0) > 1; return (UserStore.getCurrentUser().premiumType ?? 0) > 1;
}, },
@ -224,51 +229,34 @@ export default definePlugin({
this.preSend = addPreSendListener((channelId, messageObj, extra) => { this.preSend = addPreSendListener((channelId, messageObj, extra) => {
const { guildId } = this; const { guildId } = this;
if (settings.enableStickerBypass) { stickerBypass: {
const stickerId = extra?.stickerIds?.[0]; if (!settings.enableStickerBypass)
break stickerBypass;
if (stickerId) { const sticker = StickerStore.getStickerById(extra?.stickerIds?.[0]!);
let stickerLink = this.getStickerLink(stickerId); if (!sticker)
let sticker: Sticker | undefined; break stickerBypass;
const discordStickerPack = StickerStore.getPremiumPacks().find(pack => { if (sticker.available !== false && (this.canUseStickers || (sticker as GuildSticker)?.guild_id === guildId))
const discordSticker = pack.stickers.find(sticker => sticker.id === stickerId); break stickerBypass;
if (discordSticker) {
sticker = discordSticker;
}
return discordSticker;
});
if (discordStickerPack) { let link = this.getStickerLink(sticker.id);
// discord stickers provided by the Distok project if (sticker.format_type === 2) {
stickerLink = `https://distok.top/stickers/${discordStickerPack.id}/${stickerId}.gif`; this.sendAnimatedSticker(this.getStickerLink(sticker.id), sticker.id, channelId);
} else {
// guild stickers
sticker = StickerStore.getStickerById(stickerId);
}
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 }; 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;
if (messageObj.content) link = `https://distok.top/stickers/${packId}/${sticker.id}.gif`;
messageObj.content += " "; }
messageObj.content += stickerLink;
delete extra.stickerIds; delete extra.stickerIds;
} messageObj.content += " " + link;
}
} }
} }