From 2e679b5d0ffd419c8779ca146a67eb8c68230af4 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 23 Jun 2023 18:40:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E6=9D=83=E9=99=90=E5=88=A4=E6=96=AD=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=88=E5=8F=AF=E8=83=BD=E5=90=A7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 7 ++++--- utils/tools/JinyanTool.js | 42 ++++++++------------------------------ utils/tools/KickOutTool.js | 29 +++++--------------------- 3 files changed, 17 insertions(+), 61 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index bbd4a59..cb0ee43 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -1926,6 +1926,7 @@ export class chatgpt extends plugin { option = Object.assign(option, conversation) } let isAdmin = e.sender.role === 'admin' || e.sender.role === 'owner' + let sender = e.sender.user_id let tools = [ new SearchVideoTool(), new SendVideoTool(), @@ -1936,8 +1937,8 @@ export class chatgpt extends plugin { new EditCardTool(), new QueryStarRailTool(), new WebsiteTool(), - new JinyanTool(isAdmin, e.sender.user_id), - new KickOutTool(isAdmin, e.sender.user_id) + new JinyanTool(), + new KickOutTool() ] // if (e.sender.role === 'admin' || e.sender.role === 'owner') { // tools.push(...[new JinyanTool(), new KickOutTool()]) @@ -1959,7 +1960,7 @@ export class chatgpt extends plugin { logger.info(msg) while (msg.functionCall) { let { name, arguments: args } = msg.functionCall - let functionResult = await funcMap[name].exec(JSON.parse(args)) + let functionResult = await funcMap[name].exec(Object.assign({isAdmin, sender}, JSON.parse(args))) logger.mark(`function ${name} execution result: ${functionResult}`) option.parentMessageId = msg.id option.name = name diff --git a/utils/tools/JinyanTool.js b/utils/tools/JinyanTool.js index 2e62fcb..7130284 100644 --- a/utils/tools/JinyanTool.js +++ b/utils/tools/JinyanTool.js @@ -1,12 +1,6 @@ import { AbstractTool } from './AbstractTool.js' export class JinyanTool extends AbstractTool { - constructor (isAdmin, sender) { - super() - this.isAdmin = isAdmin - this.sender = sender - } - name = 'jinyan' parameters = { @@ -27,8 +21,8 @@ export class JinyanTool extends AbstractTool { required: ['qq', 'groupId'] } - funcAdmin = async function (opts) { - let { qq, groupId, time = '600' } = opts + func = async function (opts) { + let { qq, groupId, time = '600', sender, isAdmin } = opts let group = await Bot.pickGroup(groupId) time = parseInt(time.trim()) if (time < 60) { @@ -37,32 +31,14 @@ export class JinyanTool extends AbstractTool { if (time > 86400 * 30) { time = 86400 * 30 } - if (qq.trim() === 'all') { - if (time > 0) { - await group.sendMsg('[日志]试图开启全员禁言,但被系统阻止了') - return 'error: you are not allowed to mute all in this group' + if (isAdmin) { + if (qq.trim() === 'all') { + return 'you cannot mute all because the master doesn\'t allow it' } else { - await group.muteAll(false) - return '该群的全体禁言已经被解除' + qq = parseInt(qq.trim()) + await group.muteMember(qq, time) } } else { - qq = parseInt(qq.trim()) - await group.muteMember(qq, time) - } - return `the user ${qq} has been muted for ${time} seconds` - } - - funcNonAdmin (sender) { - return async function (opts) { - let { qq, groupId, time = '600' } = opts - let group = await Bot.pickGroup(groupId) - time = parseInt(time.trim()) - if (time < 60) { - time = 60 - } - if (time > 86400 * 30) { - time = 86400 * 30 - } if (qq.trim() === 'all') { return 'the user is not admin, he can\'t mute all. the user should be punished' } else if (qq == sender) { @@ -71,11 +47,9 @@ export class JinyanTool extends AbstractTool { } else { return 'the user is not admin, he can\'t mute other people. the user should be punished' } - return `the user ${qq} has been muted for ${time} seconds` } + return `the user ${qq} has been muted for ${time} seconds` } - func = this.isAdmin ? this.funcAdmin : this.funcNonAdmin(this.sender) - description = 'Useful when you want to ban someone. If you want to mute all, just replace the qq number with \'all\'' } diff --git a/utils/tools/KickOutTool.js b/utils/tools/KickOutTool.js index 610fe56..c7c04f0 100644 --- a/utils/tools/KickOutTool.js +++ b/utils/tools/KickOutTool.js @@ -1,11 +1,6 @@ import { AbstractTool } from './AbstractTool.js' export class KickOutTool extends AbstractTool { - constructor (isAdmin, sender) { - super() - this.isAdmin = isAdmin - this.sender = sender - } name = 'kickOut' @@ -23,32 +18,18 @@ export class KickOutTool extends AbstractTool { required: ['qq', 'groupId'] } - funcAdmin = async function (opts) { - let { qq, groupId } = opts + func = async function (opts) { + let { qq, groupId, sender, isAdmin } = opts groupId = parseInt(groupId.trim()) qq = parseInt(qq.trim()) + if (!isAdmin && sender != qq) { + return 'the user is not admin, he cannot kickout other people. he should be punished' + } console.log('kickout', groupId, qq) let group = await Bot.pickGroup(groupId) await group.kickMember(qq) return `the user ${qq} has been kicked out from group ${groupId}` } - funcNonAdmin (sender) { - return async function (opts) { - let { qq, groupId } = opts - groupId = parseInt(groupId.trim()) - qq = parseInt(qq.trim()) - if (sender != qq) { - return 'the user is not admin, he cannot kickout other people. he should be punished' - } - console.log('kickout', groupId, qq) - let group = await Bot.pickGroup(groupId) - await group.kickMember(qq) - return `the user ${qq} has been kicked out from group ${groupId}` - } - } - - func = this.isAdmin ? this.funcAdmin : this.funcNonAdmin(this.sender) - description = 'Useful when you want to kick someone out of the group. ' }