feat: give title

This commit is contained in:
ikechan8370 2023-07-03 01:19:11 +08:00
parent 8a531bf551
commit 9be8b54faf
3 changed files with 62 additions and 10 deletions

View file

@ -65,6 +65,7 @@ import { SendMusicTool } from '../utils/tools/SendMusicTool.js'
import { SendDiceTool } from '../utils/tools/SendDiceTool.js'
import { SendAvatarTool } from '../utils/tools/SendAvatarTool.js'
import { SendMessageToSpecificGroupOrUserTool } from '../utils/tools/SendMessageToSpecificGroupOrUserTool.js'
import {SetTitleTool} from "../utils/tools/SetTitleTool.js";
try {
await import('emoji-strip')
@ -1511,6 +1512,7 @@ export class chatgpt extends plugin {
let abtrs = await getAvailableBingToken(conversation, throttledTokens)
if (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom') {
bingToken = abtrs.bingToken
// eslint-disable-next-line no-unused-vars
allThrottled = abtrs.allThrottled
if (bingToken?.indexOf('=') > -1) {
cookies = bingToken
@ -1828,7 +1830,7 @@ export class chatgpt extends plugin {
admin: 'group administrator'
}
if (chats) {
system += `There is the conversation history in the group, you must chat according to the conversation history context"`
system += 'There is the conversation history in the group, you must chat according to the conversation history context"'
system += chats
.map(chat => {
let sender = chat.sender || {}
@ -1923,7 +1925,8 @@ export class chatgpt extends plugin {
new EliMovieTool(),
new SendMessageToSpecificGroupOrUserTool(),
new SendDiceTool(),
new QueryGenshinTool()
new QueryGenshinTool(),
new SetTitleTool()
]
// todo 3.0再重构tool的插拔和管理
let tools = [
@ -1956,7 +1959,7 @@ export class chatgpt extends plugin {
let botInfo = await Bot.getGroupMemberInfo(e.group_id, Bot.uin, true)
if (botInfo.role !== 'member') {
// 管理员才给这些工具
tools.push(...[new EditCardTool(), new JinyanTool(), new KickOutTool(), new HandleMessageMsgTool()])
tools.push(...[new EditCardTool(), new JinyanTool(), new KickOutTool(), new HandleMessageMsgTool(), new SetTitleTool()])
// 用于撤回和加精的id
if (e.source?.seq) {
let source = (await e.group.getChatHistory(e.source?.seq, 1)).pop()

View file

@ -31,13 +31,15 @@ export class JinyanTool extends AbstractTool {
qq = qq !== 'all'
? isNaN(qq) || !qq ? e.sender.user_id : parseInt(qq.trim())
: 'all'
let group = await Bot.pickGroup(groupId)
let m = await group.getMemberMap()
if (!m.has(qq)) {
return `failed, the user ${qq} is not in group ${groupId}`
}
if (m.get(Bot.uin).role === 'member') {
return `failed, you, not user, don't have permission to edit card in group ${groupId}`
if (qq !== 'all') {
let group = await Bot.pickGroup(groupId)
let m = await group.getMemberMap()
if (!m.has(qq)) {
return `failed, the user ${qq} is not in group ${groupId}`
}
if (m.get(Bot.uin).role === 'member') {
return `failed, you, not user, don't have permission to mute other in group ${groupId}`
}
}
time = parseInt(time.trim())
if (time < 60 && time !== 0) {

View file

@ -0,0 +1,47 @@
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 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(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'
}
}
}