Skip to content

Commit

Permalink
Merge pull request #43 from eric2788/develop
Browse files Browse the repository at this point in the history
ready to v0.1.13
  • Loading branch information
Marxel-cn authored Mar 12, 2023
2 parents d33910b + c08736e commit 042b1e0
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 29 deletions.
50 changes: 38 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Vup Monitors

基于 go-cqhttp 和 nodejs 的 Vups 直播間監控機器人,支援多群使用和私人广播
基于 go-cqhttp 和 nodejs 的 Vups 直播间监控机器人,支持多群使用和私人广播

![showcase](/assets/dd_showcase.png)

#### 目前支援监控的DD行为
#### 目前支持监控的DD行为

- 进入直播间
- 发送SC
Expand All @@ -26,7 +26,7 @@

- 运行 `go-cqhttp`, 根据提示填写 QQ 号和密码等信息, 参考文档 https://docs.go-cqhttp.org/guide/quick_start.html

- 啟用正向 Websocket (这点很重要,不然之后无法连接到 go-cqhttp)
- 启用正向 Websocket (这点很重要,不然之后无法连接到 go-cqhttp)

### biligo-live-ws

Expand All @@ -49,18 +49,18 @@

-`data/settings.json` 填入设定,包括
- 设定数据源 `source``websocket`
- websocket 中 填入你自架的 biligo-live-ws 或使用 公共API地址 (如果使用公共API,則需要 `use-tls: true`)
- websocket 中 填入你自架的 biligo-live-ws 或使用 公共API地址 (如果使用公共API,则需要 `use-tls: true`)
- 在管理员 `owners` 的设定中添加你的 QQ 号
- 填入你在 go-cqhttp 中启用正向 Websocket 的端口 (如非6700)

- 再运行程序

- 开始透过指令设定监控和高亮
- 开始通过指令设定监控和高亮


#### 除了 biligo-live-ws 以外的运行方式

- [blive-redis-server](https://github.com/eric2788/blive-redis-server) + [redis](https://www.redis.com.cn/redis-installation.html) 伺服器 (比较麻烦)
- [blive-redis-server](https://github.com/eric2788/blive-redis-server) + [redis](https://www.redis.com.cn/redis-installation.html) 服务器 (比较麻烦)

运行 blive-redis-server 和 redis,然后在 `data/settings.json` 设定数据源为 `redis` 即可

Expand Down Expand Up @@ -107,11 +107,11 @@ B站直播WS讯息监控指令

### !注视名单

透过设置群注视名单,可以在广播时限制仅限在注视用户的直播间内/注视用户本人的所有DD行为。
通过设置群注视名单,可以在广播时限制仅限在注视用户的直播间内/注视用户本人的所有DD行为。

```log
- 由于注视用户不支援私聊,因此在私聊使用此指令时必须添加群id
- 如果在群添加注视用户,则无需填入群id,並以该群作为添加/删除对象
- 由于注视用户不支持私聊,因此在私聊使用此指令时必须添加群id
- 如果在群添加注视用户,则无需填入群id,并以该群作为添加/删除对象
```

- `!注视 新增 <用户id> <群id(如私聊)>` - 新增该群注视用户
Expand Down Expand Up @@ -153,20 +153,21 @@ B站直播WS讯息监控指令
// websocket 数据源
// 使用 blive.ericlamm.xyz 可贡献统计数据
"websocket": {
"id": "vup_monitors", // 支持不同ID以支援多个实例
"id": "vup_monitors", // 辨识ID,详见下面“多实例使用”部分
"host": "blive.ericlamm.xyz",
"use-tls": true
},
"source": "websocket", // 数据源选择 websocket, redis
"owners": [], // 管理员 QQ 号,列表内的 qq 号可绕过房管限制
"owners": [], // 管理员QQ号,列表内的QQ号可绕过房管限制
"identifier": "", // 多实例识别符,详见下面“多实例使用”部分
"accept_gadmin_command": true, // 是否接受群管使用指令
"enable_live_broadcast": false, // 启用开播通知
"show_cover": true, // 开播通知时是否显示封面
"show_gift_danmu": false, // 是否显示礼物弹幕
"show_image_danmu": true, // 是否显示表情包弹幕
"auto_check_update": true, // 是否自动每天检查更新
"show_detail_list": true, // 显示高亮/直播/注视列表时是否顺带显示用户名称(需要更多时间刷取)
"debug_mode": false, // 是否啟用 debug 模式
"debug_mode": false, // 是否启用 debug 模式
"disabled_commands": [ // 禁用的广播
// "DANMU_MSG", // 弹幕消息
// "SEND_GIFT", // 赠送礼物
Expand All @@ -179,6 +180,31 @@ B站直播WS讯息监控指令
}
```

### 多实例使用

分为两种场景:多实例共用同一个biligo-live-ws实例,以及多实例共用同一个go-cqhttp

#### 共用同一个biligo-live-ws
根据 [biligo-live-ws的说明](https://github.com/eric2788/biligo-live-ws#使用方式) ,同一IP下的实例需要配置不同的辨识ID以避免混淆

因此如果要在同一IP下部署多个实例同时使用同一个biligo-live-ws作为数据源,则应在设置中为每个实例指定不同的辨识ID(不指定时默认为vup_monitors)

#### 共用同一个go-cqhttp
多个实例共用同一个go-cqhttp时,因为前端的QQ号码是同一个,因此会同时响应命令,造成使用上的困难

此时应在设置中为每个实例指定不同的多实例识别符,配置后bot将只响应以``#[多实例识别符]``结尾的命令,以此达到准确控制特定实例的效果

此时命令形式将变为形如`!B站直播 监听中 #abc`的格式,具体逻辑如下

| 多实例识别符 | 命令 | 响应 |
| ------- | ----- | ----- |
| 未配置 | 不带# ||
| 未配置 | 带有# ||
| 配置为abc | 不带# ||
| 配置为abc | 以#abc结束 ||
| 配置为abc | 以#xyz结束 ||


## 统计数据

使用了 ``https://blive.ericlamm.xyz`` 作为 公共API地址 的机器人都可以贡献统计数据。
Expand Down
16 changes: 15 additions & 1 deletion src/command_listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ const { commands } = require('./config')
module.exports = async({data, ws, http}) => {
if (!data.message) return
if (data.message[0] !== '!') return // 指令用 ! 开头
let sharpPos = data.message.indexOf('#')
if (settings.identifier && settings.identifier.length > 0) { // 如果配置了identifier
if (sharpPos == -1) { // 此时如果没有#则忽略
return
} else { // 有#则检查identifier是否一致
if (data.message.substring(sharpPos+1).trim() != settings.identifier) {
return // 不一致则忽略
}
}
} else { // 如果没有配置identifier
if (sharpPos != -1) { // 此时如果有#则忽略
return
}
}

const is_group = data.message_type === 'group'

Expand All @@ -17,7 +31,7 @@ module.exports = async({data, ws, http}) => {
return // no permission
}

const msg = data.message.substring(1).trim()
const msg = data.message.substring(1, sharpPos == -1 ? 5000 : sharpPos).trim() // QQ消息长度不会超过4500,偷懒了
const command = msg.split(' ')
const [cmd, ...args] = command

Expand Down
20 changes: 11 additions & 9 deletions src/commands/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const storer = require('../el/data-storer')
const { validUser } = require('../el/utils');
const level = require('../el/cachedb')

const GROUP_REGEXP = new RegExp(/\d+[-]?\d+$/)

class AddFocus extends CommandExecutor {

async execute({ send, data }, args) {
Expand All @@ -23,9 +25,9 @@ class AddFocus extends CommandExecutor {
}

if (!isGroup) {
const group_id = Number.parseInt(args[1])
if (!group_id) {
await send('不是一个有效的群ID')
const group_id = String(args[1])
if (!GROUP_REGEXP.test(group_id)) {
await send(`${group_id} 不是一个有效的群ID`)
return
}
data.group_id = group_id
Expand Down Expand Up @@ -84,9 +86,9 @@ class RemoveFocus extends CommandExecutor {
}

if (!isGroup) {
const group_id = Number.parseInt(args[1])
if (!group_id) {
await send('不是一个有效的群ID')
const group_id = String(args[1])
if (!GROUP_REGEXP.test(group_id)) {
await send(`${group_id} 不是一个有效的群ID`)
return
}
data.group_id = group_id
Expand Down Expand Up @@ -129,9 +131,9 @@ class Focusing extends CommandExecutor {
const focus_users = json?.blive?.focus_users ?? {}

if (data.message_type !== 'group') {
const group_id = Number.parseInt(args[0])
if (!group_id) {
await send('不是一个有效的群ID')
const group_id = String(args[0])
if (!GROUP_REGEXP.test(group_id)) {
await send(`${group_id} 不是一个有效的群ID`)
return
}
data.group_id = group_id
Expand Down
19 changes: 16 additions & 3 deletions src/commands/highlights.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const level = require('../el/cachedb')

const KEY_GROUP = 'highlight'
const KEY_PRIVATE = 'highlight_private'
const GROUP_REGEXP = new RegExp(/\d+[-]?\d+$/)

class AddUser extends CommandExecutor {

Expand Down Expand Up @@ -32,7 +33,11 @@ class AddUser extends CommandExecutor {
}

if (!is_group && args[1]) { // 不是群聊發送,但是有輸入 [群 id]
data.group_id = Number.parseInt(args[1])
data.group_id = String(args[1])
if (!GROUP_REGEXP.test(data.group_id)) {
await send(`${data.group_id} 不是一个有效的群ID`)
return
}
}

const group_id = data.group_id
Expand Down Expand Up @@ -94,7 +99,11 @@ class RemoveUser extends CommandExecutor {
}

if (!is_group && args[1]) { // 不是群聊發送,但是有輸入 [群 id]
data.group_id = Number.parseInt(args[1])
data.group_id = String(args[1])
if (!GROUP_REGEXP.test(data.group_id)) {
await send(`${data.group_id} 不是一个有效的群ID`)
return
}
}

const group_id = data.group_id
Expand Down Expand Up @@ -154,7 +163,11 @@ class HighLighting extends CommandExecutor {
const is_group = data.message_type === 'group'

if (!is_group && args[0]) {
data.group_id = Number.parseInt(args[0])
data.group_id = String(args[0])
if (!GROUP_REGEXP.test(data.group_id)) {
await send(`${data.group_id} 不是一个有效的群ID`)
return
}
}

const json = await storer.read()
Expand Down
3 changes: 2 additions & 1 deletion src/el/data-storer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const DEFAULT_CONFIG = {
},
"source": "websocket",
"owners": [],
"identifier": "",
"accept_gadmin_command": true,
"enable_live_broadcast": false,
"show_cover": true,
Expand Down Expand Up @@ -82,7 +83,7 @@ const actions = {

save: (data) => {
try {
writeFileSync(PATH, JSON.stringify(data))
writeFileSync(PATH, JSON.stringify(data, null, 4))
actions.clearCache()
console.log(`离线数据储存已更新。`)
}catch(err){
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ async function executeCommands(data) {
}

const { owners, accept_gadmin_command, auto_check_update } = require('./el/data-storer').settings
console.log(`已设置管理员QQ号: ${owners}。`)
console.log(`已设置Bot管理员QQ号: ${owners}。`)
if (accept_gadmin_command) {
console.log(`群管和管理员都可使用指令。`)
console.log(`群管理和Bot管理员都可以使用指令。`)
} else {
console.log(`仅管理员可使用指令。`)
console.log(`仅Bot管理员可以使用指令。`)
}

// 同时启动 Redis 和 WS 监控
Expand Down

0 comments on commit 042b1e0

Please sign in to comment.