mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
62 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
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 |
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 4,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot v3.16.1",
|
"name": "LLOneBot v3.18.3",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
||||||
"version": "3.16.1",
|
"version": "3.18.3",
|
||||||
"icon": "./icon.jpg",
|
"icon": "./icon.jpg",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
254
package-lock.json
generated
254
package-lock.json
generated
@@ -9,12 +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",
|
||||||
"node-stream-zip": "^1.15.0",
|
"silk-wasm": "^3.2.4",
|
||||||
"silk-wasm": "^3.2.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"
|
||||||
@@ -551,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",
|
||||||
@@ -2151,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",
|
||||||
@@ -2281,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",
|
||||||
@@ -2515,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",
|
||||||
@@ -2559,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",
|
||||||
@@ -2813,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"
|
||||||
}
|
}
|
||||||
@@ -3636,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",
|
||||||
@@ -3738,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",
|
||||||
@@ -3763,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",
|
||||||
@@ -3859,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",
|
||||||
@@ -4859,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",
|
||||||
@@ -4931,18 +5066,6 @@
|
|||||||
"integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==",
|
"integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/node-stream-zip": {
|
|
||||||
"version": "1.15.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.15.0.tgz",
|
|
||||||
"integrity": "sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.12.0"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "github",
|
|
||||||
"url": "https://github.com/sponsors/antelle"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/normalize-url": {
|
"node_modules/normalize-url": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
||||||
@@ -5052,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"
|
||||||
}
|
}
|
||||||
@@ -5165,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",
|
||||||
@@ -5232,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",
|
||||||
@@ -5257,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"
|
||||||
@@ -5770,9 +5895,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/silk-wasm": {
|
"node_modules/silk-wasm": {
|
||||||
"version": "3.2.3",
|
"version": "3.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.2.4.tgz",
|
||||||
"integrity": "sha512-zZ3hgMpiPR6cFnKvCPgPpCwx6n5RoJCbEGIFlge2kAxAmgzBTf0b2F2xIPG5W4obUhQPQXXTTH074eGZJK01xw=="
|
"integrity": "sha512-oBkXmdIRl7cyzpoXEeEVN7v1M2yCnH1/bN8oANoYTvCqbYa5lM/CGJP47DYbpUFVO9PUpm58KP/HZaVzt4J6jw=="
|
||||||
},
|
},
|
||||||
"node_modules/slash": {
|
"node_modules/slash": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
@@ -5833,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",
|
||||||
@@ -5959,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",
|
||||||
@@ -5985,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",
|
||||||
@@ -6528,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",
|
||||||
@@ -6551,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",
|
||||||
@@ -6567,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",
|
||||||
|
@@ -14,12 +14,12 @@
|
|||||||
"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",
|
||||||
"node-stream-zip": "^1.15.0",
|
"silk-wasm": "^3.2.4",
|
||||||
"silk-wasm": "^3.2.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"
|
||||||
|
@@ -3,5 +3,5 @@ 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_UPDATE = 'llonebot_update'
|
||||||
export const CHANNEL_CHECKVERSION = 'llonebot_checkversion'
|
export const CHANNEL_CHECK_VERSION = 'llonebot_check_version'
|
||||||
export const CHANNEL_SELECT_FILE = 'llonebot_select_ffmpeg'
|
export const CHANNEL_SELECT_FILE = 'llonebot_select_ffmpeg'
|
||||||
|
@@ -30,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,
|
||||||
|
@@ -21,7 +21,9 @@ export let friends: Friend[] = []
|
|||||||
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未能正常启动,请检查日志查看错误'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -222,14 +222,14 @@ class DBUtil {
|
|||||||
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;
|
||||||
try {
|
try {
|
||||||
await this.db.put(key, JSON.stringify(cacheDBData));
|
await this.db.put(key, JSON.stringify(cacheDBData));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -237,8 +237,8 @@ class DBUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import express, {Express, json, Request, Response} from "express";
|
import express, {Express, Request, Response} from "express";
|
||||||
import http from "http";
|
import http from "http";
|
||||||
import {log} from "../utils/log";
|
import {log} from "../utils/log";
|
||||||
import {getConfigUtil} from "../config";
|
import {getConfigUtil} from "../config";
|
||||||
|
import {llonebotError} from "../data";
|
||||||
|
|
||||||
type RegisterHandler = (res: Response, payload: any) => Promise<any>
|
type RegisterHandler = (res: Response, payload: any) => Promise<any>
|
||||||
|
|
||||||
@@ -52,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;
|
||||||
|
@@ -3,6 +3,7 @@ import urlParse from "url";
|
|||||||
import {IncomingMessage} from "node:http";
|
import {IncomingMessage} from "node:http";
|
||||||
import {log} from "../utils/log";
|
import {log} from "../utils/log";
|
||||||
import {getConfigUtil} from "../config";
|
import {getConfigUtil} from "../config";
|
||||||
|
import {llonebotError} from "../data";
|
||||||
|
|
||||||
class WebsocketClientBase {
|
class WebsocketClientBase {
|
||||||
private wsClient: WebSocket
|
private wsClient: WebSocket
|
||||||
@@ -29,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);
|
||||||
@@ -41,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
|
||||||
@@ -28,6 +29,8 @@ export interface Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface LLOneBotError {
|
export interface LLOneBotError {
|
||||||
|
httpServerError?: string
|
||||||
|
wsServerError?: string
|
||||||
ffmpegError?: string
|
ffmpegError?: string
|
||||||
otherError?: string
|
otherError?: string
|
||||||
}
|
}
|
||||||
@@ -36,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,13 +1,18 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import fsPromise from "fs/promises";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import ffmpeg from "fluent-ffmpeg";
|
import ffmpeg from "fluent-ffmpeg";
|
||||||
import util from "util";
|
import util from "util";
|
||||||
import {encode, getDuration, isWav} from "silk-wasm";
|
import {encode, getDuration, isWav} from "silk-wasm";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import {v4 as uuidv4} from "uuid";
|
import {v4 as uuidv4} from "uuid";
|
||||||
import {DATA_DIR} from "./index";
|
import {checkFfmpeg, DATA_DIR, log, TEMP_DIR} from "./index";
|
||||||
import {log} from "./log";
|
|
||||||
import {getConfigUtil} from "../config";
|
import {getConfigUtil} from "../config";
|
||||||
|
import {dbUtil} from "../db";
|
||||||
|
import * as fileType from "file-type";
|
||||||
|
import {net} from "electron";
|
||||||
|
import config from "../../../electron.vite.config";
|
||||||
|
|
||||||
|
|
||||||
export function isGIF(path: string) {
|
export function isGIF(path: string) {
|
||||||
const buffer = Buffer.alloc(4);
|
const buffer = Buffer.alloc(4);
|
||||||
@@ -62,23 +67,6 @@ export async function file2base64(path: string) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
export async function encodeSilk(filePath: string) {
|
||||||
const fsp = require("fs").promises
|
const fsp = require("fs").promises
|
||||||
|
|
||||||
@@ -103,6 +91,23 @@ export async function encodeSilk(filePath: string) {
|
|||||||
return isWav(fs.readFileSync(filePath));
|
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) {
|
// async function getAudioSampleRate(filePath: string) {
|
||||||
// try {
|
// try {
|
||||||
// const mm = await import('music-metadata');
|
// const mm = await import('music-metadata');
|
||||||
@@ -116,7 +121,6 @@ export async function encodeSilk(filePath: string) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fileName = path.basename(filePath);
|
|
||||||
const pttPath = path.join(DATA_DIR, uuidv4());
|
const pttPath = path.join(DATA_DIR, uuidv4());
|
||||||
if (getFileHeader(filePath) !== "02232153494c4b") {
|
if (getFileHeader(filePath) !== "02232153494c4b") {
|
||||||
log(`语音文件${filePath}需要转换成silk`)
|
log(`语音文件${filePath}需要转换成silk`)
|
||||||
@@ -130,7 +134,7 @@ export async function encodeSilk(filePath: string) {
|
|||||||
if (ffmpegPath) {
|
if (ffmpegPath) {
|
||||||
ffmpeg.setFfmpegPath(ffmpegPath);
|
ffmpeg.setFfmpegPath(ffmpegPath);
|
||||||
}
|
}
|
||||||
ffmpeg(filePath).toFormat("wav").audioChannels(2).on('end', function () {
|
ffmpeg(filePath).toFormat("wav").audioChannels(1).audioFrequency(24000).on('end', function () {
|
||||||
log('wav转换完成');
|
log('wav转换完成');
|
||||||
})
|
})
|
||||||
.on('error', function (err) {
|
.on('error', function (err) {
|
||||||
@@ -151,23 +155,22 @@ export async function encodeSilk(filePath: string) {
|
|||||||
fs.writeFileSync(pttPath, silk.data);
|
fs.writeFileSync(pttPath, silk.data);
|
||||||
fs.unlink(wavPath, (err) => {
|
fs.unlink(wavPath, (err) => {
|
||||||
});
|
});
|
||||||
log(`语音文件${filePath}转换成功!`, pttPath)
|
const gDuration = await guessDuration(pttPath)
|
||||||
|
log(`语音文件${filePath}转换成功!`, pttPath, `时长:`, silk.duration)
|
||||||
return {
|
return {
|
||||||
converted: true,
|
converted: true,
|
||||||
path: pttPath,
|
path: pttPath,
|
||||||
duration: silk.duration,
|
duration: verifyDuration(silk.duration / 1000, gDuration),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const pcm = fs.readFileSync(filePath);
|
const silk = fs.readFileSync(filePath);
|
||||||
let duration = 0;
|
let duration = 0;
|
||||||
|
const gDuration = await guessDuration(filePath)
|
||||||
try {
|
try {
|
||||||
duration = getDuration(pcm);
|
duration = verifyDuration(getDuration(silk) / 1000, gDuration);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("获取语音文件时长失败", filePath, e.stack)
|
log("获取语音文件时长失败, 使用文件大小推测时长", filePath, e.stack)
|
||||||
duration = fs.statSync(filePath).size / 1024 / 3 // 每3kb大约1s
|
duration = gDuration;
|
||||||
duration = Math.floor(duration)
|
|
||||||
duration = Math.max(1, duration)
|
|
||||||
log("使用文件大小估算时长", duration)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -182,61 +185,7 @@ export async function encodeSilk(filePath: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getVideoInfo(filePath: string) {
|
|
||||||
const size = fs.statSync(filePath).size;
|
|
||||||
return new Promise<{
|
|
||||||
width: number,
|
|
||||||
height: number,
|
|
||||||
time: number,
|
|
||||||
format: string,
|
|
||||||
size: number,
|
|
||||||
filePath: string
|
|
||||||
}>((resolve, reject) => {
|
|
||||||
ffmpeg(filePath).ffprobe((err, metadata) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
const videoStream = metadata.streams.find(s => s.codec_type === 'video');
|
|
||||||
if (videoStream) {
|
|
||||||
console.log(`视频尺寸: ${videoStream.width}x${videoStream.height}`);
|
|
||||||
} else {
|
|
||||||
console.log('未找到视频流信息。');
|
|
||||||
}
|
|
||||||
resolve({
|
|
||||||
width: videoStream.width, height: videoStream.height,
|
|
||||||
time: parseInt(videoStream.duration),
|
|
||||||
format: metadata.format.format_name,
|
|
||||||
size,
|
|
||||||
filePath
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function encodeMp4(filePath: string) {
|
|
||||||
let videoInfo = await getVideoInfo(filePath);
|
|
||||||
log("视频信息", videoInfo)
|
|
||||||
if (videoInfo.format.indexOf("mp4") === -1) {
|
|
||||||
log("视频需要转换为MP4格式", filePath)
|
|
||||||
// 转成mp4
|
|
||||||
const newPath: string = await new Promise<string>((resolve, reject) => {
|
|
||||||
const newPath = filePath + ".mp4"
|
|
||||||
ffmpeg(filePath)
|
|
||||||
.toFormat('mp4')
|
|
||||||
.on('error', (err) => {
|
|
||||||
reject(`转换视频格式失败: ${err.message}`);
|
|
||||||
})
|
|
||||||
.on('end', () => {
|
|
||||||
log('视频转换为MP4格式完成');
|
|
||||||
resolve(newPath); // 返回转换后的文件路径
|
|
||||||
})
|
|
||||||
.save(newPath);
|
|
||||||
});
|
|
||||||
return await getVideoInfo(newPath)
|
|
||||||
}
|
|
||||||
return videoInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
export function calculateFileMD5(filePath: string): Promise<string> {
|
export function calculateFileMD5(filePath: string): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -261,3 +210,171 @@ export function calculateFileMD5(filePath: string): Promise<string> {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@@ -44,3 +44,25 @@ export function mergeNewProperties(newObj: any, oldObj: any) {
|
|||||||
export function isNull(value: any) {
|
export function isNull(value: any) {
|
||||||
return value === undefined || value === null;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -1,10 +1,17 @@
|
|||||||
|
import path from "node:path";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
export * from './file'
|
export * from './file'
|
||||||
export * from './helper'
|
export * from './helper'
|
||||||
export * from './log'
|
export * from './log'
|
||||||
export * from './qqlevel'
|
export * from './qqlevel'
|
||||||
export * from './qqpkg'
|
export * from './qqpkg'
|
||||||
export * from './update'
|
export * from './upgrade'
|
||||||
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
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";
|
@@ -8,3 +8,5 @@ type QQPkgInfo = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const qqPkgInfo: QQPkgInfo = require(path.join(process.resourcesPath, "app/package.json"))
|
export const qqPkgInfo: QQPkgInfo = require(path.join(process.resourcesPath, "app/package.json"))
|
||||||
|
|
||||||
|
export const isQQ998: boolean = qqPkgInfo.buildVersion >= "22106"
|
@@ -1,62 +0,0 @@
|
|||||||
import {version} from "../../version";
|
|
||||||
import https from "node:https";
|
|
||||||
|
|
||||||
export async function checkVersion() {
|
|
||||||
const latestVersionText = await getRemoteVersion();
|
|
||||||
const latestVersion = latestVersionText.split(".");
|
|
||||||
const currentVersion = version.split(".");
|
|
||||||
for (let k in [0, 1, 2]) {
|
|
||||||
if (latestVersion[k] > currentVersion[k]) {
|
|
||||||
return { result: false, version: latestVersionText };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { result: true, version: version };
|
|
||||||
}
|
|
||||||
export async function updateLLOneBot() {
|
|
||||||
let mirrorGithubList = ["https://mirror.ghproxy.com"];
|
|
||||||
const latestVersion = await getRemoteVersion();
|
|
||||||
if (latestVersion && latestVersion != "") {
|
|
||||||
const downloadUrl = "https://github.com/LLOneBot/LLOneBot/releases/download/v" + latestVersion + "/LLOneBot.zip";
|
|
||||||
const realUrl = mirrorGithubList[0] + downloadUrl;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
export async function getRemoteVersion() {
|
|
||||||
let mirrorGithubList = ["https://521github.com"];
|
|
||||||
let Version = "";
|
|
||||||
for (let i = 0; i < mirrorGithubList.length; i++) {
|
|
||||||
let mirrorGithub = mirrorGithubList[i];
|
|
||||||
let tVersion = await getRemoteVersionByMirror(mirrorGithub);
|
|
||||||
if (tVersion && tVersion != "") {
|
|
||||||
Version = tVersion;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Version;
|
|
||||||
}
|
|
||||||
export async function getRemoteVersionByMirror(mirrorGithub: string) {
|
|
||||||
let releasePage = "error";
|
|
||||||
let reqPromise = async function (): Promise<string> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
https.get(mirrorGithub + "/LLOneBot/LLOneBot/releases", res => {
|
|
||||||
let list = [];
|
|
||||||
res.on('data', chunk => {
|
|
||||||
list.push(chunk);
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
resolve(Buffer.concat(list).toString());
|
|
||||||
});
|
|
||||||
}).on('error', err => {
|
|
||||||
reject();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
releasePage = await reqPromise();
|
|
||||||
if (releasePage === "error") return "";
|
|
||||||
return releasePage.match(new RegExp('(?<=(tag/v)).*?(?=("))'))[0];
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
return "";
|
|
||||||
|
|
||||||
}
|
|
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
@@ -7,13 +7,13 @@ import {
|
|||||||
CHANNEL_ERROR,
|
CHANNEL_ERROR,
|
||||||
CHANNEL_GET_CONFIG,
|
CHANNEL_GET_CONFIG,
|
||||||
CHANNEL_LOG,
|
CHANNEL_LOG,
|
||||||
CHANNEL_CHECKVERSION,
|
CHANNEL_CHECK_VERSION,
|
||||||
CHANNEL_SELECT_FILE,
|
CHANNEL_SELECT_FILE,
|
||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
CHANNEL_UPDATE,
|
CHANNEL_UPDATE,
|
||||||
} from "../common/channels";
|
} from "../common/channels";
|
||||||
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||||
import {DATA_DIR} from "../common/utils";
|
import {DATA_DIR, wrapText} from "../common/utils";
|
||||||
import {
|
import {
|
||||||
friendRequests,
|
friendRequests,
|
||||||
getFriend,
|
getFriend,
|
||||||
@@ -41,23 +41,25 @@ import {NTQQUserApi} from "../ntqqapi/api/user";
|
|||||||
import {NTQQGroupApi} from "../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../ntqqapi/api/group";
|
||||||
import {registerPokeHandler} from "../ntqqapi/external/ccpoke";
|
import {registerPokeHandler} from "../ntqqapi/external/ccpoke";
|
||||||
import {OB11FriendPokeEvent, OB11GroupPokeEvent} from "../onebot11/event/notice/OB11PokeEvent";
|
import {OB11FriendPokeEvent, OB11GroupPokeEvent} from "../onebot11/event/notice/OB11PokeEvent";
|
||||||
import {checkVersion, updateLLOneBot} from "../common/utils/update";
|
import {checkNewVersion, upgradeLLOneBot} from "../common/utils/upgrade";
|
||||||
import {checkFfmpeg} from "../common/utils/file";
|
|
||||||
import {log} from "../common/utils/log";
|
import {log} from "../common/utils/log";
|
||||||
import {getConfigUtil} from "../common/config";
|
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_CHECKVERSION, async (event, arg) => {
|
ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => {
|
||||||
return checkVersion();
|
|
||||||
|
return checkNewVersion();
|
||||||
});
|
});
|
||||||
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
|
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
|
||||||
return updateLLOneBot();
|
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) => {
|
||||||
@@ -92,15 +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, config: Config) => {
|
ipcMain.on(CHANNEL_SET_CONFIG, (event, ask:boolean, config: Config) => {
|
||||||
setConfig(config).then();
|
if (!ask){
|
||||||
|
setConfig(config).then();
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dialog.showMessageBox(mainWindow, {
|
||||||
|
type: 'question',
|
||||||
|
buttons: ['确认', '取消'],
|
||||||
|
defaultId: 0, // 默认选中的按钮,0 代表第一个按钮,即 "确认"
|
||||||
|
title: '确认保存',
|
||||||
|
message: '是否保存?',
|
||||||
|
detail: 'LLOneBot配置已更改,是否保存?'
|
||||||
|
}).then(result => {
|
||||||
|
if (result.response === 0) {
|
||||||
|
setConfig(config).then();
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
log("保存设置询问弹窗错误", err);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on(CHANNEL_LOG, (event, arg) => {
|
ipcMain.on(CHANNEL_LOG, (event, arg) => {
|
||||||
@@ -331,7 +357,7 @@ function onLoad() {
|
|||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
log("llonebot pid", process.pid)
|
log("llonebot pid", process.pid)
|
||||||
|
llonebotError.otherError = "";
|
||||||
startTime = Date.now();
|
startTime = Date.now();
|
||||||
dbUtil.getReceivedTempUinMap().then(m=>{
|
dbUtil.getReceivedTempUinMap().then(m=>{
|
||||||
for (const [key, value] of Object.entries(m)) {
|
for (const [key, value] of Object.entries(m)) {
|
||||||
@@ -341,18 +367,8 @@ function onLoad() {
|
|||||||
startReceiveHook().then();
|
startReceiveHook().then();
|
||||||
NTQQGroupApi.getGroups(true).then()
|
NTQQGroupApi.getGroups(true).then()
|
||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
// 检查ffmpeg
|
|
||||||
checkFfmpeg(config.ffmpeg).then(exist => {
|
|
||||||
if (!exist) {
|
|
||||||
llonebotError.ffmpegError = `没有找到ffmpeg,音频只能发送wav和silk`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
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);
|
||||||
@@ -406,6 +422,7 @@ function onBrowserWindowCreated(window: BrowserWindow) {
|
|||||||
if (selfInfo.uid) {
|
if (selfInfo.uid) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
mainWindow = window;
|
||||||
log("window create", window.webContents.getURL().toString())
|
log("window create", window.webContents.getURL().toString())
|
||||||
try {
|
try {
|
||||||
hookNTQQApiCall(window);
|
hookNTQQApiCall(window);
|
||||||
@@ -421,6 +438,7 @@ try {
|
|||||||
console.log(e.toString())
|
console.log(e.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 这两个函数都是可选的
|
// 这两个函数都是可选的
|
||||||
export {
|
export {
|
||||||
onBrowserWindowCreated
|
onBrowserWindowCreated
|
||||||
|
@@ -3,8 +3,8 @@ import {ob11HTTPServer} from "../onebot11/server/http";
|
|||||||
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||||
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
||||||
import {llonebotError} from "../common/data";
|
import {llonebotError} from "../common/data";
|
||||||
import {checkFfmpeg} from "../common/utils/file";
|
|
||||||
import {getConfigUtil} from "../common/config";
|
import {getConfigUtil} from "../common/config";
|
||||||
|
import {checkFfmpeg} from "../common/utils";
|
||||||
|
|
||||||
export async function setConfig(config: Config) {
|
export async function setConfig(config: Config) {
|
||||||
let oldConfig = getConfigUtil().getConfig();
|
let oldConfig = getConfigUtil().getConfig();
|
||||||
@@ -21,6 +21,7 @@ export async function setConfig(config: Config) {
|
|||||||
// 正向ws端口变化,重启服务
|
// 正向ws端口变化,重启服务
|
||||||
if (config.ob11.wsPort != oldConfig.ob11.wsPort) {
|
if (config.ob11.wsPort != oldConfig.ob11.wsPort) {
|
||||||
ob11WebsocketServer.restart(config.ob11.wsPort);
|
ob11WebsocketServer.restart(config.ob11.wsPort);
|
||||||
|
llonebotError.wsServerError = ''
|
||||||
}
|
}
|
||||||
// 判断是否启用或关闭正向ws
|
// 判断是否启用或关闭正向ws
|
||||||
if (config.ob11.enableWs != oldConfig.ob11.enableWs) {
|
if (config.ob11.enableWs != oldConfig.ob11.enableWs) {
|
||||||
@@ -51,14 +52,5 @@ export async function setConfig(config: Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
checkFfmpeg(config.ffmpeg).then()
|
||||||
// 检查ffmpeg
|
|
||||||
if (config.ffmpeg) {
|
|
||||||
checkFfmpeg(config.ffmpeg).then(success => {
|
|
||||||
if (success) {
|
|
||||||
llonebotError.ffmpegError = ''
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@@ -4,7 +4,8 @@ import {
|
|||||||
CacheFileListItem,
|
CacheFileListItem,
|
||||||
CacheFileType,
|
CacheFileType,
|
||||||
CacheScanResult,
|
CacheScanResult,
|
||||||
ChatCacheList, ChatCacheListItemBasic,
|
ChatCacheList,
|
||||||
|
ChatCacheListItemBasic,
|
||||||
ChatType,
|
ChatType,
|
||||||
ElementType
|
ElementType
|
||||||
} from "../types";
|
} from "../types";
|
||||||
@@ -13,12 +14,13 @@ import fs from "fs";
|
|||||||
import {ReceiveCmdS} from "../hook";
|
import {ReceiveCmdS} from "../hook";
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
export class NTQQFileApi{
|
export class NTQQFileApi {
|
||||||
static async getFileType(filePath: string) {
|
static async getFileType(filePath: string) {
|
||||||
return await callNTQQApi<{ ext: string }>({
|
return await callNTQQApi<{ ext: string }>({
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_TYPE, args: [filePath]
|
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_TYPE, args: [filePath]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getFileMd5(filePath: string) {
|
static async getFileMd5(filePath: string) {
|
||||||
return await callNTQQApi<string>({
|
return await callNTQQApi<string>({
|
||||||
className: NTQQApiClass.FS_API,
|
className: NTQQApiClass.FS_API,
|
||||||
@@ -26,6 +28,7 @@ export class NTQQFileApi{
|
|||||||
args: [filePath]
|
args: [filePath]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async copyFile(filePath: string, destPath: string) {
|
static async copyFile(filePath: string, destPath: string) {
|
||||||
return await callNTQQApi<string>({
|
return await callNTQQApi<string>({
|
||||||
className: NTQQApiClass.FS_API,
|
className: NTQQApiClass.FS_API,
|
||||||
@@ -36,11 +39,13 @@ export class NTQQFileApi{
|
|||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getFileSize(filePath: string) {
|
static async getFileSize(filePath: string) {
|
||||||
return await callNTQQApi<number>({
|
return await callNTQQApi<number>({
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_SIZE, args: [filePath]
|
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_SIZE, args: [filePath]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上传文件到QQ的文件夹
|
// 上传文件到QQ的文件夹
|
||||||
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
||||||
const md5 = await NTQQFileApi.getFileMd5(filePath);
|
const md5 = await NTQQFileApi.getFileMd5(filePath);
|
||||||
@@ -79,14 +84,18 @@ export class NTQQFileApi{
|
|||||||
fileSize
|
fileSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string) {
|
|
||||||
|
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, isFile: boolean = false) {
|
||||||
// 用于下载收到的消息中的图片等
|
// 用于下载收到的消息中的图片等
|
||||||
if (fs.existsSync(sourcePath)) {
|
if (sourcePath && fs.existsSync(sourcePath)) {
|
||||||
return sourcePath
|
return sourcePath
|
||||||
}
|
}
|
||||||
const apiParams = [
|
const apiParams = [
|
||||||
{
|
{
|
||||||
getReq: {
|
getReq: {
|
||||||
|
fileModelId: "0",
|
||||||
|
downloadSourceType: 0,
|
||||||
|
triggerType: 1,
|
||||||
msgId: msgId,
|
msgId: msgId,
|
||||||
chatType: chatType,
|
chatType: chatType,
|
||||||
peerUid: peerUid,
|
peerUid: peerUid,
|
||||||
@@ -96,20 +105,21 @@ export class NTQQFileApi{
|
|||||||
filePath: thumbPath,
|
filePath: thumbPath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
undefined,
|
null,
|
||||||
]
|
]
|
||||||
// log("需要下载media", sourcePath);
|
// log("需要下载media", sourcePath);
|
||||||
await callNTQQApi({
|
await callNTQQApi({
|
||||||
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
||||||
args: apiParams,
|
args: apiParams,
|
||||||
cbCmd: ReceiveCmdS.MEDIA_DOWNLOAD_COMPLETE,
|
cbCmd: ReceiveCmdS.MEDIA_DOWNLOAD_COMPLETE,
|
||||||
cmdCB: (payload: { notifyInfo: { filePath: string } }) => {
|
cmdCB: (payload: { notifyInfo: { filePath: string, msgId: string } }) => {
|
||||||
// log("media 下载完成判断", payload.notifyInfo.filePath, sourcePath);
|
log("media 下载完成判断", payload.notifyInfo.msgId, msgId);
|
||||||
return payload.notifyInfo.filePath == sourcePath;
|
return payload.notifyInfo.msgId == msgId;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return sourcePath
|
return sourcePath
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getImageSize(filePath: string) {
|
static async getImageSize(filePath: string) {
|
||||||
return await callNTQQApi<{ width: number, height: number }>({
|
return await callNTQQApi<{ width: number, height: number }>({
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.IMAGE_SIZE, args: [filePath]
|
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.IMAGE_SIZE, args: [filePath]
|
||||||
@@ -118,7 +128,7 @@ export class NTQQFileApi{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NTQQFileCacheApi{
|
export class NTQQFileCacheApi {
|
||||||
static async setCacheSilentScan(isSilent: boolean = true) {
|
static async setCacheSilentScan(isSilent: boolean = true) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
|
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
|
||||||
@@ -127,6 +137,7 @@ export class NTQQFileCacheApi{
|
|||||||
}, null]
|
}, null]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static getCacheSessionPathList() {
|
static getCacheSessionPathList() {
|
||||||
return callNTQQApi<{
|
return callNTQQApi<{
|
||||||
key: string,
|
key: string,
|
||||||
@@ -136,6 +147,7 @@ export class NTQQFileCacheApi{
|
|||||||
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
|
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
|
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
|
||||||
return callNTQQApi<any>({ // TODO: 目前还不知道真正的返回值是什么
|
return callNTQQApi<any>({ // TODO: 目前还不知道真正的返回值是什么
|
||||||
methodName: NTQQApiMethod.CACHE_CLEAR,
|
methodName: NTQQApiMethod.CACHE_CLEAR,
|
||||||
@@ -144,6 +156,7 @@ export class NTQQFileCacheApi{
|
|||||||
}, null]
|
}, null]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static addCacheScannedPaths(pathMap: object = {}) {
|
static addCacheScannedPaths(pathMap: object = {}) {
|
||||||
return callNTQQApi<GeneralCallResult>({
|
return callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
|
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
|
||||||
@@ -152,6 +165,7 @@ export class NTQQFileCacheApi{
|
|||||||
}, null]
|
}, null]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static scanCache() {
|
static scanCache() {
|
||||||
callNTQQApi<GeneralCallResult>({
|
callNTQQApi<GeneralCallResult>({
|
||||||
methodName: ReceiveCmdS.CACHE_SCAN_FINISH,
|
methodName: ReceiveCmdS.CACHE_SCAN_FINISH,
|
||||||
@@ -163,6 +177,7 @@ export class NTQQFileCacheApi{
|
|||||||
timeoutSecond: 300,
|
timeoutSecond: 300,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static getHotUpdateCachePath() {
|
static getHotUpdateCachePath() {
|
||||||
return callNTQQApi<string>({
|
return callNTQQApi<string>({
|
||||||
className: NTQQApiClass.HOTUPDATE_API,
|
className: NTQQApiClass.HOTUPDATE_API,
|
||||||
@@ -176,6 +191,7 @@ export class NTQQFileCacheApi{
|
|||||||
methodName: NTQQApiMethod.CACHE_PATH_DESKTOP_TEMP
|
methodName: NTQQApiMethod.CACHE_PATH_DESKTOP_TEMP
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) {
|
static getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) {
|
||||||
return new Promise<ChatCacheList>((res, rej) => {
|
return new Promise<ChatCacheList>((res, rej) => {
|
||||||
callNTQQApi<ChatCacheList>({
|
callNTQQApi<ChatCacheList>({
|
||||||
@@ -190,6 +206,7 @@ export class NTQQFileCacheApi{
|
|||||||
.catch(e => rej(e));
|
.catch(e => rej(e));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) {
|
static getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) {
|
||||||
const _lastRecord = lastRecord ? lastRecord : {fileType: fileType};
|
const _lastRecord = lastRecord ? lastRecord : {fileType: fileType};
|
||||||
|
|
||||||
@@ -204,6 +221,7 @@ export class NTQQFileCacheApi{
|
|||||||
}, null]
|
}, null]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
|
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
|
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
|
||||||
|
@@ -5,6 +5,7 @@ import {uidMaps} from "../../common/data";
|
|||||||
import {BrowserWindow} from "electron";
|
import {BrowserWindow} from "electron";
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../common/db";
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../common/utils/log";
|
||||||
|
import {NTQQWindowApi, NTQQWindows} from "./window";
|
||||||
|
|
||||||
export class NTQQGroupApi{
|
export class NTQQGroupApi{
|
||||||
static async getGroups(forced = false) {
|
static async getGroups(forced = false) {
|
||||||
@@ -74,25 +75,7 @@ export class NTQQGroupApi{
|
|||||||
}
|
}
|
||||||
static async getGroupIgnoreNotifies() {
|
static async getGroupIgnoreNotifies() {
|
||||||
await NTQQGroupApi.getGroupNotifies();
|
await NTQQGroupApi.getGroupNotifies();
|
||||||
const result = callNTQQApi<GroupNotifies>({
|
return await NTQQWindowApi.openWindow(NTQQWindows.GroupNotifyFilterWindow,[], ReceiveCmdS.GROUP_NOTIFY);
|
||||||
className: NTQQApiClass.WINDOW_API,
|
|
||||||
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
|
|
||||||
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
|
||||||
afterFirstCmd: false,
|
|
||||||
args: [
|
|
||||||
"GroupNotifyFilterWindow"
|
|
||||||
]
|
|
||||||
})
|
|
||||||
// 关闭窗口
|
|
||||||
setTimeout(() => {
|
|
||||||
for (const w of BrowserWindow.getAllWindows()) {
|
|
||||||
// log("close window", w.webContents.getURL())
|
|
||||||
if (w.webContents.getURL().indexOf("#/notify-filter/") != -1) {
|
|
||||||
w.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||||
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
||||||
|
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";
|
@@ -5,6 +5,7 @@ import {selfInfo} from "../../common/data";
|
|||||||
import {ReceiveCmdS, registerReceiveHook} from "../hook";
|
import {ReceiveCmdS, registerReceiveHook} from "../hook";
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../common/utils/log";
|
||||||
import {sleep} from "../../common/utils/helper";
|
import {sleep} from "../../common/utils/helper";
|
||||||
|
import {isQQ998} from "../../common/utils";
|
||||||
|
|
||||||
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {}// peerUid: callbackFunnc
|
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {}// peerUid: callbackFunnc
|
||||||
|
|
||||||
@@ -23,6 +24,17 @@ export class NTQQMsgApi {
|
|||||||
args: [{peer:{peerUid: groupCode, chatType: ChatType.group}, cnt: 20}, null]
|
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(){
|
static async fetchRecentContact(){
|
||||||
await callNTQQApi({
|
await callNTQQApi({
|
||||||
methodName: NTQQApiMethod.RECENT_CONTACT,
|
methodName: NTQQApiMethod.RECENT_CONTACT,
|
||||||
|
@@ -53,5 +53,4 @@ export class NTQQUserApi{
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
87
src/ntqqapi/api/webapi.ts
Normal file
87
src/ntqqapi/api/webapi.ts
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import {net, session} from "electron";
|
||||||
|
import {NTQQApi} from "../ntcall";
|
||||||
|
import {groups} from "../../common/data";
|
||||||
|
import {log} from "../../common/utils";
|
||||||
|
|
||||||
|
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 NTQQApi.getSkey(group.groupName, group.groupCode)).data;
|
||||||
|
WebApi.bkn = this.genBkn(WebApi.skey);
|
||||||
|
let cookie = await NTQQApi.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;
|
||||||
|
}
|
||||||
|
}
|
@@ -14,9 +14,9 @@ import {
|
|||||||
import {promises as fs} from "node:fs";
|
import {promises as fs} from "node:fs";
|
||||||
import ffmpeg from "fluent-ffmpeg"
|
import ffmpeg from "fluent-ffmpeg"
|
||||||
import {NTQQFileApi} from "./api/file";
|
import {NTQQFileApi} from "./api/file";
|
||||||
import {calculateFileMD5, encodeSilk, getVideoInfo, isGIF} from "../common/utils/file";
|
import {calculateFileMD5, encodeSilk, isGIF} from "../common/utils/file";
|
||||||
import {log} from "../common/utils/log";
|
import {log} from "../common/utils/log";
|
||||||
import {sleep} from "../common/utils/helper";
|
import {defaultVideoThumb, getVideoInfo} from "../common/utils/video";
|
||||||
|
|
||||||
|
|
||||||
export class SendMsgElementConstructor {
|
export class SendMsgElementConstructor {
|
||||||
@@ -108,29 +108,45 @@ export class SendMsgElementConstructor {
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async video(filePath: string, fileName: string = ""): Promise<SendVideoElement> {
|
static async video(filePath: string, fileName: string = "", diyThumbPath: string = ""): Promise<SendVideoElement> {
|
||||||
let {fileName: _fileName, path, fileSize, md5} = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO);
|
let {fileName: _fileName, path, fileSize, md5} = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO);
|
||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw "文件异常,大小为0";
|
throw "文件异常,大小为0";
|
||||||
}
|
}
|
||||||
// const videoInfo = await encodeMp4(path);
|
|
||||||
// path = videoInfo.filePath
|
|
||||||
// md5 = videoInfo.md5;
|
|
||||||
// fileSize = videoInfo.size;
|
|
||||||
// log("上传视频", md5, path, fileSize, fileName || _fileName)
|
|
||||||
const pathLib = require("path");
|
const pathLib = require("path");
|
||||||
let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
|
let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
|
||||||
thumb = pathLib.dirname(thumb)
|
thumb = pathLib.dirname(thumb)
|
||||||
// log("thumb 目录", thumb)
|
// log("thumb 目录", thumb)
|
||||||
const videoInfo = await getVideoInfo(path);
|
let videoInfo ={
|
||||||
log("视频信息", 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 createThumb = new Promise<string>((resolve, reject) => {
|
||||||
const thumbFileName = `${md5}_0.png`
|
const thumbFileName = `${md5}_0.png`
|
||||||
|
const thumbPath = pathLib.join(thumb, thumbFileName)
|
||||||
ffmpeg(filePath)
|
ffmpeg(filePath)
|
||||||
.on("end", () => {
|
.on("end", () => {
|
||||||
})
|
})
|
||||||
.on("error", (err) => {
|
.on("error", (err) => {
|
||||||
reject(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({
|
.screenshots({
|
||||||
timestamps: [0],
|
timestamps: [0],
|
||||||
@@ -138,7 +154,7 @@ export class SendMsgElementConstructor {
|
|||||||
folder: thumb,
|
folder: thumb,
|
||||||
size: videoInfo.width + "x" + videoInfo.height
|
size: videoInfo.width + "x" + videoInfo.height
|
||||||
}).on("end", () => {
|
}).on("end", () => {
|
||||||
resolve(pathLib.join(thumb, thumbFileName));
|
resolve(thumbPath);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
let thumbPath = new Map()
|
let thumbPath = new Map()
|
||||||
@@ -195,7 +211,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,
|
||||||
@@ -225,7 +241,11 @@ export class SendMsgElementConstructor {
|
|||||||
return {
|
return {
|
||||||
elementType: ElementType.ARK,
|
elementType: ElementType.ARK,
|
||||||
elementId: "",
|
elementId: "",
|
||||||
arkElement: data
|
arkElement: {
|
||||||
|
bytesData: data,
|
||||||
|
linkInfo: null,
|
||||||
|
subElementType: null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -33,6 +33,7 @@ export let ReceiveCmdS = {
|
|||||||
SELF_STATUS: 'nodeIKernelProfileListener/onSelfStatusChanged',
|
SELF_STATUS: 'nodeIKernelProfileListener/onSelfStatusChanged',
|
||||||
CACHE_SCAN_FINISH: "nodeIKernelStorageCleanListener/onFinishScan",
|
CACHE_SCAN_FINISH: "nodeIKernelStorageCleanListener/onFinishScan",
|
||||||
MEDIA_UPLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaUploadComplete",
|
MEDIA_UPLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaUploadComplete",
|
||||||
|
SKEY_UPDATE: "onSkeyUpdate"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ReceiveCmd = typeof ReceiveCmdS[keyof typeof ReceiveCmdS]
|
export type ReceiveCmd = typeof ReceiveCmdS[keyof typeof ReceiveCmdS]
|
||||||
@@ -60,45 +61,56 @@ let receiveHooks: Array<{
|
|||||||
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) => {
|
||||||
|
// console.log("hookNTQQApiReceive", channel, args)
|
||||||
|
let isLogger = false
|
||||||
try {
|
try {
|
||||||
if (!args[0]?.eventName?.startsWith("ns-LoggerApi")) {
|
isLogger = args[0]?.eventName?.startsWith("ns-LoggerApi")
|
||||||
HOOK_LOG && log(`received ntqq api message: ${channel}`, JSON.stringify(args))
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
if (args?.[1] instanceof Array) {
|
if (!isLogger) {
|
||||||
for (let receiveData of args?.[1]) {
|
try {
|
||||||
const ntQQApiMethodName = receiveData.cmdName;
|
HOOK_LOG && log(`received ntqq api message: ${channel}`, args)
|
||||||
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
}catch (e) {
|
||||||
for (let hook of receiveHooks) {
|
log("hook log error", e, args)
|
||||||
if (hook.method.includes(ntQQApiMethodName)) {
|
}
|
||||||
new Promise((resolve, reject) => {
|
}
|
||||||
try {
|
try {
|
||||||
let _ = hook.hookFunc(receiveData.payload)
|
if (args?.[1] instanceof Array) {
|
||||||
if (hook.hookFunc.constructor.name === "AsyncFunction") {
|
for (let receiveData of args?.[1]) {
|
||||||
(_ as Promise<void>).then()
|
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;
|
||||||
}
|
}
|
||||||
@@ -110,12 +122,19 @@ export function hookNTQQApiCall(window: BrowserWindow) {
|
|||||||
|
|
||||||
const proxyIpcMsg = new Proxy(ipc_message_proxy, {
|
const proxyIpcMsg = new Proxy(ipc_message_proxy, {
|
||||||
apply(target, thisArg, args) {
|
apply(target, thisArg, args) {
|
||||||
|
// console.log(thisArg, args);
|
||||||
|
let isLogger = false
|
||||||
try {
|
try {
|
||||||
if (args[3][1][0] !== "info") {
|
isLogger = args[3][0].eventName.startsWith("ns-LoggerApi")
|
||||||
HOOK_LOG && log("call NTQQ api", thisArg, args);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!isLogger) {
|
||||||
|
try{
|
||||||
|
HOOK_LOG && log("call NTQQ api", thisArg, args);
|
||||||
|
}catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return target.apply(thisArg, args);
|
return target.apply(thisArg, args);
|
||||||
},
|
},
|
||||||
@@ -125,6 +144,31 @@ export function hookNTQQApiCall(window: BrowserWindow) {
|
|||||||
} 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 | ReceiveCmd[], hookFunc: (payload: PayloadType) => void): string {
|
export function registerReceiveHook<PayloadType>(method: ReceiveCmd | ReceiveCmd[], hookFunc: (payload: PayloadType) => void): string {
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
import {ipcMain} from "electron";
|
import {ipcMain} from "electron";
|
||||||
import {hookApiCallbacks, ReceiveCmd, registerReceiveHook, removeReceiveHook} from "./hook";
|
import {hookApiCallbacks, ReceiveCmd, ReceiveCmdS, registerReceiveHook, removeReceiveHook} from "./hook";
|
||||||
|
|
||||||
import {v4 as uuidv4} from "uuid"
|
import {v4 as uuidv4} from "uuid"
|
||||||
import {log} from "../common/utils/log";
|
import {log} from "../common/utils/log";
|
||||||
|
import {NTQQWindow, NTQQWindowApi, NTQQWindows} from "./api/window";
|
||||||
|
import {WebApi} from "./api/webapi";
|
||||||
|
import {HOOK_LOG} from "../common/config";
|
||||||
|
|
||||||
export enum NTQQApiClass {
|
export enum NTQQApiClass {
|
||||||
NT_API = "ns-ntApi",
|
NT_API = "ns-ntApi",
|
||||||
@@ -11,13 +14,17 @@ export enum NTQQApiClass {
|
|||||||
WINDOW_API = "ns-WindowApi",
|
WINDOW_API = "ns-WindowApi",
|
||||||
HOTUPDATE_API = "ns-HotUpdateApi",
|
HOTUPDATE_API = "ns-HotUpdateApi",
|
||||||
BUSINESS_API = "ns-BusinessApi",
|
BUSINESS_API = "ns-BusinessApi",
|
||||||
GLOBAL_DATA = "ns-GlobalDataApi"
|
GLOBAL_DATA = "ns-GlobalDataApi",
|
||||||
|
SKEY_API = "ns-SkeyApi",
|
||||||
|
GROUP_HOME_WORK = "ns-GroupHomeWork",
|
||||||
|
GROUP_ESSENCE = "ns-GroupEssence",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum NTQQApiMethod {
|
export enum NTQQApiMethod {
|
||||||
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
|
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
|
||||||
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
||||||
ADD_ACTIVE_CHAT_2 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
HISTORY_MSG_998 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
||||||
|
HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelf",
|
||||||
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
||||||
SELF_INFO = "fetchAuthData",
|
SELF_INFO = "fetchAuthData",
|
||||||
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
||||||
@@ -65,7 +72,9 @@ export enum NTQQApiMethod {
|
|||||||
|
|
||||||
OPEN_EXTRA_WINDOW = 'openExternalWindow',
|
OPEN_EXTRA_WINDOW = 'openExternalWindow',
|
||||||
|
|
||||||
SET_QQ_AVATAR = 'nodeIKernelProfileService/setHeader'
|
SET_QQ_AVATAR = 'nodeIKernelProfileService/setHeader',
|
||||||
|
GET_SKEY = "nodeIKernelTipOffService/getPskey",
|
||||||
|
UPDATE_SKEY = "updatePskey"
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NTQQApiChannel {
|
enum NTQQApiChannel {
|
||||||
@@ -98,7 +107,7 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
|||||||
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 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
|
||||||
@@ -109,7 +118,7 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
|||||||
}
|
}
|
||||||
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)
|
||||||
@@ -178,4 +187,58 @@ export class NTQQApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
// ]
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getPSkey() {
|
||||||
|
return await callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.GROUP_HOME_WORK,
|
||||||
|
methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
domain: "qun.qq.com"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async addGroupDigest(groupCode: string, msgSeq: string) {
|
||||||
|
return await new WebApi().addGroupDigest(groupCode, msgSeq);
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getGroupDigest(groupCode: string) {
|
||||||
|
return await new WebApi().getGroupDigest(groupCode);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -18,7 +18,54 @@ export interface User {
|
|||||||
longNick?: string; // 签名
|
longNick?: string; // 签名
|
||||||
remark?: string;
|
remark?: string;
|
||||||
sex?: Sex;
|
sex?: Sex;
|
||||||
"qqLevel"?: QQLevel
|
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 {
|
export interface SelfInfo extends User {
|
||||||
|
@@ -1,29 +0,0 @@
|
|||||||
import BaseAction from "./BaseAction";
|
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
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 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
|
|
||||||
}
|
|
||||||
}
|
|
@@ -2,9 +2,12 @@ import BaseAction from "./BaseAction";
|
|||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../common/db";
|
||||||
import {getConfigUtil} from "../../common/config";
|
import {getConfigUtil} from "../../common/config";
|
||||||
|
import {log, sleep, uri2local} from "../../common/utils";
|
||||||
|
import {NTQQFileApi} from "../../ntqqapi/api/file";
|
||||||
|
import {ActionName} from "./types";
|
||||||
|
|
||||||
export interface GetFilePayload {
|
export interface GetFilePayload {
|
||||||
file: string // 文件名
|
file: string // 文件名或者fileUuid
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetFileResponse {
|
export interface GetFileResponse {
|
||||||
@@ -26,6 +29,42 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|||||||
if (cache.downloadFunc) {
|
if (cache.downloadFunc) {
|
||||||
await 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)
|
||||||
|
const element = msg.elements.find(e=>e.fileElement)
|
||||||
|
log("找到了文件 element", element);
|
||||||
|
// 构建下载函数
|
||||||
|
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
|
element.elementId, "", "", true)
|
||||||
|
await sleep(1000);
|
||||||
|
msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||||
|
log("下载完成后的msg", msg)
|
||||||
|
cache.filePath = msg?.elements.find(e=>e.fileElement)?.fileElement?.filePath
|
||||||
|
dbUtil.addFileCache(payload.file, cache).then()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
let res: GetFileResponse = {
|
let res: GetFileResponse = {
|
||||||
file: cache.filePath,
|
file: cache.filePath,
|
||||||
url: cache.url,
|
url: cache.url,
|
||||||
@@ -34,14 +73,30 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|||||||
}
|
}
|
||||||
if (enableLocalFile2Url) {
|
if (enableLocalFile2Url) {
|
||||||
if (!cache.url) {
|
if (!cache.url) {
|
||||||
res.base64 = await fs.readFile(cache.filePath, 'base64')
|
try{
|
||||||
|
res.base64 = await fs.readFile(cache.filePath, 'base64')
|
||||||
|
}catch (e) {
|
||||||
|
throw new Error("文件下载失败. " + e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (autoDeleteFile) {
|
// if (autoDeleteFile) {
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
fs.unlink(cache.filePath)
|
// fs.unlink(cache.filePath)
|
||||||
}, autoDeleteFileSecond * 1000)
|
// }, autoDeleteFileSecond * 1000)
|
||||||
}
|
// }
|
||||||
return res
|
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);
|
||||||
|
}
|
||||||
|
}
|
@@ -25,7 +25,6 @@ import {
|
|||||||
} from '../types';
|
} from '../types';
|
||||||
import {Peer} from "../../ntqqapi/api/msg";
|
import {Peer} from "../../ntqqapi/api/msg";
|
||||||
import {SendMsgElementConstructor} from "../../ntqqapi/constructor";
|
import {SendMsgElementConstructor} from "../../ntqqapi/constructor";
|
||||||
import {uri2local} from "../utils";
|
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {ActionName, BaseCheckResult} from "./types";
|
import {ActionName, BaseCheckResult} from "./types";
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
@@ -35,6 +34,7 @@ import {ALLOW_SEND_TEMP_MSG} from "../../common/config";
|
|||||||
import {NTQQMsgApi} from "../../ntqqapi/api/msg";
|
import {NTQQMsgApi} from "../../ntqqapi/api/msg";
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../common/utils/log";
|
||||||
import {sleep} from "../../common/utils/helper";
|
import {sleep} from "../../common/utils/helper";
|
||||||
|
import {uri2local} from "../../common/utils";
|
||||||
|
|
||||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||||
function checkUri(uri: string): boolean {
|
function checkUri(uri: string): boolean {
|
||||||
@@ -430,7 +430,14 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
|
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
|
||||||
} else if (sendMsg.type === OB11MessageDataType.video) {
|
} else if (sendMsg.type === OB11MessageDataType.video) {
|
||||||
log("发送视频", path, payloadFileName || fileName)
|
log("发送视频", path, payloadFileName || fileName)
|
||||||
sendElements.push(await SendMsgElementConstructor.video(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) {
|
} else if (sendMsg.type === OB11MessageDataType.voice) {
|
||||||
sendElements.push(await SendMsgElementConstructor.ptt(path));
|
sendElements.push(await SendMsgElementConstructor.ptt(path));
|
||||||
}else if (sendMsg.type === OB11MessageDataType.image) {
|
}else if (sendMsg.type === OB11MessageDataType.image) {
|
||||||
@@ -438,8 +445,10 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
case OB11MessageDataType.json: {
|
||||||
|
sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data))
|
||||||
|
}break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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 NTQQFriendApi.handleFriendRequest(parseInt(payload.flag), payload.approve)
|
const approve = payload.approve.toString() === "true";
|
||||||
|
await NTQQFriendApi.handleFriendRequest(parseInt(payload.flag), approve)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -16,8 +16,9 @@ export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const seq = payload.flag.toString();
|
const seq = payload.flag.toString();
|
||||||
|
const approve = payload.approve.toString() === "true";
|
||||||
await NTQQGroupApi.handleGroupRequest(seq,
|
await NTQQGroupApi.handleGroupRequest(seq,
|
||||||
payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||||
payload.reason
|
payload.reason
|
||||||
)
|
)
|
||||||
return null
|
return null
|
||||||
|
@@ -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 NTQQGroupApi.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
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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 NTQQGroupApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
await NTQQGroupApi.banGroup(payload.group_id.toString(), enable)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
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 ("查无此人")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,9 @@ import {getGroup} from "../../../common/data";
|
|||||||
import {ActionName} from "../types";
|
import {ActionName} from "../types";
|
||||||
import {SendMsgElementConstructor} from "../../../ntqqapi/constructor";
|
import {SendMsgElementConstructor} from "../../../ntqqapi/constructor";
|
||||||
import {ChatType, SendFileElement} from "../../../ntqqapi/types";
|
import {ChatType, SendFileElement} from "../../../ntqqapi/types";
|
||||||
import {uri2local} from "../../utils";
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||||
|
import {uri2local} from "../../../common/utils";
|
||||||
|
|
||||||
interface Payload{
|
interface Payload{
|
||||||
group_id: number
|
group_id: number
|
||||||
|
@@ -20,7 +20,7 @@ import SendLike from "./SendLike";
|
|||||||
import SetGroupAddRequest from "./SetGroupAddRequest";
|
import SetGroupAddRequest from "./SetGroupAddRequest";
|
||||||
import SetGroupLeave from "./SetGroupLeave";
|
import SetGroupLeave from "./SetGroupLeave";
|
||||||
import GetGuildList from "./GetGuildList";
|
import GetGuildList from "./GetGuildList";
|
||||||
import Debug from "./Debug";
|
import Debug from "./llonebot/Debug";
|
||||||
import SetFriendAddRequest from "./SetFriendAddRequest";
|
import SetFriendAddRequest from "./SetFriendAddRequest";
|
||||||
import SetGroupWholeBan from "./SetGroupWholeBan";
|
import SetGroupWholeBan from "./SetGroupWholeBan";
|
||||||
import SetGroupName from "./SetGroupName";
|
import SetGroupName from "./SetGroupName";
|
||||||
@@ -36,8 +36,12 @@ import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
|||||||
import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
||||||
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
||||||
import SetQQAvatar from './llonebot/SetQQAvatar'
|
import SetQQAvatar from './llonebot/SetQQAvatar'
|
||||||
|
import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
||||||
|
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
||||||
|
import GetFile from "./GetFile";
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
|
new GetFile(),
|
||||||
new Debug(),
|
new Debug(),
|
||||||
new GetConfigAction(),
|
new GetConfigAction(),
|
||||||
new SetConfigAction(),
|
new SetConfigAction(),
|
||||||
@@ -72,9 +76,11 @@ export const actionHandlers = [
|
|||||||
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 GoCQHTTPUploadGroupFile(),
|
||||||
|
new GoCQHTTPGetGroupMsgHistory(),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
31
src/onebot11/action/llonebot/Debug.ts
Normal file
31
src/onebot11/action/llonebot/Debug.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import * as ntqqApi 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);
|
||||||
|
for (const ntqqApiClass in ntqqApi) {
|
||||||
|
const method = ntqqApi[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
|
||||||
|
}
|
||||||
|
}
|
@@ -1,9 +1,8 @@
|
|||||||
import BaseAction from "../BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "../types";
|
import {ActionName} from "../types";
|
||||||
import { uri2local } from "../../utils";
|
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||||
import {checkFileReceived} from "../../../common/utils/file";
|
import {checkFileReceived, uri2local} from "../../../common/utils/file";
|
||||||
// import { log } from "../../../common/utils";
|
// import { log } from "../../../common/utils";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
|
@@ -14,11 +14,14 @@ export interface InvalidCheckResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum ActionName {
|
export enum ActionName {
|
||||||
|
// llonebot
|
||||||
GetGroupIgnoreAddRequest = "get_group_ignore_add_request",
|
GetGroupIgnoreAddRequest = "get_group_ignore_add_request",
|
||||||
SetQQAvatar = "set_qq_avatar",
|
SetQQAvatar = "set_qq_avatar",
|
||||||
GetConfig = "get_config",
|
GetConfig = "get_config",
|
||||||
SetConfig = "set_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",
|
||||||
@@ -54,4 +57,6 @@ export enum ActionName {
|
|||||||
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_UploadGroupFile = "upload_group_file",
|
||||||
|
GoCQHTTP_DownloadFile = "download_file",
|
||||||
|
GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history",
|
||||||
}
|
}
|
@@ -16,7 +16,8 @@ import {
|
|||||||
GroupMember,
|
GroupMember,
|
||||||
IMAGE_HTTP_HOST,
|
IMAGE_HTTP_HOST,
|
||||||
RawMessage,
|
RawMessage,
|
||||||
SelfInfo, Sex,
|
SelfInfo,
|
||||||
|
Sex,
|
||||||
TipGroupElementType,
|
TipGroupElementType,
|
||||||
User
|
User
|
||||||
} from '../ntqqapi/types';
|
} from '../ntqqapi/types';
|
||||||
@@ -174,10 +175,12 @@ export class OB11Constructor {
|
|||||||
message_data["type"] = OB11MessageDataType.file;
|
message_data["type"] = OB11MessageDataType.file;
|
||||||
message_data["data"]["file"] = element.fileElement.fileName
|
message_data["data"]["file"] = element.fileElement.fileName
|
||||||
// message_data["data"]["path"] = element.fileElement.filePath
|
// message_data["data"]["path"] = element.fileElement.filePath
|
||||||
// message_data["data"]["file_id"] = element.fileElement.fileUuid
|
message_data["data"]["file_id"] = element.fileElement.fileUuid
|
||||||
message_data["data"]["file_size"] = element.fileElement.fileSize
|
message_data["data"]["file_size"] = element.fileElement.fileSize
|
||||||
dbUtil.addFileCache(element.fileElement.fileName, {
|
dbUtil.addFileCache(element.fileElement.fileUuid, {
|
||||||
|
msgId: msg.msgId,
|
||||||
fileName: element.fileElement.fileName,
|
fileName: element.fileElement.fileName,
|
||||||
|
fileUuid: element.fileElement.fileUuid,
|
||||||
filePath: element.fileElement.filePath,
|
filePath: element.fileElement.filePath,
|
||||||
fileSize: element.fileElement.fileSize,
|
fileSize: element.fileElement.fileSize,
|
||||||
downloadFunc: async () => {
|
downloadFunc: async () => {
|
||||||
@@ -251,18 +254,16 @@ export class OB11Constructor {
|
|||||||
// log("构造群增加事件", event)
|
// log("构造群增加事件", event)
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
}
|
} else if (groupElement.type === TipGroupElementType.ban) {
|
||||||
else if (groupElement.type === TipGroupElementType.ban) {
|
|
||||||
log("收到群群员禁言提示", groupElement)
|
log("收到群群员禁言提示", groupElement)
|
||||||
const memberUid = groupElement.shutUp.member.uid
|
const memberUid = groupElement.shutUp.member.uid
|
||||||
const adminUid = groupElement.shutUp.admin.uid
|
const adminUid = groupElement.shutUp.admin.uid
|
||||||
let memberUin: string = ""
|
let memberUin: string = ""
|
||||||
let duration = parseInt(groupElement.shutUp.duration)
|
let duration = parseInt(groupElement.shutUp.duration)
|
||||||
let sub_type: "ban" | "lift_ban" = duration > 0 ? "ban" : "lift_ban"
|
let sub_type: "ban" | "lift_ban" = duration > 0 ? "ban" : "lift_ban"
|
||||||
if (memberUid){
|
if (memberUid) {
|
||||||
memberUin = (await getGroupMember(msg.peerUid, memberUid))?.uin || (await NTQQUserApi.getUserDetailInfo(memberUid))?.uin
|
memberUin = (await getGroupMember(msg.peerUid, memberUid))?.uin || (await NTQQUserApi.getUserDetailInfo(memberUid))?.uin
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
memberUin = "0"; // 0表示全员禁言
|
memberUin = "0"; // 0表示全员禁言
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
duration = -1
|
duration = -1
|
||||||
@@ -273,16 +274,19 @@ export class OB11Constructor {
|
|||||||
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (element.fileElement) {
|
||||||
else if (element.fileElement){
|
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), {
|
||||||
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), {id: element.fileElement.fileUuid, name: element.fileElement.fileName, size: parseInt(element.fileElement.fileSize)})
|
id: element.fileElement.fileUuid,
|
||||||
|
name: element.fileElement.fileName,
|
||||||
|
size: parseInt(element.fileElement.fileSize)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grayTipElement) {
|
if (grayTipElement) {
|
||||||
if (grayTipElement.subElementType == GrayTipElementSubType.INVITE_NEW_MEMBER){
|
if (grayTipElement.subElementType == GrayTipElementSubType.INVITE_NEW_MEMBER) {
|
||||||
log("收到新人被邀请进群消息", grayTipElement)
|
log("收到新人被邀请进群消息", grayTipElement)
|
||||||
const xmlElement = grayTipElement.xmlElement
|
const xmlElement = grayTipElement.xmlElement
|
||||||
if (xmlElement?.content){
|
if (xmlElement?.content) {
|
||||||
const regex = /jp="(\d+)"/g;
|
const regex = /jp="(\d+)"/g;
|
||||||
|
|
||||||
let matches = [];
|
let matches = [];
|
||||||
@@ -291,7 +295,7 @@ export class OB11Constructor {
|
|||||||
while ((match = regex.exec(xmlElement.content)) !== null) {
|
while ((match = regex.exec(xmlElement.content)) !== null) {
|
||||||
matches.push(match[1]);
|
matches.push(match[1]);
|
||||||
}
|
}
|
||||||
if (matches.length === 2){
|
if (matches.length === 2) {
|
||||||
const [inviter, invitee] = matches;
|
const [inviter, invitee] = matches;
|
||||||
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
||||||
}
|
}
|
||||||
@@ -305,15 +309,16 @@ export class OB11Constructor {
|
|||||||
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +334,7 @@ export class OB11Constructor {
|
|||||||
}[role]
|
}[role]
|
||||||
}
|
}
|
||||||
|
|
||||||
static sex(sex: Sex): OB11UserSex{
|
static sex(sex: Sex): OB11UserSex {
|
||||||
const sexMap = {
|
const sexMap = {
|
||||||
[Sex.male]: OB11UserSex.male,
|
[Sex.male]: OB11UserSex.male,
|
||||||
[Sex.female]: OB11UserSex.female,
|
[Sex.female]: OB11UserSex.female,
|
||||||
@@ -337,6 +342,7 @@ export class OB11Constructor {
|
|||||||
}
|
}
|
||||||
return sexMap[sex] || 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),
|
||||||
@@ -359,6 +365,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))
|
||||||
|
@@ -6,6 +6,7 @@ import {WebSocket as WebSocketClass} from "ws";
|
|||||||
import {wsReply} from "./ws/reply";
|
import {wsReply} from "./ws/reply";
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../common/utils/log";
|
||||||
import {getConfigUtil} from "../../common/config";
|
import {getConfigUtil} from "../../common/config";
|
||||||
|
import crypto from 'crypto';
|
||||||
|
|
||||||
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
||||||
|
|
||||||
@@ -39,18 +40,26 @@ export function postOB11Event(msg: PostEventType, reportSelf = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (config.ob11.enableHttpPost) {
|
if (config.ob11.enableHttpPost) {
|
||||||
|
const msgStr = JSON.stringify(msg);
|
||||||
|
const hmac = crypto.createHmac('sha1', config.ob11.httpSecret);
|
||||||
|
hmac.update(msgStr);
|
||||||
|
const sig = hmac.digest('hex');
|
||||||
|
let headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-self-id": selfInfo.uin
|
||||||
|
}
|
||||||
|
if (config.ob11.httpSecret) {
|
||||||
|
headers["x-signature"] = "sha1=" + sig;
|
||||||
|
}
|
||||||
for (const host of config.ob11.httpHosts) {
|
for (const host of config.ob11.httpHosts) {
|
||||||
fetch(host, {
|
fetch(host, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers,
|
||||||
"Content-Type": "application/json",
|
body: msgStr
|
||||||
"x-self-id": selfInfo.uin
|
|
||||||
},
|
|
||||||
body: JSON.stringify(msg)
|
|
||||||
}).then((res: any) => {
|
}).then((res: any) => {
|
||||||
log(`新消息事件HTTP上报成功: ${host} ` + JSON.stringify(msg));
|
log(`新消息事件HTTP上报成功: ${host} ` + msgStr);
|
||||||
}, (err: any) => {
|
}, (err: any) => {
|
||||||
log(`新消息事件HTTP上报失败: ${host} ` + err + JSON.stringify(msg));
|
log(`新消息事件HTTP上报失败: ${host} `, err, msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,12 @@ import {EventType} from "./event/OB11BaseEvent";
|
|||||||
export interface OB11User {
|
export interface OB11User {
|
||||||
user_id: number;
|
user_id: number;
|
||||||
nickname: string;
|
nickname: string;
|
||||||
remark?: string
|
remark?: string;
|
||||||
|
sex?: OB11UserSex;
|
||||||
|
level?: number;
|
||||||
|
age?: number;
|
||||||
|
qid?: string;
|
||||||
|
login_days?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum OB11UserSex {
|
export enum OB11UserSex {
|
||||||
@@ -115,6 +120,7 @@ export interface OB11MessageText {
|
|||||||
|
|
||||||
interface OB11MessageFileBase {
|
interface OB11MessageFileBase {
|
||||||
data: {
|
data: {
|
||||||
|
thumb?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
file: string,
|
file: string,
|
||||||
url?: string;
|
url?: string;
|
||||||
@@ -185,12 +191,17 @@ export interface OB11MessageCustomMusic{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface OB11MessageJson {
|
||||||
|
type: OB11MessageDataType.json
|
||||||
|
data: {config: {token: string}} & any
|
||||||
|
}
|
||||||
|
|
||||||
export type OB11MessageData =
|
export type OB11MessageData =
|
||||||
OB11MessageText |
|
OB11MessageText |
|
||||||
OB11MessageFace |
|
OB11MessageFace |
|
||||||
OB11MessageAt | OB11MessageReply |
|
OB11MessageAt | OB11MessageReply |
|
||||||
OB11MessageImage | OB11MessageRecord | OB11MessageFile | OB11MessageVideo |
|
OB11MessageImage | OB11MessageRecord | OB11MessageFile | OB11MessageVideo |
|
||||||
OB11MessageNode | OB11MessageCustomMusic
|
OB11MessageNode | OB11MessageCustomMusic | OB11MessageJson
|
||||||
|
|
||||||
export interface OB11PostSendMsg {
|
export interface OB11PostSendMsg {
|
||||||
message_type?: "private" | "group"
|
message_type?: "private" | "group"
|
||||||
|
@@ -1,130 +0,0 @@
|
|||||||
import {DATA_DIR} from "../common/utils";
|
|
||||||
import {v4 as uuidv4} from "uuid";
|
|
||||||
import * as path from 'node:path';
|
|
||||||
import * as fileType from 'file-type';
|
|
||||||
import {dbUtil} from "../common/db";
|
|
||||||
import {isGIF} from "../common/utils/file";
|
|
||||||
import {log} from "../common/utils/log";
|
|
||||||
|
|
||||||
const fs = require("fs").promises;
|
|
||||||
|
|
||||||
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(DATA_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');
|
|
||||||
await fs.writeFile(filePath, buffer);
|
|
||||||
|
|
||||||
} catch (e: any) {
|
|
||||||
res.errMsg = `base64文件下载失败,` + e.toString()
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
} else if (url.protocol == "http:" || url.protocol == "https:") {
|
|
||||||
// 下载文件
|
|
||||||
let fetchRes: Response;
|
|
||||||
try{
|
|
||||||
fetchRes = await fetch(url)
|
|
||||||
}catch (e) {
|
|
||||||
res.errMsg = `${url}下载失败`
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
if (!fetchRes.ok) {
|
|
||||||
res.errMsg = `${url}下载失败,` + fetchRes.statusText
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
let blob = await fetchRes.blob();
|
|
||||||
let buffer = await blob.arrayBuffer();
|
|
||||||
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(DATA_DIR, uuidv4() + fileName)
|
|
||||||
await fs.writeFile(filePath, Buffer.from(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)
|
|
||||||
await fs.rename(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
|
|
||||||
}
|
|
@@ -5,7 +5,7 @@ import {
|
|||||||
CHANNEL_ERROR,
|
CHANNEL_ERROR,
|
||||||
CHANNEL_GET_CONFIG,
|
CHANNEL_GET_CONFIG,
|
||||||
CHANNEL_LOG,
|
CHANNEL_LOG,
|
||||||
CHANNEL_CHECKVERSION,
|
CHANNEL_CHECK_VERSION,
|
||||||
CHANNEL_SELECT_FILE,
|
CHANNEL_SELECT_FILE,
|
||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
CHANNEL_UPDATE,
|
CHANNEL_UPDATE,
|
||||||
@@ -19,18 +19,18 @@ const llonebot = {
|
|||||||
ipcRenderer.send(CHANNEL_LOG, data);
|
ipcRenderer.send(CHANNEL_LOG, data);
|
||||||
},
|
},
|
||||||
checkVersion:async (): Promise<CheckVersion> => {
|
checkVersion:async (): Promise<CheckVersion> => {
|
||||||
return ipcRenderer.invoke(CHANNEL_CHECKVERSION);
|
return ipcRenderer.invoke(CHANNEL_CHECK_VERSION);
|
||||||
},
|
},
|
||||||
updateLLOneBot:async (): Promise<boolean> => {
|
updateLLOneBot:async (): Promise<boolean> => {
|
||||||
return ipcRenderer.invoke(CHANNEL_UPDATE);
|
return ipcRenderer.invoke(CHANNEL_UPDATE);
|
||||||
},
|
},
|
||||||
setConfig: (config: Config) => {
|
setConfig: (ask: boolean, config: Config) => {
|
||||||
ipcRenderer.send(CHANNEL_SET_CONFIG, config);
|
ipcRenderer.send(CHANNEL_SET_CONFIG, ask, config);
|
||||||
},
|
},
|
||||||
getConfig: async (): Promise<Config> => {
|
getConfig: async (): Promise<Config> => {
|
||||||
return ipcRenderer.invoke(CHANNEL_GET_CONFIG);
|
return ipcRenderer.invoke(CHANNEL_GET_CONFIG);
|
||||||
},
|
},
|
||||||
getError: async (): Promise<LLOneBotError> => {
|
getError: async (): Promise<string> => {
|
||||||
return ipcRenderer.invoke(CHANNEL_ERROR);
|
return ipcRenderer.invoke(CHANNEL_ERROR);
|
||||||
},
|
},
|
||||||
selectFile: (): Promise<string> => {
|
selectFile: (): Promise<string> => {
|
||||||
|
@@ -1,11 +1,77 @@
|
|||||||
import { SettingOption } from "./option";
|
import { SettingOption } from "./option";
|
||||||
|
|
||||||
export const SettingSelect = (items: Array<{ text: string, value: string }>, configKey?: string, configValue?: any) => {
|
interface MouseEventExtend extends MouseEvent {
|
||||||
return `<setting-select ${configKey ? `data-config-key="${configKey}"` : ''}>
|
target: HTMLElement,
|
||||||
<div>
|
}
|
||||||
${items.map((e, i) => {
|
|
||||||
return SettingOption(e.text, e.value, (configKey && configValue ? configValue === e.value : i === 0));
|
// <ob-setting-select>
|
||||||
}).join('')}
|
const SelectTemplate = document.createElement('template');
|
||||||
</div>
|
SelectTemplate.innerHTML = `<style>
|
||||||
</setting-select>`;
|
.hidden { display: none !important; }
|
||||||
|
</style>
|
||||||
|
<div part="parent">
|
||||||
|
<div part="button">
|
||||||
|
<input type="text" placeholder="请选择" part="current-text" />
|
||||||
|
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" part="button-arrow">
|
||||||
|
<path d="M12 6.0001L8.00004 10L4 6" stroke="currentColor" stroke-linejoin="round"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<ul class="hidden" part="option-list"><slot></slot></ul>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
window.customElements.define('ob-setting-select', class extends HTMLElement {
|
||||||
|
readonly _button: HTMLDivElement;
|
||||||
|
readonly _text: HTMLInputElement;
|
||||||
|
readonly _context: HTMLUListElement;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.attachShadow({ mode: 'open' });
|
||||||
|
this.shadowRoot.append(SelectTemplate.content.cloneNode(true));
|
||||||
|
|
||||||
|
this._button = this.shadowRoot.querySelector('div[part="button"]');
|
||||||
|
this._text = this.shadowRoot.querySelector('input[part="current-text"]');
|
||||||
|
this._context = this.shadowRoot.querySelector('ul[part="option-list"]');
|
||||||
|
|
||||||
|
const buttonClick = () => {
|
||||||
|
const isHidden = this._context.classList.toggle('hidden');
|
||||||
|
window[`${isHidden ? 'remove': 'add'}EventListener`]('pointerdown', windowPointerDown);
|
||||||
|
};
|
||||||
|
|
||||||
|
const windowPointerDown = ({ target }) => {
|
||||||
|
if (!this.contains(target)) buttonClick();
|
||||||
|
};
|
||||||
|
|
||||||
|
this._button.addEventListener('click', buttonClick);
|
||||||
|
this._context.addEventListener('click', ({ target }: MouseEventExtend) => {
|
||||||
|
if (target.tagName !== 'SETTING-OPTION') return;
|
||||||
|
buttonClick();
|
||||||
|
|
||||||
|
if (target.hasAttribute('is-selected')) return;
|
||||||
|
|
||||||
|
this.querySelectorAll('setting-option[is-selected]').forEach(dom => dom.toggleAttribute('is-selected'));
|
||||||
|
target.toggleAttribute('is-selected');
|
||||||
|
|
||||||
|
this._text.value = target.textContent;
|
||||||
|
this.dispatchEvent(new CustomEvent('selected', {
|
||||||
|
bubbles: true,
|
||||||
|
composed: true,
|
||||||
|
detail: {
|
||||||
|
name: target.textContent,
|
||||||
|
value: target.dataset.value,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
this._text.value = this.querySelector('setting-option[is-selected]').textContent;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const SettingSelect = (items: Array<{ text: string, value: string }>, configKey?: string, configValue?: any) => {
|
||||||
|
return `<ob-setting-select ${configKey ? `data-config-key="${configKey}"` : ''}>
|
||||||
|
${items.map((e, i) => {
|
||||||
|
return SettingOption(e.text, e.value, (configKey && configValue ? configValue === e.value : i === 0));
|
||||||
|
}).join('')}
|
||||||
|
</ob-setting-select>`;
|
||||||
}
|
}
|
@@ -1,11 +1,6 @@
|
|||||||
/// <reference path="../global.d.ts" />
|
/// <reference path="../global.d.ts" />
|
||||||
import {
|
import { CheckVersion } from '../common/types';
|
||||||
SettingButton,
|
import {SettingButton, SettingItem, SettingList, SettingSwitch, SettingSelect} from './components';
|
||||||
SettingItem,
|
|
||||||
SettingList,
|
|
||||||
SettingSelect,
|
|
||||||
SettingSwitch
|
|
||||||
} from './components';
|
|
||||||
import StyleRaw from './style.css?raw';
|
import StyleRaw from './style.css?raw';
|
||||||
|
|
||||||
// 打开设置界面时触发
|
// 打开设置界面时触发
|
||||||
@@ -14,7 +9,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
window.llonebot.log("setting window created");
|
window.llonebot.log("setting window created");
|
||||||
const isEmpty = (value: any) => value === undefined || value === null || value === '';
|
const isEmpty = (value: any) => value === undefined || value === null || value === '';
|
||||||
let config = await window.llonebot.getConfig();
|
let config = await window.llonebot.getConfig();
|
||||||
let ob11Config = { ...config.ob11 };
|
let ob11Config = {...config.ob11};
|
||||||
const setConfig = (key: string, value: any) => {
|
const setConfig = (key: string, value: any) => {
|
||||||
const configKey = key.split('.');
|
const configKey = key.split('.');
|
||||||
|
|
||||||
@@ -25,8 +20,8 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
if (configKey.length === 2) config[configKey[0]][configKey[1]] = value;
|
if (configKey.length === 2) config[configKey[0]][configKey[1]] = value;
|
||||||
else config[key] = value;
|
else config[key] = value;
|
||||||
|
|
||||||
if (!['heartInterval', 'token', 'ffmpeg'].includes(key)){
|
if (!['heartInterval', 'token', 'ffmpeg'].includes(key)) {
|
||||||
window.llonebot.setConfig(config);
|
window.llonebot.setConfig(false, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -35,18 +30,39 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
const doc = parser.parseFromString([
|
const doc = parser.parseFromString([
|
||||||
'<div>',
|
'<div>',
|
||||||
`<style>${StyleRaw}</style>`,
|
`<style>${StyleRaw}</style>`,
|
||||||
|
`<setting-section>
|
||||||
|
<setting-panel>
|
||||||
|
<setting-list data-direction="column" class="new">
|
||||||
|
<setting-item data-direction="row">
|
||||||
|
<setting-text class="llonebot-update-title">正在检查LLOneBot版本中</setting-text>
|
||||||
|
<setting-button data-type="secondary" class="llonebot-update-button">请稍后</setting-button>
|
||||||
|
</setting-item>
|
||||||
|
</setting-list>
|
||||||
|
</setting-panel>
|
||||||
|
<setting-section>`,
|
||||||
|
SettingList([
|
||||||
|
'<div id="llonebot-error" class="llonebot-error"></div>',
|
||||||
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem('启用 HTTP 服务', null,
|
SettingItem('启用 HTTP 服务', null,
|
||||||
SettingSwitch('ob11.enableHttp', config.ob11.enableHttp, { 'control-display-id': 'config-ob11-httpPort' }),
|
SettingSwitch('ob11.enableHttp', config.ob11.enableHttp, {'control-display-id': 'config-ob11-httpPort'}),
|
||||||
),
|
),
|
||||||
SettingItem('HTTP 服务监听端口', null,
|
SettingItem('HTTP 服务监听端口', null,
|
||||||
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.httpPort" type="number" min="1" max="65534" value="${config.ob11.httpPort}" placeholder="${config.ob11.httpPort}" /></div>`,
|
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.httpPort" type="number" min="1" max="65534" value="${config.ob11.httpPort}" placeholder="${config.ob11.httpPort}" /></div>`,
|
||||||
'config-ob11-httpPort', config.ob11.enableHttp
|
'config-ob11-httpPort', config.ob11.enableHttp
|
||||||
),
|
),
|
||||||
SettingItem('启用 HTTP 事件上报', null,
|
SettingItem('启用 HTTP 事件上报', null,
|
||||||
SettingSwitch('ob11.enableHttpPost', config.ob11.enableHttpPost, { 'control-display-id': 'config-ob11-httpHosts' }),
|
SettingSwitch('ob11.enableHttpPost', config.ob11.enableHttpPost, {'control-display-id': 'config-ob11-httpHosts'}),
|
||||||
),
|
),
|
||||||
`<div class="config-host-list" id="config-ob11-httpHosts" ${config.ob11.enableHttpPost ? '' : 'is-hidden'}>
|
`<div class="config-host-list" id="config-ob11-httpHosts" ${config.ob11.enableHttpPost ? '' : 'is-hidden'}>
|
||||||
|
<setting-item data-direction="row">
|
||||||
|
<div>
|
||||||
|
<setting-text>HTTP 事件上报密钥</setting-text>
|
||||||
|
</div>
|
||||||
|
<div class="q-input">
|
||||||
|
<input id="config-ob11-httpSecret" class="q-input__inner" data-config-key="ob11.httpSecret" type="text" value="${config.ob11.httpSecret}" placeholder="未设置" />
|
||||||
|
</div>
|
||||||
|
</setting-item>
|
||||||
<setting-item data-direction="row">
|
<setting-item data-direction="row">
|
||||||
<div>
|
<div>
|
||||||
<setting-text>HTTP 事件上报地址</setting-text>
|
<setting-text>HTTP 事件上报地址</setting-text>
|
||||||
@@ -56,14 +72,14 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
<div id="config-ob11-httpHosts-list"></div>
|
<div id="config-ob11-httpHosts-list"></div>
|
||||||
</div>`,
|
</div>`,
|
||||||
SettingItem('启用正向 WebSocket 服务', null,
|
SettingItem('启用正向 WebSocket 服务', null,
|
||||||
SettingSwitch('ob11.enableWs', config.ob11.enableWs, { 'control-display-id': 'config-ob11-wsPort' }),
|
SettingSwitch('ob11.enableWs', config.ob11.enableWs, {'control-display-id': 'config-ob11-wsPort'}),
|
||||||
),
|
),
|
||||||
SettingItem('正向 WebSocket 服务监听端口', null,
|
SettingItem('正向 WebSocket 服务监听端口', null,
|
||||||
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.wsPort" type="number" min="1" max="65534" value="${config.ob11.wsPort}" placeholder="${config.ob11.wsPort}" /></div>`,
|
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.wsPort" type="number" min="1" max="65534" value="${config.ob11.wsPort}" placeholder="${config.ob11.wsPort}" /></div>`,
|
||||||
'config-ob11-wsPort', config.ob11.enableWs
|
'config-ob11-wsPort', config.ob11.enableWs
|
||||||
),
|
),
|
||||||
SettingItem('启用反向 WebSocket 服务', null,
|
SettingItem('启用反向 WebSocket 服务', null,
|
||||||
SettingSwitch('ob11.enableWsReverse', config.ob11.enableWsReverse, { 'control-display-id': 'config-ob11-wsHosts' }),
|
SettingSwitch('ob11.enableWsReverse', config.ob11.enableWsReverse, {'control-display-id': 'config-ob11-wsHosts'}),
|
||||||
),
|
),
|
||||||
`<div class="config-host-list" id="config-ob11-wsHosts" ${config.ob11.enableWsReverse ? '' : 'is-hidden'}>
|
`<div class="config-host-list" id="config-ob11-wsHosts" ${config.ob11.enableWsReverse ? '' : 'is-hidden'}>
|
||||||
<setting-item data-direction="row">
|
<setting-item data-direction="row">
|
||||||
@@ -82,11 +98,11 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="token" type="text" value="${config.token}" placeholder="未设置" /></div>`,
|
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="token" type="text" value="${config.token}" placeholder="未设置" /></div>`,
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'消息上报格式类型',
|
'启用CQ码上报格式,不启用则为消息段格式',
|
||||||
'如客户端无特殊需求推荐保持默认设置,两者的详细差异可参考 <a href="javascript:LiteLoader.api.openExternal(\'https://github.com/botuniverse/onebot-11/tree/master/message#readme\');">OneBot v11 文档</a>',
|
'如客户端无特殊需求推荐保持默认设置,两者的详细差异可参考 <a href="javascript:LiteLoader.api.openExternal(\'https://github.com/botuniverse/onebot-11/tree/master/message#readme\');">OneBot v11 文档</a>',
|
||||||
SettingSelect([
|
SettingSelect([
|
||||||
{ text: '消息段', value: 'array' },
|
{text: '消息段', value: 'array'},
|
||||||
{ text: 'CQ码', value: 'string' },
|
{text: 'CQ码', value: 'string'},
|
||||||
], 'ob11.messagePostFormat', config.ob11.messagePostFormat),
|
], 'ob11.messagePostFormat', config.ob11.messagePostFormat),
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
@@ -122,7 +138,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'自动删除收到的文件',
|
'自动删除收到的文件',
|
||||||
'在收到文件后的指定时间内删除该文件',
|
'在收到文件后的指定时间内删除该文件',
|
||||||
SettingSwitch('autoDeleteFile', config.autoDeleteFile, { 'control-display-id': 'config-auto-delete-file-second' }),
|
SettingSwitch('autoDeleteFile', config.autoDeleteFile, {'control-display-id': 'config-auto-delete-file-second'}),
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'自动删除文件时间',
|
'自动删除文件时间',
|
||||||
@@ -166,6 +182,18 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
'</div>',
|
'</div>',
|
||||||
].join(''), "text/html");
|
].join(''), "text/html");
|
||||||
|
|
||||||
|
let errorEle = <HTMLElement>doc.querySelector("#llonebot-error");
|
||||||
|
errorEle.style.display = 'none';
|
||||||
|
const showError = async () => {
|
||||||
|
setTimeout(async () => {
|
||||||
|
let errMessage = await window.llonebot.getError();
|
||||||
|
console.log(errMessage)
|
||||||
|
errMessage = errMessage.replace(/\n/g, '<br>')
|
||||||
|
errorEle.innerHTML = errMessage;
|
||||||
|
errorEle.style.display = errMessage ? 'flex' : 'none';
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
showError().then()
|
||||||
// 外链按钮
|
// 外链按钮
|
||||||
doc.querySelector('#open-github').addEventListener('click', () => {
|
doc.querySelector('#open-github').addEventListener('click', () => {
|
||||||
window.LiteLoader.api.openExternal('https://github.com/LLOneBot/LLOneBot')
|
window.LiteLoader.api.openExternal('https://github.com/LLOneBot/LLOneBot')
|
||||||
@@ -180,7 +208,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
window.LiteLoader.api.openExternal('https://llonebot.github.io/')
|
window.LiteLoader.api.openExternal('https://llonebot.github.io/')
|
||||||
})
|
})
|
||||||
// 生成反向地址列表
|
// 生成反向地址列表
|
||||||
const buildHostListItem = (type: string, host: string, index: number, inputAttrs: any={}) => {
|
const buildHostListItem = (type: string, host: string, index: number, inputAttrs: any = {}) => {
|
||||||
const dom = {
|
const dom = {
|
||||||
container: document.createElement('setting-item'),
|
container: document.createElement('setting-item'),
|
||||||
input: document.createElement('input'),
|
input: document.createElement('input'),
|
||||||
@@ -212,7 +240,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
|
|
||||||
return dom.container;
|
return dom.container;
|
||||||
};
|
};
|
||||||
const buildHostList = (hosts: string[], type: string, inputAttr: any={}) => {
|
const buildHostList = (hosts: string[], type: string, inputAttr: any = {}) => {
|
||||||
const result: HTMLElement[] = [];
|
const result: HTMLElement[] = [];
|
||||||
|
|
||||||
hosts.forEach((host, index) => {
|
hosts.forEach((host, index) => {
|
||||||
@@ -221,14 +249,14 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
const addReverseHost = (type: string, doc: Document = document, inputAttr: any={}) => {
|
const addReverseHost = (type: string, doc: Document = document, inputAttr: any = {}) => {
|
||||||
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`);
|
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`);
|
||||||
hostContainerDom.appendChild(buildHostListItem(type, '', ob11Config[type].length, inputAttr));
|
hostContainerDom.appendChild(buildHostListItem(type, '', ob11Config[type].length, inputAttr));
|
||||||
ob11Config[type].push('');
|
ob11Config[type].push('');
|
||||||
};
|
};
|
||||||
const initReverseHost = (type: string, doc: Document = document) => {
|
const initReverseHost = (type: string, doc: Document = document) => {
|
||||||
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`);
|
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`);
|
||||||
[ ...hostContainerDom.childNodes ].forEach(dom => dom.remove());
|
[...hostContainerDom.childNodes].forEach(dom => dom.remove());
|
||||||
buildHostList(ob11Config[type], type).forEach(dom => {
|
buildHostList(ob11Config[type], type).forEach(dom => {
|
||||||
hostContainerDom.appendChild(dom);
|
hostContainerDom.appendChild(dom);
|
||||||
});
|
});
|
||||||
@@ -236,8 +264,8 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
initReverseHost('httpHosts', doc);
|
initReverseHost('httpHosts', doc);
|
||||||
initReverseHost('wsHosts', doc);
|
initReverseHost('wsHosts', doc);
|
||||||
|
|
||||||
doc.querySelector('#config-ob11-httpHosts-add').addEventListener('click', () => addReverseHost('httpHosts', document, {'placeholder': '如:http://127.0.0.1:5140/onebot' }));
|
doc.querySelector('#config-ob11-httpHosts-add').addEventListener('click', () => addReverseHost('httpHosts', document, {'placeholder': '如:http://127.0.0.1:5140/onebot'}));
|
||||||
doc.querySelector('#config-ob11-wsHosts-add').addEventListener('click', () => addReverseHost('wsHosts', document, {'placeholder': '如:ws://127.0.0.1:5140/onebot' }));
|
doc.querySelector('#config-ob11-wsHosts-add').addEventListener('click', () => addReverseHost('wsHosts', document, {'placeholder': '如:ws://127.0.0.1:5140/onebot'}));
|
||||||
|
|
||||||
doc.querySelector('#config-ffmpeg-select').addEventListener('click', () => {
|
doc.querySelector('#config-ffmpeg-select').addEventListener('click', () => {
|
||||||
window.llonebot.selectFile()
|
window.llonebot.selectFile()
|
||||||
@@ -283,7 +311,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 下拉框
|
// 下拉框
|
||||||
doc.querySelectorAll('setting-select').forEach((dom: HTMLElement) => {
|
doc.querySelectorAll('ob-setting-select[data-config-key]').forEach((dom: HTMLElement) => {
|
||||||
dom.addEventListener('selected', (e: CustomEvent) => {
|
dom.addEventListener('selected', (e: CustomEvent) => {
|
||||||
const configKey = dom.dataset.configKey;
|
const configKey = dom.dataset.configKey;
|
||||||
const configValue = e.detail.value;
|
const configValue = e.detail.value;
|
||||||
@@ -296,28 +324,69 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
doc.querySelector('#config-ob11-save').addEventListener('click', () => {
|
doc.querySelector('#config-ob11-save').addEventListener('click', () => {
|
||||||
config.ob11 = ob11Config;
|
config.ob11 = ob11Config;
|
||||||
|
|
||||||
window.llonebot.setConfig(config);
|
window.llonebot.setConfig(false, config);
|
||||||
|
// window.location.reload();
|
||||||
|
showError().then()
|
||||||
alert('保存成功');
|
alert('保存成功');
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.body.childNodes.forEach(node => {
|
doc.body.childNodes.forEach(node => {
|
||||||
view.appendChild(node);
|
view.appendChild(node);
|
||||||
});
|
});
|
||||||
|
// 更新逻辑
|
||||||
|
async function checkVersionFunc(ResultVersion: CheckVersion) {
|
||||||
|
console.log(ResultVersion);
|
||||||
|
if (ResultVersion.version === "") {
|
||||||
|
view.querySelector(".llonebot-update-title").innerHTML = "检查更新失败";
|
||||||
|
view.querySelector(".llonebot-update-button").innerHTML = "点击重试";
|
||||||
|
view.querySelector(".llonebot-update-button").addEventListener("click", async () => {
|
||||||
|
window.llonebot.checkVersion().then(checkVersionFunc);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ResultVersion.result) {
|
||||||
|
view.querySelector(".llonebot-update-title").innerHTML = "当前已是最新版本 V" + ResultVersion.version;
|
||||||
|
view.querySelector(".llonebot-update-button").innerHTML = "无需更新";
|
||||||
|
} else {
|
||||||
|
view.querySelector(".llonebot-update-title").innerHTML = "已检测到最新版本 V" + ResultVersion.version;
|
||||||
|
view.querySelector(".llonebot-update-button").innerHTML = "点击更新";
|
||||||
|
const update = async () => {
|
||||||
|
view.querySelector(".llonebot-update-button").innerHTML = "正在更新中...";
|
||||||
|
const result = await window.llonebot.updateLLOneBot();
|
||||||
|
if (result) {
|
||||||
|
view.querySelector(".llonebot-update-button").innerHTML = "更新完成请重启";
|
||||||
|
view.querySelector(".llonebot-update-button").removeEventListener("click", update);
|
||||||
|
} else {
|
||||||
|
view.querySelector(".llonebot-update-button").innerHTML = "更新失败前往仓库下载";
|
||||||
|
view.querySelector(".llonebot-update-button").removeEventListener("click", update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
view.querySelector(".llonebot-update-button").addEventListener("click", update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.llonebot.checkVersion().then(checkVersionFunc);
|
||||||
|
window.addEventListener('beforeunload', (event) => {
|
||||||
|
if (JSON.stringify(ob11Config) === JSON.stringify(config.ob11)) return;
|
||||||
|
config.ob11 = ob11Config;
|
||||||
|
window.llonebot.setConfig(true, config);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function init () {
|
function init() {
|
||||||
const hash = location.hash
|
const hash = location.hash
|
||||||
if (hash === '#/blank') {
|
if (hash === '#/blank') {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location.hash === '#/blank') {
|
if (location.hash === '#/blank') {
|
||||||
(window as any).navigation.addEventListener('navigatesuccess', init, { once: true })
|
(window as any).navigation.addEventListener('navigatesuccess', init, {once: true})
|
||||||
} else {
|
} else {
|
||||||
init()
|
init()
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
onSettingWindowCreated
|
onSettingWindowCreated
|
||||||
}
|
}
|
||||||
|
@@ -62,3 +62,104 @@ setting-item a:active,
|
|||||||
setting-item a:visited {
|
setting-item a:visited {
|
||||||
color: var(--text-link);
|
color: var(--text-link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ob-setting-select {
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ob-setting-select,
|
||||||
|
ob-setting-select::part(parent),
|
||||||
|
ob-setting-select::part(button) {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
height: 24px;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 24px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
ob-setting-select::part(button) {
|
||||||
|
display: flex;
|
||||||
|
padding: 0px 8px;
|
||||||
|
background-color: transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid var(--border_dark);
|
||||||
|
z-index: 5;
|
||||||
|
cursor: default;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
ob-setting-select::part(current-text) {
|
||||||
|
display: block;
|
||||||
|
margin-right: 8px;
|
||||||
|
padding: 0px;
|
||||||
|
background: none;
|
||||||
|
background-color: transparent;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text_primary);
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
border-radius: 0px;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
overflow: hidden;
|
||||||
|
appearance: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
cursor: default;
|
||||||
|
flex: 1;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-moz-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
-o-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-pointer-events: none;
|
||||||
|
-moz-pointer-events: none;
|
||||||
|
-ms-pointer-events: none;
|
||||||
|
-o-pointer-events: none;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
ob-setting-select::part(button-arrow) {
|
||||||
|
position: relative;
|
||||||
|
display: block;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
color: var(--icon_primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
ob-setting-select::part(option-list) {
|
||||||
|
display: flex;
|
||||||
|
position: absolute;
|
||||||
|
top: 100%;
|
||||||
|
padding: 4px;
|
||||||
|
margin: 5px 0px;
|
||||||
|
width: 100%;
|
||||||
|
max-height: var(--q-contextmenu-max-height);
|
||||||
|
background-color: var(--blur_middle_standard);
|
||||||
|
background-clip: padding-box;
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
font-size: 12px;
|
||||||
|
box-shadow: var(--shadow_bg_middle_secondary);
|
||||||
|
border: 1px solid var(--border_secondary);
|
||||||
|
border-radius: 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
app-region: no-drag;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: auto;
|
||||||
|
list-style: none;
|
||||||
|
z-index: 999;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
justify-content: flex-start;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#llonebot-error {
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
overflow: visible;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const version = "3.16.1"
|
export const version = "3.18.3"
|
Reference in New Issue
Block a user