aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/noCanaryMessageLinks.ts
blob: c566c5ea54b530f186b4608cb65db61fd70e5593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import definePlugin from "../utils/types";
import { addPreSendListener, MessageObject, removePreSendListener } from "../api/MessageEvents";

export default definePlugin({
    name: "NoCanaryMessageLinks",
    description: "Removes the canary and ptb prefix from message links",
    authors: [{ name: "ICodeInAssembly", id: 702973430449832038n }],
    dependencies: ["MessageEventsAPI"],

    removeBetas(msg: MessageObject) {
        msg.content = msg.content.replace(/(?<=https:\/\/)(canary.|ptb.)(?=discord(?:app)?.com\/channels\/(?:\d{17,20}|@me)\/\d{17,20}\/\d{17,20})/g, ""); // Ven W
    },

    start() {
        this.preSend = addPreSendListener((_, msg) => this.removeBetas(msg));
    },

    stop() {
        removePreSendListener(this.preSend);
    }
});