From c51d54335cd337084416e3a95d8a2980dcac3d44 Mon Sep 17 00:00:00 2001 From: yeyang <746659424@qq.com> Date: Fri, 17 Mar 2023 13:50:46 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/groupAdmin.js | 70 +++++++++++++------------------------------- apps/groupVerify.js | 16 ++++------ apps/handle.js | 8 ++--- lib/common/common.js | 30 +++++++++++++++++++ 4 files changed, 59 insertions(+), 65 deletions(-) diff --git a/apps/groupAdmin.js b/apps/groupAdmin.js index 7cac79a..81a0976 100644 --- a/apps/groupAdmin.js +++ b/apps/groupAdmin.js @@ -151,39 +151,9 @@ export class GroupAdmin extends plugin { this.task = redisTask } - /** - * @description: 判断权限 - * @param {*} e - * @param {'master'|'admin'|'owner'|'all'} permission 权限 - * @param {'admin'|'owner'|'all'} role 需要的权限 - * @return {Boolean} - */ - Authentication (e, permission, role) { - if (role == 'owner' && !e.group.is_owner) { - e.reply('我连群主都木有,这种事怎么可能做到的辣!!!', true) - return false - } else if (role == 'admin' && !e.group.is_admin && !e.group.is_owner) { - e.reply('我连管理员都木有,这种事怎么可能做到的辣!!!', true) - return false - } - // 判断权限 - if (e.isMaster) return true - if (permission == 'master' && !e.isMaster) { - e.reply('❎ 该命令仅限主人可用', true) - return false - } else if (permission == 'owner' && !e.member.is_owner) { - e.reply('❎ 该命令仅限群主可用', true) - return false - } else if (permission == 'admin' && !e.member.is_admin && !e.member.is_owner) { - e.reply('❎ 该命令仅限管理可用') - return false - } - return true - } - /** 禁言 */ async muteMember (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let qq = e.message.find(item => item.type == 'at')?.qq let reg = `#禁言\\s?((\\d+)\\s)?(${Numreg})?(${TimeUnitReg})?` let regRet = e.msg.match(new RegExp(reg)) @@ -198,7 +168,7 @@ export class GroupAdmin extends plugin { /** 解禁 */ async noMuteMember (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let qq = e.message.find(item => item.type == 'at')?.qq let regRet = e.msg.match(/#解禁(\d+)/) @@ -211,7 +181,7 @@ export class GroupAdmin extends plugin { /** 全体禁言 */ async muteAll (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let type = /全体禁言/.test(e.msg) let res = await e.group.muteAll(type) @@ -221,7 +191,7 @@ export class GroupAdmin extends plugin { // 踢群员 async kickMember (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let qq = e.message.find(item => item.type == 'at')?.qq if (!qq) qq = e.msg.replace(/#|踢/g, '').trim() @@ -249,7 +219,7 @@ export class GroupAdmin extends plugin { // 设置管理 async SetAdmin (e) { - if (!this.Authentication(e, 'master', 'owner')) return + if (!common.Authentication(e, 'master', 'owner')) return let qq = e.message.find(item => item.type == 'at')?.qq let type = /设置管理/.test(e.msg) if (!qq) qq = e.msg.replace(/#|(设置|取消)管理/g, '').trim() @@ -267,7 +237,7 @@ export class GroupAdmin extends plugin { // 匿名 async AllowAnony (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let type = /(允许|开启)匿名/.test(e.msg) let res = await e.group.allowAnony(type) @@ -277,7 +247,7 @@ export class GroupAdmin extends plugin { // 发群公告 async AddAnnounce (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return // 获取发送的内容 let msg = e.msg.replace(/#|发群公告/g, '').trim() if (!msg) return e.reply('❎ 公告不能为空') @@ -299,7 +269,7 @@ export class GroupAdmin extends plugin { // 删群公告 async DelAnnounce (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let msg = e.msg.replace(/#|删群公告/, '').trim() if (!msg) return e.reply('❎ 序号不可为空') @@ -315,7 +285,7 @@ export class GroupAdmin extends plugin { // 修改头衔 async adminsetTitle (e) { - if (!this.Authentication(e, 'master', 'owner')) return + if (!common.Authentication(e, 'master', 'owner')) return let qq = e.message.find(item => item.type == 'at')?.qq if (qq) return e.reply('请艾特要修改的人哦~') @@ -330,7 +300,7 @@ export class GroupAdmin extends plugin { // 申请头衔 async SetGroupSpecialTitle (e) { - if (!this.Authentication(e, 'all', 'owner')) return + if (!common.Authentication(e, 'all', 'owner')) return let Title = e.msg.replace(/#|申请头衔/g, '') // 屏蔽词处理 @@ -384,7 +354,7 @@ export class GroupAdmin extends plugin { // 替换幸运字符 async qun_luckyuse (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let id = e.msg.replace(/#|替换(幸运)?字符/g, '') let res = await QQApi.equipLucky(e.group_id, id) @@ -395,7 +365,7 @@ export class GroupAdmin extends plugin { // 开启或关闭群字符 async qun_luckyset (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let res = await QQApi.swichLucky(e.group_id, /开启/.test(e.msg)) if (!res) return e.reply(API_ERROR) @@ -414,14 +384,14 @@ export class GroupAdmin extends plugin { // 解除全部禁言 async relieveAllMute (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let res = await ga.releaseAllMute(e.group_id) e.reply(res ? '已经把全部的禁言解除辣╮( •́ω•̀ )╭' : '都没有人被禁言我怎么解的辣\(`Δ’)/') } // 查看和清理多久没发言的人 async noactive (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let regRet = noactivereg.exec(e.msg) regRet[2] = common.translateChinaNum(regRet[2] || 1) @@ -455,7 +425,7 @@ export class GroupAdmin extends plugin { // 查看和清理从未发言的人 async neverspeak (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let list = await ga.getNeverSpeak(e.group_id) if (!list) return e.reply('咋群全是好淫哦~全都发过言辣٩(๑•̀ω•́๑)۶') // 确认清理直接执行 @@ -494,7 +464,7 @@ export class GroupAdmin extends plugin { // 发送通知 async Send_notice (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return e.message[0].text = e.message[0].text.replace('#发通知', '').trim() if (!e.message[0].text) e.message.shift() @@ -505,7 +475,7 @@ export class GroupAdmin extends plugin { // 设置定时群禁言 async timeMute (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let type = /禁言/.test(e.msg) if (/任务/.test(e.msg)) { let task = ga.getMuteTask() @@ -580,7 +550,7 @@ export class GroupAdmin extends plugin { // 群发言榜单 async SpeakRank (e) { - if (!this.Authentication(e, 'all', 'admin')) return + if (!common.Authentication(e, 'all', 'admin')) return // 图片截图 let screenshot = await puppeteer.Webpage({ @@ -647,7 +617,7 @@ export class GroupAdmin extends plugin { // 群数据 async groupData (e) { - if (!this.Authentication(e, 'all', 'admin')) return + if (!common.Authentication(e, 'all', 'admin')) return // 浏览器截图 let screenshot = await puppeteer.Webpage({ @@ -692,7 +662,7 @@ export class GroupAdmin extends plugin { /** 开启或关闭加群通知 */ async handleGroupAdd (e) { - if (!this.Authentication(e, 'admin', 'admin')) return + if (!common.Authentication(e, 'admin', 'admin')) return let type = /开启/.test(e.msg) ? 'add' : 'del' let isopen = Config.groupAdd.openGroup.includes(e.group_id) if (isopen && type == 'add') return e.reply('❎ 本群加群申请通知已处于开启状态') diff --git a/apps/groupVerify.js b/apps/groupVerify.js index 2d573ff..9055338 100644 --- a/apps/groupVerify.js +++ b/apps/groupVerify.js @@ -6,7 +6,6 @@ import _ from 'lodash' // 全局 let temp = {} const ops = ['+', '-'] -const ROLE_ERROR = '我连管理员都木有,这种事怎么可能做到的辣!!!' export class NewGroupVerify extends plugin { constructor () { super({ @@ -42,12 +41,10 @@ export class NewGroupVerify extends plugin { // 重新验证 async cmdReverify (e) { - if (!e.group.is_admin && !e.group.is_owner) return e.reply(ROLE_ERROR, true) + if (!common.Authentication(e, 'admin', 'admin')) return if (!this.verifycfg.openGroup.includes(e.group_id)) return e.reply('当前群未开启验证哦~', true) - if (!e.isMaster && !e.member.is_owner && !e.member.is_admin) return e.reply('❎ 该命令仅限管理员可用', true) - let qq = e.message.find(item => item.type == 'at')?.qq if (!qq) qq = e.msg.replace(/#|重新验证/g, '').trim() @@ -66,12 +63,10 @@ export class NewGroupVerify extends plugin { // 绕过验证 async cmdPass (e) { - if (!e.group.is_admin && !e.group.is_owner) return e.reply(ROLE_ERROR, true) + if (!common.Authentication(e, 'admin', 'admin')) return if (!this.verifycfg.openGroup.includes(e.group_id)) return e.reply('当前群未开启验证哦~', true) - if (!e.isMaster && !e.member.is_owner && !e.member.is_admin) return e.reply('❎ 该命令仅限管理员可用', true) - let qq = e.message.find(item => item.type == 'at')?.qq if (!qq) qq = e.msg.replace(/#|绕过验证/g, '').trim() @@ -101,8 +96,7 @@ export class NewGroupVerify extends plugin { // 开启验证 async handelverify (e) { - if (!e.isMaster && !e.member.is_owner && !e.member.is_admin) return e.reply('❎ 该命令仅限管理员可用', true) - if (!e.group.is_admin && !e.group.is_owner) return e.reply(ROLE_ERROR, true) + if (!common.Authentication(e, 'admin', 'admin')) return let type = /开启/.test(e.msg) ? 'add' : 'del' let isopen = this.verifycfg.openGroup.includes(e.group_id) if (isopen && type == 'add') return e.reply('❎ 本群验证已处于开启状态') @@ -113,7 +107,7 @@ export class NewGroupVerify extends plugin { // 切换验证模式 async setmode (e) { - if (!e.isMaster) return e.reply('❎ 该命令仅限主人可用', true) + if (!common.Authentication(e, 'master')) return let value = this.verifycfg.mode == '模糊' ? '精确' : '模糊' Config.modify('groupverify', 'mode', value) e.reply(`✅ 已切换验证模式为${value}验证`) @@ -121,7 +115,7 @@ export class NewGroupVerify extends plugin { // 设置验证超时时间 async setovertime (e) { - if (!e.isMaster) return e.reply('❎ 该命令仅限主人可用', true) + if (!common.Authentication(e, 'master')) return let overtime = e.msg.match(/\d+/g) Config.modify('groupverify', 'time', Number(overtime)) e.reply(`✅ 已将验证超时时间设置为${overtime}秒`) diff --git a/apps/handle.js b/apps/handle.js index d5f9846..945725a 100644 --- a/apps/handle.js +++ b/apps/handle.js @@ -130,12 +130,14 @@ export class NewHandle extends plugin { let sourceMsg = source.raw_message?.split('\n') if (!sourceMsg) return e.reply('❎ 获取原消息失败,请使用"同意xxx"进行处理') if (e.isGroup) { - if (!e.member.is_admin && !e.member.is_owner && !e.isMaster) return e.reply('你是坏人!') + if (!common.Authentication(e, 'admin', 'admin')) return + let source = (await e.group.getChatHistory(e.source.seq, 1)).pop() let yes = /同意/.test(e.msg) logger.mark(`${e.logFnc}${yes ? '同意' : '拒绝'}加群通知`) let userId = await redis.get(`yenai:groupAdd:${source.message_id}`) if (!userId) return e.reply('找不到原消息了,手动同意叭~') + let member = (await Bot.getSystemMsg()) .find(item => item.request_type == 'group' && item.sub_type == 'add' && item.group_id == e.group_id && item.user_id == userId) @@ -289,9 +291,7 @@ export class NewHandle extends plugin { ] return common.getforwardMsg(e, msg) } - if (!e.isMaster && !e.member.is_owner && !e.member.is_admin) { - return e.reply('❎ 该命令仅限管理员可用', true) - } + if (!common.Authentication(e, 'admin', 'admin')) return let yes = /同意/.test(e.msg) if (/全部/.test(e.msg)) { diff --git a/lib/common/common.js b/lib/common/common.js index fa23c58..9ebf513 100644 --- a/lib/common/common.js +++ b/lib/common/common.js @@ -13,6 +13,36 @@ export default new class newCommon { return new Promise((resolve) => setTimeout(resolve, ms)) } + /** + * @description: 判断权限 + * @param {*} e + * @param {'master'|'admin'|'owner'|'all'} permission 权限 + * @param {'admin'|'owner'|'all'} role 需要的权限 + * @return {Boolean} + */ + Authentication (e, permission = 'all', role = 'all') { + if (role == 'owner' && !e.group.is_owner) { + e.reply('我连群主都木有,这种事怎么可能做到的辣!!!', true) + return false + } else if (role == 'admin' && !e.group.is_admin && !e.group.is_owner) { + e.reply('我连管理员都木有,这种事怎么可能做到的辣!!!', true) + return false + } + // 判断权限 + if (e.isMaster) return true + if (permission == 'master' && !e.isMaster) { + e.reply('❎ 该命令仅限主人可用', true) + return false + } else if (permission == 'owner' && !e.member.is_owner) { + e.reply('❎ 该命令仅限群主可用', true) + return false + } else if (permission == 'admin' && !e.member.is_admin && !e.member.is_owner) { + e.reply('❎ 该命令仅限管理可用') + return false + } + return true + } + /** 发消息 */ async sendMasterMsg (msg) { if (Config.Notice.notificationsAll) {