diff --git a/apps/chat.js b/apps/chat.js index 0f3b9ae..bbd4a59 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -1925,6 +1925,7 @@ export class chatgpt extends plugin { if (conversation) { option = Object.assign(option, conversation) } + let isAdmin = e.sender.role === 'admin' || e.sender.role === 'owner' let tools = [ new SearchVideoTool(), new SendVideoTool(), @@ -1934,11 +1935,13 @@ export class chatgpt extends plugin { // new SendDiceTool(), new EditCardTool(), new QueryStarRailTool(), - new WebsiteTool() + new WebsiteTool(), + new JinyanTool(isAdmin, e.sender.user_id), + new KickOutTool(isAdmin, e.sender.user_id) ] - if (e.sender.role === 'admin' || e.sender.role === 'owner') { - tools.push(...[new JinyanTool(), new KickOutTool()]) - } + // if (e.sender.role === 'admin' || e.sender.role === 'owner') { + // tools.push(...[new JinyanTool(), new KickOutTool()]) + // } let funcMap = {} tools.forEach(tool => { funcMap[tool.name] = { diff --git a/utils/tools/JinyanTool.js b/utils/tools/JinyanTool.js index f73cf91..2e62fcb 100644 --- a/utils/tools/JinyanTool.js +++ b/utils/tools/JinyanTool.js @@ -1,6 +1,12 @@ import { AbstractTool } from './AbstractTool.js' export class JinyanTool extends AbstractTool { + constructor (isAdmin, sender) { + super() + this.isAdmin = isAdmin + this.sender = sender + } + name = 'jinyan' parameters = { @@ -21,7 +27,7 @@ export class JinyanTool extends AbstractTool { required: ['qq', 'groupId'] } - func = async function (opts) { + funcAdmin = async function (opts) { let { qq, groupId, time = '600' } = opts let group = await Bot.pickGroup(groupId) time = parseInt(time.trim()) @@ -46,5 +52,30 @@ export class JinyanTool extends AbstractTool { 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) { + qq = parseInt(qq.trim()) + await group.muteMember(qq, time) + } 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` + } + } + + 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 9fd9620..610fe56 100644 --- a/utils/tools/KickOutTool.js +++ b/utils/tools/KickOutTool.js @@ -1,6 +1,12 @@ import { AbstractTool } from './AbstractTool.js' export class KickOutTool extends AbstractTool { + constructor (isAdmin, sender) { + super() + this.isAdmin = isAdmin + this.sender = sender + } + name = 'kickOut' parameters = { @@ -17,7 +23,7 @@ export class KickOutTool extends AbstractTool { required: ['qq', 'groupId'] } - func = async function (opts) { + funcAdmin = async function (opts) { let { qq, groupId } = opts groupId = parseInt(groupId.trim()) qq = parseInt(qq.trim()) @@ -27,5 +33,22 @@ export class KickOutTool extends AbstractTool { 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. ' }