Created
January 10, 2018 13:58
-
-
Save jeasonstudio/d5300f35832ffe60f8db57894ad925b1 to your computer and use it in GitHub Desktop.
b 站弹幕姬 终端版本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { Room } = require('bilibili-live') | |
| const config = { | |
| roomId: 30493, | |
| url: 30493, | |
| useWebsocket: true, | |
| useWSS: true | |
| } | |
| const br = s => `\x1b[1m\x1b[31m${s}\x1b[0m` | |
| const bu = s => `\x1b[1m\x1b[4m${s}\x1b[0m` | |
| new Room(config) | |
| .connect() | |
| .then(room => { | |
| room.on('danmaku.connect', () => { | |
| // console.log(`进入直播间: ${config.roomId}`) | |
| }) | |
| room.on('danmaku.message', msg => { | |
| if (msg.type == 'gift') { | |
| const { gift: { name: giftName, count }, user: { name: userName } } = msg | |
| console.log(`🎁 🎁 收到礼物: ${br(giftName + ' X ' + count)} 来自 ${userName}`) | |
| } | |
| else if (msg.type == 'online') { | |
| // console.log('当前在线人数' + msg.number) | |
| } | |
| else if (msg.type == 'comment') { | |
| let comment = '' | |
| if (msg.user.isVIP || msg.user.isSVIP) { | |
| comment += br('[年]') | |
| } | |
| if (msg.user.badge) { // 主播勋章 | |
| comment += br(`[${msg.user.badge.title}${msg.user.badge.level}]`) | |
| } | |
| if (msg.user.level) { // 用户等级 | |
| comment += `[Lv.${msg.user.level}]` | |
| } | |
| comment += `${msg.user.name}: ${bu(msg.comment)}` | |
| console.log(`==> ${comment}`) | |
| } | |
| else if (msg.type == 'welcome' || msg.type == 'welcomeGuard' || msg.type == 'guardBuy' || msg.type == 'block') { | |
| // console.log('others') | |
| } | |
| }) | |
| room.on('newFans', msg => { | |
| console.log(`👏 👏 ${msg.user.name} 关注了直播间`) | |
| }) | |
| room.on('danmaku.error', () => { | |
| console.log(br('something wrong')) | |
| }) | |
| room.on('info', ({ liveStartTime, title }) => { | |
| console.log(`成功进入直播间: ${config.roomId} ${title}`) | |
| console.log(`直播开始时间: ${liveStartTime}`) | |
| }) | |
| }) | |
| .catch(e => { | |
| console.log(e) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment