This commit is contained in:
thororen1234 2024-08-30 22:10:03 -04:00
commit 69d28600ac
4 changed files with 43 additions and 4 deletions

View file

@ -77,6 +77,7 @@
"stylelint": "^16.8.1",
"stylelint-config-standard": "^36.0.1",
"ts-patch": "^3.2.1",
"ts-pattern": "^5.3.1",
"tsx": "^4.16.5",
"type-fest": "^4.23.0",
"typed-emitter": "^2.1.0",

View file

@ -134,6 +134,9 @@ importers:
ts-patch:
specifier: ^3.2.1
version: 3.2.1
ts-pattern:
specifier: ^5.3.1
version: 5.3.1
tsx:
specifier: ^4.16.5
version: 4.16.5
@ -2374,6 +2377,9 @@ packages:
resolution: {integrity: sha512-hlR43v+GUIUy8/ZGFP1DquEqPh7PFKQdDMTAmYt671kCCA6AkDQMoeFaFmZ7ObPLYOmpMgyKUqL1C+coFMf30w==}
hasBin: true
ts-pattern@5.3.1:
resolution: {integrity: sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==}
tsconfig-paths@3.15.0:
resolution: {integrity: sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==}
@ -4823,6 +4829,8 @@ snapshots:
semver: 7.6.3
strip-ansi: 6.0.1
ts-pattern@5.3.1: {}
tsconfig-paths@3.15.0:
dependencies:
'@types/json5': 0.0.29

View file

@ -21,6 +21,7 @@ import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { MessageStore } from "@webpack/common";
import { Message } from "discord-types/general";
const RelationshipStore = findByPropsLazy("getRelationships", "isBlocked");
@ -28,7 +29,7 @@ const RelationshipStore = findByPropsLazy("getRelationships", "isBlocked");
export default definePlugin({
name: "NoBlockedMessages",
description: "Hides all blocked messages from chat completely.",
authors: [Devs.rushii, Devs.Samu],
authors: [Devs.rushii, Devs.Samu, Devs.F53],
patches: [
{
find: "Messages.BLOCKED_MESSAGES_HIDE",
@ -48,10 +49,17 @@ export default definePlugin({
replacement: [
{
match: /(?<=MESSAGE_CREATE:function\((\i)\){)/,
replace: (_, props) => `if($self.isBlocked(${props}.message))return;`
replace: (_, props) => `if($self.isBlocked(${props}.message)||$self.isReplyToBlocked(${props}.message))return;`
}
]
}))
})),
{
find: ".messageListItem",
replacement: {
match: /(?<=\i=)(?=\(0,(\i)\.jsx)/,
replace: "!$self.isReplyToBlocked(arguments[0].message)&&"
}
}
],
options: {
ignoreBlockedMessages: {
@ -60,9 +68,26 @@ export default definePlugin({
default: false,
restartNeeded: true,
},
hideRepliesToBlockedMessages: {
description: "Hide replies to messages made by users you've blocked",
type: OptionType.BOOLEAN,
default: false,
restartNeeded: false,
}
},
isBlocked(message: Message) {
isReplyToBlocked(message: Message) {
if (!Settings.plugins.NoBlockedMessages.hideRepliesToBlockedMessages)
return false;
const { messageReference } = message;
if (!messageReference) return false;
const replyMessage = MessageStore.getMessage(messageReference.channel_id, messageReference.message_id);
return this.isBlocked(replyMessage);
},
isBlocked(message: Message | undefined) {
if (!message) return false;
try {
return RelationshipStore.isBlocked(message.author.id);
} catch (e) {

View file

@ -52,6 +52,11 @@ export const useDrag = findByCodeLazy("useDrag::spec.begin was deprecated");
// you cant make a better finder i love that they remove display names sm
export const useDrop = findByCodeLazy(".options);return", ".collect,");
export const { match, P }: Pick<typeof import("ts-pattern"), "match" | "P"> = mapMangledModuleLazy("@ts-pattern/matcher", {
match: filters.byCode("return new"),
P: filters.byProps("when")
});
export const lodash: typeof import("lodash") = findByPropsLazy("debounce", "cloneDeep");
export const i18n: t.i18n = findLazy(m => m.Messages?.["en-US"]);