mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-11 10:26:21 +00:00
KeywordNotify now highlights messages
This commit is contained in:
parent
99036977bb
commit
c0fb89496f
1 changed files with 27 additions and 10 deletions
|
@ -10,11 +10,12 @@ import { definePluginSettings } from "@api/Settings";
|
||||||
import { DeleteIcon } from "@components/Icons";
|
import { DeleteIcon } from "@components/Icons";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { Flex } from "@components/Flex";
|
import { Flex } from "@components/Flex";
|
||||||
import { TextInput, useState, Forms, Button } from "@webpack/common";
|
import { TextInput, useState, Forms, Button, UserStore, UserUtils } from "@webpack/common";
|
||||||
import { useForceUpdater } from "@utils/react";
|
import { useForceUpdater } from "@utils/react";
|
||||||
import "./style.css";
|
import "./style.css";
|
||||||
|
|
||||||
let regexes = [];
|
let regexes = [];
|
||||||
|
let me = null;
|
||||||
|
|
||||||
async function setRegexes(idx: number, reg: string) {
|
async function setRegexes(idx: number, reg: string) {
|
||||||
regexes[idx] = reg;
|
regexes[idx] = reg;
|
||||||
|
@ -90,19 +91,35 @@ export default definePlugin({
|
||||||
authors: [Devs.camila314],
|
authors: [Devs.camila314],
|
||||||
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: "isRawMessageMentioned:",
|
{
|
||||||
|
find: "}_dispatch(",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /isRawMessageMentioned:function\(\){return (.{1,2}).{1,512}function \1\(.{1,512}?=(.{1,2});return/,
|
match: /}_dispatch\((.{1,2}),.{1,2}\){/,
|
||||||
replace: "$& $self.contains($2) ||"
|
replace: "$&$1=$self.modify($1);"
|
||||||
}
|
}
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
regexes = await DataStore.get("KeywordNotify_rules") ?? [];
|
regexes = await DataStore.get("KeywordNotify_rules") ?? [];
|
||||||
|
me = await UserUtils.getUser(UserStore.getCurrentUser().id);
|
||||||
},
|
},
|
||||||
|
|
||||||
contains(e) {
|
applyRegexes(m) {
|
||||||
return regexes.some(a => a != "" && e.rawMessage.content.match(new RegExp(a)));
|
if (regexes.some(r => m.content.match(new RegExp(r)))) {
|
||||||
|
m.mentions.push(me);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
modify(e) {
|
||||||
|
if (e.type == "MESSAGE_CREATE") {
|
||||||
|
this.applyRegexes(e.message);
|
||||||
|
} else if (e.type == "LOAD_MESSAGES_SUCCESS") {
|
||||||
|
for (let msg = 0; msg < e.messages.length; ++msg) {
|
||||||
|
this.applyRegexes(e.messages[msg]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return e;
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in a new issue