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

export default definePlugin({
    name: "NoCanaryMessageLinks",
    description: "Removes the canary and ptb prefix from message links",
    authors: [Devs.Samu],
    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);
    }
});