Equicord/src/equicordplugins/replyPingControl/index.ts

65 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-04-17 14:29:47 -04:00
/*
* Vencord, a Discord client mod
2024-06-01 14:32:22 -04:00
* Copyright (c) 2023 Vendicated, MrDiamond, ant0n, and contributors
2024-04-17 14:29:47 -04:00
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
2024-04-18 19:15:01 -04:00
import { Devs, EquicordDevs } from "@utils/constants";
2024-04-17 14:29:47 -04:00
import definePlugin, { OptionType } from "@utils/types";
2024-06-01 14:32:22 -04:00
import { MessageStore, UserStore } from "@webpack/common";
2024-04-17 14:29:47 -04:00
import { MessageJSON } from "discord-types/general";
export const settings = definePluginSettings({
alwaysPingOnReply: {
type: OptionType.BOOLEAN,
description: "Always get pinged when someone replies to your messages",
default: false,
},
replyPingWhitelist: {
type: OptionType.STRING,
description: "Comma-separated list of User IDs to always receive reply pings from",
default: "",
disabled: () => settings.store.alwaysPingOnReply,
}
});
export default definePlugin({
name: "ReplyPingControl",
description: "Control whether to always or never get pinged on message replies, with a whitelist feature",
2024-04-18 19:15:01 -04:00
authors: [Devs.ant0n, EquicordDevs.MrDiamond],
2024-04-17 14:29:47 -04:00
settings,
patches: [{
find: "_channelMessages",
replacement: {
match: /receiveMessage\((\i)\)\{/,
replace: "$&$self.modifyMentions($1);"
}
}],
modifyMentions(message: MessageJSON) {
const user = UserStore.getCurrentUser();
2024-06-01 14:32:22 -04:00
if (message.author.id === user.id) return;
2024-04-17 14:29:47 -04:00
const repliedMessage = this.getRepliedMessage(message);
2024-06-01 14:32:22 -04:00
if (!repliedMessage || repliedMessage.author.id !== user.id) return;
2024-04-17 14:29:47 -04:00
2024-06-01 14:32:22 -04:00
const whitelist = settings.store.replyPingWhitelist.split(",").map(id => id.trim());
const isWhitelisted = settings.store.replyPingWhitelist.includes(message.author.id);
2024-04-17 14:29:47 -04:00
if (isWhitelisted || settings.store.alwaysPingOnReply) {
2024-06-01 14:32:22 -04:00
if (!message.mentions.some(mention => mention.id === user.id)) {
2024-04-17 14:29:47 -04:00
message.mentions.push(user as any);
2024-06-01 14:32:22 -04:00
}
2024-04-17 14:29:47 -04:00
} else {
message.mentions = message.mentions.filter(mention => mention.id !== user.id);
}
},
getRepliedMessage(message: MessageJSON) {
const ref = message.message_reference;
return ref && MessageStore.getMessage(ref.channel_id, ref.message_id);
},
});