mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 23:38:32 +00:00
Added whitelist
Added whitelist for "never ping" mode that input verifies comma-separated IDs. Parsed IDs are also cached until the next update.
This commit is contained in:
commit
ef4ab9588c
2 changed files with 46 additions and 6 deletions
|
@ -6,5 +6,7 @@ Overrides notification settings for received reply pings to either always notify
|
||||||
- **Enabled**: You will always be notified when someone replies to your messages, regardless of if the sender has reply pings enabled.
|
- **Enabled**: You will always be notified when someone replies to your messages, regardless of if the sender has reply pings enabled.
|
||||||
- **Disabled (Default)**: You will not receive notification pings for replies, regardless of if the sender has reply pings enabled.
|
- **Disabled (Default)**: You will not receive notification pings for replies, regardless of if the sender has reply pings enabled.
|
||||||
|
|
||||||
|
- **Whitelist**: You will be mentioned if any of the userIDs added to this reply to you, regardless of their ping setting or your ping setting. Formatted as comma seperated IDs, e.g. `145224646868860928,1017176847865352332`.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
This project is licensed under the GPL-3.0-or-later License - see file for details.
|
This project is licensed under the GPL-3.0-or-later License - see file for details.
|
||||||
|
|
|
@ -7,20 +7,42 @@
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { MessageStore, UserStore } from "@webpack/common";
|
import { MessageStore, showToast, UserStore } from "@webpack/common";
|
||||||
import { MessageJSON } from "discord-types/general";
|
import { MessageJSON } from "discord-types/general";
|
||||||
|
|
||||||
|
let cachedWhitelist: string[] = [];
|
||||||
|
|
||||||
export const settings = definePluginSettings({
|
export const settings = definePluginSettings({
|
||||||
alwaysPingOnReply: {
|
alwaysPingOnReply: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Always get pinged when someone replies to your messages",
|
description: "Always get pinged when someone replies to your messages",
|
||||||
default: false,
|
default: false,
|
||||||
|
},
|
||||||
|
replyPingWhitelist: {
|
||||||
|
type: OptionType.STRING,
|
||||||
|
description: "Comma-separated list of User IDs to always receive reply pings from",
|
||||||
|
default: "",
|
||||||
|
disabled: () => settings.store.alwaysPingOnReply,
|
||||||
|
onChange: newValue => {
|
||||||
|
const originalIDs = newValue.split(",")
|
||||||
|
.map(id => id.trim())
|
||||||
|
.filter(id => id !== "");
|
||||||
|
|
||||||
|
const isInvalid = originalIDs.some(id => !isValidUserId(id));
|
||||||
|
|
||||||
|
if (isInvalid) {
|
||||||
|
showToast("Invalid User ID: One or more User IDs in the whitelist are invalid. Please check your input.");
|
||||||
|
} else {
|
||||||
|
cachedWhitelist = originalIDs;
|
||||||
|
showToast("Whitelist Updated: Reply ping whitelist has been successfully updated.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "ReplyPingControl",
|
name: "ReplyPingControl",
|
||||||
description: "Control whether to always or never get pinged on message replies",
|
description: "Control whether to always or never get pinged on message replies, with a whitelist feature",
|
||||||
authors: [Devs.ant0n, Devs.MrDiamond],
|
authors: [Devs.ant0n, Devs.MrDiamond],
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
|
@ -36,13 +58,19 @@ export default definePlugin({
|
||||||
const user = UserStore.getCurrentUser();
|
const user = UserStore.getCurrentUser();
|
||||||
if (message.author.id === user.id)
|
if (message.author.id === user.id)
|
||||||
return;
|
return;
|
||||||
if (this.getRepliedMessage(message)?.author.id !== user.id)
|
|
||||||
|
const repliedMessage = this.getRepliedMessage(message);
|
||||||
|
if (!repliedMessage || repliedMessage.author.id !== user.id)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!settings.store.alwaysPingOnReply)
|
const isWhitelisted = cachedWhitelist.includes(message.author.id);
|
||||||
|
|
||||||
|
if (isWhitelisted || settings.store.alwaysPingOnReply) {
|
||||||
|
if (!message.mentions.some(mention => mention.id === user.id))
|
||||||
|
message.mentions.push(user as any);
|
||||||
|
} else {
|
||||||
message.mentions = message.mentions.filter(mention => mention.id !== user.id);
|
message.mentions = message.mentions.filter(mention => mention.id !== user.id);
|
||||||
else if (!message.mentions.some(mention => mention.id === user.id))
|
}
|
||||||
message.mentions.push(user as any);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getRepliedMessage(message: MessageJSON) {
|
getRepliedMessage(message: MessageJSON) {
|
||||||
|
@ -50,3 +78,13 @@ export default definePlugin({
|
||||||
return ref && MessageStore.getMessage(ref.channel_id, ref.message_id);
|
return ref && MessageStore.getMessage(ref.channel_id, ref.message_id);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function parseWhitelist(value: string) {
|
||||||
|
return value.split(",")
|
||||||
|
.map(id => id.trim())
|
||||||
|
.filter(id => id !== "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidUserId(id: string) {
|
||||||
|
return /^\d+$/.test(id);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue