SplitMessages: spread args when calling orig(), instead() takes rest params not an array
This commit is contained in:
parent
0283f2e224
commit
46d9ce7926
1 changed files with 7 additions and 7 deletions
|
|
@ -56,13 +56,13 @@ export default {
|
||||||
return clone;
|
return clone;
|
||||||
};
|
};
|
||||||
|
|
||||||
unpatchSend = instead("sendMessage", MessageActions, (args: any[], orig: (a: any[]) => any) => {
|
unpatchSend = instead("sendMessage", MessageActions, (args: any[], orig: (...a: any[]) => any) => {
|
||||||
const [channelId, message, , options] = args;
|
const [channelId, message, , options] = args;
|
||||||
const content: string = message?.content ?? "";
|
const content: string = message?.content ?? "";
|
||||||
const limit = maxLength();
|
const limit = maxLength();
|
||||||
const hasAttachments = !!options?.attachmentsToUpload?.length;
|
const hasAttachments = !!options?.attachmentsToUpload?.length;
|
||||||
|
|
||||||
if (content.length <= limit && !hasAttachments) return orig(args);
|
if (content.length <= limit && !hasAttachments) return orig(...args);
|
||||||
|
|
||||||
const chunks = content ? intoChunks(content, limit, storage.splitOnWords) : [];
|
const chunks = content ? intoChunks(content, limit, storage.splitOnWords) : [];
|
||||||
if (chunks === false || chunks.length > MAX_CHUNKS) {
|
if (chunks === false || chunks.length > MAX_CHUNKS) {
|
||||||
|
|
@ -74,22 +74,22 @@ export default {
|
||||||
if (hasAttachments) {
|
if (hasAttachments) {
|
||||||
await sendChunks(channelId, chunks, message);
|
await sendChunks(channelId, chunks, message);
|
||||||
if (chunks.length) await sleep(delayFor(channelId));
|
if (chunks.length) await sleep(delayFor(channelId));
|
||||||
await orig(withArg(args, 1, { ...message, content: "" }));
|
await orig(...withArg(args, 1, { ...message, content: "" }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const first = { ...message, content: chunks.shift() };
|
const first = { ...message, content: chunks.shift() };
|
||||||
await orig(withArg(args, 1, first));
|
await orig(...withArg(args, 1, first));
|
||||||
await sendChunks(channelId, chunks, message);
|
await sendChunks(channelId, chunks, message);
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
unpatchEdit = instead("editMessage", MessageActions, (args: any[], orig: (a: any[]) => any) => {
|
unpatchEdit = instead("editMessage", MessageActions, (args: any[], orig: (...a: any[]) => any) => {
|
||||||
const [channelId, , message] = args;
|
const [channelId, , message] = args;
|
||||||
const content: string = message?.content ?? "";
|
const content: string = message?.content ?? "";
|
||||||
const limit = maxLength();
|
const limit = maxLength();
|
||||||
|
|
||||||
if (content.length <= limit) return orig(args);
|
if (content.length <= limit) return orig(...args);
|
||||||
|
|
||||||
const chunks = intoChunks(content, limit, storage.splitOnWords);
|
const chunks = intoChunks(content, limit, storage.splitOnWords);
|
||||||
if (!chunks || chunks.length > MAX_CHUNKS) {
|
if (!chunks || chunks.length > MAX_CHUNKS) {
|
||||||
|
|
@ -98,7 +98,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (async () => {
|
return (async () => {
|
||||||
const result = await orig(withArg(args, 2, { ...message, content: chunks.shift() }));
|
const result = await orig(...withArg(args, 2, { ...message, content: chunks.shift() }));
|
||||||
await sendChunks(channelId, chunks, message);
|
await sendChunks(channelId, chunks, message);
|
||||||
return result;
|
return result;
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue