diff options
author | V <vendicated@riseup.net> | 2023-05-02 02:55:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-02 02:55:21 +0200 |
commit | 7bc1362cbd3323c982dcc8bf10d399e581082d18 (patch) | |
tree | 6a964c43ea3a9287acfb6b5a3ced0b0c32e097ff | |
parent | 4dce836ff73f22ef5ead1dd4803d4516f0ebd1e8 (diff) | |
download | Vencord-7bc1362cbd3323c982dcc8bf10d399e581082d18.tar.gz Vencord-7bc1362cbd3323c982dcc8bf10d399e581082d18.tar.bz2 Vencord-7bc1362cbd3323c982dcc8bf10d399e581082d18.zip |
MessageEvents: Support sendMessage with attachments (#1023)
-rw-r--r-- | src/api/MessageEvents.ts | 29 | ||||
-rw-r--r-- | src/plugins/apiMessageEvents.ts | 22 |
2 files changed, 43 insertions, 8 deletions
diff --git a/src/api/MessageEvents.ts b/src/api/MessageEvents.ts index aaf8d40..4bd3bc0 100644 --- a/src/api/MessageEvents.ts +++ b/src/api/MessageEvents.ts @@ -36,10 +36,36 @@ export interface Emoji { export interface MessageObject { content: string, validNonShortcutEmojis: Emoji[]; + invalidEmojis: any[]; + tts: boolean; } +export interface Upload { + classification: string; + currentSize: number; + description: string | null; + filename: string; + id: string; + isImage: boolean; + isVideo: boolean; + item: { + file: File; + platform: number; + }; + loaded: number; + mimeType: string; + preCompressionSize: number; + responseUrl: string; + sensitive: boolean; + showLargeMessageDialog: boolean; + spoiler: boolean; + status: "NOT_STARTED" | "STARTED" | "UPLOADING" | "ERROR" | "COMPLETED" | "CANCELLED"; + uniqueId: string; + uploadedFilename: string; +} export interface MessageExtra { stickerIds?: string[]; + uploads?: Upload[]; } export type SendListener = (channelId: string, messageObj: MessageObject, extra: MessageExtra) => Promisable<void | { cancel: boolean; }>; @@ -48,7 +74,8 @@ export type EditListener = (channelId: string, messageId: string, messageObj: Me const sendListeners = new Set<SendListener>(); const editListeners = new Set<EditListener>(); -export async function _handlePreSend(channelId: string, messageObj: MessageObject, extra: MessageExtra) { +export async function _handlePreSend(channelId: string, messageObj: MessageObject, extra: MessageExtra, uploads: Upload[]) { + extra.uploads = uploads; for (const listener of sendListeners) { try { const result = await listener(channelId, messageObj, extra); diff --git a/src/plugins/apiMessageEvents.ts b/src/plugins/apiMessageEvents.ts index 6843200..1fe3623 100644 --- a/src/plugins/apiMessageEvents.ts +++ b/src/plugins/apiMessageEvents.ts @@ -22,17 +22,25 @@ import definePlugin from "@utils/types"; export default definePlugin({ name: "MessageEventsAPI", description: "Api required by anything using message events.", - authors: [Devs.Arjix, Devs.hunt], + authors: [Devs.Arjix, Devs.hunt, Devs.Ven], patches: [ { find: '"MessageActionCreators"', - replacement: [{ - match: /_sendMessage:(function\([^)]+\)){/, - replace: "_sendMessage:async $1{if(await Vencord.Api.MessageEvents._handlePreSend(...arguments))return;" - }, { - match: /\beditMessage:(function\([^)]+\)){/, + replacement: { + // editMessage: function (...) { + match: /\beditMessage:(function\(.+?\))\{/, + // editMessage: async function (...) { await handlePreEdit(...); ... replace: "editMessage:async $1{await Vencord.Api.MessageEvents._handlePreEdit(...arguments);" - }] + } + }, + { + find: ".handleSendMessage=", + replacement: { + // checkIsMessageValid().then((function (isValidData) { ... getSendMessageOptionsForReply(data); ... sendMessage(channel.id, msg, void 0, mergeMessageSendOptions(...)) + match: /(?<=uploads:(\i),channel:\i\}\)\.then\(\()function\((\i)\)\{(var \i=\i\.valid.+?\.getSendMessageOptionsForReply\(\i\);)(?=.+?\.sendMessage\((\i)\.id,(\i),void 0,(\i\(.+?)\):)/, + // checkIsMessageValid().then((async function (isValidData) { ...; if (await handlePresend(channel.id, msg, extra)) return; ... + replace: "async function($2){$3 if (await Vencord.Api.MessageEvents._handlePreSend($4.id,$5,$6,$1)) return {shouldClear:true,shouldRefocus:true};" + } }, { find: '("interactionUsernameProfile', |