diff --git a/src/equicordplugins/keywordNotify/index.tsx b/src/equicordplugins/keywordNotify/index.tsx index cadce33a1..bd535b0f6 100644 --- a/src/equicordplugins/keywordNotify/index.tsx +++ b/src/equicordplugins/keywordNotify/index.tsx @@ -7,23 +7,37 @@ import "./style.css"; import { DataStore } from "@api/index"; -import { showNotification } from "@api/Notifications"; import { definePluginSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; import { Flex } from "@components/Flex"; import { DeleteIcon } from "@components/Icons"; import { EquicordDevs } from "@utils/constants"; import { Margins } from "@utils/margins"; +import { classes } from "@utils/misc"; import { useForceUpdater } from "@utils/react"; import definePlugin, { OptionType } from "@utils/types"; -import { Button, ChannelStore, Forms, NavigationRouter, Select, Switch, TextInput, useState } from "@webpack/common"; -import { Message } from "discord-types/general/index.js"; +import { findByCodeLazy, findByPropsLazy } from "@webpack"; +import { Button, ChannelStore, 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"; + +type IconProps = JSX.IntrinsicElements["svg"]; type KeywordEntry = { regex: string, listIds: Array, listType: ListType, ignoreCase: boolean; }; let keywordEntries: Array = []; +let currentUser: User; +let keywordLog: Array = []; +const recentMentionsPopoutClass = findByPropsLazy("recentMentionsPopout"); +const tabClass = findByPropsLazy("tab"); +const buttonClass = findByPropsLazy("size36"); + +const MenuHeader = findByCodeLazy(".getMessageReminders()).length"); +const Popout = findByCodeLazy("e.get(e.jumpTargetId"); +const createMessageRecord = findByCodeLazy(".createFromServer(", ".isBlockedForMessage", "messageReference:"); const KEYWORD_ENTRIES_KEY = "KeywordNotify_keywordEntries"; +const KEYWORD_LOG_KEY = "KeywordNotify_log"; const cl = classNameFactory("vc-keywordnotify-"); @@ -52,6 +66,32 @@ enum ListType { Whitelist = "Whitelist" } +interface BaseIconProps extends IconProps { + viewBox: string; +} + +function highlightKeywords(str: string, entries: Array) { + let regexes: Array; + try { + regexes = entries.map(e => new RegExp(e.regex, "g" + (e.ignoreCase ? "i" : ""))); + } catch (err) { + return [str]; + } + + const matches = regexes.map(r => str.match(r)).flat().filter(e => e != null) as Array; + if (matches.length === 0) { + return [str]; + } + + const idx = str.indexOf(matches[0]); + + return [ + {str.substring(0, idx)}, + {matches[0]}, + {str.substring(idx + matches[0].length)} + ]; +} + function Collapsible({ title, children }) { const [isOpen, setIsOpen] = useState(false); @@ -115,7 +155,7 @@ function ListedIds({ listIds, setListIds }) { ); } -function ListTypeSelector({ listType, setListType }) { +function ListTypeSelector({ listType, setListType }: { listType: ListType, setListType: (v: ListType) => void; }) { return (