Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Plugin): Filter bot mentions #2865

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/plugins/filterBotMentions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Filter Bot Mentions
AdiGro marked this conversation as resolved.
Show resolved Hide resolved
Allows you to filter bot mentions in recent mentions panel.

# Usage
You can include/exclude bot mentions via the checkbox in recent mentions panel, or the plugin settings.
64 changes: 64 additions & 0 deletions src/plugins/filterBotMentions/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 { findByProps } from "@webpack";
import { FluxDispatcher } from "@webpack/common";

const settings = definePluginSettings({
toggle: {
type: OptionType.BOOLEAN,
description: "Filter out mentions by bots",
default: false,
},
});


export default definePlugin({
name: "Filter Bot Mentions",
AdiGro marked this conversation as resolved.
Show resolved Hide resolved
description: "Filter mentions by bots",
AdiGro marked this conversation as resolved.
Show resolved Hide resolved
authors: [{ name: "Taran", id: 482951588055351306n }],
AdiGro marked this conversation as resolved.
Show resolved Hide resolved

patches: [
{
find: "type:\"LOAD_RECENT_MENTIONS_SUCCESS\"",
replacement: {
match: /dispatch\(\{type:"LOAD_RECENT_MENTIONS_SUCCESS",messages:(\i)/,
replace: "$&.filter(function (message) {if (!message.author.bot){return true} else {return $self.settings.store.toggle}})"
AdiGro marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
find: "analyticsName:\"Recent Mentions\"",
replacement: {
match: /channel:\i,messages:\i/,
replace: "$&?.filter(function (message) {if (!message.author.bot){return true} else {return $self.settings.store.toggle}})"
}
},
{
find: "mentions-filter",
replacement: {
match: /children:\[\(0,(\i)\.jsx\)\((\i).{0,200}(\i)\.(\i)\.setGuildFilter.{0,100}checked:(\i).{0,200}checked:(\i).{0,300}checked:(.{0,30})\}\)\]/,
AdiGro marked this conversation as resolved.
Show resolved Hide resolved
replace: "$&.concat([(0,$1.jsx)($2.MenuCheckboxItem, {id:\"Bots\", label:\"Include mentions by bots\", action: function() {$self.toggleBotMentions();$self.reloadMentions($5, $6, $7)}, checked: $self.settings.store.toggle})])"
}
}

],
settings,
reloadMentions(everyone, role, all_servers) {
AdiGro marked this conversation as resolved.
Show resolved Hide resolved
FluxDispatcher.dispatch({ type: "CLEAR_MENTIONS" });
all_servers = all_servers ? null : getCurrentGuild()?.id;

findByProps("fetchRecentMentions").fetchRecentMentions(null, null, all_servers, role, everyone);
AdiGro marked this conversation as resolved.
Show resolved Hide resolved

},
toggleBotMentions() {
this.settings.store.toggle = !this.settings.store.toggle;
}

});
4 changes: 4 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "RamziAH",
id: 1279957227612147747n,
},
Taran: {
name: "Taran",
id: 482951588055351306n
},
} satisfies Record<string, Dev>);

// iife so #__PURE__ works correctly
Expand Down