From b158cecd4b4b3e4486fc2092daa9b753b1c136fa Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sun, 31 Mar 2024 01:00:09 +0100 Subject: [PATCH] FakeNitro: Fix sending unavailable emotes of the current server --- src/plugins/fakeNitro/index.tsx | 25 +++++++++++++------------ src/utils/constants.ts | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/plugins/fakeNitro/index.tsx b/src/plugins/fakeNitro/index.tsx index eb99319..d6822d9 100644 --- a/src/plugins/fakeNitro/index.tsx +++ b/src/plugins/fakeNitro/index.tsx @@ -25,6 +25,7 @@ import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy, findStoreLazy, proxyLazyWebpack } from "@webpack"; import { Alerts, ChannelStore, EmojiStore, FluxDispatcher, Forms, lodash, Parser, PermissionsBits, PermissionStore, UploadHandler, UserSettingsActionCreators, UserStore } from "@webpack/common"; +import type { CustomEmoji } from "@webpack/types"; import type { Message } from "discord-types/general"; import { applyPalette, GIFEncoder, quantize } from "gifenc"; import type { ReactElement, ReactNode } from "react"; @@ -784,6 +785,16 @@ export default definePlugin({ UploadHandler.promptToUpload([file], ChannelStore.getChannel(channelId), DRAFT_TYPE); }, + canUseEmote(e: CustomEmoji, channelId: string) { + if (e.require_colons === false) return true; + if (e.available === false) return false; + + if (this.canUseEmotes) + return e.guildId === this.guildId || hasExternalEmojiPerms(channelId); + else + return !e.animated && e.guildId === this.guildId; + }, + start() { const s = settings.store; @@ -882,12 +893,8 @@ export default definePlugin({ } if (s.enableEmojiBypass) { - const canUseEmotes = this.canUseEmotes && hasExternalEmojiPerms(channelId); - for (const emoji of messageObj.validNonShortcutEmojis) { - if (!emoji.require_colons) continue; - if (emoji.available !== false && canUseEmotes) continue; - if (emoji.guildId === guildId && !emoji.animated) continue; + if (this.canUseEmote(emoji, channelId)) continue; hasBypass = true; @@ -917,18 +924,12 @@ export default definePlugin({ this.preEdit = addPreEditListener(async (channelId, __, messageObj) => { if (!s.enableEmojiBypass) return; - const { guildId } = this; - let hasBypass = false; - const canUseEmotes = this.canUseEmotes && hasExternalEmojiPerms(channelId); - messageObj.content = messageObj.content.replace(/(?/ig, (emojiStr, emojiId, offset, origStr) => { const emoji = EmojiStore.getCustomEmojiById(emojiId); if (emoji == null) return emojiStr; - if (!emoji.require_colons) return emojiStr; - if (emoji.available !== false && canUseEmotes) return emojiStr; - if (emoji.guildId === guildId && !emoji.animated) return emojiStr; + if (this.canUseEmote(emoji, channelId)) return emojiStr; hasBypass = true; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index f3626aa..53f9934 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -155,7 +155,7 @@ export const Devs = /* #__PURE__*/ Object.freeze({ }, kemo: { name: "kemo", - id: 299693897859465228n + id: 715746190813298788n }, dzshn: { name: "dzshn",