Skip to content

Commit

Permalink
fix: 修复 onebot v11 撤回消息失败的bug
Browse files Browse the repository at this point in the history
* 修改自定义音乐分享时的字段读取优先级
  • Loading branch information
Misaka-Mikoto-Tech committed Oct 12, 2023
1 parent 4293de9 commit 499d219
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/service/V11/action/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ export class CommonAction {

/**
* 撤回消息
* @param message_id {string} 消息id
* @param message_id {number} 消息id
*/
deleteMsg(this: V11, message_id: string) {
return this.client.deleteMsg(message_id)
async deleteMsg(this: V11, message_id: number) {
if(message_id == 0) throw new Error('getMsg: message_id[0] is invalid')
let msg_entry = await this.db.getMsgById(message_id)
if(!msg_entry) throw new Error(`getMsg: can not find msg[${message_id}] in db`)

return this.client.deleteMsg(msg_entry.base64_id)
}

/**
Expand All @@ -29,6 +33,7 @@ export class CommonAction {
if(message_id == 0) throw new Error('getMsg: message_id[0] is invalid')
let msg_entry = await this.db.getMsgById(message_id)
if(!msg_entry) throw new Error(`getMsg: can not find msg[${message_id}] in db`)

let msg: Message = await this.client.getMsg(msg_entry.base64_id)
msg.message_id = String(message_id) // nonebot v11 要求 message_id 是 number 类型
msg["real_id"] = msg.message_id // nonebot 的reply类型会检测real_id是否存在,虽然它从未使用
Expand Down
2 changes: 1 addition & 1 deletion src/service/V11/db_sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Database {
if(msgDataExists) {
// send_msg() 返回值和同步的 message 消息哪个先来不确定,send_msg 返回值后来时不允许更新数据库
if(msgData.content.length == 0) {
return
return msgDataExists.id
}
msgData.id = msgDataExists.id
await this.msgRepo.update({id: msgData.id}, msgData)
Expand Down
4 changes: 2 additions & 2 deletions src/service/shareMusicCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export async function buildMusic(target: string | number, bu: string | 0 | 1, mu
let { singer=null, title=null, jumpUrl=null, musicUrl=null, preview=null } = music.id ? await getMusicInfo(music.id) : {}
singer = music['content'] || music.singer || singer // 自定义参数优先级高于默认值(gocq的参数名与icqq有区别,做下兼容)
title = music.title || title
jumpUrl = music.jumpUrl || jumpUrl
musicUrl = music['url'] || music['voice'] || music.musicUrl || musicUrl
jumpUrl = music.jumpUrl || music['url'] || jumpUrl
musicUrl = music['voice'] || music['url'] || music.musicUrl || musicUrl
preview = music['image'] || music.preview || preview
if (!musicUrl) style = 0
return {
Expand Down

0 comments on commit 499d219

Please sign in to comment.