mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-16 09:57:08 -04:00
Fully Update KeywordNotify
This commit is contained in:
parent
0e720a0f75
commit
3d5d1825f0
3 changed files with 28 additions and 21 deletions
|
@ -72,7 +72,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
|
||||||
- Jumpscare by Surgedevs
|
- Jumpscare by Surgedevs
|
||||||
- JumpToStart by Samwich
|
- JumpToStart by Samwich
|
||||||
- KeyboardSounds by HypedDomi
|
- KeyboardSounds by HypedDomi
|
||||||
- KeywordNotify by camila314 (maintained by thororen)
|
- KeywordNotify by camila314 and x3rt
|
||||||
- LoginWithQR by nexpid
|
- LoginWithQR by nexpid
|
||||||
- MediaDownloader by Colorman
|
- MediaDownloader by Colorman
|
||||||
- MediaPlaybackSpeed by D3SOX
|
- MediaPlaybackSpeed by D3SOX
|
||||||
|
|
|
@ -17,7 +17,7 @@ import { classes } from "@utils/misc";
|
||||||
import { useForceUpdater } from "@utils/react";
|
import { useForceUpdater } from "@utils/react";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
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 { Message, User } from "discord-types/general/index.js";
|
||||||
import type { PropsWithChildren } from "react";
|
import type { PropsWithChildren } from "react";
|
||||||
|
|
||||||
|
@ -28,17 +28,19 @@ type KeywordEntry = { regex: string, listIds: Array<string>, listType: ListType,
|
||||||
let keywordEntries: Array<KeywordEntry> = [];
|
let keywordEntries: Array<KeywordEntry> = [];
|
||||||
let currentUser: User;
|
let currentUser: User;
|
||||||
let keywordLog: Array<any> = [];
|
let keywordLog: Array<any> = [];
|
||||||
|
let interceptor: (e: any) => void;
|
||||||
|
|
||||||
|
|
||||||
const recentMentionsPopoutClass = findByPropsLazy("recentMentionsPopout");
|
const recentMentionsPopoutClass = findByPropsLazy("recentMentionsPopout");
|
||||||
const tabClass = findByPropsLazy("inboxTitle", "tab");
|
const tabClass = findByPropsLazy("inboxTitle", "tab");
|
||||||
const buttonClass = findByPropsLazy("size36");
|
const buttonClass = findByPropsLazy("size36");
|
||||||
|
const MenuHeader = findByCodeLazy(".getUnseenInviteCount())");
|
||||||
const Popout = findByCodeLazy(".Messages.UNBLOCK_TO_JUMP_TITLE", "canCloseAllMessages:");
|
const Popout = findByCodeLazy(".Messages.UNBLOCK_TO_JUMP_TITLE", "canCloseAllMessages:");
|
||||||
const createMessageRecord = findByCodeLazy(".createFromServer(", ".isBlockedForMessage", "messageReference:");
|
const createMessageRecord = findByCodeLazy(".createFromServer(", ".isBlockedForMessage", "messageReference:");
|
||||||
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 cl = classNameFactory("vc-keywordnotify-");
|
const cl = classNameFactory("vc-keywordnotify-");
|
||||||
const MenuHeader = findByCodeLazy("getUnseenInviteCount())");
|
|
||||||
|
|
||||||
async function addKeywordEntry(forceUpdate: () => void) {
|
async function addKeywordEntry(forceUpdate: () => void) {
|
||||||
keywordEntries.push({ regex: "", listIds: [], listType: ListType.BlackList, ignoreCase: false });
|
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 :/
|
// Ideally I would just add this to Icons.tsx, but I cannot as this is a user-plugin :/
|
||||||
function DoubleCheckmarkIcon(props: IconProps) {
|
function DoubleCheckmarkIcon(props: IconProps) {
|
||||||
|
// noinspection TypeScriptValidateTypes
|
||||||
return (
|
return (
|
||||||
<Icon
|
<Icon
|
||||||
{...props}
|
{...props}
|
||||||
className={classes(props.className, "vc-double-checkmark-icon")}
|
className={classes(props.className, "vc-double-checkmark-icon")}
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
>
|
>
|
||||||
<path fill="currentColor"
|
<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"
|
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"
|
||||||
|
@ -306,17 +311,10 @@ const settings = definePluginSettings({
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "KeywordNotify",
|
name: "KeywordNotify",
|
||||||
authors: [EquicordDevs.camila314, EquicordDevs.x3rt, EquicordDevs.thororen],
|
authors: [EquicordDevs.camila314, EquicordDevs.x3rt],
|
||||||
description: "Sends a notification if a given message matches certain keywords or regexes",
|
description: "Sends a notification if a given message matches certain keywords or regexes",
|
||||||
settings,
|
settings,
|
||||||
patches: [
|
patches: [
|
||||||
{
|
|
||||||
find: "Dispatch.dispatch(...) called without an action type",
|
|
||||||
replacement: {
|
|
||||||
match: /}_dispatch\((\i),\i\){/,
|
|
||||||
replace: "$&$1=$self.modify($1);"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
find: "Messages.UNREADS_TAB_LABEL}",
|
find: "Messages.UNREADS_TAB_LABEL}",
|
||||||
replacement: {
|
replacement: {
|
||||||
|
@ -355,6 +353,17 @@ export default definePlugin({
|
||||||
(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 => {
|
||||||
this.addToLog(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) {
|
applyKeywordEntries(m: Message) {
|
||||||
|
@ -427,8 +436,9 @@ export default definePlugin({
|
||||||
keywordLog.push(thing);
|
keywordLog.push(thing);
|
||||||
keywordLog.sort((a, b) => b.timestamp - a.timestamp);
|
keywordLog.sort((a, b) => b.timestamp - a.timestamp);
|
||||||
|
|
||||||
if (keywordLog.length > settings.store.amountToKeep)
|
while (keywordLog.length > settings.store.amountToKeep) {
|
||||||
keywordLog.pop();
|
keywordLog.pop();
|
||||||
|
}
|
||||||
|
|
||||||
this.onUpdate();
|
this.onUpdate();
|
||||||
},
|
},
|
||||||
|
@ -451,20 +461,16 @@ export default definePlugin({
|
||||||
<MenuHeader tab={8} setTab={setTab} closePopout={closePopout} badgeState={{ badgeForYou: false }} children={
|
<MenuHeader tab={8} setTab={setTab} closePopout={closePopout} badgeState={{ badgeForYou: false }} children={
|
||||||
<Tooltip text="Clear All">
|
<Tooltip text="Clear All">
|
||||||
{({ onMouseLeave, onMouseEnter }) => (
|
{({ onMouseLeave, onMouseEnter }) => (
|
||||||
<Button
|
<div className={classes(tabClass.controlButton, buttonClass.button, buttonClass.tertiary, buttonClass.size32)}
|
||||||
onMouseLeave={onMouseLeave}
|
onMouseLeave={onMouseLeave}
|
||||||
onMouseEnter={onMouseEnter}
|
onMouseEnter={onMouseEnter}
|
||||||
look={Button.Looks.BLANK}
|
|
||||||
size={Button.Sizes.ICON}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
keywordLog = [];
|
keywordLog = [];
|
||||||
DataStore.set(KEYWORD_LOG_KEY, []);
|
DataStore.set(KEYWORD_LOG_KEY, []);
|
||||||
this.onUpdate();
|
this.onUpdate();
|
||||||
}}>
|
}}>
|
||||||
<div className={classes(buttonClass.button, buttonClass.secondary, buttonClass.size32)}>
|
|
||||||
<DoubleCheckmarkIcon />
|
<DoubleCheckmarkIcon />
|
||||||
</div>
|
</div>
|
||||||
</Button>
|
|
||||||
)}
|
)}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
} />
|
} />
|
||||||
|
@ -514,13 +520,12 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
|
|
||||||
modify(e) {
|
modify(e) {
|
||||||
if (e.type === "MESSAGE_CREATE") {
|
if (e.type === "MESSAGE_CREATE" || e.type === "MESSAGE_UPDATE") {
|
||||||
this.applyKeywordEntries(e.message);
|
this.applyKeywordEntries(e.message);
|
||||||
} else if (e.type === "LOAD_MESSAGES_SUCCESS") {
|
} else if (e.type === "LOAD_MESSAGES_SUCCESS") {
|
||||||
for (let msg = 0; msg < e.messages.length; ++msg) {
|
for (let msg = 0; msg < e.messages.length; ++msg) {
|
||||||
this.applyKeywordEntries(e.messages[msg]);
|
this.applyKeywordEntries(e.messages[msg]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return e;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
2
src/webpack/common/types/utils.d.ts
vendored
2
src/webpack/common/types/utils.d.ts
vendored
|
@ -27,7 +27,9 @@ export { FluxEvents };
|
||||||
|
|
||||||
export interface FluxDispatcher {
|
export interface FluxDispatcher {
|
||||||
_actionHandlers: any;
|
_actionHandlers: any;
|
||||||
|
_interceptors: any;
|
||||||
_subscriptions: any;
|
_subscriptions: any;
|
||||||
|
addInterceptor(interceptor: any): void;
|
||||||
dispatch(event: { [key: string]: unknown; type: FluxEvents; }): Promise<void>;
|
dispatch(event: { [key: string]: unknown; type: FluxEvents; }): Promise<void>;
|
||||||
isDispatching(): boolean;
|
isDispatching(): boolean;
|
||||||
subscribe(event: FluxEvents, callback: (data: any) => void): void;
|
subscribe(event: FluxEvents, callback: (data: any) => void): void;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue