diff --git a/src/equicordplugins/betterBanReasons/index.tsx b/src/equicordplugins/betterBanReasons/index.tsx index dc9ee5bdc..4743ee28b 100644 --- a/src/equicordplugins/betterBanReasons/index.tsx +++ b/src/equicordplugins/betterBanReasons/index.tsx @@ -10,7 +10,6 @@ import { definePluginSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; import { DeleteIcon, PlusIcon } from "@components/Icons"; import { Devs } from "@utils/constants"; -import { getIntlMessage } from "@utils/discord"; import definePlugin, { OptionType } from "@utils/types"; import { Button, Forms, TextInput } from "@webpack/common"; @@ -78,8 +77,8 @@ export default definePlugin({ { find: "#{intl::BAN_REASON_OPTION_SPAM_ACCOUNT}", replacement: [{ - match: /\[(\{name:\i\.\i\.\i\(\i\.\i\.\i\),value:(\i\.\i\.\i\(\i\.\i\.\i\)|"other")\},?)+\]/, - replace: "$self.getReasons()" + match: /(\[\{name:\i\.\i\.\i\(\i\.\i\.\i\),.+?"other"\}\])/, + replace: "$self.getReasons($1)" }, { match: /useState\(null\)(?=.{0,300}targetUserId:)/, @@ -87,16 +86,15 @@ export default definePlugin({ }] } ], - getReasons() { + getReasons(defaults) { const storedReasons = settings.store.reasons.filter((r: string) => r.trim()); const reasons: string[] = storedReasons.length ? storedReasons - : [ - getIntlMessage("BAN_REASON_OPTION_SPAM_ACCOUNT"), - getIntlMessage("BAN_REASON_OPTION_HACKED_ACCOUNT"), - getIntlMessage("BAN_REASON_OPTION_BREAKING_RULES"), - ]; - return reasons.map(s => ({ name: s, value: s })); + : []; + return [ + ...reasons.map(s => ({ name: s, value: s })), + ...defaults + ]; }, getDefaultState: () => settings.store.isTextInputDefault ? 1 : 0, settings, diff --git a/src/equicordplugins/betterQuickReact/index.tsx b/src/equicordplugins/betterQuickReact/index.tsx index 74cef86e4..055ccff65 100644 --- a/src/equicordplugins/betterQuickReact/index.tsx +++ b/src/equicordplugins/betterQuickReact/index.tsx @@ -14,6 +14,7 @@ export const settings = definePluginSettings({ frequentEmojis: { description: "Use frequently used emojis instead of favourite emojis", type: OptionType.BOOLEAN, + restartNeeded: true, default: true }, rows: { @@ -54,8 +55,9 @@ export default definePlugin({ find: "this.favoriteEmojisWithoutFetchingLatest.concat", replacement: { match: /(this\.favoriteEmojisWithoutFetchingLatest)\.concat/, - replace: "($self.settings.store.frequentEmojis?[]:$1).concat" - } + replace: "[].concat" + }, + predicate: () => settings.store.frequentEmojis }, { find: "#{intl::ADD_REACTION_NAMED}", @@ -69,7 +71,7 @@ export default definePlugin({ // Add a custom class to identify the quick reactions have been modified and a CSS variable for the number of columns to display { match: /className:(\i)\.wrapper,/, - replace: "className:\"vc-better-quick-react \"+($self.settings.store.compactMode?\"vc-better-quick-react-compact \":\"\")+$1.wrapper,style:{\"--vc-better-quick-react-columns\":$self.settings.store.columns}," + replace: "className:\"vc-better-quick-react \"+(Vencord.Settings.plugins.BetterQuickReact.compactMode?\"vc-better-quick-react-compact \":\"\")+$1.wrapper,style:{\"--vc-better-quick-react-columns\":$self.settings.store.columns}," }, // Scroll handler + Apply the emoji count limit from earlier with custom logic { diff --git a/src/equicordplugins/blockKeywords/index.ts b/src/equicordplugins/blockKeywords/index.ts index 206807924..9535387a4 100644 --- a/src/equicordplugins/blockKeywords/index.ts +++ b/src/equicordplugins/blockKeywords/index.ts @@ -7,7 +7,7 @@ import { definePluginSettings, Settings } from "@api/Settings"; import { EquicordDevs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { MessageJSON } from "@vencord/discord-types"; +import { Message } from "@vencord/discord-types"; let blockedKeywords: Array; @@ -38,6 +38,35 @@ const settings = definePluginSettings({ }, }); +export function containsBlockedKeywords(message: Message) { + if (blockedKeywords.length === 0) { return false; } + + // can't use forEach because we need to return from inside the loop + // message content loop + for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) { + if (blockedKeywords[wordIndex].test(message.content)) { + return true; + } + } + + // embed content loop (e.g. twitter embeds) + for (let embedIndex = 0; embedIndex < message.embeds.length; embedIndex++) { + const embed = message.embeds[embedIndex]; + for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) { + // doing this because undefined strings get converted to the string "undefined" in regex tests + // @ts-ignore + const descriptionHasKeywords = embed.rawDescription != null && blockedKeywords[wordIndex].test(embed.rawDescription); + // @ts-ignore + const titleHasKeywords = embed.rawTitle != null && blockedKeywords[wordIndex].test(embed.rawTitle); + if (descriptionHasKeywords || titleHasKeywords) { + return true; + } + } + } + + return false; +} + export default definePlugin({ name: "BlockKeywords", description: "Blocks messages containing specific user-defined keywords, as if the user sending them was blocked.", @@ -45,12 +74,14 @@ export default definePlugin({ patches: [ { find: '"_channelMessages",{})', + predicate: () => settings.store.blockedWords.length > 0, replacement: { match: /static commit\((.{1,2})\){/g, replace: "$&$1=$self.blockMessagesWithKeywords($1);" } }, ...[ + '"MessageStore"', '"ReadStateStore"' ].map(find => ({ find, @@ -65,6 +96,7 @@ export default definePlugin({ ], settings, + containsBlockedKeywords, start() { const blockedWordsList: Array = Settings.plugins.BlockKeywords.blockedWords.split(","); @@ -84,35 +116,6 @@ export default definePlugin({ console.log(blockedKeywords); }, - containsBlockedKeywords(message: MessageJSON) { - if (blockedKeywords.length === 0) { return false; } - - // can't use forEach because we need to return from inside the loop - // message content loop - for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) { - if (blockedKeywords[wordIndex].test(message.content)) { - return true; - } - } - - // embed content loop (e.g. twitter embeds) - for (let embedIndex = 0; embedIndex < message.embeds.length; embedIndex++) { - const embed = message.embeds[embedIndex]; - for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) { - // doing this because undefined strings get converted to the string "undefined" in regex tests - // @ts-ignore - const descriptionHasKeywords = embed.rawDescription != null && blockedKeywords[wordIndex].test(embed.rawDescription); - // @ts-ignore - const titleHasKeywords = embed.rawTitle != null && blockedKeywords[wordIndex].test(embed.rawTitle); - if (descriptionHasKeywords || titleHasKeywords) { - return true; - } - } - } - - return false; - }, - blockMessagesWithKeywords(messageList: any) { return messageList.reset(messageList.map( message => message.set("blocked", message.blocked || this.containsBlockedKeywords(message)) diff --git a/src/plugins/noBlockedMessages/index.ts b/src/plugins/noBlockedMessages/index.ts index 3532e7444..731e4d466 100644 --- a/src/plugins/noBlockedMessages/index.ts +++ b/src/plugins/noBlockedMessages/index.ts @@ -16,7 +16,8 @@ * along with this program. If not, see . */ -import { definePluginSettings, migratePluginSetting } from "@api/Settings"; +import { definePluginSettings, migratePluginSetting, Settings } from "@api/Settings"; +import { containsBlockedKeywords } from "@equicordplugins/blockKeywords"; import { Devs, EquicordDevs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; @@ -187,6 +188,16 @@ export default definePlugin({ repliedMessage = messageReference ? MessageStore.getMessage(messageReference.channel_id, messageReference.message_id) : null; } + const { BlockKeywords } = Settings.plugins; + if ( + BlockKeywords && + BlockKeywords.enabled && + BlockKeywords.ignoreBlockedMessages && + containsBlockedKeywords(message) + ) { + return true; + } + return repliedMessage && this.isBlocked(repliedMessage) ? repliedMessage : false; } catch (e) { new Logger("NoBlockedMessages").error("Failed to check if referenced message is blocked or ignored:", e); @@ -196,6 +207,17 @@ export default definePlugin({ isBlocked(message: Message) { try { if (RelationshipStore.isBlocked(message.author.id)) return true; + + const { BlockKeywords } = Settings.plugins; + if ( + BlockKeywords && + BlockKeywords.enabled && + BlockKeywords.ignoreBlockedMessages && + containsBlockedKeywords(message) + ) { + return true; + } + return settings.store.alsoHideIgnoredUsers && RelationshipStore.isIgnored(message.author.id); } catch (e) { new Logger("NoBlockedMessages").error("Failed to check if message is blocked or ignored:", e);