chatgpt-plugin/utils/tools/SetTitleTool.js
2023-10-14 13:07:01 +08:00

47 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { AbstractTool } from './AbstractTool.js'
export class SetTitleTool extends AbstractTool {
name = 'setTitle'
parameters = {
properties: {
qq: {
type: 'string',
description: '你想给予群头衔的那个人的qq号默认为聊天对象'
},
title: {
type: 'string',
description: '群头衔'
},
groupId: {
type: 'string',
description: 'group number'
}
},
required: ['title', 'groupId']
}
description = 'Useful when you want to give someone a title in the group(群头衔)'
func = async function (opts, e) {
let { qq, title, groupId } = opts
qq = isNaN(qq) || !qq ? e.sender.user_id : parseInt(qq.trim())
groupId = isNaN(groupId) || !groupId ? e.group_id : parseInt(groupId.trim())
let group = await e.bot.pickGroup(groupId)
let mm = await group.getMemberMap()
if (!mm.has(qq)) {
return `failed, the user ${qq} is not in group ${groupId}`
}
if (mm.get(e.bot.uin).role !== 'owner') {
return 'on group owner can give title'
}
logger.info('edit card: ', groupId, qq)
let result = await group.setTitle(qq, title)
if (result) {
return `the user ${qq}'s title has been changed into ${title}`
} else {
return 'failed'
}
}
}