aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/apiMessageEvents.ts
blob: 154e60150a37870d80f387be90939f6cf3dca3b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Devs } from "../utils/constants";
import definePlugin from "../utils/types";

export default definePlugin({
    name: "MessageEventsAPI",
    description: "Api required by anything using message events.",
    authors: [Devs.Arjix],
    patches: [
        {
            find: "sendMessage:function",
            replacement: [{
                match: /(?<=_sendMessage:function\([^)]+\)){/,
                replace: "{Vencord.Api.MessageEvents._handlePreSend(...arguments);"
            }, {
                match: /(?<=\beditMessage:function\([^)]+\)){/,
                replace: "{Vencord.Api.MessageEvents._handlePreEdit(...arguments);"
            }]
        },
        {
            find: "if(e.altKey){",
            replacement: {
                match: /var \w=(\w)\.id,\w=(\w)\.id;return .{1,2}\.useCallback\(\(?function\((.{1,2})\){/,
                replace: (m, message, channel, event) =>
                    // the message param is shadowed by the event param, so need to alias them
                    `var _msg=${message},_chan=${channel};${m}Vencord.Api.MessageEvents._handleClick(_msg, _chan, ${event});`
            }
        }
    ]
});