mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5ff6ceec6d | ||
![]() |
17af156451 | ||
![]() |
c3c9e74832 | ||
![]() |
0480208738 | ||
![]() |
62eefbdb69 | ||
![]() |
566537cbe3 | ||
![]() |
ed831ae4cd | ||
![]() |
501031b39b | ||
![]() |
7bfb3f2003 | ||
![]() |
ba8ed36c6a | ||
![]() |
55d046b4f9 | ||
![]() |
ac417cedd3 | ||
![]() |
ade509f26d | ||
![]() |
a66c1a9779 | ||
![]() |
239cf18887 |
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 4,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot v3.13.1",
|
"name": "LLOneBot v3.13.8",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "3.13.1",
|
"version": "3.13.8",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
194
package-lock.json
generated
194
package-lock.json
generated
@@ -986,16 +986,6 @@
|
|||||||
"url": "https://opencollective.com/eslint"
|
"url": "https://opencollective.com/eslint"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@eslint/eslintrc/node_modules/brace-expansion": {
|
|
||||||
"version": "1.1.11",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"balanced-match": "^1.0.0",
|
|
||||||
"concat-map": "0.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@eslint/eslintrc/node_modules/globals": {
|
"node_modules/@eslint/eslintrc/node_modules/globals": {
|
||||||
"version": "13.24.0",
|
"version": "13.24.0",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/globals/-/globals-13.24.0.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/globals/-/globals-13.24.0.tgz",
|
||||||
@@ -1011,18 +1001,6 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@eslint/eslintrc/node_modules/minimatch": {
|
|
||||||
"version": "3.1.2",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/minimatch/-/minimatch-3.1.2.tgz",
|
|
||||||
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"brace-expansion": "^1.1.7"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@eslint/eslintrc/node_modules/type-fest": {
|
"node_modules/@eslint/eslintrc/node_modules/type-fest": {
|
||||||
"version": "0.20.2",
|
"version": "0.20.2",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/type-fest/-/type-fest-0.20.2.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/type-fest/-/type-fest-0.20.2.tgz",
|
||||||
@@ -1058,28 +1036,6 @@
|
|||||||
"node": ">=10.10.0"
|
"node": ">=10.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@humanwhocodes/config-array/node_modules/brace-expansion": {
|
|
||||||
"version": "1.1.11",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"balanced-match": "^1.0.0",
|
|
||||||
"concat-map": "0.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@humanwhocodes/config-array/node_modules/minimatch": {
|
|
||||||
"version": "3.1.2",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/minimatch/-/minimatch-3.1.2.tgz",
|
|
||||||
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"brace-expansion": "^1.1.7"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@humanwhocodes/module-importer": {
|
"node_modules/@humanwhocodes/module-importer": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz",
|
||||||
@@ -3225,16 +3181,6 @@
|
|||||||
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8"
|
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint-plugin-import/node_modules/brace-expansion": {
|
|
||||||
"version": "1.1.11",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"balanced-match": "^1.0.0",
|
|
||||||
"concat-map": "0.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/eslint-plugin-import/node_modules/debug": {
|
"node_modules/eslint-plugin-import/node_modules/debug": {
|
||||||
"version": "3.2.7",
|
"version": "3.2.7",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/debug/-/debug-3.2.7.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/debug/-/debug-3.2.7.tgz",
|
||||||
@@ -3256,18 +3202,6 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint-plugin-import/node_modules/minimatch": {
|
|
||||||
"version": "3.1.2",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/minimatch/-/minimatch-3.1.2.tgz",
|
|
||||||
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"brace-expansion": "^1.1.7"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/eslint-plugin-n": {
|
"node_modules/eslint-plugin-n": {
|
||||||
"version": "16.6.2",
|
"version": "16.6.2",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/eslint-plugin-n/-/eslint-plugin-n-16.6.2.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/eslint-plugin-n/-/eslint-plugin-n-16.6.2.tgz",
|
||||||
@@ -3296,16 +3230,6 @@
|
|||||||
"eslint": ">=7.0.0"
|
"eslint": ">=7.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint-plugin-n/node_modules/brace-expansion": {
|
|
||||||
"version": "1.1.11",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"balanced-match": "^1.0.0",
|
|
||||||
"concat-map": "0.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/eslint-plugin-n/node_modules/globals": {
|
"node_modules/eslint-plugin-n/node_modules/globals": {
|
||||||
"version": "13.24.0",
|
"version": "13.24.0",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/globals/-/globals-13.24.0.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/globals/-/globals-13.24.0.tgz",
|
||||||
@@ -3321,18 +3245,6 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint-plugin-n/node_modules/minimatch": {
|
|
||||||
"version": "3.1.2",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/minimatch/-/minimatch-3.1.2.tgz",
|
|
||||||
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"brace-expansion": "^1.1.7"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/eslint-plugin-n/node_modules/semver": {
|
"node_modules/eslint-plugin-n/node_modules/semver": {
|
||||||
"version": "7.6.0",
|
"version": "7.6.0",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/semver/-/semver-7.6.0.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/semver/-/semver-7.6.0.tgz",
|
||||||
@@ -3384,16 +3296,6 @@
|
|||||||
"url": "https://opencollective.com/eslint"
|
"url": "https://opencollective.com/eslint"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint/node_modules/brace-expansion": {
|
|
||||||
"version": "1.1.11",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"balanced-match": "^1.0.0",
|
|
||||||
"concat-map": "0.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/eslint/node_modules/eslint-scope": {
|
"node_modules/eslint/node_modules/eslint-scope": {
|
||||||
"version": "7.2.2",
|
"version": "7.2.2",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/eslint-scope/-/eslint-scope-7.2.2.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/eslint-scope/-/eslint-scope-7.2.2.tgz",
|
||||||
@@ -3477,18 +3379,6 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint/node_modules/minimatch": {
|
|
||||||
"version": "3.1.2",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/minimatch/-/minimatch-3.1.2.tgz",
|
|
||||||
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"brace-expansion": "^1.1.7"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/eslint/node_modules/p-limit": {
|
"node_modules/eslint/node_modules/p-limit": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/p-limit/-/p-limit-3.1.0.tgz",
|
"resolved": "https://mirrors.cloud.tencent.com/npm/p-limit/-/p-limit-3.1.0.tgz",
|
||||||
@@ -4012,6 +3902,26 @@
|
|||||||
"url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
|
"url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/glob": {
|
||||||
|
"version": "7.2.3",
|
||||||
|
"resolved": "https://mirrors.cloud.tencent.com/npm/glob/-/glob-7.2.3.tgz",
|
||||||
|
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"fs.realpath": "^1.0.0",
|
||||||
|
"inflight": "^1.0.4",
|
||||||
|
"inherits": "2",
|
||||||
|
"minimatch": "^3.1.1",
|
||||||
|
"once": "^1.3.0",
|
||||||
|
"path-is-absolute": "^1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/glob-parent": {
|
"node_modules/glob-parent": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
||||||
@@ -4922,6 +4832,28 @@
|
|||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/minimatch": {
|
||||||
|
"version": "3.1.2",
|
||||||
|
"resolved": "https://mirrors.cloud.tencent.com/npm/minimatch/-/minimatch-3.1.2.tgz",
|
||||||
|
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"brace-expansion": "^1.1.7"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/minimatch/node_modules/brace-expansion": {
|
||||||
|
"version": "1.1.11",
|
||||||
|
"resolved": "https://mirrors.cloud.tencent.com/npm/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
|
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"balanced-match": "^1.0.0",
|
||||||
|
"concat-map": "0.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/minimist": {
|
"node_modules/minimist": {
|
||||||
"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",
|
||||||
@@ -5509,48 +5441,6 @@
|
|||||||
"url": "https://github.com/sponsors/isaacs"
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/rimraf/node_modules/brace-expansion": {
|
|
||||||
"version": "1.1.11",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"balanced-match": "^1.0.0",
|
|
||||||
"concat-map": "0.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/rimraf/node_modules/glob": {
|
|
||||||
"version": "7.2.3",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/glob/-/glob-7.2.3.tgz",
|
|
||||||
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"fs.realpath": "^1.0.0",
|
|
||||||
"inflight": "^1.0.4",
|
|
||||||
"inherits": "2",
|
|
||||||
"minimatch": "^3.1.1",
|
|
||||||
"once": "^1.3.0",
|
|
||||||
"path-is-absolute": "^1.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"url": "https://github.com/sponsors/isaacs"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/rimraf/node_modules/minimatch": {
|
|
||||||
"version": "3.1.2",
|
|
||||||
"resolved": "https://mirrors.cloud.tencent.com/npm/minimatch/-/minimatch-3.1.2.tgz",
|
|
||||||
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"brace-expansion": "^1.1.7"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/roarr": {
|
"node_modules/roarr": {
|
||||||
"version": "2.15.4",
|
"version": "2.15.4",
|
||||||
"resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.4.tgz",
|
"resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.4.tgz",
|
||||||
|
@@ -4,6 +4,8 @@ import {mergeNewProperties} from "./utils";
|
|||||||
|
|
||||||
export const HOOK_LOG = false;
|
export const HOOK_LOG = false;
|
||||||
|
|
||||||
|
export const ALLOW_SEND_TEMP_MSG = false;
|
||||||
|
|
||||||
export class ConfigUtil {
|
export class ConfigUtil {
|
||||||
private readonly configPath: string;
|
private readonly configPath: string;
|
||||||
private config: Config | null = null;
|
private config: Config | null = null;
|
||||||
|
@@ -11,6 +11,7 @@ import {
|
|||||||
import {type FileCache, type LLOneBotError} from './types'
|
import {type FileCache, type LLOneBotError} from './types'
|
||||||
import {dbUtil} from "./db";
|
import {dbUtil} from "./db";
|
||||||
import {raw} from "express";
|
import {raw} from "express";
|
||||||
|
import {log} from "./utils";
|
||||||
|
|
||||||
export const selfInfo: SelfInfo = {
|
export const selfInfo: SelfInfo = {
|
||||||
uid: '',
|
uid: '',
|
||||||
@@ -27,31 +28,34 @@ export const llonebotError: LLOneBotError = {
|
|||||||
otherError: ''
|
otherError: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fileCache = new Map<string, FileCache>()
|
|
||||||
|
|
||||||
|
export async function getFriend(qq: string, uid: string = ""): Promise<Friend | undefined> {
|
||||||
export async function getHistoryMsgByShortId(shortId: number) {
|
let filterKey = uid ? "uid" : "uin"
|
||||||
// log("getHistoryMsgByShortId", shortId, Object.values(msgHistory).map(m=>m.msgShortId))
|
let filterValue = uid ? uid : qq
|
||||||
return await dbUtil.getMsgByShortId(shortId);
|
let friend = friends.find(friend => friend[filterKey] === filterValue.toString())
|
||||||
}
|
// if (!friend) {
|
||||||
|
// try {
|
||||||
export async function getFriend(qq: string): Promise<Friend | undefined> {
|
// friends = (await NTQQApi.getFriends(true))
|
||||||
let friend = friends.find(friend => friend.uin === qq)
|
// friend = friends.find(friend => friend[filterKey] === filterValue.toString())
|
||||||
if (!friend){
|
// } catch (e) {
|
||||||
friends = (await NTQQApi.getFriends(true))
|
// // log("刷新好友列表失败", e.stack.toString())
|
||||||
friend = friends.find(friend => friend.uin === qq)
|
// }
|
||||||
}
|
// }
|
||||||
return friend
|
return friend
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGroup(qq: string): Promise<Group | undefined> {
|
export async function getGroup(qq: string): Promise<Group | undefined> {
|
||||||
let group = groups.find(group => group.groupCode === qq)
|
let group = groups.find(group => group.groupCode === qq.toString())
|
||||||
if (!group){
|
if (!group) {
|
||||||
const _groups = await NTQQApi.getGroups(true);
|
try {
|
||||||
group = _groups.find(group => group.groupCode === qq)
|
const _groups = await NTQQApi.getGroups(true);
|
||||||
if (group){
|
group = _groups.find(group => group.groupCode === qq.toString())
|
||||||
groups.push(group)
|
if (group) {
|
||||||
|
groups.push(group)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
@@ -63,18 +67,20 @@ export async function getGroupMember(groupQQ: string | number, memberQQ: string
|
|||||||
}
|
}
|
||||||
const group = await getGroup(groupQQ)
|
const group = await getGroup(groupQQ)
|
||||||
if (group) {
|
if (group) {
|
||||||
let filterFunc: (member: GroupMember) => boolean
|
const filterKey = memberQQ ? "uin" : "uid"
|
||||||
if (memberQQ) {
|
const filterValue = memberQQ ? memberQQ : memberUid
|
||||||
filterFunc = member => member.uin === memberQQ
|
let filterFunc: (member: GroupMember) => boolean = member => member[filterKey] === filterValue
|
||||||
} else if (memberUid) {
|
|
||||||
filterFunc = member => member.uid === memberUid
|
|
||||||
}
|
|
||||||
let member = group.members?.find(filterFunc)
|
let member = group.members?.find(filterFunc)
|
||||||
if (!member) {
|
if (!member) {
|
||||||
const _members = await NTQQApi.getGroupMembers(groupQQ)
|
try {
|
||||||
if (_members.length > 0) {
|
const _members = await NTQQApi.getGroupMembers(groupQQ)
|
||||||
group.members = _members
|
if (_members.length > 0) {
|
||||||
|
group.members = _members
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// log("刷新群成员列表失败", e.stack.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
member = group.members?.find(filterFunc)
|
member = group.members?.find(filterFunc)
|
||||||
}
|
}
|
||||||
return member
|
return member
|
||||||
|
111
src/common/db.ts
111
src/common/db.ts
@@ -1,22 +1,25 @@
|
|||||||
// import {DATA_DIR} from "./utils";
|
|
||||||
import {Level} from "level";
|
import {Level} from "level";
|
||||||
import {RawMessage} from "../ntqqapi/types";
|
import {RawMessage} from "../ntqqapi/types";
|
||||||
import {DATA_DIR, log} from "./utils";
|
import {DATA_DIR, log} from "./utils";
|
||||||
import {selfInfo} from "./data";
|
import {selfInfo} from "./data";
|
||||||
|
import {FileCache} from "./types";
|
||||||
|
|
||||||
|
|
||||||
class DBUtil {
|
class DBUtil {
|
||||||
private readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
private readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
||||||
private readonly DB_KEY_PREFIX_MSG_SHORT_ID = "msg_short_id_";
|
private readonly DB_KEY_PREFIX_MSG_SHORT_ID = "msg_short_id_";
|
||||||
private readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
private readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
||||||
|
private readonly DB_KEY_PREFIX_FILE = "file_";
|
||||||
private db: Level;
|
private db: Level;
|
||||||
private cache: Record<string, RawMessage> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
private cache: Record<string, RawMessage | string | FileCache> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
||||||
|
private currentShortId: number;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 数据库结构
|
* 数据库结构
|
||||||
* msg_id_101231230999: {} // 长id: RawMessage
|
* msg_id_101231230999: {} // 长id: RawMessage
|
||||||
* msg_short_id_1: 101231230999 // 短id: 长id
|
* msg_short_id_1: 101231230999 // 短id: 长id
|
||||||
* msg_seq_id_1: 101231230999 // 序列id: 长id
|
* msg_seq_id_1: 101231230999 // 序列id: 长id
|
||||||
|
* file_7827DBAFJFW2323.png: {} // 文件名: FileCache
|
||||||
* */
|
* */
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -24,9 +27,9 @@ class DBUtil {
|
|||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const initDB = () => {
|
const initDB = () => {
|
||||||
initCount++;
|
initCount++;
|
||||||
if (initCount > 50) {
|
// if (initCount > 50) {
|
||||||
return reject("init db fail")
|
// return reject("init db fail")
|
||||||
}
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!selfInfo.uin) {
|
if (!selfInfo.uin) {
|
||||||
@@ -38,7 +41,7 @@ class DBUtil {
|
|||||||
console.log("llonebot init db success")
|
console.log("llonebot init db success")
|
||||||
resolve(null)
|
resolve(null)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// console.log("init db fail", e.stack.toString())
|
console.log("init db fail", e.stack.toString())
|
||||||
setTimeout(initDB, 300);
|
setTimeout(initDB, 300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,13 +56,13 @@ class DBUtil {
|
|||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + msg.msgShortId
|
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + msg.msgShortId
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq
|
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq
|
||||||
this.cache[longIdKey] = this.cache[shortIdKey] = this.cache[seqIdKey] = msg
|
this.cache[longIdKey] = this.cache[shortIdKey] = msg
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMsgByShortId(shortMsgId: number): Promise<RawMessage> {
|
async getMsgByShortId(shortMsgId: number): Promise<RawMessage> {
|
||||||
const shortMsgIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
const shortMsgIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
||||||
if (this.cache[shortMsgIdKey]) {
|
if (this.cache[shortMsgIdKey]) {
|
||||||
return this.cache[shortMsgIdKey]
|
return this.cache[shortMsgIdKey] as RawMessage
|
||||||
}
|
}
|
||||||
const longId = await this.db.get(shortMsgIdKey);
|
const longId = await this.db.get(shortMsgIdKey);
|
||||||
const msg = await this.getMsgByLongId(longId)
|
const msg = await this.getMsgByLongId(longId)
|
||||||
@@ -70,7 +73,7 @@ class DBUtil {
|
|||||||
async getMsgByLongId(longId: string): Promise<RawMessage> {
|
async getMsgByLongId(longId: string): Promise<RawMessage> {
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + longId;
|
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + longId;
|
||||||
if (this.cache[longIdKey]) {
|
if (this.cache[longIdKey]) {
|
||||||
return this.cache[longIdKey]
|
return this.cache[longIdKey] as RawMessage
|
||||||
}
|
}
|
||||||
const data = await this.db.get(longIdKey)
|
const data = await this.db.get(longIdKey)
|
||||||
const msg = JSON.parse(data)
|
const msg = JSON.parse(data)
|
||||||
@@ -81,7 +84,7 @@ class DBUtil {
|
|||||||
async getMsgBySeqId(seqId: string): Promise<RawMessage> {
|
async getMsgBySeqId(seqId: string): Promise<RawMessage> {
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + seqId;
|
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + seqId;
|
||||||
if (this.cache[seqIdKey]) {
|
if (this.cache[seqIdKey]) {
|
||||||
return this.cache[seqIdKey]
|
return this.cache[seqIdKey] as RawMessage
|
||||||
}
|
}
|
||||||
const longId = await this.db.get(seqIdKey);
|
const longId = await this.db.get(seqIdKey);
|
||||||
const msg = await this.getMsgByLongId(longId)
|
const msg = await this.getMsgByLongId(longId)
|
||||||
@@ -91,8 +94,9 @@ class DBUtil {
|
|||||||
|
|
||||||
async addMsg(msg: RawMessage) {
|
async addMsg(msg: RawMessage) {
|
||||||
// 有则更新,无则添加
|
// 有则更新,无则添加
|
||||||
|
// log("addMsg", msg.msgId, msg.msgSeq, msg.msgShortId);
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
||||||
let existMsg = this.cache[longIdKey]
|
let existMsg = this.cache[longIdKey] as RawMessage
|
||||||
if (!existMsg) {
|
if (!existMsg) {
|
||||||
try {
|
try {
|
||||||
existMsg = await this.getMsgByLongId(msg.msgId)
|
existMsg = await this.getMsgByLongId(msg.msgId)
|
||||||
@@ -101,6 +105,7 @@ class DBUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (existMsg) {
|
if (existMsg) {
|
||||||
|
// log("消息已存在", existMsg.msgSeq, existMsg.msgShortId, existMsg.msgId)
|
||||||
this.updateMsg(msg).then()
|
this.updateMsg(msg).then()
|
||||||
return existMsg.msgShortId
|
return existMsg.msgShortId
|
||||||
}
|
}
|
||||||
@@ -110,43 +115,93 @@ class DBUtil {
|
|||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
||||||
msg.msgShortId = shortMsgId;
|
msg.msgShortId = shortMsgId;
|
||||||
try {
|
try {
|
||||||
await this.db.put(shortIdKey, msg.msgId);
|
this.db.put(shortIdKey, msg.msgId).then();
|
||||||
await this.db.put(longIdKey, JSON.stringify(msg));
|
this.db.put(longIdKey, JSON.stringify(msg)).then();
|
||||||
await this.db.put(seqIdKey, msg.msgId);
|
try {
|
||||||
|
await this.db.get(seqIdKey)
|
||||||
|
} catch (e) {
|
||||||
|
// log("新的seqId", seqIdKey)
|
||||||
|
this.db.put(seqIdKey, msg.msgId).then();
|
||||||
|
}
|
||||||
|
this.cache[shortIdKey] = this.cache[longIdKey] = msg;
|
||||||
|
if (!this.cache[seqIdKey]) {
|
||||||
|
this.cache[seqIdKey] = msg;
|
||||||
|
}
|
||||||
|
// log(`消息入库 ${seqIdKey}: ${msg.msgId}, ${shortMsgId}: ${msg.msgId}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("addMsg db error", e.stack.toString());
|
// log("addMsg db error", e.stack.toString());
|
||||||
}
|
}
|
||||||
this.cache[seqIdKey] = this.cache[shortIdKey] = this.cache[longIdKey] = msg;
|
|
||||||
return shortMsgId
|
return shortMsgId
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateMsg(msg: RawMessage) {
|
async updateMsg(msg: RawMessage) {
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
||||||
let existMsg = this.cache[longIdKey]
|
let existMsg = this.cache[longIdKey] as RawMessage
|
||||||
if (!existMsg) {
|
if (!existMsg) {
|
||||||
try {
|
try {
|
||||||
existMsg = await this.getMsgByLongId(msg.msgId)
|
existMsg = await this.getMsgByLongId(msg.msgId)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return
|
existMsg = msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(existMsg, msg)
|
Object.assign(existMsg, msg)
|
||||||
await this.db.put(longIdKey, JSON.stringify(existMsg));
|
this.db.put(longIdKey, JSON.stringify(existMsg)).then();
|
||||||
|
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + existMsg.msgShortId;
|
||||||
|
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
||||||
|
if (!this.cache[seqIdKey]) {
|
||||||
|
this.cache[seqIdKey] = existMsg;
|
||||||
|
}
|
||||||
|
this.db.put(shortIdKey, msg.msgId).then();
|
||||||
|
try {
|
||||||
|
await this.db.get(seqIdKey)
|
||||||
|
} catch (e) {
|
||||||
|
this.db.put(seqIdKey, msg.msgId).then();
|
||||||
|
// log("更新seqId error", e.stack, seqIdKey);
|
||||||
|
}
|
||||||
|
// log("更新消息", existMsg.msgSeq, existMsg.msgShortId, existMsg.msgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async genMsgShortId(): Promise<number> {
|
private async genMsgShortId(): Promise<number> {
|
||||||
let shortId = -2147483640
|
|
||||||
const key = "msg_current_short_id";
|
const key = "msg_current_short_id";
|
||||||
try {
|
if (this.currentShortId === undefined) {
|
||||||
let id: string = await this.db.get(key);
|
try {
|
||||||
shortId = parseInt(id);
|
let id: string = await this.db.get(key);
|
||||||
} catch (e) {
|
this.currentShortId = parseInt(id);
|
||||||
|
} catch (e) {
|
||||||
|
this.currentShortId = -2147483640
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentShortId++;
|
||||||
|
await this.db.put(key, this.currentShortId.toString());
|
||||||
|
return this.currentShortId;
|
||||||
|
}
|
||||||
|
|
||||||
|
async addFileCache(fileName: string, data: FileCache) {
|
||||||
|
const key = this.DB_KEY_PREFIX_FILE + fileName;
|
||||||
|
if (this.cache[key]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let cacheDBData = {...data}
|
||||||
|
delete cacheDBData['downloadFunc']
|
||||||
|
this.cache[fileName] = data;
|
||||||
|
await this.db.put(key, JSON.stringify(cacheDBData));
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFileCache(fileName: string): Promise<FileCache | undefined> {
|
||||||
|
const key = this.DB_KEY_PREFIX_FILE + fileName;
|
||||||
|
if (this.cache[key]) {
|
||||||
|
return this.cache[key] as FileCache
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
|
||||||
|
let data = await this.db.get(key);
|
||||||
|
return JSON.parse(data);
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
shortId++;
|
|
||||||
await this.db.put(key, shortId.toString());
|
|
||||||
return shortId;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ import {
|
|||||||
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||||
import {checkFfmpeg, DATA_DIR, getConfigUtil, log} from "../common/utils";
|
import {checkFfmpeg, DATA_DIR, getConfigUtil, log} from "../common/utils";
|
||||||
import {
|
import {
|
||||||
friendRequests,
|
friendRequests, getFriend,
|
||||||
getGroup,
|
getGroup,
|
||||||
getGroupMember,
|
getGroupMember,
|
||||||
groupNotifies,
|
groupNotifies,
|
||||||
@@ -155,7 +155,7 @@ function onLoad() {
|
|||||||
async function postReceiveMsg(msgList: RawMessage[]) {
|
async function postReceiveMsg(msgList: RawMessage[]) {
|
||||||
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
||||||
for (let message of msgList) {
|
for (let message of msgList) {
|
||||||
// log("收到新消息", message)
|
// log("收到新消息", message.msgSeq)
|
||||||
message.msgShortId = await dbUtil.addMsg(message)
|
message.msgShortId = await dbUtil.addMsg(message)
|
||||||
|
|
||||||
OB11Constructor.message(message).then((msg) => {
|
OB11Constructor.message(message).then((msg) => {
|
||||||
@@ -213,7 +213,7 @@ function onLoad() {
|
|||||||
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
dbUtil.addMsg(message).then();
|
dbUtil.updateMsg(message).then();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, async (payload) => {
|
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, async (payload) => {
|
||||||
@@ -305,7 +305,10 @@ function onLoad() {
|
|||||||
log("收到邀请我加群通知")
|
log("收到邀请我加群通知")
|
||||||
let groupInviteEvent = new OB11GroupRequestEvent();
|
let groupInviteEvent = new OB11GroupRequestEvent();
|
||||||
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
||||||
let user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin
|
let user_id = (await getFriend("", notify.user2.uid))?.uin
|
||||||
|
if (!user_id){
|
||||||
|
user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin
|
||||||
|
}
|
||||||
groupInviteEvent.user_id = parseInt(user_id);
|
groupInviteEvent.user_id = parseInt(user_id);
|
||||||
groupInviteEvent.sub_type = "invite";
|
groupInviteEvent.sub_type = "invite";
|
||||||
groupInviteEvent.flag = notify.seq;
|
groupInviteEvent.flag = notify.seq;
|
||||||
|
@@ -89,6 +89,9 @@ export class SendMsgElementConstructor {
|
|||||||
picWidth = 768;
|
picWidth = 768;
|
||||||
}
|
}
|
||||||
const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE);
|
const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE);
|
||||||
|
if (fileSize === 0){
|
||||||
|
throw "文件异常,大小为0";
|
||||||
|
}
|
||||||
let element: SendFileElement = {
|
let element: SendFileElement = {
|
||||||
elementType: ElementType.FILE,
|
elementType: ElementType.FILE,
|
||||||
elementId: "",
|
elementId: "",
|
||||||
|
@@ -233,7 +233,7 @@ registerReceiveHook<{
|
|||||||
registerReceiveHook<{ msgList: RawMessage[] }>(ReceiveCmd.NEW_MSG, (payload) => {
|
registerReceiveHook<{ msgList: RawMessage[] }>(ReceiveCmd.NEW_MSG, (payload) => {
|
||||||
const {autoDeleteFile, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
const {autoDeleteFile, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
||||||
for (const message of payload.msgList) {
|
for (const message of payload.msgList) {
|
||||||
// log("收到新消息,push到历史记录", message)
|
// log("收到新消息,push到历史记录", message.msgSeq)
|
||||||
dbUtil.addMsg(message).then()
|
dbUtil.addMsg(message).then()
|
||||||
// 清理文件
|
// 清理文件
|
||||||
if (!autoDeleteFile) {
|
if (!autoDeleteFile) {
|
||||||
@@ -268,6 +268,8 @@ registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, ({msgRe
|
|||||||
const message = msgRecord
|
const message = msgRecord
|
||||||
const peerUid = message.peerUid
|
const peerUid = message.peerUid
|
||||||
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
||||||
|
// log("收到自己发送成功的消息", message);
|
||||||
|
dbUtil.addMsg(message).then()
|
||||||
const sendCallback = sendMessagePool[peerUid]
|
const sendCallback = sendMessagePool[peerUid]
|
||||||
if (sendCallback) {
|
if (sendCallback) {
|
||||||
try {
|
try {
|
||||||
|
@@ -17,7 +17,7 @@ import {
|
|||||||
type User
|
type User
|
||||||
} from './types'
|
} from './types'
|
||||||
import * as fs from 'node:fs'
|
import * as fs from 'node:fs'
|
||||||
import {friendRequests, groupNotifies, selfInfo} from '../common/data'
|
import {friendRequests, groupNotifies, selfInfo, uidMaps} from '../common/data'
|
||||||
import {v4 as uuidv4} from 'uuid'
|
import {v4 as uuidv4} from 'uuid'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import {dbUtil} from "../common/db";
|
import {dbUtil} from "../common/db";
|
||||||
@@ -292,7 +292,7 @@ export class NTQQApi {
|
|||||||
|
|
||||||
const members: GroupMember[] = Array.from(values)
|
const members: GroupMember[] = Array.from(values)
|
||||||
for (const member of members) {
|
for (const member of members) {
|
||||||
// uidMaps[member.uid] = member.uin;
|
uidMaps[member.uid] = member.uin;
|
||||||
}
|
}
|
||||||
// log(uidMaps);
|
// log(uidMaps);
|
||||||
// log("members info", values);
|
// log("members info", values);
|
||||||
@@ -422,7 +422,7 @@ export class NTQQApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = false, timeout = 10000) {
|
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
||||||
const peerUid = peer.peerUid
|
const peerUid = peer.peerUid
|
||||||
|
|
||||||
// 等待上一个相同的peer发送完
|
// 等待上一个相同的peer发送完
|
||||||
@@ -469,7 +469,7 @@ export class NTQQApi {
|
|||||||
await sleep(500)
|
await sleep(500)
|
||||||
return await checkSendComplete()
|
return await checkSendComplete()
|
||||||
}
|
}
|
||||||
|
log("开始发送消息", peer, msgElements)
|
||||||
callNTQQApi({
|
callNTQQApi({
|
||||||
methodName: NTQQApiMethod.SEND_MSG,
|
methodName: NTQQApiMethod.SEND_MSG,
|
||||||
args: [{
|
args: [{
|
||||||
|
@@ -233,6 +233,7 @@ export interface PicElement {
|
|||||||
fileSize: number;
|
fileSize: number;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
fileUuid: string;
|
fileUuid: string;
|
||||||
|
md5HexStr?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GrayTipElement {
|
export interface GrayTipElement {
|
||||||
|
@@ -21,7 +21,7 @@ class BaseAction<PayloadType, ReturnDataType> {
|
|||||||
const resData = await this._handle(payload);
|
const resData = await this._handle(payload);
|
||||||
return OB11Response.ok(resData);
|
return OB11Response.ok(resData);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("发送错误", e.stack)
|
log("发生错误", e)
|
||||||
return OB11Response.error(e.toString(), 200);
|
return OB11Response.error(e.toString(), 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ class BaseAction<PayloadType, ReturnDataType> {
|
|||||||
const resData = await this._handle(payload)
|
const resData = await this._handle(payload)
|
||||||
return OB11Response.ok(resData, echo);
|
return OB11Response.ok(resData, echo);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("发生错误", e.stack.toString())
|
log("发生错误", e)
|
||||||
return OB11Response.error(e.toString(), 1200, echo)
|
return OB11Response.error(e.toString(), 1200, echo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {fileCache} from "../../common/data";
|
|
||||||
import {getConfigUtil} from "../../common/utils";
|
import {getConfigUtil} from "../../common/utils";
|
||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
|
import {dbUtil} from "../../common/db";
|
||||||
|
|
||||||
export interface GetFilePayload {
|
export interface GetFilePayload {
|
||||||
file: string // 文件名
|
file: string // 文件名
|
||||||
@@ -18,7 +18,7 @@ export interface GetFileResponse {
|
|||||||
|
|
||||||
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||||
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
||||||
const cache = fileCache.get(payload.file)
|
const cache = await dbUtil.getFileCache(payload.file)
|
||||||
const {autoDeleteFile, enableLocalFile2Url, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
const {autoDeleteFile, enableLocalFile2Url, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
throw new Error('file not found')
|
throw new Error('file not found')
|
||||||
|
@@ -1,9 +1,17 @@
|
|||||||
import SendMsg from "./SendMsg";
|
import SendMsg from "./SendMsg";
|
||||||
import {ActionName} from "./types";
|
import {ActionName, BaseCheckResult} from "./types";
|
||||||
|
import {OB11PostSendMsg} from "../types";
|
||||||
|
import {log} from "../../common/utils";
|
||||||
|
|
||||||
|
|
||||||
class SendGroupMsg extends SendMsg {
|
class SendGroupMsg extends SendMsg {
|
||||||
actionName = ActionName.SendGroupMsg
|
actionName = ActionName.SendGroupMsg
|
||||||
|
|
||||||
|
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||||
|
delete payload.user_id;
|
||||||
|
payload.message_type = "group"
|
||||||
|
return super.check(payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SendGroupMsg
|
export default SendGroupMsg
|
@@ -1,7 +1,8 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {getFriend} from "../../common/data";
|
import {getFriend, getUidByUin, uidMaps} from "../../common/data";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {log} from "../../common/utils";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
user_id: number,
|
user_id: number,
|
||||||
@@ -12,13 +13,17 @@ export default class SendLike extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName.SendLike
|
actionName = ActionName.SendLike
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const qq = payload.user_id.toString();
|
log("点赞参数", payload)
|
||||||
const friend = await getFriend(qq)
|
|
||||||
if (!friend) {
|
|
||||||
throw (`点赞失败,${qq}不是好友`)
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
let result = await NTQQApi.likeFriend(friend.uid, parseInt(payload.times.toString()) || 1);
|
const qq = payload.user_id.toString();
|
||||||
|
const friend = await getFriend(qq)
|
||||||
|
let uid: string;
|
||||||
|
if (!friend) {
|
||||||
|
uid = getUidByUin(qq)
|
||||||
|
} else {
|
||||||
|
uid = friend.uid
|
||||||
|
}
|
||||||
|
let result = await NTQQApi.likeFriend(uid, parseInt(payload.times?.toString()) || 1);
|
||||||
if (result.result !== 0) {
|
if (result.result !== 0) {
|
||||||
throw result.errMsg
|
throw result.errMsg
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import {AtType, ChatType, Group, RawMessage, SendArkElement, SendMessageElement} from "../../ntqqapi/types";
|
import {AtType, ChatType, Group, RawMessage, SendArkElement, SendMessageElement} from "../../ntqqapi/types";
|
||||||
import {friends, getGroup, getGroupMember, getUidByUin, selfInfo,} from "../../common/data";
|
import {friends, getFriend, getGroup, getGroupMember, getUidByUin, selfInfo,} from "../../common/data";
|
||||||
import {
|
import {
|
||||||
OB11MessageCustomMusic,
|
OB11MessageCustomMusic,
|
||||||
OB11MessageData,
|
OB11MessageData,
|
||||||
@@ -17,6 +17,8 @@ import * as fs from "node:fs";
|
|||||||
import {log} from "../../common/utils";
|
import {log} from "../../common/utils";
|
||||||
import {decodeCQCode} from "../cqcode";
|
import {decodeCQCode} from "../cqcode";
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../common/db";
|
||||||
|
import {ALLOW_SEND_TEMP_MSG} from "../../common/config";
|
||||||
|
import {FileCache} from "../../common/types";
|
||||||
|
|
||||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||||
function checkUri(uri: string): boolean {
|
function checkUri(uri: string): boolean {
|
||||||
@@ -69,6 +71,22 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
message: "转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素"
|
message: "转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (payload.group_id && !(await getGroup(payload.group_id))) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
message: `群${payload.group_id}不存在`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (payload.user_id && payload.message_type !== "group") {
|
||||||
|
if (!(await getFriend(payload.user_id))) {
|
||||||
|
if (!ALLOW_SEND_TEMP_MSG) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
message: `不能发送临时消息`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
valid: true,
|
valid: true,
|
||||||
}
|
}
|
||||||
@@ -79,17 +97,16 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
chatType: ChatType.friend,
|
chatType: ChatType.friend,
|
||||||
peerUid: ""
|
peerUid: ""
|
||||||
}
|
}
|
||||||
|
let isTempMsg = false;
|
||||||
let group: Group | undefined = undefined;
|
let group: Group | undefined = undefined;
|
||||||
if (payload?.group_id) {
|
const genGroupPeer = async () => {
|
||||||
group = await getGroup(payload.group_id.toString())
|
group = await getGroup(payload.group_id.toString())
|
||||||
if (!group) {
|
|
||||||
throw (`群${payload.group_id}不存在`)
|
|
||||||
}
|
|
||||||
peer.chatType = ChatType.group
|
peer.chatType = ChatType.group
|
||||||
// peer.name = group.name
|
// peer.name = group.name
|
||||||
peer.peerUid = group.groupCode
|
peer.peerUid = group.groupCode
|
||||||
} else if (payload?.user_id) {
|
}
|
||||||
|
|
||||||
|
const genFriendPeer = () => {
|
||||||
const friend = friends.find(f => f.uin == payload.user_id.toString())
|
const friend = friends.find(f => f.uin == payload.user_id.toString())
|
||||||
if (friend) {
|
if (friend) {
|
||||||
// peer.name = friend.nickName
|
// peer.name = friend.nickName
|
||||||
@@ -101,9 +118,20 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
throw (`找不到私聊对象${payload.user_id}`)
|
throw (`找不到私聊对象${payload.user_id}`)
|
||||||
}
|
}
|
||||||
// peer.name = tempUser.nickName
|
// peer.name = tempUser.nickName
|
||||||
|
isTempMsg = true;
|
||||||
peer.peerUid = tempUserUid;
|
peer.peerUid = tempUserUid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (payload?.group_id && payload.message_type === "group") {
|
||||||
|
await genGroupPeer()
|
||||||
|
|
||||||
|
} else if (payload?.user_id) {
|
||||||
|
genFriendPeer()
|
||||||
|
} else if (payload.group_id) {
|
||||||
|
await genGroupPeer()
|
||||||
|
} else {
|
||||||
|
throw ("发送消息参数错误, 请指定group_id或user_id")
|
||||||
|
}
|
||||||
const messages = this.convertMessage2List(payload.message);
|
const messages = this.convertMessage2List(payload.message);
|
||||||
if (this.getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
if (this.getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||||
try {
|
try {
|
||||||
@@ -131,6 +159,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
const {sendElements, deleteAfterSentFiles} = await this.createSendElements(messages, group)
|
const {sendElements, deleteAfterSentFiles} = await this.createSendElements(messages, group)
|
||||||
try {
|
try {
|
||||||
const returnMsg = await this.send(peer, sendElements, deleteAfterSentFiles)
|
const returnMsg = await this.send(peer, sendElements, deleteAfterSentFiles)
|
||||||
|
deleteAfterSentFiles.map(f => fs.unlink(f, () => {}));
|
||||||
return {message_id: returnMsg.msgShortId}
|
return {message_id: returnMsg.msgShortId}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("发送消息失败", e.stack.toString())
|
log("发送消息失败", e.stack.toString())
|
||||||
@@ -186,7 +215,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
deleteAfterSentFiles
|
deleteAfterSentFiles
|
||||||
} = await this.createSendElements(this.convertMessage2List(messageNode.data.content), group);
|
} = await this.createSendElements(this.convertMessage2List(messageNode.data.content), group);
|
||||||
log("开始生成转发节点", sendElements);
|
log("开始生成转发节点", sendElements);
|
||||||
const nodeMsg = await this.send(selfPeer, sendElements, deleteAfterSentFiles, true);
|
const nodeMsg = await this.send(selfPeer, sendElements, deleteAfterSentFiles, false);
|
||||||
selfNodeMsgList.push(nodeMsg);
|
selfNodeMsgList.push(nodeMsg);
|
||||||
log("转发节点生成成功", nodeMsg.msgId);
|
log("转发节点生成成功", nodeMsg.msgId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -260,6 +289,9 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OB11MessageDataType.at: {
|
case OB11MessageDataType.at: {
|
||||||
|
if (!group){
|
||||||
|
continue
|
||||||
|
}
|
||||||
let atQQ = sendMsg.data?.qq;
|
let atQQ = sendMsg.data?.qq;
|
||||||
if (atQQ) {
|
if (atQQ) {
|
||||||
atQQ = atQQ.toString()
|
atQQ = atQQ.toString()
|
||||||
@@ -297,10 +329,24 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
case OB11MessageDataType.file:
|
case OB11MessageDataType.file:
|
||||||
case OB11MessageDataType.video:
|
case OB11MessageDataType.video:
|
||||||
case OB11MessageDataType.voice: {
|
case OB11MessageDataType.voice: {
|
||||||
const file = sendMsg.data?.file
|
let file = sendMsg.data?.file
|
||||||
const payloadFileName = sendMsg.data?.name
|
const payloadFileName = sendMsg.data?.name
|
||||||
if (file) {
|
if (file) {
|
||||||
const {path, isLocal, fileName} = (await uri2local(file))
|
const cache = await dbUtil.getFileCache(file)
|
||||||
|
if (cache){
|
||||||
|
if (fs.existsSync(cache.filePath)){
|
||||||
|
file = "file://" + cache.filePath
|
||||||
|
}
|
||||||
|
else if (cache.downloadFunc){
|
||||||
|
await cache.downloadFunc()
|
||||||
|
file = cache.filePath;
|
||||||
|
log("找到文件缓存", file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const {path, isLocal, fileName, errMsg} = (await uri2local(file))
|
||||||
|
if (errMsg){
|
||||||
|
throw errMsg
|
||||||
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||||
deleteAfterSentFiles.push(path)
|
deleteAfterSentFiles.push(path)
|
||||||
@@ -334,7 +380,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async send(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = false) {
|
private async send(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
||||||
if (!sendElements.length) {
|
if (!sendElements.length) {
|
||||||
throw ("消息体无法解析")
|
throw ("消息体无法解析")
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,14 @@
|
|||||||
import SendMsg from "./SendMsg";
|
import SendMsg from "./SendMsg";
|
||||||
import {ActionName} from "./types";
|
import {ActionName, BaseCheckResult} from "./types";
|
||||||
|
import {OB11PostSendMsg} from "../types";
|
||||||
|
|
||||||
class SendPrivateMsg extends SendMsg {
|
class SendPrivateMsg extends SendMsg {
|
||||||
actionName = ActionName.SendPrivateMsg
|
actionName = ActionName.SendPrivateMsg
|
||||||
|
|
||||||
|
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||||
|
payload.message_type = "private"
|
||||||
|
return super.check(payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SendPrivateMsg
|
export default SendPrivateMsg
|
@@ -9,7 +9,7 @@ import {
|
|||||||
OB11UserSex
|
OB11UserSex
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import {AtType, ChatType, Group, GroupMember, IMAGE_HTTP_HOST, RawMessage, SelfInfo, User} from '../ntqqapi/types';
|
import {AtType, ChatType, Group, GroupMember, IMAGE_HTTP_HOST, RawMessage, SelfInfo, User} from '../ntqqapi/types';
|
||||||
import {fileCache, getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
||||||
import {getConfigUtil, log} from "../common/utils";
|
import {getConfigUtil, log} from "../common/utils";
|
||||||
import {NTQQApi} from "../ntqqapi/ntcall";
|
import {NTQQApi} from "../ntqqapi/ntcall";
|
||||||
import {EventType} from "./event/OB11BaseEvent";
|
import {EventType} from "./event/OB11BaseEvent";
|
||||||
@@ -96,30 +96,44 @@ export class OB11Constructor {
|
|||||||
message_data["data"]["text"] = text
|
message_data["data"]["text"] = text
|
||||||
} else if (element.replyElement) {
|
} else if (element.replyElement) {
|
||||||
message_data["type"] = "reply"
|
message_data["type"] = "reply"
|
||||||
const replyMsg = await dbUtil.getMsgBySeqId(element.replyElement.replayMsgSeq)
|
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
||||||
if (replyMsg) {
|
try{
|
||||||
message_data["data"]["id"] = replyMsg.msgShortId.toString()
|
const replyMsg = await dbUtil.getMsgBySeqId(element.replyElement.replayMsgSeq)
|
||||||
} else {
|
// log("找到回复消息", replyMsg.msgShortId, replyMsg.msgId)
|
||||||
continue
|
if (replyMsg) {
|
||||||
|
message_data["data"]["id"] = replyMsg.msgShortId.toString()
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}catch (e) {
|
||||||
|
log("获取不到引用的消息", e.stack, element.replyElement.replayMsgSeq)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (element.picElement) {
|
} else if (element.picElement) {
|
||||||
message_data["type"] = "image"
|
message_data["type"] = "image"
|
||||||
// message_data["data"]["file"] = element.picElement.sourcePath
|
// message_data["data"]["file"] = element.picElement.sourcePath
|
||||||
message_data["data"]["file"] = element.picElement.fileName
|
message_data["data"]["file"] = element.picElement.fileName
|
||||||
// message_data["data"]["path"] = element.picElement.sourcePath
|
// message_data["data"]["path"] = element.picElement.sourcePath
|
||||||
message_data["data"]["url"] = IMAGE_HTTP_HOST + element.picElement.originImageUrl
|
const url = element.picElement.originImageUrl
|
||||||
|
const fileMd5 = element.picElement.md5HexStr
|
||||||
|
if (url){
|
||||||
|
message_data["data"]["url"] = IMAGE_HTTP_HOST + url
|
||||||
|
}
|
||||||
|
else if (fileMd5 && element.picElement.fileUuid.indexOf("_") === -1){ // fileuuid有下划线的是Linux发送的,这个url是另外的格式,目前尚未得知如何组装
|
||||||
|
message_data["data"]["url"] = `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${fileMd5.toUpperCase()}/0`
|
||||||
|
}
|
||||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||||
message_data["data"]["file_size"] = element.picElement.fileSize
|
message_data["data"]["file_size"] = element.picElement.fileSize
|
||||||
fileCache.set(element.picElement.fileName, {
|
dbUtil.addFileCache(element.picElement.fileName, {
|
||||||
fileName: element.picElement.fileName,
|
fileName: element.picElement.fileName,
|
||||||
filePath: element.picElement.sourcePath,
|
filePath: element.picElement.sourcePath,
|
||||||
fileSize: element.picElement.fileSize.toString(),
|
fileSize: element.picElement.fileSize.toString(),
|
||||||
url: IMAGE_HTTP_HOST + element.picElement.originImageUrl,
|
url: message_data["data"]["url"],
|
||||||
downloadFunc: async () => {
|
downloadFunc: async () => {
|
||||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
element.elementId, element.picElement.thumbPath.get(0), element.picElement.sourcePath)
|
element.elementId, element.picElement.thumbPath?.get(0) || "", element.picElement.sourcePath)
|
||||||
}
|
}
|
||||||
})
|
}).then()
|
||||||
// 不在自动下载图片
|
// 不在自动下载图片
|
||||||
|
|
||||||
} else if (element.videoElement) {
|
} else if (element.videoElement) {
|
||||||
@@ -128,7 +142,7 @@ export class OB11Constructor {
|
|||||||
message_data["data"]["path"] = element.videoElement.filePath
|
message_data["data"]["path"] = element.videoElement.filePath
|
||||||
// message_data["data"]["file_id"] = element.videoElement.fileUuid
|
// message_data["data"]["file_id"] = element.videoElement.fileUuid
|
||||||
message_data["data"]["file_size"] = element.videoElement.fileSize
|
message_data["data"]["file_size"] = element.videoElement.fileSize
|
||||||
fileCache.set(element.videoElement.fileName, {
|
dbUtil.addFileCache(element.videoElement.fileName, {
|
||||||
fileName: element.videoElement.fileName,
|
fileName: element.videoElement.fileName,
|
||||||
filePath: element.videoElement.filePath,
|
filePath: element.videoElement.filePath,
|
||||||
fileSize: element.videoElement.fileSize,
|
fileSize: element.videoElement.fileSize,
|
||||||
@@ -136,7 +150,7 @@ export class OB11Constructor {
|
|||||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
element.elementId, element.videoElement.thumbPath.get(0), element.videoElement.filePath)
|
element.elementId, element.videoElement.thumbPath.get(0), element.videoElement.filePath)
|
||||||
}
|
}
|
||||||
})
|
}).then()
|
||||||
// 怎么拿到url呢
|
// 怎么拿到url呢
|
||||||
} else if (element.fileElement) {
|
} else if (element.fileElement) {
|
||||||
message_data["type"] = OB11MessageDataType.file;
|
message_data["type"] = OB11MessageDataType.file;
|
||||||
@@ -144,7 +158,7 @@ export class OB11Constructor {
|
|||||||
// 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
|
||||||
fileCache.set(element.fileElement.fileName, {
|
dbUtil.addFileCache(element.fileElement.fileName, {
|
||||||
fileName: element.fileElement.fileName,
|
fileName: element.fileElement.fileName,
|
||||||
filePath: element.fileElement.filePath,
|
filePath: element.fileElement.filePath,
|
||||||
fileSize: element.fileElement.fileSize,
|
fileSize: element.fileElement.fileSize,
|
||||||
@@ -152,7 +166,7 @@ export class OB11Constructor {
|
|||||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
element.elementId, null, element.fileElement.filePath)
|
element.elementId, null, element.fileElement.filePath)
|
||||||
}
|
}
|
||||||
})
|
}).then()
|
||||||
// 怎么拿到url呢
|
// 怎么拿到url呢
|
||||||
} else if (element.pttElement) {
|
} else if (element.pttElement) {
|
||||||
message_data["type"] = OB11MessageDataType.voice;
|
message_data["type"] = OB11MessageDataType.voice;
|
||||||
@@ -160,11 +174,11 @@ export class OB11Constructor {
|
|||||||
message_data["data"]["path"] = element.pttElement.filePath
|
message_data["data"]["path"] = element.pttElement.filePath
|
||||||
// message_data["data"]["file_id"] = element.pttElement.fileUuid
|
// message_data["data"]["file_id"] = element.pttElement.fileUuid
|
||||||
message_data["data"]["file_size"] = element.pttElement.fileSize
|
message_data["data"]["file_size"] = element.pttElement.fileSize
|
||||||
fileCache.set(element.pttElement.fileName, {
|
dbUtil.addFileCache(element.pttElement.fileName, {
|
||||||
fileName: element.pttElement.fileName,
|
fileName: element.pttElement.fileName,
|
||||||
filePath: element.pttElement.filePath,
|
filePath: element.pttElement.filePath,
|
||||||
fileSize: element.pttElement.fileSize,
|
fileSize: element.pttElement.fileSize,
|
||||||
})
|
}).then()
|
||||||
|
|
||||||
// log("收到语音消息", msg)
|
// log("收到语音消息", msg)
|
||||||
// window.LLAPI.Ptt2Text(message.raw.msgId, message.peer, messages).then(text => {
|
// window.LLAPI.Ptt2Text(message.raw.msgId, message.peer, messages).then(text => {
|
||||||
|
@@ -28,7 +28,7 @@ class OB11WebsocketServer extends WebsocketServerBase {
|
|||||||
let handleResult = await action.websocketHandle(params, echo);
|
let handleResult = await action.websocketHandle(params, echo);
|
||||||
wsReply(wsClient, handleResult)
|
wsReply(wsClient, handleResult)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
wsReply(wsClient, OB11Response.error(`api处理出错:${e}`, 1200, echo))
|
wsReply(wsClient, OB11Response.error(`api处理出错:${e.stack}`, 1200, echo))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import {DATA_DIR, isGIF, log} from "../common/utils";
|
import {DATA_DIR, isGIF, log} from "../common/utils";
|
||||||
import {v4 as uuidv4} from "uuid";
|
import {v4 as uuidv4} from "uuid";
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import {fileCache} from "../common/data";
|
|
||||||
import * as fileType from 'file-type';
|
import * as fileType from 'file-type';
|
||||||
|
import {dbUtil} from "../common/db";
|
||||||
|
|
||||||
const fs = require("fs").promises;
|
const fs = require("fs").promises;
|
||||||
|
|
||||||
@@ -33,7 +33,13 @@ export async function uri2local(uri: string, fileName: string = null) {
|
|||||||
}
|
}
|
||||||
} else if (url.protocol == "http:" || url.protocol == "https:") {
|
} else if (url.protocol == "http:" || url.protocol == "https:") {
|
||||||
// 下载文件
|
// 下载文件
|
||||||
let fetchRes = await fetch(url)
|
let fetchRes: Response;
|
||||||
|
try{
|
||||||
|
fetchRes = await fetch(url)
|
||||||
|
}catch (e) {
|
||||||
|
res.errMsg = `${url}下载失败`
|
||||||
|
return res
|
||||||
|
}
|
||||||
if (!fetchRes.ok) {
|
if (!fetchRes.ok) {
|
||||||
res.errMsg = `${url}下载失败,` + fetchRes.statusText
|
res.errMsg = `${url}下载失败,` + fetchRes.statusText
|
||||||
return res
|
return res
|
||||||
@@ -46,7 +52,7 @@ export async function uri2local(uri: string, fileName: string = null) {
|
|||||||
fileName = pathInfo.name
|
fileName = pathInfo.name
|
||||||
if (pathInfo.ext){
|
if (pathInfo.ext){
|
||||||
fileName += pathInfo.ext
|
fileName += pathInfo.ext
|
||||||
res.ext = pathInfo.ext
|
// res.ext = pathInfo.ext
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.fileName = fileName
|
res.fileName = fileName
|
||||||
@@ -67,7 +73,7 @@ export async function uri2local(uri: string, fileName: string = null) {
|
|||||||
filePath = pathname
|
filePath = pathname
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const cache = fileCache.get(uri)
|
const cache = await dbUtil.getFileCache(uri);
|
||||||
if (cache) {
|
if (cache) {
|
||||||
filePath = cache.filePath
|
filePath = cache.filePath
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const version = "3.13.2"
|
export const version = "3.13.8"
|
Reference in New Issue
Block a user