From b51f70297ed14af2c8a30d8ccadfe8c3615700de Mon Sep 17 00:00:00 2001 From: Admilk Date: Sun, 15 Sep 2024 12:33:32 +0000 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BB=E4=BA=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=AF=BB=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Admilk --- plugins/system/master.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/system/master.js b/plugins/system/master.js index 7ea809f0..d5e46046 100644 --- a/plugins/system/master.js +++ b/plugins/system/master.js @@ -1,5 +1,6 @@ import fs from "node:fs/promises" import { ulid } from "ulid" +import YAML from "yaml" const code = {} const file = "config/config/other.yaml" export class master extends plugin { @@ -31,16 +32,15 @@ export class master extends plugin { } async edit(file, key, value) { - let data = await fs.readFile(file, "utf8") - if (data.match(RegExp(`- "?${value}"?`))) - return - value = `${key}:\n - "${value}"` - if (data.match(RegExp(`${key}:`))) - data = data.replace(RegExp(`${key}:`), value) - else - data = `${data}\n${value}` - return fs.writeFile(file, data, "utf8") - } + const doc = YAML.parseDocument(await fs.readFile(file, "utf8")) + const values = doc.get(key) + if (values) { + if (values.items.some(item => item.value == value)) + return + values.add(value) + } else doc.set(key, [value]) + return fs.writeFile(file, doc.toString(), "utf8") +} master() { if (this.e.isMaster)