fix: 工具调整

This commit is contained in:
ikechan8370 2025-02-16 21:43:23 +08:00
parent 08afc95f06
commit 777279e410
3 changed files with 19 additions and 54 deletions

View file

@ -557,6 +557,7 @@ class Core {
tools.push(new EditCardTool())
tools.push(new JinyanTool())
tools.push(new KickOutTool())
tools.push(new HandleMessageMsgTool())
}
if (e.group.is_owner) {
tools.push(new SetTitleTool())

View file

@ -24,7 +24,7 @@ export class EditCardTool extends AbstractTool {
description = 'Useful when you want to edit someone\'s card in the group(群名片)'
func = async function (opts, e) {
let { qq, card, groupId, isAdmin } = opts
let { qq, card, groupId, sender, isAdmin } = opts
qq = isNaN(qq) || !qq ? e.sender.user_id : parseInt(qq.trim())
groupId = isNaN(groupId) || !groupId ? e.group_id : parseInt(groupId.trim())
@ -41,7 +41,7 @@ export class EditCardTool extends AbstractTool {
logger.error('获取群信息失败,可能使用的底层协议不完善')
}
logger.info('edit card: ', groupId, qq)
if (isAdmin) {
if (isAdmin || sender == qq) {
await group.setCard(qq, card)
} else {
return 'the user is not admin, he can\'t edit card of other people.'

View file

@ -22,65 +22,29 @@ export class QueryStarRailTool extends AbstractTool {
}
func = async function (opts, e) {
let { qq, uid, character } = opts
let { qq, uid = '', character = '' } = opts
qq = isNaN(qq) || !qq ? e.sender.user_id : parseInt(qq.trim())
if (e.at === e.bot.uin) {
e.at = null
}
e.atBot = false
if (!uid) {
try {
let { Panel } = await import('../../../StarRail-plugin/apps/panel.js')
uid = await redis.get(`STAR_RAILWAY:UID:${qq}`)
if (!uid) {
return '用户没有绑定uid无法查询。可以让用户主动提供uid进行查询'
}
} catch (e) {
// todo support miao-plugin and sruid
return '未安装StarRail-Plugin无法查询'
}
}
try {
let { Panel } = await import('../../../StarRail-plugin/apps/panel.js')
e.msg = character ? `*${character}面板${uid}` : '*更新面板' + uid
e.user_id = qq
e.isSr = true
let panel = new Panel(e)
panel.e = e
panel.panel(e).catch(e => logger.warn(e))
let uidRes = await fetch('https://avocado.wiki/v1/info/' + uid)
uidRes = await uidRes.json()
let { assistAvatar, displayAvatars } = uidRes.playerDetailInfo
function dealAvatar (avatar) {
delete avatar.position
delete avatar.vo_tag
delete avatar.desc
delete avatar.promption
delete avatar.relics
delete avatar.behaviorList
delete avatar.images
delete avatar.ranks
if (avatar.equipment) {
avatar.equipment = {
level: avatar.equipment.level,
rank: avatar.equipment.rank,
name: avatar.equipment.name,
skill_desc: avatar.equipment.skill_desc
}
}
if (character) {
let ProfileDetail = (await import('../../../miao-plugin/apps/profile/ProfileDetail.js')).default
// e.msg = `#${character}面板${uid}`
e.original_msg = `*${character}面板${uid}`
e.user_id = parseInt(qq)
e.isSr = true
await ProfileDetail.detail(e)
return 'the character panel of star rail has been sent to group. you don\'t need text version'
} else {
let ProfileList = (await import('../../../miao-plugin/apps/profile/ProfileList.js')).default
e.msg = `*面板${uid}`
e.user_id = qq
e.isSr = true
await ProfileList.render(e)
return 'the player panel of genshin impact has been sent to group. you don\'t need text version'
}
dealAvatar(assistAvatar)
if (displayAvatars) {
displayAvatars.forEach(avatar => {
dealAvatar(avatar)
})
}
uidRes.playerDetailInfo.assistAvatar = assistAvatar
uidRes.playerDetailInfo.displayAvatars = displayAvatars
delete uidRes.repository
delete uidRes.version
return `the player info in json format is: \n${JSON.stringify(uidRes)}`
} catch (err) {
return `failed to query, error: ${err.toString()}`
}