rename variables from old plugin name
This commit is contained in:
parent
a83285a4c7
commit
272cb77f34
1 changed files with 19 additions and 19 deletions
38
index.tsx
38
index.tsx
|
|
@ -37,18 +37,18 @@ interface IRPCNotificationCreate {
|
|||
message: Message;
|
||||
}
|
||||
|
||||
const CLICKER_RULES_KEY = "[Clicker]-rules";
|
||||
const TRIGGER_RULES_KEY = "[soundTrigger]-rules";
|
||||
|
||||
interface ClickerRule {
|
||||
interface TriggerRule {
|
||||
trigger: string;
|
||||
sound: string;
|
||||
}
|
||||
let clickerRules = [
|
||||
let triggerRules = [
|
||||
{
|
||||
sound: "",
|
||||
trigger: "",
|
||||
},
|
||||
] as ClickerRule[];
|
||||
] as TriggerRule[];
|
||||
|
||||
interface InputProps {
|
||||
placeholder: string;
|
||||
|
|
@ -71,31 +71,31 @@ function Input({ placeholder, initalValue, onChange }: InputProps) {
|
|||
|
||||
function RuleInputter({ update }: { update: () => void; }) {
|
||||
async function deleteRule(index: number) {
|
||||
if (index === clickerRules.length - 1) return;
|
||||
clickerRules.splice(index, 1);
|
||||
if (index === triggerRules.length - 1) return;
|
||||
triggerRules.splice(index, 1);
|
||||
|
||||
await DataStore.set(CLICKER_RULES_KEY, clickerRules);
|
||||
await DataStore.set(TRIGGER_RULES_KEY, triggerRules);
|
||||
update();
|
||||
}
|
||||
|
||||
async function modifyRule(
|
||||
newValue: string,
|
||||
index: number,
|
||||
key: keyof ClickerRule
|
||||
key: keyof TriggerRule
|
||||
) {
|
||||
if (index === clickerRules.length - 1) {
|
||||
clickerRules.push({
|
||||
if (index === triggerRules.length - 1) {
|
||||
triggerRules.push({
|
||||
sound: "",
|
||||
trigger: "",
|
||||
});
|
||||
}
|
||||
clickerRules[index][key] = newValue;
|
||||
triggerRules[index][key] = newValue;
|
||||
|
||||
if (clickerRules[index].trigger === "" && clickerRules[index].sound === "" && index !== clickerRules.length - 1) {
|
||||
clickerRules.splice(index, 1);
|
||||
if (triggerRules[index].trigger === "" && triggerRules[index].sound === "" && index !== triggerRules.length - 1) {
|
||||
triggerRules.splice(index, 1);
|
||||
}
|
||||
|
||||
await DataStore.set(CLICKER_RULES_KEY, clickerRules);
|
||||
await DataStore.set(TRIGGER_RULES_KEY, triggerRules);
|
||||
update();
|
||||
}
|
||||
return (
|
||||
|
|
@ -103,7 +103,7 @@ function RuleInputter({ update }: { update: () => void; }) {
|
|||
<Forms.FormDivider />
|
||||
<Forms.FormTitle tag="h4">Rules</Forms.FormTitle>
|
||||
<Flex flexDirection="column" style={{ gap: "0.5em" }}>
|
||||
{clickerRules.map((rule, ind) => {
|
||||
{triggerRules.map((rule, ind) => {
|
||||
return (
|
||||
<React.Fragment key={`${rule.trigger}-${ind}`}>
|
||||
<Flex flexDirection="row" style={{ gap: "0.5em" }}>
|
||||
|
|
@ -132,7 +132,7 @@ function RuleInputter({ update }: { update: () => void; }) {
|
|||
style={{
|
||||
background: "none",
|
||||
color: "var(--status-danger)",
|
||||
...(ind === clickerRules.length - 1
|
||||
...(ind === triggerRules.length - 1
|
||||
? {
|
||||
visibility: "hidden",
|
||||
pointerEvents: "none",
|
||||
|
|
@ -192,7 +192,7 @@ export default definePlugin({
|
|||
],
|
||||
settings,
|
||||
async start() {
|
||||
clickerRules = (await DataStore.get(CLICKER_RULES_KEY)) ?? clickerRules;
|
||||
triggerRules = (await DataStore.get(TRIGGER_RULES_KEY)) ?? triggerRules;
|
||||
},
|
||||
flux: {
|
||||
async RPC_NOTIFICATION_CREATE({ type, message }: IRPCNotificationCreate) {
|
||||
|
|
@ -229,9 +229,9 @@ export default definePlugin({
|
|||
});
|
||||
|
||||
async function handleMessage(message: Message) {
|
||||
let queue = [] as ClickerRule[];
|
||||
let queue = [] as TriggerRule[];
|
||||
|
||||
for (const rule of clickerRules) {
|
||||
for (const rule of triggerRules) {
|
||||
if (!rule.trigger) continue;
|
||||
const regex = new RegExp(rule.trigger, "g");
|
||||
const count = (message.content.match(regex) ?? []).length;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue