mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-11 02:16:23 +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 { Devs } from "@utils/constants";
|
||||
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 "./style.css";
|
||||
|
||||
let regexes = [];
|
||||
let me = null;
|
||||
|
||||
async function setRegexes(idx: number, reg: string) {
|
||||
regexes[idx] = reg;
|
||||
|
@ -90,19 +91,35 @@ export default definePlugin({
|
|||
authors: [Devs.camila314],
|
||||
description: "Sends a notification if a given message matches certain keywords or regexes",
|
||||
settings,
|
||||
patches: [{
|
||||
find: "isRawMessageMentioned:",
|
||||
replacement: {
|
||||
match: /isRawMessageMentioned:function\(\){return (.{1,2}).{1,512}function \1\(.{1,512}?=(.{1,2});return/,
|
||||
replace: "$& $self.contains($2) ||"
|
||||
}
|
||||
}],
|
||||
patches: [
|
||||
{
|
||||
find: "}_dispatch(",
|
||||
replacement: {
|
||||
match: /}_dispatch\((.{1,2}),.{1,2}\){/,
|
||||
replace: "$&$1=$self.modify($1);"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
async start() {
|
||||
regexes = await DataStore.get("KeywordNotify_rules") ?? [];
|
||||
me = await UserUtils.getUser(UserStore.getCurrentUser().id);
|
||||
},
|
||||
|
||||
contains(e) {
|
||||
return regexes.some(a => a != "" && e.rawMessage.content.match(new RegExp(a)));
|
||||
applyRegexes(m) {
|
||||
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