feat(MessageLinkEmbeds): add whitelist/blacklist modes (#813)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Ryan Cao 2023-07-26 07:41:41 +08:00 committed by GitHub
parent f2c6fcaa3b
commit c69c6f8cb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -93,6 +93,26 @@ const settings = definePluginSettings({
} }
] ]
}, },
listMode: {
description: "Whether to use ID list as blacklist or whitelist",
type: OptionType.SELECT,
options: [
{
label: "Blacklist",
value: "blacklist",
default: true
},
{
label: "Whitelist",
value: "whitelist"
}
]
},
idList: {
description: "Guild/channel/user IDs to blacklist or whitelist (separate with comma)",
type: OptionType.STRING,
default: ""
},
clearMessageCache: { clearMessageCache: {
type: OptionType.COMPONENT, type: OptionType.COMPONENT,
description: "Clear the linked message cache", description: "Clear the linked message cache",
@ -217,6 +237,13 @@ function MessageEmbedAccessory({ message }: { message: Message; }) {
continue; continue;
} }
const { listMode, idList } = settings.store;
const isListed = [guildID, channelID, message.author.id].some(id => id && idList.includes(id));
if (listMode === "blacklist" && isListed) continue;
if (listMode === "whitelist" && !isListed) continue;
let linkedMessage = messageCache.get(messageID)?.message; let linkedMessage = messageCache.get(messageID)?.message;
if (!linkedMessage) { if (!linkedMessage) {
linkedMessage ??= MessageStore.getMessage(channelID, messageID); linkedMessage ??= MessageStore.getMessage(channelID, messageID);
@ -335,7 +362,7 @@ function AutomodEmbedAccessory(props: MessageEmbedProps): JSX.Element | null {
export default definePlugin({ export default definePlugin({
name: "MessageLinkEmbeds", name: "MessageLinkEmbeds",
description: "Adds a preview to messages that link another message", description: "Adds a preview to messages that link another message",
authors: [Devs.TheSun, Devs.Ven], authors: [Devs.TheSun, Devs.Ven, Devs.RyanCaoDev],
dependencies: ["MessageAccessoriesAPI"], dependencies: ["MessageAccessoriesAPI"],
patches: [ patches: [
{ {
@ -363,7 +390,9 @@ export default definePlugin({
return ( return (
<ErrorBoundary> <ErrorBoundary>
<MessageEmbedAccessory message={props.message} /> <MessageEmbedAccessory
message={props.message}
/>
</ErrorBoundary> </ErrorBoundary>
); );
}, 4 /* just above rich embeds */); }, 4 /* just above rich embeds */);