Skip to content

Commit

Permalink
更新详见 changelog.md
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Dec 2, 2021
1 parent b6b7ad3 commit 94be991
Show file tree
Hide file tree
Showing 30 changed files with 116 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build Executable And Publish
env:
version: 0.1.2
version: 0.1.3
artifact_name: vup_monitors
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
22 changes: 16 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
FROM node:17-alpine
FROM node:16 AS builder

WORKDIR /app

RUN cd /app
COPY ./src ./src
COPY *.json .

COPY . .
RUN npm install
RUN npm install pkg -g
RUN pkg .

VOLUME [ "/app/data" ]
FROM ubuntu:latest

RUN npm install
WORKDIR /

ENV NODE_ENV=production

COPY --from=builder /app/dist/vup_monitors-linux /vup_monitors
RUN chmod +x /vup_monitors

VOLUME [ "/data" ]

CMD ["npm", "run", "start"]
ENTRYPOINT [ "/vup_monitors" ]
66 changes: 64 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Vup Monitors

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

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

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

- 进入直播间
- 发送SC
- 发送弹幕

## 前置

Expand All @@ -23,7 +31,7 @@

### 本项目 (Vup_monitors)

- 下载对应平台的可执行文件
- `releases` 下载对应平台的可执行文件

- 运行程序后关闭

Expand All @@ -33,13 +41,67 @@

- 再运行程序

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


#### 除了 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 和 redis,然后在 `data/settings.json` 设定数据源为 `redis` 即可

## 指令

`<>` 为必填参数, `[]` 为选填参数

### !B站直播

B站直播WS讯息监控指令

- `!B站直播 监控 <房间号>` - 监听房间
- `!B站直播 中止 <房间号>` - 中止监听房间
- `!B站直播 监听中` - 获取正在监听中的房间号列表

### !高亮名单

控制高亮名单用户,以进行广播

```log
- 如果在群使用指令,则会添加/删除到该群所属的高亮用户名单
- 如果在私聊使用且附上`[群id]`,则会添加/删除该群id所属的高亮用户名单
- 如果在私聊使用而不附上`[群id]`,则会添加/删除属于你自己的高亮用户名单
```

- `!高亮 新增 <用户id> [群id]` - 新增用户到高亮名单
- `!高亮 移除 <用户id> [群id]` - 删除用户到高亮名单
- `!高亮 列表 [群id]` - 显示高亮用户名单列表

**高亮名单会分开群号和QQ号,只有在私聊才会接受 `[群id]` 作为参数以私下设置群高亮名单,如不填则为属于该QQ号的高亮名单**

### !注视名单

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

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

- `!注视 新增 <用户id> <群id(如私聊)>` - 新增该群注视用户
- `!注视 移除 <用户id> <群id(如私聊)>` - 移除该群注视用户
- `!注视 列表 <用户id> <群id(如私聊)>` - 查看该群所属注视用户名单

添加注视用户后,广播规则将如下

| 高亮用户 | 直播间 | 广播 |
| ------- | ----- | ----- |
| 在注视名单内 | 不在注视名单内 ||
| 不在注视名单内 | 不在注视名单内 ||
| 不在注视名单内 | 在注视名单内 ||
| 在注视名单内 | 在注视名单内 ||

如果没有注视用户,则默认广播所有高亮用户在监控中的直播间的DD行为。

## 其他部署方式

### Docker
Expand Down
Binary file added assets/dd_showcase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

### 更新

- 刪除插件模塊機制
- 把所有js檔案放入 src folder
- 更新 readme.md
- 修复无法读取外部 data/settings.json
- reduce docker image size
35 changes: 0 additions & 35 deletions data/storage.json

This file was deleted.

23 changes: 9 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "vup_monitors",
"version": "0.1.2",
"bin": "index.js",
"main": "index.js",
"version": "0.1.3",
"bin": "src/index.js",
"main": "src/index.js",
"scripts": {
"nodemon:dev": "cross-env NODE_ENV=development nodemon index.js",
"dev": "cross-env NODE_ENV=development node index.js",
"start": "cross-env NODE_ENV=production node --trace-warnings index.js",
"nodemon:test": "cross-env NODE_ENV=development nodemon test.js",
"test": "cross-env NODE_ENV=development node test.js",
"reload": "pm2 reload go-cqhttp-node"
"nodemon:dev": "cross-env NODE_ENV=development nodemon src/index.js",
"dev": "cross-env NODE_ENV=development node src/index.js",
"start": "cross-env NODE_ENV=production node --trace-warnings src/index.js",
"nodemon:test": "cross-env NODE_ENV=development nodemon src/test.js",
"test": "cross-env NODE_ENV=development node src/test.js"
},
"dependencies": {
"axios": "^0.21.4",
Expand All @@ -19,11 +18,7 @@
},
"pkg": {
"scripts": [
"./ws_handles/*.js",
"./plugin/*.js",
"./el/**/*.js",
"./commands/*.js",
"./bot/*.js"
"./src/**/*.js"
],
"targets": [
"node16-win-x64",
Expand Down
2 changes: 1 addition & 1 deletion bot/http.js → src/bot/http.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const axios = require('axios')
const config = require('../data/settings.json')
const config = require('../el/data-storer').settings

const http = axios.create({
baseURL: config.bot.http,
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions bot/ws.js → src/bot/ws.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const WebSocket = require('ws')
const config = require('../config')
const { bot } = require('../data/settings.json')
const { bot } = require('../el/data-storer').settings
const { sleep } = require('../el/utils')


Expand All @@ -9,12 +9,12 @@ async function connect(){

return new Promise((res, rej) => {
ws.on('error', err => {
console.warn(`连接 WS 时出现错误: ${err?.message ?? err}`)
console.warn(`连接 go-cqhttp 时出现错误: ${err?.message ?? err}`)
rej(err)
})

ws.on('open', () => {
console.log(`WS 连接成功。`)
console.log(`go-cqhttp 连接成功。`)
res(ws)
})
})
Expand Down
2 changes: 1 addition & 1 deletion command_listener.js → src/command_listener.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { invoke } = require('./el/command-manager')
const { owners } = require('./data/settings.json')
const { owners } = require('./el/data-storer').settings
const { commands } = require('./config')

module.exports = async({data, ws, http}) => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion el/api/message-source.js → src/el/api/message-source.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const redisSource = require('./redis_api')
const websocketSource = require('./websocket_api')
const { source } = require('../../data/settings.json')
const { source } = require('../data-storer').settings

const sources = {
...redisSource,
Expand Down
2 changes: 1 addition & 1 deletion el/api/redis_api.js → src/el/api/redis_api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { createClient } = require('redis');
const settings = require('../../data/settings.json')
const settings = require('../data-storer').settings
const utils = require('../utils');

const { handleMessage } = require('../message-handler');
Expand Down
3 changes: 2 additions & 1 deletion el/api/websocket_api.js → src/el/api/websocket_api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const WebSocket = require('ws')
const { websocket } = require('../../data/settings.json')
const { websocket } = require('../data-storer').settings
const utils = require('../utils')
const { default: axios } = require('axios')
const FormData = require('form-data')
Expand Down Expand Up @@ -68,6 +68,7 @@ class WebSocketSouce extends MessageSource {
}

async listenAll(rooms){
if (rooms.length == 0) return
const form = new FormData()
for (const room of rooms){
form.append('subscribes', room)
Expand Down
File renamed without changes.
10 changes: 7 additions & 3 deletions el/data-storer.js → src/el/data-storer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { existsSync, mkdirSync, writeFileSync , promises: fs } = require('fs')
const { existsSync, mkdirSync, writeFileSync, readFileSync , promises: fs } = require('fs')


const PATH = './data/storage.json'
Expand Down Expand Up @@ -47,18 +47,22 @@ if (!existsSync('./data')){
mkdirSync('./data')
}

const SETTING_PATH = './data/settings.json'

if (!existsSync('./data/settings.json')) {
if (!existsSync(SETTING_PATH)) {
console.log("找不到 data/settings.json 档案")
const config = JSON.stringify(DEFAULT_CONFIG, undefined, 4)
writeFileSync('./data/settings.json', config)
writeFileSync(SETTING_PATH, config)
console.log("已新增默认的 data/settings.json 设定档。")

}

const settings = JSON.parse(readFileSync(SETTING_PATH))

const write_transactions = []

const actions = {
settings,
// this.update(data => { ... })
update: async (update) => {
const data = await actions.read()
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions el/types.js → src/el/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MessageSource {
}

async listenAll(rooms){
if (rooms.length == 0) return
for (const room of rooms) {
await this.listen(room, false)
}
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion index.js → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ async function executeCommands(data) {
}
}

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

// 同时启动 Redis 和 WS 监控
console.log('正在启动 vup monitors...')
Promise.all([ ws.startWS(), messager.connect()])
Promise.all([ws.startWS(), messager.connect()])
.then(() => {
ws.listen(data => {
if (process.env.NODE_ENV === 'development') {
Expand Down
2 changes: 1 addition & 1 deletion test.js → src/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { invoke } = require('./el/command-manager')
const readline = require("readline");
const { connect } = require('./el/redis_api');
const { connect } = require('./el/api/message-source');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 94be991

Please sign in to comment.