yeyang52/yenai-plugin

forwardMsg.data.replace is not a function报错修复

Closed this issue · 1 comments

问题描述
在使用最新版喵崽时,发送转发消息,如 #tagpro搜图 #来点秀人 功能时,会报错forwardMsg.data.replace is not a function

Yunzai版本
Miao-Yunzai
2.4.3

如何复现
发送 #tagpro搜图某某 或者是 #来点秀人

修复办法
把yenai-plugin/lib/common/common.js中的getforwardMsg函数改成下面这样。

async getforwardMsg (e, message, {
    recallMsg = 0,
    info,
    fkmsg,
    isxml,
    xmlTitle,
    oneMsg,
    anony
  } = {}) {
    
    let forwardMsg = await this.makeForwardMsg(e,message, {
      recallMsg,
      info,
      fkmsg,
      isxml,
      xmlTitle,
      oneMsg,
      anony
    })
    
    let msgRes = await e.reply(forwardMsg)

    return msgRes
  }

然后继续在yenai-plugin/lib/common/common.js中添加一个函数如下:

  /**
 * 制作转发消息
 * @param e 消息事件
 * @param msg 消息数组
 * @param dec 转发描述
 * @param msgsscr 转发信息是否为Bot
 */
  async makeForwardMsg(e, msg = [], {
    recallMsg = 0,
    info,
    fkmsg,
    xmlTitle,
    anony
  } = {}, msgsscr = false) {
    if (!Array.isArray(msg)) msg = [msg]
  
    let userInfo = {
      user_id: info?.user_id ?? (e.bot ?? Bot).uin,
      nickname: info?.nickname ?? (e.bot ?? Bot).nickname
    }
  
    let forwardMsg = []
    for (const message of msg){
      if(!message) continue
      forwardMsg.push({
        ...userInfo,
        message: message
      })
    }
      
  
    /** 制作转发内容 */
    if (e?.group?.makeForwardMsg) {
      forwardMsg = await e.group.makeForwardMsg(forwardMsg)
    } else if (e?.friend?.makeForwardMsg) {
      forwardMsg = await e.friend.makeForwardMsg(forwardMsg)
    } else {
      return msg.join('\n')
    }
  
    if (xmlTitle) {
      /** 处理描述 */
      if (typeof (forwardMsg.data) === 'object') {
        let detail = forwardMsg.data?.meta?.detail
        if (detail) {
          detail.news = [{ text: xmlTitle }]
        }
      } else {
        forwardMsg.data = forwardMsg.data
          .replace(/\n/g, '')
          .replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
          .replace(/___+/, `<title color="#777777" size="26">${xmlTitle}</title>`)
      }
    }
  
    return forwardMsg
  }

之后就可以正常使用了。功能没有复现完,但是大多数情况下是可以像往常一样使用的。

感谢