Skip to content

Commit

Permalink
细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeRainStarSky committed Aug 2, 2024
1 parent d4ab2e2 commit f57f56c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
7 changes: 5 additions & 2 deletions lib/plugins/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,15 @@ class PluginsLoader {
async loadPlugin(file, p) {
if (!p?.prototype) return
this.pluginCount++
const plugin = new p
/** 初始化、定时任务实例 */
let plugin = new p
Bot.makeLog("debug", `加载插件 [${file.name}][${plugin.name}]`, "Plugin")
/** 执行初始化,返回 return 则跳过加载 */
if (plugin.init && await plugin.init() === "return") return
/** 初始化定时任务 */
/** 设置定时任务 */
this.collectTask(plugin.task, plugin.name)
/** 处理消息实例 */
plugin = new p
/** 初始化正则表达式 */
if (plugin.rule) for (const i of plugin.rule)
if (!(i.reg instanceof RegExp))
Expand Down
18 changes: 8 additions & 10 deletions lib/plugins/stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import path from "node:path"
import { spawn } from "node:child_process"

Bot.adapter.push(new class stdinAdapter {
constructor() {
this.id = "stdin"
this.name = "标准输入"
this.path = "data/stdin/"
this.catimg = file => new Promise(resolve =>
spawn("catimg", ["-l0", file], { stdio: "inherit" })
.on("error", () => this.catimg = () => {})
.on("close", resolve)
)
}
id = "stdin"
name = "标准输入"
path = "data/stdin/"
catimg = file => new Promise(resolve =>
spawn("catimg", ["-l0", file], { stdio: "inherit" })
.on("error", () => this.catimg = () => {})
.on("close", resolve)
)

async sendMsg(msg) {
if (!Array.isArray(msg))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"chalk": "^5.3.0",
"chokidar": "^3.6.0",
"express": "^4.19.2",
"file-type": "^19.3.0",
"file-type": "^19.4.0",
"https-proxy-agent": "7.0.5",
"image-size": "^1.1.1",
"level": "^8.0.1",
Expand Down
14 changes: 6 additions & 8 deletions plugins/other/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,29 @@ export class update extends plugin {
}

init() {
const p = new update
p.e = {
this.e = {
isMaster: true,
logFnc: "[自动更新]",
msg: "#全部静更新",
reply: msg => Bot.sendMasterMsg(msg),
}
if (cfg.bot.update_time)
p.autoUpdate()
this.autoUpdate()

this.task = []
if (cfg.bot.update_cron)
for (const i of Array.isArray(cfg.bot.update_cron) ? cfg.bot.update_cron : [cfg.bot.update_cron])
this.task.push({
name: "定时更新",
cron: i,
fnc: () => p.updateAll(),
fnc: () => this.updateAll(),
})
}

autoUpdate() {
setTimeout(() => {
this.updateAll()
this.autoUpdate()
}, cfg.bot.update_time*60000)
setTimeout(() =>
this.updateAll().finally(this.autoUpdate.bind(this))
, cfg.bot.update_time*60000)
}

async update() {
Expand Down

0 comments on commit f57f56c

Please sign in to comment.