🐛 权限

This commit is contained in:
🌌
2024-04-15 22:16:25 +08:00
parent d8176c0da4
commit 54b4b409ce
4 changed files with 31 additions and 21 deletions

View File

@@ -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")

View File

@@ -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

View File

@@ -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事件对象

View File

@@ -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"