mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 09:56:24 +00:00
make work again
This commit is contained in:
parent
d3a6f71b1d
commit
5c843bdbb7
2 changed files with 49 additions and 44 deletions
|
@ -6,40 +6,42 @@
|
||||||
|
|
||||||
import "./style.css";
|
import "./style.css";
|
||||||
|
|
||||||
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
import { Button, ChannelStore, Forms, SearchableSelect,SelectedChannelStore, TabBar, TextInput, UserStore, UserUtils, useState } from "@webpack/common";
|
||||||
|
import { classNameFactory } from "@api/Styles";
|
||||||
import { DataStore } from "@api/index";
|
import { DataStore } from "@api/index";
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { Flex } from "@components/Flex";
|
|
||||||
import { DeleteIcon } from "@components/Icons";
|
import { DeleteIcon } from "@components/Icons";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { Margins } from "@utils/margins";
|
|
||||||
import { useForceUpdater } from "@utils/react";
|
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
|
||||||
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
||||||
import { Button, ChannelStore, Forms, SearchableSelect,SelectedChannelStore, TabBar, TextInput, UserStore, UserUtils, useState } from "@webpack/common";
|
import { Flex } from "@components/Flex";
|
||||||
|
import { Margins } from "@utils/margins";
|
||||||
import { Message, User } from "discord-types/general/index.js";
|
import { Message, User } from "discord-types/general/index.js";
|
||||||
|
import { useForceUpdater } from "@utils/react";
|
||||||
|
|
||||||
let keywordEntries: Array<{ regex: string, listIds: Array<string>, listType: ListType }> = [];
|
let keywordEntries: Array<{ regex: string, listIds: Array<string>, listType: ListType }> = [];
|
||||||
let currentUser: User;
|
let currentUser: User;
|
||||||
let keywordLog: Array<any> = [];
|
let keywordLog: Array<any> = [];
|
||||||
|
|
||||||
const MenuHeader = findByCodeLazy(".useInDesktopNotificationCenterExperiment)()?");
|
const MenuHeader = findByCodeLazy(".sv)()?(0,");
|
||||||
const Popout = findByCodeLazy("let{analyticsName:");
|
const Popout = findByCodeLazy(".loadingMore&&null==");
|
||||||
const recentMentionsPopoutClass = findByPropsLazy("recentMentionsPopout");
|
const recentMentionsPopoutClass = findByPropsLazy("recentMentionsPopout");
|
||||||
|
const createMessageRecord = findByCodeLazy("THREAD_CREATED?[]:(0,");
|
||||||
const KEYWORD_ENTRIES_KEY = "KeywordNotify_keywordEntries";
|
const KEYWORD_ENTRIES_KEY = "KeywordNotify_keywordEntries";
|
||||||
const KEYWORD_LOG_KEY = "KeywordNotify_log";
|
const KEYWORD_LOG_KEY = "KeywordNotify_log";
|
||||||
|
|
||||||
const { createMessageRecord } = findByPropsLazy("createMessageRecord", "updateMessageRecord");
|
const cl = classNameFactory("vc-keywordnotify-");
|
||||||
|
|
||||||
async function addKeywordEntry(updater: () => void) {
|
async function addKeywordEntry(forceUpdate: () => void) {
|
||||||
keywordEntries.push({ regex: "", listIds: [], listType: ListType.BlackList });
|
keywordEntries.push({ regex: "", listIds: [], listType: ListType.BlackList });
|
||||||
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
|
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
|
||||||
updater();
|
forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeKeywordEntry(idx: number, updater: () => void) {
|
async function removeKeywordEntry(idx: number, forceUpdate: () => void) {
|
||||||
keywordEntries.splice(idx, 1);
|
keywordEntries.splice(idx, 1);
|
||||||
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
|
await DataStore.set(KEYWORD_ENTRIES_KEY, keywordEntries);
|
||||||
updater();
|
forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
function safeMatchesRegex(s: string, r: string) {
|
function safeMatchesRegex(s: string, r: string) {
|
||||||
|
@ -50,7 +52,6 @@ function safeMatchesRegex(s: string, r: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum ListType {
|
enum ListType {
|
||||||
BlackList = "BlackList",
|
BlackList = "BlackList",
|
||||||
Whitelist = "Whitelist"
|
Whitelist = "Whitelist"
|
||||||
|
@ -90,7 +91,7 @@ function Collapsible({ title, children }) {
|
||||||
onClick={() => setIsOpen(!isOpen)}
|
onClick={() => setIsOpen(!isOpen)}
|
||||||
look={Button.Looks.BLANK}
|
look={Button.Looks.BLANK}
|
||||||
size={Button.Sizes.ICON}
|
size={Button.Sizes.ICON}
|
||||||
className="keywordnotify-collapsible">
|
className={cl("collapsible")}>
|
||||||
<div style={{ display: "flex", alignItems: "center" }}>
|
<div style={{ display: "flex", alignItems: "center" }}>
|
||||||
<div style={{ marginLeft: "auto", color: "var(--text-muted)", paddingRight: "5px" }}>{isOpen ? "▼" : "▶"}</div>
|
<div style={{ marginLeft: "auto", color: "var(--text-muted)", paddingRight: "5px" }}>{isOpen ? "▼" : "▶"}</div>
|
||||||
<Forms.FormTitle tag="h4">{title}</Forms.FormTitle>
|
<Forms.FormTitle tag="h4">{title}</Forms.FormTitle>
|
||||||
|
@ -130,7 +131,7 @@ function ListedIds({ listIds, setListIds }) {
|
||||||
}}
|
}}
|
||||||
look={Button.Looks.BLANK}
|
look={Button.Looks.BLANK}
|
||||||
size={Button.Sizes.ICON}
|
size={Button.Sizes.ICON}
|
||||||
className="keywordnotify-delete">
|
className={cl("delete")}>
|
||||||
<DeleteIcon/>
|
<DeleteIcon/>
|
||||||
</Button>
|
</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
@ -200,18 +201,18 @@ function KeywordEntries() {
|
||||||
onClick={() => removeKeywordEntry(i, update)}
|
onClick={() => removeKeywordEntry(i, update)}
|
||||||
look={Button.Looks.BLANK}
|
look={Button.Looks.BLANK}
|
||||||
size={Button.Sizes.ICON}
|
size={Button.Sizes.ICON}
|
||||||
className="keywordnotify-delete">
|
className={cl("delete")}>
|
||||||
<DeleteIcon/>
|
<DeleteIcon/>
|
||||||
</Button>
|
</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Forms.FormDivider className={Margins.top8 + " " + Margins.bottom8}/>
|
<Forms.FormDivider className={[Margins.top8, Margins.bottom8].join(" ") }/>
|
||||||
<Forms.FormTitle tag="h5">Whitelist/Blacklist</Forms.FormTitle>
|
<Forms.FormTitle tag="h5">Whitelist/Blacklist</Forms.FormTitle>
|
||||||
<Flex flexDirection="row">
|
<Flex flexDirection="row">
|
||||||
<div style={{ flexGrow: 1 }}>
|
<div style={{ flexGrow: 1 }}>
|
||||||
<ListedIds listIds={values[i].listIds} setListIds={e => setListIds(i, e)}/>
|
<ListedIds listIds={values[i].listIds} setListIds={e => setListIds(i, e)}/>
|
||||||
</div>
|
</div>
|
||||||
</Flex>
|
</Flex>
|
||||||
<div className={Margins.top8 + " " + Margins.bottom8}/>
|
<div className={[Margins.top8, Margins.bottom8].join(" ") }/>
|
||||||
<Flex flexDirection="row">
|
<Flex flexDirection="row">
|
||||||
<Button onClick={() => {
|
<Button onClick={() => {
|
||||||
values[i].listIds.push("");
|
values[i].listIds.push("");
|
||||||
|
@ -242,7 +243,6 @@ const settings = definePluginSettings({
|
||||||
},
|
},
|
||||||
keywords: {
|
keywords: {
|
||||||
type: OptionType.COMPONENT,
|
type: OptionType.COMPONENT,
|
||||||
description: "",
|
|
||||||
component: () => <KeywordEntries/>
|
component: () => <KeywordEntries/>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -254,7 +254,7 @@ export default definePlugin({
|
||||||
settings,
|
settings,
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
find: "}_dispatch(",
|
find: "Dispatch.dispatch(...) called without an action type",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /}_dispatch\((\i),\i\){/,
|
match: /}_dispatch\((\i),\i\){/,
|
||||||
replace: "$&$1=$self.modify($1);"
|
replace: "$&$1=$self.modify($1);"
|
||||||
|
@ -268,9 +268,9 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
find: "InboxTab.TODOS?(",
|
find: "location:\"RecentsPopout\"",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /:\i&&(\i)===\i\.InboxTab\.TODOS.{1,50}setTab:(\i),onJump:(\i),closePopout:(\i)/,
|
match: /:(\i)===\i\.\i\.MENTIONS\?\(0,.+?setTab:(\i),onJump:(\i),badgeState:\i,closePopout:(\i)/,
|
||||||
replace: ": $1 === 5 ? $self.tryKeywordMenu($2, $3, $4) $&"
|
replace: ": $1 === 5 ? $self.tryKeywordMenu($2, $3, $4) $&"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -280,12 +280,19 @@ export default definePlugin({
|
||||||
match: /function (\i)\(\i\){let{message:\i,gotoMessage/,
|
match: /function (\i)\(\i\){let{message:\i,gotoMessage/,
|
||||||
replace: "$self.renderMsg = $1; $&"
|
replace: "$self.renderMsg = $1; $&"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
find: ".guildFilter:null",
|
||||||
|
replacement: {
|
||||||
|
match: /onClick:\(\)=>(\i\.\i\.deleteRecentMention\((\i)\.id\))/,
|
||||||
|
replace: "onClick: () => $2._keyword ? $self.deleteKeyword($2.id) : $1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
keywordEntries = await DataStore.get(KEYWORD_ENTRIES_KEY) ?? [];
|
keywordEntries = await DataStore.get(KEYWORD_ENTRIES_KEY) ?? [];
|
||||||
currentUser = await UserUtils.getUser(UserStore.getCurrentUser().id);
|
currentUser = UserStore.getCurrentUser();
|
||||||
this.onUpdate = () => null;
|
this.onUpdate = () => null;
|
||||||
|
|
||||||
(await DataStore.get(KEYWORD_LOG_KEY) ?? []).map(e => JSON.parse(e)).forEach(e => {
|
(await DataStore.get(KEYWORD_LOG_KEY) ?? []).map(e => JSON.parse(e)).forEach(e => {
|
||||||
|
@ -341,7 +348,6 @@ export default definePlugin({
|
||||||
});
|
});
|
||||||
|
|
||||||
if (matches) {
|
if (matches) {
|
||||||
// @ts-ignore
|
|
||||||
m.mentions.push(currentUser);
|
m.mentions.push(currentUser);
|
||||||
|
|
||||||
if (m.author.id !== currentUser.id)
|
if (m.author.id !== currentUser.id)
|
||||||
|
@ -353,6 +359,10 @@ export default definePlugin({
|
||||||
if (m == null || keywordLog.some(e => e.id === m.id))
|
if (m == null || keywordLog.some(e => e.id === m.id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
DataStore.get(KEYWORD_LOG_KEY).then(log => {
|
||||||
|
DataStore.set(KEYWORD_LOG_KEY, [...log, JSON.stringify(m)]);
|
||||||
|
});
|
||||||
|
|
||||||
const thing = createMessageRecord(m);
|
const thing = createMessageRecord(m);
|
||||||
keywordLog.push(thing);
|
keywordLog.push(thing);
|
||||||
keywordLog.sort((a, b) => b.timestamp - a.timestamp);
|
keywordLog.sort((a, b) => b.timestamp - a.timestamp);
|
||||||
|
@ -363,6 +373,10 @@ export default definePlugin({
|
||||||
this.onUpdate();
|
this.onUpdate();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
deleteKeyword(id) {
|
||||||
|
keywordLog = keywordLog.filter(e => e.id !== id);
|
||||||
|
this.onUpdate();
|
||||||
|
},
|
||||||
|
|
||||||
keywordTabBar() {
|
keywordTabBar() {
|
||||||
return (
|
return (
|
||||||
|
@ -381,32 +395,23 @@ export default definePlugin({
|
||||||
|
|
||||||
const [tempLogs, setKeywordLog] = useState(keywordLog);
|
const [tempLogs, setKeywordLog] = useState(keywordLog);
|
||||||
this.onUpdate = () => {
|
this.onUpdate = () => {
|
||||||
const newLog = [...keywordLog];
|
const newLog = Array.from(keywordLog);
|
||||||
setKeywordLog(newLog);
|
setKeywordLog(newLog);
|
||||||
|
|
||||||
DataStore.set(KEYWORD_LOG_KEY, newLog.map(e => JSON.stringify(e)));
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDelete = m => {
|
|
||||||
keywordLog = keywordLog.filter(e => e.id !== m.id);
|
|
||||||
this.onUpdate();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const messageRender = (e, t) => {
|
const messageRender = (e, t) => {
|
||||||
|
e._keyword = true;
|
||||||
|
|
||||||
|
e.customRenderedContent = {
|
||||||
|
content: highlightKeywords(e.content, keywordEntries.map(e => e.regex))
|
||||||
|
};
|
||||||
|
|
||||||
const msg = this.renderMsg({
|
const msg = this.renderMsg({
|
||||||
message: e,
|
message: e,
|
||||||
gotoMessage: t,
|
gotoMessage: t,
|
||||||
dismissible: true
|
dismissible: true
|
||||||
});
|
});
|
||||||
|
|
||||||
if (msg == null)
|
|
||||||
return [null];
|
|
||||||
|
|
||||||
msg.props.children[0].props.children.props.onClick = () => onDelete(e);
|
|
||||||
msg.props.children[1].props.children[1].props.message.customRenderedContent = {
|
|
||||||
content: highlightKeywords(e.content, keywordEntries.map(e => e.regex))
|
|
||||||
};
|
|
||||||
|
|
||||||
return [msg];
|
return [msg];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -419,7 +424,7 @@ export default definePlugin({
|
||||||
channel={channel}
|
channel={channel}
|
||||||
onJump={onJump}
|
onJump={onJump}
|
||||||
onFetch={() => null}
|
onFetch={() => null}
|
||||||
onCloseMessage={onDelete}
|
onCloseMessage={this.deleteKeyword}
|
||||||
loadMore={() => null}
|
loadMore={() => null}
|
||||||
messages={tempLogs}
|
messages={tempLogs}
|
||||||
renderEmptyState={() => null}
|
renderEmptyState={() => null}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
.keywordnotify-delete:hover {
|
.vc-keywordnotify-delete:hover {
|
||||||
color: var(--status-danger);
|
color: var(--status-danger);
|
||||||
}
|
}
|
||||||
|
|
||||||
.keywordnotify-delete {
|
.vc-keywordnotify-delete {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
color: var(--primary-400);
|
color: var(--primary-400);
|
||||||
transition: color 0.2s ease-in-out;
|
transition: color 0.2s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.keywordnotify-collapsible {
|
.vc-keywordnotify-collapsible {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
|
Loading…
Reference in a new issue