Fix FakeNitro sticker support
This commit is contained in:
parent
6eb2207040
commit
590522a40d
3 changed files with 22 additions and 17 deletions
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
import { Logger } from "@utils/Logger";
|
||||
import type { Channel, CloudUpload, CustomEmoji, Message } from "@vencord/discord-types";
|
||||
import type { Channel, CustomEmoji, Message } from "@vencord/discord-types";
|
||||
import { MessageStore } from "@webpack/common";
|
||||
import type { Promisable } from "type-fest";
|
||||
|
||||
|
|
@ -30,35 +30,40 @@ export interface MessageObject {
|
|||
tts: boolean;
|
||||
}
|
||||
|
||||
export interface MessageReplyOptions {
|
||||
messageReference: Message["messageReference"];
|
||||
export interface SendMessageOptions {
|
||||
messageReference?: Message["messageReference"];
|
||||
allowedMentions?: {
|
||||
parse: Array<string>;
|
||||
parse: string[];
|
||||
repliedUser: boolean;
|
||||
};
|
||||
location: string;
|
||||
stickerIds?: string[];
|
||||
alsoForwardToChannelId?: string;
|
||||
|
||||
// If you end up using these, update their type
|
||||
scheduledTimestamp?: unknown;
|
||||
mediaMention?: unknown;
|
||||
}
|
||||
|
||||
export interface MessageOptions {
|
||||
stickers?: string[];
|
||||
uploads?: CloudUpload[];
|
||||
replyOptions: MessageReplyOptions;
|
||||
export interface SendMessageProps {
|
||||
hasStickers: boolean;
|
||||
hasAttachments: boolean;
|
||||
content: string;
|
||||
channel: Channel;
|
||||
type?: any;
|
||||
openWarningPopout: (props: any) => any;
|
||||
}
|
||||
|
||||
export type MessageSendListener = (channelId: string, messageObj: MessageObject, options: MessageOptions) => Promisable<void | { cancel: boolean; }>;
|
||||
export type MessageSendListener = (channelId: string, messageObj: MessageObject, options: SendMessageOptions, props: SendMessageProps) => Promisable<void | { cancel: boolean; }>;
|
||||
export type MessageEditListener = (channelId: string, messageId: string, messageObj: MessageObject) => Promisable<void | { cancel: boolean; }>;
|
||||
|
||||
const sendListeners = new Set<MessageSendListener>();
|
||||
const editListeners = new Set<MessageEditListener>();
|
||||
|
||||
export async function _handlePreSend(channelId: string, messageObj: MessageObject, options: MessageOptions, replyOptions: MessageReplyOptions) {
|
||||
options.replyOptions = replyOptions;
|
||||
export async function _handlePreSend(channelId: string, messageObj: MessageObject, options: SendMessageOptions, props: SendMessageProps) {
|
||||
for (const listener of sendListeners) {
|
||||
try {
|
||||
const result = await listener(channelId, messageObj, options);
|
||||
const result = await listener(channelId, messageObj, options, props);
|
||||
if (result?.cancel) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ export default definePlugin({
|
|||
replacement: {
|
||||
// https://regex101.com/r/7iswuk/1
|
||||
match: /let (\i)=\i\.\i\.parse\((\i),.+?\.getSendMessageOptions\(\{.+?\}\)?;(?=.+?(\i)\.flags=)(?<=\)\(({.+?})\)\.then.+?)/,
|
||||
replace: (m, parsedMessage, channel, replyOptions, extra) => m +
|
||||
`if(await Vencord.Api.MessageEvents._handlePreSend(${channel}.id,${parsedMessage},${extra},${replyOptions}))` +
|
||||
replace: (m, parsedMessage, channel, options, props) => m +
|
||||
`if(await Vencord.Api.MessageEvents._handlePreSend(${channel}.id,${parsedMessage},${options},${props}))` +
|
||||
"return{shouldClear:false,shouldRefocus:true};"
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -822,7 +822,7 @@ export default definePlugin({
|
|||
return;
|
||||
}
|
||||
|
||||
this.preSend = addMessagePreSendListener(async (channelId, messageObj, extra) => {
|
||||
this.preSend = addMessagePreSendListener(async (channelId, messageObj, options) => {
|
||||
const { guildId } = this;
|
||||
|
||||
let hasBypass = false;
|
||||
|
|
@ -831,7 +831,7 @@ export default definePlugin({
|
|||
if (!s.enableStickerBypass)
|
||||
break stickerBypass;
|
||||
|
||||
const sticker = StickersStore.getStickerById(extra.stickers?.[0]!);
|
||||
const sticker = StickersStore.getStickerById(options.stickerIds?.[0]!);
|
||||
if (!sticker)
|
||||
break stickerBypass;
|
||||
|
||||
|
|
@ -877,7 +877,7 @@ export default definePlugin({
|
|||
const linkText = s.hyperLinkText.replaceAll("{{NAME}}", sticker.name);
|
||||
|
||||
messageObj.content += `${getWordBoundary(messageObj.content, messageObj.content.length - 1)}${s.useHyperLinks ? `[${linkText}](${url})` : url}`;
|
||||
extra.stickers!.length = 0;
|
||||
options.stickerIds!.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue