KeywordNotify: Update

This commit is contained in:
thororen1234 2026-07-19 09:18:54 -04:00
parent 7c0df3d7ec
commit 6a3a7a5087
No known key found for this signature in database
11 changed files with 534 additions and 298 deletions

View file

@ -1210,3 +1210,17 @@ export function SkullIcon(props: IconProps) {
</Icon>
);
}
export function DoubleCheckmarkIcon(props: IconProps) {
return (
<Icon
{...props}
viewBox="0 0 24 24"
>
<path fill="currentColor"
d="M16.7 8.7a1 1 0 0 0-1.4-1.4l-3.26 3.24a1 1 0 0 0 1.42 1.42L16.7 8.7ZM3.7 11.3a1 1 0 0 0-1.4 1.4l4.5 4.5a1 1 0 0 0 1.4-1.4l-4.5-4.5Z" />
<path fill="currentColor"
d="M21.7 9.7a1 1 0 0 0-1.4-1.4L13 15.58l-3.3-3.3a1 1 0 0 0-1.4 1.42l4 4a1 1 0 0 0 1.4 0l8-8Z" />
</Icon>
);
}

View file

@ -0,0 +1,6 @@
.vc-keywordnotify-collapsible {
display: flex;
align-items: center;
padding: 8px;
cursor: pointer;
}

View file

@ -0,0 +1,35 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2026 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import "./Collapsible.css";
import { TextButton } from "@components/Button";
import { Heading } from "@components/Heading";
import { useState } from "@webpack/common";
import { cl } from "..";
export function Collapsible({ title, children }) {
const [isOpen, setIsOpen] = useState(false);
return (
<div>
<TextButton
onClick={() => setIsOpen(!isOpen)}
className={cl("collapsible")}>
<div style={{ display: "flex", alignItems: "center" }}>
<div style={{
marginLeft: "auto",
color: "var(--text-muted)",
paddingRight: "5px"
}}>{isOpen ? "▼" : "▶"}</div>
<Heading tag="h4">{title}</Heading>
</div>
</TextButton>
{isOpen && children}
</div>
);
}

View file

@ -0,0 +1,32 @@
.vc-keywordnotify-form-generic-label-wrapper {
margin-bottom: 20px;
cursor: pointer;
}
.vc-keywordnotify-form-generic-label {
display: flex;
width: 100%;
> :last-child {
margin-left: auto;
max-width: fit-content;
min-width: fit-content;
}
}
.vc-keywordnotify-form-generic-label-disabled {
opacity: 0.5;
pointer-events: none;
cursor: not-allowed;
}
.vc-keywordnotify-form-generic-label-text {
display: flex;
flex-direction: column;
justify-content: center;
gap: 8px;
}
.vc-keywordnotify-form-generic-label-border {
margin-top: 20px;
}

View file

@ -0,0 +1,44 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2026 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import "./FormGenericLabel.css";
import { Divider } from "@components/Divider";
import { Span } from "@components/Span";
import { classNameFactory } from "@utils/css";
import { classes } from "@utils/misc";
import type { ReactNode } from "react";
import { cl as pluginCl } from "..";
const cl = classNameFactory("vc-keywordnotify-form-generic-label-");
interface FormGenericLabelProps {
title: ReactNode;
description?: ReactNode;
className?: string;
disabled?: boolean;
hideBorder?: boolean;
children: ReactNode;
}
export function FormGenericLabel({ title, description, disabled, className, hideBorder, children }: FormGenericLabelProps) {
return (
<label className={cl("wrapper")}>
<div className={classes(pluginCl("form-generic-label"), className, disabled && cl("disabled"))}>
<div className={cl("text")}>
<Span size="md" weight="medium">{title}</Span>
{description && <Span size="sm" weight="normal">{description}</Span>}
</div>
{children}
</div>
{!hideBorder && <Divider className={cl("border")} />}
</label>
);
}

View file

@ -0,0 +1,160 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2026 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { DataStore } from "@api/index";
import { Button } from "@components/Button";
import { Flex } from "@components/Flex";
import { FormSwitch } from "@components/FormSwitch";
import { Heading } from "@components/Heading";
import { DeleteIcon } from "@components/Icons";
import { Margins } from "@components/margins";
import { Paragraph } from "@components/Paragraph";
import { classes } from "@utils/misc";
import { useForceUpdater } from "@utils/react";
import { TextInput, useState } from "@webpack/common";
import { addKeywordEntry, cl, KEYWORD_ENTRIES_KEY, keywordEntries, ListType, removeKeywordEntry } from "..";
import { Collapsible } from "./Collapsible";
import { FormGenericLabel } from "./FormGenericLabel";
import { ListedIds } from "./ListedIds";
import { ListPrioritySelector } from "./ListPrioritySelector";
export function KeywordEntries() {
const update = useForceUpdater();
const [values] = useState(keywordEntries);
async function updateStoreAndRender() {
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
update();
}
async function setRegex(index: number, value: string) {
keywordEntries[index].regex = value;
updateStoreAndRender();
}
async function setListPriority(index: number, value: ListType) {
keywordEntries[index].listPriority = value;
updateStoreAndRender();
}
async function setWhitelist(index: number, value: string[]) {
keywordEntries[index].whitelist = value;
updateStoreAndRender();
}
async function setBlacklist(index: number, value: string[]) {
keywordEntries[index].blacklist = value;
updateStoreAndRender();
}
async function setIgnoreCase(index: number, value: boolean) {
keywordEntries[index].ignoreCase = value;
updateStoreAndRender();
}
async function setIgnoreBots(index: number, value: boolean) {
keywordEntries[index].ignoreBots = value,
updateStoreAndRender();
}
const elements = keywordEntries.map((entry, i) => {
return (
<>
<Collapsible title={`Keyword Entry ${i + 1}`}>
<Flex flexDirection="row">
<div style={{ flexGrow: 1 }}>
<TextInput
placeholder="example|regex"
spellCheck={false}
value={values[i].regex}
onChange={e => setRegex(i, e)} />
</div>
<Button
onClick={() => removeKeywordEntry(i, update)}
variant="none"
size="iconOnly"
className={cl("delete")}>
<DeleteIcon />
</Button>
</Flex>
<FormSwitch
value={values[i].ignoreCase}
onChange={() => {
setIgnoreCase(i, !values[i].ignoreCase);
}}
title="Ignore Case"
className={cl("ignoreCaseSwitch")} />
<FormSwitch
value={values[i].ignoreBots ?? false}
onChange={() => {
setIgnoreBots(i, !values[i].ignoreBots);
}}
title="Ignore Bots"
description="Ignore messages from bots"
className={cl("ignoreCaseSwitch")} />
<Flex flexDirection="row">
<div style={{ flexGrow: 1 }}>
<Heading tag="h5">Whitelist</Heading>
</div>
<Button onClick={() => {
values[i].whitelist.push("");
update();
}}>Add ID</Button>
</Flex>
{!!values[i].whitelist.length && <>
<div className={classes(Margins.top8, Margins.bottom8)} />
<Flex flexDirection="row">
<div style={{ flexGrow: 1 }}>
<ListedIds listIds={values[i].whitelist} setListIds={e => setWhitelist(i, e)} />
</div>
</Flex>
</>}
<div className={classes(Margins.top8, Margins.bottom8)} />
<Flex flexDirection="row">
<div style={{ flexGrow: 1 }}>
<Heading tag="h5">Blacklist</Heading>
</div>
<Button onClick={() => {
values[i].blacklist.push("");
update();
}}>Add ID</Button>
</Flex>
{!!values[i].blacklist.length && <>
<div className={classes(Margins.top8, Margins.bottom8)} />
<Flex flexDirection="row">
<div style={{ flexGrow: 1 }}>
<ListedIds listIds={values[i].blacklist} setListIds={e => setBlacklist(i, e)} />
</div>
</Flex>
</>}
<div className={classes(Margins.top8, Margins.bottom8)} />
<FormGenericLabel
title="List priority (Advanced)"
description={<>
<Paragraph>
Which list to prioritize in case a message triggers both lists
</Paragraph>
<Paragraph>
If you are not sure, in most common scenarios it is usually set to Blacklist
</Paragraph>
</>}
hideBorder
>
<ListPrioritySelector listType={values[i].listPriority} setListPriority={e => setListPriority(i, e)} />
</FormGenericLabel>
</Collapsible>
</>
);
});
return (
<>
{elements}
<div><Button onClick={() => addKeywordEntry(update)}>Add Keyword Entry</Button></div>
</>
);
}

View file

@ -0,0 +1,25 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2026 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Select } from "@webpack/common";
import { ListType } from "..";
export function ListPrioritySelector({ listType, setListPriority }: { listType: ListType; setListPriority: (v: ListType) => void; }) {
return (
<Select
options={[
{ label: "Whitelist", value: ListType.Whitelist },
{ label: "Blacklist", value: ListType.BlackList }
]}
placeholder={"Select a list type"}
isSelected={v => v === listType}
closeOnSelect={true}
select={setListPriority}
serialize={v => v}
/>
);
}

View file

@ -0,0 +1,51 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2026 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Button } from "@components/Button";
import { Flex } from "@components/Flex";
import { DeleteIcon } from "@components/Icons";
import { useForceUpdater } from "@utils/react";
import { TextInput, useState } from "@webpack/common";
import { cl } from "..";
export function ListedIds({ listIds, setListIds }: { listIds: string[]; setListIds: (v: string[]) => void; }) {
const update = useForceUpdater();
const [values] = useState(listIds);
async function onChange(e: string, index: number) {
values[index] = e.trim();
setListIds(values);
update();
}
const elements = values.map((currentValue: string, index: number) => {
return (
<Flex key={index} flexDirection="row" style={{ marginBottom: "5px" }}>
<div style={{ flexGrow: 1 }}>
<TextInput
placeholder="ID"
spellCheck={false}
value={currentValue}
onChange={e => onChange(e, index)} />
</div>
<Button
onClick={() => {
values.splice(index, 1);
setListIds(values);
update();
}}
variant="none"
size="iconOnly"
className={cl("delete")}>
<DeleteIcon />
</Button>
</Flex>
);
});
return <>{elements}</>;
}

View file

@ -8,45 +8,87 @@ import "./style.css";
import { DataStore } from "@api/index";
import { definePluginSettings } from "@api/Settings";
import { Button, TextButton } from "@components/Button";
import { Flex } from "@components/Flex";
import { FormSwitch } from "@components/FormSwitch";
import { Heading } from "@components/Heading";
import { DeleteIcon } from "@components/Icons";
import { Button } from "@components/Button";
import ErrorBoundary from "@components/ErrorBoundary";
import { DoubleCheckmarkIcon } from "@components/Icons";
import { EquicordDevs } from "@utils/constants";
import { classNameFactory } from "@utils/css";
import { Margins } from "@utils/margins";
import { classes } from "@utils/misc";
import { useForceUpdater } from "@utils/react";
import definePlugin, { OptionType } from "@utils/types";
import { Message } from "@vencord/discord-types";
import { Message, ScrollerBaseRef } from "@vencord/discord-types";
import { findByCodeLazy, findCssClassesLazy } from "@webpack";
import { ChannelStore, FluxDispatcher, Select, SelectedChannelStore, TabBar, TextInput, Tooltip, UserStore, useState } from "@webpack/common";
import type { JSX, PropsWithChildren } from "react";
import {
ChannelStore,
FluxDispatcher,
ScrollerThin,
TabBar,
Tooltip,
useRef,
UserStore,
useState
} from "@webpack/common";
import type { JSX, RefObject } from "react";
type IconProps = JSX.IntrinsicElements["svg"];
type KeywordEntry = { regex: string, listIds: Array<string>, listType: ListType, ignoreCase: boolean; };
import { KeywordEntries } from "./components/KeywordEntries";
let keywordEntries: Array<KeywordEntry> = [];
let keywordLog: Array<any> = [];
interface KeywordEntry {
regex: string;
listIds?: string[];
listType?: ListType;
ignoreCase: boolean;
ignoreBots?: boolean;
whitelist: string[];
blacklist: string[];
listPriority: ListType;
}
export let keywordEntries: Array<KeywordEntry> = [];
let keywordLog: Array<Message> = [];
let interceptor: (e: any) => void;
const recentMentionsPopoutClass = findCssClassesLazy("recentMentionsPopout", "scroller");
interface ScrollerContext {
id: string;
onKeyDown: () => void;
orientation: string;
ref: RefObject<unknown>;
tabIndex: number;
}
interface ScrollerOpts {
role: string;
tabIndex: ScrollerContext["tabIndex"];
"data-list-id": ScrollerContext["id"];
onKeyDown: ScrollerContext["onKeyDown"];
ref: ScrollerContext["ref"];
"aria-orientation": ScrollerContext["orientation"];
}
const scrollerClass = findCssClassesLazy("singleMessage", "scroller");
const tabClass = findCssClassesLazy("inboxTitle", "tab");
const Popout = findByCodeLazy("getProTip", "canCloseAllMessages:");
const PopoutContainer = findByCodeLazy("navigator", "Provider");
const getMessageScrollerOptions: () => ScrollerOpts = findByCodeLazy("onKeyDown", "tabIndex", "useContext", "aria-orientation");
const createNavigator = findByCodeLazy("keyboardModeEnabled)", "scrollIntoViewNode");
const createMessageRecord = findByCodeLazy(".createFromServer(", ".isBlockedForMessage", "messageReference:");
const KEYWORD_ENTRIES_KEY = "KeywordNotify_keywordEntries";
export const KEYWORD_ENTRIES_KEY = "KeywordNotify_keywordEntries";
const KEYWORD_LOG_KEY = "KeywordNotify_log";
const cl = classNameFactory("vc-keywordnotify-");
export const cl = classNameFactory("vc-keywordnotify-");
async function addKeywordEntry(forceUpdate: () => void) {
keywordEntries.push({ regex: "", listIds: [], listType: ListType.BlackList, ignoreCase: false });
export async function addKeywordEntry(forceUpdate: () => void) {
keywordEntries.push({
regex: "",
ignoreCase: false,
ignoreBots: true,
whitelist: [],
blacklist: [],
listPriority: ListType.BlackList,
});
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
forceUpdate();
}
async function removeKeywordEntry(idx: number, forceUpdate: () => void) {
export async function removeKeywordEntry(idx: number, forceUpdate: () => void) {
keywordEntries.splice(idx, 1);
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
forceUpdate();
@ -60,15 +102,11 @@ function safeMatchesRegex(str: string, regex: string, flags: string) {
}
}
enum ListType {
export enum ListType {
BlackList = "BlackList",
Whitelist = "Whitelist"
}
interface BaseIconProps extends IconProps {
viewBox: string;
}
function highlightKeywords(str: string, entries: Array<KeywordEntry>) {
let regexes: Array<RegExp>;
try {
@ -77,7 +115,7 @@ function highlightKeywords(str: string, entries: Array<KeywordEntry>) {
return [str];
}
const matches = regexes.map(r => str.match(r)).flat().filter(e => e !== null) as Array<string>;
const matches = regexes.map(r => str.match(r)).flat().filter(e => e != null) as Array<string>;
if (matches.length === 0) {
return [str];
}
@ -93,214 +131,12 @@ function highlightKeywords(str: string, entries: Array<KeywordEntry>) {
);
}
function Collapsible({ title, children }) {
const [isOpen, setIsOpen] = useState(false);
return (
<div>
<TextButton
onClick={() => setIsOpen(!isOpen)}
className={cl("collapsible")}>
<div style={{ display: "flex", alignItems: "center" }}>
<div style={{
marginLeft: "auto",
color: "var(--text-muted)",
paddingRight: "5px"
}}>{isOpen ? "▼" : "▶"}</div>
<Heading tag="h4">{title}</Heading>
</div>
</TextButton>
{isOpen && children}
</div>
);
}
function ListedIds({ listIds, setListIds }) {
const update = useForceUpdater();
const [values] = useState(listIds);
async function onChange(e: string, index: number) {
values[index] = e.trim();
setListIds(values);
update();
}
const elements = values.map((currentValue: string, index: number) => {
return (
<Flex key={index} flexDirection="row" style={{ marginBottom: "5px" }}>
<div style={{ flexGrow: 1 }}>
<TextInput
placeholder="ID"
spellCheck={false}
value={currentValue}
onChange={e => onChange(e, index)}
/>
</div>
<Button
onClick={() => {
values.splice(index, 1);
setListIds(values);
update();
}}
variant="none"
size="iconOnly"
className={cl("delete")}>
<DeleteIcon />
</Button>
</Flex>
);
});
return (
<>
{elements}
</>
);
}
function ListTypeSelector({ listType, setListType }: { listType: ListType, setListType: (v: ListType) => void; }) {
return (
<Select
options={[
{ label: "Whitelist", value: ListType.Whitelist },
{ label: "Blacklist", value: ListType.BlackList }
]}
placeholder={"Select a list type"}
isSelected={v => v === listType}
closeOnSelect={true}
select={setListType}
serialize={v => v}
/>
);
}
function KeywordEntries() {
const update = useForceUpdater();
const [values] = useState(keywordEntries);
async function setRegex(index: number, value: string) {
keywordEntries[index].regex = value;
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
update();
}
async function setListType(index: number, value: ListType) {
keywordEntries[index].listType = value;
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
update();
}
async function setListIds(index: number, value: Array<string>) {
keywordEntries[index].listIds = value ?? [];
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
update();
}
async function setIgnoreCase(index: number, value: boolean) {
keywordEntries[index].ignoreCase = value;
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
update();
}
const elements = keywordEntries.map((entry, i) => {
return (
<>
<Collapsible title={`Keyword Entry ${i + 1}`}>
<Flex flexDirection="row">
<div style={{ flexGrow: 1 }}>
<TextInput
placeholder="example|regex"
spellCheck={false}
value={values[i].regex}
onChange={e => setRegex(i, e)}
/>
</div>
<Button
onClick={() => removeKeywordEntry(i, update)}
variant="none"
size="iconOnly"
className={cl("delete")}>
<DeleteIcon />
</Button>
</Flex>
<FormSwitch
title="Ignore Case"
className={cl("ignoreCaseSwitch")}
value={values[i].ignoreCase}
onChange={() => {
setIgnoreCase(i, !values[i].ignoreCase);
}}
/>
<Heading tag="h5">Whitelist/Blacklist</Heading>
<Flex flexDirection="row">
<div style={{ flexGrow: 1 }}>
<ListedIds listIds={values[i].listIds} setListIds={e => setListIds(i, e)} />
</div>
</Flex>
<div className={[Margins.top8, Margins.bottom8].join(" ")} />
<Flex flexDirection="row">
<Button onClick={() => {
values[i].listIds.push("");
update();
}}>Add ID</Button>
<div style={{ flexGrow: 1 }}>
<ListTypeSelector listType={values[i].listType} setListType={e => setListType(i, e)} />
</div>
</Flex>
</Collapsible>
</>
);
});
return (
<>
{elements}
<div><Button onClick={() => addKeywordEntry(update)}>Add Keyword Entry</Button></div>
</>
);
}
function Icon({ height = 24, width = 24, className, children, viewBox, ...svgProps }: PropsWithChildren<BaseIconProps>) {
return (
<svg
className={classes(className, "vc-icon")}
role="img"
width={width}
height={height}
viewBox={viewBox}
{...svgProps}
>
{children}
</svg>
);
}
// 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 (
<Icon
{...props}
className={classes(props.className, "vc-double-checkmark-icon")}
viewBox="0 0 24 24"
width={16}
height={16}
>
<path fill="currentColor"
d="M16.7 8.7a1 1 0 0 0-1.4-1.4l-3.26 3.24a1 1 0 0 0 1.42 1.42L16.7 8.7ZM3.7 11.3a1 1 0 0 0-1.4 1.4l4.5 4.5a1 1 0 0 0 1.4-1.4l-4.5-4.5Z"
/>
<path fill="currentColor"
d="M21.7 9.7a1 1 0 0 0-1.4-1.4L13 15.58l-3.3-3.3a1 1 0 0 0-1.4 1.42l4 4a1 1 0 0 0 1.4 0l8-8Z"
/>
</Icon>
);
}
const settings = definePluginSettings({
ignoreBots: {
type: OptionType.BOOLEAN,
description: "Ignore messages from bots",
default: true
default: true,
hidden: true,
},
amountToKeep: {
type: OptionType.NUMBER,
@ -316,13 +152,12 @@ const settings = definePluginSettings({
export default definePlugin({
name: "KeywordNotify",
authors: [EquicordDevs.camila314, EquicordDevs.x3rt],
authors: [EquicordDevs.camila314, EquicordDevs.x3rt, EquicordDevs.benjas333],
description: "Sends a notification if a given message matches certain keywords or regexes",
tags: ["Chat", "Notifications"],
settings,
patches: [
{
find: "#{intl::UNREADS_TAB_LABEL})}",
find: "#{intl::MENTIONS})",
group: true,
replacement: [
{
@ -331,33 +166,47 @@ export default definePlugin({
},
{
match: /:(\i)===\i\.\i\.MENTIONS\?\(0,.{0,500}null}/,
replace: ": $1 === 8 ? $self.keywordClearButton() $&"
replace: ": $1 === 8 ? $self.keywordClearButton() $&",
},
{
match: /:(\i)===\i\.\i\.MENTIONS\?\(0,.{0,500}onJump:(\i)}\)/,
replace: ": $1 === 8 ? $self.tryKeywordMenu($2) $&"
}
]
},
{
find: "#{intl::RECENT_MENTIONS_EMPTY_STATE_TIP}",
replacement: [
replace: ": $1 === 8 ? $self.tryKeywordMenu($2) $&",
},
{
match: /function (\i)\(\i\){let{message:\i,onJump/,
replace: "$self.renderMsg = $1; $&"
replace: "$self.RenderMsg = $1; $&",
},
{
match: /onClick:\(\)=>(\i\.\i\.deleteRecentMention\((\i)\.id\))/,
replace: "onClick: () => $2._keyword ? $self.deleteKeyword($2.id) : $1"
}
replace: "onClick: () => $2._keyword ? $self.deleteKeyword($2.id) : $1",
},
]
},
],
async start() {
this.onUpdate = () => null;
keywordEntries = await DataStore.get(KEYWORD_ENTRIES_KEY) ?? [];
keywordEntries.forEach(entry => {
entry.ignoreBots = entry.ignoreBots ?? this.settings.store.ignoreBots;
entry.whitelist = entry.whitelist ?? [];
entry.blacklist = entry.blacklist ?? [];
entry.listPriority = entry.listPriority ?? ListType.BlackList;
if (entry.listType == null || entry.listIds == null) return;
if (entry.listType === ListType.Whitelist) {
entry.whitelist = entry.listIds;
} else {
entry.blacklist = entry.listIds;
}
delete entry.listIds;
delete entry.listType;
});
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
(await DataStore.get(KEYWORD_LOG_KEY) ?? []).map(e => JSON.parse(e)).forEach(e => {
try {
this.addToLog(e);
@ -369,10 +218,8 @@ export default definePlugin({
interceptor = (e: any) => {
return this.modify(e);
};
FluxDispatcher.addInterceptor(interceptor);
},
stop() {
const index = FluxDispatcher._interceptors.indexOf(interceptor);
if (index > -1) {
@ -388,24 +235,45 @@ export default definePlugin({
continue;
}
let listed = entry.listIds.some(id => id.trim() === m.channel_id || id === m.author.id);
if (!listed) {
let isInWhitelist = entry.whitelist.some(id => {
const trimmed = id.trim();
return trimmed === m.channel_id || trimmed === m.author.id;
});
if (!isInWhitelist) {
const channel = ChannelStore.getChannel(m.channel_id);
if (channel != null) {
listed = entry.listIds.some(id => id.trim() === channel.guild_id);
isInWhitelist = entry.whitelist.some(id => id.trim() === channel.guild_id);
}
}
const whitelistMode = entry.listType === ListType.Whitelist;
if (!whitelistMode && listed) {
continue;
}
if (whitelistMode && !listed) {
continue;
let isInBlacklist = entry.blacklist.some(id => {
const trimmed = id.trim();
return trimmed === m.channel_id || trimmed === m.author.id;
});
if (!isInBlacklist) {
const channel = ChannelStore.getChannel(m.channel_id);
if (channel != null) {
isInBlacklist = entry.whitelist.some(id => id.trim() === channel.guild_id);
}
}
if (settings.store.ignoreBots && m.author.bot && (!whitelistMode || !entry.listIds.includes(m.author.id))) {
const isWhitelistPrioritized = entry.listPriority === ListType.Whitelist;
if (isInWhitelist && isInBlacklist) {
if (!isWhitelistPrioritized) {
continue;
}
} else {
if (entry.whitelist.length && !isInWhitelist) {
continue;
}
if (isInBlacklist) {
continue;
}
}
if (m.author.bot && entry.ignoreBots && (!entry.whitelist.length || !entry.whitelist.includes(m.author.id))) {
continue;
}
@ -431,7 +299,7 @@ export default definePlugin({
if (matches) {
const id = UserStore.getCurrentUser()?.id;
if (id !== null) {
if (id != null) {
// @ts-ignore
m.mentions.push({ id: id });
}
@ -479,7 +347,7 @@ export default definePlugin({
}
keywordLog.push(messageRecord);
keywordLog.sort((a, b) => b.timestamp - a.timestamp);
keywordLog.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime());
while (keywordLog.length > settings.store.amountToKeep) {
keywordLog.pop();
@ -515,7 +383,7 @@ export default definePlugin({
DataStore.set(KEYWORD_LOG_KEY, []);
this.onUpdate();
}}>
<DoubleCheckmarkIcon />
<DoubleCheckmarkIcon width={16} height={16} className={"vc-double-checkmark-icon"} />
</Button>
)}
</Tooltip>
@ -523,50 +391,54 @@ export default definePlugin({
},
tryKeywordMenu(onJump) {
const channel = ChannelStore.getChannel(SelectedChannelStore.getChannelId());
const [tempLogs, setKeywordLog] = useState(keywordLog);
const navigatorScrollerRef = useRef<ScrollerBaseRef | null>(null);
const navigator = createNavigator("keywords", navigatorScrollerRef);
this.onUpdate = () => {
const newLog = Array.from(keywordLog);
setKeywordLog(newLog);
};
const messageRender = (e, t) => {
e._keyword = true;
const RenderMsgWrapper = (message: Message & { _keyword?: boolean; }): JSX.Element => {
message._keyword = true;
e.customRenderedContent = {
content: highlightKeywords(e.content, keywordEntries)
message.customRenderedContent = {
content: highlightKeywords(message.content, keywordEntries)
};
const msg = this.renderMsg({
message: e,
gotoMessage: t,
dismissible: true
return this.RenderMsg({
message,
onJump,
});
};
return [msg];
const MessageScrollerHelper = ({ children }: { children: (scrollerOpts: ScrollerOpts) => JSX.Element; }) => {
return children(getMessageScrollerOptions());
};
return (
<>
<Popout
className={classes(recentMentionsPopoutClass.recentMentionsPopout)}
scrollerClassName={classes(recentMentionsPopoutClass.scroller)}
renderHeader={() => null}
renderMessage={messageRender}
channel={channel}
onJump={onJump}
onFetch={() => null}
onCloseMessage={(id: string) => {
this.deleteKeyword(id);
this.discardMessage(id);
}}
loadMore={() => null}
messages={tempLogs}
renderEmptyState={() => null}
canCloseAllMessages={true}
/>
</>
<ErrorBoundary>
<PopoutContainer navigator={navigator}>
<MessageScrollerHelper>
{({ ref, ...restOpts }) => {
return <ScrollerThin
ref={thinScrollerRef => {
navigatorScrollerRef.current = thinScrollerRef;
// @ts-ignore
ref.current = thinScrollerRef?.getScrollerNode() ?? null;
}}
className={classes(scrollerClass.scroller)}
onScroll={void 0}
{...restOpts}
>
{tempLogs.map(m => <div key={m.id}>{RenderMsgWrapper(m)}</div>)}
</ScrollerThin>;
}}
</MessageScrollerHelper>
</PopoutContainer>
</ErrorBoundary>
);
},

View file

@ -8,13 +8,6 @@
color: var(--status-danger);
}
.vc-keywordnotify-collapsible {
display: flex;
align-items: center;
padding: 8px;
cursor: pointer;
}
.vc-keywordnotify-ignoreCaseSwitch {
margin-top: 0.5em;
margin-right: 40px;

View file

@ -1398,6 +1398,10 @@ export const EquicordDevs = Object.freeze({
name: "luca.beyer",
id: 405090676771127317n
},
benjas333: {
name: "benjas333",
id: 456577284464443394n,
},
} satisfies Record<string, Dev>);
// iife so #__PURE__ works correctly