-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(live-mini): add monorepo live-mini
- Loading branch information
Showing
16 changed files
with
215 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { startApp } from '@bilicli/live-mini' | ||
|
||
interface ArgOptions { | ||
badge: boolean | ||
rank: boolean | ||
} | ||
|
||
const mini = async(roomId: string, options: ArgOptions) => { | ||
startApp(~~roomId, { | ||
badge: options.badge, | ||
rank: options.rank, | ||
}) | ||
} | ||
|
||
export { mini } |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@bilicli/live-mini", | ||
"version": "0.0.1", | ||
"description": "Bili-Live danmu client, lite version", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"dev": "tsup --watch", | ||
"build": "tsup" | ||
}, | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"bilibili", | ||
"bilibili-live", | ||
"danmaku", | ||
"danmu", | ||
"terminal", | ||
"cli", | ||
"tui" | ||
], | ||
"author": "ddiu8081 <ddiu8081@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"blive-message-listener": "^0.3.0", | ||
"colorette": "^2.0.19", | ||
"ohmyfetch": "^0.4.19" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
interface AppOptions { | ||
badge: boolean | ||
rank: boolean | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { DanmuMsg } from 'blive-message-listener' | ||
import { username } from '../username' | ||
|
||
export const danmuMsg = (msg: DanmuMsg) => { | ||
const userCom = username(msg.user) | ||
return `${userCom}: ${msg.content}` | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './danmu' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { blue } from 'colorette' | ||
import type { User } from 'blive-message-listener' | ||
|
||
export const username = (user: User) => { | ||
return blue(user.uname) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { startInstance } from './instance' | ||
import { getRoomInfo } from './utils/getInfo' | ||
|
||
const startApp = async (roomId: number, options: AppOptions) => { | ||
const roomInfo = await getRoomInfo(roomId) | ||
if (!roomInfo) { | ||
console.log('房间不存在') | ||
return process.exit(1) | ||
} | ||
console.log(roomId, `(${roomInfo.parent_area_name}·${roomInfo.area_name})`, roomInfo.title) | ||
startInstance(roomInfo.room_id, options) | ||
} | ||
|
||
export { startApp } |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { startListen } from 'blive-message-listener' | ||
import type { | ||
MsgHandler, Message, | ||
DanmuMsg, SuperChatMsg, GiftMsg, GuardBuyMsg, UserActionMsg | ||
} from 'blive-message-listener' | ||
import { danmuMsg } from './component/msg' | ||
|
||
export const startInstance = (roomId: number, options: AppOptions) => { | ||
const handler: MsgHandler = { | ||
onIncomeDanmu: (msg) => { | ||
console.log(danmuMsg(msg.body)) | ||
}, | ||
} | ||
startListen(roomId, handler) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { $fetch } from 'ohmyfetch' | ||
|
||
export interface RoomInfo { | ||
uid: number | ||
room_id: number | ||
short_id: number | ||
attention: number | ||
online: number | ||
is_portrait: boolean | ||
description: string | ||
live_status: number | ||
area_id: number | ||
parent_area_id: number | ||
parent_area_name: string | ||
background: string | ||
title: string | ||
user_cover: string | ||
keyframe: string | ||
live_time: string | ||
area_name: string | ||
} | ||
|
||
interface RoomInfoResponse { | ||
code: number | ||
msg: string | ||
message: string | ||
data: RoomInfo | ||
} | ||
|
||
export const getRoomInfo = async (roomId: number) => { | ||
const url = `https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomId}` | ||
const response = await $fetch<RoomInfoResponse>(url) | ||
return response.code === 0 ? response.data : null | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineConfig } from 'tsup' | ||
|
||
export default defineConfig({ | ||
format: ['cjs', 'esm'], | ||
entry: [ | ||
'src/index.ts', | ||
], | ||
dts: { | ||
resolve: true, | ||
entry: './src/index.ts', | ||
}, | ||
clean: true, | ||
}) |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.