mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-15 09:33:03 -04:00
Fully Update KeywordNotify
This commit is contained in:
parent
0e720a0f75
commit
3d5d1825f0
3 changed files with 28 additions and 21 deletions
|
@ -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<string>, listType: ListType,
|
|||
let keywordEntries: Array<KeywordEntry> = [];
|
||||
let currentUser: User;
|
||||
let keywordLog: Array<any> = [];
|
||||
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 (
|
||||
<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"
|
||||
|
@ -306,17 +311,10 @@ const settings = definePluginSettings({
|
|||
|
||||
export default definePlugin({
|
||||
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",
|
||||
settings,
|
||||
patches: [
|
||||
{
|
||||
find: "Dispatch.dispatch(...) called without an action type",
|
||||
replacement: {
|
||||
match: /}_dispatch\((\i),\i\){/,
|
||||
replace: "$&$1=$self.modify($1);"
|
||||
}
|
||||
},
|
||||
{
|
||||
find: "Messages.UNREADS_TAB_LABEL}",
|
||||
replacement: {
|
||||
|
@ -355,6 +353,17 @@ export default definePlugin({
|
|||
(await DataStore.get(KEYWORD_LOG_KEY) ?? []).map(e => 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({
|
|||
<MenuHeader tab={8} setTab={setTab} closePopout={closePopout} badgeState={{ badgeForYou: false }} children={
|
||||
<Tooltip text="Clear All">
|
||||
{({ onMouseLeave, onMouseEnter }) => (
|
||||
<Button
|
||||
<div className={classes(tabClass.controlButton, buttonClass.button, buttonClass.tertiary, buttonClass.size32)}
|
||||
onMouseLeave={onMouseLeave}
|
||||
onMouseEnter={onMouseEnter}
|
||||
look={Button.Looks.BLANK}
|
||||
size={Button.Sizes.ICON}
|
||||
onClick={() => {
|
||||
keywordLog = [];
|
||||
DataStore.set(KEYWORD_LOG_KEY, []);
|
||||
this.onUpdate();
|
||||
}}>
|
||||
<div className={classes(buttonClass.button, buttonClass.secondary, buttonClass.size32)}>
|
||||
<DoubleCheckmarkIcon />
|
||||
</div>
|
||||
</Button>
|
||||
<DoubleCheckmarkIcon />
|
||||
</div>
|
||||
)}
|
||||
</Tooltip>
|
||||
} />
|
||||
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
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 {
|
||||
_actionHandlers: any;
|
||||
_interceptors: any;
|
||||
_subscriptions: any;
|
||||
addInterceptor(interceptor: any): void;
|
||||
dispatch(event: { [key: string]: unknown; type: FluxEvents; }): Promise<void>;
|
||||
isDispatching(): boolean;
|
||||
subscribe(event: FluxEvents, callback: (data: any) => void): void;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue