Skip to content

Commit

Permalink
设置主人优化读写
Browse files Browse the repository at this point in the history
Signed-off-by: Admilk <[email protected]>
  • Loading branch information
Admilk authored and TimeRainStarSky committed Sep 15, 2024
1 parent c68b2ee commit b51f702
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions plugins/system/master.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b51f702

Please sign in to comment.