ddiu8081 / blive-message-listener

Bilibili live danmu listener with type. 类型友好的 Bilibili 直播间弹幕监听库。

Home Page:https://npmjs.com/blive-message-listener

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

emoji表情

pkptzx opened this issue · comments

commented

既然你要类型友好,就不如把emoji加上,不是指别的表情
比如[花],[爱]的这种从表情面板选择的

我现在的做法如下,字段是在info[0][15]里,height,width也有,但我写死20了,反正也是20
你可以定义个更友好的字段或几个字段,让用户自己这样拼也行

我的实现
//解emoji表情的地址
const extra = JSON.parse(msg.raw.info[0][15].extra)
if(extra.emots){
    // 替换emoji表情
    console.log(extra.emots)
    msg.body.contentHtml = msg.body.content
    for(let key in extra.emots){
        let reg = new RegExp(key.replace('[','\\[').replace(']','\\]'),'gi')
        msg.body.contentHtml = msg.body.contentHtml.replaceAll(reg, `<img style="width: 20px; height: 20px;" src="${extra.emots[key].url}" />`)
    }
}
commented

我觉得可行,之前没发现还能发这种表情

commented

还有这几个事件你都加上呗 ^_^

  • 点赞的人 LIKE_INFO_V3_CLICK
  • 房管这俩可以定义到一起:
    • 设立房管 room_admin_entrance
    • 撤销房管 ROOM_ADMIN_REVOKE
  • 发送红包POPULARITY_RED_POCKET_NEW
commented

计划新增一个 in_message_emoticon 来对应消息中的表情,应该还算方便

/** 弹幕内小表情映射,key为表情文字,如"[妙]" */
type InMessageEmoticon = Record<string, {
  id: string
  emoticon_id: number
  height: number
  width: number
  url: string
  description: string
}>

example:

{
  "user": { ... },
  "content": "test[dog][妙]",
  "timestamp": 1673951572580,
  "lottery": false,
  "in_message_emoticon": {
    "[dog]": {
      "id": "emoji_208",
      "emoticon_id": 208,
      "height": 20,
      "width": 20,
      "url": "http://i0.hdslb.com/bfs/live/4428c84e694fbf4e0ef6c06e958d9352c3582740.png",
      "description": "[dog]"
    },
    "[妙]": {
      "id": "emoji_210",
      "emoticon_id": 210,
      "height": 20,
      "width": 20,
      "url": "http://i0.hdslb.com/bfs/live/08f735d950a0fba267dda140673c9ab2edf6410d.png",
      "description": "[妙]"
    }
  }
}
commented

增加事件的再开个 issue 吧,方便关🤣