kook适配器无法正常处理接收到的图文混合消息

rt,kook适配器已是最新4.6.4版本

  async accept() {
    this._sn = 0;
    clearInterval(this._heartbeat);
    this.socket.addEventListener("message", async ({ data }) => {
      let parsed;
      data = data.toString();
      try {
        parsed = JSON.parse(data);
        console.log(parsed);
      } catch (error) {
        return this.bot.logger.warn("cannot parse message", data);
      }
      this.bot.logger.debug("[receive] %o", parsed);
      if (parsed.s === 0 /* event */) {
        this._sn = Math.max(this._sn, parsed.sn);
        const session = await adaptSession(this.bot, parsed.d);
        console.log(session);
        if (session)
          this.bot.dispatch(session);
      } else if (parsed.s === 1 /* hello */) {
        this._heartbeat = setInterval(() => this.heartbeat(), import_satori2.Time.minute * 0.5);
        await this.bot.getLogin();
        this.bot.online();
      } else if (parsed.s === 3 /* pong */) {
        clearTimeout(this._ping);
      } else if (parsed.s === 5 /* resume */) {
        this.socket.close(1013);
      }
    });
  }

首先我修改了kook适配器的js文件,添加了两行console.log来获取parsed和session
然后我向机器人所在的服务器发送了一条消息

{
  s: 0,
  d: {
    channel_type: 'GROUP',
    type: 9,
    target_id: '1130646729606676',
    author_id: '1799857468',
    content: '1',
    extra: {
      type: 9,
      code: '',
      guild_id: '3758081468121419',
      guild_type: 0,
      channel_name: 'test',
      author: [Object],
      visible_only: null,
      mention: [],
      mention_all: false,
      mention_roles: [],
      mention_here: false,
      nav_channels: [],
      kmarkdown: [Object],
      emoji: [],
      preview_content: '',
      channel_type: 1,
      last_msg_content: 'SC-UN-炸毛狗头/AC Alex:1',
      send_msg_device: 1
    },
    msg_id: 'b1e535d9-fb91-44d5-8cd3-a071d0e96370',
    msg_timestamp: 1720295533847,
    nonce: 'njpfoW4UPl38Bhlh3qL7s3GY',
    from_type: 1
  },
  sn: 2
}
Session {
  id: 8,
  event: {
    selfId: '2956683510',
    platform: 'kook',
    timestamp: 1720295533683,
    _type: 'kook',
    _data: {
      channel_type: 'GROUP',
      type: 9,
      target_id: '1130646729606676',
      author_id: '1799857468',
      content: '1',
      extra: [Object],
      msg_id: 'b1e535d9-fb91-44d5-8cd3-a071d0e96370',
      msg_timestamp: 1720295533847,
      nonce: 'njpfoW4UPl38Bhlh3qL7s3GY',
      from_type: 1
    },
    type: 'message',
    guild: { id: '3758081468121419' },
    channel: { type: 0, id: '1130646729606676', name: 'test' },
    member: { nick: 'SC-UN-炸毛狗头/AC Alex' },
    user: {
      id: '1799857468',
      name: '炸毛狗头',
      userId: '1799857468',
      avatar: 'https://img.kookapp.cn/avatars/2024-04/C6wHD2YbHe0dw0dw.jpg?x-oss-process=style/icon',
      username: '炸毛狗头',
      discriminator: '2791'
    },
    message: {
      content: '1',
      elements: [Array],
      user: [Object],
      member: [Object],
      messageId: 'b1e535d9-fb91-44d5-8cd3-a071d0e96370',
      id: 'b1e535d9-fb91-44d5-8cd3-a071d0e96370',
      timestamp: 1720295533847
    }
  },
  locales: [],
  argv: undefined,
  user: undefined,
  channel: undefined,
  guild: undefined,
  permissions: [],
  scope: undefined,
  response: undefined,
  _stripped: undefined,
  _queuedTasks: [],
  _queuedTimeout: undefined
}

可以发现session中的content和接收到的content一致
然后我再发送一条图片消息

{
  s: 0,
  d: {
    channel_type: 'GROUP',
    type: 10,
    target_id: '1130646729606676',
    author_id: '1799857468',
    content: '[{"theme":"invisible","color":"","size":"lg","expand":false,"modules":[{"type":"container","elements":[{"type":"image","src":"https:\\/\\/img.kookapp.cn\\/assets\\/2024-07\\/07\\/1wt7hIrxY304203c.png","alt":"","size":"lg","circle":false,"title":"","elements":[]}]}],"type":"card"}]',
    extra: {
      type: 10,
      code: '',
      guild_id: '3758081468121419',
      guild_type: 0,
      channel_name: 'test',
      author: [Object],
      visible_only: null,
      mention: [],
      mention_all: false,
      mention_roles: [],
      mention_here: false,
      nav_channels: [],
      emoji: [],
      kmarkdown: [Object],
      editable: true,
      preview_content: '[图片]',
      channel_type: 1,
      last_msg_content: 'SC-UN-炸毛狗头/AC Alex:[图片]',
      send_msg_device: 1
    },
    msg_id: '7ba2b703-688a-4fc7-b4d4-d002b5309374',
    msg_timestamp: 1720295635391,
    nonce: 'ub67RdhbjdgojNCDIitwOqSx',
    from_type: 1
  },
  extra: {
    verifyToken: 'gnp9PPuKLNJ20TJ8',
    encryptKey: 'rAnQmuHmOcMNh',
    callbackUrl: ''
  },
  sn: 3
}
Session {
  id: 9,
  event: {
    selfId: '2956683510',
    platform: 'kook',
    timestamp: 1720295635327,
    _type: 'kook',
    _data: {
      channel_type: 'GROUP',
      type: 10,
      target_id: '1130646729606676',
      author_id: '1799857468',
      content: '[{"theme":"invisible","color":"","size":"lg","expand":false,"modules":[{"type":"container","elements":[{"type":"image","src":"https:\\/\\/img.kookapp.cn\\/assets\\/2024-07\\/07\\/1wt7hIrxY304203c.png","alt":"","size":"lg","circle":false,"title":"","elements":[]}]}],"type":"card"}]',
      extra: [Object],
      msg_id: '7ba2b703-688a-4fc7-b4d4-d002b5309374',
      msg_timestamp: 1720295635391,
      nonce: 'ub67RdhbjdgojNCDIitwOqSx',
      from_type: 1
    },
    type: 'message',
    guild: { id: '3758081468121419' },
    channel: { type: 0, id: '1130646729606676', name: 'test' },
    member: { nick: 'SC-UN-炸毛狗头/AC Alex' },
    user: {
      id: '1799857468',
      name: '炸毛狗头',
      userId: '1799857468',
      avatar: 'https://img.kookapp.cn/avatars/2024-04/C6wHD2YbHe0dw0dw.jpg?x-oss-process=style/icon',
      username: '炸毛狗头',
      discriminator: '2791'
    },
    message: {
      elements: [Array],
      content: '<card theme="invisible" color="" size="lg" no-expand><container><image src="https://img.kookapp.cn/assets/2024-07/07/1wt7hIrxY304203c.png" alt="" size="lg" no-circle title=""/></container></card>',
      user: [Object],
      member: [Object],
      messageId: '7ba2b703-688a-4fc7-b4d4-d002b5309374',
      id: '7ba2b703-688a-4fc7-b4d4-d002b5309374',
      timestamp: 1720295635391
    }
  },
  locales: [],
  argv: undefined,
  user: undefined,
  channel: undefined,
  guild: undefined,
  permissions: [],
  scope: undefined,
  response: undefined,
  _stripped: undefined,
  _queuedTasks: [],
  _queuedTimeout: undefined
}

也很正常,session中也出现了正确的图片url
那么我再发一条图文混合消息呢?

{
  s: 0,
  d: {
    channel_type: 'GROUP',
    type: 10,
    target_id: '1130646729606676',
    author_id: '1799857468',
    content: '[{"theme":"invisible","color":"","size":"lg","expand":false,"modules":[{"type":"container","elements":[{"type":"image","src":"https:\\/\\/img.kookapp.cn\\/assets\\/2024-07\\/07\\/FZsinV0iRB04203c.png","alt":"","size":"lg","circle":false,"title":"","elements":[]}]},{"type":"section","mode":"left","accessory":null,"text":{"type":"kmarkdown","content":"12312321312313","elements":[]},"elements":[]}],"type":"card"}]',
    extra: {
      type: 10,
      code: '',
      guild_id: '3758081468121419',
      guild_type: 0,
      channel_name: 'test',
      author: [Object],
      visible_only: null,
      mention: [],
      mention_all: false,
      mention_roles: [],
      mention_here: false,
      nav_channels: [],
      emoji: [],
      kmarkdown: [Object],
      editable: true,
      preview_content: '[图片]12312321312313',
      channel_type: 1,
      last_msg_content: 'SC-UN-炸毛狗头/AC Alex:[图片]12312321312313',
      send_msg_device: 1
    },
    msg_id: '4c1d6d12-39c8-413b-b295-6bb2f76a5c67',
    msg_timestamp: 1720295741279,
    nonce: '47CMPG2mD7LAQ7oyCZjQsbC4',
    from_type: 1
  },
  extra: {
    verifyToken: 'gnp9PPuKLNJ20TJ8',
    encryptKey: 'rAnQmuHmOcMNh',
    callbackUrl: ''
  },
  sn: 4
}
Session {
  id: 10,
  event: {
    selfId: '2956683510',
    platform: 'kook',
    timestamp: 1720295741728,
    _type: 'kook',
    _data: {
      channel_type: 'GROUP',
      type: 10,
      target_id: '1130646729606676',
      author_id: '1799857468',
      content: '[{"theme":"invisible","color":"","size":"lg","expand":false,"modules":[{"type":"container","elements":[{"type":"image","src":"https:\\/\\/img.kookapp.cn\\/assets\\/2024-07\\/07\\/FZsinV0iRB04203c.png","alt":"","size":"lg","circle":false,"title":"","elements":[]}]},{"type":"section","mode":"left","accessory":null,"text":{"type":"kmarkdown","content":"12312321312313","elements":[]},"elements":[]}],"type":"card"}]',
      extra: [Object],
      msg_id: '4c1d6d12-39c8-413b-b295-6bb2f76a5c67',
      msg_timestamp: 1720295741279,
      nonce: '47CMPG2mD7LAQ7oyCZjQsbC4',
      from_type: 1
    },
    type: 'message',
    guild: { id: '3758081468121419' },
    channel: { type: 0, id: '1130646729606676', name: 'test' },
    member: { nick: 'SC-UN-炸毛狗头/AC Alex' },
    user: {
      id: '1799857468',
      name: '炸毛狗头',
      userId: '1799857468',
      avatar: 'https://img.kookapp.cn/avatars/2024-04/C6wHD2YbHe0dw0dw.jpg?x-oss-process=style/icon',
      username: '炸毛狗头',
      discriminator: '2791'
    },
    message: {
      elements: [Array],
      content: '<card theme="invisible" color="" size="lg" no-expand><container><image src="https://img.kookapp.cn/assets/2024-07/07/FZsinV0iRB04203c.png" alt="" size="lg" no-circle title=""/></container><section mode="left"/></card>',
      user: [Object],
      member: [Object],
      messageId: '4c1d6d12-39c8-413b-b295-6bb2f76a5c67',
      id: '4c1d6d12-39c8-413b-b295-6bb2f76a5c67',
      timestamp: 1720295741279
    }
  },
  locales: [],
  argv: undefined,
  user: undefined,
  channel: undefined,
  guild: undefined,
  permissions: [],
  scope: undefined,
  response: undefined,
  _stripped: undefined,
  _queuedTasks: [],
  _queuedTimeout: undefined
}

诶!立马就出问题了!
session.event._data.content中正常显示了接收到的消息
但我们一般调用的是session.event.message.content
而这里面,却只有图片的url,而没有文字

我个人认为这个bug挺大的,我是一个游戏中的一个公会的管理,有时我会在kook上发些通知然后用机器人转发到QQ,有次我发了一个图文混合的通知,结果转发到QQ的只有图片,md尴尬死我了 :disappointed_relieved:

1 个赞