fix: 修复管理员权限判断问题(可能吧)

This commit is contained in:
ikechan8370 2023-06-23 18:40:37 +08:00
parent ef72d886a5
commit 2e679b5d0f
3 changed files with 17 additions and 61 deletions

View file

@ -1926,6 +1926,7 @@ export class chatgpt extends plugin {
option = Object.assign(option, conversation) option = Object.assign(option, conversation)
} }
let isAdmin = e.sender.role === 'admin' || e.sender.role === 'owner' let isAdmin = e.sender.role === 'admin' || e.sender.role === 'owner'
let sender = e.sender.user_id
let tools = [ let tools = [
new SearchVideoTool(), new SearchVideoTool(),
new SendVideoTool(), new SendVideoTool(),
@ -1936,8 +1937,8 @@ export class chatgpt extends plugin {
new EditCardTool(), new EditCardTool(),
new QueryStarRailTool(), new QueryStarRailTool(),
new WebsiteTool(), new WebsiteTool(),
new JinyanTool(isAdmin, e.sender.user_id), new JinyanTool(),
new KickOutTool(isAdmin, e.sender.user_id) new KickOutTool()
] ]
// if (e.sender.role === 'admin' || e.sender.role === 'owner') { // if (e.sender.role === 'admin' || e.sender.role === 'owner') {
// tools.push(...[new JinyanTool(), new KickOutTool()]) // tools.push(...[new JinyanTool(), new KickOutTool()])
@ -1959,7 +1960,7 @@ export class chatgpt extends plugin {
logger.info(msg) logger.info(msg)
while (msg.functionCall) { while (msg.functionCall) {
let { name, arguments: args } = 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}`) logger.mark(`function ${name} execution result: ${functionResult}`)
option.parentMessageId = msg.id option.parentMessageId = msg.id
option.name = name option.name = name

View file

@ -1,12 +1,6 @@
import { AbstractTool } from './AbstractTool.js' import { AbstractTool } from './AbstractTool.js'
export class JinyanTool extends AbstractTool { export class JinyanTool extends AbstractTool {
constructor (isAdmin, sender) {
super()
this.isAdmin = isAdmin
this.sender = sender
}
name = 'jinyan' name = 'jinyan'
parameters = { parameters = {
@ -27,8 +21,8 @@ export class JinyanTool extends AbstractTool {
required: ['qq', 'groupId'] required: ['qq', 'groupId']
} }
funcAdmin = async function (opts) { func = async function (opts) {
let { qq, groupId, time = '600' } = opts let { qq, groupId, time = '600', sender, isAdmin } = opts
let group = await Bot.pickGroup(groupId) let group = await Bot.pickGroup(groupId)
time = parseInt(time.trim()) time = parseInt(time.trim())
if (time < 60) { if (time < 60) {
@ -37,32 +31,14 @@ export class JinyanTool extends AbstractTool {
if (time > 86400 * 30) { if (time > 86400 * 30) {
time = 86400 * 30 time = 86400 * 30
} }
if (qq.trim() === 'all') { if (isAdmin) {
if (time > 0) { if (qq.trim() === 'all') {
await group.sendMsg('[日志]试图开启全员禁言,但被系统阻止了') return 'you cannot mute all because the master doesn\'t allow it'
return 'error: you are not allowed to mute all in this group'
} else { } else {
await group.muteAll(false) qq = parseInt(qq.trim())
return '该群的全体禁言已经被解除' await group.muteMember(qq, time)
} }
} else { } 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') { if (qq.trim() === 'all') {
return 'the user is not admin, he can\'t mute all. the user should be punished' return 'the user is not admin, he can\'t mute all. the user should be punished'
} else if (qq == sender) { } else if (qq == sender) {
@ -71,11 +47,9 @@ export class JinyanTool extends AbstractTool {
} else { } else {
return 'the user is not admin, he can\'t mute other people. the user should be punished' 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\'' description = 'Useful when you want to ban someone. If you want to mute all, just replace the qq number with \'all\''
} }

View file

@ -1,11 +1,6 @@
import { AbstractTool } from './AbstractTool.js' import { AbstractTool } from './AbstractTool.js'
export class KickOutTool extends AbstractTool { export class KickOutTool extends AbstractTool {
constructor (isAdmin, sender) {
super()
this.isAdmin = isAdmin
this.sender = sender
}
name = 'kickOut' name = 'kickOut'
@ -23,32 +18,18 @@ export class KickOutTool extends AbstractTool {
required: ['qq', 'groupId'] required: ['qq', 'groupId']
} }
funcAdmin = async function (opts) { func = async function (opts) {
let { qq, groupId } = opts let { qq, groupId, sender, isAdmin } = opts
groupId = parseInt(groupId.trim()) groupId = parseInt(groupId.trim())
qq = parseInt(qq.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) console.log('kickout', groupId, qq)
let group = await Bot.pickGroup(groupId) let group = await Bot.pickGroup(groupId)
await group.kickMember(qq) await group.kickMember(qq)
return `the user ${qq} has been kicked out from group ${groupId}` 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. ' description = 'Useful when you want to kick someone out of the group. '
} }