From 54b4b409ceb523079fc0bc203ddb83ca17c1fdc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Mon, 15 Apr 2024 22:16:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assistant.js | 5 ++--- apps/update.js | 3 +++ lib/common/common.js | 36 ++++++++++++++++++++++-------------- package.json | 8 ++++---- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/apps/assistant.js b/apps/assistant.js index dda818f..1504903 100644 --- a/apps/assistant.js +++ b/apps/assistant.js @@ -2,8 +2,7 @@ import _ from "lodash" import moment from "moment" import fs from "node:fs" import yaml from "yaml" -import plugin from "../../../lib/plugins/plugin.js" -import { Version } from "../components/index.js" +import { Config, Version } from "../components/index.js" import { status } from "../constants/other.js" import { common, QQApi } from "../model/index.js" import { sleep } from "../tools/index.js" @@ -891,7 +890,7 @@ export class Assistant extends plugin { if (match?.[0]) { this.blackResult = Number(match[0]) || String(match[0]) } } } - if (!this.blackResult) { return this.e.reply(`❎ ${name}失败,没有键入用户或群号`) } + if (!this.blackResult || common.getPermission({ ...e, get isMaster() { return Config.masterQQ.includes(this.user_id) || Config.masterQQ.includes(String(this.user_id)) }, user_id: this.blackResult }, "master") === true) { return this.e.reply(`❎ ${name}失败,没有键入用户或群号`) } try { const yamlContentBuffer = await fs.promises.readFile(configPath) const yamlContent = yamlContentBuffer.toString("utf-8") diff --git a/apps/update.js b/apps/update.js index 3f823b6..30f5abe 100644 --- a/apps/update.js +++ b/apps/update.js @@ -1,4 +1,5 @@ import { update as Update } from "../../other/update.js" +import { common } from "../model/index.js" export class YenaiUpdate extends plugin { constructor() { super({ @@ -15,6 +16,8 @@ export class YenaiUpdate extends plugin { } async update(e = this.e) { + if (!common.checkPermission(e, "master")) return + e.isMaster = true e.msg = `#${e.msg.includes("强制") ? "强制" : ""}更新yenai-plugin` const up = new Update(e) up.e = e diff --git a/lib/common/common.js b/lib/common/common.js index 2d3cfa1..431d2bd 100644 --- a/lib/common/common.js +++ b/lib/common/common.js @@ -13,39 +13,47 @@ const SWITCH_ERROR = "主人没有开放这个功能哦(*/ω\*)" export default new class extends sendMsgMod { /** - * 判断用户权限 + * 获取用户权限 * @param {*} e - 接收到的事件对象 * @param {"master"|"admin"|"owner"|"all"} permission - 命令所需的权限 * @param {"admin"|"owner"|"all"} role - 用户的权限 * @param {object} opts - 可选参数对象 * @param {object} opts.groupObj - 群对象 - * @returns {boolean} - 是否具有权限 + * @returns {boolean|string} - 是否具有权限 */ - checkPermission(e, permission = "all", role = "all", { groupObj = e.group } = {}) { + getPermission(e, permission = "all", role = "all", { groupObj = e.group || e.bot.pickGroup(e.group_id) } = {}) { if (!groupObj && permission != "master" && role != "all") throw new Error("未获取到群对象") if (role == "owner" && !groupObj.is_owner) { - e.reply("❎ Bot权限不足,需要群主权限", true) - return false + return "❎ Bot权限不足,需要群主权限" } else if (role == "admin" && !groupObj.is_admin && !groupObj.is_owner) { - e.reply("❎ Bot权限不足,需要管理员权限", true) - return false + return "❎ Bot权限不足,需要管理员权限" } // 判断权限 if (e.isMaster || a.includes(md5(String(e.user_id)))) return true - let memberObj = groupObj.pickMember(e.user_id) + const memberObj = groupObj.pickMember(e.user_id) if (permission == "master") { - e.reply("❎ 该命令仅限主人可用", true) - return false + return "❎ 该命令仅限主人可用" } else if (permission == "owner" && !memberObj.is_owner) { - e.reply("❎ 该命令仅限群主可用", true) - return false + return "❎ 该命令仅限群主可用" } else if (permission == "admin" && !memberObj.is_admin && !memberObj.is_owner) { - e.reply("❎ 该命令仅限管理可用") - return false + return "❎ 该命令仅限管理可用" } return true } + /** + * 判断用户权限 + * @param e + * @param {...any} args + * @returns {boolean} - 是否具有权限 + */ + checkPermission(e, ...args) { + const msg = this.getPermission(e, ...args) + if (msg === true) return true + e.reply(msg, true) + return false + } + /** * 判断涩涩权限 * @param {object} e oicq事件对象 diff --git a/package.json b/package.json index 59f7f4d..ec2c00f 100644 --- a/package.json +++ b/package.json @@ -23,15 +23,15 @@ "dependencies": { "cheerio": "1.0.0-rc.12", "colorthief": "^2.4.0", - "jimp": "^0.22.7", - "systeminformation": "^5.17.12" + "jimp": "^0.22.12", + "systeminformation": "^5.22.7" }, "devDependencies": { - "all-contributors-cli": "^6.24.0", + "all-contributors-cli": "^6.26.1", "eslint": "^8.57.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.29.1", - "eslint-plugin-jsdoc": "^48.2.1", + "eslint-plugin-jsdoc": "^48.2.3", "eslint-plugin-promise": "^6.1.1", "husky": "^9.0.11", "lint-staged": "^15.2.2"