mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
79090d764f | ||
![]() |
6ab0cd7f4b | ||
![]() |
bb3bce203d | ||
![]() |
36f7f1b026 | ||
![]() |
5a0dbdb5ce | ||
![]() |
48d62be2d6 | ||
![]() |
b314e2f3a0 | ||
![]() |
63b9204a4b | ||
![]() |
bf701c2110 | ||
![]() |
95b4b11f02 | ||
![]() |
1735babb7d | ||
![]() |
89c3f07cba | ||
![]() |
5cf45a452b | ||
![]() |
23d5fa7218 | ||
![]() |
983d2462d4 | ||
![]() |
3c68bc77ce | ||
![]() |
501211fb57 | ||
![]() |
0cd41a8a52 | ||
![]() |
d339a778df | ||
![]() |
dc843f77a3 | ||
![]() |
b103f2015c | ||
![]() |
baf35d5496 | ||
![]() |
5c34afc228 | ||
![]() |
a8a6290b70 | ||
![]() |
9d50c6d4fd | ||
![]() |
175a8ceb3d | ||
![]() |
31601981f2 | ||
![]() |
6a8c5ec24a | ||
![]() |
ebca6a07c5 | ||
![]() |
4f9345e4e5 | ||
![]() |
ac17dbefe0 | ||
![]() |
c9486b4f55 | ||
![]() |
35951fd61a | ||
![]() |
fdc23d7721 | ||
![]() |
560428a5f9 |
20
.github/ISSUE_TEMPLATE/bug_report.md
vendored
20
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug反馈
|
|
||||||
about: 报个Bug
|
|
||||||
title: ''
|
|
||||||
labels: bug
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
QQ版本:
|
|
||||||
|
|
||||||
LLOneBot版本:
|
|
||||||
|
|
||||||
调用LLOneBot的方式或者应用端(如postman直接调用,或NoneBot2、Koishi):
|
|
||||||
|
|
||||||
BUG描述:
|
|
||||||
|
|
||||||
复现步骤:
|
|
||||||
|
|
||||||
LLOneBot日志:
|
|
81
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
81
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
name: Bug 反馈
|
||||||
|
description: 报告可能的 LLOneBot 异常行为
|
||||||
|
title: '[BUG] '
|
||||||
|
labels: bug
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
欢迎来到 LLOneBot 的 Issue Tracker!请填写以下表格来提交 Bug。
|
||||||
|
在提交新的 Bug 反馈前,请确保您:
|
||||||
|
* 已经搜索了现有的 issues,并且没有找到可以解决您问题的方法
|
||||||
|
* 不与现有的某一 issue 重复
|
||||||
|
- type: input
|
||||||
|
id: system-version
|
||||||
|
attributes:
|
||||||
|
label: 系统版本
|
||||||
|
description: 运行 QQNT 的系统版本
|
||||||
|
placeholder: Windows 10 Pro Workstation 22H2
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: qqnt-version
|
||||||
|
attributes:
|
||||||
|
label: QQNT 版本
|
||||||
|
description: 可在 QQNT 的「关于」或是在 LiteLoaderQQNT 的设置页中找到
|
||||||
|
placeholder: 9.9.7-21804
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: llonebot-version
|
||||||
|
attributes:
|
||||||
|
label: LLOneBot 版本
|
||||||
|
description: 可在 LiteLoaderQQNT 的设置页或是 QQNT 的设置页侧栏中找到
|
||||||
|
placeholder: 3.18.0
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: onebot-client-version
|
||||||
|
attributes:
|
||||||
|
label: OneBot 客户端
|
||||||
|
description: 连接至 LLOneBot 的客户端版本信息
|
||||||
|
placeholder: Overflow 2.16.0-2cf7991-SNAPSHOT
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: what-happened
|
||||||
|
attributes:
|
||||||
|
label: 发生了什么?
|
||||||
|
description: 填写你认为的 LLOneBot 的不正常行为
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: how-reproduce
|
||||||
|
attributes:
|
||||||
|
label: 如何复现
|
||||||
|
description: 填写应当如何操作才能触发这个不正常行为
|
||||||
|
placeholder: |
|
||||||
|
1. xxx
|
||||||
|
2. xxx
|
||||||
|
3. xxx
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: what-expected
|
||||||
|
attributes:
|
||||||
|
label: 期望的结果?
|
||||||
|
description: 填写你认为 LLOneBot 应当执行的正常行为
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: llonebot-log
|
||||||
|
attributes:
|
||||||
|
label: LLOneBot 运行日志
|
||||||
|
description: 在 LLOneBot 的设置页中打开「写入日志」然后粘贴相关日志内容到此处
|
||||||
|
render: shell
|
||||||
|
- type: textarea
|
||||||
|
id: onebot-client-log
|
||||||
|
attributes:
|
||||||
|
label: OneBot 客户端运行日志
|
||||||
|
description: 粘贴 OneBot 客户端的相关日志内容到此处
|
||||||
|
render: shell
|
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 4,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot v3.17.0",
|
"name": "LLOneBot v3.19.0",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
||||||
"version": "3.17.0",
|
"version": "3.19.0",
|
||||||
"icon": "./icon.jpg",
|
"icon": "./icon.jpg",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
8
package-lock.json
generated
8
package-lock.json
generated
@@ -14,7 +14,7 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
"silk-wasm": "^3.2.3",
|
"silk-wasm": "^3.3.3",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
@@ -5895,9 +5895,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/silk-wasm": {
|
"node_modules/silk-wasm": {
|
||||||
"version": "3.2.3",
|
"version": "3.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.3.3.tgz",
|
||||||
"integrity": "sha512-zZ3hgMpiPR6cFnKvCPgPpCwx6n5RoJCbEGIFlge2kAxAmgzBTf0b2F2xIPG5W4obUhQPQXXTTH074eGZJK01xw=="
|
"integrity": "sha512-9Qj93EtiIuBNkDyEwlPntabEtrm6Xu6LE4y9qZvomvo5+IsXFcXSy+N55kV22OehUTBYlZqOZYtRggA8G9IDGg=="
|
||||||
},
|
},
|
||||||
"node_modules/slash": {
|
"node_modules/slash": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
"silk-wasm": "^3.2.3",
|
"silk-wasm": "^3.3.3",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
|
@@ -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,
|
||||||
|
@@ -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
|
||||||
|
137
src/common/utils/audio.ts
Normal file
137
src/common/utils/audio.ts
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
import {encode, getDuration, getWavFileInfo, isWav} from "silk-wasm";
|
||||||
|
import fsPromise from "fs/promises";
|
||||||
|
import {log} from "./log";
|
||||||
|
import path from "node:path";
|
||||||
|
import {DATA_DIR, TEMP_DIR} from "./index";
|
||||||
|
import {v4 as uuidv4} from "uuid";
|
||||||
|
import {getConfigUtil} from "../config";
|
||||||
|
import ffmpeg from "fluent-ffmpeg";
|
||||||
|
|
||||||
|
export async function encodeSilk(filePath: string) {
|
||||||
|
function getFileHeader(filePath: string) {
|
||||||
|
// 定义要读取的字节数
|
||||||
|
const bytesToRead = 7;
|
||||||
|
try {
|
||||||
|
const buffer = fs.readFileSync(filePath, {
|
||||||
|
encoding: null,
|
||||||
|
flag: "r",
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileHeader = buffer.toString("hex", 0, bytesToRead);
|
||||||
|
return fileHeader;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("读取文件错误:", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function isWavFile(filePath: string) {
|
||||||
|
return isWav(fs.readFileSync(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function guessDuration(pttPath: string) {
|
||||||
|
const pttFileInfo = await fsPromise.stat(pttPath)
|
||||||
|
let duration = pttFileInfo.size / 1024 / 3 // 3kb/s
|
||||||
|
duration = Math.floor(duration)
|
||||||
|
duration = Math.max(1, duration)
|
||||||
|
log(`通过文件大小估算语音的时长:`, duration)
|
||||||
|
return duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// function verifyDuration(oriDuration: number, guessDuration: number) {
|
||||||
|
// // 单位都是秒
|
||||||
|
// if (oriDuration - guessDuration > 10) {
|
||||||
|
// return guessDuration
|
||||||
|
// }
|
||||||
|
// oriDuration = Math.max(1, oriDuration)
|
||||||
|
// return oriDuration
|
||||||
|
// }
|
||||||
|
// async function getAudioSampleRate(filePath: string) {
|
||||||
|
// try {
|
||||||
|
// const mm = await import('music-metadata');
|
||||||
|
// const metadata = await mm.parseFile(filePath);
|
||||||
|
// log(`${filePath}采样率`, metadata.format.sampleRate);
|
||||||
|
// return metadata.format.sampleRate;
|
||||||
|
// } catch (error) {
|
||||||
|
// log(`${filePath}采样率获取失败`, error.stack);
|
||||||
|
// // console.error(error);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
try {
|
||||||
|
const pttPath = path.join(TEMP_DIR, uuidv4());
|
||||||
|
if (getFileHeader(filePath) !== "02232153494c4b") {
|
||||||
|
log(`语音文件${filePath}需要转换成silk`)
|
||||||
|
const _isWav = await isWavFile(filePath);
|
||||||
|
const wavPath = pttPath + ".wav"
|
||||||
|
const convert = async () => {
|
||||||
|
return await new Promise((resolve, reject) => {
|
||||||
|
const ffmpegPath = getConfigUtil().getConfig().ffmpeg;
|
||||||
|
if (ffmpegPath) {
|
||||||
|
ffmpeg.setFfmpegPath(ffmpegPath);
|
||||||
|
}
|
||||||
|
ffmpeg(filePath).toFormat("wav")
|
||||||
|
.audioChannels(1)
|
||||||
|
.audioFrequency(24000)
|
||||||
|
.on('end', function () {
|
||||||
|
log('wav转换完成');
|
||||||
|
})
|
||||||
|
.on('error', function (err) {
|
||||||
|
log(`wav转换出错: `, err.message,);
|
||||||
|
reject(err);
|
||||||
|
})
|
||||||
|
.save(wavPath)
|
||||||
|
.on("end", () => {
|
||||||
|
filePath = wavPath
|
||||||
|
resolve(wavPath);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
let wav: Buffer
|
||||||
|
if (!_isWav) {
|
||||||
|
log(`语音文件${filePath}正在转换成wav`)
|
||||||
|
await convert()
|
||||||
|
} else {
|
||||||
|
wav = fs.readFileSync(filePath)
|
||||||
|
const allowSampleRate = [8000, 12000, 16000, 24000, 32000, 44100, 48000]
|
||||||
|
const {fmt} = getWavFileInfo(wav)
|
||||||
|
// log(`wav文件信息`, fmt)
|
||||||
|
if (!allowSampleRate.includes(fmt.sampleRate)) {
|
||||||
|
wav = undefined
|
||||||
|
await convert()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wav ||= fs.readFileSync(filePath);
|
||||||
|
const silk = await encode(wav, 0);
|
||||||
|
fs.writeFileSync(pttPath, silk.data);
|
||||||
|
fs.unlink(wavPath, (err) => {
|
||||||
|
});
|
||||||
|
// const gDuration = await guessDuration(pttPath)
|
||||||
|
log(`语音文件${filePath}转换成功!`, pttPath, `时长:`, silk.duration)
|
||||||
|
return {
|
||||||
|
converted: true,
|
||||||
|
path: pttPath,
|
||||||
|
duration: silk.duration / 1000
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const silk = fs.readFileSync(filePath);
|
||||||
|
let duration = 0;
|
||||||
|
try {
|
||||||
|
duration = getDuration(silk) / 1000
|
||||||
|
} catch (e) {
|
||||||
|
log("获取语音文件时长失败, 使用文件大小推测时长", filePath, e.stack)
|
||||||
|
duration = await guessDuration(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
converted: false,
|
||||||
|
path: filePath,
|
||||||
|
duration: duration,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log("convert silk failed", error.stack);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
@@ -1,17 +1,13 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import fsPromise from "fs/promises";
|
import fsPromise from "fs/promises";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import ffmpeg from "fluent-ffmpeg";
|
|
||||||
import util from "util";
|
import util from "util";
|
||||||
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 {checkFfmpeg, DATA_DIR, log, TEMP_DIR} from "./index";
|
import {log, TEMP_DIR} from "./index";
|
||||||
import {getConfigUtil} from "../config";
|
|
||||||
import {dbUtil} from "../db";
|
import {dbUtil} from "../db";
|
||||||
import * as fileType from "file-type";
|
import * as fileType from "file-type";
|
||||||
import {net} from "electron";
|
import {net} from "electron";
|
||||||
import config from "../../../electron.vite.config";
|
|
||||||
|
|
||||||
|
|
||||||
export function isGIF(path: string) {
|
export function isGIF(path: string) {
|
||||||
@@ -67,109 +63,6 @@ export async function file2base64(path: string) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function encodeSilk(filePath: string) {
|
|
||||||
const fsp = require("fs").promises
|
|
||||||
|
|
||||||
function getFileHeader(filePath: string) {
|
|
||||||
// 定义要读取的字节数
|
|
||||||
const bytesToRead = 7;
|
|
||||||
try {
|
|
||||||
const buffer = fs.readFileSync(filePath, {
|
|
||||||
encoding: null,
|
|
||||||
flag: "r",
|
|
||||||
});
|
|
||||||
|
|
||||||
const fileHeader = buffer.toString("hex", 0, bytesToRead);
|
|
||||||
return fileHeader;
|
|
||||||
} catch (err) {
|
|
||||||
console.error("读取文件错误:", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function isWavFile(filePath: string) {
|
|
||||||
return isWav(fs.readFileSync(filePath));
|
|
||||||
}
|
|
||||||
|
|
||||||
// async function getAudioSampleRate(filePath: string) {
|
|
||||||
// try {
|
|
||||||
// const mm = await import('music-metadata');
|
|
||||||
// const metadata = await mm.parseFile(filePath);
|
|
||||||
// log(`${filePath}采样率`, metadata.format.sampleRate);
|
|
||||||
// return metadata.format.sampleRate;
|
|
||||||
// } catch (error) {
|
|
||||||
// log(`${filePath}采样率获取失败`, error.stack);
|
|
||||||
// // console.error(error);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
try {
|
|
||||||
const fileName = path.basename(filePath);
|
|
||||||
const pttPath = path.join(DATA_DIR, uuidv4());
|
|
||||||
if (getFileHeader(filePath) !== "02232153494c4b") {
|
|
||||||
log(`语音文件${filePath}需要转换成silk`)
|
|
||||||
const _isWav = await isWavFile(filePath);
|
|
||||||
const wavPath = pttPath + ".wav"
|
|
||||||
if (!_isWav) {
|
|
||||||
log(`语音文件${filePath}正在转换成wav`)
|
|
||||||
// let voiceData = await fsp.readFile(filePath)
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
const ffmpegPath = getConfigUtil().getConfig().ffmpeg;
|
|
||||||
if (ffmpegPath) {
|
|
||||||
ffmpeg.setFfmpegPath(ffmpegPath);
|
|
||||||
}
|
|
||||||
ffmpeg(filePath).toFormat("wav").audioChannels(2).on('end', function () {
|
|
||||||
log('wav转换完成');
|
|
||||||
})
|
|
||||||
.on('error', function (err) {
|
|
||||||
log(`wav转换出错: `, err.message,);
|
|
||||||
reject(err);
|
|
||||||
})
|
|
||||||
.save(wavPath)
|
|
||||||
.on("end", () => {
|
|
||||||
filePath = wavPath
|
|
||||||
resolve(wavPath);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// const sampleRate = await getAudioSampleRate(filePath) || 0;
|
|
||||||
// log("音频采样率", sampleRate)
|
|
||||||
const pcm = fs.readFileSync(filePath);
|
|
||||||
const silk = await encode(pcm, 0);
|
|
||||||
fs.writeFileSync(pttPath, silk.data);
|
|
||||||
fs.unlink(wavPath, (err) => {
|
|
||||||
});
|
|
||||||
log(`语音文件${filePath}转换成功!`, pttPath)
|
|
||||||
return {
|
|
||||||
converted: true,
|
|
||||||
path: pttPath,
|
|
||||||
duration: silk.duration,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const pcm = fs.readFileSync(filePath);
|
|
||||||
let duration = 0;
|
|
||||||
try {
|
|
||||||
duration = getDuration(pcm);
|
|
||||||
} catch (e) {
|
|
||||||
log("获取语音文件时长失败", filePath, e.stack)
|
|
||||||
duration = fs.statSync(filePath).size / 1024 / 3 // 每3kb大约1s
|
|
||||||
duration = Math.floor(duration)
|
|
||||||
duration = Math.max(1, duration)
|
|
||||||
log("使用文件大小估算时长", duration)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
converted: false,
|
|
||||||
path: filePath,
|
|
||||||
duration: duration,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
log("convert silk failed", error.stack);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function calculateFileMD5(filePath: string): Promise<string> {
|
export function calculateFileMD5(filePath: string): Promise<string> {
|
||||||
|
@@ -11,7 +11,8 @@ export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
|||||||
export const TEMP_DIR = path.join(DATA_DIR, "temp");
|
export const TEMP_DIR = path.join(DATA_DIR, "temp");
|
||||||
export const PLUGIN_DIR = global.LiteLoader.plugins["LLOneBot"].path.plugin;
|
export const PLUGIN_DIR = global.LiteLoader.plugins["LLOneBot"].path.plugin;
|
||||||
if (!fs.existsSync(TEMP_DIR)) {
|
if (!fs.existsSync(TEMP_DIR)) {
|
||||||
fs.mkdirSync(TEMP_DIR);
|
fs.mkdirSync(TEMP_DIR, {recursive: true});
|
||||||
}
|
}
|
||||||
export {getVideoInfo} from "./video";
|
export {getVideoInfo} from "./video";
|
||||||
export {checkFfmpeg} from "./video";
|
export {checkFfmpeg} from "./video";
|
||||||
|
export {encodeSilk} from "./audio";
|
@@ -4,16 +4,18 @@ import path from "node:path";
|
|||||||
import {DATA_DIR, truncateString} from "./index";
|
import {DATA_DIR, truncateString} from "./index";
|
||||||
import {getConfigUtil} from "../config";
|
import {getConfigUtil} from "../config";
|
||||||
|
|
||||||
|
const date = new Date();
|
||||||
|
const logFileName = `llonebot-${date.toLocaleString("zh-CN")}.log`.replace(/\//g, "-").replace(/:/g, "-");
|
||||||
|
const logDir = path.join(DATA_DIR, "logs");
|
||||||
|
if (!fs.existsSync(logDir)) {
|
||||||
|
fs.mkdirSync(logDir, {recursive: true});
|
||||||
|
}
|
||||||
|
|
||||||
export function log(...msg: any[]) {
|
export function log(...msg: any[]) {
|
||||||
if (!getConfigUtil().getConfig().log) {
|
if (!getConfigUtil().getConfig().log) {
|
||||||
return //console.log(...msg);
|
return //console.log(...msg);
|
||||||
}
|
}
|
||||||
let currentDateTime = new Date().toLocaleString();
|
|
||||||
const date = new Date();
|
|
||||||
const year = date.getFullYear();
|
|
||||||
const month = date.getMonth() + 1;
|
|
||||||
const day = date.getDate();
|
|
||||||
const currentDate = `${year}-${month}-${day}`;
|
|
||||||
const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : ""
|
const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : ""
|
||||||
let logMsg = "";
|
let logMsg = "";
|
||||||
for (let msgItem of msg) {
|
for (let msgItem of msg) {
|
||||||
@@ -25,10 +27,11 @@ export function log(...msg: any[]) {
|
|||||||
}
|
}
|
||||||
logMsg += msgItem + " ";
|
logMsg += msgItem + " ";
|
||||||
}
|
}
|
||||||
|
let currentDateTime = new Date().toLocaleString();
|
||||||
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
||||||
// sendLog(...msg);
|
// sendLog(...msg);
|
||||||
// console.log(msg)
|
// console.log(msg)
|
||||||
fs.appendFile(path.join(DATA_DIR, `llonebot-${currentDate}.log`), logMsg, (err: any) => {
|
fs.appendFile(path.join(logDir, logFileName), logMsg, (err: any) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
@@ -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"
|
@@ -49,11 +49,13 @@ import {checkFfmpeg} from "../common/utils/video";
|
|||||||
|
|
||||||
let running = false;
|
let running = false;
|
||||||
|
|
||||||
|
let mainWindow: BrowserWindow | null = null;
|
||||||
|
|
||||||
// 加载插件时触发
|
// 加载插件时触发
|
||||||
function onLoad() {
|
function onLoad() {
|
||||||
log("llonebot main onLoad");
|
log("llonebot main onLoad");
|
||||||
ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => {
|
ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => {
|
||||||
|
|
||||||
return checkNewVersion();
|
return checkNewVersion();
|
||||||
});
|
});
|
||||||
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
|
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
|
||||||
@@ -105,8 +107,26 @@ function onLoad() {
|
|||||||
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) => {
|
||||||
|
if (!ask){
|
||||||
setConfig(config).then();
|
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) => {
|
||||||
@@ -198,7 +218,6 @@ function onLoad() {
|
|||||||
parseInt(operatorId),
|
parseInt(operatorId),
|
||||||
oriMessage.msgShortId
|
oriMessage.msgShortId
|
||||||
)
|
)
|
||||||
|
|
||||||
postOB11Event(groupRecallEvent);
|
postOB11Event(groupRecallEvent);
|
||||||
}
|
}
|
||||||
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
||||||
@@ -370,24 +389,29 @@ function onLoad() {
|
|||||||
selfInfo.nick = selfInfo.uin;
|
selfInfo.nick = selfInfo.uin;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("retry get self info", e);
|
log("retry get self info", e);
|
||||||
|
selfInfo.uin = globalThis.authData?.uin;
|
||||||
|
selfInfo.uid = globalThis.authData?.uid;
|
||||||
|
selfInfo.nick = selfInfo.uin;
|
||||||
}
|
}
|
||||||
log("self info", selfInfo);
|
log("self info", selfInfo, globalThis.authData);
|
||||||
if (selfInfo.uin) {
|
if (selfInfo.uin) {
|
||||||
|
async function getUserNick(){
|
||||||
try {
|
try {
|
||||||
|
getSelfNickCount++;
|
||||||
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
||||||
log("self info", userInfo);
|
log("self info", userInfo);
|
||||||
if (userInfo) {
|
if (userInfo) {
|
||||||
selfInfo.nick = userInfo.nick;
|
selfInfo.nick = userInfo.nick;
|
||||||
} else {
|
return
|
||||||
getSelfNickCount++;
|
|
||||||
if (getSelfNickCount < 10) {
|
|
||||||
return setTimeout(init, 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("get self nickname failed", e.toString());
|
log("get self nickname failed", e.stack);
|
||||||
return setTimeout(init, 1000);
|
|
||||||
}
|
}
|
||||||
|
if (getSelfNickCount < 10) {
|
||||||
|
return setTimeout(getUserNick, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getUserNick().then()
|
||||||
start().then();
|
start().then();
|
||||||
} else {
|
} else {
|
||||||
setTimeout(init, 1000)
|
setTimeout(init, 1000)
|
||||||
@@ -402,6 +426,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);
|
||||||
@@ -417,6 +442,7 @@ try {
|
|||||||
console.log(e.toString())
|
console.log(e.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 这两个函数都是可选的
|
// 这两个函数都是可选的
|
||||||
export {
|
export {
|
||||||
onBrowserWindowCreated
|
onBrowserWindowCreated
|
||||||
|
@@ -2,7 +2,6 @@ import {ReceiveCmdS} from "../hook";
|
|||||||
import {Group, GroupMember, GroupMemberRole, GroupNotifies, GroupNotify, GroupRequestOperateTypes} from "../types";
|
import {Group, GroupMember, GroupMemberRole, GroupNotifies, GroupNotify, GroupRequestOperateTypes} from "../types";
|
||||||
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||||
import {uidMaps} from "../../common/data";
|
import {uidMaps} from "../../common/data";
|
||||||
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";
|
import {NTQQWindowApi, NTQQWindows} 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
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ export class NTQQMsgApi {
|
|||||||
}
|
}
|
||||||
static async getMsgHistory(peer: Peer, msgId: string, count: number) {
|
static async getMsgHistory(peer: Peer, msgId: string, count: number) {
|
||||||
return await callNTQQApi<GeneralCallResult & {msgList: RawMessage[]}>({
|
return await callNTQQApi<GeneralCallResult & {msgList: RawMessage[]}>({
|
||||||
methodName: NTQQApiMethod.HISTORY_MSG,
|
methodName: isQQ998 ? NTQQApiMethod.HISTORY_MSG_998 : NTQQApiMethod.HISTORY_MSG,
|
||||||
args: [{
|
args: [{
|
||||||
peer,
|
peer,
|
||||||
msgId,
|
msgId,
|
||||||
|
@@ -2,6 +2,7 @@ import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../nt
|
|||||||
import {SelfInfo, User} from "../types";
|
import {SelfInfo, User} from "../types";
|
||||||
import {ReceiveCmdS} from "../hook";
|
import {ReceiveCmdS} from "../hook";
|
||||||
import {uidMaps} from "../../common/data";
|
import {uidMaps} from "../../common/data";
|
||||||
|
import {NTQQWindowApi, NTQQWindows} from "./window";
|
||||||
|
|
||||||
|
|
||||||
export class NTQQUserApi{
|
export class NTQQUserApi{
|
||||||
@@ -53,4 +54,50 @@ export class NTQQUserApi{
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getPSkey() {
|
||||||
|
return await callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.GROUP_HOME_WORK,
|
||||||
|
methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
domain: "qun.qq.com"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async getSkey(groupName: string, groupCode: string): Promise<{data: string}> {
|
||||||
|
return await NTQQWindowApi.openWindow<{data: string}>(NTQQWindows.GroupHomeWorkWindow, [{
|
||||||
|
groupName,
|
||||||
|
groupCode,
|
||||||
|
"source": "funcbar"
|
||||||
|
}], ReceiveCmdS.SKEY_UPDATE, 1);
|
||||||
|
// return await callNTQQApi<string>({
|
||||||
|
// className: NTQQApiClass.GROUP_HOME_WORK,
|
||||||
|
// methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||||
|
// args: [
|
||||||
|
// {
|
||||||
|
// domain: "qun.qq.com"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// })
|
||||||
|
// return await callNTQQApi<GeneralCallResult>({
|
||||||
|
// methodName: NTQQApiMethod.GET_SKEY,
|
||||||
|
// args: [
|
||||||
|
// {
|
||||||
|
// "domains": [
|
||||||
|
// "qzone.qq.com",
|
||||||
|
// "qlive.qq.com",
|
||||||
|
// "qun.qq.com",
|
||||||
|
// "gamecenter.qq.com",
|
||||||
|
// "vip.qq.com",
|
||||||
|
// "qianbao.qq.com",
|
||||||
|
// "qidian.qq.com"
|
||||||
|
// ],
|
||||||
|
// "isForNewPCQQ": false
|
||||||
|
// },
|
||||||
|
// null
|
||||||
|
// ]
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -1,7 +1,6 @@
|
|||||||
import {net, session} from "electron";
|
|
||||||
import {NTQQApi} from "../ntcall";
|
|
||||||
import {groups} from "../../common/data";
|
import {groups} from "../../common/data";
|
||||||
import {log} from "../../common/utils";
|
import {log} from "../../common/utils";
|
||||||
|
import {NTQQUserApi} from "./user";
|
||||||
|
|
||||||
export class WebApi{
|
export class WebApi{
|
||||||
private static bkn: string;
|
private static bkn: string;
|
||||||
@@ -43,9 +42,9 @@ export class WebApi{
|
|||||||
private async init(){
|
private async init(){
|
||||||
if (!WebApi.bkn) {
|
if (!WebApi.bkn) {
|
||||||
const group = groups[0];
|
const group = groups[0];
|
||||||
WebApi.skey = (await NTQQApi.getSkey(group.groupName, group.groupCode)).data;
|
WebApi.skey = (await NTQQUserApi.getSkey(group.groupName, group.groupCode)).data;
|
||||||
WebApi.bkn = this.genBkn(WebApi.skey);
|
WebApi.bkn = this.genBkn(WebApi.skey);
|
||||||
let cookie = await NTQQApi.getPSkey();
|
let cookie = await NTQQUserApi.getPSkey();
|
||||||
const pskeyRegex = /p_skey=([^;]+)/;
|
const pskeyRegex = /p_skey=([^;]+)/;
|
||||||
const match = cookie.match(pskeyRegex);
|
const match = cookie.match(pskeyRegex);
|
||||||
const pskeyValue = match ? match[1] : null;
|
const pskeyValue = match ? match[1] : null;
|
||||||
|
@@ -14,9 +14,10 @@ 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, isGIF} from "../common/utils/file";
|
import {calculateFileMD5, isGIF} from "../common/utils/file";
|
||||||
import {log} from "../common/utils/log";
|
import {log} from "../common/utils/log";
|
||||||
import {defaultVideoThumb, getVideoInfo} from "../common/utils/video";
|
import {defaultVideoThumb, getVideoInfo} from "../common/utils/video";
|
||||||
|
import {encodeSilk} from "../common/utils/audio";
|
||||||
|
|
||||||
|
|
||||||
export class SendMsgElementConstructor {
|
export class SendMsgElementConstructor {
|
||||||
@@ -211,7 +212,7 @@ export class SendMsgElementConstructor {
|
|||||||
md5HexStr: md5,
|
md5HexStr: md5,
|
||||||
fileSize: fileSize,
|
fileSize: fileSize,
|
||||||
// duration: Math.max(1, Math.round(fileSize / 1024 / 3)), // 一秒钟大概是3kb大小, 小于1秒的按1秒算
|
// duration: Math.max(1, Math.round(fileSize / 1024 / 3)), // 一秒钟大概是3kb大小, 小于1秒的按1秒算
|
||||||
duration: duration / 1000,
|
duration: duration,
|
||||||
formatType: 1,
|
formatType: 1,
|
||||||
voiceType: 1,
|
voiceType: 1,
|
||||||
voiceChangeType: 0,
|
voiceChangeType: 0,
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import {BrowserWindow} from 'electron';
|
import {BrowserWindow} from 'electron';
|
||||||
import {NTQQApiClass} from "./ntcall";
|
import {NTQQApiClass} from "./ntcall";
|
||||||
import {NTQQMsgApi, sendMessagePool} from "./api/msg"
|
import {NTQQMsgApi, sendMessagePool} from "./api/msg"
|
||||||
import {ChatType, Group, RawMessage, User} from "./types";
|
import {ChatType, Group, GroupMember, RawMessage, User} from "./types";
|
||||||
import {friends, groups, selfInfo, tempGroupCodeMap, uidMaps} from "../common/data";
|
import {friends, groups, selfInfo, tempGroupCodeMap, uidMaps} from "../common/data";
|
||||||
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
||||||
import {v4 as uuidv4} from "uuid"
|
import {v4 as uuidv4} from "uuid"
|
||||||
@@ -12,6 +12,7 @@ import {dbUtil} from "../common/db";
|
|||||||
import {NTQQGroupApi} from "./api/group";
|
import {NTQQGroupApi} from "./api/group";
|
||||||
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 {OB11GroupCardEvent} from "../onebot11/event/notice/OB11GroupCardEvent";
|
||||||
|
|
||||||
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ export let ReceiveCmdS = {
|
|||||||
USER_DETAIL_INFO: "nodeIKernelProfileListener/onProfileDetailInfoChanged",
|
USER_DETAIL_INFO: "nodeIKernelProfileListener/onProfileDetailInfoChanged",
|
||||||
GROUPS: "nodeIKernelGroupListener/onGroupListUpdate",
|
GROUPS: "nodeIKernelGroupListener/onGroupListUpdate",
|
||||||
GROUPS_UNIX: "onGroupListUpdate",
|
GROUPS_UNIX: "onGroupListUpdate",
|
||||||
|
GROUP_MEMBER_INFO_UPDATE: "nodeIKernelGroupListener/onMemberInfoChange",
|
||||||
FRIENDS: "onBuddyListChange",
|
FRIENDS: "onBuddyListChange",
|
||||||
MEDIA_DOWNLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaDownloadComplete",
|
MEDIA_DOWNLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaDownloadComplete",
|
||||||
UNREAD_GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated",
|
UNREAD_GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated",
|
||||||
@@ -192,7 +194,7 @@ export function removeReceiveHook(id: string) {
|
|||||||
let activatedGroups: string[] = [];
|
let activatedGroups: string[] = [];
|
||||||
async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
||||||
for (let group of _groups) {
|
for (let group of _groups) {
|
||||||
// log("update group", group)
|
log("update group", group)
|
||||||
if (!activatedGroups.includes(group.groupCode)) {
|
if (!activatedGroups.includes(group.groupCode)) {
|
||||||
NTQQMsgApi.activateGroupChat(group.groupCode).then((r) => {
|
NTQQMsgApi.activateGroupChat(group.groupCode).then((r) => {
|
||||||
activatedGroups.push(group.groupCode);
|
activatedGroups.push(group.groupCode);
|
||||||
@@ -221,12 +223,13 @@ async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processGroupEvent(payload) {
|
async function processGroupEvent(payload: {groupList: Group[]}) {
|
||||||
try {
|
try {
|
||||||
const newGroupList = payload.groupList;
|
const newGroupList = payload.groupList;
|
||||||
for (const group of newGroupList) {
|
for (const group of newGroupList) {
|
||||||
let existGroup = groups.find(g => g.groupCode == group.groupCode);
|
let existGroup = groups.find(g => g.groupCode == group.groupCode);
|
||||||
if (existGroup) {
|
if (existGroup) {
|
||||||
|
|
||||||
if (existGroup.memberCount > group.memberCount) {
|
if (existGroup.memberCount > group.memberCount) {
|
||||||
const oldMembers = existGroup.members;
|
const oldMembers = existGroup.members;
|
||||||
|
|
||||||
@@ -242,39 +245,50 @@ async function processGroupEvent(payload) {
|
|||||||
|
|
||||||
for (const member of oldMembers) {
|
for (const member of oldMembers) {
|
||||||
if (!newMembersSet.has(member.uin)) {
|
if (!newMembersSet.has(member.uin)) {
|
||||||
postOB11Event(new OB11GroupDecreaseEvent(group.groupCode, parseInt(member.uin)));
|
postOB11Event(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGroups(newGroupList, false).then();
|
updateGroups(newGroupList, false).then();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
updateGroups(payload.groupList).then();
|
updateGroups(payload.groupList).then();
|
||||||
console.log(e);
|
log("更新群信息错误", e.stack.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 群列表变动
|
// 群列表变动
|
||||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS, (payload) => {
|
registerReceiveHook<{ groupList: Group[], updateType: number }>([ReceiveCmdS.GROUPS, ReceiveCmdS.GROUPS_UNIX], (payload) => {
|
||||||
|
log("群列表变动", payload)
|
||||||
if (payload.updateType != 2) {
|
if (payload.updateType != 2) {
|
||||||
updateGroups(payload.groupList).then();
|
updateGroups(payload.groupList).then();
|
||||||
} else {
|
} else {
|
||||||
if (process.platform == "win32") {
|
|
||||||
processGroupEvent(payload).then();
|
processGroupEvent(payload).then();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS_UNIX, (payload) => {
|
|
||||||
if (payload.updateType != 2) {
|
registerReceiveHook<{groupCode: string, dataSource: number, members: Set<GroupMember>}>(ReceiveCmdS.GROUP_MEMBER_INFO_UPDATE, (payload) => {
|
||||||
updateGroups(payload.groupList).then();
|
const groupCode = payload.groupCode;
|
||||||
} else {
|
const members = Array.from(payload.members.values());
|
||||||
if (process.platform != "win32") {
|
// log("群成员变动", groupCode, payload.members.keys(), payload.members.values())
|
||||||
processGroupEvent(payload).then();
|
// const existGroup = groups.find(g => g.groupCode == groupCode);
|
||||||
}
|
// if (existGroup) {
|
||||||
}
|
// log("对比群成员", existGroup.members, members)
|
||||||
|
// for (const member of members) {
|
||||||
|
// const existMember = existGroup.members.find(m => m.uin == member.uin);
|
||||||
|
// if (existMember) {
|
||||||
|
// log("对比群名片", existMember.cardName, member.cardName)
|
||||||
|
// if (existMember.cardName != member.cardName) {
|
||||||
|
// postOB11Event(new OB11GroupCardEvent(parseInt(existGroup.groupCode), parseInt(member.uin), member.cardName, existMember.cardName));
|
||||||
|
// }
|
||||||
|
// Object.assign(existMember, member);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
})
|
})
|
||||||
|
|
||||||
// 好友列表变动
|
// 好友列表变动
|
||||||
|
@@ -23,7 +23,8 @@ export enum NTQQApiClass {
|
|||||||
export enum NTQQApiMethod {
|
export enum NTQQApiMethod {
|
||||||
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
|
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
|
||||||
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
||||||
HISTORY_MSG = "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",
|
||||||
@@ -117,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)
|
||||||
@@ -185,59 +186,4 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -180,6 +180,7 @@ export interface PicElement {
|
|||||||
|
|
||||||
export enum GrayTipElementSubType {
|
export enum GrayTipElementSubType {
|
||||||
INVITE_NEW_MEMBER = 12,
|
INVITE_NEW_MEMBER = 12,
|
||||||
|
MEMBER_NEW_TITLE = 17
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GrayTipElement {
|
export interface GrayTipElement {
|
||||||
@@ -196,6 +197,9 @@ export interface GrayTipElement {
|
|||||||
groupElement: TipGroupElement,
|
groupElement: TipGroupElement,
|
||||||
xmlElement: {
|
xmlElement: {
|
||||||
content: string;
|
content: string;
|
||||||
|
},
|
||||||
|
jsonGrayTipElement:{
|
||||||
|
jsonStr: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import {ActionName, BaseCheckResult} from "./types"
|
import {ActionName, BaseCheckResult} from "./types"
|
||||||
import {OB11Response} from "./utils"
|
import {OB11Response} from "./OB11Response"
|
||||||
import {OB11Return} from "../types";
|
import {OB11Return} from "../types";
|
||||||
|
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../common/utils/log";
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
import BaseAction from "./BaseAction";
|
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 {log, sleep, uri2local} from "../../../common/utils";
|
||||||
import {NTQQFileApi} from "../../ntqqapi/api/file";
|
import {NTQQFileApi} from "../../../ntqqapi/api/file";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
import {FileElement, RawMessage, VideoElement} from "../../../ntqqapi/types";
|
||||||
|
|
||||||
export interface GetFilePayload {
|
export interface GetFilePayload {
|
||||||
file: string // 文件名或者fileUuid
|
file: string // 文件名或者fileUuid
|
||||||
@@ -20,6 +21,14 @@ export interface GetFileResponse {
|
|||||||
|
|
||||||
|
|
||||||
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||||
|
private getElement(msg: RawMessage): {id: string, element: VideoElement | FileElement}{
|
||||||
|
let element = msg.elements.find(e=>e.fileElement)
|
||||||
|
if (!element){
|
||||||
|
element = msg.elements.find(e=>e.videoElement)
|
||||||
|
return {id: element.elementId, element: element.videoElement}
|
||||||
|
}
|
||||||
|
return {id: element.elementId, element: element.fileElement}
|
||||||
|
}
|
||||||
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
||||||
const cache = await dbUtil.getFileCache(payload.file)
|
const cache = await dbUtil.getFileCache(payload.file)
|
||||||
const {autoDeleteFile, enableLocalFile2Url, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
const {autoDeleteFile, enableLocalFile2Url, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
||||||
@@ -49,18 +58,17 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|||||||
let msg = await dbUtil.getMsgByLongId(cache.msgId)
|
let msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||||
if (msg){
|
if (msg){
|
||||||
log("找到了文件 msg", msg)
|
log("找到了文件 msg", msg)
|
||||||
const element = msg.elements.find(e=>e.fileElement)
|
let element = this.getElement(msg);
|
||||||
log("找到了文件 element", element);
|
log("找到了文件 element", element);
|
||||||
// 构建下载函数
|
// 构建下载函数
|
||||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
element.elementId, "", "", true)
|
element.id, "", "", true)
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
msg = await dbUtil.getMsgByLongId(cache.msgId)
|
msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||||
log("下载完成后的msg", msg)
|
log("下载完成后的msg", msg)
|
||||||
cache.filePath = msg?.elements.find(e=>e.fileElement)?.fileElement?.filePath
|
cache.filePath = this.getElement(msg).element.filePath
|
||||||
dbUtil.addFileCache(payload.file, cache).then()
|
dbUtil.addFileCache(payload.file, cache).then()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@@ -1,5 +1,5 @@
|
|||||||
import {GetFileBase} from "./GetFile";
|
import {GetFileBase} from "./GetFile";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
|
|
||||||
export default class GetImage extends GetFileBase {
|
export default class GetImage extends GetFileBase {
|
@@ -1,5 +1,5 @@
|
|||||||
import {GetFileBase, GetFilePayload, GetFileResponse} from "./GetFile";
|
import {GetFileBase, GetFilePayload, GetFileResponse} from "./GetFile";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
interface Payload extends GetFilePayload {
|
interface Payload extends GetFilePayload {
|
||||||
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
|
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
|
@@ -11,24 +11,29 @@ import {log} from "../../../common/utils";
|
|||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number
|
group_id: number
|
||||||
message_seq: number
|
message_seq: number,
|
||||||
|
count: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, OB11Message[]> {
|
interface Response{
|
||||||
|
messages: OB11Message[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Response> {
|
||||||
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory
|
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<OB11Message[]> {
|
protected async _handle(payload: Payload): Promise<Response> {
|
||||||
const group = groups.find(group => group.groupCode === payload.group_id.toString())
|
const group = groups.find(group => group.groupCode === payload.group_id.toString())
|
||||||
if (!group) {
|
if (!group) {
|
||||||
throw `群${payload.group_id}不存在`
|
throw `群${payload.group_id}不存在`
|
||||||
}
|
}
|
||||||
const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || "0"
|
const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || "0"
|
||||||
// log("startMsgId", startMsgId)
|
// log("startMsgId", startMsgId)
|
||||||
let msgList = (await NTQQMsgApi.getMsgHistory({chatType: ChatType.group, peerUid: group.groupCode}, startMsgId, 20)).msgList
|
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 => {
|
await Promise.all(msgList.map(async msg => {
|
||||||
msg.msgShortId = await dbUtil.addMsg(msg)
|
msg.msgShortId = await dbUtil.addMsg(msg)
|
||||||
}))
|
}))
|
||||||
const ob11MsgList = await Promise.all(msgList.map(msg=>OB11Constructor.message(msg)))
|
const ob11MsgList = await Promise.all(msgList.map(msg=>OB11Constructor.message(msg)))
|
||||||
return ob11MsgList
|
return {"messages": ob11MsgList}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
import SendMsg from "../SendMsg";
|
import SendMsg from "../msg/SendMsg";
|
||||||
import {OB11PostSendMsg} from "../../types";
|
import {OB11PostSendMsg} from "../../types";
|
||||||
import {ActionName} from "../types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
@@ -6,7 +6,9 @@ export class GoCQHTTPSendGroupForwardMsg extends SendMsg {
|
|||||||
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||||
|
|
||||||
protected async check(payload: OB11PostSendMsg) {
|
protected async check(payload: OB11PostSendMsg) {
|
||||||
|
if (payload.messages){
|
||||||
payload.message = this.convertMessage2List(payload.messages);
|
payload.message = this.convertMessage2List(payload.messages);
|
||||||
|
}
|
||||||
return super.check(payload);
|
return super.check(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11Group} from '../types';
|
import {OB11Group} from '../../types';
|
||||||
import {getGroup} from "../../common/data";
|
import {getGroup} from "../../../common/data";
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
interface PayloadType {
|
interface PayloadType {
|
||||||
group_id: number
|
group_id: number
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11Group} from '../types';
|
import {OB11Group} from '../../types';
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import {groups} from "../../common/data";
|
import {groups} from "../../../common/data";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
|
|
||||||
class GetGroupList extends BaseAction<null, OB11Group[]> {
|
class GetGroupList extends BaseAction<null, OB11Group[]> {
|
@@ -1,11 +1,11 @@
|
|||||||
import {OB11GroupMember} from '../types';
|
import {OB11GroupMember} from '../../types';
|
||||||
import {getGroupMember} from "../../common/data";
|
import {getGroupMember} from "../../../common/data";
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQUserApi} from "../../ntqqapi/api/user";
|
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../../common/utils/log";
|
||||||
import {isNull} from "../../common/utils/helper";
|
import {isNull} from "../../../common/utils/helper";
|
||||||
|
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
@@ -1,9 +1,9 @@
|
|||||||
import {OB11GroupMember} from '../types';
|
import {OB11GroupMember} from '../../types';
|
||||||
import {getGroup} from "../../common/data";
|
import {getGroup} from "../../../common/data";
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
||||||
group_id: number
|
group_id: number
|
@@ -1,5 +1,5 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
export default class GetGuildList extends BaseAction<null, null> {
|
export default class GetGuildList extends BaseAction<null, null> {
|
||||||
actionName = ActionName.GetGuildList
|
actionName = ActionName.GetGuildList
|
@@ -1,8 +1,8 @@
|
|||||||
import SendMsg from "./SendMsg";
|
import SendMsg from "../msg/SendMsg";
|
||||||
import {ActionName, BaseCheckResult} from "./types";
|
import {ActionName, BaseCheckResult} from "../types";
|
||||||
import {OB11PostSendMsg} from "../types";
|
import {OB11PostSendMsg} from "../../types";
|
||||||
|
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
|
|
||||||
class SendGroupMsg extends SendMsg {
|
class SendGroupMsg extends SendMsg {
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {GroupRequestOperateTypes} from "../../ntqqapi/types";
|
import {GroupRequestOperateTypes} from "../../../ntqqapi/types";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
flag: string,
|
flag: string,
|
||||||
@@ -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
|
@@ -1,8 +1,8 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {getGroupMember} from "../../common/data";
|
import {getGroupMember} from "../../../common/data";
|
||||||
import {GroupMemberRole} from "../../ntqqapi/types";
|
import {GroupMemberRole} from "../../../ntqqapi/types";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -15,10 +15,11 @@ export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||||
|
const enable = payload.enable.toString() === "true"
|
||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`
|
throw `群成员${payload.user_id}不存在`
|
||||||
}
|
}
|
||||||
await 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
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {getGroupMember} from "../../common/data";
|
import {getGroupMember} from "../../../common/data";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {getGroupMember} from "../../common/data";
|
import {getGroupMember} from "../../../common/data";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {getGroupMember} from "../../common/data";
|
import {getGroupMember} from "../../../common/data";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
@@ -1,6 +1,6 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
@@ -1,6 +1,6 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -11,8 +11,8 @@ export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName.SetGroupWholeBan
|
actionName = ActionName.SetGroupWholeBan
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
const enable = payload.enable.toString() === "true"
|
||||||
await NTQQGroupApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
await NTQQGroupApi.banGroup(payload.group_id.toString(), enable)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,44 +1,44 @@
|
|||||||
import GetMsg from './GetMsg'
|
import GetMsg from './msg/GetMsg'
|
||||||
import GetLoginInfo from './GetLoginInfo'
|
import GetLoginInfo from './system/GetLoginInfo'
|
||||||
import GetFriendList from './GetFriendList'
|
import GetFriendList from './user/GetFriendList'
|
||||||
import GetGroupList from './GetGroupList'
|
import GetGroupList from './group/GetGroupList'
|
||||||
import GetGroupInfo from './GetGroupInfo'
|
import GetGroupInfo from './group/GetGroupInfo'
|
||||||
import GetGroupMemberList from './GetGroupMemberList'
|
import GetGroupMemberList from './group/GetGroupMemberList'
|
||||||
import GetGroupMemberInfo from './GetGroupMemberInfo'
|
import GetGroupMemberInfo from './group/GetGroupMemberInfo'
|
||||||
import SendGroupMsg from './SendGroupMsg'
|
import SendGroupMsg from './group/SendGroupMsg'
|
||||||
import SendPrivateMsg from './SendPrivateMsg'
|
import SendPrivateMsg from './msg/SendPrivateMsg'
|
||||||
import SendMsg from './SendMsg'
|
import SendMsg from './msg/SendMsg'
|
||||||
import DeleteMsg from "./DeleteMsg";
|
import DeleteMsg from "./msg/DeleteMsg";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import GetVersionInfo from "./GetVersionInfo";
|
import GetVersionInfo from "./system/GetVersionInfo";
|
||||||
import CanSendRecord from "./CanSendRecord";
|
import CanSendRecord from "./system/CanSendRecord";
|
||||||
import CanSendImage from "./CanSendImage";
|
import CanSendImage from "./system/CanSendImage";
|
||||||
import GetStatus from "./GetStatus";
|
import GetStatus from "./system/GetStatus";
|
||||||
import {GoCQHTTPSendGroupForwardMsg, GoCQHTTPSendPrivateForwardMsg} from "./go-cqhttp/SendForwardMsg";
|
import {GoCQHTTPSendGroupForwardMsg, GoCQHTTPSendPrivateForwardMsg} from "./go-cqhttp/SendForwardMsg";
|
||||||
import GoCQHTTPGetStrangerInfo from "./go-cqhttp/GetStrangerInfo";
|
import GoCQHTTPGetStrangerInfo from "./go-cqhttp/GetStrangerInfo";
|
||||||
import SendLike from "./SendLike";
|
import SendLike from "./user/SendLike";
|
||||||
import SetGroupAddRequest from "./SetGroupAddRequest";
|
import SetGroupAddRequest from "./group/SetGroupAddRequest";
|
||||||
import SetGroupLeave from "./SetGroupLeave";
|
import SetGroupLeave from "./group/SetGroupLeave";
|
||||||
import GetGuildList from "./GetGuildList";
|
import GetGuildList from "./group/GetGuildList";
|
||||||
import Debug from "./llonebot/Debug";
|
import Debug from "./llonebot/Debug";
|
||||||
import SetFriendAddRequest from "./SetFriendAddRequest";
|
import SetFriendAddRequest from "./user/SetFriendAddRequest";
|
||||||
import SetGroupWholeBan from "./SetGroupWholeBan";
|
import SetGroupWholeBan from "./group/SetGroupWholeBan";
|
||||||
import SetGroupName from "./SetGroupName";
|
import SetGroupName from "./group/SetGroupName";
|
||||||
import SetGroupBan from "./SetGroupBan";
|
import SetGroupBan from "./group/SetGroupBan";
|
||||||
import SetGroupKick from "./SetGroupKick";
|
import SetGroupKick from "./group/SetGroupKick";
|
||||||
import SetGroupAdmin from "./SetGroupAdmin";
|
import SetGroupAdmin from "./group/SetGroupAdmin";
|
||||||
import SetGroupCard from "./SetGroupCard";
|
import SetGroupCard from "./group/SetGroupCard";
|
||||||
import GetImage from "./GetImage";
|
import GetImage from "./file/GetImage";
|
||||||
import GetRecord from "./GetRecord";
|
import GetRecord from "./file/GetRecord";
|
||||||
import GoCQHTTPMarkMsgAsRead from "./MarkMsgAsRead";
|
import GoCQHTTPMarkMsgAsRead from "./msg/MarkMsgAsRead";
|
||||||
import CleanCache from "./CleanCache";
|
import CleanCache from "./system/CleanCache";
|
||||||
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
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 GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
||||||
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
||||||
import GetFile from "./GetFile";
|
import GetFile from "./file/GetFile";
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new GetFile(),
|
new GetFile(),
|
||||||
|
@@ -1,5 +1,14 @@
|
|||||||
import BaseAction from "../BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import * as ntqqApi from "../../../ntqqapi/api";
|
// import * as ntqqApi from "../../../ntqqapi/api";
|
||||||
|
import {
|
||||||
|
NTQQMsgApi,
|
||||||
|
NTQQFriendApi,
|
||||||
|
NTQQGroupApi,
|
||||||
|
NTQQUserApi,
|
||||||
|
NTQQFileApi,
|
||||||
|
NTQQFileCacheApi,
|
||||||
|
NTQQWindowApi,
|
||||||
|
} from "../../../ntqqapi/api";
|
||||||
import {ActionName} from "../types";
|
import {ActionName} from "../types";
|
||||||
import {log} from "../../../common/utils/log";
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
@@ -13,8 +22,10 @@ export default class Debug extends BaseAction<Payload, any> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
log("debug call ntqq api", payload);
|
log("debug call ntqq api", payload);
|
||||||
for (const ntqqApiClass in ntqqApi) {
|
const ntqqApi = [NTQQMsgApi, NTQQFriendApi, NTQQGroupApi, NTQQUserApi, NTQQFileApi, NTQQFileCacheApi, NTQQWindowApi]
|
||||||
const method = ntqqApi[ntqqApiClass][payload.method]
|
for (const ntqqApiClass of ntqqApi) {
|
||||||
|
log("ntqqApiClass", ntqqApiClass)
|
||||||
|
const method = ntqqApiClass[payload.method]
|
||||||
if (method) {
|
if (method) {
|
||||||
const result = method(...payload.args);
|
const result = method(...payload.args);
|
||||||
if (method.constructor.name === "AsyncFunction") {
|
if (method.constructor.name === "AsyncFunction") {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../../common/db";
|
||||||
import {NTQQMsgApi} from "../../ntqqapi/api/msg";
|
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: number
|
message_id: number
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11Message} from '../types';
|
import {OB11Message} from '../../types';
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../../common/db";
|
||||||
|
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
@@ -1,5 +1,5 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
interface Payload{
|
interface Payload{
|
||||||
message_id: number
|
message_id: number
|
@@ -6,7 +6,7 @@ import {
|
|||||||
RawMessage,
|
RawMessage,
|
||||||
SendArkElement,
|
SendArkElement,
|
||||||
SendMessageElement
|
SendMessageElement
|
||||||
} from "../../ntqqapi/types";
|
} from "../../../ntqqapi/types";
|
||||||
import {
|
import {
|
||||||
friends,
|
friends,
|
||||||
getFriend,
|
getFriend,
|
||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
getGroupMember,
|
getGroupMember,
|
||||||
getUidByUin,
|
getUidByUin,
|
||||||
selfInfo,
|
selfInfo,
|
||||||
} from "../../common/data";
|
} from "../../../common/data";
|
||||||
import {
|
import {
|
||||||
OB11MessageCustomMusic,
|
OB11MessageCustomMusic,
|
||||||
OB11MessageData,
|
OB11MessageData,
|
||||||
@@ -22,19 +22,19 @@ import {
|
|||||||
OB11MessageMixType,
|
OB11MessageMixType,
|
||||||
OB11MessageNode,
|
OB11MessageNode,
|
||||||
OB11PostSendMsg
|
OB11PostSendMsg
|
||||||
} 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 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";
|
||||||
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 {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";
|
import {uri2local} from "../../../common/utils";
|
||||||
|
|
||||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||||
function checkUri(uri: string): boolean {
|
function checkUri(uri: string): boolean {
|
||||||
@@ -75,278 +75,25 @@ export interface ReturnDataType {
|
|||||||
message_id: number
|
message_id: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
export function convertMessage2List(message: OB11MessageMixType, autoEscape = false) {
|
||||||
actionName = ActionName.SendMsg
|
|
||||||
|
|
||||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
|
||||||
const messages = this.convertMessage2List(payload.message);
|
|
||||||
const fmNum = this.getSpecialMsgNum(payload, OB11MessageDataType.node)
|
|
||||||
if (fmNum && fmNum != messages.length) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
message: "转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (payload.group_id && !(await getGroup(payload.group_id))) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
message: `群${payload.group_id}不存在`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (payload.user_id && payload.message_type !== "group") {
|
|
||||||
if (!(await getFriend(payload.user_id))) {
|
|
||||||
if (!ALLOW_SEND_TEMP_MSG && !(await dbUtil.getReceivedTempUinMap())[payload.user_id.toString()]) {
|
|
||||||
return {
|
|
||||||
valid: false,
|
|
||||||
message: `不能发送临时消息`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
valid: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async _handle(payload: OB11PostSendMsg) {
|
|
||||||
|
|
||||||
const peer: Peer = {
|
|
||||||
chatType: ChatType.friend,
|
|
||||||
peerUid: ""
|
|
||||||
}
|
|
||||||
let isTempMsg = false;
|
|
||||||
let group: Group | undefined = undefined;
|
|
||||||
const genGroupPeer = async () => {
|
|
||||||
group = await getGroup(payload.group_id.toString())
|
|
||||||
peer.chatType = ChatType.group
|
|
||||||
// peer.name = group.name
|
|
||||||
peer.peerUid = group.groupCode
|
|
||||||
}
|
|
||||||
|
|
||||||
const genFriendPeer = () => {
|
|
||||||
const friend = friends.find(f => f.uin == payload.user_id.toString())
|
|
||||||
if (friend) {
|
|
||||||
// peer.name = friend.nickName
|
|
||||||
peer.peerUid = friend.uid
|
|
||||||
} else {
|
|
||||||
peer.chatType = ChatType.temp
|
|
||||||
const tempUserUid = getUidByUin(payload.user_id.toString())
|
|
||||||
if (!tempUserUid) {
|
|
||||||
throw (`找不到私聊对象${payload.user_id}`)
|
|
||||||
}
|
|
||||||
// peer.name = tempUser.nickName
|
|
||||||
isTempMsg = true;
|
|
||||||
peer.peerUid = tempUserUid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (payload?.group_id && payload.message_type === "group") {
|
|
||||||
await genGroupPeer()
|
|
||||||
|
|
||||||
} else if (payload?.user_id) {
|
|
||||||
genFriendPeer()
|
|
||||||
} else if (payload.group_id) {
|
|
||||||
await genGroupPeer()
|
|
||||||
} else {
|
|
||||||
throw ("发送消息参数错误, 请指定group_id或user_id")
|
|
||||||
}
|
|
||||||
const messages = this.convertMessage2List(payload.message);
|
|
||||||
if (this.getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
|
||||||
try {
|
|
||||||
const returnMsg = await this.handleForwardNode(peer, messages as OB11MessageNode[], group)
|
|
||||||
return {message_id: returnMsg.msgShortId}
|
|
||||||
} catch (e) {
|
|
||||||
throw ("发送转发消息失败 " + e.toString())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
|
||||||
const music: OB11MessageCustomMusic = messages[0] as OB11MessageCustomMusic
|
|
||||||
if (music) {
|
|
||||||
const {url, audio, title, content, image} = music.data;
|
|
||||||
const selfPeer: Peer = {peerUid: selfInfo.uid, chatType: ChatType.friend}
|
|
||||||
// 搞不定!
|
|
||||||
// const musicMsg = await this.send(selfPeer, [this.genMusicElement(url, audio, title, content, image)], [], false)
|
|
||||||
// 转发
|
|
||||||
// const res = await NTQQApi.forwardMsg(selfPeer, peer, [musicMsg.msgId])
|
|
||||||
// log("转发音乐消息成功", res);
|
|
||||||
// return {message_id: musicMsg.msgShortId}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// log("send msg:", peer, sendElements)
|
|
||||||
const {sendElements, deleteAfterSentFiles} = await this.createSendElements(messages, group)
|
|
||||||
const returnMsg = await this.send(peer, sendElements, deleteAfterSentFiles)
|
|
||||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
|
||||||
}));
|
|
||||||
return {message_id: returnMsg.msgShortId}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected convertMessage2List(message: OB11MessageMixType) {
|
|
||||||
if (typeof message === "string") {
|
if (typeof message === "string") {
|
||||||
// message = [{
|
if (!autoEscape) {
|
||||||
// type: OB11MessageDataType.text,
|
|
||||||
// data: {
|
|
||||||
// text: message
|
|
||||||
// }
|
|
||||||
// }] as OB11MessageData[]
|
|
||||||
message = decodeCQCode(message.toString())
|
message = decodeCQCode(message.toString())
|
||||||
|
} else {
|
||||||
|
message = [{
|
||||||
|
type: OB11MessageDataType.text,
|
||||||
|
data: {
|
||||||
|
text: message
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
} else if (!Array.isArray(message)) {
|
} else if (!Array.isArray(message)) {
|
||||||
message = [message]
|
message = [message]
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
|
export async function createSendElements(messageData: OB11MessageData[], group: Group | undefined, ignoreTypes: OB11MessageDataType[] = []) {
|
||||||
if (Array.isArray(payload.message)) {
|
|
||||||
return payload.message.filter(msg => msg.type == msgType).length
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
private async cloneMsg(msg: RawMessage): Promise<RawMessage> {
|
|
||||||
log("克隆的目标消息", msg)
|
|
||||||
let sendElements: SendMessageElement[] = [];
|
|
||||||
for (const ele of msg.elements) {
|
|
||||||
sendElements.push(ele as SendMessageElement)
|
|
||||||
// Object.keys(ele).forEach((eleKey) => {
|
|
||||||
// if (eleKey.endsWith("Element")) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
if (sendElements.length === 0) {
|
|
||||||
log("需要clone的消息无法解析,将会忽略掉", msg)
|
|
||||||
}
|
|
||||||
log("克隆消息", sendElements)
|
|
||||||
try {
|
|
||||||
const nodeMsg = await NTQQMsgApi.sendMsg({
|
|
||||||
chatType: ChatType.friend,
|
|
||||||
peerUid: selfInfo.uid
|
|
||||||
}, sendElements, true);
|
|
||||||
await sleep(500);
|
|
||||||
return nodeMsg
|
|
||||||
} catch (e) {
|
|
||||||
log(e, "克隆转发消息失败,将忽略本条消息", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 返回一个合并转发的消息id
|
|
||||||
private async handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[], group: Group | undefined) {
|
|
||||||
|
|
||||||
const selfPeer = {
|
|
||||||
chatType: ChatType.friend,
|
|
||||||
peerUid: selfInfo.uid
|
|
||||||
}
|
|
||||||
let nodeMsgIds: string[] = []
|
|
||||||
// 先判断一遍是不是id和自定义混用
|
|
||||||
let needClone = messageNodes.filter(node => node.data.id).length && messageNodes.filter(node => !node.data.id).length
|
|
||||||
for (const messageNode of messageNodes) {
|
|
||||||
// 一个node表示一个人的消息
|
|
||||||
let nodeId = messageNode.data.id;
|
|
||||||
// 有nodeId表示一个子转发消息卡片
|
|
||||||
if (nodeId) {
|
|
||||||
let nodeMsg = await dbUtil.getMsgByShortId(parseInt(nodeId));
|
|
||||||
if (!needClone) {
|
|
||||||
nodeMsgIds.push(nodeMsg.msgId)
|
|
||||||
} else {
|
|
||||||
if (nodeMsg.peerUid !== selfInfo.uid) {
|
|
||||||
const cloneMsg = await this.cloneMsg(nodeMsg)
|
|
||||||
if (cloneMsg) {
|
|
||||||
nodeMsgIds.push(cloneMsg.msgId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 自定义的消息
|
|
||||||
// 提取消息段,发给自己生成消息id
|
|
||||||
try {
|
|
||||||
const {
|
|
||||||
sendElements,
|
|
||||||
deleteAfterSentFiles
|
|
||||||
} = await this.createSendElements(this.convertMessage2List(messageNode.data.content), group);
|
|
||||||
log("开始生成转发节点", sendElements);
|
|
||||||
let sendElementsSplit: SendMessageElement[][] = []
|
|
||||||
let splitIndex = 0;
|
|
||||||
for (const ele of sendElements) {
|
|
||||||
if (!sendElementsSplit[splitIndex]) {
|
|
||||||
sendElementsSplit[splitIndex] = []
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ele.elementType === ElementType.FILE || ele.elementType === ElementType.VIDEO) {
|
|
||||||
if (sendElementsSplit[splitIndex].length > 0) {
|
|
||||||
splitIndex++;
|
|
||||||
}
|
|
||||||
sendElementsSplit[splitIndex] = [ele]
|
|
||||||
splitIndex++;
|
|
||||||
} else {
|
|
||||||
sendElementsSplit[splitIndex].push(ele)
|
|
||||||
}
|
|
||||||
log(sendElementsSplit)
|
|
||||||
}
|
|
||||||
// log("分割后的转发节点", sendElementsSplit)
|
|
||||||
for (const eles of sendElementsSplit) {
|
|
||||||
const nodeMsg = await this.send(selfPeer, eles, [], true);
|
|
||||||
nodeMsgIds.push(nodeMsg.msgId)
|
|
||||||
await sleep(500);
|
|
||||||
log("转发节点生成成功", nodeMsg.msgId);
|
|
||||||
}
|
|
||||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
|
||||||
}));
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
log("生成转发消息节点失败", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查srcPeer是否一致,不一致则需要克隆成自己的消息, 让所有srcPeer都变成自己的,使其保持一致才能够转发
|
|
||||||
let nodeMsgArray: Array<RawMessage> = []
|
|
||||||
let srcPeer: Peer = null;
|
|
||||||
let needSendSelf = false;
|
|
||||||
for (const [index, msgId] of nodeMsgIds.entries()) {
|
|
||||||
const nodeMsg = await dbUtil.getMsgByLongId(msgId)
|
|
||||||
if (nodeMsg) {
|
|
||||||
nodeMsgArray.push(nodeMsg)
|
|
||||||
if (!srcPeer) {
|
|
||||||
srcPeer = {chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid}
|
|
||||||
} else if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
|
||||||
needSendSelf = true
|
|
||||||
srcPeer = selfPeer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log("nodeMsgArray", nodeMsgArray);
|
|
||||||
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
|
||||||
if (needSendSelf) {
|
|
||||||
log("需要克隆转发消息");
|
|
||||||
for (const [index, msg] of nodeMsgArray.entries()) {
|
|
||||||
if (msg.peerUid !== selfInfo.uid) {
|
|
||||||
const cloneMsg = await this.cloneMsg(msg)
|
|
||||||
if (cloneMsg) {
|
|
||||||
nodeMsgIds[index] = cloneMsg.msgId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// elements之间用换行符分隔
|
|
||||||
// let _sendForwardElements: SendMessageElement[] = []
|
|
||||||
// for(let i = 0; i < sendForwardElements.length; i++){
|
|
||||||
// _sendForwardElements.push(sendForwardElements[i])
|
|
||||||
// _sendForwardElements.push(SendMsgElementConstructor.text("\n\n"))
|
|
||||||
// }
|
|
||||||
// const nodeMsg = await NTQQApi.sendMsg(selfPeer, _sendForwardElements, true);
|
|
||||||
// nodeIds.push(nodeMsg.msgId)
|
|
||||||
// await sleep(500);
|
|
||||||
// 开发转发
|
|
||||||
try {
|
|
||||||
log("开发转发", nodeMsgIds)
|
|
||||||
return await NTQQMsgApi.multiForwardMsg(srcPeer, destPeer, nodeMsgIds)
|
|
||||||
} catch (e) {
|
|
||||||
log("forward failed", e)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createSendElements(messageData: OB11MessageData[], group: Group | undefined, ignoreTypes: OB11MessageDataType[] = []) {
|
|
||||||
let sendElements: SendMessageElement[] = []
|
let sendElements: SendMessageElement[] = []
|
||||||
let deleteAfterSentFiles: string[] = []
|
let deleteAfterSentFiles: string[] = []
|
||||||
for (let sendMsg of messageData) {
|
for (let sendMsg of messageData) {
|
||||||
@@ -445,10 +192,12 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
case OB11MessageDataType.json: {
|
case OB11MessageDataType.json: {
|
||||||
sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data))
|
sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data))
|
||||||
}break
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -459,7 +208,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async send(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
export async function sendMsg(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
||||||
if (!sendElements.length) {
|
if (!sendElements.length) {
|
||||||
throw ("消息体无法解析")
|
throw ("消息体无法解析")
|
||||||
}
|
}
|
||||||
@@ -471,6 +220,266 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
return returnMsg
|
return returnMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||||
|
actionName = ActionName.SendMsg
|
||||||
|
|
||||||
|
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||||
|
const messages = convertMessage2List(payload.message);
|
||||||
|
const fmNum = this.getSpecialMsgNum(payload, OB11MessageDataType.node)
|
||||||
|
if (fmNum && fmNum != messages.length) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
message: "转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (payload.group_id && !(await getGroup(payload.group_id))) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
message: `群${payload.group_id}不存在`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (payload.user_id && payload.message_type !== "group") {
|
||||||
|
if (!(await getFriend(payload.user_id))) {
|
||||||
|
if (!ALLOW_SEND_TEMP_MSG && !(await dbUtil.getReceivedTempUinMap())[payload.user_id.toString()]) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
message: `不能发送临时消息`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
valid: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _handle(payload: OB11PostSendMsg) {
|
||||||
|
|
||||||
|
const peer: Peer = {
|
||||||
|
chatType: ChatType.friend,
|
||||||
|
peerUid: ""
|
||||||
|
}
|
||||||
|
let isTempMsg = false;
|
||||||
|
let group: Group | undefined = undefined;
|
||||||
|
const genGroupPeer = async () => {
|
||||||
|
group = await getGroup(payload.group_id.toString())
|
||||||
|
peer.chatType = ChatType.group
|
||||||
|
// peer.name = group.name
|
||||||
|
peer.peerUid = group.groupCode
|
||||||
|
}
|
||||||
|
|
||||||
|
const genFriendPeer = () => {
|
||||||
|
const friend = friends.find(f => f.uin == payload.user_id.toString())
|
||||||
|
if (friend) {
|
||||||
|
// peer.name = friend.nickName
|
||||||
|
peer.peerUid = friend.uid
|
||||||
|
} else {
|
||||||
|
peer.chatType = ChatType.temp
|
||||||
|
const tempUserUid = getUidByUin(payload.user_id.toString())
|
||||||
|
if (!tempUserUid) {
|
||||||
|
throw (`找不到私聊对象${payload.user_id}`)
|
||||||
|
}
|
||||||
|
// peer.name = tempUser.nickName
|
||||||
|
isTempMsg = true;
|
||||||
|
peer.peerUid = tempUserUid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (payload?.group_id && payload.message_type === "group") {
|
||||||
|
await genGroupPeer()
|
||||||
|
|
||||||
|
} else if (payload?.user_id) {
|
||||||
|
genFriendPeer()
|
||||||
|
} else if (payload.group_id) {
|
||||||
|
await genGroupPeer()
|
||||||
|
} else {
|
||||||
|
throw ("发送消息参数错误, 请指定group_id或user_id")
|
||||||
|
}
|
||||||
|
const messages = convertMessage2List(payload.message);
|
||||||
|
if (this.getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||||
|
try {
|
||||||
|
const returnMsg = await this.handleForwardNode(peer, messages as OB11MessageNode[], group)
|
||||||
|
return {message_id: returnMsg.msgShortId}
|
||||||
|
} catch (e) {
|
||||||
|
throw ("发送转发消息失败 " + e.toString())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
||||||
|
const music: OB11MessageCustomMusic = messages[0] as OB11MessageCustomMusic
|
||||||
|
if (music) {
|
||||||
|
const {url, audio, title, content, image} = music.data;
|
||||||
|
const selfPeer: Peer = {peerUid: selfInfo.uid, chatType: ChatType.friend}
|
||||||
|
// 搞不定!
|
||||||
|
// const musicMsg = await this.send(selfPeer, [this.genMusicElement(url, audio, title, content, image)], [], false)
|
||||||
|
// 转发
|
||||||
|
// const res = await NTQQApi.forwardMsg(selfPeer, peer, [musicMsg.msgId])
|
||||||
|
// log("转发音乐消息成功", res);
|
||||||
|
// return {message_id: musicMsg.msgShortId}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// log("send msg:", peer, sendElements)
|
||||||
|
const {sendElements, deleteAfterSentFiles} = await createSendElements(messages, group)
|
||||||
|
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles)
|
||||||
|
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||||
|
}));
|
||||||
|
return {message_id: returnMsg.msgShortId}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
|
||||||
|
if (Array.isArray(payload.message)) {
|
||||||
|
return payload.message.filter(msg => msg.type == msgType).length
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private async cloneMsg(msg: RawMessage): Promise<RawMessage> {
|
||||||
|
log("克隆的目标消息", msg)
|
||||||
|
let sendElements: SendMessageElement[] = [];
|
||||||
|
for (const ele of msg.elements) {
|
||||||
|
sendElements.push(ele as SendMessageElement)
|
||||||
|
// Object.keys(ele).forEach((eleKey) => {
|
||||||
|
// if (eleKey.endsWith("Element")) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
if (sendElements.length === 0) {
|
||||||
|
log("需要clone的消息无法解析,将会忽略掉", msg)
|
||||||
|
}
|
||||||
|
log("克隆消息", sendElements)
|
||||||
|
try {
|
||||||
|
const nodeMsg = await NTQQMsgApi.sendMsg({
|
||||||
|
chatType: ChatType.friend,
|
||||||
|
peerUid: selfInfo.uid
|
||||||
|
}, sendElements, true);
|
||||||
|
await sleep(500);
|
||||||
|
return nodeMsg
|
||||||
|
} catch (e) {
|
||||||
|
log(e, "克隆转发消息失败,将忽略本条消息", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回一个合并转发的消息id
|
||||||
|
private async handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[], group: Group | undefined) {
|
||||||
|
|
||||||
|
const selfPeer = {
|
||||||
|
chatType: ChatType.friend,
|
||||||
|
peerUid: selfInfo.uid
|
||||||
|
}
|
||||||
|
let nodeMsgIds: string[] = []
|
||||||
|
// 先判断一遍是不是id和自定义混用
|
||||||
|
let needClone = messageNodes.filter(node => node.data.id).length && messageNodes.filter(node => !node.data.id).length
|
||||||
|
for (const messageNode of messageNodes) {
|
||||||
|
// 一个node表示一个人的消息
|
||||||
|
let nodeId = messageNode.data.id;
|
||||||
|
// 有nodeId表示一个子转发消息卡片
|
||||||
|
if (nodeId) {
|
||||||
|
let nodeMsg = await dbUtil.getMsgByShortId(parseInt(nodeId));
|
||||||
|
if (!needClone) {
|
||||||
|
nodeMsgIds.push(nodeMsg.msgId)
|
||||||
|
} else {
|
||||||
|
if (nodeMsg.peerUid !== selfInfo.uid) {
|
||||||
|
const cloneMsg = await this.cloneMsg(nodeMsg)
|
||||||
|
if (cloneMsg) {
|
||||||
|
nodeMsgIds.push(cloneMsg.msgId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 自定义的消息
|
||||||
|
// 提取消息段,发给自己生成消息id
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
sendElements,
|
||||||
|
deleteAfterSentFiles
|
||||||
|
} = await createSendElements(convertMessage2List(messageNode.data.content), group);
|
||||||
|
log("开始生成转发节点", sendElements);
|
||||||
|
let sendElementsSplit: SendMessageElement[][] = []
|
||||||
|
let splitIndex = 0;
|
||||||
|
for (const ele of sendElements) {
|
||||||
|
if (!sendElementsSplit[splitIndex]) {
|
||||||
|
sendElementsSplit[splitIndex] = []
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ele.elementType === ElementType.FILE || ele.elementType === ElementType.VIDEO) {
|
||||||
|
if (sendElementsSplit[splitIndex].length > 0) {
|
||||||
|
splitIndex++;
|
||||||
|
}
|
||||||
|
sendElementsSplit[splitIndex] = [ele]
|
||||||
|
splitIndex++;
|
||||||
|
} else {
|
||||||
|
sendElementsSplit[splitIndex].push(ele)
|
||||||
|
}
|
||||||
|
log(sendElementsSplit)
|
||||||
|
}
|
||||||
|
// log("分割后的转发节点", sendElementsSplit)
|
||||||
|
for (const eles of sendElementsSplit) {
|
||||||
|
const nodeMsg = await sendMsg(selfPeer, eles, [], true);
|
||||||
|
nodeMsgIds.push(nodeMsg.msgId)
|
||||||
|
await sleep(500);
|
||||||
|
log("转发节点生成成功", nodeMsg.msgId);
|
||||||
|
}
|
||||||
|
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||||
|
}));
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
log("生成转发消息节点失败", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查srcPeer是否一致,不一致则需要克隆成自己的消息, 让所有srcPeer都变成自己的,使其保持一致才能够转发
|
||||||
|
let nodeMsgArray: Array<RawMessage> = []
|
||||||
|
let srcPeer: Peer = null;
|
||||||
|
let needSendSelf = false;
|
||||||
|
for (const [index, msgId] of nodeMsgIds.entries()) {
|
||||||
|
const nodeMsg = await dbUtil.getMsgByLongId(msgId)
|
||||||
|
if (nodeMsg) {
|
||||||
|
nodeMsgArray.push(nodeMsg)
|
||||||
|
if (!srcPeer) {
|
||||||
|
srcPeer = {chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid}
|
||||||
|
} else if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||||
|
needSendSelf = true
|
||||||
|
srcPeer = selfPeer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log("nodeMsgArray", nodeMsgArray);
|
||||||
|
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
||||||
|
if (needSendSelf) {
|
||||||
|
log("需要克隆转发消息");
|
||||||
|
for (const [index, msg] of nodeMsgArray.entries()) {
|
||||||
|
if (msg.peerUid !== selfInfo.uid) {
|
||||||
|
const cloneMsg = await this.cloneMsg(msg)
|
||||||
|
if (cloneMsg) {
|
||||||
|
nodeMsgIds[index] = cloneMsg.msgId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// elements之间用换行符分隔
|
||||||
|
// let _sendForwardElements: SendMessageElement[] = []
|
||||||
|
// for(let i = 0; i < sendForwardElements.length; i++){
|
||||||
|
// _sendForwardElements.push(sendForwardElements[i])
|
||||||
|
// _sendForwardElements.push(SendMsgElementConstructor.text("\n\n"))
|
||||||
|
// }
|
||||||
|
// const nodeMsg = await NTQQApi.sendMsg(selfPeer, _sendForwardElements, true);
|
||||||
|
// nodeIds.push(nodeMsg.msgId)
|
||||||
|
// await sleep(500);
|
||||||
|
// 开发转发
|
||||||
|
try {
|
||||||
|
log("开发转发", nodeMsgIds)
|
||||||
|
return await NTQQMsgApi.multiForwardMsg(srcPeer, destPeer, nodeMsgIds)
|
||||||
|
} catch (e) {
|
||||||
|
log("forward failed", e)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private genMusicElement(url: string, audio: string, title: string, content: string, image: string): SendArkElement {
|
private genMusicElement(url: string, audio: string, title: string, content: string, image: string): SendArkElement {
|
||||||
const musicJson = {
|
const musicJson = {
|
||||||
app: 'com.tencent.structmsg',
|
app: 'com.tencent.structmsg',
|
@@ -1,6 +1,6 @@
|
|||||||
import SendMsg from "./SendMsg";
|
import SendMsg from "./SendMsg";
|
||||||
import {ActionName, BaseCheckResult} from "./types";
|
import {ActionName, BaseCheckResult} from "../types";
|
||||||
import {OB11PostSendMsg} from "../types";
|
import {OB11PostSendMsg} from "../../types";
|
||||||
|
|
||||||
class SendPrivateMsg extends SendMsg {
|
class SendPrivateMsg extends SendMsg {
|
||||||
actionName = ActionName.SendPrivateMsg
|
actionName = ActionName.SendPrivateMsg
|
@@ -1,4 +1,4 @@
|
|||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import CanSendRecord from "./CanSendRecord";
|
import CanSendRecord from "./CanSendRecord";
|
||||||
|
|
||||||
interface ReturnType {
|
interface ReturnType {
|
@@ -1,5 +1,5 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
interface ReturnType {
|
interface ReturnType {
|
||||||
yes: boolean
|
yes: boolean
|
@@ -1,14 +1,14 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import Path from "path";
|
import Path from "path";
|
||||||
import {
|
import {
|
||||||
ChatType,
|
ChatType,
|
||||||
ChatCacheListItemBasic,
|
ChatCacheListItemBasic,
|
||||||
CacheFileType
|
CacheFileType
|
||||||
} from '../../ntqqapi/types';
|
} from '../../../ntqqapi/types';
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../../common/db";
|
||||||
import {NTQQFileApi, NTQQFileCacheApi} from "../../ntqqapi/api/file";
|
import {NTQQFileApi, NTQQFileCacheApi} from "../../../ntqqapi/api/file";
|
||||||
|
|
||||||
export default class CleanCache extends BaseAction<void, void> {
|
export default class CleanCache extends BaseAction<void, void> {
|
||||||
actionName = ActionName.CleanCache
|
actionName = ActionName.CleanCache
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11User} from '../types';
|
import {OB11User} from '../../types';
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import {selfInfo} from "../../common/data";
|
import {selfInfo} from "../../../common/data";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
|
|
||||||
class GetLoginInfo extends BaseAction<null, OB11User> {
|
class GetLoginInfo extends BaseAction<null, OB11User> {
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {OB11Status} from "../types";
|
import {OB11Status} from "../../types";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {selfInfo} from "../../common/data";
|
import {selfInfo} from "../../../common/data";
|
||||||
|
|
||||||
|
|
||||||
export default class GetStatus extends BaseAction<any, OB11Status> {
|
export default class GetStatus extends BaseAction<any, OB11Status> {
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {OB11Version} from "../types";
|
import {OB11Version} from "../../types";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {version} from "../../version";
|
import {version} from "../../../version";
|
||||||
|
|
||||||
export default class GetVersionInfo extends BaseAction<any, OB11Version> {
|
export default class GetVersionInfo extends BaseAction<any, OB11Version> {
|
||||||
actionName = ActionName.GetVersionInfo
|
actionName = ActionName.GetVersionInfo
|
@@ -1,8 +1,8 @@
|
|||||||
import {OB11User} from '../types';
|
import {OB11User} from '../../types';
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../../constructor";
|
||||||
import {friends} from "../../common/data";
|
import {friends} from "../../../common/data";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
|
|
||||||
class GetFriendList extends BaseAction<null, OB11User[]> {
|
class GetFriendList extends BaseAction<null, OB11User[]> {
|
@@ -1,8 +1,8 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {getFriend, getUidByUin, uidMaps} from "../../common/data";
|
import {getFriend, getUidByUin, uidMaps} from "../../../common/data";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQFriendApi} from "../../ntqqapi/api/friend";
|
import {NTQQFriendApi} from "../../../ntqqapi/api/friend";
|
||||||
import {log} from "../../common/utils/log";
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
user_id: number,
|
user_id: number,
|
@@ -1,6 +1,6 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQFriendApi} from "../../ntqqapi/api/friend";
|
import {NTQQFriendApi} from "../../../ntqqapi/api/friend";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
flag: string,
|
flag: string,
|
||||||
@@ -12,7 +12,8 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName.SetFriendAddRequest;
|
actionName = ActionName.SetFriendAddRequest;
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
await NTQQFriendApi.handleFriendRequest(parseInt(payload.flag), payload.approve)
|
const approve = payload.approve.toString() === "true";
|
||||||
|
await NTQQFriendApi.handleFriendRequest(parseInt(payload.flag), approve)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -19,7 +19,7 @@ import {
|
|||||||
SelfInfo,
|
SelfInfo,
|
||||||
Sex,
|
Sex,
|
||||||
TipGroupElementType,
|
TipGroupElementType,
|
||||||
User
|
User, VideoElement
|
||||||
} from '../ntqqapi/types';
|
} from '../ntqqapi/types';
|
||||||
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
||||||
import {EventType} from "./event/OB11BaseEvent";
|
import {EventType} from "./event/OB11BaseEvent";
|
||||||
@@ -35,6 +35,8 @@ import {calcQQLevel} from "../common/utils/qqlevel";
|
|||||||
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 {getConfigUtil} from "../common/config";
|
import {getConfigUtil} from "../common/config";
|
||||||
|
import {OB11GroupTitleEvent} from "./event/notice/OB11GroupTitleEvent";
|
||||||
|
import {OB11GroupCardEvent} from "./event/notice/OB11GroupCardEvent";
|
||||||
|
|
||||||
|
|
||||||
export class OB11Constructor {
|
export class OB11Constructor {
|
||||||
@@ -155,37 +157,25 @@ export class OB11Constructor {
|
|||||||
}).then()
|
}).then()
|
||||||
// 不在自动下载图片
|
// 不在自动下载图片
|
||||||
|
|
||||||
} else if (element.videoElement) {
|
} else if (element.videoElement || element.fileElement) {
|
||||||
message_data["type"] = OB11MessageDataType.video;
|
const videoOrFileElement = element.videoElement || element.fileElement
|
||||||
message_data["data"]["file"] = element.videoElement.fileName
|
const ob11MessageDataType = element.videoElement ? OB11MessageDataType.video : OB11MessageDataType.file
|
||||||
message_data["data"]["path"] = element.videoElement.filePath
|
message_data["type"] = ob11MessageDataType;
|
||||||
// message_data["data"]["file_id"] = element.videoElement.fileUuid
|
message_data["data"]["file"] = videoOrFileElement.fileName
|
||||||
message_data["data"]["file_size"] = element.videoElement.fileSize
|
message_data["data"]["path"] = videoOrFileElement.filePath
|
||||||
dbUtil.addFileCache(element.videoElement.fileName, {
|
message_data["data"]["file_id"] = videoOrFileElement.fileUuid
|
||||||
fileName: element.videoElement.fileName,
|
message_data["data"]["file_size"] = videoOrFileElement.fileSize
|
||||||
filePath: element.videoElement.filePath,
|
dbUtil.addFileCache(videoOrFileElement.fileUuid, {
|
||||||
fileSize: element.videoElement.fileSize,
|
|
||||||
downloadFunc: async () => {
|
|
||||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
|
||||||
element.elementId, element.videoElement.thumbPath.get(0), element.videoElement.filePath)
|
|
||||||
}
|
|
||||||
}).then()
|
|
||||||
// 怎么拿到url呢
|
|
||||||
} else if (element.fileElement) {
|
|
||||||
message_data["type"] = OB11MessageDataType.file;
|
|
||||||
message_data["data"]["file"] = element.fileElement.fileName
|
|
||||||
// message_data["data"]["path"] = element.fileElement.filePath
|
|
||||||
message_data["data"]["file_id"] = element.fileElement.fileUuid
|
|
||||||
message_data["data"]["file_size"] = element.fileElement.fileSize
|
|
||||||
dbUtil.addFileCache(element.fileElement.fileUuid, {
|
|
||||||
msgId: msg.msgId,
|
msgId: msg.msgId,
|
||||||
fileName: element.fileElement.fileName,
|
fileName: videoOrFileElement.fileName,
|
||||||
fileUuid: element.fileElement.fileUuid,
|
filePath: videoOrFileElement.filePath,
|
||||||
filePath: element.fileElement.filePath,
|
fileSize: videoOrFileElement.fileSize,
|
||||||
fileSize: element.fileElement.fileSize,
|
|
||||||
downloadFunc: async () => {
|
downloadFunc: async () => {
|
||||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQFileApi.downloadMedia(
|
||||||
element.elementId, null, element.fileElement.filePath)
|
msg.msgId, msg.chatType, msg.peerUid,
|
||||||
|
element.elementId,
|
||||||
|
ob11MessageDataType == OB11MessageDataType.video ? (videoOrFileElement as VideoElement).thumbPath.get(0) : null,
|
||||||
|
videoOrFileElement.filePath)
|
||||||
}
|
}
|
||||||
}).then()
|
}).then()
|
||||||
// 怎么拿到url呢
|
// 怎么拿到url呢
|
||||||
@@ -231,6 +221,13 @@ export class OB11Constructor {
|
|||||||
if (msg.chatType !== ChatType.group) {
|
if (msg.chatType !== ChatType.group) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (msg.senderUin){
|
||||||
|
let member = await getGroupMember(msg.peerUid, msg.senderUin);
|
||||||
|
if (member && member.cardName !== msg.sendMemberName) {
|
||||||
|
member.cardName = msg.sendMemberName;
|
||||||
|
return new OB11GroupCardEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), msg.sendMemberName, member.cardName)
|
||||||
|
}
|
||||||
|
}
|
||||||
// log("group msg", msg);
|
// log("group msg", msg);
|
||||||
for (let element of msg.elements) {
|
for (let element of msg.elements) {
|
||||||
const grayTipElement = element.grayTipElement
|
const grayTipElement = element.grayTipElement
|
||||||
@@ -300,6 +297,36 @@ export class OB11Constructor {
|
|||||||
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (grayTipElement.subElementType == GrayTipElementSubType.MEMBER_NEW_TITLE) {
|
||||||
|
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr)
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
align: 'center',
|
||||||
|
items: [
|
||||||
|
{ txt: '恭喜', type: 'nor' },
|
||||||
|
{
|
||||||
|
col: '3',
|
||||||
|
jp: '5',
|
||||||
|
param: ["QQ号"],
|
||||||
|
txt: '林雨辰',
|
||||||
|
type: 'url'
|
||||||
|
},
|
||||||
|
{ txt: '获得群主授予的', type: 'nor' },
|
||||||
|
{
|
||||||
|
col: '3',
|
||||||
|
jp: '',
|
||||||
|
txt: '好好好',
|
||||||
|
type: 'url'
|
||||||
|
},
|
||||||
|
{ txt: '头衔', type: 'nor' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
* */
|
||||||
|
const memberUin = json.items[1].param[0]
|
||||||
|
const title = json.items[3].txt
|
||||||
|
log("收到群成员新头衔消息", json)
|
||||||
|
return new OB11GroupTitleEvent(parseInt(msg.peerUid), parseInt(memberUin), title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
src/onebot11/event/notice/OB11GroupCardEvent.ts
Normal file
16
src/onebot11/event/notice/OB11GroupCardEvent.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||||
|
|
||||||
|
export class OB11GroupCardEvent extends OB11GroupNoticeEvent {
|
||||||
|
notice_type = "group_card";
|
||||||
|
card_new: string;
|
||||||
|
card_old: string;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(groupId: number, userId: number, cardNew: string, cardOld: string) {
|
||||||
|
super();
|
||||||
|
this.group_id = groupId;
|
||||||
|
this.user_id = userId;
|
||||||
|
this.card_new = cardNew;
|
||||||
|
this.card_old = cardOld;
|
||||||
|
}
|
||||||
|
}
|
15
src/onebot11/event/notice/OB11GroupTitleEvent.ts
Normal file
15
src/onebot11/event/notice/OB11GroupTitleEvent.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||||
|
|
||||||
|
export class OB11GroupTitleEvent extends OB11GroupNoticeEvent {
|
||||||
|
notice_type = "notify";
|
||||||
|
sub_type = "title";
|
||||||
|
title: string
|
||||||
|
|
||||||
|
|
||||||
|
constructor(groupId: number, userId: number, title: string) {
|
||||||
|
super();
|
||||||
|
this.group_id = groupId;
|
||||||
|
this.user_id = userId;
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
}
|
@@ -7,7 +7,6 @@ class OB11PokeEvent extends OB11BaseNoticeEvent{
|
|||||||
sub_type = "poke"
|
sub_type = "poke"
|
||||||
target_id = parseInt(selfInfo.uin)
|
target_id = parseInt(selfInfo.uin)
|
||||||
user_id: number
|
user_id: number
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OB11FriendPokeEvent extends OB11PokeEvent{
|
export class OB11FriendPokeEvent extends OB11PokeEvent{
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import {Response} from "express";
|
import {Response} from "express";
|
||||||
import {OB11Response} from "../action/utils";
|
import {OB11Response} from "../action/OB11Response";
|
||||||
import {HttpServerBase} from "../../common/server/http";
|
import {HttpServerBase} from "../../common/server/http";
|
||||||
import {actionHandlers} from "../action";
|
import {actionHandlers} from "../action";
|
||||||
import {getConfigUtil} from "../../common/config";
|
import {getConfigUtil} from "../../common/config";
|
||||||
|
@@ -1,14 +1,53 @@
|
|||||||
import {OB11Message} from "../types";
|
import {OB11Message, OB11MessageAt, OB11MessageData} from "../types";
|
||||||
import {selfInfo} from "../../common/data";
|
import {getGroup, selfInfo} from "../../common/data";
|
||||||
import {OB11BaseMetaEvent} from "../event/meta/OB11BaseMetaEvent";
|
import {OB11BaseMetaEvent} from "../event/meta/OB11BaseMetaEvent";
|
||||||
import {OB11BaseNoticeEvent} from "../event/notice/OB11BaseNoticeEvent";
|
import {OB11BaseNoticeEvent} from "../event/notice/OB11BaseNoticeEvent";
|
||||||
import {WebSocket as WebSocketClass} from "ws";
|
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';
|
||||||
|
import {NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, Peer} from "../../ntqqapi/api";
|
||||||
|
import {ChatType, Group, GroupRequestOperateTypes} from "../../ntqqapi/types";
|
||||||
|
import {convertMessage2List, createSendElements, sendMsg} from "../action/msg/SendMsg";
|
||||||
|
import {dbUtil} from "../../common/db";
|
||||||
|
import {OB11FriendRequestEvent} from "../event/request/OB11FriendRequest";
|
||||||
|
import {OB11GroupRequestEvent} from "../event/request/OB11GroupRequest";
|
||||||
|
import {isNull} from "../../common/utils";
|
||||||
|
|
||||||
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
||||||
|
|
||||||
|
interface QuickActionPrivateMessage {
|
||||||
|
reply?: string;
|
||||||
|
auto_escape?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QuickActionGroupMessage extends QuickActionPrivateMessage {
|
||||||
|
// 回复群消息
|
||||||
|
at_sender?: boolean
|
||||||
|
delete?: boolean
|
||||||
|
kick?: boolean
|
||||||
|
ban?: boolean
|
||||||
|
ban_duration?: number
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QuickActionFriendRequest {
|
||||||
|
approve?: boolean
|
||||||
|
remark?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QuickActionGroupRequest {
|
||||||
|
approve?: boolean
|
||||||
|
reason?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type QuickAction =
|
||||||
|
QuickActionPrivateMessage
|
||||||
|
& QuickActionGroupMessage
|
||||||
|
& QuickActionFriendRequest
|
||||||
|
& QuickActionGroupRequest
|
||||||
|
|
||||||
const eventWSList: WebSocketClass[] = [];
|
const eventWSList: WebSocketClass[] = [];
|
||||||
|
|
||||||
export function registerWsEventSender(ws: WebSocketClass) {
|
export function registerWsEventSender(ws: WebSocketClass) {
|
||||||
@@ -39,18 +78,95 @@ 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
|
}).then(async (res) => {
|
||||||
},
|
log(`新消息事件HTTP上报成功: ${host} `, msgStr);
|
||||||
body: JSON.stringify(msg)
|
// todo: 处理不够优雅,应该使用高级泛型进行QuickAction类型识别
|
||||||
}).then((res: any) => {
|
let resJson: QuickAction;
|
||||||
log(`新消息事件HTTP上报成功: ${host} ` + JSON.stringify(msg));
|
try {
|
||||||
|
resJson = await res.json();
|
||||||
|
log(`新消息事件HTTP上报返回快速操作: `, JSON.stringify(resJson))
|
||||||
|
} catch (e) {
|
||||||
|
log(`新消息事件HTTP上报没有返回快速操作,不需要处理`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (msg.post_type === "message") {
|
||||||
|
msg = msg as OB11Message;
|
||||||
|
const rawMessage = await dbUtil.getMsgByShortId(msg.message_id)
|
||||||
|
resJson = resJson as QuickActionPrivateMessage | QuickActionGroupMessage
|
||||||
|
const reply = resJson.reply
|
||||||
|
let peer: Peer = {
|
||||||
|
chatType: ChatType.friend,
|
||||||
|
peerUid: msg.user_id.toString()
|
||||||
|
}
|
||||||
|
if (msg.message_type == "private") {
|
||||||
|
if (msg.sub_type === "group") {
|
||||||
|
peer.chatType = ChatType.temp
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
peer.chatType = ChatType.group
|
||||||
|
peer.peerUid = msg.group_id.toString()
|
||||||
|
}
|
||||||
|
if (reply) {
|
||||||
|
let group: Group = null
|
||||||
|
let replyMessage: OB11MessageData[] = []
|
||||||
|
|
||||||
|
if (msg.message_type == "group") {
|
||||||
|
group = await getGroup(msg.group_id.toString())
|
||||||
|
if ((resJson as QuickActionGroupMessage).at_sender) {
|
||||||
|
replyMessage.push({
|
||||||
|
type: "at",
|
||||||
|
data: {
|
||||||
|
qq: msg.user_id.toString()
|
||||||
|
}
|
||||||
|
} as OB11MessageAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
replyMessage = replyMessage.concat(convertMessage2List(reply, resJson.auto_escape))
|
||||||
|
const {sendElements, deleteAfterSentFiles} = await createSendElements(replyMessage, group)
|
||||||
|
sendMsg(peer, sendElements, deleteAfterSentFiles, false).then()
|
||||||
|
} else if (resJson.delete) {
|
||||||
|
NTQQMsgApi.recallMsg(peer, [rawMessage.msgId]).then()
|
||||||
|
} else if (resJson.kick) {
|
||||||
|
NTQQGroupApi.kickMember(peer.peerUid, [rawMessage.senderUid]).then()
|
||||||
|
} else if (resJson.ban) {
|
||||||
|
NTQQGroupApi.banMember(peer.peerUid, [{
|
||||||
|
uid: rawMessage.senderUid,
|
||||||
|
timeStamp: resJson.ban_duration || 60 * 30
|
||||||
|
}],).then()
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (msg.post_type === "request") {
|
||||||
|
if ((msg as OB11FriendRequestEvent).request_type === "friend") {
|
||||||
|
resJson = resJson as QuickActionFriendRequest
|
||||||
|
if (!isNull(resJson.approve)) {
|
||||||
|
// todo: set remark
|
||||||
|
NTQQFriendApi.handleFriendRequest(parseInt((msg as OB11FriendRequestEvent).flag), resJson.approve).then()
|
||||||
|
}
|
||||||
|
} else if ((msg as OB11GroupRequestEvent).request_type === "group") {
|
||||||
|
resJson = resJson as QuickActionGroupRequest
|
||||||
|
if (!isNull(resJson.approve)) {
|
||||||
|
NTQQGroupApi.handleGroupRequest((msg as OB11FriendRequestEvent).flag, resJson.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject, resJson.reason).then()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}, (err: any) => {
|
}, (err: any) => {
|
||||||
log(`新消息事件HTTP上报失败: ${host} ` + err + JSON.stringify(msg));
|
log(`新消息事件HTTP上报失败: ${host} `, err, msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import {selfInfo} from "../../../common/data";
|
import {selfInfo} from "../../../common/data";
|
||||||
import {LifeCycleSubType, OB11LifeCycleEvent} from "../../event/meta/OB11LifeCycleEvent";
|
import {LifeCycleSubType, OB11LifeCycleEvent} from "../../event/meta/OB11LifeCycleEvent";
|
||||||
import {ActionName} from "../../action/types";
|
import {ActionName} from "../../action/types";
|
||||||
import {OB11Response} from "../../action/utils";
|
import {OB11Response} from "../../action/OB11Response";
|
||||||
import BaseAction from "../../action/BaseAction";
|
import BaseAction from "../../action/BaseAction";
|
||||||
import {actionMap} from "../../action";
|
import {actionMap} from "../../action";
|
||||||
import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import {WebSocket} from "ws";
|
import {WebSocket} from "ws";
|
||||||
import {actionMap} from "../../action";
|
import {actionMap} from "../../action";
|
||||||
import {OB11Response} from "../../action/utils";
|
import {OB11Response} from "../../action/OB11Response";
|
||||||
import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
||||||
import {ActionName} from "../../action/types";
|
import {ActionName} from "../../action/types";
|
||||||
import BaseAction from "../../action/BaseAction";
|
import BaseAction from "../../action/BaseAction";
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import {WebSocket as WebSocketClass} from "ws";
|
import {WebSocket as WebSocketClass} from "ws";
|
||||||
import {OB11Response} from "../../action/utils";
|
import {OB11Response} from "../../action/OB11Response";
|
||||||
import {PostEventType} from "../postOB11Event";
|
import {PostEventType} from "../postOB11Event";
|
||||||
import {log} from "../../../common/utils/log";
|
import {log} from "../../../common/utils/log";
|
||||||
import {isNull} from "../../../common/utils/helper";
|
import {isNull} from "../../../common/utils/helper";
|
||||||
|
@@ -108,6 +108,7 @@ export enum OB11MessageDataType {
|
|||||||
reply = "reply",
|
reply = "reply",
|
||||||
json = "json",
|
json = "json",
|
||||||
face = "face",
|
face = "face",
|
||||||
|
mface = "face", // 商城表情
|
||||||
node = "node", // 合并转发消息
|
node = "node", // 合并转发消息
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,8 +24,8 @@ const llonebot = {
|
|||||||
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);
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/// <reference path="../global.d.ts" />
|
/// <reference path="../global.d.ts" />
|
||||||
import { CheckVersion } from '../common/types';
|
import { CheckVersion } from '../common/types';
|
||||||
import {SettingButton, SettingItem, SettingList, SettingSwitch, SettingSelect} from './components';
|
import {SettingButton, SettingItem, SettingList, SettingSwitch, SettingSelect} from './components';
|
||||||
|
// @ts-ignore
|
||||||
import StyleRaw from './style.css?raw';
|
import StyleRaw from './style.css?raw';
|
||||||
|
|
||||||
// 打开设置界面时触发
|
// 打开设置界面时触发
|
||||||
@@ -21,7 +22,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -30,18 +31,14 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
const doc = parser.parseFromString([
|
const doc = parser.parseFromString([
|
||||||
'<div>',
|
'<div>',
|
||||||
`<style>${StyleRaw}</style>`,
|
`<style>${StyleRaw}</style>`,
|
||||||
`<setting-section>
|
`<setting-section id="llonebot-error">
|
||||||
<setting-panel>
|
<setting-panel><pre><code></code></pre></setting-panel>
|
||||||
<setting-list data-direction="column" class="new">
|
</setting-section>`,
|
||||||
<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([
|
SettingList([
|
||||||
'<div id="llonebot-error" class="llonebot-error"></div>',
|
SettingItem(
|
||||||
|
'<span id="llonebot-update-title">正在检查 LLOneBot 更新</span>', null,
|
||||||
|
SettingButton('请稍候', 'llonebot-update-button', 'secondary'),
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem('启用 HTTP 服务', null,
|
SettingItem('启用 HTTP 服务', null,
|
||||||
@@ -55,6 +52,14 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
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>
|
||||||
@@ -90,7 +95,7 @@ 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'},
|
||||||
@@ -114,7 +119,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'使用 Base64 编码获取文件',
|
'使用 Base64 编码获取文件',
|
||||||
'开启后,调用 /get_image、/get_record 时,获取不到 url 时添加一个 Base64 字段',
|
'调用 /get_image、/get_record、/get_file 时,没有 url 时添加 Base64 字段',
|
||||||
SettingSwitch('enableLocalFile2Url', config.enableLocalFile2Url),
|
SettingSwitch('enableLocalFile2Url', config.enableLocalFile2Url),
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
@@ -174,18 +179,20 @@ 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 () => {
|
const showError = async () => {
|
||||||
setTimeout(async () => {
|
await (new Promise((res) => setTimeout(() => res(true), 1000)));
|
||||||
let errMessage = await window.llonebot.getError();
|
|
||||||
console.log(errMessage)
|
const errDom = doc.querySelector('#llonebot-error');
|
||||||
errMessage = errMessage.replace(/\n/g, '<br>')
|
const errCodeDom = errDom.querySelector('code');
|
||||||
errorEle.innerHTML = errMessage;
|
const errMsg = await window.llonebot.getError();
|
||||||
errorEle.style.display = errMessage ? 'flex' : 'none';
|
|
||||||
}, 1000)
|
if (!errMsg) return;
|
||||||
|
|
||||||
|
errDom.classList.add('show');
|
||||||
|
errCodeDom.innerHTML = errMsg;
|
||||||
}
|
}
|
||||||
showError().then()
|
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')
|
||||||
@@ -316,7 +323,7 @@ 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();
|
// window.location.reload();
|
||||||
showError().then()
|
showError().then()
|
||||||
alert('保存成功');
|
alert('保存成功');
|
||||||
@@ -327,36 +334,47 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
});
|
});
|
||||||
// 更新逻辑
|
// 更新逻辑
|
||||||
async function checkVersionFunc(ResultVersion: CheckVersion) {
|
async function checkVersionFunc(ResultVersion: CheckVersion) {
|
||||||
console.log(ResultVersion);
|
const titleDom = view.querySelector<HTMLSpanElement>("#llonebot-update-title")!;
|
||||||
|
const buttonDom = view.querySelector<HTMLButtonElement>("#llonebot-update-button")!;
|
||||||
|
|
||||||
if (ResultVersion.version === "") {
|
if (ResultVersion.version === "") {
|
||||||
view.querySelector(".llonebot-update-title").innerHTML = "检查更新失败";
|
titleDom.innerHTML = "检查更新失败";
|
||||||
view.querySelector(".llonebot-update-button").innerHTML = "点击重试";
|
buttonDom.innerHTML = "点击重试";
|
||||||
view.querySelector(".llonebot-update-button").addEventListener("click", async () => {
|
|
||||||
|
buttonDom.addEventListener("click", async () => {
|
||||||
window.llonebot.checkVersion().then(checkVersionFunc);
|
window.llonebot.checkVersion().then(checkVersionFunc);
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!ResultVersion.result) {
|
if (!ResultVersion.result) {
|
||||||
view.querySelector(".llonebot-update-title").innerHTML = "当前已是最新版本 V" + ResultVersion.version;
|
titleDom.innerHTML = "当前已是最新版本 v" + ResultVersion.version;
|
||||||
view.querySelector(".llonebot-update-button").innerHTML = "无需更新";
|
buttonDom.innerHTML = "无需更新";
|
||||||
} else {
|
} else {
|
||||||
view.querySelector(".llonebot-update-title").innerHTML = "已检测到最新版本 V" + ResultVersion.version;
|
titleDom.innerHTML = "已检测到最新版本 v" + ResultVersion.version;
|
||||||
view.querySelector(".llonebot-update-button").innerHTML = "点击更新";
|
buttonDom.innerHTML = "点击更新";
|
||||||
|
buttonDom.dataset.type = 'primary';
|
||||||
|
|
||||||
const update = async () => {
|
const update = async () => {
|
||||||
view.querySelector(".llonebot-update-button").innerHTML = "正在更新中...";
|
buttonDom.innerHTML = "正在更新中...";
|
||||||
const result = await window.llonebot.updateLLOneBot();
|
const result = await window.llonebot.updateLLOneBot();
|
||||||
if (result) {
|
if (result) {
|
||||||
view.querySelector(".llonebot-update-button").innerHTML = "更新完成请重启";
|
buttonDom.innerHTML = "更新完成,请重启";
|
||||||
view.querySelector(".llonebot-update-button").removeEventListener("click", update);
|
|
||||||
} else {
|
} else {
|
||||||
view.querySelector(".llonebot-update-button").innerHTML = "更新失败前往仓库下载";
|
buttonDom.innerHTML = "更新失败,前往仓库下载";
|
||||||
view.querySelector(".llonebot-update-button").removeEventListener("click", update);
|
}
|
||||||
|
|
||||||
|
buttonDom.removeEventListener("click", update);
|
||||||
|
}
|
||||||
|
buttonDom.addEventListener("click", update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view.querySelector(".llonebot-update-button").addEventListener("click", update);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
window.llonebot.checkVersion().then(checkVersionFunc);
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -157,9 +157,24 @@ ob-setting-select::part(option-list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#llonebot-error {
|
#llonebot-error {
|
||||||
padding-top: 10px;
|
display: none;
|
||||||
padding-bottom: 10px;
|
}
|
||||||
overflow: visible;
|
|
||||||
display: flex;
|
#llonebot-error setting-panel {
|
||||||
align-items: center;
|
background: rgba(255, 0, 0, 0.5);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
#llonebot-error setting-panel pre {
|
||||||
|
margin: 0;
|
||||||
|
padding: 16px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
#llonebot-error setting-panel pre code {
|
||||||
|
font-family: 'FiraCode Nerd Font', 'Fira Code', 'Cascadia Code', Consolas, 'Courier New', monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
#llonebot-error.show {
|
||||||
|
display: block;
|
||||||
}
|
}
|
@@ -1 +1 @@
|
|||||||
export const version = "3.17.0"
|
export const version = "3.19.0"
|
29
test/quick_action/server.py
Normal file
29
test/quick_action/server.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import uvicorn
|
||||||
|
from fastapi import FastAPI, Request
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
@app.post("/")
|
||||||
|
async def root(request: Request):
|
||||||
|
data = await request.json()
|
||||||
|
print(data)
|
||||||
|
if (data["post_type"] == "message"):
|
||||||
|
text = list(filter(lambda x: x["type"] == "text", data["message"]))[0]["data"]["text"]
|
||||||
|
if text == "禁言":
|
||||||
|
return {"ban": True, "ban_duration": 10}
|
||||||
|
elif text == "踢我":
|
||||||
|
return {"kick": True}
|
||||||
|
elif text == "撤回":
|
||||||
|
return {"delete": True}
|
||||||
|
# print(data["message"])
|
||||||
|
return {"reply": "[CQ:at,qq=]Hello World", "auto_escape": True}
|
||||||
|
elif data["post_type"] == "request":
|
||||||
|
if data["request_type"] == "group":
|
||||||
|
return {"approve": False, "reason": "不让你进群"}
|
||||||
|
else:
|
||||||
|
# 加好友
|
||||||
|
return {"approve": True}
|
||||||
|
return {}
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
uvicorn.run(app, host="", port=8000)
|
Reference in New Issue
Block a user