diff --git a/README.md b/README.md index 9f64e444..80411982 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch - Jumpscare by Surgedevs - JumpToStart by Samwich - KeyboardSounds by HypedDomi -- KeywordNotify by camila314 (maintained by thororen) +- KeywordNotify by camila314 and x3rt - LoginWithQR by nexpid - MediaDownloader by Colorman - MediaPlaybackSpeed by D3SOX diff --git a/src/equicordplugins/keywordNotify/index.tsx b/src/equicordplugins/keywordNotify/index.tsx index 4b3fe341..74a19f95 100644 --- a/src/equicordplugins/keywordNotify/index.tsx +++ b/src/equicordplugins/keywordNotify/index.tsx @@ -17,7 +17,7 @@ import { classes } from "@utils/misc"; import { useForceUpdater } from "@utils/react"; import definePlugin, { OptionType } from "@utils/types"; import { findByCodeLazy, findByPropsLazy } from "@webpack"; -import { Button, ChannelStore, Forms, Select, SelectedChannelStore, Switch, TabBar, TextInput, Tooltip, UserStore, useState } from "@webpack/common"; +import { Button, ChannelStore, FluxDispatcher, Forms, Select, SelectedChannelStore, Switch, TabBar, TextInput, Tooltip, UserStore, useState } from "@webpack/common"; import { Message, User } from "discord-types/general/index.js"; import type { PropsWithChildren } from "react"; @@ -28,17 +28,19 @@ type KeywordEntry = { regex: string, listIds: Array, listType: ListType, let keywordEntries: Array = []; let currentUser: User; let keywordLog: Array = []; +let interceptor: (e: any) => void; + const recentMentionsPopoutClass = findByPropsLazy("recentMentionsPopout"); const tabClass = findByPropsLazy("inboxTitle", "tab"); const buttonClass = findByPropsLazy("size36"); +const MenuHeader = findByCodeLazy(".getUnseenInviteCount())"); const Popout = findByCodeLazy(".Messages.UNBLOCK_TO_JUMP_TITLE", "canCloseAllMessages:"); const createMessageRecord = findByCodeLazy(".createFromServer(", ".isBlockedForMessage", "messageReference:"); const KEYWORD_ENTRIES_KEY = "KeywordNotify_keywordEntries"; const KEYWORD_LOG_KEY = "KeywordNotify_log"; const cl = classNameFactory("vc-keywordnotify-"); -const MenuHeader = findByCodeLazy("getUnseenInviteCount())"); async function addKeywordEntry(forceUpdate: () => void) { keywordEntries.push({ regex: "", listIds: [], listType: ListType.BlackList, ignoreCase: false }); @@ -270,11 +272,14 @@ function Icon({ height = 24, width = 24, className, children, viewBox, ...svgPro // Ideally I would just add this to Icons.tsx, but I cannot as this is a user-plugin :/ function DoubleCheckmarkIcon(props: IconProps) { + // noinspection TypeScriptValidateTypes return ( JSON.parse(e)).forEach(e => { this.addToLog(e); }); + + interceptor = (e: any) => { + return this.modify(e); + }; + FluxDispatcher.addInterceptor(interceptor); + }, + stop() { + const index = FluxDispatcher._interceptors.indexOf(interceptor); + if (index > -1) { + FluxDispatcher._interceptors.splice(index, 1); + } }, applyKeywordEntries(m: Message) { @@ -427,8 +436,9 @@ export default definePlugin({ keywordLog.push(thing); keywordLog.sort((a, b) => b.timestamp - a.timestamp); - if (keywordLog.length > settings.store.amountToKeep) + while (keywordLog.length > settings.store.amountToKeep) { keywordLog.pop(); + } this.onUpdate(); }, @@ -451,20 +461,16 @@ export default definePlugin({ {({ onMouseLeave, onMouseEnter }) => ( - + + )} } /> @@ -514,13 +520,12 @@ export default definePlugin({ }, modify(e) { - if (e.type === "MESSAGE_CREATE") { + if (e.type === "MESSAGE_CREATE" || e.type === "MESSAGE_UPDATE") { this.applyKeywordEntries(e.message); } else if (e.type === "LOAD_MESSAGES_SUCCESS") { for (let msg = 0; msg < e.messages.length; ++msg) { this.applyKeywordEntries(e.messages[msg]); } } - return e; } }); diff --git a/src/webpack/common/types/utils.d.ts b/src/webpack/common/types/utils.d.ts index dd76d1ad..92052a8b 100644 --- a/src/webpack/common/types/utils.d.ts +++ b/src/webpack/common/types/utils.d.ts @@ -27,7 +27,9 @@ export { FluxEvents }; export interface FluxDispatcher { _actionHandlers: any; + _interceptors: any; _subscriptions: any; + addInterceptor(interceptor: any): void; dispatch(event: { [key: string]: unknown; type: FluxEvents; }): Promise; isDispatching(): boolean; subscribe(event: FluxEvents, callback: (data: any) => void): void;