diff --git a/src/plugins/filterBotMentions/README.md b/src/plugins/filterBotMentions/README.md new file mode 100644 index 000000000..7b74176b6 --- /dev/null +++ b/src/plugins/filterBotMentions/README.md @@ -0,0 +1,13 @@ +# FilterBotMentions +Allows you to filter bot mentions in recent mentions panel. + +# Usage +You can include/exclude mentions by bots in the box either using the checkbox in recent mentions panel, or in the plugin settings. + +Include mentions by bots: +![image](https://github.com/user-attachments/assets/a80a41fc-9bae-4612-a23a-b1894e0f8fd2) + +Excluded mentions by bots: +![image](https://github.com/user-attachments/assets/fdf973eb-23ef-4101-b4de-e3fb6663f41b) + + diff --git a/src/plugins/filterBotMentions/index.tsx b/src/plugins/filterBotMentions/index.tsx new file mode 100644 index 000000000..ae1d97286 --- /dev/null +++ b/src/plugins/filterBotMentions/index.tsx @@ -0,0 +1,84 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import { getCurrentGuild } from "@utils/discord"; +import definePlugin, { OptionType } from "@utils/types"; +import { findByPropsLazy, findStoreLazy } from "@webpack"; +import { Menu } from "@webpack/common"; +import { Message } from "discord-types/general"; + + +const settings = definePluginSettings({ + toggle: { + type: OptionType.BOOLEAN, + description: "Include mentions by bots in inbox", + default: true, + }, +}); + +type RecentMentionsStore = { guildFilter: string, roleFilter: boolean, everyoneFilter: boolean; }; +type fetchRecentMentionsType = (before: BigInt | null, limit: Number | null, all_servers: string | null | undefined, role: boolean, everyone: boolean,) => void; + +const { fetchRecentMentions } = findByPropsLazy("fetchRecentMentions") as { fetchRecentMentions: fetchRecentMentionsType; }; +const recentMentionsStore = findStoreLazy("RecentMentionsStore") as RecentMentionsStore; + + +export default definePlugin({ + name: "FilterBotMentions", + description: "Filter mentions by bots in inbox", + authors: [Devs.Taran], + + patches: [ + { + find: "get lastLoaded", + replacement: { + match: /getMentions.{0,30}\?\i/, + replace: "$&.filter($self.filterMessages)" + } + }, + { + find: "mentions-filter", + replacement: { + match: /children:\[\(0,\i\.jsx\).{0,600}\}\)\]/, + replace: "$&.concat($self.patchMenu())" + } + } + + ], + settings, + reloadMentions(): void { + const all_servers: boolean = recentMentionsStore.guildFilter === "ALL_SERVERS"; + const { roleFilter: role, everyoneFilter: everyone } = recentMentionsStore; + const serverToFilter: string | undefined | null = all_servers ? null : getCurrentGuild()?.id; + fetchRecentMentions(null, null, serverToFilter, role, everyone); + }, + + toggleBotMentions(): void { + settings.store.toggle = !settings.store.toggle; + }, + + filterMessages(message: Message): boolean { + return !message.author.bot || settings.store.toggle; + + }, + + patchMenu() { + return ( + { + this.toggleBotMentions(); + this.reloadMentions(); + }} + checked={settings.store.toggle} + /> + ); + } + +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 6653e6307..0583a226e 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -575,6 +575,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "RamziAH", id: 1279957227612147747n, }, + Taran: { + name: "Taran", + id: 482951588055351306n + }, } satisfies Record); // iife so #__PURE__ works correctly