mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
163 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6d5ccc6664 | ||
![]() |
79090d764f | ||
![]() |
6ab0cd7f4b | ||
![]() |
bb3bce203d | ||
![]() |
36f7f1b026 | ||
![]() |
5a0dbdb5ce | ||
![]() |
48d62be2d6 | ||
![]() |
b314e2f3a0 | ||
![]() |
63b9204a4b | ||
![]() |
bf701c2110 | ||
![]() |
95b4b11f02 | ||
![]() |
1735babb7d | ||
![]() |
89c3f07cba | ||
![]() |
5cf45a452b | ||
![]() |
23d5fa7218 | ||
![]() |
983d2462d4 | ||
![]() |
3c68bc77ce | ||
![]() |
501211fb57 | ||
![]() |
0cd41a8a52 | ||
![]() |
d339a778df | ||
![]() |
dc843f77a3 | ||
![]() |
b103f2015c | ||
![]() |
baf35d5496 | ||
![]() |
5c34afc228 | ||
![]() |
a8a6290b70 | ||
![]() |
9d50c6d4fd | ||
![]() |
175a8ceb3d | ||
![]() |
31601981f2 | ||
![]() |
6a8c5ec24a | ||
![]() |
ebca6a07c5 | ||
![]() |
4f9345e4e5 | ||
![]() |
ac17dbefe0 | ||
![]() |
c9486b4f55 | ||
![]() |
35951fd61a | ||
![]() |
fdc23d7721 | ||
![]() |
560428a5f9 | ||
![]() |
e276d0e4f8 | ||
![]() |
965aa48729 | ||
![]() |
51e332ec38 | ||
![]() |
1307679dae | ||
![]() |
7966bf75c3 | ||
![]() |
d5a3687f2b | ||
![]() |
7cafbdfae5 | ||
![]() |
103bf94170 | ||
![]() |
235328e4fe | ||
![]() |
c371f1c5a3 | ||
![]() |
d0377bd2d3 | ||
![]() |
aae10181b5 | ||
![]() |
a298377717 | ||
![]() |
8afe0af940 | ||
![]() |
352793d05f | ||
![]() |
3a443f4ebf | ||
![]() |
917b55c1c3 | ||
![]() |
01d77827a8 | ||
![]() |
ead79a39f7 | ||
![]() |
ebc245b9f3 | ||
![]() |
47d6dc09db | ||
![]() |
165fcb13cb | ||
![]() |
c2405abdd3 | ||
![]() |
56492b21dd | ||
![]() |
37c4f02118 | ||
![]() |
92a2d8b5e2 | ||
![]() |
3a964af0b0 | ||
![]() |
fa5540da5c | ||
![]() |
eccf588569 | ||
![]() |
aad165ce5e | ||
![]() |
10c48a5b86 | ||
![]() |
63c2b95cbb | ||
![]() |
1d130d4580 | ||
![]() |
2dd5d81ffe | ||
![]() |
affefca19f | ||
![]() |
7381fb3e11 | ||
![]() |
9679f29f48 | ||
![]() |
dda5ea3972 | ||
![]() |
b12d205059 | ||
![]() |
6ea6b33e9a | ||
![]() |
b5655a1a5f | ||
![]() |
dc559ce36c | ||
![]() |
9ed67628bc | ||
![]() |
5aecf45959 | ||
![]() |
911841401a | ||
![]() |
4c6bd3df0b | ||
![]() |
c5932bcd98 | ||
![]() |
3abc9f2ae0 | ||
![]() |
e716c28e9a | ||
![]() |
9209ae766c | ||
![]() |
af8cf1882c | ||
![]() |
d93193c7fd | ||
![]() |
8a2245e2ec | ||
![]() |
1e144a1377 | ||
![]() |
8a44086419 | ||
![]() |
133719f96a | ||
![]() |
75c92a68bd | ||
![]() |
90820cf74d | ||
![]() |
f149594e23 | ||
![]() |
60e0c9e4ba | ||
![]() |
1a6739ffab | ||
![]() |
d8e31985af | ||
![]() |
c313fcd491 | ||
![]() |
f42727c8ad | ||
![]() |
17d9c48e68 | ||
![]() |
54179cb686 | ||
![]() |
c9a5ee69cf | ||
![]() |
e348103e84 | ||
![]() |
fccb0852aa | ||
![]() |
b3ea8fbc0c | ||
![]() |
ee483dd0cc | ||
![]() |
ed681b8adf | ||
![]() |
dcd4533eb3 | ||
![]() |
178c32053b | ||
![]() |
49ba276f5d | ||
![]() |
2bfe9e236b | ||
![]() |
05fd258afd | ||
![]() |
3b3098e017 | ||
![]() |
ddf9eed3a5 | ||
![]() |
712f0a8256 | ||
![]() |
a93220f9d2 | ||
![]() |
253cee7458 | ||
![]() |
82f9a4c63f | ||
![]() |
de6c8a5558 | ||
![]() |
c75337b8cb | ||
![]() |
2b796e33fe | ||
![]() |
175307d980 | ||
![]() |
993f8a9e8f | ||
![]() |
0130b8f6f7 | ||
![]() |
ba482d492f | ||
![]() |
6e71cd6064 | ||
![]() |
83dc1abd4a | ||
![]() |
4cabb9696e | ||
![]() |
75883e9cae | ||
![]() |
eeadaa12e9 | ||
![]() |
192736c8be | ||
![]() |
586fbb6518 | ||
![]() |
0a42e2df5b | ||
![]() |
97a637f0c6 | ||
![]() |
3f10b7a002 | ||
![]() |
f638e48260 | ||
![]() |
354ee389bc | ||
![]() |
7188946d7a | ||
![]() |
53055e9eab | ||
![]() |
7bdb84b11b | ||
![]() |
c906bcf7ea | ||
![]() |
cdc82562a3 | ||
![]() |
c34ce8ce0c | ||
![]() |
d1c94754ee | ||
![]() |
2626555c51 | ||
![]() |
66ca936148 | ||
![]() |
5088112864 | ||
![]() |
91075e192b | ||
![]() |
11108bc13f | ||
![]() |
3ec1134204 | ||
![]() |
de41dab846 | ||
![]() |
ededfe0f8c | ||
![]() |
6548876c74 | ||
![]() |
839fd7f1ab | ||
![]() |
2f9cd8ba19 | ||
![]() |
85d648622d | ||
![]() |
f08c816286 | ||
![]() |
6c267044f0 | ||
![]() |
b548fd3f0e | ||
![]() |
f110c2d3df | ||
![]() |
f521873ba7 | ||
![]() |
afe0ff89a7 |
20
.github/ISSUE_TEMPLATE/bug_report.md
vendored
20
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug反馈
|
|
||||||
about: 报个Bug
|
|
||||||
title: ''
|
|
||||||
labels: bug
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
QQ版本:
|
|
||||||
|
|
||||||
LLOneBot版本:
|
|
||||||
|
|
||||||
调用LLOneBot的方式或者应用端(如postman直接调用,或NoneBot2、Koishi):
|
|
||||||
|
|
||||||
BUG描述:
|
|
||||||
|
|
||||||
复现步骤:
|
|
||||||
|
|
||||||
LLOneBot日志:
|
|
81
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
81
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
name: Bug 反馈
|
||||||
|
description: 报告可能的 LLOneBot 异常行为
|
||||||
|
title: '[BUG] '
|
||||||
|
labels: bug
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
欢迎来到 LLOneBot 的 Issue Tracker!请填写以下表格来提交 Bug。
|
||||||
|
在提交新的 Bug 反馈前,请确保您:
|
||||||
|
* 已经搜索了现有的 issues,并且没有找到可以解决您问题的方法
|
||||||
|
* 不与现有的某一 issue 重复
|
||||||
|
- type: input
|
||||||
|
id: system-version
|
||||||
|
attributes:
|
||||||
|
label: 系统版本
|
||||||
|
description: 运行 QQNT 的系统版本
|
||||||
|
placeholder: Windows 10 Pro Workstation 22H2
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: qqnt-version
|
||||||
|
attributes:
|
||||||
|
label: QQNT 版本
|
||||||
|
description: 可在 QQNT 的「关于」或是在 LiteLoaderQQNT 的设置页中找到
|
||||||
|
placeholder: 9.9.7-21804
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: llonebot-version
|
||||||
|
attributes:
|
||||||
|
label: LLOneBot 版本
|
||||||
|
description: 可在 LiteLoaderQQNT 的设置页或是 QQNT 的设置页侧栏中找到
|
||||||
|
placeholder: 3.18.0
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: onebot-client-version
|
||||||
|
attributes:
|
||||||
|
label: OneBot 客户端
|
||||||
|
description: 连接至 LLOneBot 的客户端版本信息
|
||||||
|
placeholder: Overflow 2.16.0-2cf7991-SNAPSHOT
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: what-happened
|
||||||
|
attributes:
|
||||||
|
label: 发生了什么?
|
||||||
|
description: 填写你认为的 LLOneBot 的不正常行为
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: how-reproduce
|
||||||
|
attributes:
|
||||||
|
label: 如何复现
|
||||||
|
description: 填写应当如何操作才能触发这个不正常行为
|
||||||
|
placeholder: |
|
||||||
|
1. xxx
|
||||||
|
2. xxx
|
||||||
|
3. xxx
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: what-expected
|
||||||
|
attributes:
|
||||||
|
label: 期望的结果?
|
||||||
|
description: 填写你认为 LLOneBot 应当执行的正常行为
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: llonebot-log
|
||||||
|
attributes:
|
||||||
|
label: LLOneBot 运行日志
|
||||||
|
description: 在 LLOneBot 的设置页中打开「写入日志」然后粘贴相关日志内容到此处
|
||||||
|
render: shell
|
||||||
|
- type: textarea
|
||||||
|
id: onebot-client-log
|
||||||
|
attributes:
|
||||||
|
label: OneBot 客户端运行日志
|
||||||
|
description: 粘贴 OneBot 客户端的相关日志内容到此处
|
||||||
|
render: shell
|
178
README.md
178
README.md
@@ -1,175 +1,25 @@
|
|||||||
|
|
||||||
# LLOneBot API
|
# LLOneBot API
|
||||||
LiteLoaderQQNT的OneBot11协议插件
|
LiteLoaderQQNT插件,使你的NTQQ支持OneBot11协议进行QQ机器人开发
|
||||||
|
|
||||||
TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||||
|
|
||||||
*注意:本文档对应的是 LiteLoader 1.0.0及以上版本,如果你使用的是旧版本请切换到本项目v1分支查看文档*
|
|
||||||
|
|
||||||
*V3之后不再需要LLAPI*
|
|
||||||
|
|
||||||
## 安装方法
|
## 安装方法
|
||||||
|
|
||||||
### 通用手动安装方法
|
见 <https://llonebot.github.io/zh-CN/guide/getting-started>
|
||||||
|
|
||||||
1.安装[LiteLoaderQQNT](https://liteloaderqqnt.github.io/guide/install.html)
|
## 设置界面
|
||||||
|
|
||||||
2.安装本项目插件[LLOneBot](https://github.com/linyuchen/LiteLoaderQQNT-OneBotApi/releases/), 注意本插件2.0以下的版本不支持LiteLoader 1.0.0及以上版本
|
<img src="./doc/image/setting.png" width="500px" alt="图片名称"/>
|
||||||
|
|
||||||
*关于插件的安装方法: 下载后解压复制到插件目录*
|
## HTTP 调用示例
|
||||||
|
|
||||||
*插件目录:`LiteLoaderQQNT/plugins`*
|
|
||||||
|
|
||||||
安装后的目录结构如下
|
|
||||||
```
|
|
||||||
├── plugins
|
|
||||||
│ ├── LLOneBot
|
|
||||||
│ │ └── main/
|
|
||||||
│ │ └── preload/
|
|
||||||
│ │ └── renderer/
|
|
||||||
│ │ └── manifest.json
|
|
||||||
│ │ └── node_modules/...
|
|
||||||
```
|
|
||||||
|
|
||||||
### Linux 容器化快速安装
|
|
||||||
|
|
||||||
执行以下任意脚本,按照提示设置NoVnc密码,即可运行,脚本问题与异常参考 [llonebot-docker](https://github.com/MliKiowa/llonebot-docker) 项目。
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl https://cdn.jsdelivr.net/gh/LLOneBot/llonebot-docker/fastboot.sh -o fastboot.sh & chmod +x fastboot.sh & sudo sh fastboot.sh
|
|
||||||
```
|
|
||||||
```bash
|
|
||||||
wget -O fastboot.sh https://cdn.jsdelivr.net/gh/LLOneBot/llonebot-docker/fastboot.sh & chmod +x fastboot.sh & sudo sh fastboot.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
### 使用termux安装
|
|
||||||
|
|
||||||
具体安装过程与教程,参考 [llonebot-termux](https://github.com/LLOneBot/llonebot-termux) 项目。
|
|
||||||
|
|
||||||
## 支持的功能
|
|
||||||
|
|
||||||
目前支持的协议
|
|
||||||
- [x] http调用api
|
|
||||||
- [x] http事件上报,不支持快捷回复等快捷操作
|
|
||||||
- [x] 正向websocket
|
|
||||||
- [x] 反向websocket
|
|
||||||
|
|
||||||
主要功能:
|
|
||||||
- [x] 发送好友消息
|
|
||||||
- [x] 发送群消息
|
|
||||||
- [x] 获取好友列表
|
|
||||||
- [x] 获取群列表
|
|
||||||
- [x] 获取群成员列表
|
|
||||||
- [x] 撤回消息
|
|
||||||
- [x] 处理添加好友请求
|
|
||||||
- [x] 处理加群请求
|
|
||||||
- [x] 退群
|
|
||||||
- [x] 上报好友消息
|
|
||||||
- [x] 上报添加好友请求
|
|
||||||
- [x] 上报群消息
|
|
||||||
- [x] 上报好友、群消息撤回
|
|
||||||
- [x] 上报加群请求
|
|
||||||
- [x] 上报群员人数变动(尚不支持识别群员人数变动原因)
|
|
||||||
- [x] 设置群管理员
|
|
||||||
- [x] 群禁言/全体禁言
|
|
||||||
- [x] 群踢人
|
|
||||||
- [x] 群改群成员名片
|
|
||||||
- [x] 修改群名
|
|
||||||
|
|
||||||
消息格式支持:
|
|
||||||
- [x] cq码
|
|
||||||
- [x] 文字
|
|
||||||
- [x] 表情
|
|
||||||
- [x] 图片
|
|
||||||
- [x] 引用消息
|
|
||||||
- [x] @群成员
|
|
||||||
- [x] 语音(支持mp3、wav等多种音频格式直接发送)
|
|
||||||
- [x] json消息(只上报)
|
|
||||||
- [x] 转发消息记录(目前只能发不能收)
|
|
||||||
- [x] 视频(上报时暂时只有个空的file)
|
|
||||||
- [x] 文件(上报时暂时只有个空的file), type为file, data为{file: uri}, 发送时uri支持http://, file://, base64://
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"type": "file",
|
|
||||||
"data": {
|
|
||||||
"file": "file:///D:/1.txt",
|
|
||||||
"name": "自定义显示的文件名" // 此字段不是必须的
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- [ ] 发送音乐卡片
|
|
||||||
- [ ] 红包(没有计划支持)
|
|
||||||
- [ ] xml (没有计划支持)
|
|
||||||
|
|
||||||
## 示例
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 一些坑
|
## 支持的 api 和功能详情
|
||||||
|
|
||||||
<details>
|
见 <https://llonebot.github.io/zh-CN/develop/api>
|
||||||
<summary>下载了插件但是没有看到在NTQQ中生效</summary>
|
|
||||||
<br/>
|
|
||||||
检查是否下载的是插件release的版本,如果是源码的话需要自行编译。依然不生效请查阅<a href="https://liteloaderqqnt.github.io/guide/plugins.html">LiteLoaderQQNT的文档</a>
|
|
||||||
</details>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>调用接口报404</summary>
|
|
||||||
<br/>
|
|
||||||
目前没有支持全部的onebot规范接口,请检查是否调用了不支持的接口
|
|
||||||
-
|
|
||||||
</details>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>发送不了图片和语音</summary>
|
|
||||||
<br/>
|
|
||||||
检查当前操作用户是否有LiteLoaderQQNT/data/LLOneBot的写入权限,如Windows把QQ上安装到C盘有可能会出现无权限导致发送失败
|
|
||||||
</details>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>QQ变得很卡</summary>
|
|
||||||
<br/>
|
|
||||||
这是你的群特别多导致的,因为启动后会批量获取群成员列表,获取完之后就正常了
|
|
||||||
</details>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
## 支持的onebot v11 api:
|
|
||||||
- [x] get_login_info
|
|
||||||
- [x] send_msg
|
|
||||||
- [x] send_group_msg
|
|
||||||
- [x] send_private_msg
|
|
||||||
- [x] delete_msg
|
|
||||||
- [x] get_group_list
|
|
||||||
- [x] get_group_info
|
|
||||||
- [x] get_group_member_list
|
|
||||||
- [x] get_group_member_info
|
|
||||||
- [x] get_friend_list
|
|
||||||
- [x] set_friend_add_request
|
|
||||||
- [x] get_msg
|
|
||||||
- [x] send_like
|
|
||||||
- [x] set_group_add_request
|
|
||||||
- [x] set_group_leave
|
|
||||||
- [x] set_group_kick
|
|
||||||
- [x] set_group_ban
|
|
||||||
- [x] set_group_whole_ban
|
|
||||||
- [x] set_group_kick
|
|
||||||
- [x] set_group_admin
|
|
||||||
- [x] set_group_card
|
|
||||||
- [x] set_group_name
|
|
||||||
- [x] get_version_info
|
|
||||||
- [x] get_status
|
|
||||||
- [x] can_send_image
|
|
||||||
- [x] can_send_record
|
|
||||||
- [x] get_image
|
|
||||||
- [x] get_record
|
|
||||||
|
|
||||||
### 支持的go-cqhtp api:
|
|
||||||
- [x] send_private_forward_msg
|
|
||||||
- [x] send_group_forward_msg
|
|
||||||
- [x] get_stranger_info
|
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
- [x] 重构摆脱LLAPI,目前调用LLAPI只能在renderer进程调用,需重构成在main进程调用
|
- [x] 重构摆脱LLAPI,目前调用LLAPI只能在renderer进程调用,需重构成在main进程调用
|
||||||
@@ -179,14 +29,24 @@ wget -O fastboot.sh https://cdn.jsdelivr.net/gh/LLOneBot/llonebot-docker/fastboo
|
|||||||
- [x] 群管理功能,禁言、踢人,改群名片等
|
- [x] 群管理功能,禁言、踢人,改群名片等
|
||||||
- [x] 视频消息
|
- [x] 视频消息
|
||||||
- [x] 文件消息
|
- [x] 文件消息
|
||||||
- [ ] 音乐卡片
|
- [x] 群禁言事件上报
|
||||||
|
- [x] 优化加群成功事件上报
|
||||||
|
- [x] 清理缓存api
|
||||||
- [ ] 无头模式
|
- [ ] 无头模式
|
||||||
|
- [ ] 框架对接文档
|
||||||
|
|
||||||
## onebot11文档
|
## onebot11文档
|
||||||
<https://11.onebot.dev/>
|
<https://11.onebot.dev/>
|
||||||
|
|
||||||
|
## Stargazers over time
|
||||||
|
[](https://starchart.cc/LLOneBot/LLOneBot)
|
||||||
|
|
||||||
|
|
||||||
## 鸣谢
|
## 鸣谢
|
||||||
* [LiteLoaderQQNT](https://liteloaderqqnt.github.io/guide/install.html)
|
* [LiteLoaderQQNT](https://liteloaderqqnt.github.io/guide/install.html)
|
||||||
* [LLAPI](https://github.com/Night-stars-1/LiteLoaderQQNT-Plugin-LLAPI)
|
* [LLAPI](https://github.com/Night-stars-1/LiteLoaderQQNT-Plugin-LLAPI)
|
||||||
* chronocat
|
* [chronocat](https://github.com/chrononeko/chronocat/)
|
||||||
* [koishi-plugin-adapter-onebot](https://github.com/koishijs/koishi-plugin-adapter-onebot)
|
* [koishi-plugin-adapter-onebot](https://github.com/koishijs/koishi-plugin-adapter-onebot)
|
||||||
|
|
||||||
|
## 友链
|
||||||
|
* [Lagrange.Core](https://github.com/LagrangeDev/Lagrange.Core) 一款用C#实现的NTQQ纯协议跨平台QQ机器人框架
|
||||||
|
BIN
doc/image/setting.png
Normal file
BIN
doc/image/setting.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
@@ -6,7 +6,7 @@ const external = ["silk-wasm", "ws",
|
|||||||
"module-error", "catering", "node-gyp-build"];
|
"module-error", "catering", "node-gyp-build"];
|
||||||
|
|
||||||
function genCpModule(module: string) {
|
function genCpModule(module: string) {
|
||||||
return { src: `./node_modules/${module}`, dest: `dist/node_modules/${module}`, flatten: false }
|
return {src: `./node_modules/${module}`, dest: `dist/node_modules/${module}`, flatten: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
@@ -16,19 +16,25 @@ let config = {
|
|||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
lib: {
|
lib: {
|
||||||
formats: ["cjs"],
|
formats: ["cjs"],
|
||||||
entry: { "main": "src/main/main.ts" },
|
entry: {"main": "src/main/main.ts"},
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external,
|
external,
|
||||||
input: "src/main/main.ts",
|
input: "src/main/main.ts",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolve:{
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg'
|
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [cp({ targets: [...external.map(genCpModule), { src: './manifest.json', dest: 'dist' }] })]
|
plugins: [cp({
|
||||||
|
targets: [
|
||||||
|
...external.map(genCpModule),
|
||||||
|
{src: './manifest.json', dest: 'dist'}, {src: './icon.jpg', dest: 'dist'},
|
||||||
|
{src: './src/ntqqapi/external/ccpoke/poke-win32-x64.node', dest: 'dist/main/ccpoke/'},
|
||||||
|
]
|
||||||
|
})]
|
||||||
},
|
},
|
||||||
preload: {
|
preload: {
|
||||||
// vite config options
|
// vite config options
|
||||||
@@ -37,15 +43,14 @@ let config = {
|
|||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
lib: {
|
lib: {
|
||||||
formats: ["cjs"],
|
formats: ["cjs"],
|
||||||
entry: { "preload": "src/preload.ts" },
|
entry: {"preload": "src/preload.ts"},
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
// external: externalAll,
|
// external: externalAll,
|
||||||
input: "src/preload.ts",
|
input: "src/preload.ts",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolve:{
|
resolve: {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
renderer: {
|
renderer: {
|
||||||
// vite config options
|
// vite config options
|
||||||
@@ -54,15 +59,14 @@ let config = {
|
|||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
lib: {
|
lib: {
|
||||||
formats: ["es"],
|
formats: ["es"],
|
||||||
entry: { "renderer": "src/renderer/index.ts" },
|
entry: {"renderer": "src/renderer/index.ts"},
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
// external: externalAll,
|
// external: externalAll,
|
||||||
input: "src/renderer/index.ts",
|
input: "src/renderer/index.ts",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolve:{
|
resolve: {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 4,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot v3.13.8",
|
"name": "LLOneBot v3.19.1",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
||||||
"version": "3.13.8",
|
"version": "3.19.1",
|
||||||
"thumbnail": "./icon.png",
|
"icon": "./icon.jpg",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
|
241
package-lock.json
generated
241
package-lock.json
generated
@@ -9,11 +9,12 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"compressing": "^1.10.0",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
"silk-wasm": "^3.2.3",
|
"silk-wasm": "^3.3.3",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
@@ -550,6 +551,15 @@
|
|||||||
"@jridgewell/sourcemap-codec": "^1.4.10"
|
"@jridgewell/sourcemap-codec": "^1.4.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@eggjs/yauzl": {
|
||||||
|
"version": "2.11.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/@eggjs/yauzl/-/yauzl-2.11.0.tgz",
|
||||||
|
"integrity": "sha512-Jq+k2fCZJ3i3HShb0nxLUiAgq5pwo8JTT1TrH22JoehZQ0Nm2dvByGIja1NYfNyuE4Tx5/Dns5nVsBN/mlC8yg==",
|
||||||
|
"dependencies": {
|
||||||
|
"buffer-crc32": "~0.2.3",
|
||||||
|
"fd-slicer2": "^1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@electron/get": {
|
"node_modules/@electron/get": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/@electron/get/-/get-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@electron/get/-/get-2.0.3.tgz",
|
||||||
@@ -2150,6 +2160,47 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"node_modules/bl": {
|
||||||
|
"version": "1.2.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/bl/-/bl-1.2.3.tgz",
|
||||||
|
"integrity": "sha512-pvcNpa0UU69UT341rO6AYy4FVAIkUHuZXRIWbq+zHnsVcRzDDjIAhGuuYoi0d//cwIwtt4pkpKycWEfjdV+vww==",
|
||||||
|
"dependencies": {
|
||||||
|
"readable-stream": "^2.3.5",
|
||||||
|
"safe-buffer": "^5.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/bl/node_modules/isarray": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/isarray/-/isarray-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
|
||||||
|
},
|
||||||
|
"node_modules/bl/node_modules/readable-stream": {
|
||||||
|
"version": "2.3.8",
|
||||||
|
"resolved": "https://registry.npmmirror.com/readable-stream/-/readable-stream-2.3.8.tgz",
|
||||||
|
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
||||||
|
"dependencies": {
|
||||||
|
"core-util-is": "~1.0.0",
|
||||||
|
"inherits": "~2.0.3",
|
||||||
|
"isarray": "~1.0.0",
|
||||||
|
"process-nextick-args": "~2.0.0",
|
||||||
|
"safe-buffer": "~5.1.1",
|
||||||
|
"string_decoder": "~1.1.1",
|
||||||
|
"util-deprecate": "~1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/bl/node_modules/safe-buffer": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
|
},
|
||||||
|
"node_modules/bl/node_modules/string_decoder": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||||
|
"dependencies": {
|
||||||
|
"safe-buffer": "~5.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/body-parser": {
|
"node_modules/body-parser": {
|
||||||
"version": "1.20.2",
|
"version": "1.20.2",
|
||||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
|
||||||
@@ -2280,15 +2331,33 @@
|
|||||||
"ieee754": "^1.2.1"
|
"ieee754": "^1.2.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/buffer-alloc": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/buffer-alloc/-/buffer-alloc-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==",
|
||||||
|
"dependencies": {
|
||||||
|
"buffer-alloc-unsafe": "^1.1.0",
|
||||||
|
"buffer-fill": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/buffer-alloc-unsafe": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg=="
|
||||||
|
},
|
||||||
"node_modules/buffer-crc32": {
|
"node_modules/buffer-crc32": {
|
||||||
"version": "0.2.13",
|
"version": "0.2.13",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
|
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
|
||||||
"integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==",
|
"integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "*"
|
"node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/buffer-fill": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/buffer-fill/-/buffer-fill-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-T7zexNBwiiaCOGDg9xNX9PBmjrubblRkENuptryuI64URkXDFum9il/JGL8Lm8wYfAXpredVXXZz7eMHilimiQ=="
|
||||||
|
},
|
||||||
"node_modules/buffer-from": {
|
"node_modules/buffer-from": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/buffer-from/-/buffer-from-1.1.2.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||||
@@ -2514,6 +2583,36 @@
|
|||||||
"optional": true,
|
"optional": true,
|
||||||
"peer": true
|
"peer": true
|
||||||
},
|
},
|
||||||
|
"node_modules/compressing": {
|
||||||
|
"version": "1.10.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/compressing/-/compressing-1.10.0.tgz",
|
||||||
|
"integrity": "sha512-k2vpbZLaJoHe9euyUZjYYE8vOrbR19aU3HcWIYw5EBXiUs34ygfDVnXU+ubI41JXMriHutnoiu0ZFdwCkH6jPA==",
|
||||||
|
"dependencies": {
|
||||||
|
"@eggjs/yauzl": "^2.11.0",
|
||||||
|
"flushwritable": "^1.0.0",
|
||||||
|
"get-ready": "^1.0.0",
|
||||||
|
"iconv-lite": "^0.5.0",
|
||||||
|
"mkdirp": "^0.5.1",
|
||||||
|
"pump": "^3.0.0",
|
||||||
|
"streamifier": "^0.1.1",
|
||||||
|
"tar-stream": "^1.5.2",
|
||||||
|
"yazl": "^2.4.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/compressing/node_modules/iconv-lite": {
|
||||||
|
"version": "0.5.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.5.2.tgz",
|
||||||
|
"integrity": "sha512-kERHXvpSaB4aU3eANwidg79K8FlrN77m8G9V+0vOR3HYaRifrlwMEpT7ZBJqLSEIHnEgJTHcWK82wwLwwKwtag==",
|
||||||
|
"dependencies": {
|
||||||
|
"safer-buffer": ">= 2.1.2 < 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/concat-map": {
|
"node_modules/concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
@@ -2558,6 +2657,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
|
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/core-util-is": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmmirror.com/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||||
|
},
|
||||||
"node_modules/create-require": {
|
"node_modules/create-require": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/create-require/-/create-require-1.1.1.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/create-require/-/create-require-1.1.1.tgz",
|
||||||
@@ -2812,7 +2916,6 @@
|
|||||||
"version": "1.4.4",
|
"version": "1.4.4",
|
||||||
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
|
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
|
||||||
"integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
|
"integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"once": "^1.4.0"
|
"once": "^1.4.0"
|
||||||
}
|
}
|
||||||
@@ -3635,6 +3738,14 @@
|
|||||||
"pend": "~1.2.0"
|
"pend": "~1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fd-slicer2": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/fd-slicer2/-/fd-slicer2-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-3lBUNUckhMZduCc4g+Pw4Ve16LD9vpX9b8qUkkKq2mgDRLYWzblszZH2luADnJqjJe+cypngjCuKRm/IW12rRw==",
|
||||||
|
"dependencies": {
|
||||||
|
"pend": "^1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/file-entry-cache": {
|
"node_modules/file-entry-cache": {
|
||||||
"version": "6.0.1",
|
"version": "6.0.1",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/file-entry-cache/-/file-entry-cache-6.0.1.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/file-entry-cache/-/file-entry-cache-6.0.1.tgz",
|
||||||
@@ -3737,6 +3848,11 @@
|
|||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/flushwritable": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/flushwritable/-/flushwritable-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-3VELfuWCLVzt5d2Gblk8qcqFro6nuwvxwMzHaENVDHI7rxcBRtMCwTk/E9FXcgh+82DSpavPNDueA9+RxXJoFg=="
|
||||||
|
},
|
||||||
"node_modules/for-each": {
|
"node_modules/for-each": {
|
||||||
"version": "0.3.3",
|
"version": "0.3.3",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/for-each/-/for-each-0.3.3.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/for-each/-/for-each-0.3.3.tgz",
|
||||||
@@ -3762,6 +3878,11 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fs-constants": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/fs-constants/-/fs-constants-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow=="
|
||||||
|
},
|
||||||
"node_modules/fs-extra": {
|
"node_modules/fs-extra": {
|
||||||
"version": "8.1.0",
|
"version": "8.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
||||||
@@ -3858,6 +3979,11 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/get-ready": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/get-ready/-/get-ready-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-mFXCZPJIlcYcth+N8267+mghfYN9h3EhsDa6JSnbA3Wrhh/XFpuowviFcsDeYZtKspQyWyJqfs4O6P8CHeTwzw=="
|
||||||
|
},
|
||||||
"node_modules/get-stream": {
|
"node_modules/get-stream": {
|
||||||
"version": "5.2.0",
|
"version": "5.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
|
||||||
@@ -4858,11 +4984,21 @@
|
|||||||
"version": "1.2.8",
|
"version": "1.2.8",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/minimist/-/minimist-1.2.8.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/minimist/-/minimist-1.2.8.tgz",
|
||||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||||
"dev": true,
|
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/mkdirp": {
|
||||||
|
"version": "0.5.6",
|
||||||
|
"resolved": "https://registry.npmmirror.com/mkdirp/-/mkdirp-0.5.6.tgz",
|
||||||
|
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
||||||
|
"dependencies": {
|
||||||
|
"minimist": "^1.2.6"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"mkdirp": "bin/cmd.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/module-error": {
|
"node_modules/module-error": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/module-error/-/module-error-1.0.2.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/module-error/-/module-error-1.0.2.tgz",
|
||||||
@@ -5039,7 +5175,6 @@
|
|||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
|
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"wrappy": "1"
|
"wrappy": "1"
|
||||||
}
|
}
|
||||||
@@ -5152,8 +5287,7 @@
|
|||||||
"node_modules/pend": {
|
"node_modules/pend": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
|
||||||
"integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==",
|
"integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"node_modules/picocolors": {
|
"node_modules/picocolors": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
@@ -5219,6 +5353,11 @@
|
|||||||
"node": ">= 0.8.0"
|
"node": ">= 0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/process-nextick-args": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
|
||||||
|
},
|
||||||
"node_modules/progress": {
|
"node_modules/progress": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
|
||||||
@@ -5244,7 +5383,6 @@
|
|||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
||||||
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
|
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"end-of-stream": "^1.1.0",
|
"end-of-stream": "^1.1.0",
|
||||||
"once": "^1.3.1"
|
"once": "^1.3.1"
|
||||||
@@ -5757,9 +5895,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/silk-wasm": {
|
"node_modules/silk-wasm": {
|
||||||
"version": "3.2.3",
|
"version": "3.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.3.3.tgz",
|
||||||
"integrity": "sha512-zZ3hgMpiPR6cFnKvCPgPpCwx6n5RoJCbEGIFlge2kAxAmgzBTf0b2F2xIPG5W4obUhQPQXXTTH074eGZJK01xw=="
|
"integrity": "sha512-9Qj93EtiIuBNkDyEwlPntabEtrm6Xu6LE4y9qZvomvo5+IsXFcXSy+N55kV22OehUTBYlZqOZYtRggA8G9IDGg=="
|
||||||
},
|
},
|
||||||
"node_modules/slash": {
|
"node_modules/slash": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
@@ -5820,6 +5958,14 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/streamifier": {
|
||||||
|
"version": "0.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/streamifier/-/streamifier-0.1.1.tgz",
|
||||||
|
"integrity": "sha512-zDgl+muIlWzXNsXeyUfOk9dChMjlpkq0DRsxujtYPgyJ676yQ8jEm6zzaaWHFDg5BNcLuif0eD2MTyJdZqXpdg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/string_decoder": {
|
"node_modules/string_decoder": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||||
@@ -5946,6 +6092,55 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tar-stream": {
|
||||||
|
"version": "1.6.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/tar-stream/-/tar-stream-1.6.2.tgz",
|
||||||
|
"integrity": "sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==",
|
||||||
|
"dependencies": {
|
||||||
|
"bl": "^1.0.0",
|
||||||
|
"buffer-alloc": "^1.2.0",
|
||||||
|
"end-of-stream": "^1.0.0",
|
||||||
|
"fs-constants": "^1.0.0",
|
||||||
|
"readable-stream": "^2.3.0",
|
||||||
|
"to-buffer": "^1.1.1",
|
||||||
|
"xtend": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tar-stream/node_modules/isarray": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/isarray/-/isarray-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
|
||||||
|
},
|
||||||
|
"node_modules/tar-stream/node_modules/readable-stream": {
|
||||||
|
"version": "2.3.8",
|
||||||
|
"resolved": "https://registry.npmmirror.com/readable-stream/-/readable-stream-2.3.8.tgz",
|
||||||
|
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
||||||
|
"dependencies": {
|
||||||
|
"core-util-is": "~1.0.0",
|
||||||
|
"inherits": "~2.0.3",
|
||||||
|
"isarray": "~1.0.0",
|
||||||
|
"process-nextick-args": "~2.0.0",
|
||||||
|
"safe-buffer": "~5.1.1",
|
||||||
|
"string_decoder": "~1.1.1",
|
||||||
|
"util-deprecate": "~1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tar-stream/node_modules/safe-buffer": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
|
},
|
||||||
|
"node_modules/tar-stream/node_modules/string_decoder": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||||
|
"dependencies": {
|
||||||
|
"safe-buffer": "~5.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/terser": {
|
"node_modules/terser": {
|
||||||
"version": "5.28.1",
|
"version": "5.28.1",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/terser/-/terser-5.28.1.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/terser/-/terser-5.28.1.tgz",
|
||||||
@@ -5972,6 +6167,11 @@
|
|||||||
"integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=",
|
"integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/to-buffer": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/to-buffer/-/to-buffer-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg=="
|
||||||
|
},
|
||||||
"node_modules/to-fast-properties": {
|
"node_modules/to-fast-properties": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
|
||||||
@@ -6515,8 +6715,7 @@
|
|||||||
"node_modules/wrappy": {
|
"node_modules/wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
|
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"node_modules/ws": {
|
"node_modules/ws": {
|
||||||
"version": "8.16.0",
|
"version": "8.16.0",
|
||||||
@@ -6538,6 +6737,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/xtend": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmmirror.com/xtend/-/xtend-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/yallist": {
|
"node_modules/yallist": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||||
@@ -6554,6 +6761,14 @@
|
|||||||
"fd-slicer": "~1.1.0"
|
"fd-slicer": "~1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/yazl": {
|
||||||
|
"version": "2.5.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/yazl/-/yazl-2.5.1.tgz",
|
||||||
|
"integrity": "sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw==",
|
||||||
|
"dependencies": {
|
||||||
|
"buffer-crc32": "~0.2.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/yn": {
|
"node_modules/yn": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/yn/-/yn-3.1.1.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/yn/-/yn-3.1.1.tgz",
|
||||||
|
@@ -9,16 +9,17 @@
|
|||||||
"build-mac": "npm run build && npm run deploy-mac",
|
"build-mac": "npm run build && npm run deploy-mac",
|
||||||
"deploy-mac": "cp -r dist/* ~/Library/Containers/com.tencent.qq/Data/LiteLoaderQQNT/plugins/LLOneBot/",
|
"deploy-mac": "cp -r dist/* ~/Library/Containers/com.tencent.qq/Data/LiteLoaderQQNT/plugins/LLOneBot/",
|
||||||
"build-win": "npm run build && npm run deploy-win",
|
"build-win": "npm run build && npm run deploy-win",
|
||||||
"deploy-win": "cmd /c \"xcopy /S /Y dist\\* %USERPROFILE%\\documents\\LiteLoaderQQNT\\plugins\\LLOneBot\\\""
|
"deploy-win": "cmd /c \"xcopy /C /S /Y dist\\* %USERPROFILE%\\documents\\LiteLoaderQQNT\\plugins\\LLOneBot\\\""
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"compressing": "^1.10.0",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
"silk-wasm": "^3.2.3",
|
"silk-wasm": "^3.3.3",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
|
17
scripts/test/test_db.ts
Normal file
17
scripts/test/test_db.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import {Level} from "level"
|
||||||
|
|
||||||
|
const db = new Level(process.env["level_db_path"], {valueEncoding: 'json'});
|
||||||
|
|
||||||
|
async function getGroupNotify() {
|
||||||
|
let keys = await db.keys().all();
|
||||||
|
let result = []
|
||||||
|
for (const key of keys) {
|
||||||
|
// console.log(key)
|
||||||
|
if (key.startsWith("group_notify_")) {
|
||||||
|
result.push(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
getGroupNotify().then(console.log)
|
@@ -2,4 +2,6 @@ export const CHANNEL_GET_CONFIG = 'llonebot_get_config'
|
|||||||
export const CHANNEL_SET_CONFIG = 'llonebot_set_config'
|
export const CHANNEL_SET_CONFIG = 'llonebot_set_config'
|
||||||
export const CHANNEL_LOG = 'llonebot_log'
|
export const CHANNEL_LOG = 'llonebot_log'
|
||||||
export const CHANNEL_ERROR = 'llonebot_error'
|
export const CHANNEL_ERROR = 'llonebot_error'
|
||||||
|
export const CHANNEL_UPDATE = 'llonebot_update'
|
||||||
|
export const CHANNEL_CHECK_VERSION = 'llonebot_check_version'
|
||||||
export const CHANNEL_SELECT_FILE = 'llonebot_select_ffmpeg'
|
export const CHANNEL_SELECT_FILE = 'llonebot_select_ffmpeg'
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import {Config, OB11Config} from './types';
|
import {Config, OB11Config} from './types';
|
||||||
import {mergeNewProperties} from "./utils";
|
|
||||||
|
import {mergeNewProperties} from "./utils/helper";
|
||||||
|
import path from "node:path";
|
||||||
|
import {selfInfo} from "./data";
|
||||||
|
import {DATA_DIR} from "./utils";
|
||||||
|
|
||||||
export const HOOK_LOG = false;
|
export const HOOK_LOG = false;
|
||||||
|
|
||||||
@@ -26,6 +30,7 @@ export class ConfigUtil {
|
|||||||
let ob11Default: OB11Config = {
|
let ob11Default: OB11Config = {
|
||||||
httpPort: 3000,
|
httpPort: 3000,
|
||||||
httpHosts: [],
|
httpHosts: [],
|
||||||
|
httpSecret: "",
|
||||||
wsPort: 3001,
|
wsPort: 3001,
|
||||||
wsHosts: [],
|
wsHosts: [],
|
||||||
enableHttp: true,
|
enableHttp: true,
|
||||||
@@ -44,6 +49,7 @@ export class ConfigUtil {
|
|||||||
reportSelfMessage: false,
|
reportSelfMessage: false,
|
||||||
autoDeleteFile: false,
|
autoDeleteFile: false,
|
||||||
autoDeleteFileSecond: 60,
|
autoDeleteFileSecond: 60,
|
||||||
|
enablePoke: false
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!fs.existsSync(this.configPath)) {
|
if (!fs.existsSync(this.configPath)) {
|
||||||
@@ -84,3 +90,8 @@ export class ConfigUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getConfigUtil() {
|
||||||
|
const configFilePath = path.join(DATA_DIR, `config_${selfInfo.uin}.json`)
|
||||||
|
return new ConfigUtil(configFilePath)
|
||||||
|
}
|
@@ -1,17 +1,14 @@
|
|||||||
import {NTQQApi} from '../ntqqapi/ntcall'
|
|
||||||
import {
|
import {
|
||||||
type Friend,
|
type Friend,
|
||||||
type FriendRequest,
|
type FriendRequest,
|
||||||
type Group,
|
type Group,
|
||||||
type GroupMember,
|
type GroupMember,
|
||||||
type GroupNotify,
|
|
||||||
type RawMessage,
|
|
||||||
type SelfInfo
|
type SelfInfo
|
||||||
} from '../ntqqapi/types'
|
} from '../ntqqapi/types'
|
||||||
import {type FileCache, type LLOneBotError} from './types'
|
import {type FileCache, type LLOneBotError} from './types'
|
||||||
import {dbUtil} from "./db";
|
import {NTQQGroupApi} from "../ntqqapi/api/group";
|
||||||
import {raw} from "express";
|
import {log} from "./utils/log";
|
||||||
import {log} from "./utils";
|
import {isNumeric} from "./utils/helper";
|
||||||
|
|
||||||
export const selfInfo: SelfInfo = {
|
export const selfInfo: SelfInfo = {
|
||||||
uid: '',
|
uid: '',
|
||||||
@@ -21,17 +18,18 @@ export const selfInfo: SelfInfo = {
|
|||||||
}
|
}
|
||||||
export let groups: Group[] = []
|
export let groups: Group[] = []
|
||||||
export let friends: Friend[] = []
|
export let friends: Friend[] = []
|
||||||
export let groupNotifies: Map<string, GroupNotify> = new Map<string, GroupNotify>()
|
|
||||||
export let friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>()
|
export let friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>()
|
||||||
export const llonebotError: LLOneBotError = {
|
export const llonebotError: LLOneBotError = {
|
||||||
ffmpegError: '',
|
ffmpegError: '',
|
||||||
otherError: ''
|
httpServerError: '',
|
||||||
|
wsServerError: '',
|
||||||
|
otherError: 'LLOnebot未能正常启动,请检查日志查看错误'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getFriend(qq: string, uid: string = ""): Promise<Friend | undefined> {
|
export async function getFriend(uinOrUid: string): Promise<Friend | undefined> {
|
||||||
let filterKey = uid ? "uid" : "uin"
|
let filterKey = isNumeric(uinOrUid) ? "uin" : "uid"
|
||||||
let filterValue = uid ? uid : qq
|
let filterValue = uinOrUid
|
||||||
let friend = friends.find(friend => friend[filterKey] === filterValue.toString())
|
let friend = friends.find(friend => friend[filterKey] === filterValue.toString())
|
||||||
// if (!friend) {
|
// if (!friend) {
|
||||||
// try {
|
// try {
|
||||||
@@ -48,7 +46,7 @@ export async function getGroup(qq: string): Promise<Group | undefined> {
|
|||||||
let group = groups.find(group => group.groupCode === qq.toString())
|
let group = groups.find(group => group.groupCode === qq.toString())
|
||||||
if (!group) {
|
if (!group) {
|
||||||
try {
|
try {
|
||||||
const _groups = await NTQQApi.getGroups(true);
|
const _groups = await NTQQGroupApi.getGroups(true);
|
||||||
group = _groups.find(group => group.groupCode === qq.toString())
|
group = _groups.find(group => group.groupCode === qq.toString())
|
||||||
if (group) {
|
if (group) {
|
||||||
groups.push(group)
|
groups.push(group)
|
||||||
@@ -60,20 +58,18 @@ export async function getGroup(qq: string): Promise<Group | undefined> {
|
|||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroupMember(groupQQ: string | number, memberQQ: string | number, memberUid: string = null) {
|
export async function getGroupMember(groupQQ: string | number, memberUinOrUid: string | number) {
|
||||||
groupQQ = groupQQ.toString()
|
groupQQ = groupQQ.toString()
|
||||||
if (memberQQ) {
|
memberUinOrUid = memberUinOrUid.toString()
|
||||||
memberQQ = memberQQ.toString()
|
|
||||||
}
|
|
||||||
const group = await getGroup(groupQQ)
|
const group = await getGroup(groupQQ)
|
||||||
if (group) {
|
if (group) {
|
||||||
const filterKey = memberQQ ? "uin" : "uid"
|
const filterKey = isNumeric(memberUinOrUid) ? "uin" : "uid"
|
||||||
const filterValue = memberQQ ? memberQQ : memberUid
|
const filterValue = memberUinOrUid
|
||||||
let filterFunc: (member: GroupMember) => boolean = member => member[filterKey] === filterValue
|
let filterFunc: (member: GroupMember) => boolean = member => member[filterKey] === filterValue
|
||||||
let member = group.members?.find(filterFunc)
|
let member = group.members?.find(filterFunc)
|
||||||
if (!member) {
|
if (!member) {
|
||||||
try {
|
try {
|
||||||
const _members = await NTQQApi.getGroupMembers(groupQQ)
|
const _members = await NTQQGroupApi.getGroupMembers(groupQQ)
|
||||||
if (_members.length > 0) {
|
if (_members.length > 0) {
|
||||||
group.members = _members
|
group.members = _members
|
||||||
}
|
}
|
||||||
@@ -91,7 +87,7 @@ export async function getGroupMember(groupQQ: string | number, memberQQ: string
|
|||||||
export async function refreshGroupMembers(groupQQ: string) {
|
export async function refreshGroupMembers(groupQQ: string) {
|
||||||
const group = groups.find(group => group.groupCode === groupQQ)
|
const group = groups.find(group => group.groupCode === groupQQ)
|
||||||
if (group) {
|
if (group) {
|
||||||
group.members = await NTQQApi.getGroupMembers(groupQQ)
|
group.members = await NTQQGroupApi.getGroupMembers(groupQQ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
165
src/common/db.ts
165
src/common/db.ts
@@ -1,17 +1,21 @@
|
|||||||
import {Level} from "level";
|
import {Level} from "level";
|
||||||
import {RawMessage} from "../ntqqapi/types";
|
import {type GroupNotify, RawMessage} from "../ntqqapi/types";
|
||||||
import {DATA_DIR, log} from "./utils";
|
import {DATA_DIR} from "./utils";
|
||||||
import {selfInfo} from "./data";
|
import {selfInfo} from "./data";
|
||||||
import {FileCache} from "./types";
|
import {FileCache} from "./types";
|
||||||
|
import {log} from "./utils/log";
|
||||||
|
|
||||||
|
type ReceiveTempUinMap = Record<string, string>;
|
||||||
|
|
||||||
class DBUtil {
|
class DBUtil {
|
||||||
private readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
public readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
||||||
private readonly DB_KEY_PREFIX_MSG_SHORT_ID = "msg_short_id_";
|
public readonly DB_KEY_PREFIX_MSG_SHORT_ID = "msg_short_id_";
|
||||||
private readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
public readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
||||||
private readonly DB_KEY_PREFIX_FILE = "file_";
|
public readonly DB_KEY_PREFIX_FILE = "file_";
|
||||||
private db: Level;
|
public readonly DB_KEY_PREFIX_GROUP_NOTIFY = "group_notify_";
|
||||||
private cache: Record<string, RawMessage | string | FileCache> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
private readonly DB_KEY_RECEIVED_TEMP_UIN_MAP = "received_temp_uin_map";
|
||||||
|
public db: Level;
|
||||||
|
public cache: Record<string, RawMessage | string | FileCache | GroupNotify | ReceiveTempUinMap> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
||||||
private currentShortId: number;
|
private currentShortId: number;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -47,11 +51,36 @@ class DBUtil {
|
|||||||
}
|
}
|
||||||
initDB();
|
initDB();
|
||||||
}).then()
|
}).then()
|
||||||
|
|
||||||
|
const expiredMilliSecond = 1000 * 60 * 60;
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
this.cache = {}
|
// this.cache = {}
|
||||||
}, 1000 * 60 * 10)
|
// 清理时间较久的缓存
|
||||||
|
const now = Date.now()
|
||||||
|
for (let key in this.cache) {
|
||||||
|
let message: RawMessage = this.cache[key] as RawMessage;
|
||||||
|
if (message?.msgTime){
|
||||||
|
if ((now - (parseInt(message.msgTime) * 1000)) > expiredMilliSecond) {
|
||||||
|
delete this.cache[key]
|
||||||
|
// log("clear cache", key, message.msgTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, expiredMilliSecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getReceivedTempUinMap(): Promise<ReceiveTempUinMap> {
|
||||||
|
try{
|
||||||
|
this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] = JSON.parse(await this.db.get(this.DB_KEY_RECEIVED_TEMP_UIN_MAP));
|
||||||
|
}catch (e) {
|
||||||
|
}
|
||||||
|
return (this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] || {}) as ReceiveTempUinMap;
|
||||||
|
}
|
||||||
|
public setReceivedTempUinMap(data: ReceiveTempUinMap) {
|
||||||
|
this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] = data;
|
||||||
|
this.db.put(this.DB_KEY_RECEIVED_TEMP_UIN_MAP, JSON.stringify(data)).then();
|
||||||
|
}
|
||||||
private addCache(msg: RawMessage) {
|
private addCache(msg: RawMessage) {
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + msg.msgShortId
|
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + msg.msgShortId
|
||||||
@@ -59,15 +88,24 @@ class DBUtil {
|
|||||||
this.cache[longIdKey] = this.cache[shortIdKey] = msg
|
this.cache[longIdKey] = this.cache[shortIdKey] = msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public clearCache() {
|
||||||
|
this.cache = {}
|
||||||
|
}
|
||||||
|
|
||||||
async getMsgByShortId(shortMsgId: number): Promise<RawMessage> {
|
async getMsgByShortId(shortMsgId: number): Promise<RawMessage> {
|
||||||
const shortMsgIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
const shortMsgIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
||||||
if (this.cache[shortMsgIdKey]) {
|
if (this.cache[shortMsgIdKey]) {
|
||||||
|
// log("getMsgByShortId cache", shortMsgIdKey, this.cache[shortMsgIdKey])
|
||||||
return this.cache[shortMsgIdKey] as RawMessage
|
return this.cache[shortMsgIdKey] as RawMessage
|
||||||
}
|
}
|
||||||
const longId = await this.db.get(shortMsgIdKey);
|
try {
|
||||||
const msg = await this.getMsgByLongId(longId)
|
const longId = await this.db.get(shortMsgIdKey);
|
||||||
this.addCache(msg)
|
const msg = await this.getMsgByLongId(longId)
|
||||||
return msg
|
this.addCache(msg)
|
||||||
|
return msg
|
||||||
|
} catch (e) {
|
||||||
|
log("getMsgByShortId db error", e.stack.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMsgByLongId(longId: string): Promise<RawMessage> {
|
async getMsgByLongId(longId: string): Promise<RawMessage> {
|
||||||
@@ -75,10 +113,14 @@ class DBUtil {
|
|||||||
if (this.cache[longIdKey]) {
|
if (this.cache[longIdKey]) {
|
||||||
return this.cache[longIdKey] as RawMessage
|
return this.cache[longIdKey] as RawMessage
|
||||||
}
|
}
|
||||||
const data = await this.db.get(longIdKey)
|
try {
|
||||||
const msg = JSON.parse(data)
|
const data = await this.db.get(longIdKey)
|
||||||
this.addCache(msg)
|
const msg = JSON.parse(data)
|
||||||
return msg
|
this.addCache(msg)
|
||||||
|
return msg
|
||||||
|
} catch (e) {
|
||||||
|
// log("getMsgByLongId db error", e.stack.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMsgBySeqId(seqId: string): Promise<RawMessage> {
|
async getMsgBySeqId(seqId: string): Promise<RawMessage> {
|
||||||
@@ -86,10 +128,14 @@ class DBUtil {
|
|||||||
if (this.cache[seqIdKey]) {
|
if (this.cache[seqIdKey]) {
|
||||||
return this.cache[seqIdKey] as RawMessage
|
return this.cache[seqIdKey] as RawMessage
|
||||||
}
|
}
|
||||||
const longId = await this.db.get(seqIdKey);
|
try {
|
||||||
const msg = await this.getMsgByLongId(longId)
|
const longId = await this.db.get(seqIdKey);
|
||||||
this.addCache(msg)
|
const msg = await this.getMsgByLongId(longId)
|
||||||
return msg
|
this.addCache(msg)
|
||||||
|
return msg
|
||||||
|
} catch (e) {
|
||||||
|
log("getMsgBySeqId db error", e.stack.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addMsg(msg: RawMessage) {
|
async addMsg(msg: RawMessage) {
|
||||||
@@ -101,7 +147,7 @@ class DBUtil {
|
|||||||
try {
|
try {
|
||||||
existMsg = await this.getMsgByLongId(msg.msgId)
|
existMsg = await this.getMsgByLongId(msg.msgId)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// log("addMsg getMsgByLongId error", e.stack.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (existMsg) {
|
if (existMsg) {
|
||||||
@@ -109,29 +155,26 @@ class DBUtil {
|
|||||||
this.updateMsg(msg).then()
|
this.updateMsg(msg).then()
|
||||||
return existMsg.msgShortId
|
return existMsg.msgShortId
|
||||||
}
|
}
|
||||||
|
this.addCache(msg);
|
||||||
|
|
||||||
const shortMsgId = await this.genMsgShortId();
|
const shortMsgId = await this.genMsgShortId();
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
||||||
msg.msgShortId = shortMsgId;
|
msg.msgShortId = shortMsgId;
|
||||||
|
// log("新增消息记录", msg.msgId)
|
||||||
|
this.db.put(shortIdKey, msg.msgId).then().catch();
|
||||||
|
this.db.put(longIdKey, JSON.stringify(msg)).then().catch();
|
||||||
try {
|
try {
|
||||||
this.db.put(shortIdKey, msg.msgId).then();
|
await this.db.get(seqIdKey)
|
||||||
this.db.put(longIdKey, JSON.stringify(msg)).then();
|
|
||||||
try {
|
|
||||||
await this.db.get(seqIdKey)
|
|
||||||
} catch (e) {
|
|
||||||
// log("新的seqId", seqIdKey)
|
|
||||||
this.db.put(seqIdKey, msg.msgId).then();
|
|
||||||
}
|
|
||||||
this.cache[shortIdKey] = this.cache[longIdKey] = msg;
|
|
||||||
if (!this.cache[seqIdKey]) {
|
|
||||||
this.cache[seqIdKey] = msg;
|
|
||||||
}
|
|
||||||
// log(`消息入库 ${seqIdKey}: ${msg.msgId}, ${shortMsgId}: ${msg.msgId}`);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// log("addMsg db error", e.stack.toString());
|
// log("新的seqId", seqIdKey)
|
||||||
|
this.db.put(seqIdKey, msg.msgId).then().catch();
|
||||||
|
}
|
||||||
|
if (!this.cache[seqIdKey]) {
|
||||||
|
this.cache[seqIdKey] = msg;
|
||||||
}
|
}
|
||||||
return shortMsgId
|
return shortMsgId
|
||||||
|
// log(`消息入库 ${seqIdKey}: ${msg.msgId}, ${shortMsgId}: ${msg.msgId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateMsg(msg: RawMessage) {
|
async updateMsg(msg: RawMessage) {
|
||||||
@@ -146,17 +189,17 @@ class DBUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(existMsg, msg)
|
Object.assign(existMsg, msg)
|
||||||
this.db.put(longIdKey, JSON.stringify(existMsg)).then();
|
this.db.put(longIdKey, JSON.stringify(existMsg)).then().catch();
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + existMsg.msgShortId;
|
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + existMsg.msgShortId;
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
||||||
if (!this.cache[seqIdKey]) {
|
if (!this.cache[seqIdKey]) {
|
||||||
this.cache[seqIdKey] = existMsg;
|
this.cache[seqIdKey] = existMsg;
|
||||||
}
|
}
|
||||||
this.db.put(shortIdKey, msg.msgId).then();
|
this.db.put(shortIdKey, msg.msgId).then().catch();
|
||||||
try {
|
try {
|
||||||
await this.db.get(seqIdKey)
|
await this.db.get(seqIdKey)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.db.put(seqIdKey, msg.msgId).then();
|
this.db.put(seqIdKey, msg.msgId).then().catch();
|
||||||
// log("更新seqId error", e.stack, seqIdKey);
|
// log("更新seqId error", e.stack, seqIdKey);
|
||||||
}
|
}
|
||||||
// log("更新消息", existMsg.msgSeq, existMsg.msgShortId, existMsg.msgId);
|
// log("更新消息", existMsg.msgSeq, existMsg.msgShortId, existMsg.msgId);
|
||||||
@@ -175,32 +218,58 @@ class DBUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.currentShortId++;
|
this.currentShortId++;
|
||||||
await this.db.put(key, this.currentShortId.toString());
|
this.db.put(key, this.currentShortId.toString()).then().catch();
|
||||||
return this.currentShortId;
|
return this.currentShortId;
|
||||||
}
|
}
|
||||||
|
|
||||||
async addFileCache(fileName: string, data: FileCache) {
|
async addFileCache(fileNameOrUuid: string, data: FileCache) {
|
||||||
const key = this.DB_KEY_PREFIX_FILE + fileName;
|
const key = this.DB_KEY_PREFIX_FILE + fileNameOrUuid;
|
||||||
if (this.cache[key]) {
|
if (this.cache[key]) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let cacheDBData = {...data}
|
let cacheDBData = {...data}
|
||||||
delete cacheDBData['downloadFunc']
|
delete cacheDBData['downloadFunc']
|
||||||
this.cache[fileName] = data;
|
this.cache[fileNameOrUuid] = data;
|
||||||
await this.db.put(key, JSON.stringify(cacheDBData));
|
try {
|
||||||
|
await this.db.put(key, JSON.stringify(cacheDBData));
|
||||||
|
} catch (e) {
|
||||||
|
log("addFileCache db error", e.stack.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFileCache(fileName: string): Promise<FileCache | undefined> {
|
async getFileCache(fileNameOrUuid: string): Promise<FileCache | undefined> {
|
||||||
const key = this.DB_KEY_PREFIX_FILE + fileName;
|
const key = this.DB_KEY_PREFIX_FILE + (fileNameOrUuid);
|
||||||
if (this.cache[key]) {
|
if (this.cache[key]) {
|
||||||
return this.cache[key] as FileCache
|
return this.cache[key] as FileCache
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
||||||
let data = await this.db.get(key);
|
let data = await this.db.get(key);
|
||||||
return JSON.parse(data);
|
return JSON.parse(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// log("getFileCache db error", e.stack.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async addGroupNotify(notify: GroupNotify) {
|
||||||
|
const key = this.DB_KEY_PREFIX_GROUP_NOTIFY + notify.seq;
|
||||||
|
let existNotify = this.cache[key] as GroupNotify
|
||||||
|
if (existNotify) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.cache[key] = notify;
|
||||||
|
this.db.put(key, JSON.stringify(notify)).then().catch();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getGroupNotify(seq: string): Promise<GroupNotify | undefined> {
|
||||||
|
const key = this.DB_KEY_PREFIX_GROUP_NOTIFY + seq;
|
||||||
|
if (this.cache[key]) {
|
||||||
|
return this.cache[key] as GroupNotify
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
let data = await this.db.get(key);
|
||||||
|
return JSON.parse(data);
|
||||||
|
} catch (e) {
|
||||||
|
// log("getGroupNotify db error", e.stack.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import express, {Express, json, Request, Response} from "express";
|
import express, {Express, Request, Response} from "express";
|
||||||
import {getConfigUtil, log} from "../utils";
|
|
||||||
import http from "http";
|
import http from "http";
|
||||||
|
import {log} from "../utils/log";
|
||||||
|
import {getConfigUtil} from "../config";
|
||||||
|
import {llonebotError} from "../data";
|
||||||
|
|
||||||
type RegisterHandler = (res: Response, payload: any) => Promise<any>
|
type RegisterHandler = (res: Response, payload: any) => Promise<any>
|
||||||
|
|
||||||
@@ -11,8 +13,21 @@ export abstract class HttpServerBase {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.expressAPP = express();
|
this.expressAPP = express();
|
||||||
this.expressAPP.use(express.urlencoded({extended: true, limit: "500mb"}));
|
this.expressAPP.use(express.urlencoded({extended: true, limit: "5000mb"}));
|
||||||
this.expressAPP.use(json({limit: "500mb"}));
|
this.expressAPP.use((req, res, next) => {
|
||||||
|
// 兼容处理没有带content-type的请求
|
||||||
|
// log("req.headers['content-type']", req.headers['content-type'])
|
||||||
|
req.headers['content-type'] = 'application/json';
|
||||||
|
const originalJson = express.json({limit: "5000mb"});
|
||||||
|
// 调用原始的express.json()处理器
|
||||||
|
originalJson(req, res, (err) => {
|
||||||
|
if (err) {
|
||||||
|
log("Error parsing JSON:", err);
|
||||||
|
return res.status(400).send("Invalid JSON");
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
authorize(req: Request, res: Response, next: () => void) {
|
authorize(req: Request, res: Response, next: () => void) {
|
||||||
@@ -38,13 +53,20 @@ export abstract class HttpServerBase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
start(port: number) {
|
start(port: number) {
|
||||||
this.expressAPP.get('/', (req: Request, res: Response) => {
|
try {
|
||||||
res.send(`${this.name}已启动`);
|
this.expressAPP.get('/', (req: Request, res: Response) => {
|
||||||
})
|
res.send(`${this.name}已启动`);
|
||||||
this.listen(port);
|
})
|
||||||
|
this.listen(port);
|
||||||
|
llonebotError.httpServerError = ""
|
||||||
|
} catch (e) {
|
||||||
|
log("HTTP服务启动失败", e.toString())
|
||||||
|
llonebotError.httpServerError = "HTTP服务启动失败, " + e.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
llonebotError.httpServerError = ""
|
||||||
if (this.server) {
|
if (this.server) {
|
||||||
this.server.close()
|
this.server.close()
|
||||||
this.server = null;
|
this.server = null;
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
import {WebSocket, WebSocketServer} from "ws";
|
import {WebSocket, WebSocketServer} from "ws";
|
||||||
import {getConfigUtil, log} from "../utils";
|
|
||||||
import urlParse from "url";
|
import urlParse from "url";
|
||||||
import {IncomingMessage} from "node:http";
|
import {IncomingMessage} from "node:http";
|
||||||
|
import {log} from "../utils/log";
|
||||||
|
import {getConfigUtil} from "../config";
|
||||||
|
import {llonebotError} from "../data";
|
||||||
|
|
||||||
class WebsocketClientBase {
|
class WebsocketClientBase {
|
||||||
private wsClient: WebSocket
|
private wsClient: WebSocket
|
||||||
@@ -28,7 +30,12 @@ export class WebsocketServerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
start(port: number) {
|
start(port: number) {
|
||||||
this.ws = new WebSocketServer({port});
|
try {
|
||||||
|
this.ws = new WebSocketServer({port});
|
||||||
|
llonebotError.wsServerError = ''
|
||||||
|
}catch (e) {
|
||||||
|
llonebotError.wsServerError = "正向ws服务启动失败, " + e.toString()
|
||||||
|
}
|
||||||
this.ws.on("connection", (wsClient, req) => {
|
this.ws.on("connection", (wsClient, req) => {
|
||||||
const url = req.url.split("?").shift()
|
const url = req.url.split("?").shift()
|
||||||
this.authorize(wsClient, req);
|
this.authorize(wsClient, req);
|
||||||
@@ -40,6 +47,7 @@ export class WebsocketServerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
llonebotError.wsServerError = ''
|
||||||
this.ws.close((err) => {
|
this.ws.close((err) => {
|
||||||
log("ws server close failed!", err)
|
log("ws server close failed!", err)
|
||||||
});
|
});
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
export interface OB11Config {
|
export interface OB11Config {
|
||||||
httpPort: number
|
httpPort: number
|
||||||
httpHosts: string[]
|
httpHosts: string[]
|
||||||
|
httpSecret?: string
|
||||||
wsPort: number
|
wsPort: number
|
||||||
wsHosts: string[]
|
wsHosts: string[]
|
||||||
enableHttp?: boolean
|
enableHttp?: boolean
|
||||||
@@ -9,7 +10,10 @@ export interface OB11Config {
|
|||||||
enableWsReverse?: boolean
|
enableWsReverse?: boolean
|
||||||
messagePostFormat?: 'array' | 'string'
|
messagePostFormat?: 'array' | 'string'
|
||||||
}
|
}
|
||||||
|
export interface CheckVersion {
|
||||||
|
result: boolean,
|
||||||
|
version: string
|
||||||
|
}
|
||||||
export interface Config {
|
export interface Config {
|
||||||
ob11: OB11Config
|
ob11: OB11Config
|
||||||
token?: string
|
token?: string
|
||||||
@@ -21,9 +25,12 @@ export interface Config {
|
|||||||
autoDeleteFile?: boolean
|
autoDeleteFile?: boolean
|
||||||
autoDeleteFileSecond?: number
|
autoDeleteFileSecond?: number
|
||||||
ffmpeg?: string // ffmpeg路径
|
ffmpeg?: string // ffmpeg路径
|
||||||
|
enablePoke?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LLOneBotError {
|
export interface LLOneBotError {
|
||||||
|
httpServerError?: string
|
||||||
|
wsServerError?: string
|
||||||
ffmpegError?: string
|
ffmpegError?: string
|
||||||
otherError?: string
|
otherError?: string
|
||||||
}
|
}
|
||||||
@@ -32,6 +39,8 @@ export interface FileCache {
|
|||||||
fileName: string
|
fileName: string
|
||||||
filePath: string
|
filePath: string
|
||||||
fileSize: string
|
fileSize: string
|
||||||
|
fileUuid?: string
|
||||||
url?: string
|
url?: string
|
||||||
|
msgId?: string
|
||||||
downloadFunc?: () => Promise<void>
|
downloadFunc?: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
@@ -1,261 +0,0 @@
|
|||||||
import * as path from "node:path";
|
|
||||||
import {selfInfo} from "./data";
|
|
||||||
import {ConfigUtil} from "./config";
|
|
||||||
import util from "util";
|
|
||||||
import {encode, getDuration, isWav} from "silk-wasm";
|
|
||||||
import fs from 'fs';
|
|
||||||
import {v4 as uuidv4} from "uuid";
|
|
||||||
import ffmpeg from "fluent-ffmpeg"
|
|
||||||
|
|
||||||
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
|
||||||
|
|
||||||
export function getConfigUtil() {
|
|
||||||
const configFilePath = path.join(DATA_DIR, `config_${selfInfo.uin}.json`)
|
|
||||||
return new ConfigUtil(configFilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
function truncateString(obj: any, maxLength = 500) {
|
|
||||||
if (obj !== null && typeof obj === 'object') {
|
|
||||||
Object.keys(obj).forEach(key => {
|
|
||||||
if (typeof obj[key] === 'string') {
|
|
||||||
// 如果是字符串且超过指定长度,则截断
|
|
||||||
if (obj[key].length > maxLength) {
|
|
||||||
obj[key] = obj[key].substring(0, maxLength) + '...';
|
|
||||||
}
|
|
||||||
} else if (typeof obj[key] === 'object') {
|
|
||||||
// 如果是对象或数组,则递归调用
|
|
||||||
truncateString(obj[key], maxLength);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function log(...msg: any[]) {
|
|
||||||
if (!getConfigUtil().getConfig().log) {
|
|
||||||
return //console.log(...msg);
|
|
||||||
}
|
|
||||||
let currentDateTime = new Date().toLocaleString();
|
|
||||||
const date = new Date();
|
|
||||||
const year = date.getFullYear();
|
|
||||||
const month = date.getMonth() + 1;
|
|
||||||
const day = date.getDate();
|
|
||||||
const currentDate = `${year}-${month}-${day}`;
|
|
||||||
const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : ""
|
|
||||||
let logMsg = "";
|
|
||||||
for (let msgItem of msg) {
|
|
||||||
// 判断是否是对象
|
|
||||||
if (typeof msgItem === "object") {
|
|
||||||
let obj = JSON.parse(JSON.stringify(msgItem));
|
|
||||||
logMsg += JSON.stringify(truncateString(obj)) + " ";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
logMsg += msgItem + " ";
|
|
||||||
}
|
|
||||||
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
|
||||||
// sendLog(...msg);
|
|
||||||
// console.log(msg)
|
|
||||||
fs.appendFile(path.join(DATA_DIR, `llonebot-${currentDate}.log`), logMsg, (err: any) => {
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isGIF(path: string) {
|
|
||||||
const buffer = Buffer.alloc(4);
|
|
||||||
const fd = fs.openSync(path, 'r');
|
|
||||||
fs.readSync(fd, buffer, 0, 4, 0);
|
|
||||||
fs.closeSync(fd);
|
|
||||||
return buffer.toString() === 'GIF8'
|
|
||||||
}
|
|
||||||
|
|
||||||
export function sleep(ms: number): Promise<void> {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 定义一个异步函数来检查文件是否存在
|
|
||||||
export function checkFileReceived(path: string, timeout: number = 3000): Promise<void> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const startTime = Date.now();
|
|
||||||
|
|
||||||
function check() {
|
|
||||||
if (fs.existsSync(path)) {
|
|
||||||
resolve();
|
|
||||||
} else if (Date.now() - startTime > timeout) {
|
|
||||||
reject(new Error(`文件不存在: ${path}`));
|
|
||||||
} else {
|
|
||||||
setTimeout(check, 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
check();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function file2base64(path: string) {
|
|
||||||
const readFile = util.promisify(fs.readFile);
|
|
||||||
let result = {
|
|
||||||
err: "",
|
|
||||||
data: ""
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// 读取文件内容
|
|
||||||
// if (!fs.existsSync(path)){
|
|
||||||
// path = path.replace("\\Ori\\", "\\Thumb\\");
|
|
||||||
// }
|
|
||||||
try {
|
|
||||||
await checkFileReceived(path, 5000);
|
|
||||||
} catch (e: any) {
|
|
||||||
result.err = e.toString();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
const data = await readFile(path);
|
|
||||||
// 转换为Base64编码
|
|
||||||
result.data = data.toString('base64');
|
|
||||||
} catch (err) {
|
|
||||||
result.err = err.toString();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 在保证老对象已有的属性不变化的情况下将新对象的属性复制到老对象
|
|
||||||
export function mergeNewProperties(newObj: any, oldObj: any) {
|
|
||||||
Object.keys(newObj).forEach(key => {
|
|
||||||
// 如果老对象不存在当前属性,则直接复制
|
|
||||||
if (!oldObj.hasOwnProperty(key)) {
|
|
||||||
oldObj[key] = newObj[key];
|
|
||||||
} else {
|
|
||||||
// 如果老对象和新对象的当前属性都是对象,则递归合并
|
|
||||||
if (typeof oldObj[key] === 'object' && typeof newObj[key] === 'object') {
|
|
||||||
mergeNewProperties(newObj[key], oldObj[key]);
|
|
||||||
} else if (typeof oldObj[key] === 'object' || typeof newObj[key] === 'object') {
|
|
||||||
// 属性冲突,有一方不是对象,直接覆盖
|
|
||||||
oldObj[key] = newObj[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function checkFfmpeg(newPath: string = null): Promise<boolean> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (newPath) {
|
|
||||||
ffmpeg.setFfmpegPath(newPath);
|
|
||||||
ffmpeg.getAvailableFormats((err, formats) => {
|
|
||||||
if (err) {
|
|
||||||
log('ffmpeg is not installed or not found in PATH:', err);
|
|
||||||
resolve(false)
|
|
||||||
} else {
|
|
||||||
log('ffmpeg is installed.');
|
|
||||||
resolve(true);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function encodeSilk(filePath: string) {
|
|
||||||
const fsp = require("fs").promises
|
|
||||||
|
|
||||||
function getFileHeader(filePath: string) {
|
|
||||||
// 定义要读取的字节数
|
|
||||||
const bytesToRead = 7;
|
|
||||||
try {
|
|
||||||
const buffer = fs.readFileSync(filePath, {
|
|
||||||
encoding: null,
|
|
||||||
flag: "r",
|
|
||||||
});
|
|
||||||
|
|
||||||
const fileHeader = buffer.toString("hex", 0, bytesToRead);
|
|
||||||
return fileHeader;
|
|
||||||
} catch (err) {
|
|
||||||
console.error("读取文件错误:", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function isWavFile(filePath: string) {
|
|
||||||
return isWav(fs.readFileSync(filePath));
|
|
||||||
}
|
|
||||||
|
|
||||||
// async function getAudioSampleRate(filePath: string) {
|
|
||||||
// try {
|
|
||||||
// const mm = await import('music-metadata');
|
|
||||||
// const metadata = await mm.parseFile(filePath);
|
|
||||||
// log(`${filePath}采样率`, metadata.format.sampleRate);
|
|
||||||
// return metadata.format.sampleRate;
|
|
||||||
// } catch (error) {
|
|
||||||
// log(`${filePath}采样率获取失败`, error.stack);
|
|
||||||
// // console.error(error);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
try {
|
|
||||||
const fileName = path.basename(filePath);
|
|
||||||
const pttPath = path.join(DATA_DIR, uuidv4());
|
|
||||||
if (getFileHeader(filePath) !== "02232153494c4b") {
|
|
||||||
log(`语音文件${filePath}需要转换成silk`)
|
|
||||||
const _isWav = await isWavFile(filePath);
|
|
||||||
const wavPath = pttPath + ".wav"
|
|
||||||
if (!_isWav) {
|
|
||||||
log(`语音文件${filePath}正在转换成wav`)
|
|
||||||
// let voiceData = await fsp.readFile(filePath)
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
const ffmpegPath = getConfigUtil().getConfig().ffmpeg;
|
|
||||||
if (ffmpegPath) {
|
|
||||||
ffmpeg.setFfmpegPath(ffmpegPath);
|
|
||||||
}
|
|
||||||
ffmpeg(filePath).toFormat("wav").on('end', function () {
|
|
||||||
log('wav转换完成');
|
|
||||||
})
|
|
||||||
.on('error', function (err) {
|
|
||||||
log(`wav转换出错: `, err.message,);
|
|
||||||
reject(err);
|
|
||||||
})
|
|
||||||
.save(wavPath)
|
|
||||||
.on("end", () => {
|
|
||||||
filePath = wavPath
|
|
||||||
resolve(wavPath);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// const sampleRate = await getAudioSampleRate(filePath) || 0;
|
|
||||||
const pcm = fs.readFileSync(filePath);
|
|
||||||
const silk = await encode(pcm, 0);
|
|
||||||
fs.writeFileSync(pttPath, silk.data);
|
|
||||||
fs.unlink(wavPath, (err) => {
|
|
||||||
});
|
|
||||||
log(`语音文件${filePath}转换成功!`, pttPath)
|
|
||||||
return {
|
|
||||||
converted: true,
|
|
||||||
path: pttPath,
|
|
||||||
duration: silk.duration,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const pcm = fs.readFileSync(filePath);
|
|
||||||
let duration = 0;
|
|
||||||
try{
|
|
||||||
duration = getDuration(pcm);
|
|
||||||
}catch (e) {
|
|
||||||
log("获取语音文件时长失败", filePath, e.stack)
|
|
||||||
duration = fs.statSync(filePath).size / 1024 / 3 // 每3kb大约1s
|
|
||||||
duration = Math.floor(duration)
|
|
||||||
duration = Math.max(1, duration)
|
|
||||||
log("使用文件大小估算时长", duration)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
converted: false,
|
|
||||||
path: filePath,
|
|
||||||
duration: duration,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
log("convert silk failed", error.stack);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isNull(value: any) {
|
|
||||||
return value === undefined || value === null;
|
|
||||||
}
|
|
137
src/common/utils/audio.ts
Normal file
137
src/common/utils/audio.ts
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
import {encode, getDuration, getWavFileInfo, isWav} from "silk-wasm";
|
||||||
|
import fsPromise from "fs/promises";
|
||||||
|
import {log} from "./log";
|
||||||
|
import path from "node:path";
|
||||||
|
import {DATA_DIR, TEMP_DIR} from "./index";
|
||||||
|
import {v4 as uuidv4} from "uuid";
|
||||||
|
import {getConfigUtil} from "../config";
|
||||||
|
import ffmpeg from "fluent-ffmpeg";
|
||||||
|
|
||||||
|
export async function encodeSilk(filePath: string) {
|
||||||
|
function getFileHeader(filePath: string) {
|
||||||
|
// 定义要读取的字节数
|
||||||
|
const bytesToRead = 7;
|
||||||
|
try {
|
||||||
|
const buffer = fs.readFileSync(filePath, {
|
||||||
|
encoding: null,
|
||||||
|
flag: "r",
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileHeader = buffer.toString("hex", 0, bytesToRead);
|
||||||
|
return fileHeader;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("读取文件错误:", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function isWavFile(filePath: string) {
|
||||||
|
return isWav(fs.readFileSync(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function guessDuration(pttPath: string) {
|
||||||
|
const pttFileInfo = await fsPromise.stat(pttPath)
|
||||||
|
let duration = pttFileInfo.size / 1024 / 3 // 3kb/s
|
||||||
|
duration = Math.floor(duration)
|
||||||
|
duration = Math.max(1, duration)
|
||||||
|
log(`通过文件大小估算语音的时长:`, duration)
|
||||||
|
return duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// function verifyDuration(oriDuration: number, guessDuration: number) {
|
||||||
|
// // 单位都是秒
|
||||||
|
// if (oriDuration - guessDuration > 10) {
|
||||||
|
// return guessDuration
|
||||||
|
// }
|
||||||
|
// oriDuration = Math.max(1, oriDuration)
|
||||||
|
// return oriDuration
|
||||||
|
// }
|
||||||
|
// async function getAudioSampleRate(filePath: string) {
|
||||||
|
// try {
|
||||||
|
// const mm = await import('music-metadata');
|
||||||
|
// const metadata = await mm.parseFile(filePath);
|
||||||
|
// log(`${filePath}采样率`, metadata.format.sampleRate);
|
||||||
|
// return metadata.format.sampleRate;
|
||||||
|
// } catch (error) {
|
||||||
|
// log(`${filePath}采样率获取失败`, error.stack);
|
||||||
|
// // console.error(error);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
try {
|
||||||
|
const pttPath = path.join(TEMP_DIR, uuidv4());
|
||||||
|
if (getFileHeader(filePath) !== "02232153494c4b") {
|
||||||
|
log(`语音文件${filePath}需要转换成silk`)
|
||||||
|
const _isWav = await isWavFile(filePath);
|
||||||
|
const wavPath = pttPath + ".wav"
|
||||||
|
const convert = async () => {
|
||||||
|
return await new Promise((resolve, reject) => {
|
||||||
|
const ffmpegPath = getConfigUtil().getConfig().ffmpeg;
|
||||||
|
if (ffmpegPath) {
|
||||||
|
ffmpeg.setFfmpegPath(ffmpegPath);
|
||||||
|
}
|
||||||
|
ffmpeg(filePath).toFormat("wav")
|
||||||
|
.audioChannels(1)
|
||||||
|
.audioFrequency(24000)
|
||||||
|
.on('end', function () {
|
||||||
|
log('wav转换完成');
|
||||||
|
})
|
||||||
|
.on('error', function (err) {
|
||||||
|
log(`wav转换出错: `, err.message,);
|
||||||
|
reject(err);
|
||||||
|
})
|
||||||
|
.save(wavPath)
|
||||||
|
.on("end", () => {
|
||||||
|
filePath = wavPath
|
||||||
|
resolve(wavPath);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
let wav: Buffer
|
||||||
|
if (!_isWav) {
|
||||||
|
log(`语音文件${filePath}正在转换成wav`)
|
||||||
|
await convert()
|
||||||
|
} else {
|
||||||
|
wav = fs.readFileSync(filePath)
|
||||||
|
const allowSampleRate = [8000, 12000, 16000, 24000, 32000, 44100, 48000]
|
||||||
|
const {fmt} = getWavFileInfo(wav)
|
||||||
|
// log(`wav文件信息`, fmt)
|
||||||
|
if (!allowSampleRate.includes(fmt.sampleRate)) {
|
||||||
|
wav = undefined
|
||||||
|
await convert()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wav ||= fs.readFileSync(filePath);
|
||||||
|
const silk = await encode(wav, 0);
|
||||||
|
fs.writeFileSync(pttPath, silk.data);
|
||||||
|
fs.unlink(wavPath, (err) => {
|
||||||
|
});
|
||||||
|
// const gDuration = await guessDuration(pttPath)
|
||||||
|
log(`语音文件${filePath}转换成功!`, pttPath, `时长:`, silk.duration)
|
||||||
|
return {
|
||||||
|
converted: true,
|
||||||
|
path: pttPath,
|
||||||
|
duration: silk.duration / 1000
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const silk = fs.readFileSync(filePath);
|
||||||
|
let duration = 0;
|
||||||
|
try {
|
||||||
|
duration = getDuration(silk) / 1000
|
||||||
|
} catch (e) {
|
||||||
|
log("获取语音文件时长失败, 使用文件大小推测时长", filePath, e.stack)
|
||||||
|
duration = await guessDuration(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
converted: false,
|
||||||
|
path: filePath,
|
||||||
|
duration: duration,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log("convert silk failed", error.stack);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
258
src/common/utils/file.ts
Normal file
258
src/common/utils/file.ts
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
import fsPromise from "fs/promises";
|
||||||
|
import crypto from "crypto";
|
||||||
|
import util from "util";
|
||||||
|
import path from "node:path";
|
||||||
|
import {v4 as uuidv4} from "uuid";
|
||||||
|
import {log, TEMP_DIR} from "./index";
|
||||||
|
import {dbUtil} from "../db";
|
||||||
|
import * as fileType from "file-type";
|
||||||
|
import {net} from "electron";
|
||||||
|
|
||||||
|
|
||||||
|
export function isGIF(path: string) {
|
||||||
|
const buffer = Buffer.alloc(4);
|
||||||
|
const fd = fs.openSync(path, 'r');
|
||||||
|
fs.readSync(fd, buffer, 0, 4, 0);
|
||||||
|
fs.closeSync(fd);
|
||||||
|
return buffer.toString() === 'GIF8'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定义一个异步函数来检查文件是否存在
|
||||||
|
export function checkFileReceived(path: string, timeout: number = 3000): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const startTime = Date.now();
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
if (fs.existsSync(path)) {
|
||||||
|
resolve();
|
||||||
|
} else if (Date.now() - startTime > timeout) {
|
||||||
|
reject(new Error(`文件不存在: ${path}`));
|
||||||
|
} else {
|
||||||
|
setTimeout(check, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
check();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function file2base64(path: string) {
|
||||||
|
const readFile = util.promisify(fs.readFile);
|
||||||
|
let result = {
|
||||||
|
err: "",
|
||||||
|
data: ""
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 读取文件内容
|
||||||
|
// if (!fs.existsSync(path)){
|
||||||
|
// path = path.replace("\\Ori\\", "\\Thumb\\");
|
||||||
|
// }
|
||||||
|
try {
|
||||||
|
await checkFileReceived(path, 5000);
|
||||||
|
} catch (e: any) {
|
||||||
|
result.err = e.toString();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
const data = await readFile(path);
|
||||||
|
// 转换为Base64编码
|
||||||
|
result.data = data.toString('base64');
|
||||||
|
} catch (err) {
|
||||||
|
result.err = err.toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function calculateFileMD5(filePath: string): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// 创建一个流式读取器
|
||||||
|
const stream = fs.createReadStream(filePath);
|
||||||
|
const hash = crypto.createHash('md5');
|
||||||
|
|
||||||
|
stream.on('data', (data: Buffer) => {
|
||||||
|
// 当读取到数据时,更新哈希对象的状态
|
||||||
|
hash.update(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on('end', () => {
|
||||||
|
// 文件读取完成,计算哈希
|
||||||
|
const md5 = hash.digest('hex');
|
||||||
|
resolve(md5);
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on('error', (err: Error) => {
|
||||||
|
// 处理可能的读取错误
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HttpDownloadOptions {
|
||||||
|
url: string;
|
||||||
|
headers?: Record<string, string> | string;
|
||||||
|
}
|
||||||
|
export async function httpDownload(options: string | HttpDownloadOptions): Promise<Buffer> {
|
||||||
|
let chunks: Buffer[] = [];
|
||||||
|
let url: string;
|
||||||
|
let headers: Record<string, string> = {
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36"
|
||||||
|
};
|
||||||
|
if (typeof options === "string") {
|
||||||
|
url = options;
|
||||||
|
} else {
|
||||||
|
url = options.url;
|
||||||
|
if (options.headers) {
|
||||||
|
if (typeof options.headers === "string") {
|
||||||
|
headers = JSON.parse(options.headers);
|
||||||
|
} else {
|
||||||
|
headers = options.headers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const fetchRes = await net.fetch(url, headers);
|
||||||
|
if (!fetchRes.ok) throw new Error(`下载文件失败: ${fetchRes.statusText}`)
|
||||||
|
|
||||||
|
const blob = await fetchRes.blob();
|
||||||
|
let buffer = await blob.arrayBuffer();
|
||||||
|
return Buffer.from(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
type Uri2LocalRes = {
|
||||||
|
success: boolean,
|
||||||
|
errMsg: string,
|
||||||
|
fileName: string,
|
||||||
|
ext: string,
|
||||||
|
path: string,
|
||||||
|
isLocal: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function uri2local(uri: string, fileName: string = null): Promise<Uri2LocalRes> {
|
||||||
|
let res = {
|
||||||
|
success: false,
|
||||||
|
errMsg: "",
|
||||||
|
fileName: "",
|
||||||
|
ext: "",
|
||||||
|
path: "",
|
||||||
|
isLocal: false
|
||||||
|
}
|
||||||
|
if (!fileName) {
|
||||||
|
fileName = uuidv4();
|
||||||
|
}
|
||||||
|
let filePath = path.join(TEMP_DIR, fileName)
|
||||||
|
let url = null;
|
||||||
|
try {
|
||||||
|
url = new URL(uri);
|
||||||
|
} catch (e) {
|
||||||
|
res.errMsg = `uri ${uri} 解析失败,` + e.toString() + ` 可能${uri}不存在`
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
// log("uri protocol", url.protocol, uri);
|
||||||
|
if (url.protocol == "base64:") {
|
||||||
|
// base64转成文件
|
||||||
|
let base64Data = uri.split("base64://")[1]
|
||||||
|
try {
|
||||||
|
const buffer = Buffer.from(base64Data, 'base64');
|
||||||
|
fs.writeFileSync(filePath, buffer);
|
||||||
|
|
||||||
|
} catch (e: any) {
|
||||||
|
res.errMsg = `base64文件下载失败,` + e.toString()
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
} else if (url.protocol == "http:" || url.protocol == "https:") {
|
||||||
|
// 下载文件
|
||||||
|
let buffer: Buffer = null;
|
||||||
|
try {
|
||||||
|
buffer = await httpDownload(uri);
|
||||||
|
} catch (e) {
|
||||||
|
res.errMsg = `${url}下载失败,` + e.toString()
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const pathInfo = path.parse(decodeURIComponent(url.pathname))
|
||||||
|
if (pathInfo.name) {
|
||||||
|
fileName = pathInfo.name
|
||||||
|
if (pathInfo.ext) {
|
||||||
|
fileName += pathInfo.ext
|
||||||
|
// res.ext = pathInfo.ext
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.fileName = fileName
|
||||||
|
filePath = path.join(TEMP_DIR, uuidv4() + fileName)
|
||||||
|
fs.writeFileSync(filePath, buffer);
|
||||||
|
} catch (e: any) {
|
||||||
|
res.errMsg = `${url}下载失败,` + e.toString()
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let pathname: string;
|
||||||
|
if (url.protocol === "file:") {
|
||||||
|
// await fs.copyFile(url.pathname, filePath);
|
||||||
|
pathname = decodeURIComponent(url.pathname)
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
filePath = pathname.slice(1)
|
||||||
|
} else {
|
||||||
|
filePath = pathname
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const cache = await dbUtil.getFileCache(uri);
|
||||||
|
if (cache) {
|
||||||
|
filePath = cache.filePath
|
||||||
|
} else {
|
||||||
|
filePath = uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.isLocal = true
|
||||||
|
}
|
||||||
|
// else{
|
||||||
|
// res.errMsg = `不支持的file协议,` + url.protocol
|
||||||
|
// return res
|
||||||
|
// }
|
||||||
|
// if (isGIF(filePath) && !res.isLocal) {
|
||||||
|
// await fs.rename(filePath, filePath + ".gif");
|
||||||
|
// filePath += ".gif";
|
||||||
|
// }
|
||||||
|
if (!res.isLocal && !res.ext) {
|
||||||
|
try {
|
||||||
|
let ext: string = (await fileType.fileTypeFromFile(filePath)).ext
|
||||||
|
if (ext) {
|
||||||
|
log("获取文件类型", ext, filePath)
|
||||||
|
fs.renameSync(filePath, filePath + `.${ext}`)
|
||||||
|
filePath += `.${ext}`
|
||||||
|
res.fileName += `.${ext}`
|
||||||
|
res.ext = ext
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// log("获取文件类型失败", filePath,e.stack)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.success = true
|
||||||
|
res.path = filePath
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function copyFolder(sourcePath: string, destPath: string) {
|
||||||
|
try {
|
||||||
|
const entries = await fsPromise.readdir(sourcePath, {withFileTypes: true});
|
||||||
|
await fsPromise.mkdir(destPath, {recursive: true});
|
||||||
|
for (let entry of entries) {
|
||||||
|
const srcPath = path.join(sourcePath, entry.name);
|
||||||
|
const dstPath = path.join(destPath, entry.name);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
await copyFolder(srcPath, dstPath);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
await fsPromise.copyFile(srcPath, dstPath);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`无法复制文件 '${srcPath}' 到 '${dstPath}': ${error}`);
|
||||||
|
// 这里可以决定是否要继续复制其他文件
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('复制文件夹时出错:', error);
|
||||||
|
}
|
||||||
|
}
|
68
src/common/utils/helper.ts
Normal file
68
src/common/utils/helper.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
export function truncateString(obj: any, maxLength = 500) {
|
||||||
|
if (obj !== null && typeof obj === 'object') {
|
||||||
|
Object.keys(obj).forEach(key => {
|
||||||
|
if (typeof obj[key] === 'string') {
|
||||||
|
// 如果是字符串且超过指定长度,则截断
|
||||||
|
if (obj[key].length > maxLength) {
|
||||||
|
obj[key] = obj[key].substring(0, maxLength) + '...';
|
||||||
|
}
|
||||||
|
} else if (typeof obj[key] === 'object') {
|
||||||
|
// 如果是对象或数组,则递归调用
|
||||||
|
truncateString(obj[key], maxLength);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isNumeric(str: string) {
|
||||||
|
return /^\d+$/.test(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sleep(ms: number): Promise<void> {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在保证老对象已有的属性不变化的情况下将新对象的属性复制到老对象
|
||||||
|
export function mergeNewProperties(newObj: any, oldObj: any) {
|
||||||
|
Object.keys(newObj).forEach(key => {
|
||||||
|
// 如果老对象不存在当前属性,则直接复制
|
||||||
|
if (!oldObj.hasOwnProperty(key)) {
|
||||||
|
oldObj[key] = newObj[key];
|
||||||
|
} else {
|
||||||
|
// 如果老对象和新对象的当前属性都是对象,则递归合并
|
||||||
|
if (typeof oldObj[key] === 'object' && typeof newObj[key] === 'object') {
|
||||||
|
mergeNewProperties(newObj[key], oldObj[key]);
|
||||||
|
} else if (typeof oldObj[key] === 'object' || typeof newObj[key] === 'object') {
|
||||||
|
// 属性冲突,有一方不是对象,直接覆盖
|
||||||
|
oldObj[key] = newObj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isNull(value: any) {
|
||||||
|
return value === undefined || value === null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将字符串按最大长度分割并添加换行符
|
||||||
|
* @param str 原始字符串
|
||||||
|
* @param maxLength 每行的最大字符数
|
||||||
|
* @returns 处理后的字符串,超过长度的地方将会换行
|
||||||
|
*/
|
||||||
|
export function wrapText(str: string, maxLength: number): string {
|
||||||
|
// 初始化一个空字符串用于存放结果
|
||||||
|
let result: string = '';
|
||||||
|
|
||||||
|
// 循环遍历字符串,每次步进maxLength个字符
|
||||||
|
for (let i = 0; i < str.length; i += maxLength) {
|
||||||
|
// 从i开始,截取长度为maxLength的字符串段,并添加到结果字符串
|
||||||
|
// 如果不是第一段,先添加一个换行符
|
||||||
|
if (i > 0) result += '\n';
|
||||||
|
result += str.substring(i, i + maxLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
18
src/common/utils/index.ts
Normal file
18
src/common/utils/index.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import path from "node:path";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
|
export * from './file'
|
||||||
|
export * from './helper'
|
||||||
|
export * from './log'
|
||||||
|
export * from './qqlevel'
|
||||||
|
export * from './qqpkg'
|
||||||
|
export * from './upgrade'
|
||||||
|
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
||||||
|
export const TEMP_DIR = path.join(DATA_DIR, "temp");
|
||||||
|
export const PLUGIN_DIR = global.LiteLoader.plugins["LLOneBot"].path.plugin;
|
||||||
|
if (!fs.existsSync(TEMP_DIR)) {
|
||||||
|
fs.mkdirSync(TEMP_DIR, {recursive: true});
|
||||||
|
}
|
||||||
|
export {getVideoInfo} from "./video";
|
||||||
|
export {checkFfmpeg} from "./video";
|
||||||
|
export {encodeSilk} from "./audio";
|
37
src/common/utils/log.ts
Normal file
37
src/common/utils/log.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import {selfInfo} from "../data";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import {DATA_DIR, truncateString} from "./index";
|
||||||
|
import {getConfigUtil} from "../config";
|
||||||
|
|
||||||
|
const date = new Date();
|
||||||
|
const logFileName = `llonebot-${date.toLocaleString("zh-CN")}.log`.replace(/\//g, "-").replace(/:/g, "-");
|
||||||
|
const logDir = path.join(DATA_DIR, "logs");
|
||||||
|
if (!fs.existsSync(logDir)) {
|
||||||
|
fs.mkdirSync(logDir, {recursive: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function log(...msg: any[]) {
|
||||||
|
if (!getConfigUtil().getConfig().log) {
|
||||||
|
return //console.log(...msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : ""
|
||||||
|
let logMsg = "";
|
||||||
|
for (let msgItem of msg) {
|
||||||
|
// 判断是否是对象
|
||||||
|
if (typeof msgItem === "object") {
|
||||||
|
let obj = JSON.parse(JSON.stringify(msgItem));
|
||||||
|
logMsg += JSON.stringify(truncateString(obj)) + " ";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
logMsg += msgItem + " ";
|
||||||
|
}
|
||||||
|
let currentDateTime = new Date().toLocaleString();
|
||||||
|
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
||||||
|
// sendLog(...msg);
|
||||||
|
// console.log(msg)
|
||||||
|
fs.appendFile(path.join(logDir, logFileName), logMsg, (err: any) => {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
7
src/common/utils/qqlevel.ts
Normal file
7
src/common/utils/qqlevel.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// QQ等级换算
|
||||||
|
import {QQLevel} from "../../ntqqapi/types";
|
||||||
|
|
||||||
|
export function calcQQLevel(level: QQLevel) {
|
||||||
|
const {crownNum, sunNum, moonNum, starNum} = level
|
||||||
|
return crownNum * 64 + sunNum * 16 + moonNum * 4 + starNum
|
||||||
|
}
|
12
src/common/utils/qqpkg.ts
Normal file
12
src/common/utils/qqpkg.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import path from "path";
|
||||||
|
|
||||||
|
type QQPkgInfo = {
|
||||||
|
version: string;
|
||||||
|
buildVersion: string;
|
||||||
|
platform: string;
|
||||||
|
eleArch: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const qqPkgInfo: QQPkgInfo = require(path.join(process.resourcesPath, "app/package.json"))
|
||||||
|
|
||||||
|
export const isQQ998: boolean = qqPkgInfo.buildVersion >= "22106"
|
98
src/common/utils/upgrade.ts
Normal file
98
src/common/utils/upgrade.ts
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import { version } from "../../version";
|
||||||
|
import * as path from "node:path";
|
||||||
|
import * as fs from "node:fs";
|
||||||
|
import { copyFolder, httpDownload, log, PLUGIN_DIR, TEMP_DIR } from ".";
|
||||||
|
import compressing from "compressing";
|
||||||
|
|
||||||
|
|
||||||
|
const downloadMirrorHosts = ["https://mirror.ghproxy.com/"];
|
||||||
|
const checkVersionMirrorHosts = ["https://521github.com"];
|
||||||
|
|
||||||
|
export async function checkNewVersion() {
|
||||||
|
const latestVersionText = await getRemoteVersion();
|
||||||
|
const latestVersion = latestVersionText.split(".");
|
||||||
|
log("llonebot last version", latestVersion);
|
||||||
|
const currentVersion: string[] = version.split(".");
|
||||||
|
log("llonebot current version", currentVersion);
|
||||||
|
for (let k of [0, 1, 2]) {
|
||||||
|
if (parseInt(latestVersion[k]) > parseInt(currentVersion[k])) {
|
||||||
|
log("")
|
||||||
|
return { result: true, version: latestVersionText };
|
||||||
|
}
|
||||||
|
else if (parseInt(latestVersion[k]) < parseInt(currentVersion[k])) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { result: false, version: version };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function upgradeLLOneBot() {
|
||||||
|
const latestVersion = await getRemoteVersion();
|
||||||
|
if (latestVersion && latestVersion != "") {
|
||||||
|
const downloadUrl = "https://github.com/LLOneBot/LLOneBot/releases/download/v" + latestVersion + "/LLOneBot.zip";
|
||||||
|
const filePath = path.join(TEMP_DIR, "./update-" + latestVersion + ".zip");
|
||||||
|
let downloadSuccess = false;
|
||||||
|
// 多镜像下载
|
||||||
|
for (const mirrorGithub of downloadMirrorHosts) {
|
||||||
|
try {
|
||||||
|
const buffer = await httpDownload(mirrorGithub + downloadUrl);
|
||||||
|
fs.writeFileSync(filePath, buffer)
|
||||||
|
downloadSuccess = true;
|
||||||
|
break;
|
||||||
|
} catch (e) {
|
||||||
|
log("llonebot upgrade error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!downloadSuccess) {
|
||||||
|
log("llonebot upgrade error", "download failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const temp_ver_dir = path.join(TEMP_DIR, "LLOneBot" + latestVersion);
|
||||||
|
let uncompressedPromise = async function () {
|
||||||
|
return new Promise<boolean>((resolve, reject) => {
|
||||||
|
compressing.zip.uncompress(filePath, temp_ver_dir).then(() => {
|
||||||
|
resolve(true);
|
||||||
|
}).catch((reason: any) => {
|
||||||
|
log("llonebot upgrade failed, ", reason);
|
||||||
|
if (reason?.errno == -4082) {
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
resolve(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const uncompressedResult = await uncompressedPromise();
|
||||||
|
// 复制文件
|
||||||
|
await copyFolder(temp_ver_dir, PLUGIN_DIR);
|
||||||
|
|
||||||
|
return uncompressedResult;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getRemoteVersion() {
|
||||||
|
let Version = "";
|
||||||
|
for (let i = 0; i < checkVersionMirrorHosts.length; i++) {
|
||||||
|
let mirrorGithub = checkVersionMirrorHosts[i];
|
||||||
|
let tVersion = await getRemoteVersionByMirror(mirrorGithub);
|
||||||
|
if (tVersion && tVersion != "") {
|
||||||
|
Version = tVersion;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Version;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getRemoteVersionByMirror(mirrorGithub: string) {
|
||||||
|
let releasePage = "error";
|
||||||
|
|
||||||
|
try {
|
||||||
|
releasePage = (await httpDownload(mirrorGithub + "/LLOneBot/LLOneBot/releases")).toString();
|
||||||
|
// log("releasePage", releasePage);
|
||||||
|
if (releasePage === "error") return "";
|
||||||
|
return releasePage.match(new RegExp('(?<=(tag/v)).*?(?=("))'))[0];
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
|
||||||
|
}
|
88
src/common/utils/video.ts
Normal file
88
src/common/utils/video.ts
Normal file
File diff suppressed because one or more lines are too long
254
src/main/main.ts
254
src/main/main.ts
@@ -7,50 +7,60 @@ import {
|
|||||||
CHANNEL_ERROR,
|
CHANNEL_ERROR,
|
||||||
CHANNEL_GET_CONFIG,
|
CHANNEL_GET_CONFIG,
|
||||||
CHANNEL_LOG,
|
CHANNEL_LOG,
|
||||||
|
CHANNEL_CHECK_VERSION,
|
||||||
CHANNEL_SELECT_FILE,
|
CHANNEL_SELECT_FILE,
|
||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
|
CHANNEL_UPDATE,
|
||||||
} from "../common/channels";
|
} from "../common/channels";
|
||||||
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||||
import {checkFfmpeg, DATA_DIR, getConfigUtil, log} from "../common/utils";
|
import {DATA_DIR, wrapText} from "../common/utils";
|
||||||
import {
|
import {
|
||||||
friendRequests, getFriend,
|
friendRequests,
|
||||||
|
getFriend,
|
||||||
getGroup,
|
getGroup,
|
||||||
getGroupMember,
|
getGroupMember,
|
||||||
groupNotifies,
|
llonebotError,
|
||||||
llonebotError, refreshGroupMembers,
|
refreshGroupMembers,
|
||||||
selfInfo
|
selfInfo, uidMaps
|
||||||
} from "../common/data";
|
} from "../common/data";
|
||||||
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmd, registerReceiveHook} from "../ntqqapi/hook";
|
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook} from "../ntqqapi/hook";
|
||||||
import {OB11Constructor} from "../onebot11/constructor";
|
import {OB11Constructor} from "../onebot11/constructor";
|
||||||
import {NTQQApi} from "../ntqqapi/ntcall";
|
import {ChatType, FriendRequestNotify, GroupNotifies, GroupNotifyTypes, RawMessage} from "../ntqqapi/types";
|
||||||
import {
|
|
||||||
ChatType,
|
|
||||||
FriendRequestNotify,
|
|
||||||
GroupMember,
|
|
||||||
GroupNotifies,
|
|
||||||
GroupNotifyTypes,
|
|
||||||
RawMessage
|
|
||||||
} from "../ntqqapi/types";
|
|
||||||
import {ob11HTTPServer} from "../onebot11/server/http";
|
import {ob11HTTPServer} from "../onebot11/server/http";
|
||||||
import {OB11FriendRecallNoticeEvent} from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
import {OB11FriendRecallNoticeEvent} from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
||||||
import {OB11GroupRecallNoticeEvent} from "../onebot11/event/notice/OB11GroupRecallNoticeEvent";
|
import {OB11GroupRecallNoticeEvent} from "../onebot11/event/notice/OB11GroupRecallNoticeEvent";
|
||||||
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
||||||
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
||||||
import {OB11GroupAdminNoticeEvent} from "../onebot11/event/notice/OB11GroupAdminNoticeEvent";
|
import {OB11GroupAdminNoticeEvent} from "../onebot11/event/notice/OB11GroupAdminNoticeEvent";
|
||||||
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
|
||||||
import {OB11GroupRequestEvent} from "../onebot11/event/request/OB11GroupRequest";
|
import {OB11GroupRequestEvent} from "../onebot11/event/request/OB11GroupRequest";
|
||||||
import {OB11FriendRequestEvent} from "../onebot11/event/request/OB11FriendRequest";
|
import {OB11FriendRequestEvent} from "../onebot11/event/request/OB11FriendRequest";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
import {dbUtil} from "../common/db";
|
import {dbUtil} from "../common/db";
|
||||||
|
import {setConfig} from "./setConfig";
|
||||||
|
import {NTQQUserApi} from "../ntqqapi/api/user";
|
||||||
|
import {NTQQGroupApi} from "../ntqqapi/api/group";
|
||||||
|
import {registerPokeHandler} from "../ntqqapi/external/ccpoke";
|
||||||
|
import {OB11FriendPokeEvent, OB11GroupPokeEvent} from "../onebot11/event/notice/OB11PokeEvent";
|
||||||
|
import {checkNewVersion, upgradeLLOneBot} from "../common/utils/upgrade";
|
||||||
|
import {log} from "../common/utils/log";
|
||||||
|
import {getConfigUtil} from "../common/config";
|
||||||
|
import {checkFfmpeg} from "../common/utils/video";
|
||||||
|
|
||||||
|
|
||||||
let running = false;
|
let running = false;
|
||||||
|
|
||||||
|
let mainWindow: BrowserWindow | null = null;
|
||||||
|
|
||||||
// 加载插件时触发
|
// 加载插件时触发
|
||||||
function onLoad() {
|
function onLoad() {
|
||||||
log("llonebot main onLoad");
|
log("llonebot main onLoad");
|
||||||
|
ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => {
|
||||||
|
|
||||||
|
return checkNewVersion();
|
||||||
|
});
|
||||||
|
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
|
||||||
|
return upgradeLLOneBot();
|
||||||
|
});
|
||||||
ipcMain.handle(CHANNEL_SELECT_FILE, async (event, arg) => {
|
ipcMain.handle(CHANNEL_SELECT_FILE, async (event, arg) => {
|
||||||
const selectPath = new Promise<string>((resolve, reject) => {
|
const selectPath = new Promise<string>((resolve, reject) => {
|
||||||
dialog
|
dialog
|
||||||
@@ -84,68 +94,39 @@ function onLoad() {
|
|||||||
if (!fs.existsSync(DATA_DIR)) {
|
if (!fs.existsSync(DATA_DIR)) {
|
||||||
fs.mkdirSync(DATA_DIR, {recursive: true});
|
fs.mkdirSync(DATA_DIR, {recursive: true});
|
||||||
}
|
}
|
||||||
ipcMain.handle(CHANNEL_ERROR, (event, arg) => {
|
ipcMain.handle(CHANNEL_ERROR, async (event, arg) => {
|
||||||
return llonebotError;
|
const ffmpegOk = await checkFfmpeg(getConfigUtil().getConfig().ffmpeg)
|
||||||
|
llonebotError.ffmpegError = ffmpegOk ? "" : "没有找到ffmpeg,音频只能发送wav和silk,视频尺寸可能异常"
|
||||||
|
let {httpServerError, wsServerError, otherError, ffmpegError} = llonebotError;
|
||||||
|
let error = `${otherError}\n${httpServerError}\n${wsServerError}\n${ffmpegError}`
|
||||||
|
error = error.replace("\n\n", "\n")
|
||||||
|
error = error.trim();
|
||||||
|
return error;
|
||||||
})
|
})
|
||||||
ipcMain.handle(CHANNEL_GET_CONFIG, async (event, arg) => {
|
ipcMain.handle(CHANNEL_GET_CONFIG, async (event, arg) => {
|
||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
return config;
|
return config;
|
||||||
})
|
})
|
||||||
ipcMain.on(CHANNEL_SET_CONFIG, (event, arg: Config) => {
|
ipcMain.on(CHANNEL_SET_CONFIG, (event, ask:boolean, config: Config) => {
|
||||||
let oldConfig = getConfigUtil().getConfig();
|
if (!ask){
|
||||||
getConfigUtil().setConfig(arg)
|
setConfig(config).then();
|
||||||
if (arg.ob11.httpPort != oldConfig.ob11.httpPort && arg.ob11.enableHttp) {
|
return
|
||||||
ob11HTTPServer.restart(arg.ob11.httpPort);
|
|
||||||
}
|
}
|
||||||
// 判断是否启用或关闭HTTP服务
|
dialog.showMessageBox(mainWindow, {
|
||||||
if (!arg.ob11.enableHttp) {
|
type: 'question',
|
||||||
ob11HTTPServer.stop();
|
buttons: ['确认', '取消'],
|
||||||
} else {
|
defaultId: 0, // 默认选中的按钮,0 代表第一个按钮,即 "确认"
|
||||||
ob11HTTPServer.start(arg.ob11.httpPort);
|
title: '确认保存',
|
||||||
}
|
message: '是否保存?',
|
||||||
// 正向ws端口变化,重启服务
|
detail: 'LLOneBot配置已更改,是否保存?'
|
||||||
if (arg.ob11.wsPort != oldConfig.ob11.wsPort) {
|
}).then(result => {
|
||||||
ob11WebsocketServer.restart(arg.ob11.wsPort);
|
if (result.response === 0) {
|
||||||
}
|
setConfig(config).then();
|
||||||
// 判断是否启用或关闭正向ws
|
|
||||||
if (arg.ob11.enableWs != oldConfig.ob11.enableWs) {
|
|
||||||
if (arg.ob11.enableWs) {
|
|
||||||
ob11WebsocketServer.start(arg.ob11.wsPort);
|
|
||||||
} else {
|
} else {
|
||||||
ob11WebsocketServer.stop();
|
|
||||||
}
|
}
|
||||||
}
|
}).catch(err => {
|
||||||
// 判断是否启用或关闭反向ws
|
log("保存设置询问弹窗错误", err);
|
||||||
if (arg.ob11.enableWsReverse != oldConfig.ob11.enableWsReverse) {
|
});
|
||||||
if (arg.ob11.enableWsReverse) {
|
|
||||||
ob11ReverseWebsockets.start();
|
|
||||||
} else {
|
|
||||||
ob11ReverseWebsockets.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (arg.ob11.enableWsReverse) {
|
|
||||||
// 判断反向ws地址有变化
|
|
||||||
if (arg.ob11.wsHosts.length != oldConfig.ob11.wsHosts.length) {
|
|
||||||
ob11ReverseWebsockets.restart();
|
|
||||||
} else {
|
|
||||||
for (const newHost of arg.ob11.wsHosts) {
|
|
||||||
if (!oldConfig.ob11.wsHosts.includes(newHost)) {
|
|
||||||
ob11ReverseWebsockets.restart();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查ffmpeg
|
|
||||||
if (arg.ffmpeg) {
|
|
||||||
checkFfmpeg(arg.ffmpeg).then(success => {
|
|
||||||
if (success) {
|
|
||||||
llonebotError.ffmpegError = ''
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on(CHANNEL_LOG, (event, arg) => {
|
ipcMain.on(CHANNEL_LOG, (event, arg) => {
|
||||||
@@ -155,35 +136,65 @@ function onLoad() {
|
|||||||
async function postReceiveMsg(msgList: RawMessage[]) {
|
async function postReceiveMsg(msgList: RawMessage[]) {
|
||||||
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
||||||
for (let message of msgList) {
|
for (let message of msgList) {
|
||||||
// log("收到新消息", message.msgSeq)
|
|
||||||
message.msgShortId = await dbUtil.addMsg(message)
|
// log("收到新消息", message.msgId, message.msgSeq)
|
||||||
|
// if (message.senderUin !== selfInfo.uin){
|
||||||
|
message.msgShortId = await dbUtil.addMsg(message);
|
||||||
|
// }
|
||||||
|
|
||||||
OB11Constructor.message(message).then((msg) => {
|
OB11Constructor.message(message).then((msg) => {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
msg.raw = message;
|
msg.raw = message;
|
||||||
|
} else {
|
||||||
|
if (msg.message.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
||||||
if (isSelfMsg && !reportSelfMessage) {
|
if (isSelfMsg && !reportSelfMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (isSelfMsg) {
|
||||||
|
msg.target_id = parseInt(message.peerUin);
|
||||||
|
}
|
||||||
postOB11Event(msg);
|
postOB11Event(msg);
|
||||||
// log("post msg", msg)
|
// log("post msg", msg)
|
||||||
}).catch(e => log("constructMessage error: ", e.stack.toString()));
|
}).catch(e => log("constructMessage error: ", e.stack.toString()));
|
||||||
|
OB11Constructor.GroupEvent(message).then(groupEvent => {
|
||||||
|
if (groupEvent) {
|
||||||
|
// log("post group event", groupEvent);
|
||||||
|
postOB11Event(groupEvent);
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startReceiveHook() {
|
async function startReceiveHook() {
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, async (payload) => {
|
if (getConfigUtil().getConfig().enablePoke) {
|
||||||
|
registerPokeHandler((id, isGroup) => {
|
||||||
|
log(`收到戳一戳消息了!是否群聊:${isGroup},id:${id}`)
|
||||||
|
let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent;
|
||||||
|
if (isGroup) {
|
||||||
|
pokeEvent = new OB11GroupPokeEvent(parseInt(id));
|
||||||
|
} else {
|
||||||
|
pokeEvent = new OB11FriendPokeEvent(parseInt(id));
|
||||||
|
}
|
||||||
|
postOB11Event(pokeEvent);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
registerReceiveHook<{
|
||||||
|
msgList: Array<RawMessage>
|
||||||
|
}>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], async (payload) => {
|
||||||
try {
|
try {
|
||||||
await postReceiveMsg(payload.msgList);
|
await postReceiveMsg(payload.msgList);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("report message error: ", e.stack.toString());
|
log("report message error: ", e.stack.toString());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.UPDATE_MSG, async (payload) => {
|
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.UPDATE_MSG], async (payload) => {
|
||||||
for (const message of payload.msgList) {
|
for (const message of payload.msgList) {
|
||||||
// log("message update", message.sendStatus, message)
|
// log("message update", message.sendStatus, message.msgId, message.msgSeq)
|
||||||
if (message.recallTime != "0") {
|
if (message.recallTime != "0") { //todo: 这个判断方法不太好,应该使用灰色消息元素来判断
|
||||||
// 撤回消息上报
|
// 撤回消息上报
|
||||||
const oriMessage = await dbUtil.getMsgByLongId(message.msgId)
|
const oriMessage = await dbUtil.getMsgByLongId(message.msgId)
|
||||||
if (!oriMessage) {
|
if (!oriMessage) {
|
||||||
@@ -198,7 +209,7 @@ function onLoad() {
|
|||||||
let operatorId = message.senderUin
|
let operatorId = message.senderUin
|
||||||
for (const element of message.elements) {
|
for (const element of message.elements) {
|
||||||
const operatorUid = element.grayTipElement?.revokeElement.operatorUid
|
const operatorUid = element.grayTipElement?.revokeElement.operatorUid
|
||||||
const operator = await getGroupMember(message.peerUin, null, operatorUid)
|
const operator = await getGroupMember(message.peerUin, operatorUid)
|
||||||
operatorId = operator.uin
|
operatorId = operator.uin
|
||||||
}
|
}
|
||||||
const groupRecallEvent = new OB11GroupRecallNoticeEvent(
|
const groupRecallEvent = new OB11GroupRecallNoticeEvent(
|
||||||
@@ -207,7 +218,6 @@ function onLoad() {
|
|||||||
parseInt(operatorId),
|
parseInt(operatorId),
|
||||||
oriMessage.msgShortId
|
oriMessage.msgShortId
|
||||||
)
|
)
|
||||||
|
|
||||||
postOB11Event(groupRecallEvent);
|
postOB11Event(groupRecallEvent);
|
||||||
}
|
}
|
||||||
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
||||||
@@ -216,7 +226,7 @@ function onLoad() {
|
|||||||
dbUtil.updateMsg(message).then();
|
dbUtil.updateMsg(message).then();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, async (payload) => {
|
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, async (payload) => {
|
||||||
const {reportSelfMessage} = getConfigUtil().getConfig();
|
const {reportSelfMessage} = getConfigUtil().getConfig();
|
||||||
if (!reportSelfMessage) {
|
if (!reportSelfMessage) {
|
||||||
return
|
return
|
||||||
@@ -232,12 +242,12 @@ function onLoad() {
|
|||||||
"doubt": boolean,
|
"doubt": boolean,
|
||||||
"oldestUnreadSeq": string,
|
"oldestUnreadSeq": string,
|
||||||
"unreadCount": number
|
"unreadCount": number
|
||||||
}>(ReceiveCmd.UNREAD_GROUP_NOTIFY, async (payload) => {
|
}>(ReceiveCmdS.UNREAD_GROUP_NOTIFY, async (payload) => {
|
||||||
if (payload.unreadCount) {
|
if (payload.unreadCount) {
|
||||||
// log("开始获取群通知详情")
|
// log("开始获取群通知详情")
|
||||||
let notify: GroupNotifies;
|
let notify: GroupNotifies;
|
||||||
try {
|
try {
|
||||||
notify = await NTQQApi.getGroupNotifies();
|
notify = await NTQQGroupApi.getGroupNotifies();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// log("获取群通知详情失败", e);
|
// log("获取群通知详情失败", e);
|
||||||
return
|
return
|
||||||
@@ -249,25 +259,23 @@ function onLoad() {
|
|||||||
for (const notify of notifies) {
|
for (const notify of notifies) {
|
||||||
try {
|
try {
|
||||||
notify.time = Date.now();
|
notify.time = Date.now();
|
||||||
const notifyTime = parseInt(notify.seq) / 1000
|
// const notifyTime = parseInt(notify.seq) / 1000
|
||||||
// log(`加群通知时间${notifyTime}`, `LLOneBot启动时间${startTime}`);
|
// log(`加群通知时间${notifyTime}`, `LLOneBot启动时间${startTime}`);
|
||||||
// if (notifyTime < startTime) {
|
// if (notifyTime < startTime) {
|
||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
let existNotify = groupNotifies[notify.seq];
|
let existNotify = await dbUtil.getGroupNotify(notify.seq);
|
||||||
if (existNotify) {
|
if (existNotify) {
|
||||||
if (Date.now() - existNotify.time < 3000) {
|
continue
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
log("收到群通知", notify);
|
log("收到群通知", notify);
|
||||||
groupNotifies[notify.seq] = notify;
|
await dbUtil.addGroupNotify(notify);
|
||||||
// let member2: GroupMember;
|
// let member2: GroupMember;
|
||||||
// if (notify.user2.uid) {
|
// if (notify.user2.uid) {
|
||||||
// member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
|
// member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
|
||||||
// }
|
// }
|
||||||
if ([GroupNotifyTypes.ADMIN_SET, GroupNotifyTypes.ADMIN_UNSET].includes(notify.type)) {
|
if ([GroupNotifyTypes.ADMIN_SET, GroupNotifyTypes.ADMIN_UNSET].includes(notify.type)) {
|
||||||
const member1 = await getGroupMember(notify.group.groupCode, null, notify.user1.uid);
|
const member1 = await getGroupMember(notify.group.groupCode, notify.user1.uid);
|
||||||
log("有管理员变动通知");
|
log("有管理员变动通知");
|
||||||
refreshGroupMembers(notify.group.groupCode).then()
|
refreshGroupMembers(notify.group.groupCode).then()
|
||||||
let groupAdminNoticeEvent = new OB11GroupAdminNoticeEvent()
|
let groupAdminNoticeEvent = new OB11GroupAdminNoticeEvent()
|
||||||
@@ -292,7 +300,7 @@ function onLoad() {
|
|||||||
groupRequestEvent.group_id = parseInt(notify.group.groupCode);
|
groupRequestEvent.group_id = parseInt(notify.group.groupCode);
|
||||||
let requestQQ = ""
|
let requestQQ = ""
|
||||||
try {
|
try {
|
||||||
requestQQ = (await NTQQApi.getUserDetailInfo(notify.user1.uid)).uin;
|
requestQQ = (await NTQQUserApi.getUserDetailInfo(notify.user1.uid)).uin;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("获取加群人QQ号失败", e)
|
log("获取加群人QQ号失败", e)
|
||||||
}
|
}
|
||||||
@@ -305,9 +313,9 @@ function onLoad() {
|
|||||||
log("收到邀请我加群通知")
|
log("收到邀请我加群通知")
|
||||||
let groupInviteEvent = new OB11GroupRequestEvent();
|
let groupInviteEvent = new OB11GroupRequestEvent();
|
||||||
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
||||||
let user_id = (await getFriend("", notify.user2.uid))?.uin
|
let user_id = (await getFriend(notify.user2.uid))?.uin
|
||||||
if (!user_id){
|
if (!user_id) {
|
||||||
user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin
|
user_id = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))?.uin
|
||||||
}
|
}
|
||||||
groupInviteEvent.user_id = parseInt(user_id);
|
groupInviteEvent.user_id = parseInt(user_id);
|
||||||
groupInviteEvent.sub_type = "invite";
|
groupInviteEvent.sub_type = "invite";
|
||||||
@@ -324,14 +332,14 @@ function onLoad() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
registerReceiveHook<FriendRequestNotify>(ReceiveCmd.FRIEND_REQUEST, async (payload) => {
|
registerReceiveHook<FriendRequestNotify>(ReceiveCmdS.FRIEND_REQUEST, async (payload) => {
|
||||||
for (const req of payload.data.buddyReqs) {
|
for (const req of payload.data.buddyReqs) {
|
||||||
if (req.isUnread && !friendRequests[req.sourceId] && (parseInt(req.reqTime) > startTime / 1000)) {
|
if (req.isUnread && !friendRequests[req.sourceId] && (parseInt(req.reqTime) > startTime / 1000)) {
|
||||||
friendRequests[req.sourceId] = req;
|
friendRequests[req.sourceId] = req;
|
||||||
log("有新的好友请求", req);
|
log("有新的好友请求", req);
|
||||||
let friendRequestEvent = new OB11FriendRequestEvent();
|
let friendRequestEvent = new OB11FriendRequestEvent();
|
||||||
try {
|
try {
|
||||||
let requester = await NTQQApi.getUserDetailInfo(req.friendUid)
|
let requester = await NTQQUserApi.getUserDetailInfo(req.friendUid)
|
||||||
friendRequestEvent.user_id = parseInt(requester.uin);
|
friendRequestEvent.user_id = parseInt(requester.uin);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("获取加好友者QQ号失败", e);
|
log("获取加好友者QQ号失败", e);
|
||||||
@@ -347,22 +355,19 @@ function onLoad() {
|
|||||||
let startTime = 0;
|
let startTime = 0;
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
|
log("llonebot pid", process.pid)
|
||||||
|
llonebotError.otherError = "";
|
||||||
startTime = Date.now();
|
startTime = Date.now();
|
||||||
startReceiveHook().then();
|
dbUtil.getReceivedTempUinMap().then(m=>{
|
||||||
NTQQApi.getGroups(true).then()
|
for (const [key, value] of Object.entries(m)) {
|
||||||
const config = getConfigUtil().getConfig()
|
uidMaps[value] = key;
|
||||||
// 检查ffmpeg
|
|
||||||
checkFfmpeg(config.ffmpeg).then(exist => {
|
|
||||||
if (!exist) {
|
|
||||||
llonebotError.ffmpegError = `没有找到ffmpeg,音频只能发送wav和silk`
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
startReceiveHook().then();
|
||||||
|
NTQQGroupApi.getGroups(true).then()
|
||||||
|
const config = getConfigUtil().getConfig()
|
||||||
if (config.ob11.enableHttp) {
|
if (config.ob11.enableHttp) {
|
||||||
try {
|
ob11HTTPServer.start(config.ob11.httpPort)
|
||||||
ob11HTTPServer.start(config.ob11.httpPort)
|
|
||||||
} catch (e) {
|
|
||||||
log("http server start failed", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (config.ob11.enableWs) {
|
if (config.ob11.enableWs) {
|
||||||
ob11WebsocketServer.start(config.ob11.wsPort);
|
ob11WebsocketServer.start(config.ob11.wsPort);
|
||||||
@@ -378,30 +383,35 @@ function onLoad() {
|
|||||||
const init = async () => {
|
const init = async () => {
|
||||||
try {
|
try {
|
||||||
log("start get self info")
|
log("start get self info")
|
||||||
const _ = await NTQQApi.getSelfInfo();
|
const _ = await NTQQUserApi.getSelfInfo();
|
||||||
log("get self info api result:", _);
|
log("get self info api result:", _);
|
||||||
Object.assign(selfInfo, _);
|
Object.assign(selfInfo, _);
|
||||||
selfInfo.nick = selfInfo.uin;
|
selfInfo.nick = selfInfo.uin;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("retry get self info", e);
|
log("retry get self info", e);
|
||||||
|
selfInfo.uin = globalThis.authData?.uin;
|
||||||
|
selfInfo.uid = globalThis.authData?.uid;
|
||||||
|
selfInfo.nick = selfInfo.uin;
|
||||||
}
|
}
|
||||||
log("self info", selfInfo);
|
log("self info", selfInfo, globalThis.authData);
|
||||||
if (selfInfo.uin) {
|
if (selfInfo.uin) {
|
||||||
try {
|
async function getUserNick(){
|
||||||
const userInfo = (await NTQQApi.getUserDetailInfo(selfInfo.uid));
|
try {
|
||||||
log("self info", userInfo);
|
|
||||||
if (userInfo) {
|
|
||||||
selfInfo.nick = userInfo.nick;
|
|
||||||
} else {
|
|
||||||
getSelfNickCount++;
|
getSelfNickCount++;
|
||||||
if (getSelfNickCount < 10) {
|
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
||||||
return setTimeout(init, 1000);
|
log("self info", userInfo);
|
||||||
|
if (userInfo) {
|
||||||
|
selfInfo.nick = userInfo.nick;
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log("get self nickname failed", e.stack);
|
||||||
|
}
|
||||||
|
if (getSelfNickCount < 10) {
|
||||||
|
return setTimeout(getUserNick, 1000);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
log("get self nickname failed", e.toString());
|
|
||||||
return setTimeout(init, 1000);
|
|
||||||
}
|
}
|
||||||
|
getUserNick().then()
|
||||||
start().then();
|
start().then();
|
||||||
} else {
|
} else {
|
||||||
setTimeout(init, 1000)
|
setTimeout(init, 1000)
|
||||||
@@ -413,6 +423,11 @@ function onLoad() {
|
|||||||
|
|
||||||
// 创建窗口时触发
|
// 创建窗口时触发
|
||||||
function onBrowserWindowCreated(window: BrowserWindow) {
|
function onBrowserWindowCreated(window: BrowserWindow) {
|
||||||
|
if (selfInfo.uid) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mainWindow = window;
|
||||||
|
log("window create", window.webContents.getURL().toString())
|
||||||
try {
|
try {
|
||||||
hookNTQQApiCall(window);
|
hookNTQQApiCall(window);
|
||||||
hookNTQQApiReceive(window);
|
hookNTQQApiReceive(window);
|
||||||
@@ -427,6 +442,7 @@ try {
|
|||||||
console.log(e.toString())
|
console.log(e.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 这两个函数都是可选的
|
// 这两个函数都是可选的
|
||||||
export {
|
export {
|
||||||
onBrowserWindowCreated
|
onBrowserWindowCreated
|
||||||
|
56
src/main/setConfig.ts
Normal file
56
src/main/setConfig.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import {Config} from "../common/types";
|
||||||
|
import {ob11HTTPServer} from "../onebot11/server/http";
|
||||||
|
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||||
|
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
||||||
|
import {llonebotError} from "../common/data";
|
||||||
|
import {getConfigUtil} from "../common/config";
|
||||||
|
import {checkFfmpeg} from "../common/utils";
|
||||||
|
|
||||||
|
export async function setConfig(config: Config) {
|
||||||
|
let oldConfig = getConfigUtil().getConfig();
|
||||||
|
getConfigUtil().setConfig(config)
|
||||||
|
if (config.ob11.httpPort != oldConfig.ob11.httpPort && config.ob11.enableHttp) {
|
||||||
|
ob11HTTPServer.restart(config.ob11.httpPort);
|
||||||
|
}
|
||||||
|
// 判断是否启用或关闭HTTP服务
|
||||||
|
if (!config.ob11.enableHttp) {
|
||||||
|
ob11HTTPServer.stop();
|
||||||
|
} else {
|
||||||
|
ob11HTTPServer.start(config.ob11.httpPort);
|
||||||
|
}
|
||||||
|
// 正向ws端口变化,重启服务
|
||||||
|
if (config.ob11.wsPort != oldConfig.ob11.wsPort) {
|
||||||
|
ob11WebsocketServer.restart(config.ob11.wsPort);
|
||||||
|
llonebotError.wsServerError = ''
|
||||||
|
}
|
||||||
|
// 判断是否启用或关闭正向ws
|
||||||
|
if (config.ob11.enableWs != oldConfig.ob11.enableWs) {
|
||||||
|
if (config.ob11.enableWs) {
|
||||||
|
ob11WebsocketServer.start(config.ob11.wsPort);
|
||||||
|
} else {
|
||||||
|
ob11WebsocketServer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 判断是否启用或关闭反向ws
|
||||||
|
if (config.ob11.enableWsReverse != oldConfig.ob11.enableWsReverse) {
|
||||||
|
if (config.ob11.enableWsReverse) {
|
||||||
|
ob11ReverseWebsockets.start();
|
||||||
|
} else {
|
||||||
|
ob11ReverseWebsockets.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config.ob11.enableWsReverse) {
|
||||||
|
// 判断反向ws地址有变化
|
||||||
|
if (config.ob11.wsHosts.length != oldConfig.ob11.wsHosts.length) {
|
||||||
|
ob11ReverseWebsockets.restart();
|
||||||
|
} else {
|
||||||
|
for (const newHost of config.ob11.wsHosts) {
|
||||||
|
if (!oldConfig.ob11.wsHosts.includes(newHost)) {
|
||||||
|
ob11ReverseWebsockets.restart();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkFfmpeg(config.ffmpeg).then()
|
||||||
|
}
|
235
src/ntqqapi/api/file.ts
Normal file
235
src/ntqqapi/api/file.ts
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {
|
||||||
|
CacheFileList,
|
||||||
|
CacheFileListItem,
|
||||||
|
CacheFileType,
|
||||||
|
CacheScanResult,
|
||||||
|
ChatCacheList,
|
||||||
|
ChatCacheListItemBasic,
|
||||||
|
ChatType,
|
||||||
|
ElementType
|
||||||
|
} from "../types";
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
import {ReceiveCmdS} from "../hook";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
|
export class NTQQFileApi {
|
||||||
|
static async getFileType(filePath: string) {
|
||||||
|
return await callNTQQApi<{ ext: string }>({
|
||||||
|
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_TYPE, args: [filePath]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getFileMd5(filePath: string) {
|
||||||
|
return await callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.FS_API,
|
||||||
|
methodName: NTQQApiMethod.FILE_MD5,
|
||||||
|
args: [filePath]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async copyFile(filePath: string, destPath: string) {
|
||||||
|
return await callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.FS_API,
|
||||||
|
methodName: NTQQApiMethod.FILE_COPY,
|
||||||
|
args: [{
|
||||||
|
fromPath: filePath,
|
||||||
|
toPath: destPath
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getFileSize(filePath: string) {
|
||||||
|
return await callNTQQApi<number>({
|
||||||
|
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_SIZE, args: [filePath]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传文件到QQ的文件夹
|
||||||
|
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
||||||
|
const md5 = await NTQQFileApi.getFileMd5(filePath);
|
||||||
|
let ext = (await NTQQFileApi.getFileType(filePath))?.ext
|
||||||
|
if (ext) {
|
||||||
|
ext = "." + ext
|
||||||
|
} else {
|
||||||
|
ext = ""
|
||||||
|
}
|
||||||
|
let fileName = `${path.basename(filePath)}`;
|
||||||
|
if (fileName.indexOf(".") === -1) {
|
||||||
|
fileName += ext;
|
||||||
|
}
|
||||||
|
const mediaPath = await callNTQQApi<string>({
|
||||||
|
methodName: NTQQApiMethod.MEDIA_FILE_PATH,
|
||||||
|
args: [{
|
||||||
|
path_info: {
|
||||||
|
md5HexStr: md5,
|
||||||
|
fileName: fileName,
|
||||||
|
elementType: elementType,
|
||||||
|
elementSubType: 0,
|
||||||
|
thumbSize: 0,
|
||||||
|
needCreate: true,
|
||||||
|
downloadType: 1,
|
||||||
|
file_uuid: ""
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
log("media path", mediaPath)
|
||||||
|
await NTQQFileApi.copyFile(filePath, mediaPath);
|
||||||
|
const fileSize = await NTQQFileApi.getFileSize(filePath);
|
||||||
|
return {
|
||||||
|
md5,
|
||||||
|
fileName,
|
||||||
|
path: mediaPath,
|
||||||
|
fileSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, isFile: boolean = false) {
|
||||||
|
// 用于下载收到的消息中的图片等
|
||||||
|
if (sourcePath && fs.existsSync(sourcePath)) {
|
||||||
|
return sourcePath
|
||||||
|
}
|
||||||
|
const apiParams = [
|
||||||
|
{
|
||||||
|
getReq: {
|
||||||
|
fileModelId: "0",
|
||||||
|
downloadSourceType: 0,
|
||||||
|
triggerType: 1,
|
||||||
|
msgId: msgId,
|
||||||
|
chatType: chatType,
|
||||||
|
peerUid: peerUid,
|
||||||
|
elementId: elementId,
|
||||||
|
thumbSize: 0,
|
||||||
|
downloadType: 1,
|
||||||
|
filePath: thumbPath,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
]
|
||||||
|
// log("需要下载media", sourcePath);
|
||||||
|
await callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
||||||
|
args: apiParams,
|
||||||
|
cbCmd: ReceiveCmdS.MEDIA_DOWNLOAD_COMPLETE,
|
||||||
|
cmdCB: (payload: { notifyInfo: { filePath: string, msgId: string } }) => {
|
||||||
|
log("media 下载完成判断", payload.notifyInfo.msgId, msgId);
|
||||||
|
return payload.notifyInfo.msgId == msgId;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return sourcePath
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getImageSize(filePath: string) {
|
||||||
|
return await callNTQQApi<{ width: number, height: number }>({
|
||||||
|
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.IMAGE_SIZE, args: [filePath]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NTQQFileCacheApi {
|
||||||
|
static async setCacheSilentScan(isSilent: boolean = true) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
|
||||||
|
args: [{
|
||||||
|
isSilent
|
||||||
|
}, null]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static getCacheSessionPathList() {
|
||||||
|
return callNTQQApi<{
|
||||||
|
key: string,
|
||||||
|
value: string
|
||||||
|
}[]>({
|
||||||
|
className: NTQQApiClass.OS_API,
|
||||||
|
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
|
||||||
|
return callNTQQApi<any>({ // TODO: 目前还不知道真正的返回值是什么
|
||||||
|
methodName: NTQQApiMethod.CACHE_CLEAR,
|
||||||
|
args: [{
|
||||||
|
keys: cacheKeys
|
||||||
|
}, null]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static addCacheScannedPaths(pathMap: object = {}) {
|
||||||
|
return callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
|
||||||
|
args: [{
|
||||||
|
pathMap: {...pathMap},
|
||||||
|
}, null]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static scanCache() {
|
||||||
|
callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: ReceiveCmdS.CACHE_SCAN_FINISH,
|
||||||
|
classNameIsRegister: true,
|
||||||
|
}).then();
|
||||||
|
return callNTQQApi<CacheScanResult>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_SCAN,
|
||||||
|
args: [null, null],
|
||||||
|
timeoutSecond: 300,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static getHotUpdateCachePath() {
|
||||||
|
return callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.HOTUPDATE_API,
|
||||||
|
methodName: NTQQApiMethod.CACHE_PATH_HOT_UPDATE
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDesktopTmpPath() {
|
||||||
|
return callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.BUSINESS_API,
|
||||||
|
methodName: NTQQApiMethod.CACHE_PATH_DESKTOP_TEMP
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) {
|
||||||
|
return new Promise<ChatCacheList>((res, rej) => {
|
||||||
|
callNTQQApi<ChatCacheList>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_CHAT_GET,
|
||||||
|
args: [{
|
||||||
|
chatType: type,
|
||||||
|
pageSize,
|
||||||
|
order: 1,
|
||||||
|
pageIndex
|
||||||
|
}, null]
|
||||||
|
}).then(list => res(list))
|
||||||
|
.catch(e => rej(e));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) {
|
||||||
|
const _lastRecord = lastRecord ? lastRecord : {fileType: fileType};
|
||||||
|
|
||||||
|
return callNTQQApi<CacheFileList>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_FILE_GET,
|
||||||
|
args: [{
|
||||||
|
fileType: fileType,
|
||||||
|
restart: true,
|
||||||
|
pageSize: pageSize,
|
||||||
|
order: 1,
|
||||||
|
lastRecord: _lastRecord,
|
||||||
|
}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
|
||||||
|
args: [{
|
||||||
|
chats,
|
||||||
|
fileKeys
|
||||||
|
}, null]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
61
src/ntqqapi/api/friend.ts
Normal file
61
src/ntqqapi/api/friend.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import {Friend, FriendRequest} from "../types";
|
||||||
|
import {ReceiveCmdS} from "../hook";
|
||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {friendRequests} from "../../common/data";
|
||||||
|
|
||||||
|
export class NTQQFriendApi{
|
||||||
|
static async getFriends(forced = false) {
|
||||||
|
const data = await callNTQQApi<{
|
||||||
|
data: {
|
||||||
|
categoryId: number,
|
||||||
|
categroyName: string,
|
||||||
|
categroyMbCount: number,
|
||||||
|
buddyList: Friend[]
|
||||||
|
}[]
|
||||||
|
}>(
|
||||||
|
{
|
||||||
|
methodName: NTQQApiMethod.FRIENDS,
|
||||||
|
args: [{force_update: forced}, undefined],
|
||||||
|
cbCmd: ReceiveCmdS.FRIENDS
|
||||||
|
})
|
||||||
|
let _friends: Friend[] = [];
|
||||||
|
for (const fData of data.data) {
|
||||||
|
_friends.push(...fData.buddyList)
|
||||||
|
}
|
||||||
|
return _friends
|
||||||
|
}
|
||||||
|
static async likeFriend(uid: string, count = 1) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.LIKE_FRIEND,
|
||||||
|
args: [{
|
||||||
|
doLikeUserInfo: {
|
||||||
|
friendUid: uid,
|
||||||
|
sourceId: 71,
|
||||||
|
doLikeCount: count,
|
||||||
|
doLikeTollCount: 0
|
||||||
|
}
|
||||||
|
}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async handleFriendRequest(sourceId: number, accept: boolean,) {
|
||||||
|
const request: FriendRequest = friendRequests[sourceId]
|
||||||
|
if (!request) {
|
||||||
|
throw `sourceId ${sourceId}, 对应的好友请求不存在`
|
||||||
|
}
|
||||||
|
const result = await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.HANDLE_FRIEND_REQUEST,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
"approvalInfo": {
|
||||||
|
"friendUid": request.friendUid,
|
||||||
|
"reqTime": request.reqTime,
|
||||||
|
accept
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
delete friendRequests[sourceId];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
205
src/ntqqapi/api/group.ts
Normal file
205
src/ntqqapi/api/group.ts
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
import {ReceiveCmdS} from "../hook";
|
||||||
|
import {Group, GroupMember, GroupMemberRole, GroupNotifies, GroupNotify, GroupRequestOperateTypes} from "../types";
|
||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {uidMaps} from "../../common/data";
|
||||||
|
import {dbUtil} from "../../common/db";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
import {NTQQWindowApi, NTQQWindows} from "./window";
|
||||||
|
|
||||||
|
export class NTQQGroupApi{
|
||||||
|
static async getGroups(forced = false) {
|
||||||
|
let cbCmd = ReceiveCmdS.GROUPS
|
||||||
|
if (process.platform != "win32") {
|
||||||
|
cbCmd = ReceiveCmdS.GROUPS_UNIX
|
||||||
|
}
|
||||||
|
const result = await callNTQQApi<{
|
||||||
|
updateType: number,
|
||||||
|
groupList: Group[]
|
||||||
|
}>({methodName: NTQQApiMethod.GROUPS, args: [{force_update: forced}, undefined], cbCmd})
|
||||||
|
return result.groupList
|
||||||
|
}
|
||||||
|
static async getGroupMembers(groupQQ: string, num = 3000): Promise<GroupMember[]> {
|
||||||
|
const sceneId = await callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.GROUP_MEMBER_SCENE,
|
||||||
|
args: [{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
scene: "groupMemberList_MainWindow"
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
// log("get group member sceneId", sceneId);
|
||||||
|
try {
|
||||||
|
const result = await callNTQQApi<{
|
||||||
|
result: { infos: any }
|
||||||
|
}>({
|
||||||
|
methodName: NTQQApiMethod.GROUP_MEMBERS,
|
||||||
|
args: [{
|
||||||
|
sceneId: sceneId,
|
||||||
|
num: num
|
||||||
|
},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
// log("members info", typeof result.result.infos, Object.keys(result.result.infos))
|
||||||
|
const values = result.result.infos.values()
|
||||||
|
|
||||||
|
const members: GroupMember[] = Array.from(values)
|
||||||
|
for (const member of members) {
|
||||||
|
uidMaps[member.uid] = member.uin;
|
||||||
|
}
|
||||||
|
// log(uidMaps);
|
||||||
|
// log("members info", values);
|
||||||
|
log(`get group ${groupQQ} members success`)
|
||||||
|
return members
|
||||||
|
} catch (e) {
|
||||||
|
log(`get group ${groupQQ} members failed`, e)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static async getGroupNotifies() {
|
||||||
|
// 获取管理员变更
|
||||||
|
// 加群通知,退出通知,需要管理员权限
|
||||||
|
callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: ReceiveCmdS.GROUP_NOTIFY,
|
||||||
|
classNameIsRegister: true,
|
||||||
|
}).then()
|
||||||
|
return await callNTQQApi<GroupNotifies>({
|
||||||
|
methodName: NTQQApiMethod.GET_GROUP_NOTICE,
|
||||||
|
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
||||||
|
afterFirstCmd: false,
|
||||||
|
args: [
|
||||||
|
{"doubt": false, "startSeq": "", "number": 14},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static async getGroupIgnoreNotifies() {
|
||||||
|
await NTQQGroupApi.getGroupNotifies();
|
||||||
|
return await NTQQWindowApi.openWindow(NTQQWindows.GroupNotifyFilterWindow,[], ReceiveCmdS.GROUP_NOTIFY);
|
||||||
|
}
|
||||||
|
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||||
|
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
||||||
|
if (!notify) {
|
||||||
|
throw `${seq}对应的加群通知不存在`
|
||||||
|
}
|
||||||
|
// delete groupNotifies[seq];
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
"doubt": false,
|
||||||
|
"operateMsg": {
|
||||||
|
"operateType": operateType, // 2 拒绝
|
||||||
|
"targetMsg": {
|
||||||
|
"seq": seq, // 通知序列号
|
||||||
|
"type": notify.type,
|
||||||
|
"groupCode": notify.group.groupCode,
|
||||||
|
"postscript": reason
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static async quitGroup(groupQQ: string) {
|
||||||
|
await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.QUIT_GROUP,
|
||||||
|
args: [
|
||||||
|
{"groupCode": groupQQ},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async kickMember(groupQQ: string, kickUids: string[], refuseForever: boolean = false, kickReason: string = '') {
|
||||||
|
return await callNTQQApi<GeneralCallResult>(
|
||||||
|
{
|
||||||
|
methodName: NTQQApiMethod.KICK_MEMBER,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
kickUids,
|
||||||
|
refuseForever,
|
||||||
|
kickReason,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
static async banMember(groupQQ: string, memList: Array<{ uid: string, timeStamp: number }>) {
|
||||||
|
// timeStamp为秒数, 0为解除禁言
|
||||||
|
return await callNTQQApi<GeneralCallResult>(
|
||||||
|
{
|
||||||
|
methodName: NTQQApiMethod.MUTE_MEMBER,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
memList,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
static async banGroup(groupQQ: string, shutUp: boolean) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.MUTE_GROUP,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
shutUp
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
uid: memberUid,
|
||||||
|
cardName
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_MEMBER_ROLE,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
uid: memberUid,
|
||||||
|
role
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async setGroupName(groupQQ: string, groupName: string) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_GROUP_NAME,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
groupName
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 头衔不可用
|
||||||
|
static async setGroupTitle(groupQQ: string, uid: string, title: string) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_GROUP_TITLE,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
uid,
|
||||||
|
title
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static publishGroupBulletin(groupQQ: string, title: string, content: string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
7
src/ntqqapi/api/index.ts
Normal file
7
src/ntqqapi/api/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export * from "./file";
|
||||||
|
export * from "./friend";
|
||||||
|
export * from "./group";
|
||||||
|
export * from "./msg";
|
||||||
|
export * from "./user";
|
||||||
|
export * from "./webapi";
|
||||||
|
export * from "./window";
|
200
src/ntqqapi/api/msg.ts
Normal file
200
src/ntqqapi/api/msg.ts
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {ChatType, RawMessage, SendMessageElement} from "../types";
|
||||||
|
import {dbUtil} from "../../common/db";
|
||||||
|
import {selfInfo} from "../../common/data";
|
||||||
|
import {ReceiveCmdS, registerReceiveHook} from "../hook";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
import {sleep} from "../../common/utils/helper";
|
||||||
|
import {isQQ998} from "../../common/utils";
|
||||||
|
|
||||||
|
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {}// peerUid: callbackFunnc
|
||||||
|
|
||||||
|
export interface Peer {
|
||||||
|
chatType: ChatType
|
||||||
|
peerUid: string // 如果是群聊uid为群号,私聊uid就是加密的字符串
|
||||||
|
guildId?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NTQQMsgApi {
|
||||||
|
static async activateGroupChat(groupCode: string) {
|
||||||
|
// await this.fetchRecentContact();
|
||||||
|
// await sleep(500);
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.ADD_ACTIVE_CHAT,
|
||||||
|
args: [{peer:{peerUid: groupCode, chatType: ChatType.group}, cnt: 20}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async getMsgHistory(peer: Peer, msgId: string, count: number) {
|
||||||
|
return await callNTQQApi<GeneralCallResult & {msgList: RawMessage[]}>({
|
||||||
|
methodName: isQQ998 ? NTQQApiMethod.HISTORY_MSG_998 : NTQQApiMethod.HISTORY_MSG,
|
||||||
|
args: [{
|
||||||
|
peer,
|
||||||
|
msgId,
|
||||||
|
cnt: count,
|
||||||
|
queryOrder: true,
|
||||||
|
}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async fetchRecentContact(){
|
||||||
|
await callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.RECENT_CONTACT,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
fetchParam: {
|
||||||
|
anchorPointContact: {
|
||||||
|
contactId: '',
|
||||||
|
sortField: '',
|
||||||
|
pos: 0,
|
||||||
|
},
|
||||||
|
relativeMoveCount: 0,
|
||||||
|
listType: 2, // 1普通消息,2群助手内的消息
|
||||||
|
count: 200,
|
||||||
|
fetchOld: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async recallMsg(peer: Peer, msgIds: string[]) {
|
||||||
|
return await callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.RECALL_MSG,
|
||||||
|
args: [{
|
||||||
|
peer,
|
||||||
|
msgIds
|
||||||
|
}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async sendMsg(peer: Peer, msgElements: SendMessageElement[],
|
||||||
|
waitComplete = true, timeout = 10000) {
|
||||||
|
const peerUid = peer.peerUid
|
||||||
|
|
||||||
|
// 等待上一个相同的peer发送完
|
||||||
|
let checkLastSendUsingTime = 0;
|
||||||
|
const waitLastSend = async () => {
|
||||||
|
if (checkLastSendUsingTime > timeout) {
|
||||||
|
throw ("发送超时")
|
||||||
|
}
|
||||||
|
let lastSending = sendMessagePool[peer.peerUid]
|
||||||
|
if (lastSending) {
|
||||||
|
// log("有正在发送的消息,等待中...")
|
||||||
|
await sleep(500);
|
||||||
|
checkLastSendUsingTime += 500;
|
||||||
|
return await waitLastSend();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await waitLastSend();
|
||||||
|
|
||||||
|
let sentMessage: RawMessage = null;
|
||||||
|
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
||||||
|
delete sendMessagePool[peerUid];
|
||||||
|
sentMessage = rawMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
let checkSendCompleteUsingTime = 0;
|
||||||
|
const checkSendComplete = async (): Promise<RawMessage> => {
|
||||||
|
if (sentMessage) {
|
||||||
|
if (waitComplete) {
|
||||||
|
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
||||||
|
return sentMessage
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return sentMessage
|
||||||
|
}
|
||||||
|
// log(`给${peerUid}发送消息成功`)
|
||||||
|
}
|
||||||
|
checkSendCompleteUsingTime += 500
|
||||||
|
if (checkSendCompleteUsingTime > timeout) {
|
||||||
|
throw ('发送超时')
|
||||||
|
}
|
||||||
|
await sleep(500)
|
||||||
|
return await checkSendComplete()
|
||||||
|
}
|
||||||
|
|
||||||
|
callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.SEND_MSG,
|
||||||
|
args: [{
|
||||||
|
msgId: "0",
|
||||||
|
peer, msgElements,
|
||||||
|
msgAttributeInfos: new Map(),
|
||||||
|
}, null]
|
||||||
|
}).then()
|
||||||
|
return await checkSendComplete()
|
||||||
|
}
|
||||||
|
|
||||||
|
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.FORWARD_MSG,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
msgIds: msgIds,
|
||||||
|
srcContact: srcPeer,
|
||||||
|
dstContacts: [
|
||||||
|
destPeer
|
||||||
|
],
|
||||||
|
commentElements: [],
|
||||||
|
msgAttributeInfos: new Map()
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||||
|
const msgInfos = msgIds.map(id => {
|
||||||
|
return {msgId: id, senderShowName: selfInfo.nick}
|
||||||
|
})
|
||||||
|
const apiArgs = [
|
||||||
|
{
|
||||||
|
msgInfos,
|
||||||
|
srcContact: srcPeer,
|
||||||
|
dstContact: destPeer,
|
||||||
|
commentElements: [],
|
||||||
|
msgAttributeInfos: new Map()
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
]
|
||||||
|
return await new Promise<RawMessage>((resolve, reject) => {
|
||||||
|
let complete = false
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!complete) {
|
||||||
|
reject("转发消息超时");
|
||||||
|
}
|
||||||
|
}, 5000)
|
||||||
|
registerReceiveHook(ReceiveCmdS.SELF_SEND_MSG, async (payload: { msgRecord: RawMessage }) => {
|
||||||
|
const msg = payload.msgRecord
|
||||||
|
// 需要判断它是转发的消息,并且识别到是当前转发的这一条
|
||||||
|
const arkElement = msg.elements.find(ele => ele.arkElement)
|
||||||
|
if (!arkElement) {
|
||||||
|
// log("收到的不是转发消息")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const forwardData: any = JSON.parse(arkElement.arkElement.bytesData)
|
||||||
|
if (forwardData.app != 'com.tencent.multimsg') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (msg.peerUid == destPeer.peerUid && msg.senderUid == selfInfo.uid) {
|
||||||
|
complete = true
|
||||||
|
await dbUtil.addMsg(msg)
|
||||||
|
resolve(msg)
|
||||||
|
log('转发消息成功:', payload)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.MULTI_FORWARD_MSG,
|
||||||
|
args: apiArgs
|
||||||
|
}).then(result => {
|
||||||
|
log("转发消息结果:", result, apiArgs)
|
||||||
|
if (result.result !== 0) {
|
||||||
|
complete = true;
|
||||||
|
reject("转发消息失败," + JSON.stringify(result));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
103
src/ntqqapi/api/user.ts
Normal file
103
src/ntqqapi/api/user.ts
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {SelfInfo, User} from "../types";
|
||||||
|
import {ReceiveCmdS} from "../hook";
|
||||||
|
import {uidMaps} from "../../common/data";
|
||||||
|
import {NTQQWindowApi, NTQQWindows} from "./window";
|
||||||
|
|
||||||
|
|
||||||
|
export class NTQQUserApi{
|
||||||
|
static async setQQAvatar(filePath: string) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_QQ_AVATAR,
|
||||||
|
args: [{
|
||||||
|
path:filePath
|
||||||
|
}, null],
|
||||||
|
timeoutSecond: 10 // 10秒不一定够
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getSelfInfo() {
|
||||||
|
return await callNTQQApi<SelfInfo>({
|
||||||
|
className: NTQQApiClass.GLOBAL_DATA,
|
||||||
|
methodName: NTQQApiMethod.SELF_INFO, timeoutSecond: 2
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async getUserInfo(uid: string) {
|
||||||
|
const result = await callNTQQApi<{ profiles: Map<string, User> }>({
|
||||||
|
methodName: NTQQApiMethod.USER_INFO,
|
||||||
|
args: [{force: true, uids: [uid]}, undefined],
|
||||||
|
cbCmd: ReceiveCmdS.USER_INFO
|
||||||
|
})
|
||||||
|
return result.profiles.get(uid)
|
||||||
|
}
|
||||||
|
static async getUserDetailInfo(uid: string) {
|
||||||
|
const result = await callNTQQApi<{ info: User }>({
|
||||||
|
methodName: NTQQApiMethod.USER_DETAIL_INFO,
|
||||||
|
cbCmd: ReceiveCmdS.USER_DETAIL_INFO,
|
||||||
|
afterFirstCmd: false,
|
||||||
|
cmdCB: (payload) => {
|
||||||
|
const success = payload.info.uid == uid
|
||||||
|
// log("get user detail info", success, uid, payload)
|
||||||
|
return success
|
||||||
|
},
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
uid
|
||||||
|
},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
const info = result.info
|
||||||
|
if (info?.uin) {
|
||||||
|
uidMaps[info.uid] = info.uin
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getPSkey() {
|
||||||
|
return await callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.GROUP_HOME_WORK,
|
||||||
|
methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
domain: "qun.qq.com"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async getSkey(groupName: string, groupCode: string): Promise<{data: string}> {
|
||||||
|
return await NTQQWindowApi.openWindow<{data: string}>(NTQQWindows.GroupHomeWorkWindow, [{
|
||||||
|
groupName,
|
||||||
|
groupCode,
|
||||||
|
"source": "funcbar"
|
||||||
|
}], ReceiveCmdS.SKEY_UPDATE, 1);
|
||||||
|
// return await callNTQQApi<string>({
|
||||||
|
// className: NTQQApiClass.GROUP_HOME_WORK,
|
||||||
|
// methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||||
|
// args: [
|
||||||
|
// {
|
||||||
|
// domain: "qun.qq.com"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// })
|
||||||
|
// return await callNTQQApi<GeneralCallResult>({
|
||||||
|
// methodName: NTQQApiMethod.GET_SKEY,
|
||||||
|
// args: [
|
||||||
|
// {
|
||||||
|
// "domains": [
|
||||||
|
// "qzone.qq.com",
|
||||||
|
// "qlive.qq.com",
|
||||||
|
// "qun.qq.com",
|
||||||
|
// "gamecenter.qq.com",
|
||||||
|
// "vip.qq.com",
|
||||||
|
// "qianbao.qq.com",
|
||||||
|
// "qidian.qq.com"
|
||||||
|
// ],
|
||||||
|
// "isForNewPCQQ": false
|
||||||
|
// },
|
||||||
|
// null
|
||||||
|
// ]
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
86
src/ntqqapi/api/webapi.ts
Normal file
86
src/ntqqapi/api/webapi.ts
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import {groups} from "../../common/data";
|
||||||
|
import {log} from "../../common/utils";
|
||||||
|
import {NTQQUserApi} from "./user";
|
||||||
|
|
||||||
|
export class WebApi{
|
||||||
|
private static bkn: string;
|
||||||
|
private static skey: string;
|
||||||
|
private static pskey: string;
|
||||||
|
private static cookie: string
|
||||||
|
private defaultHeaders: Record<string,string> = {
|
||||||
|
"User-Agent": "QQ/8.9.28.635 CFNetwork/1312 Darwin/21.0.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async addGroupDigest(groupCode: string, msgSeq: string){
|
||||||
|
const url = `https://qun.qq.com/cgi-bin/group_digest/cancel_digest?random=665&X-CROSS-ORIGIN=fetch&group_code=${groupCode}&msg_seq=${msgSeq}&msg_random=444021292`
|
||||||
|
const res = await this.request(url)
|
||||||
|
return await res.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getGroupDigest(groupCode: string){
|
||||||
|
const url = `https://qun.qq.com/cgi-bin/group_digest/digest_list?random=665&X-CROSS-ORIGIN=fetch&group_code=${groupCode}&page_start=0&page_limit=20`
|
||||||
|
const res = await this.request(url)
|
||||||
|
log(res.headers)
|
||||||
|
return await res.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
private genBkn(sKey: string){
|
||||||
|
sKey = sKey || "";
|
||||||
|
let hash = 5381;
|
||||||
|
|
||||||
|
for (let i = 0; i < sKey.length; i++) {
|
||||||
|
const code = sKey.charCodeAt(i);
|
||||||
|
hash = hash + (hash << 5) + code;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (hash & 0x7FFFFFFF).toString();
|
||||||
|
}
|
||||||
|
private async init(){
|
||||||
|
if (!WebApi.bkn) {
|
||||||
|
const group = groups[0];
|
||||||
|
WebApi.skey = (await NTQQUserApi.getSkey(group.groupName, group.groupCode)).data;
|
||||||
|
WebApi.bkn = this.genBkn(WebApi.skey);
|
||||||
|
let cookie = await NTQQUserApi.getPSkey();
|
||||||
|
const pskeyRegex = /p_skey=([^;]+)/;
|
||||||
|
const match = cookie.match(pskeyRegex);
|
||||||
|
const pskeyValue = match ? match[1] : null;
|
||||||
|
WebApi.pskey = pskeyValue;
|
||||||
|
if (cookie.indexOf("skey=;") !== -1) {
|
||||||
|
cookie = cookie.replace("skey=;", `skey=${WebApi.skey};`);
|
||||||
|
}
|
||||||
|
WebApi.cookie = cookie;
|
||||||
|
// for(const kv of WebApi.cookie.split(";")){
|
||||||
|
// const [key, value] = kv.split("=");
|
||||||
|
// }
|
||||||
|
// log("set cookie", key, value)
|
||||||
|
// await session.defaultSession.cookies.set({
|
||||||
|
// url: 'https://qun.qq.com', // 你要请求的域名
|
||||||
|
// name: key.trim(),
|
||||||
|
// value: value.trim(),
|
||||||
|
// expirationDate: Date.now() / 1000 + 300000, // Cookie 过期时间,例如设置为当前时间之后的300秒
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async request(url: string, method: "GET" | "POST" = "GET", headers: Record<string, string> = {}){
|
||||||
|
|
||||||
|
await this.init();
|
||||||
|
url += "&bkn=" + WebApi.bkn;
|
||||||
|
let _headers: Record<string, string> = {
|
||||||
|
...this.defaultHeaders, ...headers,
|
||||||
|
"Cookie": WebApi.cookie,
|
||||||
|
credentials: 'include'
|
||||||
|
}
|
||||||
|
log("request", url, _headers)
|
||||||
|
const options = {
|
||||||
|
method: method,
|
||||||
|
headers: _headers
|
||||||
|
}
|
||||||
|
return fetch(url, options)
|
||||||
|
}
|
||||||
|
}
|
49
src/ntqqapi/api/window.ts
Normal file
49
src/ntqqapi/api/window.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {ReceiveCmd} from "../hook";
|
||||||
|
import {BrowserWindow} from "electron";
|
||||||
|
|
||||||
|
export interface NTQQWindow{
|
||||||
|
windowName: string,
|
||||||
|
windowUrlHash: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NTQQWindows{
|
||||||
|
static GroupHomeWorkWindow: NTQQWindow = {
|
||||||
|
windowName: "GroupHomeWorkWindow",
|
||||||
|
windowUrlHash: "#/group-home-work"
|
||||||
|
}
|
||||||
|
static GroupNotifyFilterWindow: NTQQWindow = {
|
||||||
|
windowName: "GroupNotifyFilterWindow",
|
||||||
|
windowUrlHash: "#/group-notify-filter"
|
||||||
|
}
|
||||||
|
static GroupEssenceWindow: NTQQWindow = {
|
||||||
|
windowName: "GroupEssenceWindow",
|
||||||
|
windowUrlHash: "#/group-essence"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NTQQWindowApi{
|
||||||
|
|
||||||
|
// 打开窗口并获取对应的下发事件
|
||||||
|
static async openWindow<R=GeneralCallResult>(ntQQWindow: NTQQWindow, args: any[], cbCmd: ReceiveCmd=null, autoCloseSeconds: number=2){
|
||||||
|
const result = await callNTQQApi<R>({
|
||||||
|
className: NTQQApiClass.WINDOW_API,
|
||||||
|
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
|
||||||
|
cbCmd,
|
||||||
|
afterFirstCmd: false,
|
||||||
|
args: [
|
||||||
|
ntQQWindow.windowName,
|
||||||
|
...args
|
||||||
|
]
|
||||||
|
})
|
||||||
|
setTimeout(() => {
|
||||||
|
for (const w of BrowserWindow.getAllWindows()) {
|
||||||
|
// log("close window", w.webContents.getURL())
|
||||||
|
if (w.webContents.getURL().indexOf(ntQQWindow.windowUrlHash) != -1) {
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, autoCloseSeconds * 1000);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,16 +1,23 @@
|
|||||||
import {
|
import {
|
||||||
AtType,
|
AtType,
|
||||||
ElementType, PicType, SendArkElement,
|
ElementType,
|
||||||
|
PicType,
|
||||||
|
SendArkElement,
|
||||||
SendFaceElement,
|
SendFaceElement,
|
||||||
SendFileElement,
|
SendFileElement,
|
||||||
SendPicElement,
|
SendPicElement,
|
||||||
SendPttElement,
|
SendPttElement,
|
||||||
SendReplyElement,
|
SendReplyElement,
|
||||||
SendTextElement
|
SendTextElement,
|
||||||
|
SendVideoElement
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import {NTQQApi} from "./ntcall";
|
import {promises as fs} from "node:fs";
|
||||||
import {encodeSilk, isGIF} from "../common/utils";
|
import ffmpeg from "fluent-ffmpeg"
|
||||||
import * as fs from "node:fs";
|
import {NTQQFileApi} from "./api/file";
|
||||||
|
import {calculateFileMD5, isGIF} from "../common/utils/file";
|
||||||
|
import {log} from "../common/utils/log";
|
||||||
|
import {defaultVideoThumb, getVideoInfo} from "../common/utils/video";
|
||||||
|
import {encodeSilk} from "../common/utils/audio";
|
||||||
|
|
||||||
|
|
||||||
export class SendMsgElementConstructor {
|
export class SendMsgElementConstructor {
|
||||||
@@ -55,9 +62,12 @@ export class SendMsgElementConstructor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async pic(picPath: string): Promise<SendPicElement> {
|
static async pic(picPath: string, summary: string = ""): Promise<SendPicElement> {
|
||||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(picPath, ElementType.PIC);
|
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC);
|
||||||
const imageSize = await NTQQApi.getImageSize(picPath);
|
if (fileSize === 0) {
|
||||||
|
throw "文件异常,大小为0";
|
||||||
|
}
|
||||||
|
const imageSize = await NTQQFileApi.getImageSize(picPath);
|
||||||
const picElement = {
|
const picElement = {
|
||||||
md5HexStr: md5,
|
md5HexStr: md5,
|
||||||
fileSize: fileSize,
|
fileSize: fileSize,
|
||||||
@@ -71,7 +81,7 @@ export class SendMsgElementConstructor {
|
|||||||
fileUuid: "",
|
fileUuid: "",
|
||||||
fileSubId: "",
|
fileSubId: "",
|
||||||
thumbFileSize: 0,
|
thumbFileSize: 0,
|
||||||
summary: "",
|
summary,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -81,15 +91,9 @@ export class SendMsgElementConstructor {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static async file(filePath: string, showPreview: boolean = false, fileName: string = ""): Promise<SendFileElement> {
|
static async file(filePath: string, fileName: string = ""): Promise<SendFileElement> {
|
||||||
let picHeight = 0;
|
const {md5, fileName: _fileName, path, fileSize} = await NTQQFileApi.uploadFile(filePath, ElementType.FILE);
|
||||||
let picWidth = 0;
|
if (fileSize === 0) {
|
||||||
if (showPreview) {
|
|
||||||
picHeight = 1024;
|
|
||||||
picWidth = 768;
|
|
||||||
}
|
|
||||||
const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE);
|
|
||||||
if (fileSize === 0){
|
|
||||||
throw "文件异常,大小为0";
|
throw "文件异常,大小为0";
|
||||||
}
|
}
|
||||||
let element: SendFileElement = {
|
let element: SendFileElement = {
|
||||||
@@ -99,25 +103,105 @@ export class SendMsgElementConstructor {
|
|||||||
fileName: fileName || _fileName,
|
fileName: fileName || _fileName,
|
||||||
"filePath": path,
|
"filePath": path,
|
||||||
"fileSize": (fileSize).toString(),
|
"fileSize": (fileSize).toString(),
|
||||||
picHeight,
|
|
||||||
picWidth
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
static video(filePath: string, fileName: string=""): Promise<SendFileElement> {
|
static async video(filePath: string, fileName: string = "", diyThumbPath: string = ""): Promise<SendVideoElement> {
|
||||||
return SendMsgElementConstructor.file(filePath, true, fileName);
|
let {fileName: _fileName, path, fileSize, md5} = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO);
|
||||||
|
if (fileSize === 0) {
|
||||||
|
throw "文件异常,大小为0";
|
||||||
|
}
|
||||||
|
const pathLib = require("path");
|
||||||
|
let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
|
||||||
|
thumb = pathLib.dirname(thumb)
|
||||||
|
// log("thumb 目录", thumb)
|
||||||
|
let videoInfo ={
|
||||||
|
width: 1920, height: 1080,
|
||||||
|
time: 15,
|
||||||
|
format: "mp4",
|
||||||
|
size: fileSize,
|
||||||
|
filePath
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
videoInfo = await getVideoInfo(path);
|
||||||
|
log("视频信息", videoInfo)
|
||||||
|
}catch (e) {
|
||||||
|
log("获取视频信息失败", e)
|
||||||
|
}
|
||||||
|
const createThumb = new Promise<string>((resolve, reject) => {
|
||||||
|
const thumbFileName = `${md5}_0.png`
|
||||||
|
const thumbPath = pathLib.join(thumb, thumbFileName)
|
||||||
|
ffmpeg(filePath)
|
||||||
|
.on("end", () => {
|
||||||
|
})
|
||||||
|
.on("error", (err) => {
|
||||||
|
log("获取视频封面失败,使用默认封面", err)
|
||||||
|
if (diyThumbPath) {
|
||||||
|
fs.copyFile(diyThumbPath, thumbPath).then(() => {
|
||||||
|
resolve(thumbPath);
|
||||||
|
}).catch(reject)
|
||||||
|
} else {
|
||||||
|
fs.writeFile(thumbPath, defaultVideoThumb).then(() => {
|
||||||
|
resolve(thumbPath);
|
||||||
|
}).catch(reject)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.screenshots({
|
||||||
|
timestamps: [0],
|
||||||
|
filename: thumbFileName,
|
||||||
|
folder: thumb,
|
||||||
|
size: videoInfo.width + "x" + videoInfo.height
|
||||||
|
}).on("end", () => {
|
||||||
|
resolve(thumbPath);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
let thumbPath = new Map()
|
||||||
|
const _thumbPath = await createThumb;
|
||||||
|
const thumbSize = (await fs.stat(_thumbPath)).size;
|
||||||
|
// log("生成缩略图", _thumbPath)
|
||||||
|
thumbPath.set(0, _thumbPath)
|
||||||
|
const thumbMd5 = await calculateFileMD5(_thumbPath);
|
||||||
|
let element: SendVideoElement = {
|
||||||
|
elementType: ElementType.VIDEO,
|
||||||
|
elementId: "",
|
||||||
|
videoElement: {
|
||||||
|
fileName: fileName || _fileName,
|
||||||
|
filePath: path,
|
||||||
|
videoMd5: md5,
|
||||||
|
thumbMd5,
|
||||||
|
fileTime: videoInfo.time,
|
||||||
|
thumbPath: thumbPath,
|
||||||
|
thumbSize,
|
||||||
|
thumbWidth: videoInfo.width,
|
||||||
|
thumbHeight: videoInfo.height,
|
||||||
|
fileSize: "" + fileSize,
|
||||||
|
// fileUuid: "",
|
||||||
|
// transferStatus: 0,
|
||||||
|
// progress: 0,
|
||||||
|
// invalidState: 0,
|
||||||
|
// fileSubId: "",
|
||||||
|
// fileBizId: null,
|
||||||
|
// originVideoMd5: "",
|
||||||
|
// fileFormat: 2,
|
||||||
|
// import_rich_media_context: null,
|
||||||
|
// sourceVideoCodecFormat: 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async ptt(pttPath: string): Promise<SendPttElement> {
|
static async ptt(pttPath: string): Promise<SendPttElement> {
|
||||||
const {converted, path: silkPath, duration} = await encodeSilk(pttPath);
|
const {converted, path: silkPath, duration} = await encodeSilk(pttPath);
|
||||||
// log("生成语音", silkPath, duration);
|
// log("生成语音", silkPath, duration);
|
||||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(silkPath, ElementType.PTT);
|
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(silkPath, ElementType.PTT);
|
||||||
|
if (fileSize === 0) {
|
||||||
|
throw "文件异常,大小为0";
|
||||||
|
}
|
||||||
if (converted) {
|
if (converted) {
|
||||||
fs.unlink(silkPath, () => {
|
fs.unlink(silkPath).then();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
elementType: ElementType.PTT,
|
elementType: ElementType.PTT,
|
||||||
@@ -128,7 +212,7 @@ export class SendMsgElementConstructor {
|
|||||||
md5HexStr: md5,
|
md5HexStr: md5,
|
||||||
fileSize: fileSize,
|
fileSize: fileSize,
|
||||||
// duration: Math.max(1, Math.round(fileSize / 1024 / 3)), // 一秒钟大概是3kb大小, 小于1秒的按1秒算
|
// duration: Math.max(1, Math.round(fileSize / 1024 / 3)), // 一秒钟大概是3kb大小, 小于1秒的按1秒算
|
||||||
duration: duration / 1000,
|
duration: duration,
|
||||||
formatType: 1,
|
formatType: 1,
|
||||||
voiceType: 1,
|
voiceType: 1,
|
||||||
voiceChangeType: 0,
|
voiceChangeType: 0,
|
||||||
@@ -158,7 +242,11 @@ export class SendMsgElementConstructor {
|
|||||||
return {
|
return {
|
||||||
elementType: ElementType.ARK,
|
elementType: ElementType.ARK,
|
||||||
elementId: "",
|
elementId: "",
|
||||||
arkElement: data
|
arkElement: {
|
||||||
|
bytesData: data,
|
||||||
|
linkInfo: null,
|
||||||
|
subElementType: null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
28
src/ntqqapi/external/ccpoke/index.ts
vendored
Normal file
28
src/ntqqapi/external/ccpoke/index.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
|
let pokeEngine: any = null
|
||||||
|
|
||||||
|
type PokeHandler = (id: string, isGroup: boolean)=>void
|
||||||
|
|
||||||
|
let pokeRecords: Record<string, number> = {}
|
||||||
|
export function registerPokeHandler(handler: PokeHandler){
|
||||||
|
if(!pokeEngine){
|
||||||
|
try {
|
||||||
|
pokeEngine = require("./ccpoke/poke-win32-x64.node")
|
||||||
|
pokeEngine.performHooks();
|
||||||
|
}catch (e) {
|
||||||
|
log("戳一戳引擎加载失败", e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pokeEngine.setHandlerForPokeHook((id: string, isGroup: boolean)=>{
|
||||||
|
let existTime = pokeRecords[id]
|
||||||
|
if (existTime){
|
||||||
|
if (Date.now() - existTime < 1500){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pokeRecords[id] = Date.now()
|
||||||
|
handler(id, isGroup);
|
||||||
|
})
|
||||||
|
}
|
BIN
src/ntqqapi/external/ccpoke/poke-win32-x64.node
vendored
Normal file
BIN
src/ntqqapi/external/ccpoke/poke-win32-x64.node
vendored
Normal file
Binary file not shown.
@@ -1,226 +1,305 @@
|
|||||||
import {type BrowserWindow} from 'electron'
|
import {BrowserWindow} from 'electron';
|
||||||
import {getConfigUtil, log, sleep} from '../common/utils'
|
import {NTQQApiClass} from "./ntcall";
|
||||||
import {NTQQApi, type NTQQApiClass, sendMessagePool} from './ntcall'
|
import {NTQQMsgApi, sendMessagePool} from "./api/msg"
|
||||||
import {type Group, type RawMessage, type User} from './types'
|
import {ChatType, Group, GroupMember, RawMessage, User} from "./types";
|
||||||
import {friends, groups, selfInfo, tempGroupCodeMap} from '../common/data'
|
import {friends, groups, selfInfo, tempGroupCodeMap, uidMaps} from "../common/data";
|
||||||
import {OB11GroupDecreaseEvent} from '../onebot11/event/notice/OB11GroupDecreaseEvent'
|
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
||||||
import {OB11GroupIncreaseEvent} from '../onebot11/event/notice/OB11GroupIncreaseEvent'
|
import {v4 as uuidv4} from "uuid"
|
||||||
import {v4 as uuidv4} from 'uuid'
|
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
||||||
import {postOB11Event} from '../onebot11/server/postOB11Event'
|
import {getConfigUtil, HOOK_LOG} from "../common/config";
|
||||||
import {HOOK_LOG} from '../common/config'
|
import fs from "fs";
|
||||||
import fs from 'fs'
|
|
||||||
import {dbUtil} from "../common/db";
|
import {dbUtil} from "../common/db";
|
||||||
|
import {NTQQGroupApi} from "./api/group";
|
||||||
|
import {log} from "../common/utils/log";
|
||||||
|
import {sleep} from "../common/utils/helper";
|
||||||
|
import {OB11GroupCardEvent} from "../onebot11/event/notice/OB11GroupCardEvent";
|
||||||
|
|
||||||
export const hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
||||||
|
|
||||||
export enum ReceiveCmd {
|
export let ReceiveCmdS = {
|
||||||
UPDATE_MSG = 'nodeIKernelMsgListener/onMsgInfoListUpdate',
|
UPDATE_MSG: "nodeIKernelMsgListener/onMsgInfoListUpdate",
|
||||||
NEW_MSG = 'nodeIKernelMsgListener/onRecvMsg',
|
UPDATE_ACTIVE_MSG: "nodeIKernelMsgListener/onActiveMsgInfoUpdate",
|
||||||
SELF_SEND_MSG = 'nodeIKernelMsgListener/onAddSendMsg',
|
NEW_MSG: `nodeIKernelMsgListener/onRecvMsg`,
|
||||||
USER_INFO = 'nodeIKernelProfileListener/onProfileSimpleChanged',
|
NEW_ACTIVE_MSG: `nodeIKernelMsgListener/onRecvActiveMsg`,
|
||||||
USER_DETAIL_INFO = 'nodeIKernelProfileListener/onProfileDetailInfoChanged',
|
SELF_SEND_MSG: "nodeIKernelMsgListener/onAddSendMsg",
|
||||||
GROUPS = 'nodeIKernelGroupListener/onGroupListUpdate',
|
USER_INFO: "nodeIKernelProfileListener/onProfileSimpleChanged",
|
||||||
GROUPS_UNIX = 'onGroupListUpdate',
|
USER_DETAIL_INFO: "nodeIKernelProfileListener/onProfileDetailInfoChanged",
|
||||||
FRIENDS = 'onBuddyListChange',
|
GROUPS: "nodeIKernelGroupListener/onGroupListUpdate",
|
||||||
MEDIA_DOWNLOAD_COMPLETE = 'nodeIKernelMsgListener/onRichMediaDownloadComplete',
|
GROUPS_UNIX: "onGroupListUpdate",
|
||||||
UNREAD_GROUP_NOTIFY = 'nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated',
|
GROUP_MEMBER_INFO_UPDATE: "nodeIKernelGroupListener/onMemberInfoChange",
|
||||||
GROUP_NOTIFY = 'nodeIKernelGroupListener/onGroupSingleScreenNotifies',
|
FRIENDS: "onBuddyListChange",
|
||||||
FRIEND_REQUEST = 'nodeIKernelBuddyListener/onBuddyReqChange',
|
MEDIA_DOWNLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaDownloadComplete",
|
||||||
SELF_STATUS = 'nodeIKernelProfileListener/onSelfStatusChanged',
|
UNREAD_GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated",
|
||||||
|
GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupSingleScreenNotifies",
|
||||||
|
FRIEND_REQUEST: "nodeIKernelBuddyListener/onBuddyReqChange",
|
||||||
|
SELF_STATUS: 'nodeIKernelProfileListener/onSelfStatusChanged',
|
||||||
|
CACHE_SCAN_FINISH: "nodeIKernelStorageCleanListener/onFinishScan",
|
||||||
|
MEDIA_UPLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaUploadComplete",
|
||||||
|
SKEY_UPDATE: "onSkeyUpdate"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ReceiveCmd = typeof ReceiveCmdS[keyof typeof ReceiveCmdS]
|
||||||
|
|
||||||
interface NTQQApiReturnData<PayloadType = unknown> extends Array<any> {
|
interface NTQQApiReturnData<PayloadType = unknown> extends Array<any> {
|
||||||
0: {
|
0: {
|
||||||
'type': 'request'
|
"type": "request",
|
||||||
'eventName': NTQQApiClass
|
"eventName": NTQQApiClass,
|
||||||
'callbackId'?: string
|
"callbackId"?: string
|
||||||
}
|
},
|
||||||
1:
|
1:
|
||||||
Array<{
|
{
|
||||||
cmdName: ReceiveCmd
|
cmdName: ReceiveCmd,
|
||||||
cmdType: 'event'
|
cmdType: "event",
|
||||||
payload: PayloadType
|
payload: PayloadType
|
||||||
}>
|
}[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const receiveHooks: Array<{
|
let receiveHooks: Array<{
|
||||||
method: ReceiveCmd
|
method: ReceiveCmd[],
|
||||||
hookFunc: ((payload: any) => void | Promise<void>)
|
hookFunc: ((payload: any) => void | Promise<void>)
|
||||||
id: string
|
id: string
|
||||||
}> = []
|
}> = []
|
||||||
|
|
||||||
export function hookNTQQApiReceive(window: BrowserWindow) {
|
export function hookNTQQApiReceive(window: BrowserWindow) {
|
||||||
const originalSend = window.webContents.send
|
const originalSend = window.webContents.send;
|
||||||
const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
|
const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
|
||||||
HOOK_LOG && log(`received ntqq api message: ${channel}`, JSON.stringify(args))
|
// console.log("hookNTQQApiReceive", channel, args)
|
||||||
if (args?.[1] instanceof Array) {
|
let isLogger = false
|
||||||
for (const receiveData of args?.[1]) {
|
try {
|
||||||
const ntQQApiMethodName = receiveData.cmdName
|
isLogger = args[0]?.eventName?.startsWith("ns-LoggerApi")
|
||||||
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
} catch (e) {
|
||||||
for (const hook of receiveHooks) {
|
|
||||||
if (hook.method === ntQQApiMethodName) {
|
}
|
||||||
new Promise((resolve, reject) => {
|
if (!isLogger) {
|
||||||
try {
|
try {
|
||||||
const _ = hook.hookFunc(receiveData.payload)
|
HOOK_LOG && log(`received ntqq api message: ${channel}`, args)
|
||||||
if (hook.hookFunc.constructor.name === 'AsyncFunction') {
|
}catch (e) {
|
||||||
(_ as Promise<void>).then()
|
log("hook log error", e, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (args?.[1] instanceof Array) {
|
||||||
|
for (let receiveData of args?.[1]) {
|
||||||
|
const ntQQApiMethodName = receiveData.cmdName;
|
||||||
|
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
||||||
|
for (let hook of receiveHooks) {
|
||||||
|
if (hook.method.includes(ntQQApiMethodName)) {
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
let _ = hook.hookFunc(receiveData.payload)
|
||||||
|
if (hook.hookFunc.constructor.name === "AsyncFunction") {
|
||||||
|
(_ as Promise<void>).then()
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log("hook error", e, receiveData.payload)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
}).then()
|
||||||
log('hook error', e, receiveData.payload)
|
}
|
||||||
}
|
|
||||||
}).then()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (args[0]?.callbackId) {
|
||||||
if (args[0]?.callbackId) {
|
// log("hookApiCallback", hookApiCallbacks, args)
|
||||||
// log("hookApiCallback", hookApiCallbacks, args)
|
const callbackId = args[0].callbackId;
|
||||||
const callbackId = args[0].callbackId
|
if (hookApiCallbacks[callbackId]) {
|
||||||
if (hookApiCallbacks[callbackId]) {
|
// log("callback found")
|
||||||
// log("callback found")
|
new Promise((resolve, reject) => {
|
||||||
new Promise((resolve, reject) => {
|
hookApiCallbacks[callbackId](args[1]);
|
||||||
hookApiCallbacks[callbackId](args[1])
|
}).then()
|
||||||
}).then()
|
delete hookApiCallbacks[callbackId];
|
||||||
delete hookApiCallbacks[callbackId]
|
}
|
||||||
}
|
}
|
||||||
|
}catch (e) {
|
||||||
|
log("hookNTQQApiReceive error", e.stack.toString(), args)
|
||||||
}
|
}
|
||||||
return originalSend.call(window.webContents, channel, ...args)
|
originalSend.call(window.webContents, channel, ...args);
|
||||||
}
|
}
|
||||||
window.webContents.send = patchSend
|
window.webContents.send = patchSend;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hookNTQQApiCall(window: BrowserWindow) {
|
export function hookNTQQApiCall(window: BrowserWindow) {
|
||||||
// 监听调用NTQQApi
|
// 监听调用NTQQApi
|
||||||
const webContents = window.webContents as any
|
let webContents = window.webContents as any;
|
||||||
const ipc_message_proxy = webContents._events['-ipc-message']?.[0] || webContents._events['-ipc-message']
|
const ipc_message_proxy = webContents._events["-ipc-message"]?.[0] || webContents._events["-ipc-message"];
|
||||||
|
|
||||||
const proxyIpcMsg = new Proxy(ipc_message_proxy, {
|
const proxyIpcMsg = new Proxy(ipc_message_proxy, {
|
||||||
apply(target, thisArg, args) {
|
apply(target, thisArg, args) {
|
||||||
HOOK_LOG && log('call NTQQ api', thisArg, args)
|
// console.log(thisArg, args);
|
||||||
return target.apply(thisArg, args)
|
let isLogger = false
|
||||||
}
|
try {
|
||||||
})
|
isLogger = args[3][0].eventName.startsWith("ns-LoggerApi")
|
||||||
if (webContents._events['-ipc-message']?.[0]) {
|
} catch (e) {
|
||||||
webContents._events['-ipc-message'][0] = proxyIpcMsg
|
|
||||||
|
}
|
||||||
|
if (!isLogger) {
|
||||||
|
try{
|
||||||
|
HOOK_LOG && log("call NTQQ api", thisArg, args);
|
||||||
|
}catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target.apply(thisArg, args);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (webContents._events["-ipc-message"]?.[0]) {
|
||||||
|
webContents._events["-ipc-message"][0] = proxyIpcMsg;
|
||||||
} else {
|
} else {
|
||||||
webContents._events['-ipc-message'] = proxyIpcMsg
|
webContents._events["-ipc-message"] = proxyIpcMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ipc_invoke_proxy = webContents._events["-ipc-invoke"]?.[0] || webContents._events["-ipc-invoke"];
|
||||||
|
const proxyIpcInvoke = new Proxy(ipc_invoke_proxy, {
|
||||||
|
apply(target, thisArg, args) {
|
||||||
|
// console.log(args);
|
||||||
|
HOOK_LOG && log("call NTQQ invoke api", thisArg, args)
|
||||||
|
args[0]["_replyChannel"]["sendReply"] = new Proxy(args[0]["_replyChannel"]["sendReply"], {
|
||||||
|
apply(sendtarget, sendthisArg, sendargs) {
|
||||||
|
sendtarget.apply(sendthisArg, sendargs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let ret = target.apply(thisArg, args);
|
||||||
|
try {
|
||||||
|
HOOK_LOG && log("call NTQQ invoke api return", ret)
|
||||||
|
}catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (webContents._events["-ipc-invoke"]?.[0]) {
|
||||||
|
webContents._events["-ipc-invoke"][0] = proxyIpcInvoke;
|
||||||
|
} else {
|
||||||
|
webContents._events["-ipc-invoke"] = proxyIpcInvoke;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerReceiveHook<PayloadType>(method: ReceiveCmd, hookFunc: (payload: PayloadType) => void): string {
|
export function registerReceiveHook<PayloadType>(method: ReceiveCmd | ReceiveCmd[], hookFunc: (payload: PayloadType) => void): string {
|
||||||
const id = uuidv4()
|
const id = uuidv4()
|
||||||
|
if (!Array.isArray(method)) {
|
||||||
|
method = [method]
|
||||||
|
}
|
||||||
receiveHooks.push({
|
receiveHooks.push({
|
||||||
method,
|
method,
|
||||||
hookFunc,
|
hookFunc,
|
||||||
id
|
id
|
||||||
})
|
})
|
||||||
return id
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeReceiveHook(id: string) {
|
export function removeReceiveHook(id: string) {
|
||||||
const index = receiveHooks.findIndex(h => h.id === id)
|
const index = receiveHooks.findIndex(h => h.id === id)
|
||||||
receiveHooks.splice(index, 1)
|
receiveHooks.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let activatedGroups: string[] = [];
|
||||||
async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
||||||
for (const group of _groups) {
|
for (let group of _groups) {
|
||||||
let existGroup = groups.find(g => g.groupCode == group.groupCode)
|
log("update group", group)
|
||||||
|
if (!activatedGroups.includes(group.groupCode)) {
|
||||||
|
NTQQMsgApi.activateGroupChat(group.groupCode).then((r) => {
|
||||||
|
activatedGroups.push(group.groupCode);
|
||||||
|
// log(`激活群聊天窗口${group.groupName}(${group.groupCode})`, r)
|
||||||
|
// if (r.result !== 0) {
|
||||||
|
// setTimeout(() => NTQQMsgApi.activateGroupChat(group.groupCode).then(r => log(`再次激活群聊天窗口${group.groupName}(${group.groupCode})`, r)), 500);
|
||||||
|
// }else {
|
||||||
|
// }
|
||||||
|
}).catch(log)
|
||||||
|
}
|
||||||
|
let existGroup = groups.find(g => g.groupCode == group.groupCode);
|
||||||
if (existGroup) {
|
if (existGroup) {
|
||||||
Object.assign(existGroup, group)
|
Object.assign(existGroup, group);
|
||||||
} else {
|
} else {
|
||||||
groups.push(group)
|
groups.push(group);
|
||||||
existGroup = group
|
existGroup = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
const members = await NTQQApi.getGroupMembers(group.groupCode)
|
const members = await NTQQGroupApi.getGroupMembers(group.groupCode);
|
||||||
|
|
||||||
if (members) {
|
if (members) {
|
||||||
existGroup.members = members
|
existGroup.members = members;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processGroupEvent(payload) {
|
async function processGroupEvent(payload: {groupList: Group[]}) {
|
||||||
try {
|
try {
|
||||||
const newGroupList = payload.groupList
|
const newGroupList = payload.groupList;
|
||||||
for (const group of newGroupList) {
|
for (const group of newGroupList) {
|
||||||
const existGroup = groups.find(g => g.groupCode == group.groupCode)
|
let existGroup = groups.find(g => g.groupCode == group.groupCode);
|
||||||
if (existGroup) {
|
if (existGroup) {
|
||||||
|
|
||||||
if (existGroup.memberCount > group.memberCount) {
|
if (existGroup.memberCount > group.memberCount) {
|
||||||
const oldMembers = existGroup.members
|
log(`群(${group.groupCode})成员数量减少${existGroup.memberCount} -> ${group.memberCount}`);
|
||||||
|
const oldMembers = existGroup.members;
|
||||||
|
|
||||||
await sleep(200) // 如果请求QQ API的速度过快,通常无法正确拉取到最新的群信息,因此这里人为引入一个延时
|
await sleep(200); // 如果请求QQ API的速度过快,通常无法正确拉取到最新的群信息,因此这里人为引入一个延时
|
||||||
const newMembers = await NTQQApi.getGroupMembers(group.groupCode)
|
const newMembers = await NTQQGroupApi.getGroupMembers(group.groupCode);
|
||||||
|
|
||||||
group.members = newMembers
|
group.members = newMembers;
|
||||||
const newMembersSet = new Set<string>() // 建立索引降低时间复杂度
|
const newMembersSet = new Set<string>(); // 建立索引降低时间复杂度
|
||||||
|
|
||||||
for (const member of newMembers) {
|
for (const member of newMembers) {
|
||||||
newMembersSet.add(member.uin)
|
newMembersSet.add(member.uin);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const member of oldMembers) {
|
for (const member of oldMembers) {
|
||||||
if (!newMembersSet.has(member.uin)) {
|
if (!newMembersSet.has(member.uin)) {
|
||||||
postOB11Event(new OB11GroupDecreaseEvent(group.groupCode, parseInt(member.uin)))
|
postOB11Event(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin)));
|
||||||
break
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (existGroup.memberCount < group.memberCount) {
|
|
||||||
const oldMembers = existGroup.members
|
|
||||||
const oldMembersSet = new Set<string>()
|
|
||||||
for (const member of oldMembers) {
|
|
||||||
oldMembersSet.add(member.uin)
|
|
||||||
}
|
|
||||||
|
|
||||||
await sleep(200)
|
|
||||||
const newMembers = await NTQQApi.getGroupMembers(group.groupCode)
|
|
||||||
|
|
||||||
group.members = newMembers
|
|
||||||
for (const member of newMembers) {
|
|
||||||
if (!oldMembersSet.has(member.uin)) {
|
|
||||||
postOB11Event(new OB11GroupIncreaseEvent(group.groupCode, parseInt(member.uin)))
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGroups(newGroupList, false).then()
|
updateGroups(newGroupList, false).then();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
updateGroups(payload.groupList).then()
|
updateGroups(payload.groupList).then();
|
||||||
console.log(e)
|
log("更新群信息错误", e.stack.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUPS, (payload) => {
|
// 群列表变动
|
||||||
|
registerReceiveHook<{ groupList: Group[], updateType: number }>(process.platform == "win32" ? ReceiveCmdS.GROUPS : ReceiveCmdS.GROUPS_UNIX, (payload) => {
|
||||||
|
log("群列表变动", payload)
|
||||||
if (payload.updateType != 2) {
|
if (payload.updateType != 2) {
|
||||||
updateGroups(payload.groupList).then()
|
updateGroups(payload.groupList).then();
|
||||||
} else {
|
} else {
|
||||||
if (process.platform == 'win32') {
|
processGroupEvent(payload).then();
|
||||||
processGroupEvent(payload).then()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUPS_UNIX, (payload) => {
|
|
||||||
if (payload.updateType != 2) {
|
|
||||||
updateGroups(payload.groupList).then()
|
|
||||||
} else {
|
|
||||||
if (process.platform != 'win32') {
|
|
||||||
processGroupEvent(payload).then()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
registerReceiveHook<{groupCode: string, dataSource: number, members: Set<GroupMember>}>(ReceiveCmdS.GROUP_MEMBER_INFO_UPDATE, (payload) => {
|
||||||
|
const groupCode = payload.groupCode;
|
||||||
|
const members = Array.from(payload.members.values());
|
||||||
|
// log("群成员变动", groupCode, payload.members.keys(), payload.members.values())
|
||||||
|
// const existGroup = groups.find(g => g.groupCode == groupCode);
|
||||||
|
// if (existGroup) {
|
||||||
|
// log("对比群成员", existGroup.members, members)
|
||||||
|
// for (const member of members) {
|
||||||
|
// const existMember = existGroup.members.find(m => m.uin == member.uin);
|
||||||
|
// if (existMember) {
|
||||||
|
// log("对比群名片", existMember.cardName, member.cardName)
|
||||||
|
// if (existMember.cardName != member.cardName) {
|
||||||
|
// postOB11Event(new OB11GroupCardEvent(parseInt(existGroup.groupCode), parseInt(member.uin), member.cardName, existMember.cardName));
|
||||||
|
// }
|
||||||
|
// Object.assign(existMember, member);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
})
|
||||||
|
|
||||||
|
// 好友列表变动
|
||||||
registerReceiveHook<{
|
registerReceiveHook<{
|
||||||
data: Array<{ categoryId: number, categroyName: string, categroyMbCount: number, buddyList: User[] }>
|
data: { categoryId: number, categroyName: string, categroyMbCount: number, buddyList: User[] }[]
|
||||||
}>(ReceiveCmd.FRIENDS, payload => {
|
}>(ReceiveCmdS.FRIENDS, payload => {
|
||||||
for (const fData of payload.data) {
|
for (const fData of payload.data) {
|
||||||
const _friends = fData.buddyList
|
const _friends = fData.buddyList;
|
||||||
for (const friend of _friends) {
|
for (let friend of _friends) {
|
||||||
const existFriend = friends.find(f => f.uin == friend.uin)
|
let existFriend = friends.find(f => f.uin == friend.uin)
|
||||||
if (!existFriend) {
|
if (!existFriend) {
|
||||||
friends.push(friend)
|
friends.push(friend)
|
||||||
} else {
|
} else {
|
||||||
@@ -230,56 +309,81 @@ registerReceiveHook<{
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
registerReceiveHook<{ msgList: RawMessage[] }>(ReceiveCmd.NEW_MSG, (payload) => {
|
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => {
|
||||||
const {autoDeleteFile, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
// 保存一下uid
|
||||||
for (const message of payload.msgList) {
|
for (const message of payload.msgList) {
|
||||||
// log("收到新消息,push到历史记录", message.msgSeq)
|
const uid = message.senderUid;
|
||||||
dbUtil.addMsg(message).then()
|
const uin = message.senderUin;
|
||||||
// 清理文件
|
if (uid && uin) {
|
||||||
if (!autoDeleteFile) {
|
if (message.chatType === ChatType.temp){
|
||||||
continue
|
dbUtil.getReceivedTempUinMap().then(receivedTempUinMap=>{
|
||||||
|
if (!receivedTempUinMap[uin]){
|
||||||
|
receivedTempUinMap[uin] = uid;
|
||||||
|
dbUtil.setReceivedTempUinMap(receivedTempUinMap)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
uidMaps[uid] = uin;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 自动清理新消息文件
|
||||||
|
const {autoDeleteFile} = getConfigUtil().getConfig();
|
||||||
|
if (!autoDeleteFile) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for (const message of payload.msgList) {
|
||||||
|
// log("收到新消息,push到历史记录", message.msgId)
|
||||||
|
// dbUtil.addMsg(message).then()
|
||||||
|
// 清理文件
|
||||||
|
|
||||||
for (const msgElement of message.elements) {
|
for (const msgElement of message.elements) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const picPath = msgElement.picElement?.sourcePath
|
const picPath = msgElement.picElement?.sourcePath
|
||||||
|
const picThumbPath = [...msgElement.picElement?.thumbPath.values()]
|
||||||
const pttPath = msgElement.pttElement?.filePath
|
const pttPath = msgElement.pttElement?.filePath
|
||||||
const pathList = [picPath, pttPath]
|
const filePath = msgElement.fileElement?.filePath
|
||||||
|
const videoPath = msgElement.videoElement?.filePath
|
||||||
|
const videoThumbPath: string[] = [...msgElement.videoElement?.thumbPath.values()]
|
||||||
|
const pathList = [picPath, ...picThumbPath, pttPath, filePath, videoPath, ...videoThumbPath]
|
||||||
if (msgElement.picElement) {
|
if (msgElement.picElement) {
|
||||||
pathList.push(...Object.values(msgElement.picElement.thumbPath))
|
pathList.push(...Object.values(msgElement.picElement.thumbPath))
|
||||||
}
|
}
|
||||||
const aioOpGrayTipElement = msgElement.grayTipElement?.aioOpGrayTipElement
|
const aioOpGrayTipElement = msgElement.grayTipElement?.aioOpGrayTipElement
|
||||||
if (aioOpGrayTipElement){
|
if (aioOpGrayTipElement) {
|
||||||
tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat;
|
tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
// log("需要清理的文件", pathList);
|
// log("需要清理的文件", pathList);
|
||||||
for (const path of pathList) {
|
for (const path of pathList) {
|
||||||
if (path) {
|
if (path) {
|
||||||
fs.unlink(picPath, () => {
|
fs.unlink(picPath, () => {
|
||||||
log('删除文件成功', path)
|
log("删除文件成功", path)
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, autoDeleteFileSecond * 1000)
|
}, getConfigUtil().getConfig().autoDeleteFileSecond * 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, ({msgRecord}) => {
|
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, ({msgRecord}) => {
|
||||||
const message = msgRecord
|
const message = msgRecord;
|
||||||
const peerUid = message.peerUid
|
const peerUid = message.peerUid;
|
||||||
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
||||||
// log("收到自己发送成功的消息", message);
|
// log("收到自己发送成功的消息", message.msgId, message.msgSeq);
|
||||||
dbUtil.addMsg(message).then()
|
dbUtil.addMsg(message).then()
|
||||||
const sendCallback = sendMessagePool[peerUid]
|
const sendCallback = sendMessagePool[peerUid]
|
||||||
if (sendCallback) {
|
if (sendCallback) {
|
||||||
try {
|
try {
|
||||||
sendCallback(message)
|
sendCallback(message);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('receive self msg error', e.stack)
|
log("receive self msg error", e.stack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
registerReceiveHook<{ info: { status: number } }>(ReceiveCmd.SELF_STATUS, (info) => {
|
registerReceiveHook<{ info: { status: number } }>(ReceiveCmdS.SELF_STATUS, (info) => {
|
||||||
selfInfo.online = info.info.status !== 20
|
selfInfo.online = info.info.status !== 20
|
||||||
})
|
})
|
||||||
|
@@ -1,164 +1,161 @@
|
|||||||
import {ipcMain} from 'electron'
|
import {ipcMain} from "electron";
|
||||||
import {hookApiCallbacks, ReceiveCmd, registerReceiveHook, removeReceiveHook} from './hook'
|
import {hookApiCallbacks, ReceiveCmd, ReceiveCmdS, registerReceiveHook, removeReceiveHook} from "./hook";
|
||||||
import {log, sleep} from '../common/utils'
|
|
||||||
import {
|
|
||||||
type ChatType,
|
|
||||||
ElementType,
|
|
||||||
type Friend,
|
|
||||||
type FriendRequest,
|
|
||||||
type Group, GroupMember,
|
|
||||||
type GroupMemberRole,
|
|
||||||
type GroupNotifies,
|
|
||||||
type GroupNotify,
|
|
||||||
type GroupRequestOperateTypes,
|
|
||||||
type RawMessage,
|
|
||||||
type SelfInfo,
|
|
||||||
type SendMessageElement,
|
|
||||||
type User
|
|
||||||
} from './types'
|
|
||||||
import * as fs from 'node:fs'
|
|
||||||
import {friendRequests, groupNotifies, selfInfo, uidMaps} from '../common/data'
|
|
||||||
import {v4 as uuidv4} from 'uuid'
|
|
||||||
import path from 'path'
|
|
||||||
import {dbUtil} from "../common/db";
|
|
||||||
|
|
||||||
interface IPCReceiveEvent {
|
import {v4 as uuidv4} from "uuid"
|
||||||
eventName: string
|
import {log} from "../common/utils/log";
|
||||||
callbackId: string
|
import {NTQQWindow, NTQQWindowApi, NTQQWindows} from "./api/window";
|
||||||
}
|
import {WebApi} from "./api/webapi";
|
||||||
|
import {HOOK_LOG} from "../common/config";
|
||||||
export type IPCReceiveDetail = [
|
|
||||||
{
|
|
||||||
cmdName: NTQQApiMethod
|
|
||||||
payload: unknown
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
export enum NTQQApiClass {
|
export enum NTQQApiClass {
|
||||||
NT_API = 'ns-ntApi',
|
NT_API = "ns-ntApi",
|
||||||
FS_API = 'ns-FsApi',
|
FS_API = "ns-FsApi",
|
||||||
GLOBAL_DATA = 'ns-GlobalDataApi'
|
OS_API = "ns-OsApi",
|
||||||
|
WINDOW_API = "ns-WindowApi",
|
||||||
|
HOTUPDATE_API = "ns-HotUpdateApi",
|
||||||
|
BUSINESS_API = "ns-BusinessApi",
|
||||||
|
GLOBAL_DATA = "ns-GlobalDataApi",
|
||||||
|
SKEY_API = "ns-SkeyApi",
|
||||||
|
GROUP_HOME_WORK = "ns-GroupHomeWork",
|
||||||
|
GROUP_ESSENCE = "ns-GroupEssence",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum NTQQApiMethod {
|
export enum NTQQApiMethod {
|
||||||
LIKE_FRIEND = 'nodeIKernelProfileLikeService/setBuddyProfileLike',
|
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
|
||||||
SELF_INFO = 'fetchAuthData',
|
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
||||||
FRIENDS = 'nodeIKernelBuddyService/getBuddyList',
|
HISTORY_MSG_998 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
||||||
GROUPS = 'nodeIKernelGroupService/getGroupList',
|
HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelf",
|
||||||
GROUP_MEMBER_SCENE = 'nodeIKernelGroupService/createMemberListScene',
|
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
||||||
GROUP_MEMBERS = 'nodeIKernelGroupService/getNextMemberList',
|
SELF_INFO = "fetchAuthData",
|
||||||
USER_INFO = 'nodeIKernelProfileService/getUserSimpleInfo',
|
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
||||||
USER_DETAIL_INFO = 'nodeIKernelProfileService/getUserDetailInfo',
|
GROUPS = "nodeIKernelGroupService/getGroupList",
|
||||||
FILE_TYPE = 'getFileType',
|
GROUP_MEMBER_SCENE = "nodeIKernelGroupService/createMemberListScene",
|
||||||
FILE_MD5 = 'getFileMd5',
|
GROUP_MEMBERS = "nodeIKernelGroupService/getNextMemberList",
|
||||||
FILE_COPY = 'copyFile',
|
USER_INFO = "nodeIKernelProfileService/getUserSimpleInfo",
|
||||||
IMAGE_SIZE = 'getImageSizeFromPath',
|
USER_DETAIL_INFO = "nodeIKernelProfileService/getUserDetailInfo",
|
||||||
FILE_SIZE = 'getFileSize',
|
FILE_TYPE = "getFileType",
|
||||||
MEDIA_FILE_PATH = 'nodeIKernelMsgService/getRichMediaFilePathForGuild',
|
FILE_MD5 = "getFileMd5",
|
||||||
RECALL_MSG = 'nodeIKernelMsgService/recallMsg',
|
FILE_COPY = "copyFile",
|
||||||
SEND_MSG = 'nodeIKernelMsgService/sendMsg',
|
IMAGE_SIZE = "getImageSizeFromPath",
|
||||||
DOWNLOAD_MEDIA = 'nodeIKernelMsgService/downloadRichMedia',
|
FILE_SIZE = "getFileSize",
|
||||||
FORWARD_MSG = "nodeIKernelMsgService/forwardMsgWithComment", // 逐条转发
|
MEDIA_FILE_PATH = "nodeIKernelMsgService/getRichMediaFilePathForGuild",
|
||||||
MULTI_FORWARD_MSG = 'nodeIKernelMsgService/multiForwardMsgWithComment', // 合并转发
|
RECALL_MSG = "nodeIKernelMsgService/recallMsg",
|
||||||
GET_GROUP_NOTICE = 'nodeIKernelGroupService/getSingleScreenNotifies',
|
SEND_MSG = "nodeIKernelMsgService/sendMsg",
|
||||||
HANDLE_GROUP_REQUEST = 'nodeIKernelGroupService/operateSysNotify',
|
DOWNLOAD_MEDIA = "nodeIKernelMsgService/downloadRichMedia",
|
||||||
QUIT_GROUP = 'nodeIKernelGroupService/quitGroup',
|
FORWARD_MSG = "nodeIKernelMsgService/forwardMsgWithComment",
|
||||||
|
MULTI_FORWARD_MSG = "nodeIKernelMsgService/multiForwardMsgWithComment", // 合并转发
|
||||||
|
GET_GROUP_NOTICE = "nodeIKernelGroupService/getSingleScreenNotifies",
|
||||||
|
HANDLE_GROUP_REQUEST = "nodeIKernelGroupService/operateSysNotify",
|
||||||
|
QUIT_GROUP = "nodeIKernelGroupService/quitGroup",
|
||||||
// READ_FRIEND_REQUEST = "nodeIKernelBuddyListener/onDoubtBuddyReqUnreadNumChange"
|
// READ_FRIEND_REQUEST = "nodeIKernelBuddyListener/onDoubtBuddyReqUnreadNumChange"
|
||||||
HANDLE_FRIEND_REQUEST = 'nodeIKernelBuddyService/approvalFriendRequest',
|
HANDLE_FRIEND_REQUEST = "nodeIKernelBuddyService/approvalFriendRequest",
|
||||||
KICK_MEMBER = 'nodeIKernelGroupService/kickMember',
|
KICK_MEMBER = "nodeIKernelGroupService/kickMember",
|
||||||
MUTE_MEMBER = 'nodeIKernelGroupService/setMemberShutUp',
|
MUTE_MEMBER = "nodeIKernelGroupService/setMemberShutUp",
|
||||||
MUTE_GROUP = 'nodeIKernelGroupService/setGroupShutUp',
|
MUTE_GROUP = "nodeIKernelGroupService/setGroupShutUp",
|
||||||
SET_MEMBER_CARD = 'nodeIKernelGroupService/modifyMemberCardName',
|
SET_MEMBER_CARD = "nodeIKernelGroupService/modifyMemberCardName",
|
||||||
SET_MEMBER_ROLE = 'nodeIKernelGroupService/modifyMemberRole',
|
SET_MEMBER_ROLE = "nodeIKernelGroupService/modifyMemberRole",
|
||||||
PUBLISH_GROUP_BULLETIN = 'nodeIKernelGroupService/publishGroupBulletinBulletin',
|
PUBLISH_GROUP_BULLETIN = "nodeIKernelGroupService/publishGroupBulletinBulletin",
|
||||||
SET_GROUP_NAME = 'nodeIKernelGroupService/modifyGroupName',
|
SET_GROUP_NAME = "nodeIKernelGroupService/modifyGroupName",
|
||||||
|
SET_GROUP_TITLE = "nodeIKernelGroupService/modifyMemberSpecialTitle",
|
||||||
|
|
||||||
|
CACHE_SET_SILENCE = 'nodeIKernelStorageCleanService/setSilentScan',
|
||||||
|
CACHE_ADD_SCANNED_PATH = 'nodeIKernelStorageCleanService/addCacheScanedPaths',
|
||||||
|
CACHE_PATH_HOT_UPDATE = 'getHotUpdateCachePath',
|
||||||
|
CACHE_PATH_DESKTOP_TEMP = 'getDesktopTmpPath',
|
||||||
|
CACHE_PATH_SESSION = 'getCleanableAppSessionPathList',
|
||||||
|
CACHE_SCAN = 'nodeIKernelStorageCleanService/scanCache',
|
||||||
|
CACHE_CLEAR = 'nodeIKernelStorageCleanService/clearCacheDataByKeys',
|
||||||
|
|
||||||
|
CACHE_CHAT_GET = 'nodeIKernelStorageCleanService/getChatCacheInfo',
|
||||||
|
CACHE_FILE_GET = 'nodeIKernelStorageCleanService/getFileCacheInfo',
|
||||||
|
CACHE_CHAT_CLEAR = 'nodeIKernelStorageCleanService/clearChatCacheInfo',
|
||||||
|
|
||||||
|
OPEN_EXTRA_WINDOW = 'openExternalWindow',
|
||||||
|
|
||||||
|
SET_QQ_AVATAR = 'nodeIKernelProfileService/setHeader',
|
||||||
|
GET_SKEY = "nodeIKernelTipOffService/getPskey",
|
||||||
|
UPDATE_SKEY = "updatePskey"
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NTQQApiChannel {
|
enum NTQQApiChannel {
|
||||||
IPC_UP_2 = 'IPC_UP_2',
|
IPC_UP_2 = "IPC_UP_2",
|
||||||
IPC_UP_3 = 'IPC_UP_3',
|
IPC_UP_3 = "IPC_UP_3",
|
||||||
IPC_UP_1 = 'IPC_UP_1',
|
IPC_UP_1 = "IPC_UP_1",
|
||||||
}
|
|
||||||
|
|
||||||
export interface Peer {
|
|
||||||
chatType: ChatType
|
|
||||||
peerUid: string // 如果是群聊uid为群号,私聊uid就是加密的字符串
|
|
||||||
guildId?: ''
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NTQQApiParams {
|
interface NTQQApiParams {
|
||||||
methodName: NTQQApiMethod | string
|
methodName: NTQQApiMethod | string,
|
||||||
className?: NTQQApiClass
|
className?: NTQQApiClass,
|
||||||
channel?: NTQQApiChannel
|
channel?: NTQQApiChannel,
|
||||||
classNameIsRegister?: boolean
|
classNameIsRegister?: boolean
|
||||||
args?: unknown[]
|
args?: unknown[],
|
||||||
cbCmd?: ReceiveCmd | null
|
cbCmd?: ReceiveCmd | null,
|
||||||
cmdCB?: (payload: any) => boolean
|
cmdCB?: (payload: any) => boolean;
|
||||||
afterFirstCmd?: boolean // 是否在methodName调用完之后再去hook cbCmd
|
afterFirstCmd?: boolean, // 是否在methodName调用完之后再去hook cbCmd
|
||||||
timeoutSecond?: number
|
timeoutSecond?: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
async function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
||||||
let {
|
let {
|
||||||
className, methodName, channel, args,
|
className, methodName, channel, args,
|
||||||
cbCmd, timeoutSecond: timeout,
|
cbCmd, timeoutSecond: timeout,
|
||||||
classNameIsRegister, cmdCB, afterFirstCmd
|
classNameIsRegister, cmdCB, afterFirstCmd
|
||||||
} = params
|
} = params;
|
||||||
className = className ?? NTQQApiClass.NT_API
|
className = className ?? NTQQApiClass.NT_API;
|
||||||
channel = channel ?? NTQQApiChannel.IPC_UP_2
|
channel = channel ?? NTQQApiChannel.IPC_UP_2;
|
||||||
args = args ?? []
|
args = args ?? [];
|
||||||
timeout = timeout ?? 5
|
timeout = timeout ?? 5;
|
||||||
afterFirstCmd = afterFirstCmd ?? true
|
afterFirstCmd = afterFirstCmd ?? true;
|
||||||
const uuid = uuidv4()
|
const uuid = uuidv4();
|
||||||
// log("callNTQQApi", channel, className, methodName, args, uuid)
|
HOOK_LOG && log("callNTQQApi", channel, className, methodName, args, uuid)
|
||||||
return await new Promise((resolve: (data: ReturnType) => void, reject) => {
|
return new Promise((resolve: (data: ReturnType) => void, reject) => {
|
||||||
// log("callNTQQApiPromise", channel, className, methodName, args, uuid)
|
// log("callNTQQApiPromise", channel, className, methodName, args, uuid)
|
||||||
const _timeout = timeout * 1000
|
const _timeout = timeout * 1000
|
||||||
let success = false
|
let success = false
|
||||||
let eventName = className + '-' + channel[channel.length - 1]
|
let eventName = className + "-" + channel[channel.length - 1];
|
||||||
if (classNameIsRegister) {
|
if (classNameIsRegister) {
|
||||||
eventName += '-register'
|
eventName += "-register";
|
||||||
}
|
}
|
||||||
const apiArgs = [methodName, ...args]
|
const apiArgs = [methodName, ...args]
|
||||||
if (!cbCmd) {
|
if (!cbCmd) {
|
||||||
// QQ后端会返回结果,并且可以插根据uuid识别
|
// QQ后端会返回结果,并且可以根据uuid识别
|
||||||
hookApiCallbacks[uuid] = (r: ReturnType) => {
|
hookApiCallbacks[uuid] = (r: ReturnType) => {
|
||||||
success = true
|
success = true
|
||||||
resolve(r)
|
resolve(r)
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
// 这里的callback比较特殊,QQ后端先返回是否调用成功,再返回一条结果数据
|
// 这里的callback比较特殊,QQ后端先返回是否调用成功,再返回一条结果数据
|
||||||
const secondCallback = () => {
|
const secondCallback = () => {
|
||||||
const hookId = registerReceiveHook<ReturnType>(cbCmd, (payload) => {
|
const hookId = registerReceiveHook<ReturnType>(cbCmd, (payload) => {
|
||||||
// log(methodName, "second callback", cbCmd, payload, cmdCB);
|
// log(methodName, "second callback", cbCmd, payload, cmdCB);
|
||||||
if (cmdCB) {
|
if (!!cmdCB) {
|
||||||
if (cmdCB(payload)) {
|
if (cmdCB(payload)) {
|
||||||
removeReceiveHook(hookId)
|
removeReceiveHook(hookId);
|
||||||
success = true
|
success = true
|
||||||
resolve(payload)
|
resolve(payload);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
removeReceiveHook(hookId)
|
removeReceiveHook(hookId);
|
||||||
success = true
|
success = true
|
||||||
resolve(payload)
|
resolve(payload);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
!afterFirstCmd && secondCallback()
|
!afterFirstCmd && secondCallback();
|
||||||
hookApiCallbacks[uuid] = (result: GeneralCallResult) => {
|
hookApiCallbacks[uuid] = (result: GeneralCallResult) => {
|
||||||
log(`${methodName} callback`, result)
|
log(`${methodName} callback`, result)
|
||||||
if (result?.result == 0 || result === undefined) {
|
if (result?.result == 0 || result === undefined) {
|
||||||
afterFirstCmd && secondCallback()
|
afterFirstCmd && secondCallback();
|
||||||
} else {
|
} else {
|
||||||
success = true
|
success = true
|
||||||
reject(`ntqq api call failed, ${result.errMsg}`)
|
reject(`ntqq api call failed, ${result.errMsg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// log("ntqq api timeout", success, channel, className, methodName)
|
// log("ntqq api timeout", success, channel, className, methodName)
|
||||||
if (!success) {
|
if (!success) {
|
||||||
log(`ntqq api timeout ${channel}, ${eventName}, ${methodName}`, apiArgs)
|
log(`ntqq api timeout ${channel}, ${eventName}, ${methodName}`, apiArgs);
|
||||||
reject(`ntqq api timeout ${channel}, ${eventName}, ${methodName}, ${apiArgs}`)
|
reject(`ntqq api timeout ${channel}, ${eventName}, ${methodName}, ${apiArgs}`)
|
||||||
}
|
}
|
||||||
}, _timeout)
|
}, _timeout)
|
||||||
@@ -172,544 +169,21 @@ async function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {}// peerUid: callbackFunnc
|
|
||||||
|
|
||||||
interface GeneralCallResult {
|
export interface GeneralCallResult {
|
||||||
result: number // 0: success
|
result: number, // 0: success
|
||||||
errMsg: string
|
errMsg: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class NTQQApi {
|
export class NTQQApi {
|
||||||
// static likeFriend = defineNTQQApi<void>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.LIKE_FRIEND)
|
static async call(className: NTQQApiClass, cmdName: string, args: any[],) {
|
||||||
static async likeFriend(uid: string, count = 1) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.LIKE_FRIEND,
|
className,
|
||||||
args: [{
|
methodName: cmdName,
|
||||||
doLikeUserInfo: {
|
|
||||||
friendUid: uid,
|
|
||||||
sourceId: 71,
|
|
||||||
doLikeCount: count,
|
|
||||||
doLikeTollCount: 0
|
|
||||||
}
|
|
||||||
}, null]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getSelfInfo() {
|
|
||||||
return await callNTQQApi<SelfInfo>({
|
|
||||||
className: NTQQApiClass.GLOBAL_DATA,
|
|
||||||
// channel: NTQQApiChannel.IPC_UP_3,
|
|
||||||
methodName: NTQQApiMethod.SELF_INFO,
|
|
||||||
timeoutSecond: 2
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getUserInfo(uid: string) {
|
|
||||||
const result = await callNTQQApi<{ profiles: Map<string, User> }>({
|
|
||||||
methodName: NTQQApiMethod.USER_INFO,
|
|
||||||
args: [{force: true, uids: [uid]}, undefined],
|
|
||||||
cbCmd: ReceiveCmd.USER_INFO
|
|
||||||
})
|
|
||||||
return result.profiles.get(uid)
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getUserDetailInfo(uid: string) {
|
|
||||||
const result = await callNTQQApi<{ info: User }>({
|
|
||||||
methodName: NTQQApiMethod.USER_DETAIL_INFO,
|
|
||||||
cbCmd: ReceiveCmd.USER_DETAIL_INFO,
|
|
||||||
afterFirstCmd: false,
|
|
||||||
cmdCB: (payload) => {
|
|
||||||
const success = payload.info.uid == uid
|
|
||||||
// log("get user detail info", success, uid, payload)
|
|
||||||
return success
|
|
||||||
},
|
|
||||||
args: [
|
args: [
|
||||||
{
|
...args,
|
||||||
uid
|
|
||||||
},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
return result.info
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getFriends(forced = false) {
|
|
||||||
const data = await callNTQQApi<{
|
|
||||||
data: Array<{
|
|
||||||
categoryId: number
|
|
||||||
categroyName: string
|
|
||||||
categroyMbCount: number
|
|
||||||
buddyList: Friend[]
|
|
||||||
}>
|
|
||||||
}>(
|
|
||||||
{
|
|
||||||
methodName: NTQQApiMethod.FRIENDS,
|
|
||||||
args: [{force_update: forced}, undefined],
|
|
||||||
cbCmd: ReceiveCmd.FRIENDS
|
|
||||||
})
|
|
||||||
const _friends: Friend[] = []
|
|
||||||
for (const fData of data.data) {
|
|
||||||
_friends.push(...fData.buddyList)
|
|
||||||
}
|
|
||||||
return _friends
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getGroups(forced = false) {
|
|
||||||
let cbCmd = ReceiveCmd.GROUPS
|
|
||||||
if (process.platform != 'win32') {
|
|
||||||
cbCmd = ReceiveCmd.GROUPS_UNIX
|
|
||||||
}
|
|
||||||
const result = await callNTQQApi<{
|
|
||||||
updateType: number
|
|
||||||
groupList: Group[]
|
|
||||||
}>({methodName: NTQQApiMethod.GROUPS, args: [{force_update: forced}, undefined], cbCmd})
|
|
||||||
return result.groupList
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getGroupMembers(groupQQ: string, num = 3000): Promise<GroupMember[]> {
|
|
||||||
const sceneId = await callNTQQApi({
|
|
||||||
methodName: NTQQApiMethod.GROUP_MEMBER_SCENE,
|
|
||||||
args: [{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
scene: 'groupMemberList_MainWindow'
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
// log("get group member sceneId", sceneId);
|
|
||||||
try {
|
|
||||||
const result = await callNTQQApi<{
|
|
||||||
result: { infos: any }
|
|
||||||
}>({
|
|
||||||
methodName: NTQQApiMethod.GROUP_MEMBERS,
|
|
||||||
args: [{
|
|
||||||
sceneId,
|
|
||||||
num
|
|
||||||
},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
// log("members info", typeof result.result.infos, Object.keys(result.result.infos))
|
|
||||||
const values = result.result.infos.values()
|
|
||||||
|
|
||||||
const members: GroupMember[] = Array.from(values)
|
|
||||||
for (const member of members) {
|
|
||||||
uidMaps[member.uid] = member.uin;
|
|
||||||
}
|
|
||||||
// log(uidMaps);
|
|
||||||
// log("members info", values);
|
|
||||||
log(`get group ${groupQQ} members success`)
|
|
||||||
return members
|
|
||||||
} catch (e) {
|
|
||||||
log(`get group ${groupQQ} members failed`, e)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getFileType(filePath: string) {
|
|
||||||
return await callNTQQApi<{ ext: string }>({
|
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_TYPE, args: [filePath]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getFileMd5(filePath: string) {
|
|
||||||
return await callNTQQApi<string>({
|
|
||||||
className: NTQQApiClass.FS_API,
|
|
||||||
methodName: NTQQApiMethod.FILE_MD5,
|
|
||||||
args: [filePath]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async copyFile(filePath: string, destPath: string) {
|
|
||||||
return await callNTQQApi<string>({
|
|
||||||
className: NTQQApiClass.FS_API,
|
|
||||||
methodName: NTQQApiMethod.FILE_COPY,
|
|
||||||
args: [{
|
|
||||||
fromPath: filePath,
|
|
||||||
toPath: destPath
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getImageSize(filePath: string) {
|
|
||||||
return await callNTQQApi<{ width: number, height: number }>({
|
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.IMAGE_SIZE, args: [filePath]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getFileSize(filePath: string) {
|
|
||||||
return await callNTQQApi<number>({
|
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_SIZE, args: [filePath]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上传文件到QQ的文件夹
|
|
||||||
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
|
||||||
const md5 = await NTQQApi.getFileMd5(filePath)
|
|
||||||
let ext = (await NTQQApi.getFileType(filePath))?.ext
|
|
||||||
if (ext) {
|
|
||||||
ext = '.' + ext
|
|
||||||
} else {
|
|
||||||
ext = ''
|
|
||||||
}
|
|
||||||
let fileName = `${path.basename(filePath)}`
|
|
||||||
if (!fileName.includes('.')) {
|
|
||||||
fileName += ext
|
|
||||||
}
|
|
||||||
const mediaPath = await callNTQQApi<string>({
|
|
||||||
methodName: NTQQApiMethod.MEDIA_FILE_PATH,
|
|
||||||
args: [{
|
|
||||||
path_info: {
|
|
||||||
md5HexStr: md5,
|
|
||||||
fileName,
|
|
||||||
elementType,
|
|
||||||
elementSubType: 0,
|
|
||||||
thumbSize: 0,
|
|
||||||
needCreate: true,
|
|
||||||
downloadType: 1,
|
|
||||||
file_uuid: ''
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
log('media path', mediaPath)
|
|
||||||
await NTQQApi.copyFile(filePath, mediaPath)
|
|
||||||
const fileSize = await NTQQApi.getFileSize(filePath)
|
|
||||||
return {
|
|
||||||
md5,
|
|
||||||
fileName,
|
|
||||||
path: mediaPath,
|
|
||||||
fileSize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string) {
|
|
||||||
// 用于下载收到的消息中的图片等
|
|
||||||
if (fs.existsSync(sourcePath)) {
|
|
||||||
return sourcePath
|
|
||||||
}
|
|
||||||
const apiParams = [
|
|
||||||
{
|
|
||||||
getReq: {
|
|
||||||
msgId,
|
|
||||||
chatType,
|
|
||||||
peerUid,
|
|
||||||
elementId,
|
|
||||||
thumbSize: 0,
|
|
||||||
downloadType: 1,
|
|
||||||
filePath: thumbPath
|
|
||||||
}
|
|
||||||
},
|
|
||||||
undefined
|
|
||||||
]
|
|
||||||
// log("需要下载media", sourcePath);
|
|
||||||
await callNTQQApi({
|
|
||||||
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
|
||||||
args: apiParams,
|
|
||||||
cbCmd: ReceiveCmd.MEDIA_DOWNLOAD_COMPLETE,
|
|
||||||
cmdCB: (payload: { notifyInfo: { filePath: string } }) => {
|
|
||||||
// log("media 下载完成判断", payload.notifyInfo.filePath, sourcePath);
|
|
||||||
return payload.notifyInfo.filePath == sourcePath
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return sourcePath
|
|
||||||
}
|
|
||||||
|
|
||||||
static async recallMsg(peer: Peer, msgIds: string[]) {
|
|
||||||
return await callNTQQApi({
|
|
||||||
methodName: NTQQApiMethod.RECALL_MSG,
|
|
||||||
args: [{
|
|
||||||
peer,
|
|
||||||
msgIds
|
|
||||||
}, null]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
|
||||||
const peerUid = peer.peerUid
|
|
||||||
|
|
||||||
// 等待上一个相同的peer发送完
|
|
||||||
let checkLastSendUsingTime = 0
|
|
||||||
const waitLastSend = async () => {
|
|
||||||
if (checkLastSendUsingTime > timeout) {
|
|
||||||
throw ('发送超时')
|
|
||||||
}
|
|
||||||
const lastSending = sendMessagePool[peer.peerUid]
|
|
||||||
if (lastSending) {
|
|
||||||
// log("有正在发送的消息,等待中...")
|
|
||||||
await sleep(500)
|
|
||||||
checkLastSendUsingTime += 500
|
|
||||||
return await waitLastSend()
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await waitLastSend()
|
|
||||||
|
|
||||||
let sentMessage: RawMessage = null
|
|
||||||
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
|
||||||
delete sendMessagePool[peerUid]
|
|
||||||
sentMessage = rawMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
let checkSendCompleteUsingTime = 0
|
|
||||||
const checkSendComplete = async (): Promise<RawMessage> => {
|
|
||||||
if (sentMessage) {
|
|
||||||
if (waitComplete) {
|
|
||||||
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
|
||||||
return sentMessage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return sentMessage
|
|
||||||
}
|
|
||||||
// log(`给${peerUid}发送消息成功`)
|
|
||||||
}
|
|
||||||
checkSendCompleteUsingTime += 500
|
|
||||||
if (checkSendCompleteUsingTime > timeout) {
|
|
||||||
throw ('发送超时')
|
|
||||||
}
|
|
||||||
await sleep(500)
|
|
||||||
return await checkSendComplete()
|
|
||||||
}
|
|
||||||
log("开始发送消息", peer, msgElements)
|
|
||||||
callNTQQApi({
|
|
||||||
methodName: NTQQApiMethod.SEND_MSG,
|
|
||||||
args: [{
|
|
||||||
msgId: '0',
|
|
||||||
peer,
|
|
||||||
msgElements,
|
|
||||||
msgAttributeInfos: new Map()
|
|
||||||
}, null]
|
|
||||||
}).then()
|
|
||||||
return await checkSendComplete()
|
|
||||||
}
|
|
||||||
|
|
||||||
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.FORWARD_MSG,
|
|
||||||
args:[
|
|
||||||
{
|
|
||||||
msgIds: msgIds,
|
|
||||||
srcContact: srcPeer,
|
|
||||||
dstContacts: [
|
|
||||||
destPeer
|
|
||||||
],
|
|
||||||
commentElements: [],
|
|
||||||
msgAttributeInfos: new Map()
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
|
||||||
const msgInfos = msgIds.map(id => {
|
|
||||||
return {msgId: id, senderShowName: selfInfo.nick}
|
|
||||||
})
|
|
||||||
const apiArgs = [
|
|
||||||
{
|
|
||||||
msgInfos,
|
|
||||||
srcContact: srcPeer,
|
|
||||||
dstContact: destPeer,
|
|
||||||
commentElements: [],
|
|
||||||
msgAttributeInfos: new Map()
|
|
||||||
},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
return await new Promise<RawMessage>((resolve, reject) => {
|
|
||||||
let complete = false
|
|
||||||
setTimeout(() => {
|
|
||||||
if (!complete) {
|
|
||||||
reject('转发消息超时')
|
|
||||||
}
|
|
||||||
}, 5000)
|
|
||||||
registerReceiveHook(ReceiveCmd.SELF_SEND_MSG, async (payload: { msgRecord: RawMessage }) => {
|
|
||||||
const msg = payload.msgRecord
|
|
||||||
// 需要判断它是转发的消息,并且识别到是当前转发的这一条
|
|
||||||
const arkElement = msg.elements.find(ele => ele.arkElement)
|
|
||||||
if (!arkElement) {
|
|
||||||
// log("收到的不是转发消息")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const forwardData: any = JSON.parse(arkElement.arkElement.bytesData)
|
|
||||||
if (forwardData.app != 'com.tencent.multimsg') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (msg.peerUid == destPeer.peerUid && msg.senderUid == selfInfo.uid) {
|
|
||||||
complete = true
|
|
||||||
await dbUtil.addMsg(msg)
|
|
||||||
resolve(msg)
|
|
||||||
log('转发消息成功:', payload)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.MULTI_FORWARD_MSG,
|
|
||||||
args: apiArgs
|
|
||||||
}).then(result => {
|
|
||||||
log('转发消息结果:', result, apiArgs)
|
|
||||||
if (result.result !== 0) {
|
|
||||||
complete = true
|
|
||||||
reject('转发消息失败,' + JSON.stringify(result))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getGroupNotifies() {
|
|
||||||
// 获取管理员变更
|
|
||||||
// 加群通知,退出通知,需要管理员权限
|
|
||||||
callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: ReceiveCmd.GROUP_NOTIFY,
|
|
||||||
classNameIsRegister: true
|
|
||||||
}).then()
|
|
||||||
return await callNTQQApi<GroupNotifies>({
|
|
||||||
methodName: NTQQApiMethod.GET_GROUP_NOTICE,
|
|
||||||
cbCmd: ReceiveCmd.GROUP_NOTIFY,
|
|
||||||
afterFirstCmd: false,
|
|
||||||
args: [
|
|
||||||
{doubt: false, startSeq: '', number: 14},
|
|
||||||
null
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
|
||||||
const notify: GroupNotify = groupNotifies[seq]
|
|
||||||
if (!notify) {
|
|
||||||
throw `${seq}对应的加群通知不存在`
|
|
||||||
}
|
|
||||||
delete groupNotifies[seq]
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
doubt: false,
|
|
||||||
operateMsg: {
|
|
||||||
operateType, // 2 拒绝
|
|
||||||
targetMsg: {
|
|
||||||
seq, // 通知序列号
|
|
||||||
type: notify.type,
|
|
||||||
groupCode: notify.group.groupCode,
|
|
||||||
postscript: reason
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async quitGroup(groupQQ: string) {
|
|
||||||
await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.QUIT_GROUP,
|
|
||||||
args: [
|
|
||||||
{groupCode: groupQQ},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async handleFriendRequest(sourceId: number, accept: boolean) {
|
|
||||||
const request: FriendRequest = friendRequests[sourceId]
|
|
||||||
if (!request) {
|
|
||||||
throw `sourceId ${sourceId}, 对应的好友请求不存在`
|
|
||||||
}
|
|
||||||
const result = await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.HANDLE_FRIEND_REQUEST,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
approvalInfo: {
|
|
||||||
friendUid: request.friendUid,
|
|
||||||
reqTime: request.reqTime,
|
|
||||||
accept
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
delete friendRequests[sourceId]
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
static async kickMember(groupQQ: string, kickUids: string[], refuseForever: boolean = false, kickReason: string = '') {
|
|
||||||
return await callNTQQApi<GeneralCallResult>(
|
|
||||||
{
|
|
||||||
methodName: NTQQApiMethod.KICK_MEMBER,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
kickUids,
|
|
||||||
refuseForever,
|
|
||||||
kickReason
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
static async banMember(groupQQ: string, memList: Array<{ uid: string, timeStamp: number }>) {
|
|
||||||
// timeStamp为秒数, 0为解除禁言
|
|
||||||
return await callNTQQApi<GeneralCallResult>(
|
|
||||||
{
|
|
||||||
methodName: NTQQApiMethod.MUTE_MEMBER,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
memList
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
static async banGroup(groupQQ: string, shutUp: boolean) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.MUTE_GROUP,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
shutUp
|
|
||||||
}, null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
uid: memberUid,
|
|
||||||
cardName
|
|
||||||
}, null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.SET_MEMBER_ROLE,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
uid: memberUid,
|
|
||||||
role
|
|
||||||
}, null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async setGroupName(groupQQ: string, groupName: string) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.SET_GROUP_NAME,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
groupName
|
|
||||||
}, null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static publishGroupBulletin(groupQQ: string, title: string, content: string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
65
src/ntqqapi/types/cache.ts
Normal file
65
src/ntqqapi/types/cache.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import {ChatType} from "./msg";
|
||||||
|
|
||||||
|
export interface CacheScanResult {
|
||||||
|
result: number,
|
||||||
|
size: [ // 单位为字节
|
||||||
|
string, // 系统总存储空间
|
||||||
|
string, // 系统可用存储空间
|
||||||
|
string, // 系统已用存储空间
|
||||||
|
string, // QQ总大小
|
||||||
|
string, // 「聊天与文件」大小
|
||||||
|
string, // 未知
|
||||||
|
string, // 「缓存数据」大小
|
||||||
|
string, // 「其他数据」大小
|
||||||
|
string, // 未知
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChatCacheList {
|
||||||
|
pageCount: number,
|
||||||
|
infos: ChatCacheListItem[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChatCacheListItem {
|
||||||
|
chatType: ChatType,
|
||||||
|
basicChatCacheInfo: ChatCacheListItemBasic,
|
||||||
|
guildChatCacheInfo: unknown[] // TODO: 没用过频道所以不知道这里边的详细内容
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChatCacheListItemBasic {
|
||||||
|
chatSize: string,
|
||||||
|
chatTime: string,
|
||||||
|
uid: string,
|
||||||
|
uin: string,
|
||||||
|
remarkName: string,
|
||||||
|
nickName: string,
|
||||||
|
chatType?: ChatType,
|
||||||
|
isChecked?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum CacheFileType {
|
||||||
|
IMAGE = 0,
|
||||||
|
VIDEO = 1,
|
||||||
|
AUDIO = 2,
|
||||||
|
DOCUMENT = 3,
|
||||||
|
OTHER = 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CacheFileList {
|
||||||
|
infos: CacheFileListItem[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CacheFileListItem {
|
||||||
|
fileSize: string,
|
||||||
|
fileTime: string,
|
||||||
|
fileKey: string,
|
||||||
|
elementId: string,
|
||||||
|
elementIdStr: string,
|
||||||
|
fileType: CacheFileType,
|
||||||
|
path: string,
|
||||||
|
fileName: string,
|
||||||
|
senderId: string,
|
||||||
|
previewPath: string,
|
||||||
|
senderName: string,
|
||||||
|
isChecked?: boolean,
|
||||||
|
}
|
55
src/ntqqapi/types/group.ts
Normal file
55
src/ntqqapi/types/group.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import {QQLevel, Sex} from "./user";
|
||||||
|
|
||||||
|
export interface Group {
|
||||||
|
groupCode: string,
|
||||||
|
maxMember: number,
|
||||||
|
memberCount: number,
|
||||||
|
groupName: string,
|
||||||
|
groupStatus: 0,
|
||||||
|
memberRole: 2,
|
||||||
|
isTop: boolean,
|
||||||
|
toppedTimestamp: "0",
|
||||||
|
privilegeFlag: number, //65760
|
||||||
|
isConf: boolean,
|
||||||
|
hasModifyConfGroupFace: boolean,
|
||||||
|
hasModifyConfGroupName: boolean,
|
||||||
|
remarkName: string,
|
||||||
|
hasMemo: boolean,
|
||||||
|
groupShutupExpireTime: string, //"0",
|
||||||
|
personShutupExpireTime: string, //"0",
|
||||||
|
discussToGroupUin: string, //"0",
|
||||||
|
discussToGroupMaxMsgSeq: number,
|
||||||
|
discussToGroupTime: number,
|
||||||
|
groupFlagExt: number, //1073938496,
|
||||||
|
authGroupType: number, //0,
|
||||||
|
groupCreditLevel: number, //0,
|
||||||
|
groupFlagExt3: number, //0,
|
||||||
|
groupOwnerId: {
|
||||||
|
"memberUin": string, //"0",
|
||||||
|
"memberUid": string, //"u_fbf8N7aeuZEnUiJAbQ9R8Q"
|
||||||
|
},
|
||||||
|
members: GroupMember[] // 原始数据是没有这个的,为了方便自己加了这个字段
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum GroupMemberRole {
|
||||||
|
normal = 2,
|
||||||
|
admin = 3,
|
||||||
|
owner = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupMember {
|
||||||
|
avatarPath: string;
|
||||||
|
cardName: string;
|
||||||
|
cardType: number;
|
||||||
|
isDelete: boolean;
|
||||||
|
nick: string;
|
||||||
|
qid: string;
|
||||||
|
remark: string;
|
||||||
|
role: GroupMemberRole; // 群主:4, 管理员:3,群员:2
|
||||||
|
shutUpTime: number; // 禁言时间,单位是什么暂时不清楚
|
||||||
|
uid: string; // 加密的字符串
|
||||||
|
uin: string; // QQ号
|
||||||
|
isRobot: boolean;
|
||||||
|
sex?: Sex
|
||||||
|
qqLevel?: QQLevel
|
||||||
|
}
|
7
src/ntqqapi/types/index.ts
Normal file
7
src/ntqqapi/types/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
export * from './user';
|
||||||
|
export * from './group';
|
||||||
|
export * from './msg';
|
||||||
|
export * from './notify';
|
||||||
|
export * from './cache';
|
||||||
|
|
@@ -1,76 +1,11 @@
|
|||||||
export interface User {
|
import {GroupMemberRole} from "./group";
|
||||||
uid: string; // 加密的字符串
|
|
||||||
uin: string; // QQ号
|
|
||||||
nick: string;
|
|
||||||
avatarUrl?: string;
|
|
||||||
longNick?: string; // 签名
|
|
||||||
remark?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SelfInfo extends User {
|
|
||||||
online?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Friend extends User {
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Group {
|
|
||||||
groupCode: string,
|
|
||||||
maxMember: number,
|
|
||||||
memberCount: number,
|
|
||||||
groupName: string,
|
|
||||||
groupStatus: 0,
|
|
||||||
memberRole: 2,
|
|
||||||
isTop: boolean,
|
|
||||||
toppedTimestamp: "0",
|
|
||||||
privilegeFlag: number, //65760
|
|
||||||
isConf: boolean,
|
|
||||||
hasModifyConfGroupFace: boolean,
|
|
||||||
hasModifyConfGroupName: boolean,
|
|
||||||
remarkName: string,
|
|
||||||
hasMemo: boolean,
|
|
||||||
groupShutupExpireTime: string, //"0",
|
|
||||||
personShutupExpireTime: string, //"0",
|
|
||||||
discussToGroupUin: string, //"0",
|
|
||||||
discussToGroupMaxMsgSeq: number,
|
|
||||||
discussToGroupTime: number,
|
|
||||||
groupFlagExt: number, //1073938496,
|
|
||||||
authGroupType: number, //0,
|
|
||||||
groupCreditLevel: number, //0,
|
|
||||||
groupFlagExt3: number, //0,
|
|
||||||
groupOwnerId: {
|
|
||||||
"memberUin": string, //"0",
|
|
||||||
"memberUid": string, //"u_fbf8N7aeuZEnUiJAbQ9R8Q"
|
|
||||||
},
|
|
||||||
members: GroupMember[] // 原始数据是没有这个的,为了方便自己加了这个字段
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum GroupMemberRole {
|
|
||||||
normal = 2,
|
|
||||||
admin = 3,
|
|
||||||
owner = 4
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GroupMember {
|
|
||||||
avatarPath: string;
|
|
||||||
cardName: string;
|
|
||||||
cardType: number;
|
|
||||||
isDelete: boolean;
|
|
||||||
nick: string;
|
|
||||||
qid: string;
|
|
||||||
remark: string;
|
|
||||||
role: GroupMemberRole; // 群主:4, 管理员:3,群员:2
|
|
||||||
shutUpTime: number; // 禁言时间,单位是什么暂时不清楚
|
|
||||||
uid: string; // 加密的字符串
|
|
||||||
uin: string; // QQ号
|
|
||||||
isRobot: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum ElementType {
|
export enum ElementType {
|
||||||
TEXT = 1,
|
TEXT = 1,
|
||||||
PIC = 2,
|
PIC = 2,
|
||||||
FILE = 3,
|
FILE = 3,
|
||||||
PTT = 4,
|
PTT = 4,
|
||||||
|
VIDEO = 5,
|
||||||
FACE = 6,
|
FACE = 6,
|
||||||
REPLY = 7,
|
REPLY = 7,
|
||||||
ARK = 10,
|
ARK = 10,
|
||||||
@@ -112,6 +47,7 @@ export enum PicType {
|
|||||||
gif = 2000,
|
gif = 2000,
|
||||||
jpg = 1000
|
jpg = 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SendPicElement {
|
export interface SendPicElement {
|
||||||
elementType: ElementType.PIC,
|
elementType: ElementType.PIC,
|
||||||
elementId: "",
|
elementId: "",
|
||||||
@@ -162,15 +98,22 @@ export interface FileElement {
|
|||||||
"fileSha3"?: "",
|
"fileSha3"?: "",
|
||||||
"fileUuid"?: "",
|
"fileUuid"?: "",
|
||||||
"fileSubId"?: "",
|
"fileSubId"?: "",
|
||||||
"thumbFileSize"?: number
|
"thumbFileSize"?: number,
|
||||||
|
fileBizId?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SendFileElement {
|
export interface SendFileElement {
|
||||||
elementType: ElementType.FILE,
|
elementType: ElementType.FILE
|
||||||
elementId: "",
|
elementId: "",
|
||||||
fileElement: FileElement
|
fileElement: FileElement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SendVideoElement {
|
||||||
|
elementType: ElementType.VIDEO
|
||||||
|
elementId: "",
|
||||||
|
videoElement: VideoElement
|
||||||
|
}
|
||||||
|
|
||||||
export interface SendArkElement {
|
export interface SendArkElement {
|
||||||
elementType: ElementType.ARK,
|
elementType: ElementType.ARK,
|
||||||
elementId: "",
|
elementId: "",
|
||||||
@@ -179,7 +122,7 @@ export interface SendArkElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type SendMessageElement = SendTextElement | SendPttElement |
|
export type SendMessageElement = SendTextElement | SendPttElement |
|
||||||
SendPicElement | SendReplyElement | SendFaceElement | SendFileElement | SendArkElement
|
SendPicElement | SendReplyElement | SendFaceElement | SendFileElement | SendVideoElement | SendArkElement
|
||||||
|
|
||||||
export enum AtType {
|
export enum AtType {
|
||||||
notAt = 0,
|
notAt = 0,
|
||||||
@@ -218,8 +161,8 @@ export interface PttElement {
|
|||||||
|
|
||||||
export interface ArkElement {
|
export interface ArkElement {
|
||||||
bytesData: string;
|
bytesData: string;
|
||||||
linkInfo:null,
|
linkInfo: null,
|
||||||
subElementType:null
|
subElementType: null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const IMAGE_HTTP_HOST = "https://gchat.qpic.cn"
|
export const IMAGE_HTTP_HOST = "https://gchat.qpic.cn"
|
||||||
@@ -236,7 +179,13 @@ export interface PicElement {
|
|||||||
md5HexStr?: string;
|
md5HexStr?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum GrayTipElementSubType {
|
||||||
|
INVITE_NEW_MEMBER = 12,
|
||||||
|
MEMBER_NEW_TITLE = 17
|
||||||
|
}
|
||||||
|
|
||||||
export interface GrayTipElement {
|
export interface GrayTipElement {
|
||||||
|
subElementType: GrayTipElementSubType;
|
||||||
revokeElement: {
|
revokeElement: {
|
||||||
operatorRole: string;
|
operatorRole: string;
|
||||||
operatorUid: string;
|
operatorUid: string;
|
||||||
@@ -245,7 +194,14 @@ export interface GrayTipElement {
|
|||||||
operatorMemRemark?: string;
|
operatorMemRemark?: string;
|
||||||
wording: string; // 自定义的撤回提示语
|
wording: string; // 自定义的撤回提示语
|
||||||
}
|
}
|
||||||
aioOpGrayTipElement: TipAioOpGrayTipElement
|
aioOpGrayTipElement: TipAioOpGrayTipElement,
|
||||||
|
groupElement: TipGroupElement,
|
||||||
|
xmlElement: {
|
||||||
|
content: string;
|
||||||
|
},
|
||||||
|
jsonGrayTipElement:{
|
||||||
|
jsonStr: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FaceElement {
|
export interface FaceElement {
|
||||||
@@ -256,37 +212,42 @@ export interface FaceElement {
|
|||||||
export interface VideoElement {
|
export interface VideoElement {
|
||||||
"filePath": string,
|
"filePath": string,
|
||||||
"fileName": string,
|
"fileName": string,
|
||||||
"videoMd5": string,
|
"videoMd5"?: string,
|
||||||
"thumbMd5": string
|
"thumbMd5"?: string
|
||||||
"fileTime": 87, // second
|
"fileTime"?: number, // second
|
||||||
"thumbSize": 314235, // byte
|
"thumbSize"?: number, // byte
|
||||||
"fileFormat": 2, // 2表示mp4?
|
"fileFormat"?: number, // 2表示mp4?
|
||||||
"fileSize": string, // byte
|
"fileSize"?: string, // byte
|
||||||
"thumbWidth": number,
|
"thumbWidth"?: number,
|
||||||
"thumbHeight": number,
|
"thumbHeight"?: number,
|
||||||
"busiType": 0, // 未知
|
"busiType"?: 0, // 未知
|
||||||
"subBusiType": 0, // 未知
|
"subBusiType"?: 0, // 未知
|
||||||
"thumbPath": Map<number, any>,
|
"thumbPath"?: Map<number, any>,
|
||||||
"transferStatus": 0, // 未知
|
"transferStatus"?: 0, // 未知
|
||||||
"progress": 0, // 下载进度?
|
"progress"?: 0, // 下载进度?
|
||||||
"invalidState": 0, // 未知
|
"invalidState"?: 0, // 未知
|
||||||
"fileUuid": string, // 可以用于下载链接?
|
"fileUuid"?: string, // 可以用于下载链接?
|
||||||
"fileSubId": "",
|
"fileSubId"?: "",
|
||||||
"fileBizId": null,
|
"fileBizId"?: null,
|
||||||
"originVideoMd5": "",
|
"originVideoMd5"?: "",
|
||||||
"import_rich_media_context": null,
|
"import_rich_media_context"?: null,
|
||||||
"sourceVideoCodecFormat": 0
|
"sourceVideoCodecFormat"?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TipAioOpGrayTipElement{
|
export interface TipAioOpGrayTipElement { // 这是什么提示来着?
|
||||||
operateType: number,
|
operateType: number,
|
||||||
peerUid: string,
|
peerUid: string,
|
||||||
fromGrpCodeOfTmpChat: string,
|
fromGrpCodeOfTmpChat: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum TipGroupElementType {
|
||||||
|
memberIncrease = 1,
|
||||||
|
ban = 8
|
||||||
|
}
|
||||||
|
|
||||||
export interface TipGroupElement {
|
export interface TipGroupElement {
|
||||||
"type": 1, // 1是表示有人加入群, 自己加入群也会收到这个
|
"type": TipGroupElementType, // 1是表示有人加入群, 自己加入群也会收到这个
|
||||||
"role": 0,
|
"role": 0, // 暂时不知
|
||||||
"groupName": string, // 暂时获取不到
|
"groupName": string, // 暂时获取不到
|
||||||
"memberUid": string,
|
"memberUid": string,
|
||||||
"memberNick": string,
|
"memberNick": string,
|
||||||
@@ -295,7 +256,7 @@ export interface TipGroupElement {
|
|||||||
"adminNick": string,
|
"adminNick": string,
|
||||||
"adminRemark": string,
|
"adminRemark": string,
|
||||||
"createGroup": null,
|
"createGroup": null,
|
||||||
"memberAdd": {
|
"memberAdd"?: {
|
||||||
"showType": 1,
|
"showType": 1,
|
||||||
"otherAdd": null,
|
"otherAdd": null,
|
||||||
"otherAddByOtherQRCode": null,
|
"otherAddByOtherQRCode": null,
|
||||||
@@ -305,7 +266,22 @@ export interface TipGroupElement {
|
|||||||
"otherInviteYou": null,
|
"otherInviteYou": null,
|
||||||
"youInviteOther": null
|
"youInviteOther": null
|
||||||
},
|
},
|
||||||
"shutUp": null
|
"shutUp"?: {
|
||||||
|
"curTime": string,
|
||||||
|
"duration": string, // 禁言时间,秒
|
||||||
|
"admin": {
|
||||||
|
"uid": string,
|
||||||
|
"card": string,
|
||||||
|
"name": string,
|
||||||
|
"role": GroupMemberRole
|
||||||
|
},
|
||||||
|
"member": {
|
||||||
|
"uid": string
|
||||||
|
"card": string,
|
||||||
|
"name": string,
|
||||||
|
"role": GroupMemberRole
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -346,61 +322,4 @@ export interface RawMessage {
|
|||||||
videoElement: VideoElement;
|
videoElement: VideoElement;
|
||||||
fileElement: FileElement;
|
fileElement: FileElement;
|
||||||
}[];
|
}[];
|
||||||
}
|
|
||||||
|
|
||||||
export enum GroupNotifyTypes {
|
|
||||||
INVITE_ME = 1,
|
|
||||||
INVITED_JOIN = 4, // 有人接受了邀请入群
|
|
||||||
JOIN_REQUEST = 7,
|
|
||||||
ADMIN_SET = 8,
|
|
||||||
ADMIN_UNSET = 12,
|
|
||||||
MEMBER_EXIT = 11, // 主动退出?
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GroupNotifies {
|
|
||||||
doubt: boolean,
|
|
||||||
nextStartSeq: string,
|
|
||||||
notifies: GroupNotify[],
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GroupNotify {
|
|
||||||
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
|
||||||
seq: string, // 转成数字,再除以1000应该就是时间戳?
|
|
||||||
type: GroupNotifyTypes,
|
|
||||||
status: 0, // 未知
|
|
||||||
group: { groupCode: string, groupName: string },
|
|
||||||
user1: { uid: string, nickName: string }, // 被设置管理员的人
|
|
||||||
user2: { uid: string, nickName: string }, // 操作者
|
|
||||||
actionUser: { uid: string, nickName: string }, //未知
|
|
||||||
actionTime: string,
|
|
||||||
invitationExt: {
|
|
||||||
srcType: number, // 0?未知
|
|
||||||
groupCode: string, waitStatus: number
|
|
||||||
},
|
|
||||||
postscript: string, // 加群用户填写的验证信息
|
|
||||||
repeatSeqs: [],
|
|
||||||
warningTips: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum GroupRequestOperateTypes {
|
|
||||||
approve = 1,
|
|
||||||
reject = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FriendRequest {
|
|
||||||
friendUid: string,
|
|
||||||
reqTime: string, // 时间戳,秒
|
|
||||||
extWords: string, // 申请人填写的验证消息
|
|
||||||
isUnread: boolean,
|
|
||||||
friendNick: string,
|
|
||||||
sourceId: number,
|
|
||||||
groupCode: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FriendRequestNotify {
|
|
||||||
data: {
|
|
||||||
unreadNums: number,
|
|
||||||
buddyReqs: FriendRequest[]
|
|
||||||
}
|
|
||||||
}
|
}
|
64
src/ntqqapi/types/notify.ts
Normal file
64
src/ntqqapi/types/notify.ts
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
|
||||||
|
export enum GroupNotifyTypes {
|
||||||
|
INVITE_ME = 1,
|
||||||
|
INVITED_JOIN = 4, // 有人接受了邀请入群
|
||||||
|
JOIN_REQUEST = 7,
|
||||||
|
ADMIN_SET = 8,
|
||||||
|
ADMIN_UNSET = 12,
|
||||||
|
MEMBER_EXIT = 11, // 主动退出?
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupNotifies {
|
||||||
|
doubt: boolean,
|
||||||
|
nextStartSeq: string,
|
||||||
|
notifies: GroupNotify[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum GroupNotifyStatus {
|
||||||
|
IGNORE = 0,
|
||||||
|
WAIT_HANDLE = 1,
|
||||||
|
APPROVE = 2,
|
||||||
|
REJECT = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupNotify {
|
||||||
|
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
||||||
|
seq: string, // 唯一标识符,转成数字再除以1000应该就是时间戳?
|
||||||
|
type: GroupNotifyTypes,
|
||||||
|
status: GroupNotifyStatus, // 0是已忽略?,1是未处理,2是已同意
|
||||||
|
group: { groupCode: string, groupName: string },
|
||||||
|
user1: { uid: string, nickName: string }, // 被设置管理员的人
|
||||||
|
user2: { uid: string, nickName: string }, // 操作者
|
||||||
|
actionUser: { uid: string, nickName: string }, //未知
|
||||||
|
actionTime: string,
|
||||||
|
invitationExt: {
|
||||||
|
srcType: number, // 0?未知
|
||||||
|
groupCode: string, waitStatus: number
|
||||||
|
},
|
||||||
|
postscript: string, // 加群用户填写的验证信息
|
||||||
|
repeatSeqs: [],
|
||||||
|
warningTips: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum GroupRequestOperateTypes {
|
||||||
|
approve = 1,
|
||||||
|
reject = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FriendRequest {
|
||||||
|
friendUid: string,
|
||||||
|
reqTime: string, // 时间戳,秒
|
||||||
|
extWords: string, // 申请人填写的验证消息
|
||||||
|
isUnread: boolean,
|
||||||
|
friendNick: string,
|
||||||
|
sourceId: number,
|
||||||
|
groupCode: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FriendRequestNotify {
|
||||||
|
data: {
|
||||||
|
unreadNums: number,
|
||||||
|
buddyReqs: FriendRequest[]
|
||||||
|
}
|
||||||
|
}
|
75
src/ntqqapi/types/user.ts
Normal file
75
src/ntqqapi/types/user.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
export enum Sex {
|
||||||
|
male = 0,
|
||||||
|
female = 2,
|
||||||
|
unknown = 255,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QQLevel {
|
||||||
|
"crownNum": number,
|
||||||
|
"sunNum": number,
|
||||||
|
"moonNum": number,
|
||||||
|
"starNum": number
|
||||||
|
}
|
||||||
|
export interface User {
|
||||||
|
uid: string; // 加密的字符串
|
||||||
|
uin: string; // QQ号
|
||||||
|
nick: string;
|
||||||
|
avatarUrl?: string;
|
||||||
|
longNick?: string; // 签名
|
||||||
|
remark?: string;
|
||||||
|
sex?: Sex;
|
||||||
|
qqLevel?: QQLevel,
|
||||||
|
qid?: string
|
||||||
|
"birthday_year"?: number,
|
||||||
|
"birthday_month"?: number,
|
||||||
|
"birthday_day"?: number,
|
||||||
|
"topTime"?: string,
|
||||||
|
"constellation"?: number,
|
||||||
|
"shengXiao"?: number,
|
||||||
|
"kBloodType"?: number,
|
||||||
|
"homeTown"?: string, //"0-0-0",
|
||||||
|
"makeFriendCareer"?: number,
|
||||||
|
"pos"?: string,
|
||||||
|
"eMail"?: string
|
||||||
|
"phoneNum"?: string,
|
||||||
|
"college"?: string,
|
||||||
|
"country"?: string,
|
||||||
|
"province"?: string,
|
||||||
|
"city"?: string,
|
||||||
|
"postCode"?: string,
|
||||||
|
"address"?: string,
|
||||||
|
"isBlock"?: boolean,
|
||||||
|
"isSpecialCareOpen"?: boolean,
|
||||||
|
"isSpecialCareZone"?: boolean,
|
||||||
|
"ringId"?: string,
|
||||||
|
"regTime"?: number,
|
||||||
|
interest?: string,
|
||||||
|
"labels"?: string[],
|
||||||
|
"isHideQQLevel"?: number,
|
||||||
|
"privilegeIcon"?: {
|
||||||
|
"jumpUrl": string,
|
||||||
|
"openIconList": unknown[],
|
||||||
|
"closeIconList": unknown[]
|
||||||
|
},
|
||||||
|
"photoWall"?: {
|
||||||
|
"picList": unknown[]
|
||||||
|
},
|
||||||
|
"vipFlag"?: boolean,
|
||||||
|
"yearVipFlag"?: boolean,
|
||||||
|
"svipFlag"?: boolean,
|
||||||
|
"vipLevel"?: number,
|
||||||
|
"status"?: number,
|
||||||
|
"qidianMasterFlag"?: number,
|
||||||
|
"qidianCrewFlag"?: number,
|
||||||
|
"qidianCrewFlag2"?: number,
|
||||||
|
"extStatus"?: number,
|
||||||
|
"recommendImgFlag"?: number,
|
||||||
|
"disableEmojiShortCuts"?: number,
|
||||||
|
"pendantId"?: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SelfInfo extends User {
|
||||||
|
online?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Friend extends User {}
|
@@ -1,7 +1,8 @@
|
|||||||
import {ActionName, BaseCheckResult} from "./types"
|
import {ActionName, BaseCheckResult} from "./types"
|
||||||
import {OB11Response} from "./utils"
|
import {OB11Response} from "./OB11Response"
|
||||||
import {OB11Return} from "../types";
|
import {OB11Return} from "../types";
|
||||||
import {log} from "../../common/utils";
|
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
class BaseAction<PayloadType, ReturnDataType> {
|
class BaseAction<PayloadType, ReturnDataType> {
|
||||||
actionName: ActionName
|
actionName: ActionName
|
||||||
@@ -22,7 +23,7 @@ class BaseAction<PayloadType, ReturnDataType> {
|
|||||||
return OB11Response.ok(resData);
|
return OB11Response.ok(resData);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("发生错误", e)
|
log("发生错误", e)
|
||||||
return OB11Response.error(e.toString(), 200);
|
return OB11Response.error(e?.toString() || e?.stack?.toString() || "未知错误,可能操作超时", 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ class BaseAction<PayloadType, ReturnDataType> {
|
|||||||
return OB11Response.ok(resData, echo);
|
return OB11Response.ok(resData, echo);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("发生错误", e)
|
log("发生错误", e)
|
||||||
return OB11Response.error(e.toString(), 1200, echo)
|
return OB11Response.error(e.stack?.toString() || e.toString(), 1200, echo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,28 +0,0 @@
|
|||||||
import BaseAction from "./BaseAction";
|
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {ActionName} from "./types";
|
|
||||||
import {log} from "../../common/utils";
|
|
||||||
|
|
||||||
interface Payload {
|
|
||||||
method: string,
|
|
||||||
args: any[],
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Debug extends BaseAction<Payload, any> {
|
|
||||||
actionName = ActionName.Debug
|
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
|
||||||
log("debug call ntqq api", payload);
|
|
||||||
const method = NTQQApi[payload.method]
|
|
||||||
if (!method) {
|
|
||||||
throw `${method} 不存在`
|
|
||||||
}
|
|
||||||
const result = method(...payload.args);
|
|
||||||
if (method.constructor.name === "AsyncFunction") {
|
|
||||||
return await result
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
// const info = await NTQQApi.getUserDetailInfo(friends[0].uid);
|
|
||||||
// return info
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,47 +0,0 @@
|
|||||||
import BaseAction from "./BaseAction";
|
|
||||||
import {getConfigUtil} from "../../common/utils";
|
|
||||||
import fs from "fs/promises";
|
|
||||||
import {dbUtil} from "../../common/db";
|
|
||||||
|
|
||||||
export interface GetFilePayload {
|
|
||||||
file: string // 文件名
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GetFileResponse {
|
|
||||||
file?: string // path
|
|
||||||
url?: string
|
|
||||||
file_size?: string
|
|
||||||
file_name?: string
|
|
||||||
base64?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|
||||||
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
|
||||||
const cache = await dbUtil.getFileCache(payload.file)
|
|
||||||
const {autoDeleteFile, enableLocalFile2Url, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
|
||||||
if (!cache) {
|
|
||||||
throw new Error('file not found')
|
|
||||||
}
|
|
||||||
if (cache.downloadFunc) {
|
|
||||||
await cache.downloadFunc()
|
|
||||||
}
|
|
||||||
let res: GetFileResponse = {
|
|
||||||
file: cache.filePath,
|
|
||||||
url: cache.url,
|
|
||||||
file_size: cache.fileSize,
|
|
||||||
file_name: cache.fileName
|
|
||||||
}
|
|
||||||
if (enableLocalFile2Url) {
|
|
||||||
if (!cache.url) {
|
|
||||||
res.base64 = await fs.readFile(cache.filePath, 'base64')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (autoDeleteFile) {
|
|
||||||
setTimeout(() => {
|
|
||||||
fs.unlink(cache.filePath)
|
|
||||||
}, autoDeleteFileSecond * 1000)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,26 +0,0 @@
|
|||||||
import {OB11GroupMember} from '../types';
|
|
||||||
import {getGroupMember} from "../../common/data";
|
|
||||||
import {OB11Constructor} from "../constructor";
|
|
||||||
import BaseAction from "./BaseAction";
|
|
||||||
import {ActionName} from "./types";
|
|
||||||
|
|
||||||
|
|
||||||
export interface PayloadType {
|
|
||||||
group_id: number
|
|
||||||
user_id: number
|
|
||||||
}
|
|
||||||
|
|
||||||
class GetGroupMemberInfo extends BaseAction<PayloadType, OB11GroupMember> {
|
|
||||||
actionName = ActionName.GetGroupMemberInfo
|
|
||||||
|
|
||||||
protected async _handle(payload: PayloadType) {
|
|
||||||
const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString())
|
|
||||||
if (member) {
|
|
||||||
return OB11Constructor.groupMember(payload.group_id.toString(), member)
|
|
||||||
} else {
|
|
||||||
throw (`群成员${payload.user_id}不存在`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default GetGroupMemberInfo
|
|
@@ -1,5 +1,6 @@
|
|||||||
import {OB11Return} from '../types';
|
import {OB11Return} from '../types';
|
||||||
import {isNull} from '../../common/utils';
|
|
||||||
|
import {isNull} from "../../common/utils/helper";
|
||||||
|
|
||||||
export class OB11Response {
|
export class OB11Response {
|
||||||
static res<T>(data: T, status: string, retcode: number, message: string = ""): OB11Return<T> {
|
static res<T>(data: T, status: string, retcode: number, message: string = ""): OB11Return<T> {
|
@@ -1,432 +0,0 @@
|
|||||||
import {AtType, ChatType, Group, RawMessage, SendArkElement, SendMessageElement} from "../../ntqqapi/types";
|
|
||||||
import {friends, getFriend, getGroup, getGroupMember, getUidByUin, selfInfo,} from "../../common/data";
|
|
||||||
import {
|
|
||||||
OB11MessageCustomMusic,
|
|
||||||
OB11MessageData,
|
|
||||||
OB11MessageDataType,
|
|
||||||
OB11MessageMixType,
|
|
||||||
OB11MessageNode,
|
|
||||||
OB11PostSendMsg
|
|
||||||
} from '../types';
|
|
||||||
import {NTQQApi, Peer} from "../../ntqqapi/ntcall";
|
|
||||||
import {SendMsgElementConstructor} from "../../ntqqapi/constructor";
|
|
||||||
import {uri2local} from "../utils";
|
|
||||||
import BaseAction from "./BaseAction";
|
|
||||||
import {ActionName, BaseCheckResult} from "./types";
|
|
||||||
import * as fs from "node:fs";
|
|
||||||
import {log} from "../../common/utils";
|
|
||||||
import {decodeCQCode} from "../cqcode";
|
|
||||||
import {dbUtil} from "../../common/db";
|
|
||||||
import {ALLOW_SEND_TEMP_MSG} from "../../common/config";
|
|
||||||
import {FileCache} from "../../common/types";
|
|
||||||
|
|
||||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
|
||||||
function checkUri(uri: string): boolean {
|
|
||||||
const pattern = /^(file:\/\/|http:\/\/|https:\/\/|base64:\/\/)/;
|
|
||||||
return pattern.test(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let msg of sendMsgList) {
|
|
||||||
if (msg["type"] && msg["data"]) {
|
|
||||||
let type = msg["type"];
|
|
||||||
let data = msg["data"];
|
|
||||||
if (type === "text" && !data["text"]) {
|
|
||||||
return 400;
|
|
||||||
} else if (["image", "voice", "record"].includes(type)) {
|
|
||||||
if (!data["file"]) {
|
|
||||||
return 400;
|
|
||||||
} else {
|
|
||||||
if (checkUri(data["file"])) {
|
|
||||||
return 200;
|
|
||||||
} else {
|
|
||||||
return 400;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (type === "at" && !data["qq"]) {
|
|
||||||
return 400;
|
|
||||||
} else if (type === "reply" && !data["id"]) {
|
|
||||||
return 400;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 400
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ReturnDataType {
|
|
||||||
message_id: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|
||||||
actionName = ActionName.SendMsg
|
|
||||||
|
|
||||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
|
||||||
const messages = this.convertMessage2List(payload.message);
|
|
||||||
const fmNum = this.getSpecialMsgNum(payload, OB11MessageDataType.node)
|
|
||||||
if (fmNum && fmNum != messages.length) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
message: "转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (payload.group_id && !(await getGroup(payload.group_id))) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
message: `群${payload.group_id}不存在`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (payload.user_id && payload.message_type !== "group") {
|
|
||||||
if (!(await getFriend(payload.user_id))) {
|
|
||||||
if (!ALLOW_SEND_TEMP_MSG) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
message: `不能发送临时消息`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
valid: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async _handle(payload: OB11PostSendMsg) {
|
|
||||||
const peer: Peer = {
|
|
||||||
chatType: ChatType.friend,
|
|
||||||
peerUid: ""
|
|
||||||
}
|
|
||||||
let isTempMsg = false;
|
|
||||||
let group: Group | undefined = undefined;
|
|
||||||
const genGroupPeer = async () => {
|
|
||||||
group = await getGroup(payload.group_id.toString())
|
|
||||||
peer.chatType = ChatType.group
|
|
||||||
// peer.name = group.name
|
|
||||||
peer.peerUid = group.groupCode
|
|
||||||
}
|
|
||||||
|
|
||||||
const genFriendPeer = () => {
|
|
||||||
const friend = friends.find(f => f.uin == payload.user_id.toString())
|
|
||||||
if (friend) {
|
|
||||||
// peer.name = friend.nickName
|
|
||||||
peer.peerUid = friend.uid
|
|
||||||
} else {
|
|
||||||
peer.chatType = ChatType.temp
|
|
||||||
const tempUserUid = getUidByUin(payload.user_id.toString())
|
|
||||||
if (!tempUserUid) {
|
|
||||||
throw (`找不到私聊对象${payload.user_id}`)
|
|
||||||
}
|
|
||||||
// peer.name = tempUser.nickName
|
|
||||||
isTempMsg = true;
|
|
||||||
peer.peerUid = tempUserUid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (payload?.group_id && payload.message_type === "group") {
|
|
||||||
await genGroupPeer()
|
|
||||||
|
|
||||||
} else if (payload?.user_id) {
|
|
||||||
genFriendPeer()
|
|
||||||
} else if (payload.group_id) {
|
|
||||||
await genGroupPeer()
|
|
||||||
} else {
|
|
||||||
throw ("发送消息参数错误, 请指定group_id或user_id")
|
|
||||||
}
|
|
||||||
const messages = this.convertMessage2List(payload.message);
|
|
||||||
if (this.getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
|
||||||
try {
|
|
||||||
const returnMsg = await this.handleForwardNode(peer, messages as OB11MessageNode[], group)
|
|
||||||
return {message_id: returnMsg.msgShortId}
|
|
||||||
} catch (e) {
|
|
||||||
throw ("发送转发消息失败 " + e.toString())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
|
||||||
const music: OB11MessageCustomMusic = messages[0] as OB11MessageCustomMusic
|
|
||||||
if (music) {
|
|
||||||
const {url, audio, title, content, image} = music.data;
|
|
||||||
const selfPeer: Peer = {peerUid: selfInfo.uid, chatType: ChatType.friend}
|
|
||||||
// 搞不定!
|
|
||||||
// const musicMsg = await this.send(selfPeer, [this.genMusicElement(url, audio, title, content, image)], [], false)
|
|
||||||
// 转发
|
|
||||||
// const res = await NTQQApi.forwardMsg(selfPeer, peer, [musicMsg.msgId])
|
|
||||||
// log("转发音乐消息成功", res);
|
|
||||||
// return {message_id: musicMsg.msgShortId}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// log("send msg:", peer, sendElements)
|
|
||||||
const {sendElements, deleteAfterSentFiles} = await this.createSendElements(messages, group)
|
|
||||||
try {
|
|
||||||
const returnMsg = await this.send(peer, sendElements, deleteAfterSentFiles)
|
|
||||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {}));
|
|
||||||
return {message_id: returnMsg.msgShortId}
|
|
||||||
} catch (e) {
|
|
||||||
log("发送消息失败", e.stack.toString())
|
|
||||||
throw (e.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected convertMessage2List(message: OB11MessageMixType) {
|
|
||||||
if (typeof message === "string") {
|
|
||||||
// message = [{
|
|
||||||
// type: OB11MessageDataType.text,
|
|
||||||
// data: {
|
|
||||||
// text: message
|
|
||||||
// }
|
|
||||||
// }] as OB11MessageData[]
|
|
||||||
message = decodeCQCode(message.toString())
|
|
||||||
} else if (!Array.isArray(message)) {
|
|
||||||
message = [message]
|
|
||||||
}
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
|
|
||||||
if (Array.isArray(payload.message)) {
|
|
||||||
return payload.message.filter(msg => msg.type == msgType).length
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// 返回一个合并转发的消息id
|
|
||||||
private async handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[], group: Group | undefined) {
|
|
||||||
const selfPeer: Peer = {
|
|
||||||
chatType: ChatType.friend,
|
|
||||||
peerUid: selfInfo.uid
|
|
||||||
}
|
|
||||||
let selfNodeMsgList: RawMessage[] = [];
|
|
||||||
let originalNodeMsgList: RawMessage[] = [];
|
|
||||||
for (const messageNode of messageNodes) {
|
|
||||||
// 一个node表示一个人的消息
|
|
||||||
let nodeId = messageNode.data.id;
|
|
||||||
// 有nodeId表示一个子转发消息卡片
|
|
||||||
if (nodeId) {
|
|
||||||
let nodeMsg = await dbUtil.getMsgByShortId(parseInt(nodeId));
|
|
||||||
if (nodeMsg) {
|
|
||||||
originalNodeMsgList.push(nodeMsg);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 自定义的消息
|
|
||||||
// 提取消息段,发给自己生成消息id
|
|
||||||
try {
|
|
||||||
const {
|
|
||||||
sendElements,
|
|
||||||
deleteAfterSentFiles
|
|
||||||
} = await this.createSendElements(this.convertMessage2List(messageNode.data.content), group);
|
|
||||||
log("开始生成转发节点", sendElements);
|
|
||||||
const nodeMsg = await this.send(selfPeer, sendElements, deleteAfterSentFiles, false);
|
|
||||||
selfNodeMsgList.push(nodeMsg);
|
|
||||||
log("转发节点生成成功", nodeMsg.msgId);
|
|
||||||
} catch (e) {
|
|
||||||
log("生效转发消息节点失败", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let nodeIds: string[] = []
|
|
||||||
// 检查是否需要克隆直接引用消息id的节点
|
|
||||||
let needSendSelf = false;
|
|
||||||
if (selfNodeMsgList.length) {
|
|
||||||
needSendSelf = true
|
|
||||||
} else {
|
|
||||||
needSendSelf = !originalNodeMsgList.every((msg, index) => msg.peerUid === originalNodeMsgList[0].peerUid && msg.recallTime.length < 2)
|
|
||||||
}
|
|
||||||
if (needSendSelf) {
|
|
||||||
nodeIds = selfNodeMsgList.map(msg => msg.msgId);
|
|
||||||
for (const originalNodeMsg of originalNodeMsgList) {
|
|
||||||
if (originalNodeMsg.peerUid === selfInfo.uid && originalNodeMsg.recallTime.length < 2) {
|
|
||||||
nodeIds.push(originalNodeMsg.msgId)
|
|
||||||
} else { // 需要进行克隆
|
|
||||||
let sendElements: SendMessageElement[] = []
|
|
||||||
Object.keys(originalNodeMsg.elements).forEach((eleKey) => {
|
|
||||||
if (eleKey !== "elementId") {
|
|
||||||
sendElements.push(originalNodeMsg.elements[eleKey])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
try {
|
|
||||||
const nodeMsg = await NTQQApi.sendMsg(selfPeer, sendElements, true);
|
|
||||||
nodeIds.push(nodeMsg.msgId)
|
|
||||||
log("克隆转发消息成功")
|
|
||||||
} catch (e) {
|
|
||||||
log("克隆转发消息失败", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
nodeIds = originalNodeMsgList.map(msg => msg.msgId)
|
|
||||||
}
|
|
||||||
|
|
||||||
let srcPeer = selfPeer;
|
|
||||||
if (!needSendSelf) {
|
|
||||||
srcPeer = {
|
|
||||||
chatType: originalNodeMsgList[0].chatType === ChatType.group ? ChatType.group : ChatType.friend,
|
|
||||||
peerUid: originalNodeMsgList[0].peerUid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 开发转发
|
|
||||||
try {
|
|
||||||
return await NTQQApi.multiForwardMsg(srcPeer, destPeer, nodeIds)
|
|
||||||
} catch (e) {
|
|
||||||
log("forward failed", e)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createSendElements(messageData: OB11MessageData[], group: Group | undefined, ignoreTypes: OB11MessageDataType[] = []) {
|
|
||||||
let sendElements: SendMessageElement[] = []
|
|
||||||
let deleteAfterSentFiles: string[] = []
|
|
||||||
for (let sendMsg of messageData) {
|
|
||||||
if (ignoreTypes.includes(sendMsg.type)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch (sendMsg.type) {
|
|
||||||
case OB11MessageDataType.text: {
|
|
||||||
const text = sendMsg.data?.text;
|
|
||||||
if (text) {
|
|
||||||
sendElements.push(SendMsgElementConstructor.text(sendMsg.data!.text))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case OB11MessageDataType.at: {
|
|
||||||
if (!group){
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
let atQQ = sendMsg.data?.qq;
|
|
||||||
if (atQQ) {
|
|
||||||
atQQ = atQQ.toString()
|
|
||||||
if (atQQ === "all") {
|
|
||||||
sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, "全体成员"))
|
|
||||||
} else {
|
|
||||||
// const atMember = group?.members.find(m => m.uin == atQQ)
|
|
||||||
const atMember = await getGroupMember(group?.groupCode, atQQ);
|
|
||||||
if (atMember) {
|
|
||||||
sendElements.push(SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case OB11MessageDataType.reply: {
|
|
||||||
let replyMsgId = sendMsg.data.id;
|
|
||||||
if (replyMsgId) {
|
|
||||||
const replyMsg = await dbUtil.getMsgByShortId(parseInt(replyMsgId))
|
|
||||||
if (replyMsg) {
|
|
||||||
sendElements.push(SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin, replyMsg.senderUin))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case OB11MessageDataType.face: {
|
|
||||||
const faceId = sendMsg.data?.id
|
|
||||||
if (faceId) {
|
|
||||||
sendElements.push(SendMsgElementConstructor.face(parseInt(faceId)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case OB11MessageDataType.image:
|
|
||||||
case OB11MessageDataType.file:
|
|
||||||
case OB11MessageDataType.video:
|
|
||||||
case OB11MessageDataType.voice: {
|
|
||||||
let file = sendMsg.data?.file
|
|
||||||
const payloadFileName = sendMsg.data?.name
|
|
||||||
if (file) {
|
|
||||||
const cache = await dbUtil.getFileCache(file)
|
|
||||||
if (cache){
|
|
||||||
if (fs.existsSync(cache.filePath)){
|
|
||||||
file = "file://" + cache.filePath
|
|
||||||
}
|
|
||||||
else if (cache.downloadFunc){
|
|
||||||
await cache.downloadFunc()
|
|
||||||
file = cache.filePath;
|
|
||||||
log("找到文件缓存", file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const {path, isLocal, fileName, errMsg} = (await uri2local(file))
|
|
||||||
if (errMsg){
|
|
||||||
throw errMsg
|
|
||||||
}
|
|
||||||
if (path) {
|
|
||||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
|
||||||
deleteAfterSentFiles.push(path)
|
|
||||||
}
|
|
||||||
const constructorMap = {
|
|
||||||
[OB11MessageDataType.image]: SendMsgElementConstructor.pic,
|
|
||||||
[OB11MessageDataType.voice]: SendMsgElementConstructor.ptt,
|
|
||||||
[OB11MessageDataType.video]: SendMsgElementConstructor.video,
|
|
||||||
[OB11MessageDataType.file]: SendMsgElementConstructor.file,
|
|
||||||
}
|
|
||||||
if (sendMsg.type === OB11MessageDataType.file) {
|
|
||||||
log("发送文件", path, payloadFileName || fileName)
|
|
||||||
sendElements.push(await SendMsgElementConstructor.file(path, false, payloadFileName || fileName));
|
|
||||||
} else if (sendMsg.type === OB11MessageDataType.video) {
|
|
||||||
log("发送视频", path, payloadFileName || fileName)
|
|
||||||
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName));
|
|
||||||
} else {
|
|
||||||
sendElements.push(await constructorMap[sendMsg.type](path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
sendElements,
|
|
||||||
deleteAfterSentFiles
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async send(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
|
||||||
if (!sendElements.length) {
|
|
||||||
throw ("消息体无法解析")
|
|
||||||
}
|
|
||||||
const returnMsg = await NTQQApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
|
||||||
log("消息发送结果", returnMsg)
|
|
||||||
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
|
||||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
|
||||||
}))
|
|
||||||
return returnMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
private genMusicElement(url: string, audio: string, title: string, content: string, image: string): SendArkElement {
|
|
||||||
const musicJson = {
|
|
||||||
app: 'com.tencent.structmsg',
|
|
||||||
config: {
|
|
||||||
ctime: 1709689928,
|
|
||||||
forward: 1,
|
|
||||||
token: '5c1e4905f926dd3a64a4bd3841460351',
|
|
||||||
type: 'normal'
|
|
||||||
},
|
|
||||||
extra: {app_type: 1, appid: 100497308, uin: selfInfo.uin},
|
|
||||||
meta: {
|
|
||||||
news: {
|
|
||||||
action: '',
|
|
||||||
android_pkg_name: '',
|
|
||||||
app_type: 1,
|
|
||||||
appid: 100497308,
|
|
||||||
ctime: 1709689928,
|
|
||||||
desc: content || title,
|
|
||||||
jumpUrl: url,
|
|
||||||
musicUrl: audio,
|
|
||||||
preview: image,
|
|
||||||
source_icon: 'https://p.qpic.cn/qqconnect/0/app_100497308_1626060999/100?max-age=2592000&t=0',
|
|
||||||
source_url: '',
|
|
||||||
tag: 'QQ音乐',
|
|
||||||
title: title,
|
|
||||||
uin: selfInfo.uin,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
prompt: content || title,
|
|
||||||
ver: '0.0.0.1',
|
|
||||||
view: 'news'
|
|
||||||
}
|
|
||||||
|
|
||||||
return SendMsgElementConstructor.ark(musicJson)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default SendMsg
|
|
@@ -1,31 +0,0 @@
|
|||||||
import BaseAction from "./BaseAction";
|
|
||||||
import {groupNotifies} from "../../common/data";
|
|
||||||
import {GroupNotify, GroupRequestOperateTypes} from "../../ntqqapi/types";
|
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {ActionName} from "./types";
|
|
||||||
|
|
||||||
interface Payload {
|
|
||||||
flag: string,
|
|
||||||
// sub_type: "add" | "invite",
|
|
||||||
// type: "add" | "invite"
|
|
||||||
approve: boolean,
|
|
||||||
reason: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
|
||||||
actionName = ActionName.SetGroupAddRequest
|
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
|
||||||
const seq = payload.flag.toString();
|
|
||||||
const notify: GroupNotify = groupNotifies[seq]
|
|
||||||
try {
|
|
||||||
await NTQQApi.handleGroupRequest(seq,
|
|
||||||
payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
|
||||||
payload.reason
|
|
||||||
)
|
|
||||||
} catch (e) {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
110
src/onebot11/action/file/GetFile.ts
Normal file
110
src/onebot11/action/file/GetFile.ts
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import fs from "fs/promises";
|
||||||
|
import {dbUtil} from "../../../common/db";
|
||||||
|
import {getConfigUtil} from "../../../common/config";
|
||||||
|
import {log, sleep, uri2local} from "../../../common/utils";
|
||||||
|
import {NTQQFileApi} from "../../../ntqqapi/api/file";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {FileElement, RawMessage, VideoElement} from "../../../ntqqapi/types";
|
||||||
|
|
||||||
|
export interface GetFilePayload {
|
||||||
|
file: string // 文件名或者fileUuid
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetFileResponse {
|
||||||
|
file?: string // path
|
||||||
|
url?: string
|
||||||
|
file_size?: string
|
||||||
|
file_name?: string
|
||||||
|
base64?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||||
|
private getElement(msg: RawMessage): {id: string, element: VideoElement | FileElement}{
|
||||||
|
let element = msg.elements.find(e=>e.fileElement)
|
||||||
|
if (!element){
|
||||||
|
element = msg.elements.find(e=>e.videoElement)
|
||||||
|
return {id: element.elementId, element: element.videoElement}
|
||||||
|
}
|
||||||
|
return {id: element.elementId, element: element.fileElement}
|
||||||
|
}
|
||||||
|
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
||||||
|
const cache = await dbUtil.getFileCache(payload.file)
|
||||||
|
const {autoDeleteFile, enableLocalFile2Url, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
||||||
|
if (!cache) {
|
||||||
|
throw new Error('file not found')
|
||||||
|
}
|
||||||
|
if (cache.downloadFunc) {
|
||||||
|
await cache.downloadFunc()
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await fs.access(cache.filePath, fs.constants.F_OK)
|
||||||
|
} catch (e) {
|
||||||
|
log("file not found", e)
|
||||||
|
if (cache.url){
|
||||||
|
const downloadResult = await uri2local(cache.url)
|
||||||
|
if (downloadResult.success) {
|
||||||
|
cache.filePath = downloadResult.path
|
||||||
|
dbUtil.addFileCache(payload.file, cache).then()
|
||||||
|
} else {
|
||||||
|
throw new Error("file download failed. " + downloadResult.errMsg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// 没有url的可能是私聊文件或者群文件,需要自己下载
|
||||||
|
log("需要调用 NTQQ 下载文件api")
|
||||||
|
if (cache.msgId) {
|
||||||
|
let msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||||
|
if (msg){
|
||||||
|
log("找到了文件 msg", msg)
|
||||||
|
let element = this.getElement(msg);
|
||||||
|
log("找到了文件 element", element);
|
||||||
|
// 构建下载函数
|
||||||
|
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
|
element.id, "", "", true)
|
||||||
|
await sleep(1000);
|
||||||
|
msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||||
|
log("下载完成后的msg", msg)
|
||||||
|
cache.filePath = this.getElement(msg).element.filePath
|
||||||
|
dbUtil.addFileCache(payload.file, cache).then()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
let res: GetFileResponse = {
|
||||||
|
file: cache.filePath,
|
||||||
|
url: cache.url,
|
||||||
|
file_size: cache.fileSize,
|
||||||
|
file_name: cache.fileName
|
||||||
|
}
|
||||||
|
if (enableLocalFile2Url) {
|
||||||
|
if (!cache.url) {
|
||||||
|
try{
|
||||||
|
res.base64 = await fs.readFile(cache.filePath, 'base64')
|
||||||
|
}catch (e) {
|
||||||
|
throw new Error("文件下载失败. " + e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (autoDeleteFile) {
|
||||||
|
// setTimeout(() => {
|
||||||
|
// fs.unlink(cache.filePath)
|
||||||
|
// }, autoDeleteFileSecond * 1000)
|
||||||
|
// }
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GetFile extends GetFileBase {
|
||||||
|
actionName = ActionName.GetFile
|
||||||
|
|
||||||
|
protected async _handle(payload: {file_id: string, file: string}): Promise<GetFileResponse> {
|
||||||
|
if (!payload.file_id) {
|
||||||
|
throw new Error('file_id 不能为空')
|
||||||
|
}
|
||||||
|
payload.file = payload.file_id
|
||||||
|
return super._handle(payload);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
import {GetFileBase} from "./GetFile";
|
import {GetFileBase} from "./GetFile";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
|
|
||||||
export default class GetImage extends GetFileBase {
|
export default class GetImage extends GetFileBase {
|
@@ -1,5 +1,5 @@
|
|||||||
import {GetFileBase, GetFilePayload, GetFileResponse} from "./GetFile";
|
import {GetFileBase, GetFilePayload, GetFileResponse} from "./GetFile";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
interface Payload extends GetFilePayload {
|
interface Payload extends GetFilePayload {
|
||||||
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
|
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
|
73
src/onebot11/action/go-cqhttp/DownloadFile.ts
Normal file
73
src/onebot11/action/go-cqhttp/DownloadFile.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import fs from "fs";
|
||||||
|
import {join as joinPath} from "node:path";
|
||||||
|
import {calculateFileMD5, httpDownload, TEMP_DIR} from "../../../common/utils";
|
||||||
|
import {v4 as uuid4} from "uuid";
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
thread_count?: number
|
||||||
|
url?: string
|
||||||
|
base64?: string
|
||||||
|
name?: string
|
||||||
|
headers?: string | string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FileResponse {
|
||||||
|
file: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GoCQHTTPDownloadFile extends BaseAction<Payload, FileResponse> {
|
||||||
|
actionName = ActionName.GoCQHTTP_DownloadFile
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload): Promise<FileResponse> {
|
||||||
|
const isRandomName = !payload.name
|
||||||
|
let name = payload.name || uuid4();
|
||||||
|
const filePath = joinPath(TEMP_DIR, name);
|
||||||
|
|
||||||
|
if (payload.base64) {
|
||||||
|
fs.writeFileSync(filePath, payload.base64, 'base64')
|
||||||
|
} else if (payload.url) {
|
||||||
|
const headers = this.getHeaders(payload.headers);
|
||||||
|
let buffer = await httpDownload({url: payload.url, headers: headers})
|
||||||
|
fs.writeFileSync(filePath, Buffer.from(buffer), 'binary');
|
||||||
|
} else {
|
||||||
|
throw new Error("不存在任何文件, 无法下载")
|
||||||
|
}
|
||||||
|
if (fs.existsSync(filePath)) {
|
||||||
|
|
||||||
|
if (isRandomName) {
|
||||||
|
// 默认实现要名称未填写时文件名为文件 md5
|
||||||
|
const md5 = await calculateFileMD5(filePath);
|
||||||
|
const newPath = joinPath(TEMP_DIR, md5);
|
||||||
|
fs.renameSync(filePath, newPath);
|
||||||
|
return { file: newPath }
|
||||||
|
}
|
||||||
|
return { file: filePath }
|
||||||
|
} else {
|
||||||
|
throw new Error("文件写入失败, 检查权限")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getHeaders(headersIn?: string | string[]): Record<string, string> {
|
||||||
|
const headers = {};
|
||||||
|
if (typeof headersIn == 'string') {
|
||||||
|
headersIn = headersIn.split('[\\r\\n]');
|
||||||
|
}
|
||||||
|
if (Array.isArray(headersIn)) {
|
||||||
|
for (const headerItem of headersIn) {
|
||||||
|
const spilt = headerItem.indexOf('=');
|
||||||
|
if (spilt < 0) {
|
||||||
|
headers[headerItem] = "";
|
||||||
|
} else {
|
||||||
|
const key = headerItem.substring(0, spilt);
|
||||||
|
headers[key] = headerItem.substring(0, spilt + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!headers['Content-Type']) {
|
||||||
|
headers['Content-Type'] = 'application/octet-stream';
|
||||||
|
}
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
}
|
39
src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts
Normal file
39
src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {OB11Message, OB11User} from "../../types";
|
||||||
|
import {groups} from "../../../common/data";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {ChatType} from "../../../ntqqapi/types";
|
||||||
|
import {dbUtil} from "../../../common/db";
|
||||||
|
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||||
|
import {OB11Constructor} from "../../constructor";
|
||||||
|
import {log} from "../../../common/utils";
|
||||||
|
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
group_id: number
|
||||||
|
message_seq: number,
|
||||||
|
count: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Response{
|
||||||
|
messages: OB11Message[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Response> {
|
||||||
|
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload): Promise<Response> {
|
||||||
|
const group = groups.find(group => group.groupCode === payload.group_id.toString())
|
||||||
|
if (!group) {
|
||||||
|
throw `群${payload.group_id}不存在`
|
||||||
|
}
|
||||||
|
const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || "0"
|
||||||
|
// log("startMsgId", startMsgId)
|
||||||
|
let msgList = (await NTQQMsgApi.getMsgHistory({chatType: ChatType.group, peerUid: group.groupCode}, startMsgId, parseInt(payload.count?.toString()) || 20)).msgList
|
||||||
|
await Promise.all(msgList.map(async msg => {
|
||||||
|
msg.msgShortId = await dbUtil.addMsg(msg)
|
||||||
|
}))
|
||||||
|
const ob11MsgList = await Promise.all(msgList.map(msg=>OB11Constructor.message(msg)))
|
||||||
|
return {"messages": ob11MsgList}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,9 @@
|
|||||||
import BaseAction from "../BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {OB11User} from "../../types";
|
import {OB11User} from "../../types";
|
||||||
import {getFriend, getGroupMember, groups} from "../../../common/data";
|
import {getUidByUin, uidMaps} from "../../../common/data";
|
||||||
import {OB11Constructor} from "../../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import {ActionName} from "../types";
|
import {ActionName} from "../types";
|
||||||
|
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||||
|
|
||||||
|
|
||||||
export default class GoCQHTTPGetStrangerInfo extends BaseAction<{ user_id: number }, OB11User> {
|
export default class GoCQHTTPGetStrangerInfo extends BaseAction<{ user_id: number }, OB11User> {
|
||||||
@@ -10,16 +11,10 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<{ user_id: numbe
|
|||||||
|
|
||||||
protected async _handle(payload: { user_id: number }): Promise<OB11User> {
|
protected async _handle(payload: { user_id: number }): Promise<OB11User> {
|
||||||
const user_id = payload.user_id.toString()
|
const user_id = payload.user_id.toString()
|
||||||
const friend = await getFriend(user_id)
|
const uid = getUidByUin(user_id)
|
||||||
if (friend) {
|
if (!uid) {
|
||||||
return OB11Constructor.friend(friend);
|
throw new Error("查无此人")
|
||||||
}
|
}
|
||||||
for (const group of groups) {
|
return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid))
|
||||||
const member = await getGroupMember(group.groupCode, user_id)
|
|
||||||
if (member) {
|
|
||||||
return OB11Constructor.groupMember(group.groupCode, member) as OB11User
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw ("查无此人")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
import SendMsg from "../SendMsg";
|
import SendMsg from "../msg/SendMsg";
|
||||||
import {OB11PostSendMsg} from "../../types";
|
import {OB11PostSendMsg} from "../../types";
|
||||||
import {ActionName} from "../types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
@@ -6,7 +6,9 @@ export class GoCQHTTPSendGroupForwardMsg extends SendMsg {
|
|||||||
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||||
|
|
||||||
protected async check(payload: OB11PostSendMsg) {
|
protected async check(payload: OB11PostSendMsg) {
|
||||||
payload.message = this.convertMessage2List(payload.messages);
|
if (payload.messages){
|
||||||
|
payload.message = this.convertMessage2List(payload.messages);
|
||||||
|
}
|
||||||
return super.check(payload);
|
return super.check(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
37
src/onebot11/action/go-cqhttp/UploadGroupFile.ts
Normal file
37
src/onebot11/action/go-cqhttp/UploadGroupFile.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {getGroup} from "../../../common/data";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {SendMsgElementConstructor} from "../../../ntqqapi/constructor";
|
||||||
|
import {ChatType, SendFileElement} from "../../../ntqqapi/types";
|
||||||
|
import fs from "fs";
|
||||||
|
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||||
|
import {uri2local} from "../../../common/utils";
|
||||||
|
|
||||||
|
interface Payload{
|
||||||
|
group_id: number
|
||||||
|
file: string
|
||||||
|
name: string
|
||||||
|
folder: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
||||||
|
actionName = ActionName.GoCQHTTP_UploadGroupFile
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
const group = await getGroup(payload.group_id.toString());
|
||||||
|
if (!group){
|
||||||
|
throw new Error(`群组${payload.group_id}不存在`)
|
||||||
|
}
|
||||||
|
let file = payload.file;
|
||||||
|
if (fs.existsSync(file)){
|
||||||
|
file = `file://${file}`
|
||||||
|
}
|
||||||
|
const downloadResult = await uri2local(file);
|
||||||
|
if (downloadResult.errMsg){
|
||||||
|
throw new Error(downloadResult.errMsg)
|
||||||
|
}
|
||||||
|
let sendFileEle: SendFileElement = await SendMsgElementConstructor.file(downloadResult.path, payload.name);
|
||||||
|
await NTQQMsgApi.sendMsg({chatType: ChatType.group, peerUid: group.groupCode}, [sendFileEle]);
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11Group} from '../types';
|
import {OB11Group} from '../../types';
|
||||||
import {getGroup} from "../../common/data";
|
import {getGroup} from "../../../common/data";
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
interface PayloadType {
|
interface PayloadType {
|
||||||
group_id: number
|
group_id: number
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11Group} from '../types';
|
import {OB11Group} from '../../types';
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import {groups} from "../../common/data";
|
import {groups} from "../../../common/data";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
|
|
||||||
class GetGroupList extends BaseAction<null, OB11Group[]> {
|
class GetGroupList extends BaseAction<null, OB11Group[]> {
|
35
src/onebot11/action/group/GetGroupMemberInfo.ts
Normal file
35
src/onebot11/action/group/GetGroupMemberInfo.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import {OB11GroupMember} from '../../types';
|
||||||
|
import {getGroupMember} from "../../../common/data";
|
||||||
|
import {OB11Constructor} from "../../constructor";
|
||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
import {isNull} from "../../../common/utils/helper";
|
||||||
|
|
||||||
|
|
||||||
|
export interface PayloadType {
|
||||||
|
group_id: number
|
||||||
|
user_id: number
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetGroupMemberInfo extends BaseAction<PayloadType, OB11GroupMember> {
|
||||||
|
actionName = ActionName.GetGroupMemberInfo
|
||||||
|
|
||||||
|
protected async _handle(payload: PayloadType) {
|
||||||
|
const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString())
|
||||||
|
if (member) {
|
||||||
|
if (isNull(member.sex)){
|
||||||
|
log("获取群成员详细信息")
|
||||||
|
let info = (await NTQQUserApi.getUserDetailInfo(member.uid))
|
||||||
|
log("群成员详细信息结果", info)
|
||||||
|
Object.assign(member, info);
|
||||||
|
}
|
||||||
|
return OB11Constructor.groupMember(payload.group_id.toString(), member)
|
||||||
|
} else {
|
||||||
|
throw (`群成员${payload.user_id}不存在`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default GetGroupMemberInfo
|
@@ -1,9 +1,9 @@
|
|||||||
import {OB11GroupMember} from '../types';
|
import {OB11GroupMember} from '../../types';
|
||||||
import {getGroup} from "../../common/data";
|
import {getGroup} from "../../../common/data";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import {OB11Constructor} from "../constructor";
|
import BaseAction from "../BaseAction";
|
||||||
import BaseAction from "./BaseAction";
|
import {ActionName} from "../types";
|
||||||
import {ActionName} from "./types";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
||||||
group_id: number
|
group_id: number
|
||||||
@@ -17,7 +17,7 @@ class GetGroupMemberList extends BaseAction<PayloadType, OB11GroupMember[]> {
|
|||||||
const group = await getGroup(payload.group_id.toString());
|
const group = await getGroup(payload.group_id.toString());
|
||||||
if (group) {
|
if (group) {
|
||||||
if (!group.members?.length) {
|
if (!group.members?.length) {
|
||||||
group.members = await NTQQApi.getGroupMembers(payload.group_id.toString())
|
group.members = await NTQQGroupApi.getGroupMembers(payload.group_id.toString())
|
||||||
}
|
}
|
||||||
return OB11Constructor.groupMembers(group);
|
return OB11Constructor.groupMembers(group);
|
||||||
} else {
|
} else {
|
@@ -1,5 +1,5 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
export default class GetGuildList extends BaseAction<null, null> {
|
export default class GetGuildList extends BaseAction<null, null> {
|
||||||
actionName = ActionName.GetGuildList
|
actionName = ActionName.GetGuildList
|
@@ -1,7 +1,8 @@
|
|||||||
import SendMsg from "./SendMsg";
|
import SendMsg from "../msg/SendMsg";
|
||||||
import {ActionName, BaseCheckResult} from "./types";
|
import {ActionName, BaseCheckResult} from "../types";
|
||||||
import {OB11PostSendMsg} from "../types";
|
import {OB11PostSendMsg} from "../../types";
|
||||||
import {log} from "../../common/utils";
|
|
||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
|
|
||||||
class SendGroupMsg extends SendMsg {
|
class SendGroupMsg extends SendMsg {
|
26
src/onebot11/action/group/SetGroupAddRequest.ts
Normal file
26
src/onebot11/action/group/SetGroupAddRequest.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {GroupRequestOperateTypes} from "../../../ntqqapi/types";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
flag: string,
|
||||||
|
// sub_type: "add" | "invite",
|
||||||
|
// type: "add" | "invite"
|
||||||
|
approve: boolean,
|
||||||
|
reason: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
||||||
|
actionName = ActionName.SetGroupAddRequest
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
const seq = payload.flag.toString();
|
||||||
|
const approve = payload.approve.toString() === "true";
|
||||||
|
await NTQQGroupApi.handleGroupRequest(seq,
|
||||||
|
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||||
|
payload.reason
|
||||||
|
)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,8 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {getGroupMember} from "../../../common/data";
|
||||||
import {getGroupMember} from "../../common/data";
|
import {GroupMemberRole} from "../../../ntqqapi/types";
|
||||||
import {GroupMemberRole} from "../../ntqqapi/types";
|
import {ActionName} from "../types";
|
||||||
import {ActionName} from "./types";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -15,10 +15,11 @@ export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||||
|
const enable = payload.enable.toString() === "true"
|
||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`
|
throw `群成员${payload.user_id}不存在`
|
||||||
}
|
}
|
||||||
await NTQQApi.setMemberRole(payload.group_id.toString(), member.uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), member.uid, enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {getGroupMember} from "../../../common/data";
|
||||||
import {getGroupMember} from "../../common/data";
|
import {ActionName} from "../types";
|
||||||
import {ActionName} from "./types";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -17,7 +17,7 @@ export default class SetGroupBan extends BaseAction<Payload, null> {
|
|||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`
|
throw `群成员${payload.user_id}不存在`
|
||||||
}
|
}
|
||||||
await NTQQApi.banMember(payload.group_id.toString(),
|
await NTQQGroupApi.banMember(payload.group_id.toString(),
|
||||||
[{uid: member.uid, timeStamp: parseInt(payload.duration.toString())}])
|
[{uid: member.uid, timeStamp: parseInt(payload.duration.toString())}])
|
||||||
return null
|
return null
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {getGroupMember} from "../../../common/data";
|
||||||
import {getGroupMember} from "../../common/data";
|
import {ActionName} from "../types";
|
||||||
import {ActionName} from "./types";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -17,7 +17,7 @@ export default class SetGroupCard extends BaseAction<Payload, null> {
|
|||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`
|
throw `群成员${payload.user_id}不存在`
|
||||||
}
|
}
|
||||||
await NTQQApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || "")
|
await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || "")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {getGroupMember} from "../../../common/data";
|
||||||
import {getGroupMember} from "../../common/data";
|
import {ActionName} from "../types";
|
||||||
import {ActionName} from "./types";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -17,7 +17,7 @@ export default class SetGroupKick extends BaseAction<Payload, null> {
|
|||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`
|
throw `群成员${payload.user_id}不存在`
|
||||||
}
|
}
|
||||||
await NTQQApi.kickMember(payload.group_id.toString(), [member.uid], !!payload.reject_add_request);
|
await NTQQGroupApi.kickMember(payload.group_id.toString(), [member.uid], !!payload.reject_add_request);
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {ActionName} from "../types";
|
||||||
import {log} from "../../common/utils";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
import {ActionName} from "./types";
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -13,7 +13,7 @@ export default class SetGroupLeave extends BaseAction<Payload, any> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
try {
|
try {
|
||||||
await NTQQApi.quitGroup(payload.group_id.toString())
|
await NTQQGroupApi.quitGroup(payload.group_id.toString())
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("退群失败", e)
|
log("退群失败", e)
|
||||||
throw e
|
throw e
|
@@ -1,6 +1,6 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {ActionName} from "../types";
|
||||||
import {ActionName} from "./types";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -12,7 +12,7 @@ export default class SetGroupName extends BaseAction<Payload, null> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
|
||||||
await NTQQApi.setGroupName(payload.group_id.toString(), payload.group_name)
|
await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {ActionName} from "../types";
|
||||||
import {ActionName} from "./types";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -11,8 +11,8 @@ export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName.SetGroupWholeBan
|
actionName = ActionName.SetGroupWholeBan
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
const enable = payload.enable.toString() === "true"
|
||||||
await NTQQApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
await NTQQGroupApi.banGroup(payload.group_id.toString(), enable)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,39 +1,53 @@
|
|||||||
import GetMsg from './GetMsg'
|
import GetMsg from './msg/GetMsg'
|
||||||
import GetLoginInfo from './GetLoginInfo'
|
import GetLoginInfo from './system/GetLoginInfo'
|
||||||
import GetFriendList from './GetFriendList'
|
import GetFriendList from './user/GetFriendList'
|
||||||
import GetGroupList from './GetGroupList'
|
import GetGroupList from './group/GetGroupList'
|
||||||
import GetGroupInfo from './GetGroupInfo'
|
import GetGroupInfo from './group/GetGroupInfo'
|
||||||
import GetGroupMemberList from './GetGroupMemberList'
|
import GetGroupMemberList from './group/GetGroupMemberList'
|
||||||
import GetGroupMemberInfo from './GetGroupMemberInfo'
|
import GetGroupMemberInfo from './group/GetGroupMemberInfo'
|
||||||
import SendGroupMsg from './SendGroupMsg'
|
import SendGroupMsg from './group/SendGroupMsg'
|
||||||
import SendPrivateMsg from './SendPrivateMsg'
|
import SendPrivateMsg from './msg/SendPrivateMsg'
|
||||||
import SendMsg from './SendMsg'
|
import SendMsg from './msg/SendMsg'
|
||||||
import DeleteMsg from "./DeleteMsg";
|
import DeleteMsg from "./msg/DeleteMsg";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import GetVersionInfo from "./GetVersionInfo";
|
import GetVersionInfo from "./system/GetVersionInfo";
|
||||||
import CanSendRecord from "./CanSendRecord";
|
import CanSendRecord from "./system/CanSendRecord";
|
||||||
import CanSendImage from "./CanSendImage";
|
import CanSendImage from "./system/CanSendImage";
|
||||||
import GetStatus from "./GetStatus";
|
import GetStatus from "./system/GetStatus";
|
||||||
import {GoCQHTTPSendGroupForwardMsg, GoCQHTTPSendPrivateForwardMsg} from "./go-cqhttp/SendForwardMsg";
|
import {GoCQHTTPSendGroupForwardMsg, GoCQHTTPSendPrivateForwardMsg} from "./go-cqhttp/SendForwardMsg";
|
||||||
import GoCQHTTPGetStrangerInfo from "./go-cqhttp/GetStrangerInfo";
|
import GoCQHTTPGetStrangerInfo from "./go-cqhttp/GetStrangerInfo";
|
||||||
import SendLike from "./SendLike";
|
import SendLike from "./user/SendLike";
|
||||||
import SetGroupAddRequest from "./SetGroupAddRequest";
|
import SetGroupAddRequest from "./group/SetGroupAddRequest";
|
||||||
import SetGroupLeave from "./SetGroupLeave";
|
import SetGroupLeave from "./group/SetGroupLeave";
|
||||||
import GetGuildList from "./GetGuildList";
|
import GetGuildList from "./group/GetGuildList";
|
||||||
import Debug from "./Debug";
|
import Debug from "./llonebot/Debug";
|
||||||
import SetFriendAddRequest from "./SetFriendAddRequest";
|
import SetFriendAddRequest from "./user/SetFriendAddRequest";
|
||||||
import SetGroupWholeBan from "./SetGroupWholeBan";
|
import SetGroupWholeBan from "./group/SetGroupWholeBan";
|
||||||
import SetGroupName from "./SetGroupName";
|
import SetGroupName from "./group/SetGroupName";
|
||||||
import SetGroupBan from "./SetGroupBan";
|
import SetGroupBan from "./group/SetGroupBan";
|
||||||
import SetGroupKick from "./SetGroupKick";
|
import SetGroupKick from "./group/SetGroupKick";
|
||||||
import SetGroupAdmin from "./SetGroupAdmin";
|
import SetGroupAdmin from "./group/SetGroupAdmin";
|
||||||
import SetGroupCard from "./SetGroupCard";
|
import SetGroupCard from "./group/SetGroupCard";
|
||||||
import GetImage from "./GetImage";
|
import GetImage from "./file/GetImage";
|
||||||
import GetRecord from "./GetRecord";
|
import GetRecord from "./file/GetRecord";
|
||||||
import GoCQHTTPMarkMsgAsRead from "./MarkMsgAsRead";
|
import GoCQHTTPMarkMsgAsRead from "./msg/MarkMsgAsRead";
|
||||||
|
import CleanCache from "./system/CleanCache";
|
||||||
|
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
||||||
|
import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
||||||
|
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
||||||
|
import SetQQAvatar from './llonebot/SetQQAvatar'
|
||||||
|
import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
||||||
|
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
||||||
|
import GetFile from "./file/GetFile";
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
|
new GetFile(),
|
||||||
new Debug(),
|
new Debug(),
|
||||||
|
new GetConfigAction(),
|
||||||
|
new SetConfigAction(),
|
||||||
|
new GetGroupAddRequest(),
|
||||||
|
new SetQQAvatar(),
|
||||||
|
// onebot11
|
||||||
new SendLike(),
|
new SendLike(),
|
||||||
new GetMsg(),
|
new GetMsg(),
|
||||||
new GetLoginInfo(),
|
new GetLoginInfo(),
|
||||||
@@ -56,13 +70,17 @@ export const actionHandlers = [
|
|||||||
new SetGroupCard(),
|
new SetGroupCard(),
|
||||||
new GetImage(),
|
new GetImage(),
|
||||||
new GetRecord(),
|
new GetRecord(),
|
||||||
|
new CleanCache(),
|
||||||
|
|
||||||
//以下为go-cqhttp api
|
//以下为go-cqhttp api
|
||||||
new GoCQHTTPSendGroupForwardMsg(),
|
new GoCQHTTPSendGroupForwardMsg(),
|
||||||
new GoCQHTTPSendPrivateForwardMsg(),
|
new GoCQHTTPSendPrivateForwardMsg(),
|
||||||
new GoCQHTTPGetStrangerInfo(),
|
new GoCQHTTPGetStrangerInfo(),
|
||||||
|
new GoCQHTTPDownloadFile(),
|
||||||
new GetGuildList(),
|
new GetGuildList(),
|
||||||
new GoCQHTTPMarkMsgAsRead(),
|
new GoCQHTTPMarkMsgAsRead(),
|
||||||
|
new GoCQHTTPUploadGroupFile(),
|
||||||
|
new GoCQHTTPGetGroupMsgHistory(),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
20
src/onebot11/action/llonebot/Config.ts
Normal file
20
src/onebot11/action/llonebot/Config.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {Config} from "../../../common/types";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {setConfig} from "../../../main/setConfig";
|
||||||
|
import {getConfigUtil} from "../../../common/config";
|
||||||
|
|
||||||
|
|
||||||
|
export class GetConfigAction extends BaseAction<null, Config> {
|
||||||
|
actionName = ActionName.GetConfig
|
||||||
|
protected async _handle(payload: null): Promise<Config> {
|
||||||
|
return getConfigUtil().getConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SetConfigAction extends BaseAction<Config, void> {
|
||||||
|
actionName = ActionName.SetConfig
|
||||||
|
protected async _handle(payload: Config): Promise<void> {
|
||||||
|
setConfig(payload).then();
|
||||||
|
}
|
||||||
|
}
|
42
src/onebot11/action/llonebot/Debug.ts
Normal file
42
src/onebot11/action/llonebot/Debug.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
// import * as ntqqApi from "../../../ntqqapi/api";
|
||||||
|
import {
|
||||||
|
NTQQMsgApi,
|
||||||
|
NTQQFriendApi,
|
||||||
|
NTQQGroupApi,
|
||||||
|
NTQQUserApi,
|
||||||
|
NTQQFileApi,
|
||||||
|
NTQQFileCacheApi,
|
||||||
|
NTQQWindowApi,
|
||||||
|
} from "../../../ntqqapi/api";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
method: string,
|
||||||
|
args: any[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Debug extends BaseAction<Payload, any> {
|
||||||
|
actionName = ActionName.Debug
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
|
log("debug call ntqq api", payload);
|
||||||
|
const ntqqApi = [NTQQMsgApi, NTQQFriendApi, NTQQGroupApi, NTQQUserApi, NTQQFileApi, NTQQFileCacheApi, NTQQWindowApi]
|
||||||
|
for (const ntqqApiClass of ntqqApi) {
|
||||||
|
log("ntqqApiClass", ntqqApiClass)
|
||||||
|
const method = ntqqApiClass[payload.method]
|
||||||
|
if (method) {
|
||||||
|
const result = method(...payload.args);
|
||||||
|
if (method.constructor.name === "AsyncFunction") {
|
||||||
|
return await result
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw `${payload.method}方法 不存在`
|
||||||
|
|
||||||
|
// const info = await NTQQApi.getUserDetailInfo(friends[0].uid);
|
||||||
|
// return info
|
||||||
|
}
|
||||||
|
}
|
33
src/onebot11/action/llonebot/GetGroupAddRequest.ts
Normal file
33
src/onebot11/action/llonebot/GetGroupAddRequest.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import {GroupNotify, GroupNotifyStatus} from "../../../ntqqapi/types";
|
||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {uidMaps} from "../../../common/data";
|
||||||
|
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||||
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
|
interface OB11GroupRequestNotify {
|
||||||
|
group_id: number,
|
||||||
|
user_id: number,
|
||||||
|
flag: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GetGroupAddRequest extends BaseAction<null, OB11GroupRequestNotify[]> {
|
||||||
|
actionName = ActionName.GetGroupIgnoreAddRequest
|
||||||
|
|
||||||
|
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[]> {
|
||||||
|
const data = await NTQQGroupApi.getGroupIgnoreNotifies()
|
||||||
|
log(data);
|
||||||
|
let notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
|
||||||
|
let returnData: OB11GroupRequestNotify[] = []
|
||||||
|
for (const notify of notifies) {
|
||||||
|
const uin = uidMaps[notify.user1.uid] || (await NTQQUserApi.getUserDetailInfo(notify.user1.uid))?.uin
|
||||||
|
returnData.push({
|
||||||
|
group_id: parseInt(notify.group.groupCode),
|
||||||
|
user_id: parseInt(uin),
|
||||||
|
flag: notify.seq
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return returnData;
|
||||||
|
}
|
||||||
|
}
|
43
src/onebot11/action/llonebot/SetQQAvatar.ts
Normal file
43
src/onebot11/action/llonebot/SetQQAvatar.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import * as fs from "node:fs";
|
||||||
|
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||||
|
import {checkFileReceived, uri2local} from "../../../common/utils/file";
|
||||||
|
// import { log } from "../../../common/utils";
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
file: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class SetAvatar extends BaseAction<Payload, null> {
|
||||||
|
actionName = ActionName.SetQQAvatar
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
const {path, isLocal, errMsg} = (await uri2local(payload.file))
|
||||||
|
if (errMsg){
|
||||||
|
throw `头像${payload.file}设置失败,file字段可能格式不正确`
|
||||||
|
}
|
||||||
|
if (path) {
|
||||||
|
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||||
|
const ret = await NTQQUserApi.setQQAvatar(path)
|
||||||
|
if (!isLocal){
|
||||||
|
fs.unlink(path, () => {})
|
||||||
|
}
|
||||||
|
if (!ret) {
|
||||||
|
throw `头像${payload.file}设置失败,api无返回`
|
||||||
|
}
|
||||||
|
// log(`头像设置返回:${JSON.stringify(ret)}`)
|
||||||
|
if (ret['result'] == 1004022) {
|
||||||
|
throw `头像${payload.file}设置失败,文件可能不是图片格式`
|
||||||
|
} else if(ret['result'] != 0) {
|
||||||
|
throw `头像${payload.file}设置失败,未知的错误,${ret['result']}:${ret['errMsg']}`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!isLocal){
|
||||||
|
fs.unlink(path, () => {})
|
||||||
|
}
|
||||||
|
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {dbUtil} from "../../../common/db";
|
||||||
import {dbUtil} from "../../common/db";
|
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: number
|
message_id: number
|
||||||
@@ -12,7 +12,7 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
let msg = await dbUtil.getMsgByShortId(payload.message_id)
|
let msg = await dbUtil.getMsgByShortId(payload.message_id)
|
||||||
await NTQQApi.recallMsg({
|
await NTQQMsgApi.recallMsg({
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid
|
peerUid: msg.peerUid
|
||||||
}, [msg.msgId])
|
}, [msg.msgId])
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11Message} from '../types';
|
import {OB11Message} from '../../types';
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../../common/db";
|
||||||
|
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
||||||
@@ -19,13 +19,14 @@ class GetMsg extends BaseAction<PayloadType, OB11Message> {
|
|||||||
if (!payload.message_id) {
|
if (!payload.message_id) {
|
||||||
throw ("参数message_id不能为空")
|
throw ("参数message_id不能为空")
|
||||||
}
|
}
|
||||||
const msg = await dbUtil.getMsgByShortId(payload.message_id)
|
let msg = await dbUtil.getMsgByShortId(payload.message_id)
|
||||||
if (msg) {
|
if(!msg) {
|
||||||
const msgData = await OB11Constructor.message(msg);
|
msg = await dbUtil.getMsgByLongId(payload.message_id.toString())
|
||||||
return msgData
|
}
|
||||||
} else {
|
if (!msg){
|
||||||
throw ("消息不存在")
|
throw ("消息不存在")
|
||||||
}
|
}
|
||||||
|
return await OB11Constructor.message(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@@ -1,5 +1,5 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
interface Payload{
|
interface Payload{
|
||||||
message_id: number
|
message_id: number
|
520
src/onebot11/action/msg/SendMsg.ts
Normal file
520
src/onebot11/action/msg/SendMsg.ts
Normal file
@@ -0,0 +1,520 @@
|
|||||||
|
import {
|
||||||
|
AtType,
|
||||||
|
ChatType,
|
||||||
|
ElementType,
|
||||||
|
Group,
|
||||||
|
RawMessage,
|
||||||
|
SendArkElement,
|
||||||
|
SendMessageElement
|
||||||
|
} from "../../../ntqqapi/types";
|
||||||
|
import {
|
||||||
|
friends,
|
||||||
|
getFriend,
|
||||||
|
getGroup,
|
||||||
|
getGroupMember,
|
||||||
|
getUidByUin,
|
||||||
|
selfInfo,
|
||||||
|
} from "../../../common/data";
|
||||||
|
import {
|
||||||
|
OB11MessageCustomMusic,
|
||||||
|
OB11MessageData,
|
||||||
|
OB11MessageDataType,
|
||||||
|
OB11MessageMixType,
|
||||||
|
OB11MessageNode,
|
||||||
|
OB11PostSendMsg
|
||||||
|
} from '../../types';
|
||||||
|
import {Peer} from "../../../ntqqapi/api/msg";
|
||||||
|
import {SendMsgElementConstructor} from "../../../ntqqapi/constructor";
|
||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {ActionName, BaseCheckResult} from "../types";
|
||||||
|
import * as fs from "node:fs";
|
||||||
|
import {decodeCQCode} from "../../cqcode";
|
||||||
|
import {dbUtil} from "../../../common/db";
|
||||||
|
import {ALLOW_SEND_TEMP_MSG} from "../../../common/config";
|
||||||
|
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
import {sleep} from "../../../common/utils/helper";
|
||||||
|
import {uri2local} from "../../../common/utils";
|
||||||
|
|
||||||
|
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||||
|
function checkUri(uri: string): boolean {
|
||||||
|
const pattern = /^(file:\/\/|http:\/\/|https:\/\/|base64:\/\/)/;
|
||||||
|
return pattern.test(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let msg of sendMsgList) {
|
||||||
|
if (msg["type"] && msg["data"]) {
|
||||||
|
let type = msg["type"];
|
||||||
|
let data = msg["data"];
|
||||||
|
if (type === "text" && !data["text"]) {
|
||||||
|
return 400;
|
||||||
|
} else if (["image", "voice", "record"].includes(type)) {
|
||||||
|
if (!data["file"]) {
|
||||||
|
return 400;
|
||||||
|
} else {
|
||||||
|
if (checkUri(data["file"])) {
|
||||||
|
return 200;
|
||||||
|
} else {
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (type === "at" && !data["qq"]) {
|
||||||
|
return 400;
|
||||||
|
} else if (type === "reply" && !data["id"]) {
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 400
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ReturnDataType {
|
||||||
|
message_id: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function convertMessage2List(message: OB11MessageMixType, autoEscape = false) {
|
||||||
|
if (typeof message === "string") {
|
||||||
|
if (!autoEscape) {
|
||||||
|
message = decodeCQCode(message.toString())
|
||||||
|
} else {
|
||||||
|
message = [{
|
||||||
|
type: OB11MessageDataType.text,
|
||||||
|
data: {
|
||||||
|
text: message
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
} else if (!Array.isArray(message)) {
|
||||||
|
message = [message]
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createSendElements(messageData: OB11MessageData[], group: Group | undefined, ignoreTypes: OB11MessageDataType[] = []) {
|
||||||
|
let sendElements: SendMessageElement[] = []
|
||||||
|
let deleteAfterSentFiles: string[] = []
|
||||||
|
for (let sendMsg of messageData) {
|
||||||
|
if (ignoreTypes.includes(sendMsg.type)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch (sendMsg.type) {
|
||||||
|
case OB11MessageDataType.text: {
|
||||||
|
const text = sendMsg.data?.text;
|
||||||
|
if (text) {
|
||||||
|
sendElements.push(SendMsgElementConstructor.text(sendMsg.data!.text))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OB11MessageDataType.at: {
|
||||||
|
if (!group) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
let atQQ = sendMsg.data?.qq;
|
||||||
|
if (atQQ) {
|
||||||
|
atQQ = atQQ.toString()
|
||||||
|
if (atQQ === "all") {
|
||||||
|
sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, "全体成员"))
|
||||||
|
} else {
|
||||||
|
// const atMember = group?.members.find(m => m.uin == atQQ)
|
||||||
|
const atMember = await getGroupMember(group?.groupCode, atQQ);
|
||||||
|
if (atMember) {
|
||||||
|
sendElements.push(SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OB11MessageDataType.reply: {
|
||||||
|
let replyMsgId = sendMsg.data.id;
|
||||||
|
if (replyMsgId) {
|
||||||
|
const replyMsg = await dbUtil.getMsgByShortId(parseInt(replyMsgId))
|
||||||
|
if (replyMsg) {
|
||||||
|
sendElements.push(SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin, replyMsg.senderUin))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OB11MessageDataType.face: {
|
||||||
|
const faceId = sendMsg.data?.id
|
||||||
|
if (faceId) {
|
||||||
|
sendElements.push(SendMsgElementConstructor.face(parseInt(faceId)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OB11MessageDataType.image:
|
||||||
|
case OB11MessageDataType.file:
|
||||||
|
case OB11MessageDataType.video:
|
||||||
|
case OB11MessageDataType.voice: {
|
||||||
|
let file = sendMsg.data?.file
|
||||||
|
const payloadFileName = sendMsg.data?.name
|
||||||
|
if (file) {
|
||||||
|
const cache = await dbUtil.getFileCache(file)
|
||||||
|
if (cache) {
|
||||||
|
if (fs.existsSync(cache.filePath)) {
|
||||||
|
file = "file://" + cache.filePath
|
||||||
|
} else if (cache.downloadFunc) {
|
||||||
|
await cache.downloadFunc()
|
||||||
|
file = cache.filePath;
|
||||||
|
} else if (cache.url) {
|
||||||
|
file = cache.url
|
||||||
|
}
|
||||||
|
log("找到文件缓存", file);
|
||||||
|
}
|
||||||
|
const {path, isLocal, fileName, errMsg} = (await uri2local(file))
|
||||||
|
if (errMsg) {
|
||||||
|
throw errMsg
|
||||||
|
}
|
||||||
|
if (path) {
|
||||||
|
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||||
|
deleteAfterSentFiles.push(path)
|
||||||
|
}
|
||||||
|
if (sendMsg.type === OB11MessageDataType.file) {
|
||||||
|
log("发送文件", path, payloadFileName || fileName)
|
||||||
|
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
|
||||||
|
} else if (sendMsg.type === OB11MessageDataType.video) {
|
||||||
|
log("发送视频", path, payloadFileName || fileName)
|
||||||
|
let thumb = sendMsg.data?.thumb;
|
||||||
|
if (thumb) {
|
||||||
|
let uri2LocalRes = await uri2local(thumb)
|
||||||
|
if (uri2LocalRes.success) {
|
||||||
|
thumb = uri2LocalRes.path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb));
|
||||||
|
} else if (sendMsg.type === OB11MessageDataType.voice) {
|
||||||
|
sendElements.push(await SendMsgElementConstructor.ptt(path));
|
||||||
|
} else if (sendMsg.type === OB11MessageDataType.image) {
|
||||||
|
sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OB11MessageDataType.json: {
|
||||||
|
sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
sendElements,
|
||||||
|
deleteAfterSentFiles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function sendMsg(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
||||||
|
if (!sendElements.length) {
|
||||||
|
throw ("消息体无法解析")
|
||||||
|
}
|
||||||
|
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
||||||
|
log("消息发送结果", returnMsg)
|
||||||
|
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
||||||
|
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||||
|
}))
|
||||||
|
return returnMsg
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||||
|
actionName = ActionName.SendMsg
|
||||||
|
|
||||||
|
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||||
|
const messages = convertMessage2List(payload.message);
|
||||||
|
const fmNum = this.getSpecialMsgNum(payload, OB11MessageDataType.node)
|
||||||
|
if (fmNum && fmNum != messages.length) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
message: "转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (payload.group_id && !(await getGroup(payload.group_id))) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
message: `群${payload.group_id}不存在`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (payload.user_id && payload.message_type !== "group") {
|
||||||
|
if (!(await getFriend(payload.user_id))) {
|
||||||
|
if (!ALLOW_SEND_TEMP_MSG && !(await dbUtil.getReceivedTempUinMap())[payload.user_id.toString()]) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
message: `不能发送临时消息`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
valid: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _handle(payload: OB11PostSendMsg) {
|
||||||
|
|
||||||
|
const peer: Peer = {
|
||||||
|
chatType: ChatType.friend,
|
||||||
|
peerUid: ""
|
||||||
|
}
|
||||||
|
let isTempMsg = false;
|
||||||
|
let group: Group | undefined = undefined;
|
||||||
|
const genGroupPeer = async () => {
|
||||||
|
group = await getGroup(payload.group_id.toString())
|
||||||
|
peer.chatType = ChatType.group
|
||||||
|
// peer.name = group.name
|
||||||
|
peer.peerUid = group.groupCode
|
||||||
|
}
|
||||||
|
|
||||||
|
const genFriendPeer = () => {
|
||||||
|
const friend = friends.find(f => f.uin == payload.user_id.toString())
|
||||||
|
if (friend) {
|
||||||
|
// peer.name = friend.nickName
|
||||||
|
peer.peerUid = friend.uid
|
||||||
|
} else {
|
||||||
|
peer.chatType = ChatType.temp
|
||||||
|
const tempUserUid = getUidByUin(payload.user_id.toString())
|
||||||
|
if (!tempUserUid) {
|
||||||
|
throw (`找不到私聊对象${payload.user_id}`)
|
||||||
|
}
|
||||||
|
// peer.name = tempUser.nickName
|
||||||
|
isTempMsg = true;
|
||||||
|
peer.peerUid = tempUserUid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (payload?.group_id && payload.message_type === "group") {
|
||||||
|
await genGroupPeer()
|
||||||
|
|
||||||
|
} else if (payload?.user_id) {
|
||||||
|
genFriendPeer()
|
||||||
|
} else if (payload.group_id) {
|
||||||
|
await genGroupPeer()
|
||||||
|
} else {
|
||||||
|
throw ("发送消息参数错误, 请指定group_id或user_id")
|
||||||
|
}
|
||||||
|
const messages = convertMessage2List(payload.message);
|
||||||
|
if (this.getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||||
|
try {
|
||||||
|
const returnMsg = await this.handleForwardNode(peer, messages as OB11MessageNode[], group)
|
||||||
|
return {message_id: returnMsg.msgShortId}
|
||||||
|
} catch (e) {
|
||||||
|
throw ("发送转发消息失败 " + e.toString())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
||||||
|
const music: OB11MessageCustomMusic = messages[0] as OB11MessageCustomMusic
|
||||||
|
if (music) {
|
||||||
|
const {url, audio, title, content, image} = music.data;
|
||||||
|
const selfPeer: Peer = {peerUid: selfInfo.uid, chatType: ChatType.friend}
|
||||||
|
// 搞不定!
|
||||||
|
// const musicMsg = await this.send(selfPeer, [this.genMusicElement(url, audio, title, content, image)], [], false)
|
||||||
|
// 转发
|
||||||
|
// const res = await NTQQApi.forwardMsg(selfPeer, peer, [musicMsg.msgId])
|
||||||
|
// log("转发音乐消息成功", res);
|
||||||
|
// return {message_id: musicMsg.msgShortId}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// log("send msg:", peer, sendElements)
|
||||||
|
const {sendElements, deleteAfterSentFiles} = await createSendElements(messages, group)
|
||||||
|
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles)
|
||||||
|
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||||
|
}));
|
||||||
|
return {message_id: returnMsg.msgShortId}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
|
||||||
|
if (Array.isArray(payload.message)) {
|
||||||
|
return payload.message.filter(msg => msg.type == msgType).length
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private async cloneMsg(msg: RawMessage): Promise<RawMessage> {
|
||||||
|
log("克隆的目标消息", msg)
|
||||||
|
let sendElements: SendMessageElement[] = [];
|
||||||
|
for (const ele of msg.elements) {
|
||||||
|
sendElements.push(ele as SendMessageElement)
|
||||||
|
// Object.keys(ele).forEach((eleKey) => {
|
||||||
|
// if (eleKey.endsWith("Element")) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
if (sendElements.length === 0) {
|
||||||
|
log("需要clone的消息无法解析,将会忽略掉", msg)
|
||||||
|
}
|
||||||
|
log("克隆消息", sendElements)
|
||||||
|
try {
|
||||||
|
const nodeMsg = await NTQQMsgApi.sendMsg({
|
||||||
|
chatType: ChatType.friend,
|
||||||
|
peerUid: selfInfo.uid
|
||||||
|
}, sendElements, true);
|
||||||
|
await sleep(500);
|
||||||
|
return nodeMsg
|
||||||
|
} catch (e) {
|
||||||
|
log(e, "克隆转发消息失败,将忽略本条消息", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回一个合并转发的消息id
|
||||||
|
private async handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[], group: Group | undefined) {
|
||||||
|
|
||||||
|
const selfPeer = {
|
||||||
|
chatType: ChatType.friend,
|
||||||
|
peerUid: selfInfo.uid
|
||||||
|
}
|
||||||
|
let nodeMsgIds: string[] = []
|
||||||
|
// 先判断一遍是不是id和自定义混用
|
||||||
|
let needClone = messageNodes.filter(node => node.data.id).length && messageNodes.filter(node => !node.data.id).length
|
||||||
|
for (const messageNode of messageNodes) {
|
||||||
|
// 一个node表示一个人的消息
|
||||||
|
let nodeId = messageNode.data.id;
|
||||||
|
// 有nodeId表示一个子转发消息卡片
|
||||||
|
if (nodeId) {
|
||||||
|
let nodeMsg = await dbUtil.getMsgByShortId(parseInt(nodeId));
|
||||||
|
if (!needClone) {
|
||||||
|
nodeMsgIds.push(nodeMsg.msgId)
|
||||||
|
} else {
|
||||||
|
if (nodeMsg.peerUid !== selfInfo.uid) {
|
||||||
|
const cloneMsg = await this.cloneMsg(nodeMsg)
|
||||||
|
if (cloneMsg) {
|
||||||
|
nodeMsgIds.push(cloneMsg.msgId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 自定义的消息
|
||||||
|
// 提取消息段,发给自己生成消息id
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
sendElements,
|
||||||
|
deleteAfterSentFiles
|
||||||
|
} = await createSendElements(convertMessage2List(messageNode.data.content), group);
|
||||||
|
log("开始生成转发节点", sendElements);
|
||||||
|
let sendElementsSplit: SendMessageElement[][] = []
|
||||||
|
let splitIndex = 0;
|
||||||
|
for (const ele of sendElements) {
|
||||||
|
if (!sendElementsSplit[splitIndex]) {
|
||||||
|
sendElementsSplit[splitIndex] = []
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ele.elementType === ElementType.FILE || ele.elementType === ElementType.VIDEO) {
|
||||||
|
if (sendElementsSplit[splitIndex].length > 0) {
|
||||||
|
splitIndex++;
|
||||||
|
}
|
||||||
|
sendElementsSplit[splitIndex] = [ele]
|
||||||
|
splitIndex++;
|
||||||
|
} else {
|
||||||
|
sendElementsSplit[splitIndex].push(ele)
|
||||||
|
}
|
||||||
|
log(sendElementsSplit)
|
||||||
|
}
|
||||||
|
// log("分割后的转发节点", sendElementsSplit)
|
||||||
|
for (const eles of sendElementsSplit) {
|
||||||
|
const nodeMsg = await sendMsg(selfPeer, eles, [], true);
|
||||||
|
nodeMsgIds.push(nodeMsg.msgId)
|
||||||
|
await sleep(500);
|
||||||
|
log("转发节点生成成功", nodeMsg.msgId);
|
||||||
|
}
|
||||||
|
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||||
|
}));
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
log("生成转发消息节点失败", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查srcPeer是否一致,不一致则需要克隆成自己的消息, 让所有srcPeer都变成自己的,使其保持一致才能够转发
|
||||||
|
let nodeMsgArray: Array<RawMessage> = []
|
||||||
|
let srcPeer: Peer = null;
|
||||||
|
let needSendSelf = false;
|
||||||
|
for (const [index, msgId] of nodeMsgIds.entries()) {
|
||||||
|
const nodeMsg = await dbUtil.getMsgByLongId(msgId)
|
||||||
|
if (nodeMsg) {
|
||||||
|
nodeMsgArray.push(nodeMsg)
|
||||||
|
if (!srcPeer) {
|
||||||
|
srcPeer = {chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid}
|
||||||
|
} else if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||||
|
needSendSelf = true
|
||||||
|
srcPeer = selfPeer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log("nodeMsgArray", nodeMsgArray);
|
||||||
|
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
||||||
|
if (needSendSelf) {
|
||||||
|
log("需要克隆转发消息");
|
||||||
|
for (const [index, msg] of nodeMsgArray.entries()) {
|
||||||
|
if (msg.peerUid !== selfInfo.uid) {
|
||||||
|
const cloneMsg = await this.cloneMsg(msg)
|
||||||
|
if (cloneMsg) {
|
||||||
|
nodeMsgIds[index] = cloneMsg.msgId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// elements之间用换行符分隔
|
||||||
|
// let _sendForwardElements: SendMessageElement[] = []
|
||||||
|
// for(let i = 0; i < sendForwardElements.length; i++){
|
||||||
|
// _sendForwardElements.push(sendForwardElements[i])
|
||||||
|
// _sendForwardElements.push(SendMsgElementConstructor.text("\n\n"))
|
||||||
|
// }
|
||||||
|
// const nodeMsg = await NTQQApi.sendMsg(selfPeer, _sendForwardElements, true);
|
||||||
|
// nodeIds.push(nodeMsg.msgId)
|
||||||
|
// await sleep(500);
|
||||||
|
// 开发转发
|
||||||
|
try {
|
||||||
|
log("开发转发", nodeMsgIds)
|
||||||
|
return await NTQQMsgApi.multiForwardMsg(srcPeer, destPeer, nodeMsgIds)
|
||||||
|
} catch (e) {
|
||||||
|
log("forward failed", e)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private genMusicElement(url: string, audio: string, title: string, content: string, image: string): SendArkElement {
|
||||||
|
const musicJson = {
|
||||||
|
app: 'com.tencent.structmsg',
|
||||||
|
config: {
|
||||||
|
ctime: 1709689928,
|
||||||
|
forward: 1,
|
||||||
|
token: '5c1e4905f926dd3a64a4bd3841460351',
|
||||||
|
type: 'normal'
|
||||||
|
},
|
||||||
|
extra: {app_type: 1, appid: 100497308, uin: selfInfo.uin},
|
||||||
|
meta: {
|
||||||
|
news: {
|
||||||
|
action: '',
|
||||||
|
android_pkg_name: '',
|
||||||
|
app_type: 1,
|
||||||
|
appid: 100497308,
|
||||||
|
ctime: 1709689928,
|
||||||
|
desc: content || title,
|
||||||
|
jumpUrl: url,
|
||||||
|
musicUrl: audio,
|
||||||
|
preview: image,
|
||||||
|
source_icon: 'https://p.qpic.cn/qqconnect/0/app_100497308_1626060999/100?max-age=2592000&t=0',
|
||||||
|
source_url: '',
|
||||||
|
tag: 'QQ音乐',
|
||||||
|
title: title,
|
||||||
|
uin: selfInfo.uin,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
prompt: content || title,
|
||||||
|
ver: '0.0.0.1',
|
||||||
|
view: 'news'
|
||||||
|
}
|
||||||
|
|
||||||
|
return SendMsgElementConstructor.ark(musicJson)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SendMsg
|
@@ -1,6 +1,6 @@
|
|||||||
import SendMsg from "./SendMsg";
|
import SendMsg from "./SendMsg";
|
||||||
import {ActionName, BaseCheckResult} from "./types";
|
import {ActionName, BaseCheckResult} from "../types";
|
||||||
import {OB11PostSendMsg} from "../types";
|
import {OB11PostSendMsg} from "../../types";
|
||||||
|
|
||||||
class SendPrivateMsg extends SendMsg {
|
class SendPrivateMsg extends SendMsg {
|
||||||
actionName = ActionName.SendPrivateMsg
|
actionName = ActionName.SendPrivateMsg
|
@@ -1,4 +1,4 @@
|
|||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import CanSendRecord from "./CanSendRecord";
|
import CanSendRecord from "./CanSendRecord";
|
||||||
|
|
||||||
interface ReturnType {
|
interface ReturnType {
|
@@ -1,5 +1,5 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
interface ReturnType {
|
interface ReturnType {
|
||||||
yes: boolean
|
yes: boolean
|
105
src/onebot11/action/system/CleanCache.ts
Normal file
105
src/onebot11/action/system/CleanCache.ts
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import fs from "fs";
|
||||||
|
import Path from "path";
|
||||||
|
import {
|
||||||
|
ChatType,
|
||||||
|
ChatCacheListItemBasic,
|
||||||
|
CacheFileType
|
||||||
|
} from '../../../ntqqapi/types';
|
||||||
|
import {dbUtil} from "../../../common/db";
|
||||||
|
import {NTQQFileApi, NTQQFileCacheApi} from "../../../ntqqapi/api/file";
|
||||||
|
|
||||||
|
export default class CleanCache extends BaseAction<void, void> {
|
||||||
|
actionName = ActionName.CleanCache
|
||||||
|
|
||||||
|
protected _handle(): Promise<void> {
|
||||||
|
return new Promise<void>(async (res, rej) => {
|
||||||
|
try {
|
||||||
|
// dbUtil.clearCache();
|
||||||
|
const cacheFilePaths: string[] = [];
|
||||||
|
|
||||||
|
await NTQQFileCacheApi.setCacheSilentScan(false);
|
||||||
|
|
||||||
|
cacheFilePaths.push((await NTQQFileCacheApi.getHotUpdateCachePath()));
|
||||||
|
cacheFilePaths.push((await NTQQFileCacheApi.getDesktopTmpPath()));
|
||||||
|
(await NTQQFileCacheApi.getCacheSessionPathList()).forEach(e => cacheFilePaths.push(e.value));
|
||||||
|
|
||||||
|
// await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
|
||||||
|
const cacheScanResult = await NTQQFileCacheApi.scanCache();
|
||||||
|
const cacheSize = parseInt(cacheScanResult.size[6]);
|
||||||
|
|
||||||
|
if (cacheScanResult.result !== 0) {
|
||||||
|
throw('Something went wrong while scanning cache. Code: ' + cacheScanResult.result);
|
||||||
|
}
|
||||||
|
|
||||||
|
await NTQQFileCacheApi.setCacheSilentScan(true);
|
||||||
|
if (cacheSize > 0 && cacheFilePaths.length > 2) { // 存在缓存文件且大小不为 0 时执行清理动作
|
||||||
|
// await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
|
||||||
|
deleteCachePath(cacheFilePaths);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取聊天记录列表
|
||||||
|
// NOTE: 以防有人不需要删除聊天记录,暂时先注释掉,日后加个开关
|
||||||
|
// const privateChatCache = await getCacheList(ChatType.friend); // 私聊消息
|
||||||
|
// const groupChatCache = await getCacheList(ChatType.group); // 群聊消息
|
||||||
|
// const chatCacheList = [ ...privateChatCache, ...groupChatCache ];
|
||||||
|
const chatCacheList: ChatCacheListItemBasic[] = [];
|
||||||
|
|
||||||
|
// 获取聊天缓存文件列表
|
||||||
|
const cacheFileList: string[] = [];
|
||||||
|
|
||||||
|
for (const name in CacheFileType) {
|
||||||
|
if (!isNaN(parseInt(name))) continue;
|
||||||
|
|
||||||
|
const fileTypeAny: any = CacheFileType[name];
|
||||||
|
const fileType: CacheFileType = fileTypeAny;
|
||||||
|
|
||||||
|
cacheFileList.push(...(await NTQQFileCacheApi.getFileCacheInfo(fileType)).infos.map(file => file.fileKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 一并清除
|
||||||
|
await NTQQFileCacheApi.clearChatCache(chatCacheList, cacheFileList);
|
||||||
|
res();
|
||||||
|
} catch(e) {
|
||||||
|
console.error('清理缓存时发生了错误');
|
||||||
|
rej(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteCachePath(pathList: string[]) {
|
||||||
|
const emptyPath = (path: string) => {
|
||||||
|
if (!fs.existsSync(path)) return;
|
||||||
|
const files = fs.readdirSync(path);
|
||||||
|
files.forEach(file => {
|
||||||
|
const filePath = Path.resolve(path, file);
|
||||||
|
const stats = fs.statSync(filePath);
|
||||||
|
if (stats.isDirectory()) emptyPath(filePath);
|
||||||
|
else fs.unlinkSync(filePath);
|
||||||
|
});
|
||||||
|
fs.rmdirSync(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const path of pathList) {
|
||||||
|
emptyPath(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCacheList(type: ChatType) { // NOTE: 做这个方法主要是因为目前还不支持针对频道消息的清理
|
||||||
|
return new Promise<Array<ChatCacheListItemBasic>>((res, rej) => {
|
||||||
|
NTQQFileCacheApi.getChatCacheList(type, 1000, 0)
|
||||||
|
.then(data => {
|
||||||
|
const list = data.infos.filter(e => e.chatType === type && parseInt(e.basicChatCacheInfo.chatSize) > 0);
|
||||||
|
const result = list.map(e => {
|
||||||
|
const result = { ...e.basicChatCacheInfo };
|
||||||
|
result.chatType = type;
|
||||||
|
result.isChecked = true;
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
res(result);
|
||||||
|
})
|
||||||
|
.catch(e => rej(e));
|
||||||
|
});
|
||||||
|
}
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11User} from '../types';
|
import {OB11User} from '../../types';
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import {selfInfo} from "../../common/data";
|
import {selfInfo} from "../../../common/data";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
|
|
||||||
class GetLoginInfo extends BaseAction<null, OB11User> {
|
class GetLoginInfo extends BaseAction<null, OB11User> {
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {OB11Status} from "../types";
|
import {OB11Status} from "../../types";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {selfInfo} from "../../common/data";
|
import {selfInfo} from "../../../common/data";
|
||||||
|
|
||||||
|
|
||||||
export default class GetStatus extends BaseAction<any, OB11Status> {
|
export default class GetStatus extends BaseAction<any, OB11Status> {
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {OB11Version} from "../types";
|
import {OB11Version} from "../../types";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {version} from "../../version";
|
import {version} from "../../../version";
|
||||||
|
|
||||||
export default class GetVersionInfo extends BaseAction<any, OB11Version> {
|
export default class GetVersionInfo extends BaseAction<any, OB11Version> {
|
||||||
actionName = ActionName.GetVersionInfo
|
actionName = ActionName.GetVersionInfo
|
@@ -14,7 +14,14 @@ export interface InvalidCheckResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum ActionName {
|
export enum ActionName {
|
||||||
|
// llonebot
|
||||||
|
GetGroupIgnoreAddRequest = "get_group_ignore_add_request",
|
||||||
|
SetQQAvatar = "set_qq_avatar",
|
||||||
|
GetConfig = "get_config",
|
||||||
|
SetConfig = "set_config",
|
||||||
Debug = "llonebot_debug",
|
Debug = "llonebot_debug",
|
||||||
|
GetFile = "get_file",
|
||||||
|
// onebot 11
|
||||||
SendLike = "send_like",
|
SendLike = "send_like",
|
||||||
GetLoginInfo = "get_login_info",
|
GetLoginInfo = "get_login_info",
|
||||||
GetFriendList = "get_friend_list",
|
GetFriendList = "get_friend_list",
|
||||||
@@ -42,10 +49,14 @@ export enum ActionName {
|
|||||||
SetGroupName = "set_group_name",
|
SetGroupName = "set_group_name",
|
||||||
GetImage = "get_image",
|
GetImage = "get_image",
|
||||||
GetRecord = "get_record",
|
GetRecord = "get_record",
|
||||||
|
CleanCache = "clean_cache",
|
||||||
// 以下为go-cqhttp api
|
// 以下为go-cqhttp api
|
||||||
GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg",
|
GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg",
|
||||||
GoCQHTTP_SendPrivateForwardMsg = "send_private_forward_msg",
|
GoCQHTTP_SendPrivateForwardMsg = "send_private_forward_msg",
|
||||||
GoCQHTTP_GetStrangerInfo = "get_stranger_info",
|
GoCQHTTP_GetStrangerInfo = "get_stranger_info",
|
||||||
GetGuildList = "get_guild_list",
|
GetGuildList = "get_guild_list",
|
||||||
GoCQHTTP_MarkMsgAsRead = "mark_msg_as_read",
|
GoCQHTTP_MarkMsgAsRead = "mark_msg_as_read",
|
||||||
|
GoCQHTTP_UploadGroupFile = "upload_group_file",
|
||||||
|
GoCQHTTP_DownloadFile = "download_file",
|
||||||
|
GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history",
|
||||||
}
|
}
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11User} from '../types';
|
import {OB11User} from '../../types';
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import {friends} from "../../common/data";
|
import {friends} from "../../../common/data";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
|
|
||||||
class GetFriendList extends BaseAction<null, OB11User[]> {
|
class GetFriendList extends BaseAction<null, OB11User[]> {
|
@@ -1,8 +1,8 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {getFriend, getUidByUin, uidMaps} from "../../common/data";
|
import {getFriend, getUidByUin, uidMaps} from "../../../common/data";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {ActionName} from "../types";
|
||||||
import {ActionName} from "./types";
|
import {NTQQFriendApi} from "../../../ntqqapi/api/friend";
|
||||||
import {log} from "../../common/utils";
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
user_id: number,
|
user_id: number,
|
||||||
@@ -23,7 +23,7 @@ export default class SendLike extends BaseAction<Payload, null> {
|
|||||||
} else {
|
} else {
|
||||||
uid = friend.uid
|
uid = friend.uid
|
||||||
}
|
}
|
||||||
let result = await NTQQApi.likeFriend(uid, parseInt(payload.times?.toString()) || 1);
|
let result = await NTQQFriendApi.likeFriend(uid, parseInt(payload.times?.toString()) || 1);
|
||||||
if (result.result !== 0) {
|
if (result.result !== 0) {
|
||||||
throw result.errMsg
|
throw result.errMsg
|
||||||
}
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {ActionName} from "../types";
|
||||||
import {ActionName} from "./types";
|
import {NTQQFriendApi} from "../../../ntqqapi/api/friend";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
flag: string,
|
flag: string,
|
||||||
@@ -12,7 +12,8 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName.SetFriendAddRequest;
|
actionName = ActionName.SetFriendAddRequest;
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
await NTQQApi.handleFriendRequest(parseInt(payload.flag), payload.approve)
|
const approve = payload.approve.toString() === "true";
|
||||||
|
await NTQQFriendApi.handleFriendRequest(parseInt(payload.flag), approve)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -8,13 +8,35 @@ import {
|
|||||||
OB11User,
|
OB11User,
|
||||||
OB11UserSex
|
OB11UserSex
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import {AtType, ChatType, Group, GroupMember, IMAGE_HTTP_HOST, RawMessage, SelfInfo, User} from '../ntqqapi/types';
|
import {
|
||||||
|
AtType,
|
||||||
|
ChatType,
|
||||||
|
GrayTipElementSubType,
|
||||||
|
Group,
|
||||||
|
GroupMember,
|
||||||
|
IMAGE_HTTP_HOST,
|
||||||
|
RawMessage,
|
||||||
|
SelfInfo,
|
||||||
|
Sex,
|
||||||
|
TipGroupElementType,
|
||||||
|
User, VideoElement
|
||||||
|
} from '../ntqqapi/types';
|
||||||
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
||||||
import {getConfigUtil, log} from "../common/utils";
|
|
||||||
import {NTQQApi} from "../ntqqapi/ntcall";
|
|
||||||
import {EventType} from "./event/OB11BaseEvent";
|
import {EventType} from "./event/OB11BaseEvent";
|
||||||
import {encodeCQCode} from "./cqcode";
|
import {encodeCQCode} from "./cqcode";
|
||||||
import {dbUtil} from "../common/db";
|
import {dbUtil} from "../common/db";
|
||||||
|
import {OB11GroupIncreaseEvent} from "./event/notice/OB11GroupIncreaseEvent";
|
||||||
|
import {OB11GroupBanEvent} from "./event/notice/OB11GroupBanEvent";
|
||||||
|
import {OB11GroupUploadNoticeEvent} from "./event/notice/OB11GroupUploadNoticeEvent";
|
||||||
|
import {OB11GroupNoticeEvent} from "./event/notice/OB11GroupNoticeEvent";
|
||||||
|
import {NTQQUserApi} from "../ntqqapi/api/user";
|
||||||
|
import {NTQQFileApi} from "../ntqqapi/api/file";
|
||||||
|
import {calcQQLevel} from "../common/utils/qqlevel";
|
||||||
|
import {log} from "../common/utils/log";
|
||||||
|
import {sleep} from "../common/utils/helper";
|
||||||
|
import {getConfigUtil} from "../common/config";
|
||||||
|
import {OB11GroupTitleEvent} from "./event/notice/OB11GroupTitleEvent";
|
||||||
|
import {OB11GroupCardEvent} from "./event/notice/OB11GroupCardEvent";
|
||||||
|
|
||||||
|
|
||||||
export class OB11Constructor {
|
export class OB11Constructor {
|
||||||
@@ -27,7 +49,7 @@ export class OB11Constructor {
|
|||||||
user_id: parseInt(msg.senderUin),
|
user_id: parseInt(msg.senderUin),
|
||||||
time: parseInt(msg.msgTime) || Date.now(),
|
time: parseInt(msg.msgTime) || Date.now(),
|
||||||
message_id: msg.msgShortId,
|
message_id: msg.msgShortId,
|
||||||
real_id: msg.msgId,
|
real_id: msg.msgShortId,
|
||||||
message_type: msg.chatType == ChatType.group ? "group" : "private",
|
message_type: msg.chatType == ChatType.group ? "group" : "private",
|
||||||
sender: {
|
sender: {
|
||||||
user_id: parseInt(msg.senderUin),
|
user_id: parseInt(msg.senderUin),
|
||||||
@@ -77,7 +99,7 @@ export class OB11Constructor {
|
|||||||
let atUid = element.textElement.atNtUid
|
let atUid = element.textElement.atNtUid
|
||||||
let atQQ = element.textElement.atUid
|
let atQQ = element.textElement.atUid
|
||||||
if (!atQQ || atQQ === "0") {
|
if (!atQQ || atQQ === "0") {
|
||||||
const atMember = await getGroupMember(msg.peerUin, null, atUid)
|
const atMember = await getGroupMember(msg.peerUin, atUid)
|
||||||
if (atMember) {
|
if (atMember) {
|
||||||
atQQ = atMember.uin
|
atQQ = atMember.uin
|
||||||
}
|
}
|
||||||
@@ -97,7 +119,7 @@ export class OB11Constructor {
|
|||||||
} else if (element.replyElement) {
|
} else if (element.replyElement) {
|
||||||
message_data["type"] = "reply"
|
message_data["type"] = "reply"
|
||||||
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
||||||
try{
|
try {
|
||||||
const replyMsg = await dbUtil.getMsgBySeqId(element.replyElement.replayMsgSeq)
|
const replyMsg = await dbUtil.getMsgBySeqId(element.replyElement.replayMsgSeq)
|
||||||
// log("找到回复消息", replyMsg.msgShortId, replyMsg.msgId)
|
// log("找到回复消息", replyMsg.msgShortId, replyMsg.msgId)
|
||||||
if (replyMsg) {
|
if (replyMsg) {
|
||||||
@@ -105,7 +127,7 @@ export class OB11Constructor {
|
|||||||
} else {
|
} else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}catch (e) {
|
} catch (e) {
|
||||||
log("获取不到引用的消息", e.stack, element.replyElement.replayMsgSeq)
|
log("获取不到引用的消息", e.stack, element.replyElement.replayMsgSeq)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,10 +138,9 @@ export class OB11Constructor {
|
|||||||
// message_data["data"]["path"] = element.picElement.sourcePath
|
// message_data["data"]["path"] = element.picElement.sourcePath
|
||||||
const url = element.picElement.originImageUrl
|
const url = element.picElement.originImageUrl
|
||||||
const fileMd5 = element.picElement.md5HexStr
|
const fileMd5 = element.picElement.md5HexStr
|
||||||
if (url){
|
if (url) {
|
||||||
message_data["data"]["url"] = IMAGE_HTTP_HOST + url
|
message_data["data"]["url"] = IMAGE_HTTP_HOST + url
|
||||||
}
|
} else if (fileMd5 && element.picElement.fileUuid.indexOf("_") === -1) { // fileuuid有下划线的是Linux发送的,这个url是另外的格式,目前尚未得知如何组装
|
||||||
else if (fileMd5 && element.picElement.fileUuid.indexOf("_") === -1){ // fileuuid有下划线的是Linux发送的,这个url是另外的格式,目前尚未得知如何组装
|
|
||||||
message_data["data"]["url"] = `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${fileMd5.toUpperCase()}/0`
|
message_data["data"]["url"] = `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${fileMd5.toUpperCase()}/0`
|
||||||
}
|
}
|
||||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||||
@@ -130,41 +151,31 @@ export class OB11Constructor {
|
|||||||
fileSize: element.picElement.fileSize.toString(),
|
fileSize: element.picElement.fileSize.toString(),
|
||||||
url: message_data["data"]["url"],
|
url: message_data["data"]["url"],
|
||||||
downloadFunc: async () => {
|
downloadFunc: async () => {
|
||||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
element.elementId, element.picElement.thumbPath?.get(0) || "", element.picElement.sourcePath)
|
element.elementId, element.picElement.thumbPath?.get(0) || "", element.picElement.sourcePath)
|
||||||
}
|
}
|
||||||
}).then()
|
}).then()
|
||||||
// 不在自动下载图片
|
// 不在自动下载图片
|
||||||
|
|
||||||
} else if (element.videoElement) {
|
} else if (element.videoElement || element.fileElement) {
|
||||||
message_data["type"] = OB11MessageDataType.video;
|
const videoOrFileElement = element.videoElement || element.fileElement
|
||||||
message_data["data"]["file"] = element.videoElement.fileName
|
const ob11MessageDataType = element.videoElement ? OB11MessageDataType.video : OB11MessageDataType.file
|
||||||
message_data["data"]["path"] = element.videoElement.filePath
|
message_data["type"] = ob11MessageDataType;
|
||||||
// message_data["data"]["file_id"] = element.videoElement.fileUuid
|
message_data["data"]["file"] = videoOrFileElement.fileName
|
||||||
message_data["data"]["file_size"] = element.videoElement.fileSize
|
message_data["data"]["path"] = videoOrFileElement.filePath
|
||||||
dbUtil.addFileCache(element.videoElement.fileName, {
|
message_data["data"]["file_id"] = videoOrFileElement.fileUuid
|
||||||
fileName: element.videoElement.fileName,
|
message_data["data"]["file_size"] = videoOrFileElement.fileSize
|
||||||
filePath: element.videoElement.filePath,
|
dbUtil.addFileCache(videoOrFileElement.fileUuid, {
|
||||||
fileSize: element.videoElement.fileSize,
|
msgId: msg.msgId,
|
||||||
|
fileName: videoOrFileElement.fileName,
|
||||||
|
filePath: videoOrFileElement.filePath,
|
||||||
|
fileSize: videoOrFileElement.fileSize,
|
||||||
downloadFunc: async () => {
|
downloadFunc: async () => {
|
||||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQFileApi.downloadMedia(
|
||||||
element.elementId, element.videoElement.thumbPath.get(0), element.videoElement.filePath)
|
msg.msgId, msg.chatType, msg.peerUid,
|
||||||
}
|
element.elementId,
|
||||||
}).then()
|
ob11MessageDataType == OB11MessageDataType.video ? (videoOrFileElement as VideoElement).thumbPath.get(0) : null,
|
||||||
// 怎么拿到url呢
|
videoOrFileElement.filePath)
|
||||||
} else if (element.fileElement) {
|
|
||||||
message_data["type"] = OB11MessageDataType.file;
|
|
||||||
message_data["data"]["file"] = element.fileElement.fileName
|
|
||||||
// message_data["data"]["path"] = element.fileElement.filePath
|
|
||||||
// message_data["data"]["file_id"] = element.fileElement.fileUuid
|
|
||||||
message_data["data"]["file_size"] = element.fileElement.fileSize
|
|
||||||
dbUtil.addFileCache(element.fileElement.fileName, {
|
|
||||||
fileName: element.fileElement.fileName,
|
|
||||||
filePath: element.fileElement.filePath,
|
|
||||||
fileSize: element.fileElement.fileSize,
|
|
||||||
downloadFunc: async () => {
|
|
||||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
|
||||||
element.elementId, null, element.fileElement.filePath)
|
|
||||||
}
|
}
|
||||||
}).then()
|
}).then()
|
||||||
// 怎么拿到url呢
|
// 怎么拿到url呢
|
||||||
@@ -193,30 +204,6 @@ export class OB11Constructor {
|
|||||||
message_data["type"] = OB11MessageDataType.face;
|
message_data["type"] = OB11MessageDataType.face;
|
||||||
message_data["data"]["id"] = element.faceElement.faceIndex.toString();
|
message_data["data"]["id"] = element.faceElement.faceIndex.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (message_data.data.file) {
|
|
||||||
// let filePath: string = message_data.data.file;
|
|
||||||
// if (!enableLocalFile2Url) {
|
|
||||||
// message_data.data.file = "file://" + filePath
|
|
||||||
// } else { // 不使用本地路径
|
|
||||||
// const ignoreTypes = [OB11MessageDataType.file, OB11MessageDataType.video]
|
|
||||||
// if (!ignoreTypes.includes(message_data.type)) {
|
|
||||||
// if (message_data.data.url && !message_data.data.url.startsWith(IMAGE_HTTP_HOST + "/download")) {
|
|
||||||
// message_data.data.file = message_data.data.url
|
|
||||||
// } else {
|
|
||||||
// let { err, data } = await file2base64(filePath);
|
|
||||||
// if (err) {
|
|
||||||
// log("文件转base64失败", filePath, err)
|
|
||||||
// } else {
|
|
||||||
// message_data.data.file = "base64://" + data
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// message_data.data.file = "file://" + filePath
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (message_data.type !== "unknown" && message_data.data) {
|
if (message_data.type !== "unknown" && message_data.data) {
|
||||||
const cqCode = encodeCQCode(message_data);
|
const cqCode = encodeCQCode(message_data);
|
||||||
if (messagePostFormat === 'string') {
|
if (messagePostFormat === 'string') {
|
||||||
@@ -230,19 +217,136 @@ export class OB11Constructor {
|
|||||||
return resMsg;
|
return resMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async GroupEvent(msg: RawMessage): Promise<OB11GroupNoticeEvent> {
|
||||||
|
if (msg.chatType !== ChatType.group) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (msg.senderUin){
|
||||||
|
let member = await getGroupMember(msg.peerUid, msg.senderUin);
|
||||||
|
if (member && member.cardName !== msg.sendMemberName) {
|
||||||
|
member.cardName = msg.sendMemberName;
|
||||||
|
return new OB11GroupCardEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), msg.sendMemberName, member.cardName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// log("group msg", msg);
|
||||||
|
for (let element of msg.elements) {
|
||||||
|
const grayTipElement = element.grayTipElement
|
||||||
|
const groupElement = grayTipElement?.groupElement
|
||||||
|
if (groupElement) {
|
||||||
|
// log("收到群提示消息", groupElement)
|
||||||
|
if (groupElement.type == TipGroupElementType.memberIncrease) {
|
||||||
|
log("收到群成员增加消息", groupElement)
|
||||||
|
await sleep(1000);
|
||||||
|
const member = await getGroupMember(msg.peerUid, groupElement.memberUid);
|
||||||
|
let memberUin = member?.uin;
|
||||||
|
if (!memberUin) {
|
||||||
|
memberUin = (await NTQQUserApi.getUserDetailInfo(groupElement.memberUid)).uin
|
||||||
|
}
|
||||||
|
// log("获取新群成员QQ", memberUin)
|
||||||
|
const adminMember = await getGroupMember(msg.peerUid, groupElement.adminUid);
|
||||||
|
// log("获取同意新成员入群的管理员", adminMember)
|
||||||
|
if (memberUin) {
|
||||||
|
const operatorUin = adminMember?.uin || memberUin
|
||||||
|
let event = new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(operatorUin));
|
||||||
|
// log("构造群增加事件", event)
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
} else if (groupElement.type === TipGroupElementType.ban) {
|
||||||
|
log("收到群群员禁言提示", groupElement)
|
||||||
|
const memberUid = groupElement.shutUp.member.uid
|
||||||
|
const adminUid = groupElement.shutUp.admin.uid
|
||||||
|
let memberUin: string = ""
|
||||||
|
let duration = parseInt(groupElement.shutUp.duration)
|
||||||
|
let sub_type: "ban" | "lift_ban" = duration > 0 ? "ban" : "lift_ban"
|
||||||
|
if (memberUid) {
|
||||||
|
memberUin = (await getGroupMember(msg.peerUid, memberUid))?.uin || (await NTQQUserApi.getUserDetailInfo(memberUid))?.uin
|
||||||
|
} else {
|
||||||
|
memberUin = "0"; // 0表示全员禁言
|
||||||
|
if (duration > 0) {
|
||||||
|
duration = -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const adminUin = (await getGroupMember(msg.peerUid, adminUid))?.uin || (await NTQQUserApi.getUserDetailInfo(adminUid))?.uin
|
||||||
|
if (memberUin && adminUin) {
|
||||||
|
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (element.fileElement) {
|
||||||
|
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), {
|
||||||
|
id: element.fileElement.fileUuid,
|
||||||
|
name: element.fileElement.fileName,
|
||||||
|
size: parseInt(element.fileElement.fileSize),
|
||||||
|
busid: element.fileElement.fileBizId || 0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grayTipElement) {
|
||||||
|
if (grayTipElement.subElementType == GrayTipElementSubType.INVITE_NEW_MEMBER) {
|
||||||
|
log("收到新人被邀请进群消息", grayTipElement)
|
||||||
|
const xmlElement = grayTipElement.xmlElement
|
||||||
|
if (xmlElement?.content) {
|
||||||
|
const regex = /jp="(\d+)"/g;
|
||||||
|
|
||||||
|
let matches = [];
|
||||||
|
let match = null
|
||||||
|
|
||||||
|
while ((match = regex.exec(xmlElement.content)) !== null) {
|
||||||
|
matches.push(match[1]);
|
||||||
|
}
|
||||||
|
if (matches.length === 2) {
|
||||||
|
const [inviter, invitee] = matches;
|
||||||
|
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (grayTipElement.subElementType == GrayTipElementSubType.MEMBER_NEW_TITLE) {
|
||||||
|
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr)
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
align: 'center',
|
||||||
|
items: [
|
||||||
|
{ txt: '恭喜', type: 'nor' },
|
||||||
|
{
|
||||||
|
col: '3',
|
||||||
|
jp: '5',
|
||||||
|
param: ["QQ号"],
|
||||||
|
txt: '林雨辰',
|
||||||
|
type: 'url'
|
||||||
|
},
|
||||||
|
{ txt: '获得群主授予的', type: 'nor' },
|
||||||
|
{
|
||||||
|
col: '3',
|
||||||
|
jp: '',
|
||||||
|
txt: '好好好',
|
||||||
|
type: 'url'
|
||||||
|
},
|
||||||
|
{ txt: '头衔', type: 'nor' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
* */
|
||||||
|
const memberUin = json.items[1].param[0]
|
||||||
|
const title = json.items[3].txt
|
||||||
|
log("收到群成员新头衔消息", json)
|
||||||
|
return new OB11GroupTitleEvent(parseInt(msg.peerUid), parseInt(memberUin), title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static friend(friend: User): OB11User {
|
static friend(friend: User): OB11User {
|
||||||
return {
|
return {
|
||||||
user_id: parseInt(friend.uin),
|
user_id: parseInt(friend.uin),
|
||||||
nickname: friend.nick,
|
nickname: friend.nick,
|
||||||
remark: friend.remark
|
remark: friend.remark,
|
||||||
|
sex: OB11Constructor.sex(friend.sex),
|
||||||
|
level: friend.qqLevel && calcQQLevel(friend.qqLevel) || 0
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static selfInfo(selfInfo: SelfInfo): OB11User {
|
static selfInfo(selfInfo: SelfInfo): OB11User {
|
||||||
return {
|
return {
|
||||||
user_id: parseInt(selfInfo.uin),
|
user_id: parseInt(selfInfo.uin),
|
||||||
nickname: selfInfo.nick
|
nickname: selfInfo.nick,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,16 +362,26 @@ export class OB11Constructor {
|
|||||||
}[role]
|
}[role]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sex(sex: Sex): OB11UserSex {
|
||||||
|
const sexMap = {
|
||||||
|
[Sex.male]: OB11UserSex.male,
|
||||||
|
[Sex.female]: OB11UserSex.female,
|
||||||
|
[Sex.unknown]: OB11UserSex.unknown
|
||||||
|
}
|
||||||
|
return sexMap[sex] || OB11UserSex.unknown
|
||||||
|
}
|
||||||
|
|
||||||
static groupMember(group_id: string, member: GroupMember): OB11GroupMember {
|
static groupMember(group_id: string, member: GroupMember): OB11GroupMember {
|
||||||
return {
|
return {
|
||||||
group_id: parseInt(group_id),
|
group_id: parseInt(group_id),
|
||||||
user_id: parseInt(member.uin),
|
user_id: parseInt(member.uin),
|
||||||
nickname: member.nick,
|
nickname: member.nick,
|
||||||
card: member.cardName,
|
card: member.cardName,
|
||||||
sex: OB11UserSex.unknown,
|
sex: OB11Constructor.sex(member.sex),
|
||||||
age: 0,
|
age: 0,
|
||||||
area: "",
|
area: "",
|
||||||
level: 0,
|
level: 0,
|
||||||
|
qq_level: member.qqLevel && calcQQLevel(member.qqLevel) || 0,
|
||||||
join_time: 0, // 暂时没法获取
|
join_time: 0, // 暂时没法获取
|
||||||
last_sent_time: 0, // 暂时没法获取
|
last_sent_time: 0, // 暂时没法获取
|
||||||
title_expire_time: 0,
|
title_expire_time: 0,
|
||||||
@@ -279,6 +393,19 @@ export class OB11Constructor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static stranger(user: User): OB11User {
|
||||||
|
return {
|
||||||
|
...user,
|
||||||
|
user_id: parseInt(user.uin),
|
||||||
|
nickname: user.nick,
|
||||||
|
sex: OB11Constructor.sex(user.sex),
|
||||||
|
age: 0,
|
||||||
|
qid: user.qid,
|
||||||
|
login_days: 0,
|
||||||
|
level: user.qqLevel && calcQQLevel(user.qqLevel) || 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static groupMembers(group: Group): OB11GroupMember[] {
|
static groupMembers(group: Group): OB11GroupMember[] {
|
||||||
log("construct ob11 group members", group)
|
log("construct ob11 group members", group)
|
||||||
return group.members.map(m => OB11Constructor.groupMember(group.groupCode, m))
|
return group.members.map(m => OB11Constructor.groupMember(group.groupCode, m))
|
||||||
|
@@ -46,15 +46,22 @@ export function decodeCQCode(source: string): OB11MessageData[] {
|
|||||||
|
|
||||||
|
|
||||||
export function encodeCQCode(data: OB11MessageData) {
|
export function encodeCQCode(data: OB11MessageData) {
|
||||||
const CQCodeEscape = (text: string) => {
|
const CQCodeEscapeText = (text: string) => {
|
||||||
return text.replace(/\[/g, '[')
|
return text.replace(/\&/g, '&')
|
||||||
|
.replace(/\[/g, '[')
|
||||||
|
.replace(/\]/g, ']')
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const CQCodeEscape = (text: string) => {
|
||||||
|
return text.replace(/\&/g, '&')
|
||||||
|
.replace(/\[/g, '[')
|
||||||
.replace(/\]/g, ']')
|
.replace(/\]/g, ']')
|
||||||
.replace(/\&/g, '&')
|
|
||||||
.replace(/,/g, ',');
|
.replace(/,/g, ',');
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.type === 'text') {
|
if (data.type === 'text') {
|
||||||
return CQCodeEscape(data.data.text);
|
return CQCodeEscapeText(data.data.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = '[CQ:' + data.type;
|
let result = '[CQ:' + data.type;
|
||||||
@@ -68,4 +75,4 @@ export function encodeCQCode(data: OB11MessageData) {
|
|||||||
|
|
||||||
// const result = parseCQCode("[CQ:at,qq=114514]早上好啊[CQ:image,file=http://baidu.com/1.jpg,type=show,id=40004]")
|
// const result = parseCQCode("[CQ:at,qq=114514]早上好啊[CQ:image,file=http://baidu.com/1.jpg,type=show,id=40004]")
|
||||||
// const result = parseCQCode("好好好")
|
// const result = parseCQCode("好好好")
|
||||||
// console.log(JSON.stringify(result))
|
// console.log(JSON.stringify(result))
|
||||||
|
17
src/onebot11/event/notice/OB11GroupBanEvent.ts
Normal file
17
src/onebot11/event/notice/OB11GroupBanEvent.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||||
|
|
||||||
|
export class OB11GroupBanEvent extends OB11GroupNoticeEvent {
|
||||||
|
notice_type = "group_ban";
|
||||||
|
operator_id: number;
|
||||||
|
duration: number;
|
||||||
|
sub_type: "ban" | "lift_ban";
|
||||||
|
|
||||||
|
constructor(groupId: number, userId: number, operatorId: number, duration: number, sub_type: "ban" | "lift_ban") {
|
||||||
|
super();
|
||||||
|
this.group_id = groupId;
|
||||||
|
this.operator_id = operatorId;
|
||||||
|
this.user_id = userId;
|
||||||
|
this.duration = duration;
|
||||||
|
this.sub_type = sub_type;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user