Fix MessageEvents Presend

This commit is contained in:
thororen1234 2026-07-02 13:47:30 -04:00
parent bf376f9bbd
commit e272a50e3b
No known key found for this signature in database
3 changed files with 24 additions and 13 deletions

View file

@ -17,7 +17,7 @@
*/
import { Logger } from "@utils/Logger";
import type { Channel, CustomEmoji, Message } from "@vencord/discord-types";
import type { Channel, CloudUpload, CustomEmoji, Message } from "@vencord/discord-types";
import { MessageStore } from "@webpack/common";
import type { Promisable } from "type-fest";
@ -30,7 +30,21 @@ export interface MessageObject {
tts: boolean;
}
export interface SendMessageOptions {
export interface MessageContentOptions {
content: string;
channelId: string;
command: unknown | null;
isGif?: boolean;
stickers?: string[];
uploads?: CloudUpload[];
alsoForwardToChannelId?: string;
// If you end up using these, update their type
scheduledTimestamp?: unknown;
mediaMention?: unknown;
}
export interface SendMessageOptions extends MessageContentOptions {
messageReference?: Message["messageReference"];
allowedMentions?: {
parse: string[];
@ -38,11 +52,6 @@ export interface SendMessageOptions {
};
location: string;
stickerIds?: string[];
alsoForwardToChannelId?: string;
// If you end up using these, update their type
scheduledTimestamp?: unknown;
mediaMention?: unknown;
}
export interface SendMessageProps {
@ -60,7 +69,9 @@ export type MessageEditListener = (channelId: string, messageId: string, message
const sendListeners = new Set<MessageSendListener>();
const editListeners = new Set<MessageEditListener>();
export async function _handlePreSend(channelId: string, messageObj: MessageObject, options: SendMessageOptions, props: SendMessageProps) {
export async function _handlePreSend(channelId: string, messageObj: MessageObject, options: SendMessageOptions, props: SendMessageProps, contentOptions: MessageContentOptions) {
options = { ...contentOptions, ...options };
for (const listener of sendListeners) {
try {
const result = await listener(channelId, messageObj, options, props);

View file

@ -6,7 +6,7 @@
import "./styles.css";
import { MessageOptions } from "@api/MessageEvents";
import { MessageObject, SendMessageOptions } from "@api/MessageEvents";
import { definePluginSettings } from "@api/Settings";
import { Devs, EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
@ -119,7 +119,7 @@ export default definePlugin({
return <MessageAccessory message={props.message} />;
},
async onBeforeMessageSend(channelId: string, messageObj: { content: string; }, options: MessageOptions) {
async onBeforeMessageSend(channelId: string, messageObj: MessageObject, options: SendMessageOptions) {
if (!isScheduleModeEnabled) return;
if (!messageObj.content.trim() && !options.uploads?.length) return;

View file

@ -38,9 +38,9 @@ export default definePlugin({
find: ".handleSendMessage,onResize:",
replacement: {
// https://regex101.com/r/7iswuk/1
match: /let (\i)=\i\.\i\.parse\((\i),.+?\.getSendMessageOptions\(\{.+?\}\)?;(?=.+?(\i)\.flags=)(?<=\)\(({.+?})\)\.then.+?)/,
replace: (m, parsedMessage, channel, options, props) => m +
`if(await Vencord.Api.MessageEvents._handlePreSend(${channel}.id,${parsedMessage},${options},${props}))` +
match: /let (\i)=\i\.\i\.parse\((\i),.+?\.getSendMessageOptions\((\{.+?\})\),.{0,100}?\};(?=.+?(\i)\.flags=)(?<=\)\(({.+?})\)\.then.+?)/,
replace: (m, parsedMessage, channel, contentOptions, options, props) => m +
`if(await Vencord.Api.MessageEvents._handlePreSend(${channel}.id,${parsedMessage},${options},${props},${contentOptions}))` +
"return{shouldClear:false,shouldRefocus:true};"
}
},