mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
54 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
de8c2e1168 | ||
![]() |
2a1fc07b94 | ||
![]() |
c1b6daaf32 | ||
![]() |
02c973fe5e | ||
![]() |
d6b44053de | ||
![]() |
1d69764952 | ||
![]() |
d9377e4684 | ||
![]() |
f30dd81455 | ||
![]() |
0116f8d384 | ||
![]() |
88d68f4360 | ||
![]() |
ea0f5a9f80 | ||
![]() |
4591c1b659 | ||
![]() |
97a424f62e | ||
![]() |
410ef5a050 | ||
![]() |
128091dff9 | ||
![]() |
c7b6fd89fd | ||
![]() |
b55f35549d | ||
![]() |
ca0a6cfb22 | ||
![]() |
3303b30c4c | ||
![]() |
429d8deb5c | ||
![]() |
48f12fc30b | ||
![]() |
41f0e8f574 | ||
![]() |
cd50df3a56 | ||
![]() |
4461c7ed47 | ||
![]() |
e5f4992eb3 | ||
![]() |
468f1710b9 | ||
![]() |
626d445dc3 | ||
![]() |
b413a224be | ||
![]() |
6542f2e63b | ||
![]() |
94c928905e | ||
![]() |
c14f8b21c2 | ||
![]() |
6d5ccc6664 | ||
![]() |
79090d764f | ||
![]() |
6ab0cd7f4b | ||
![]() |
bb3bce203d | ||
![]() |
36f7f1b026 | ||
![]() |
5a0dbdb5ce | ||
![]() |
48d62be2d6 | ||
![]() |
b314e2f3a0 | ||
![]() |
63b9204a4b | ||
![]() |
bf701c2110 | ||
![]() |
95b4b11f02 | ||
![]() |
1735babb7d | ||
![]() |
89c3f07cba | ||
![]() |
5cf45a452b | ||
![]() |
23d5fa7218 | ||
![]() |
983d2462d4 | ||
![]() |
3c68bc77ce | ||
![]() |
501211fb57 | ||
![]() |
0cd41a8a52 | ||
![]() |
d339a778df | ||
![]() |
dc843f77a3 | ||
![]() |
b103f2015c | ||
![]() |
baf35d5496 |
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,
|
||||
"type": "extension",
|
||||
"name": "LLOneBot v3.18.0",
|
||||
"name": "LLOneBot v3.20.3",
|
||||
"slug": "LLOneBot",
|
||||
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
||||
"version": "3.18.0",
|
||||
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
|
||||
"version": "3.20.3",
|
||||
"icon": "./icon.jpg",
|
||||
"authors": [
|
||||
{
|
||||
|
8
package-lock.json
generated
8
package-lock.json
generated
@@ -14,7 +14,7 @@
|
||||
"file-type": "^19.0.0",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"level": "^8.0.1",
|
||||
"silk-wasm": "^3.2.4",
|
||||
"silk-wasm": "^3.3.4",
|
||||
"utf-8-validate": "^6.0.3",
|
||||
"uuid": "^9.0.1",
|
||||
"ws": "^8.16.0"
|
||||
@@ -5895,9 +5895,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/silk-wasm": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.2.4.tgz",
|
||||
"integrity": "sha512-oBkXmdIRl7cyzpoXEeEVN7v1M2yCnH1/bN8oANoYTvCqbYa5lM/CGJP47DYbpUFVO9PUpm58KP/HZaVzt4J6jw=="
|
||||
"version": "3.3.4",
|
||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.3.4.tgz",
|
||||
"integrity": "sha512-cvjp9Zw50uPB46EfifHlO8gIh6buZOUKQaL+9BbPoLgH4bAp8wEEzVmPI34gIiltOUyeuEknm4DDGnE3kEEQ/A=="
|
||||
},
|
||||
"node_modules/slash": {
|
||||
"version": "4.0.0",
|
||||
|
@@ -19,7 +19,7 @@
|
||||
"file-type": "^19.0.0",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"level": "^8.0.1",
|
||||
"silk-wasm": "^3.2.4",
|
||||
"silk-wasm": "^3.3.4",
|
||||
"utf-8-validate": "^6.0.3",
|
||||
"uuid": "^9.0.1",
|
||||
"ws": "^8.16.0"
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import fs from "fs";
|
||||
import fsPromise from "fs/promises";
|
||||
import {Config, OB11Config} from './types';
|
||||
|
||||
import {mergeNewProperties} from "./utils/helper";
|
||||
@@ -76,7 +77,7 @@ export class ConfigUtil {
|
||||
|
||||
setConfig(config: Config) {
|
||||
this.config = config;
|
||||
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8")
|
||||
fsPromise.writeFile(this.configPath, JSON.stringify(config, null, 2), "utf-8").then()
|
||||
}
|
||||
|
||||
private checkOldConfig(currentConfig: Config | OB11Config,
|
||||
|
@@ -94,9 +94,9 @@ export async function refreshGroupMembers(groupQQ: string) {
|
||||
export const uidMaps: Record<string, string> = {} // 一串加密的字符串(uid) -> qq号
|
||||
|
||||
export function getUidByUin(uin: string) {
|
||||
for (const key in uidMaps) {
|
||||
if (uidMaps[key] === uin) {
|
||||
return key
|
||||
for (const uid in uidMaps) {
|
||||
if (uidMaps[uid] === uin) {
|
||||
return uid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ export interface CheckVersion {
|
||||
version: string
|
||||
}
|
||||
export interface Config {
|
||||
imageRKey?: string;
|
||||
ob11: OB11Config
|
||||
token?: string
|
||||
heartInterval?: number // ms
|
||||
|
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 fsPromise from "fs/promises";
|
||||
import crypto from "crypto";
|
||||
import ffmpeg from "fluent-ffmpeg";
|
||||
import util from "util";
|
||||
import {encode, getDuration, isWav} from "silk-wasm";
|
||||
import path from "node:path";
|
||||
import {v4 as uuidv4} from "uuid";
|
||||
import {checkFfmpeg, DATA_DIR, log, TEMP_DIR} from "./index";
|
||||
import {getConfigUtil} from "../config";
|
||||
import {log, TEMP_DIR} from "./index";
|
||||
import {dbUtil} from "../db";
|
||||
import * as fileType from "file-type";
|
||||
import {net} from "electron";
|
||||
import config from "../../../electron.vite.config";
|
||||
|
||||
|
||||
export function isGIF(path: string) {
|
||||
@@ -67,124 +63,6 @@ export async function file2base64(path: string) {
|
||||
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 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(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(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);
|
||||
});
|
||||
})
|
||||
}
|
||||
// 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) => {
|
||||
});
|
||||
const gDuration = await guessDuration(pttPath)
|
||||
log(`语音文件${filePath}转换成功!`, pttPath, `时长:`, silk.duration)
|
||||
return {
|
||||
converted: true,
|
||||
path: pttPath,
|
||||
duration: verifyDuration(silk.duration / 1000, gDuration),
|
||||
};
|
||||
} else {
|
||||
const silk = fs.readFileSync(filePath);
|
||||
let duration = 0;
|
||||
const gDuration = await guessDuration(filePath)
|
||||
try {
|
||||
duration = verifyDuration(getDuration(silk) / 1000, gDuration);
|
||||
} catch (e) {
|
||||
log("获取语音文件时长失败, 使用文件大小推测时长", filePath, e.stack)
|
||||
duration = gDuration;
|
||||
}
|
||||
|
||||
return {
|
||||
converted: false,
|
||||
path: filePath,
|
||||
duration: duration,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
log("convert silk failed", error.stack);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function calculateFileMD5(filePath: string): Promise<string> {
|
||||
@@ -286,9 +164,9 @@ export async function uri2local(uri: string, fileName: string = null): Promise<U
|
||||
} else if (url.protocol == "http:" || url.protocol == "https:") {
|
||||
// 下载文件
|
||||
let buffer: Buffer = null;
|
||||
try{
|
||||
try {
|
||||
buffer = await httpDownload(uri);
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
res.errMsg = `${url}下载失败,` + e.toString()
|
||||
return res
|
||||
}
|
||||
|
@@ -14,4 +14,5 @@ if (!fs.existsSync(TEMP_DIR)) {
|
||||
fs.mkdirSync(TEMP_DIR, {recursive: true});
|
||||
}
|
||||
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 {getConfigUtil} from "../config";
|
||||
|
||||
const date = new Date();
|
||||
const logFileName = `llonebot-${date.toLocaleString("zh-CN")}.log`.replace(/\//g, "-").replace(/:/g, "-");
|
||||
const logDir = path.join(DATA_DIR, "logs");
|
||||
if (!fs.existsSync(logDir)) {
|
||||
fs.mkdirSync(logDir, {recursive: true});
|
||||
}
|
||||
|
||||
export function log(...msg: any[]) {
|
||||
if (!getConfigUtil().getConfig().log) {
|
||||
return //console.log(...msg);
|
||||
}
|
||||
let currentDateTime = new Date().toLocaleString();
|
||||
const date = new Date();
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
const day = date.getDate();
|
||||
const currentDate = `${year}-${month}-${day}`;
|
||||
|
||||
const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : ""
|
||||
let logMsg = "";
|
||||
for (let msgItem of msg) {
|
||||
@@ -25,10 +27,11 @@ export function log(...msg: any[]) {
|
||||
}
|
||||
logMsg += msgItem + " ";
|
||||
}
|
||||
let currentDateTime = new Date().toLocaleString();
|
||||
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
||||
// sendLog(...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 isQQ998: boolean = qqPkgInfo.buildVersion >= "22106"
|
103
src/main/main.ts
103
src/main/main.ts
@@ -4,28 +4,36 @@ import {BrowserWindow, dialog, ipcMain} from 'electron';
|
||||
import * as fs from 'node:fs';
|
||||
import {Config} from "../common/types";
|
||||
import {
|
||||
CHANNEL_CHECK_VERSION,
|
||||
CHANNEL_ERROR,
|
||||
CHANNEL_GET_CONFIG,
|
||||
CHANNEL_LOG,
|
||||
CHANNEL_CHECK_VERSION,
|
||||
CHANNEL_SELECT_FILE,
|
||||
CHANNEL_SET_CONFIG,
|
||||
CHANNEL_UPDATE,
|
||||
} from "../common/channels";
|
||||
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||
import {DATA_DIR, wrapText} from "../common/utils";
|
||||
import {DATA_DIR} from "../common/utils";
|
||||
import {
|
||||
friendRequests,
|
||||
getFriend,
|
||||
getGroup,
|
||||
getGroupMember,
|
||||
getGroupMember, groups,
|
||||
llonebotError,
|
||||
refreshGroupMembers,
|
||||
selfInfo, uidMaps
|
||||
selfInfo,
|
||||
uidMaps
|
||||
} from "../common/data";
|
||||
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook} from "../ntqqapi/hook";
|
||||
import {OB11Constructor} from "../onebot11/constructor";
|
||||
import {ChatType, FriendRequestNotify, GroupNotifies, GroupNotifyTypes, RawMessage} from "../ntqqapi/types";
|
||||
import {
|
||||
ChatType,
|
||||
FriendRequestNotify,
|
||||
GroupMemberRole,
|
||||
GroupNotifies,
|
||||
GroupNotifyTypes,
|
||||
RawMessage
|
||||
} from "../ntqqapi/types";
|
||||
import {ob11HTTPServer} from "../onebot11/server/http";
|
||||
import {OB11FriendRecallNoticeEvent} from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
||||
import {OB11GroupRecallNoticeEvent} from "../onebot11/event/notice/OB11GroupRecallNoticeEvent";
|
||||
@@ -45,10 +53,11 @@ import {checkNewVersion, upgradeLLOneBot} from "../common/utils/upgrade";
|
||||
import {log} from "../common/utils/log";
|
||||
import {getConfigUtil} from "../common/config";
|
||||
import {checkFfmpeg} from "../common/utils/video";
|
||||
|
||||
import {GroupDecreaseSubType, OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
||||
|
||||
let running = false;
|
||||
|
||||
let mainWindow: BrowserWindow | null = null;
|
||||
|
||||
// 加载插件时触发
|
||||
function onLoad() {
|
||||
@@ -105,8 +114,26 @@ function onLoad() {
|
||||
const config = getConfigUtil().getConfig()
|
||||
return config;
|
||||
})
|
||||
ipcMain.on(CHANNEL_SET_CONFIG, (event, config: Config) => {
|
||||
setConfig(config).then();
|
||||
ipcMain.on(CHANNEL_SET_CONFIG, (event, ask: boolean, config: Config) => {
|
||||
if (!ask) {
|
||||
setConfig(config).then();
|
||||
return
|
||||
}
|
||||
dialog.showMessageBox(mainWindow, {
|
||||
type: 'question',
|
||||
buttons: ['确认', '取消'],
|
||||
defaultId: 0, // 默认选中的按钮,0 代表第一个按钮,即 "确认"
|
||||
title: '确认保存',
|
||||
message: '是否保存?',
|
||||
detail: 'LLOneBot配置已更改,是否保存?'
|
||||
}).then(result => {
|
||||
if (result.response === 0) {
|
||||
setConfig(config).then();
|
||||
} else {
|
||||
}
|
||||
}).catch(err => {
|
||||
log("保存设置询问弹窗错误", err);
|
||||
});
|
||||
})
|
||||
|
||||
ipcMain.on(CHANNEL_LOG, (event, arg) => {
|
||||
@@ -198,7 +225,6 @@ function onLoad() {
|
||||
parseInt(operatorId),
|
||||
oriMessage.msgShortId
|
||||
)
|
||||
|
||||
postOB11Event(groupRecallEvent);
|
||||
}
|
||||
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
||||
@@ -266,15 +292,28 @@ function onLoad() {
|
||||
log("变动管理员获取成功")
|
||||
groupAdminNoticeEvent.user_id = parseInt(member1.uin);
|
||||
groupAdminNoticeEvent.sub_type = notify.type == GroupNotifyTypes.ADMIN_UNSET ? "unset" : "set";
|
||||
// member1.role = notify.type == GroupNotifyTypes.ADMIN_SET ? GroupMemberRole.admin : GroupMemberRole.normal;
|
||||
postOB11Event(groupAdminNoticeEvent, true);
|
||||
} else {
|
||||
log("获取群通知的成员信息失败", notify, getGroup(notify.group.groupCode));
|
||||
}
|
||||
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT) {
|
||||
// log("有成员退出通知");
|
||||
// const member1 = await getGroupMember(notify.group.groupCode, null, notify.user1.uid);
|
||||
// let groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(notify.group.groupCode), parseInt(member1.uin))
|
||||
// postEvent(groupDecreaseEvent, true);
|
||||
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
|
||||
log("有成员退出通知", notify);
|
||||
try {
|
||||
const member1 = await NTQQUserApi.getUserDetailInfo(notify.user1.uid);
|
||||
let operatorId = member1.uin;
|
||||
let subType: GroupDecreaseSubType = "leave";
|
||||
if (notify.user2.uid) {
|
||||
// 是被踢的
|
||||
const member2 = await getGroupMember(notify.group.groupCode, notify.user2.uid);
|
||||
operatorId = member2.uin;
|
||||
subType = "kick";
|
||||
}
|
||||
let groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(notify.group.groupCode), parseInt(member1.uin), parseInt(operatorId), subType)
|
||||
postOB11Event(groupDecreaseEvent, true);
|
||||
} catch (e) {
|
||||
log("获取群通知的成员信息失败", notify, e.stack.toString())
|
||||
}
|
||||
} else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) {
|
||||
log("有加群请求");
|
||||
let groupRequestEvent = new OB11GroupRequestEvent();
|
||||
@@ -339,7 +378,7 @@ function onLoad() {
|
||||
log("llonebot pid", process.pid)
|
||||
llonebotError.otherError = "";
|
||||
startTime = Date.now();
|
||||
dbUtil.getReceivedTempUinMap().then(m=>{
|
||||
dbUtil.getReceivedTempUinMap().then(m => {
|
||||
for (const [key, value] of Object.entries(m)) {
|
||||
uidMaps[value] = key;
|
||||
}
|
||||
@@ -371,23 +410,31 @@ function onLoad() {
|
||||
} catch (e) {
|
||||
log("retry get self info", e);
|
||||
}
|
||||
log("self info", selfInfo);
|
||||
if (!selfInfo.uin) {
|
||||
selfInfo.uin = globalThis.authData?.uin;
|
||||
selfInfo.uid = globalThis.authData?.uid;
|
||||
selfInfo.nick = selfInfo.uin;
|
||||
}
|
||||
log("self info", selfInfo, globalThis.authData);
|
||||
if (selfInfo.uin) {
|
||||
try {
|
||||
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
||||
log("self info", userInfo);
|
||||
if (userInfo) {
|
||||
selfInfo.nick = userInfo.nick;
|
||||
} else {
|
||||
async function getUserNick() {
|
||||
try {
|
||||
getSelfNickCount++;
|
||||
if (getSelfNickCount < 10) {
|
||||
return setTimeout(init, 1000);
|
||||
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
||||
log("self info", userInfo);
|
||||
if (userInfo) {
|
||||
selfInfo.nick = userInfo.nick;
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
log("get self nickname failed", e.stack);
|
||||
}
|
||||
if (getSelfNickCount < 10) {
|
||||
return setTimeout(getUserNick, 1000);
|
||||
}
|
||||
} catch (e) {
|
||||
log("get self nickname failed", e.toString());
|
||||
return setTimeout(init, 1000);
|
||||
}
|
||||
|
||||
getUserNick().then()
|
||||
start().then();
|
||||
} else {
|
||||
setTimeout(init, 1000)
|
||||
@@ -402,6 +449,7 @@ function onBrowserWindowCreated(window: BrowserWindow) {
|
||||
if (selfInfo.uid) {
|
||||
return
|
||||
}
|
||||
mainWindow = window;
|
||||
log("window create", window.webContents.getURL().toString())
|
||||
try {
|
||||
hookNTQQApiCall(window);
|
||||
@@ -417,6 +465,7 @@ try {
|
||||
console.log(e.toString())
|
||||
}
|
||||
|
||||
|
||||
// 这两个函数都是可选的
|
||||
export {
|
||||
onBrowserWindowCreated
|
||||
|
@@ -47,7 +47,7 @@ export class NTQQFileApi {
|
||||
}
|
||||
|
||||
// 上传文件到QQ的文件夹
|
||||
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
||||
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType: number = 0) {
|
||||
const md5 = await NTQQFileApi.getFileMd5(filePath);
|
||||
let ext = (await NTQQFileApi.getFileType(filePath))?.ext
|
||||
if (ext) {
|
||||
@@ -66,7 +66,7 @@ export class NTQQFileApi {
|
||||
md5HexStr: md5,
|
||||
fileName: fileName,
|
||||
elementType: elementType,
|
||||
elementSubType: 0,
|
||||
elementSubType,
|
||||
thumbSize: 0,
|
||||
needCreate: true,
|
||||
downloadType: 1,
|
||||
@@ -81,7 +81,8 @@ export class NTQQFileApi {
|
||||
md5,
|
||||
fileName,
|
||||
path: mediaPath,
|
||||
fileSize
|
||||
fileSize,
|
||||
ext
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,6 @@ import {ReceiveCmdS} from "../hook";
|
||||
import {Group, GroupMember, GroupMemberRole, GroupNotifies, GroupNotify, GroupRequestOperateTypes} from "../types";
|
||||
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||
import {uidMaps} from "../../common/data";
|
||||
import {BrowserWindow} from "electron";
|
||||
import {dbUtil} from "../../common/db";
|
||||
import {log} from "../../common/utils/log";
|
||||
import {NTQQWindowApi, NTQQWindows} from "./window";
|
||||
@@ -11,7 +10,7 @@ export class NTQQGroupApi{
|
||||
static async getGroups(forced = false) {
|
||||
let cbCmd = ReceiveCmdS.GROUPS
|
||||
if (process.platform != "win32") {
|
||||
cbCmd = ReceiveCmdS.GROUPS_UNIX
|
||||
cbCmd = ReceiveCmdS.GROUPS_STORE
|
||||
}
|
||||
const result = await callNTQQApi<{
|
||||
updateType: number,
|
||||
|
@@ -5,6 +5,7 @@ import {selfInfo} from "../../common/data";
|
||||
import {ReceiveCmdS, registerReceiveHook} from "../hook";
|
||||
import {log} from "../../common/utils/log";
|
||||
import {sleep} from "../../common/utils/helper";
|
||||
import {isQQ998} from "../../common/utils";
|
||||
|
||||
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {}// peerUid: callbackFunnc
|
||||
|
||||
@@ -15,6 +16,17 @@ export interface Peer {
|
||||
}
|
||||
|
||||
export class NTQQMsgApi {
|
||||
static async getMultiMsg(peer: Peer, rootMsgId: string, parentMsgId: string) {
|
||||
return await callNTQQApi<GeneralCallResult & {msgList: RawMessage[]}>({
|
||||
methodName: NTQQApiMethod.GET_MULTI_MSG,
|
||||
args: [{
|
||||
peer,
|
||||
rootMsgId,
|
||||
parentMsgId
|
||||
}, null]
|
||||
})
|
||||
}
|
||||
|
||||
static async activateGroupChat(groupCode: string) {
|
||||
// await this.fetchRecentContact();
|
||||
// await sleep(500);
|
||||
@@ -25,7 +37,7 @@ export class NTQQMsgApi {
|
||||
}
|
||||
static async getMsgHistory(peer: Peer, msgId: string, count: number) {
|
||||
return await callNTQQApi<GeneralCallResult & {msgList: RawMessage[]}>({
|
||||
methodName: NTQQApiMethod.HISTORY_MSG,
|
||||
methodName: isQQ998 ? NTQQApiMethod.HISTORY_MSG_998 : NTQQApiMethod.HISTORY_MSG,
|
||||
args: [{
|
||||
peer,
|
||||
msgId,
|
||||
|
@@ -2,7 +2,10 @@ import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../nt
|
||||
import {SelfInfo, User} from "../types";
|
||||
import {ReceiveCmdS} from "../hook";
|
||||
import {uidMaps} from "../../common/data";
|
||||
import {NTQQWindowApi, NTQQWindows} from "./window";
|
||||
import {isQQ998, sleep} from "../../common/utils";
|
||||
|
||||
let userInfoCache: Record<string, User> = {}; // uid: User
|
||||
|
||||
export class NTQQUserApi{
|
||||
static async setQQAvatar(filePath: string) {
|
||||
@@ -29,28 +32,86 @@ export class NTQQUserApi{
|
||||
})
|
||||
return result.profiles.get(uid)
|
||||
}
|
||||
static async getUserDetailInfo(uid: string) {
|
||||
const result = await callNTQQApi<{ info: User }>({
|
||||
methodName: NTQQApiMethod.USER_DETAIL_INFO,
|
||||
cbCmd: ReceiveCmdS.USER_DETAIL_INFO,
|
||||
afterFirstCmd: false,
|
||||
cmdCB: (payload) => {
|
||||
const success = payload.info.uid == uid
|
||||
// log("get user detail info", success, uid, payload)
|
||||
return success
|
||||
},
|
||||
static async getUserDetailInfo(uid: string, getLevel=false) {
|
||||
// this.getUserInfo(uid);
|
||||
let methodName = !isQQ998 ? NTQQApiMethod.USER_DETAIL_INFO : NTQQApiMethod.USER_DETAIL_INFO_WITH_BIZ_INFO
|
||||
const fetchInfo = async ()=>{
|
||||
const result = await callNTQQApi<{ info: User }>({
|
||||
methodName,
|
||||
cbCmd: ReceiveCmdS.USER_DETAIL_INFO,
|
||||
afterFirstCmd: false,
|
||||
cmdCB: (payload) => {
|
||||
const success = payload.info.uid == uid
|
||||
// log("get user detail info", success, uid, payload)
|
||||
return success
|
||||
},
|
||||
args: [
|
||||
{
|
||||
uid
|
||||
},
|
||||
null
|
||||
]
|
||||
})
|
||||
const info = result.info
|
||||
if (info?.uin) {
|
||||
uidMaps[info.uid] = info.uin
|
||||
}
|
||||
return info
|
||||
}
|
||||
// 首次请求两次才能拿到的等级信息
|
||||
if (!userInfoCache[uid] && getLevel) {
|
||||
await fetchInfo()
|
||||
await sleep(1000);
|
||||
}
|
||||
let userInfo = await fetchInfo()
|
||||
userInfoCache[uid] = userInfo
|
||||
return userInfo
|
||||
}
|
||||
|
||||
static async getPSkey() {
|
||||
return await callNTQQApi<string>({
|
||||
className: NTQQApiClass.GROUP_HOME_WORK,
|
||||
methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||
args: [
|
||||
{
|
||||
uid
|
||||
},
|
||||
null
|
||||
domain: "qun.qq.com"
|
||||
}
|
||||
]
|
||||
})
|
||||
const info = result.info
|
||||
if (info?.uin) {
|
||||
uidMaps[info.uid] = info.uin
|
||||
}
|
||||
return info
|
||||
}
|
||||
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 {log} from "../../common/utils";
|
||||
import {NTQQUserApi} from "./user";
|
||||
|
||||
export class WebApi{
|
||||
private static bkn: string;
|
||||
@@ -43,9 +42,9 @@ export class WebApi{
|
||||
private async init(){
|
||||
if (!WebApi.bkn) {
|
||||
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);
|
||||
let cookie = await NTQQApi.getPSkey();
|
||||
let cookie = await NTQQUserApi.getPSkey();
|
||||
const pskeyRegex = /p_skey=([^;]+)/;
|
||||
const match = cookie.match(pskeyRegex);
|
||||
const pskeyValue = match ? match[1] : null;
|
||||
|
@@ -14,9 +14,10 @@ import {
|
||||
import {promises as fs} from "node:fs";
|
||||
import ffmpeg from "fluent-ffmpeg"
|
||||
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 {defaultVideoThumb, getVideoInfo} from "../common/utils/video";
|
||||
import {encodeSilk} from "../common/utils/audio";
|
||||
|
||||
|
||||
export class SendMsgElementConstructor {
|
||||
@@ -61,32 +62,32 @@ export class SendMsgElementConstructor {
|
||||
}
|
||||
}
|
||||
|
||||
static async pic(picPath: string, summary: string = ""): Promise<SendPicElement> {
|
||||
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC);
|
||||
static async pic(picPath: string, summary: string = "", subType: 0|1=0): Promise<SendPicElement> {
|
||||
const {md5, fileName, path, fileSize, ext} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC, subType);
|
||||
if (fileSize === 0) {
|
||||
throw "文件异常,大小为0";
|
||||
}
|
||||
const imageSize = await NTQQFileApi.getImageSize(picPath);
|
||||
const picElement = {
|
||||
md5HexStr: md5,
|
||||
fileSize: fileSize,
|
||||
fileSize: fileSize.toString(),
|
||||
picWidth: imageSize.width,
|
||||
picHeight: imageSize.height,
|
||||
fileName: fileName,
|
||||
fileName: md5 + ext,
|
||||
sourcePath: path,
|
||||
original: true,
|
||||
picType: isGIF(picPath) ? PicType.gif : PicType.jpg,
|
||||
picSubType: 0,
|
||||
picSubType: subType,
|
||||
fileUuid: "",
|
||||
fileSubId: "",
|
||||
thumbFileSize: 0,
|
||||
summary,
|
||||
summary
|
||||
};
|
||||
|
||||
log("图片信息", picElement)
|
||||
return {
|
||||
elementType: ElementType.PIC,
|
||||
elementId: "",
|
||||
picElement
|
||||
picElement,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ export class SendMsgElementConstructor {
|
||||
let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
|
||||
thumb = pathLib.dirname(thumb)
|
||||
// log("thumb 目录", thumb)
|
||||
let videoInfo ={
|
||||
let videoInfo = {
|
||||
width: 1920, height: 1080,
|
||||
time: 15,
|
||||
format: "mp4",
|
||||
@@ -127,7 +128,7 @@ export class SendMsgElementConstructor {
|
||||
try {
|
||||
videoInfo = await getVideoInfo(path);
|
||||
log("视频信息", videoInfo)
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
log("获取视频信息失败", e)
|
||||
}
|
||||
const createThumb = new Promise<string>((resolve, reject) => {
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import {BrowserWindow} from 'electron';
|
||||
import {NTQQApiClass} from "./ntcall";
|
||||
import {NTQQMsgApi, sendMessagePool} from "./api/msg"
|
||||
import {ChatType, Group, RawMessage, User} from "./types";
|
||||
import {friends, groups, selfInfo, tempGroupCodeMap, uidMaps} from "../common/data";
|
||||
import {ChatType, Group, GroupMember, GroupMemberRole, RawMessage, User} from "./types";
|
||||
import {friends, getGroupMember, groups, selfInfo, tempGroupCodeMap, uidMaps} from "../common/data";
|
||||
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
||||
import {v4 as uuidv4} from "uuid"
|
||||
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
||||
@@ -24,7 +24,8 @@ export let ReceiveCmdS = {
|
||||
USER_INFO: "nodeIKernelProfileListener/onProfileSimpleChanged",
|
||||
USER_DETAIL_INFO: "nodeIKernelProfileListener/onProfileDetailInfoChanged",
|
||||
GROUPS: "nodeIKernelGroupListener/onGroupListUpdate",
|
||||
GROUPS_UNIX: "onGroupListUpdate",
|
||||
GROUPS_STORE: "onGroupListUpdate",
|
||||
GROUP_MEMBER_INFO_UPDATE: "nodeIKernelGroupListener/onMemberInfoChange",
|
||||
FRIENDS: "onBuddyListChange",
|
||||
MEDIA_DOWNLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaDownloadComplete",
|
||||
UNREAD_GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated",
|
||||
@@ -192,7 +193,7 @@ export function removeReceiveHook(id: string) {
|
||||
let activatedGroups: string[] = [];
|
||||
async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
||||
for (let group of _groups) {
|
||||
// log("update group", group)
|
||||
log("update group", group)
|
||||
if (!activatedGroups.includes(group.groupCode)) {
|
||||
NTQQMsgApi.activateGroupChat(group.groupCode).then((r) => {
|
||||
activatedGroups.push(group.groupCode);
|
||||
@@ -221,13 +222,14 @@ async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
||||
}
|
||||
}
|
||||
|
||||
async function processGroupEvent(payload) {
|
||||
async function processGroupEvent(payload: {groupList: Group[]}) {
|
||||
try {
|
||||
const newGroupList = payload.groupList;
|
||||
for (const group of newGroupList) {
|
||||
let existGroup = groups.find(g => g.groupCode == group.groupCode);
|
||||
if (existGroup) {
|
||||
if (existGroup.memberCount > group.memberCount) {
|
||||
log(`群(${group.groupCode})成员数量减少${existGroup.memberCount} -> ${group.memberCount}`);
|
||||
const oldMembers = existGroup.members;
|
||||
|
||||
await sleep(200); // 如果请求QQ API的速度过快,通常无法正确拉取到最新的群信息,因此这里人为引入一个延时
|
||||
@@ -240,25 +242,33 @@ async function processGroupEvent(payload) {
|
||||
newMembersSet.add(member.uin);
|
||||
}
|
||||
|
||||
// 判断bot是否是管理员,如果是管理员不需要从这里得知有人退群,这里的退群无法得知是主动退群还是被踢
|
||||
let bot = await getGroupMember(group.groupCode, selfInfo.uin)
|
||||
if (bot.role == GroupMemberRole.admin || bot.role == GroupMemberRole.owner) {
|
||||
continue
|
||||
}
|
||||
for (const member of oldMembers) {
|
||||
if (!newMembersSet.has(member.uin)) {
|
||||
postOB11Event(new OB11GroupDecreaseEvent(group.groupCode, parseInt(member.uin)));
|
||||
if (!newMembersSet.has(member.uin) && member.uin != selfInfo.uin) {
|
||||
postOB11Event(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin), parseInt(member.uin), "leave"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
updateGroups(newGroupList, false).then();
|
||||
} catch (e) {
|
||||
updateGroups(payload.groupList).then();
|
||||
console.log(e);
|
||||
log("更新群信息错误", e.stack.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// 群列表变动
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS, (payload) => {
|
||||
// updateType 3是群列表变动,2是群成员变动
|
||||
// log("群列表变动", payload.updateType, payload.groupList)
|
||||
if (payload.updateType != 2) {
|
||||
updateGroups(payload.groupList).then();
|
||||
} else {
|
||||
@@ -267,7 +277,9 @@ registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROU
|
||||
}
|
||||
}
|
||||
})
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS_UNIX, (payload) => {
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS_STORE, (payload) => {
|
||||
// updateType 3是群列表变动,2是群成员变动
|
||||
// log("群列表变动", payload.updateType, payload.groupList)
|
||||
if (payload.updateType != 2) {
|
||||
updateGroups(payload.groupList).then();
|
||||
} else {
|
||||
@@ -277,6 +289,32 @@ registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROU
|
||||
}
|
||||
})
|
||||
|
||||
registerReceiveHook<{groupCode: string, dataSource: number, members: Set<GroupMember>}>(ReceiveCmdS.GROUP_MEMBER_INFO_UPDATE, async (payload) => {
|
||||
const groupCode = payload.groupCode;
|
||||
const members = Array.from(payload.members.values());
|
||||
// log("群成员信息变动", groupCode, members)
|
||||
for(const member of members) {
|
||||
const existMember = await getGroupMember(groupCode, member.uin);
|
||||
if (existMember){
|
||||
Object.assign(existMember, member);
|
||||
}
|
||||
}
|
||||
// const existGroup = groups.find(g => g.groupCode == groupCode);
|
||||
// if (existGroup) {
|
||||
// log("对比群成员", existGroup.members, members)
|
||||
// for (const member of members) {
|
||||
// const existMember = existGroup.members.find(m => m.uin == member.uin);
|
||||
// if (existMember) {
|
||||
// log("对比群名片", existMember.cardName, member.cardName)
|
||||
// if (existMember.cardName != member.cardName) {
|
||||
// postOB11Event(new OB11GroupCardEvent(parseInt(existGroup.groupCode), parseInt(member.uin), member.cardName, existMember.cardName));
|
||||
// }
|
||||
// Object.assign(existMember, member);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
})
|
||||
|
||||
// 好友列表变动
|
||||
registerReceiveHook<{
|
||||
data: { categoryId: number, categroyName: string, categroyMbCount: number, buddyList: User[] }[]
|
||||
|
@@ -23,7 +23,10 @@ export enum NTQQApiClass {
|
||||
export enum NTQQApiMethod {
|
||||
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
|
||||
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
||||
HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
||||
HISTORY_MSG_998 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
||||
HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelf",
|
||||
GET_MULTI_MSG = "nodeIKernelMsgService/getMultiMsg",
|
||||
|
||||
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
||||
SELF_INFO = "fetchAuthData",
|
||||
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
||||
@@ -32,6 +35,7 @@ export enum NTQQApiMethod {
|
||||
GROUP_MEMBERS = "nodeIKernelGroupService/getNextMemberList",
|
||||
USER_INFO = "nodeIKernelProfileService/getUserSimpleInfo",
|
||||
USER_DETAIL_INFO = "nodeIKernelProfileService/getUserDetailInfo",
|
||||
USER_DETAIL_INFO_WITH_BIZ_INFO = "nodeIKernelProfileService/getUserDetailInfoWithBizInfo",
|
||||
FILE_TYPE = "getFileType",
|
||||
FILE_MD5 = "getFileMd5",
|
||||
FILE_COPY = "copyFile",
|
||||
@@ -161,7 +165,12 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
||||
|
||||
ipcMain.emit(
|
||||
channel,
|
||||
{},
|
||||
{
|
||||
sender: {
|
||||
send: (..._args: unknown[]) => {
|
||||
},
|
||||
},
|
||||
},
|
||||
{type: 'request', callbackId: uuid, eventName},
|
||||
apiArgs
|
||||
)
|
||||
@@ -185,59 +194,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);
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
import {GroupMemberRole} from "./group";
|
||||
import exp from "constants";
|
||||
|
||||
export enum ElementType {
|
||||
TEXT = 1,
|
||||
@@ -48,24 +49,29 @@ export enum PicType {
|
||||
jpg = 1000
|
||||
}
|
||||
|
||||
export enum PicSubType {
|
||||
normal = 0, // 普通图片,大图
|
||||
face = 1 // 表情包小图
|
||||
}
|
||||
|
||||
export interface SendPicElement {
|
||||
elementType: ElementType.PIC,
|
||||
elementId: "",
|
||||
picElement: {
|
||||
md5HexStr: string,
|
||||
fileSize: number,
|
||||
fileSize: number | string,
|
||||
picWidth: number,
|
||||
picHeight: number,
|
||||
fileName: string,
|
||||
sourcePath: string,
|
||||
original: boolean,
|
||||
picType: PicType,
|
||||
picSubType: number,
|
||||
picSubType: PicSubType,
|
||||
fileUuid: string,
|
||||
fileSubId: string,
|
||||
thumbFileSize: number,
|
||||
summary: string,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export interface SendReplyElement {
|
||||
@@ -98,7 +104,8 @@ export interface FileElement {
|
||||
"fileSha3"?: "",
|
||||
"fileUuid"?: "",
|
||||
"fileSubId"?: "",
|
||||
"thumbFileSize"?: number
|
||||
"thumbFileSize"?: number,
|
||||
fileBizId?: number
|
||||
}
|
||||
|
||||
export interface SendFileElement {
|
||||
@@ -165,9 +172,11 @@ export interface ArkElement {
|
||||
}
|
||||
|
||||
export const IMAGE_HTTP_HOST = "https://gchat.qpic.cn"
|
||||
export const IMAGE_HTTP_HOST_NT = "https://multimedia.nt.qq.com.cn"
|
||||
|
||||
export interface PicElement {
|
||||
originImageUrl: string; // http url, 没有host,host是https://gchat.qpic.cn/
|
||||
originImageUrl: string; // http url, 没有host,host是https://gchat.qpic.cn/, 带download参数的是https://multimedia.nt.qq.com.cn
|
||||
originImageMd5?: string;
|
||||
sourcePath: string; // 图片本地路径
|
||||
thumbPath: Map<number, string>;
|
||||
picWidth: number;
|
||||
@@ -180,6 +189,7 @@ export interface PicElement {
|
||||
|
||||
export enum GrayTipElementSubType {
|
||||
INVITE_NEW_MEMBER = 12,
|
||||
MEMBER_NEW_TITLE = 17
|
||||
}
|
||||
|
||||
export interface GrayTipElement {
|
||||
@@ -196,6 +206,9 @@ export interface GrayTipElement {
|
||||
groupElement: TipGroupElement,
|
||||
xmlElement: {
|
||||
content: string;
|
||||
},
|
||||
jsonGrayTipElement: {
|
||||
jsonStr: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +217,45 @@ export interface FaceElement {
|
||||
faceType: 1
|
||||
}
|
||||
|
||||
export interface MarketFaceElement {
|
||||
"itemType": 6,
|
||||
"faceInfo": 1,
|
||||
"emojiPackageId": 203875,
|
||||
"subType": 3,
|
||||
"mediaType": 0,
|
||||
"imageWidth": 200,
|
||||
"imageHeight": 200,
|
||||
"faceName": string,
|
||||
"emojiId": "094d53bd1c9ac5d35d04b08e8a6c992c",
|
||||
"key": "a8b1dd0aebc8d910",
|
||||
"param": null,
|
||||
"mobileParam": null,
|
||||
"sourceType": null,
|
||||
"startTime": null,
|
||||
"endTime": null,
|
||||
"emojiType": 1,
|
||||
"hasIpProduct": null,
|
||||
"voiceItemHeightArr": null,
|
||||
"sourceName": null,
|
||||
"sourceJumpUrl": null,
|
||||
"sourceTypeName": null,
|
||||
"backColor": null,
|
||||
"volumeColor": null,
|
||||
"staticFacePath": "E:\\SystemDocuments\\QQ\\721011692\\nt_qq\\nt_data\\Emoji\\marketface\\203875\\094d53bd1c9ac5d35d04b08e8a6c992c_aio.png",
|
||||
"dynamicFacePath": "E:\\SystemDocuments\\QQ\\721011692\\nt_qq\\nt_data\\Emoji\\marketface\\203875\\094d53bd1c9ac5d35d04b08e8a6c992c",
|
||||
"supportSize": [
|
||||
{
|
||||
"width": 300,
|
||||
"height": 300
|
||||
},
|
||||
{
|
||||
"width": 200,
|
||||
"height": 200
|
||||
}
|
||||
],
|
||||
"apngSupportSize": null
|
||||
}
|
||||
|
||||
export interface VideoElement {
|
||||
"filePath": string,
|
||||
"fileName": string,
|
||||
@@ -229,6 +281,34 @@ export interface VideoElement {
|
||||
"sourceVideoCodecFormat"?: number
|
||||
}
|
||||
|
||||
export interface MarkdownElement {
|
||||
content: string,
|
||||
}
|
||||
|
||||
export interface InlineKeyboardElementRowButton{
|
||||
"id": "",
|
||||
"label": string,
|
||||
"visitedLabel": string,
|
||||
"style": 1, // 未知
|
||||
"type": 2, // 未知
|
||||
"clickLimit": 0, // 未知
|
||||
"unsupportTips": "请升级新版手机QQ",
|
||||
"data": string,
|
||||
"atBotShowChannelList": false,
|
||||
"permissionType": 2,
|
||||
"specifyRoleIds": [],
|
||||
"specifyTinyids": [],
|
||||
"isReply": false,
|
||||
"anchor": 0,
|
||||
"enter": false,
|
||||
"subscribeDataTemplateIds": []
|
||||
}
|
||||
export interface InlineKeyboardElement {
|
||||
rows: [{
|
||||
buttons: InlineKeyboardElementRowButton[]
|
||||
}]
|
||||
}
|
||||
|
||||
export interface TipAioOpGrayTipElement { // 这是什么提示来着?
|
||||
operateType: number,
|
||||
peerUid: string,
|
||||
@@ -237,6 +317,7 @@ export interface TipAioOpGrayTipElement { // 这是什么提示来着?
|
||||
|
||||
export enum TipGroupElementType {
|
||||
memberIncrease = 1,
|
||||
kicked = 3, // 被移出群
|
||||
ban = 8
|
||||
}
|
||||
|
||||
@@ -247,7 +328,7 @@ export interface TipGroupElement {
|
||||
"memberUid": string,
|
||||
"memberNick": string,
|
||||
"memberRemark": string,
|
||||
"adminUid": string, // 同意加群的管理员uid
|
||||
"adminUid": string,
|
||||
"adminNick": string,
|
||||
"adminRemark": string,
|
||||
"createGroup": null,
|
||||
@@ -279,6 +360,11 @@ export interface TipGroupElement {
|
||||
}
|
||||
}
|
||||
|
||||
export interface MultiForwardMsgElement{
|
||||
xmlContent: string, // xml格式的消息内容
|
||||
resId: string,
|
||||
fileName: string,
|
||||
}
|
||||
|
||||
export interface RawMessage {
|
||||
msgId: string;
|
||||
@@ -316,5 +402,9 @@ export interface RawMessage {
|
||||
faceElement: FaceElement;
|
||||
videoElement: VideoElement;
|
||||
fileElement: FileElement;
|
||||
marketFaceElement: MarketFaceElement;
|
||||
inlineKeyboardElement: InlineKeyboardElement;
|
||||
markdownElement: MarkdownElement;
|
||||
multiForwardMsgElement: MultiForwardMsgElement;
|
||||
}[];
|
||||
}
|
@@ -4,8 +4,9 @@ export enum GroupNotifyTypes {
|
||||
INVITED_JOIN = 4, // 有人接受了邀请入群
|
||||
JOIN_REQUEST = 7,
|
||||
ADMIN_SET = 8,
|
||||
KICK_MEMBER = 9,
|
||||
MEMBER_EXIT = 11, // 主动退出
|
||||
ADMIN_UNSET = 12,
|
||||
MEMBER_EXIT = 11, // 主动退出?
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import {ActionName, BaseCheckResult} from "./types"
|
||||
import {OB11Response} from "./utils"
|
||||
import {OB11Response} from "./OB11Response"
|
||||
import {OB11Return} from "../types";
|
||||
|
||||
import {log} from "../../common/utils/log";
|
||||
|
@@ -1,16 +0,0 @@
|
||||
import {OB11Group} from '../types';
|
||||
import {OB11Constructor} from "../constructor";
|
||||
import {groups} from "../../common/data";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
|
||||
class GetGroupList extends BaseAction<null, OB11Group[]> {
|
||||
actionName = ActionName.GetGroupList
|
||||
|
||||
protected async _handle(payload: null) {
|
||||
return OB11Constructor.groups(groups);
|
||||
}
|
||||
}
|
||||
|
||||
export default GetGroupList
|
@@ -1,10 +1,11 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import BaseAction from "../BaseAction";
|
||||
import fs from "fs/promises";
|
||||
import {dbUtil} from "../../common/db";
|
||||
import {getConfigUtil} from "../../common/config";
|
||||
import {log, sleep, uri2local} from "../../common/utils";
|
||||
import {NTQQFileApi} from "../../ntqqapi/api/file";
|
||||
import {ActionName} from "./types";
|
||||
import {dbUtil} from "../../../common/db";
|
||||
import {getConfigUtil} from "../../../common/config";
|
||||
import {log, sleep, uri2local} from "../../../common/utils";
|
||||
import {NTQQFileApi} from "../../../ntqqapi/api/file";
|
||||
import {ActionName} from "../types";
|
||||
import {FileElement, RawMessage, VideoElement} from "../../../ntqqapi/types";
|
||||
|
||||
export interface GetFilePayload {
|
||||
file: string // 文件名或者fileUuid
|
||||
@@ -20,6 +21,14 @@ export interface 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> {
|
||||
const cache = await dbUtil.getFileCache(payload.file)
|
||||
const {autoDeleteFile, enableLocalFile2Url, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
||||
@@ -49,18 +58,17 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
let msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||
if (msg){
|
||||
log("找到了文件 msg", msg)
|
||||
const element = msg.elements.find(e=>e.fileElement)
|
||||
let element = this.getElement(msg);
|
||||
log("找到了文件 element", element);
|
||||
// 构建下载函数
|
||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
element.elementId, "", "", true)
|
||||
element.id, "", "", true)
|
||||
await sleep(1000);
|
||||
msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import {GetFileBase} from "./GetFile";
|
||||
import {ActionName} from "./types";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
|
||||
export default class GetImage extends GetFileBase {
|
@@ -1,5 +1,5 @@
|
||||
import {GetFileBase, GetFilePayload, GetFileResponse} from "./GetFile";
|
||||
import {ActionName} from "./types";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
interface Payload extends GetFilePayload {
|
||||
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
|
39
src/onebot11/action/go-cqhttp/GetForwardMsg.ts
Normal file
39
src/onebot11/action/go-cqhttp/GetForwardMsg.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import BaseAction from "../BaseAction";
|
||||
import {OB11ForwardMessage, OB11Message, OB11MessageData} from "../../types";
|
||||
import {NTQQMsgApi, Peer} from "../../../ntqqapi/api";
|
||||
import {dbUtil} from "../../../common/db";
|
||||
import {OB11Constructor} from "../../constructor";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
interface Payload {
|
||||
message_id: string; // long msg id
|
||||
}
|
||||
|
||||
interface Response{
|
||||
messages: (OB11Message & {content: OB11MessageData})[]
|
||||
}
|
||||
|
||||
export class GoCQHTTGetForwardMsgAction extends BaseAction<Payload, any>{
|
||||
actionName = ActionName.GoCQHTTP_GetForwardMsg
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const rootMsg = await dbUtil.getMsgByLongId(payload.message_id)
|
||||
if (!rootMsg){
|
||||
throw Error("msg not found")
|
||||
}
|
||||
let data = await NTQQMsgApi.getMultiMsg({chatType: rootMsg.chatType, peerUid: rootMsg.peerUid}, rootMsg.msgId, rootMsg.msgId)
|
||||
if (data.result !== 0){
|
||||
throw Error("找不到相关的聊天记录" + data.errMsg)
|
||||
}
|
||||
let msgList = data.msgList
|
||||
let messages = await Promise.all(msgList.map(async msg => {
|
||||
let resMsg = await OB11Constructor.message(msg)
|
||||
resMsg.message_id = await dbUtil.addMsg(msg);
|
||||
return resMsg
|
||||
}))
|
||||
messages.map(msg => {
|
||||
(<OB11ForwardMessage>msg).content = msg.message;
|
||||
delete msg.message;
|
||||
})
|
||||
return {messages}
|
||||
}
|
||||
}
|
@@ -11,24 +11,29 @@ import {log} from "../../../common/utils";
|
||||
|
||||
interface Payload {
|
||||
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
|
||||
|
||||
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())
|
||||
if (!group) {
|
||||
throw `群${payload.group_id}不存在`
|
||||
}
|
||||
const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || "0"
|
||||
// log("startMsgId", startMsgId)
|
||||
let msgList = (await NTQQMsgApi.getMsgHistory({chatType: ChatType.group, peerUid: group.groupCode}, startMsgId, 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 => {
|
||||
msg.msgShortId = await dbUtil.addMsg(msg)
|
||||
}))
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg=>OB11Constructor.message(msg)))
|
||||
return ob11MsgList
|
||||
return {"messages": ob11MsgList}
|
||||
}
|
||||
}
|
@@ -15,6 +15,6 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<{ user_id: numbe
|
||||
if (!uid) {
|
||||
throw new Error("查无此人")
|
||||
}
|
||||
return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid))
|
||||
return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid, true))
|
||||
}
|
||||
}
|
@@ -1,18 +1,20 @@
|
||||
import SendMsg from "../SendMsg";
|
||||
import SendMsg, {convertMessage2List} from "../msg/SendMsg";
|
||||
import {OB11PostSendMsg} from "../../types";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
export class GoCQHTTPSendGroupForwardMsg extends SendMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||
export class GoCQHTTPSendForwardMsg extends SendMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendForwardMsg;
|
||||
|
||||
protected async check(payload: OB11PostSendMsg) {
|
||||
if (payload.messages){
|
||||
payload.message = this.convertMessage2List(payload.messages);
|
||||
}
|
||||
if (payload.messages) payload.message = convertMessage2List(payload.messages);
|
||||
return super.check(payload);
|
||||
}
|
||||
}
|
||||
|
||||
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendGroupForwardMsg {
|
||||
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
|
||||
}
|
||||
|
||||
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||
}
|
@@ -1,8 +1,8 @@
|
||||
import {OB11Group} from '../types';
|
||||
import {getGroup} from "../../common/data";
|
||||
import {OB11Constructor} from "../constructor";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {OB11Group} from '../../types';
|
||||
import {getGroup} from "../../../common/data";
|
||||
import {OB11Constructor} from "../../constructor";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
interface PayloadType {
|
||||
group_id: number
|
22
src/onebot11/action/group/GetGroupList.ts
Normal file
22
src/onebot11/action/group/GetGroupList.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {OB11Group} from '../../types';
|
||||
import {OB11Constructor} from "../../constructor";
|
||||
import {groups} from "../../../common/data";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api";
|
||||
import {log} from "../../../common/utils";
|
||||
|
||||
|
||||
class GetGroupList extends BaseAction<null, OB11Group[]> {
|
||||
actionName = ActionName.GetGroupList
|
||||
|
||||
protected async _handle(payload: null) {
|
||||
// if (groups.length === 0) {
|
||||
// const groups = await NTQQGroupApi.getGroups(true)
|
||||
// log("get groups", groups)
|
||||
// }
|
||||
return OB11Constructor.groups(groups);
|
||||
}
|
||||
}
|
||||
|
||||
export default GetGroupList
|
@@ -1,11 +1,11 @@
|
||||
import {OB11GroupMember} from '../types';
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {OB11Constructor} from "../constructor";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQUserApi} from "../../ntqqapi/api/user";
|
||||
import {log} from "../../common/utils/log";
|
||||
import {isNull} from "../../common/utils/helper";
|
||||
import {OB11GroupMember} from '../../types';
|
||||
import {getGroupMember} from "../../../common/data";
|
||||
import {OB11Constructor} from "../../constructor";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||
import {log} from "../../../common/utils/log";
|
||||
import {isNull} from "../../../common/utils/helper";
|
||||
|
||||
|
||||
export interface PayloadType {
|
||||
@@ -21,7 +21,7 @@ class GetGroupMemberInfo extends BaseAction<PayloadType, OB11GroupMember> {
|
||||
if (member) {
|
||||
if (isNull(member.sex)){
|
||||
log("获取群成员详细信息")
|
||||
let info = (await NTQQUserApi.getUserDetailInfo(member.uid))
|
||||
let info = (await NTQQUserApi.getUserDetailInfo(member.uid, true))
|
||||
log("群成员详细信息结果", info)
|
||||
Object.assign(member, info);
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
import {OB11GroupMember} from '../types';
|
||||
import {getGroup} from "../../common/data";
|
||||
import {OB11Constructor} from "../constructor";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
import {OB11GroupMember} from '../../types';
|
||||
import {getGroup} from "../../../common/data";
|
||||
import {OB11Constructor} from "../../constructor";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
|
||||
export interface PayloadType {
|
||||
group_id: number
|
@@ -1,5 +1,5 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
export default class GetGuildList extends BaseAction<null, null> {
|
||||
actionName = ActionName.GetGuildList
|
@@ -1,8 +1,8 @@
|
||||
import SendMsg from "./SendMsg";
|
||||
import {ActionName, BaseCheckResult} from "./types";
|
||||
import {OB11PostSendMsg} from "../types";
|
||||
import SendMsg from "../msg/SendMsg";
|
||||
import {ActionName, BaseCheckResult} from "../types";
|
||||
import {OB11PostSendMsg} from "../../types";
|
||||
|
||||
import {log} from "../../common/utils/log";
|
||||
import {log} from "../../../common/utils/log";
|
||||
|
||||
|
||||
class SendGroupMsg extends SendMsg {
|
@@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {GroupRequestOperateTypes} from "../../ntqqapi/types";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {GroupRequestOperateTypes} from "../../../ntqqapi/types";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
flag: string,
|
@@ -1,8 +1,8 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {GroupMemberRole} from "../../ntqqapi/types";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {getGroupMember} from "../../../common/data";
|
||||
import {GroupMemberRole} from "../../../ntqqapi/types";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
@@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {getGroupMember} from "../../../common/data";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
@@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {getGroupMember} from "../../../common/data";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
@@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {getGroupMember} from "../../../common/data";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
@@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
import {log} from "../../common/utils/log";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
import {log} from "../../../common/utils/log";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
@@ -1,6 +1,6 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
@@ -1,6 +1,6 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
@@ -1,44 +1,45 @@
|
||||
import GetMsg from './GetMsg'
|
||||
import GetLoginInfo from './GetLoginInfo'
|
||||
import GetFriendList from './GetFriendList'
|
||||
import GetGroupList from './GetGroupList'
|
||||
import GetGroupInfo from './GetGroupInfo'
|
||||
import GetGroupMemberList from './GetGroupMemberList'
|
||||
import GetGroupMemberInfo from './GetGroupMemberInfo'
|
||||
import SendGroupMsg from './SendGroupMsg'
|
||||
import SendPrivateMsg from './SendPrivateMsg'
|
||||
import SendMsg from './SendMsg'
|
||||
import DeleteMsg from "./DeleteMsg";
|
||||
import GetMsg from './msg/GetMsg'
|
||||
import GetLoginInfo from './system/GetLoginInfo'
|
||||
import GetFriendList from './user/GetFriendList'
|
||||
import GetGroupList from './group/GetGroupList'
|
||||
import GetGroupInfo from './group/GetGroupInfo'
|
||||
import GetGroupMemberList from './group/GetGroupMemberList'
|
||||
import GetGroupMemberInfo from './group/GetGroupMemberInfo'
|
||||
import SendGroupMsg from './group/SendGroupMsg'
|
||||
import SendPrivateMsg from './msg/SendPrivateMsg'
|
||||
import SendMsg from './msg/SendMsg'
|
||||
import DeleteMsg from "./msg/DeleteMsg";
|
||||
import BaseAction from "./BaseAction";
|
||||
import GetVersionInfo from "./GetVersionInfo";
|
||||
import CanSendRecord from "./CanSendRecord";
|
||||
import CanSendImage from "./CanSendImage";
|
||||
import GetStatus from "./GetStatus";
|
||||
import {GoCQHTTPSendGroupForwardMsg, GoCQHTTPSendPrivateForwardMsg} from "./go-cqhttp/SendForwardMsg";
|
||||
import GetVersionInfo from "./system/GetVersionInfo";
|
||||
import CanSendRecord from "./system/CanSendRecord";
|
||||
import CanSendImage from "./system/CanSendImage";
|
||||
import GetStatus from "./system/GetStatus";
|
||||
import {GoCQHTTPSendForwardMsg, GoCQHTTPSendGroupForwardMsg, GoCQHTTPSendPrivateForwardMsg} from "./go-cqhttp/SendForwardMsg";
|
||||
import GoCQHTTPGetStrangerInfo from "./go-cqhttp/GetStrangerInfo";
|
||||
import SendLike from "./SendLike";
|
||||
import SetGroupAddRequest from "./SetGroupAddRequest";
|
||||
import SetGroupLeave from "./SetGroupLeave";
|
||||
import GetGuildList from "./GetGuildList";
|
||||
import SendLike from "./user/SendLike";
|
||||
import SetGroupAddRequest from "./group/SetGroupAddRequest";
|
||||
import SetGroupLeave from "./group/SetGroupLeave";
|
||||
import GetGuildList from "./group/GetGuildList";
|
||||
import Debug from "./llonebot/Debug";
|
||||
import SetFriendAddRequest from "./SetFriendAddRequest";
|
||||
import SetGroupWholeBan from "./SetGroupWholeBan";
|
||||
import SetGroupName from "./SetGroupName";
|
||||
import SetGroupBan from "./SetGroupBan";
|
||||
import SetGroupKick from "./SetGroupKick";
|
||||
import SetGroupAdmin from "./SetGroupAdmin";
|
||||
import SetGroupCard from "./SetGroupCard";
|
||||
import GetImage from "./GetImage";
|
||||
import GetRecord from "./GetRecord";
|
||||
import GoCQHTTPMarkMsgAsRead from "./MarkMsgAsRead";
|
||||
import CleanCache from "./CleanCache";
|
||||
import SetFriendAddRequest from "./user/SetFriendAddRequest";
|
||||
import SetGroupWholeBan from "./group/SetGroupWholeBan";
|
||||
import SetGroupName from "./group/SetGroupName";
|
||||
import SetGroupBan from "./group/SetGroupBan";
|
||||
import SetGroupKick from "./group/SetGroupKick";
|
||||
import SetGroupAdmin from "./group/SetGroupAdmin";
|
||||
import SetGroupCard from "./group/SetGroupCard";
|
||||
import GetImage from "./file/GetImage";
|
||||
import GetRecord from "./file/GetRecord";
|
||||
import GoCQHTTPMarkMsgAsRead from "./msg/MarkMsgAsRead";
|
||||
import CleanCache from "./system/CleanCache";
|
||||
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
||||
import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
||||
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
||||
import SetQQAvatar from './llonebot/SetQQAvatar'
|
||||
import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
||||
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
||||
import GetFile from "./GetFile";
|
||||
import GetFile from "./file/GetFile";
|
||||
import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg";
|
||||
|
||||
export const actionHandlers = [
|
||||
new GetFile(),
|
||||
@@ -73,6 +74,7 @@ export const actionHandlers = [
|
||||
new CleanCache(),
|
||||
|
||||
//以下为go-cqhttp api
|
||||
new GoCQHTTPSendForwardMsg(),
|
||||
new GoCQHTTPSendGroupForwardMsg(),
|
||||
new GoCQHTTPSendPrivateForwardMsg(),
|
||||
new GoCQHTTPGetStrangerInfo(),
|
||||
@@ -81,6 +83,7 @@ export const actionHandlers = [
|
||||
new GoCQHTTPMarkMsgAsRead(),
|
||||
new GoCQHTTPUploadGroupFile(),
|
||||
new GoCQHTTPGetGroupMsgHistory(),
|
||||
new GoCQHTTGetForwardMsgAction(),
|
||||
|
||||
]
|
||||
|
||||
|
@@ -1,5 +1,14 @@
|
||||
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 {log} from "../../../common/utils/log";
|
||||
|
||||
@@ -13,8 +22,10 @@ export default class Debug extends BaseAction<Payload, any> {
|
||||
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
log("debug call ntqq api", payload);
|
||||
for (const ntqqApiClass in ntqqApi) {
|
||||
const method = ntqqApi[ntqqApiClass][payload.method]
|
||||
const ntqqApi = [NTQQMsgApi, NTQQFriendApi, NTQQGroupApi, NTQQUserApi, NTQQFileApi, NTQQFileCacheApi, NTQQWindowApi]
|
||||
for (const ntqqApiClass of ntqqApi) {
|
||||
log("ntqqApiClass", ntqqApiClass)
|
||||
const method = ntqqApiClass[payload.method]
|
||||
if (method) {
|
||||
const result = method(...payload.args);
|
||||
if (method.constructor.name === "AsyncFunction") {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import {ActionName} from "./types";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {dbUtil} from "../../common/db";
|
||||
import {NTQQMsgApi} from "../../ntqqapi/api/msg";
|
||||
import {ActionName} from "../types";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {dbUtil} from "../../../common/db";
|
||||
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||
|
||||
interface Payload {
|
||||
message_id: number
|
@@ -1,8 +1,8 @@
|
||||
import {OB11Message} from '../types';
|
||||
import {OB11Constructor} from "../constructor";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {dbUtil} from "../../common/db";
|
||||
import {OB11Message} from '../../types';
|
||||
import {OB11Constructor} from "../../constructor";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import {dbUtil} from "../../../common/db";
|
||||
|
||||
|
||||
export interface PayloadType {
|
@@ -1,5 +1,5 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
interface Payload{
|
||||
message_id: number
|
@@ -2,11 +2,11 @@ import {
|
||||
AtType,
|
||||
ChatType,
|
||||
ElementType,
|
||||
Group,
|
||||
Group, PicSubType,
|
||||
RawMessage,
|
||||
SendArkElement,
|
||||
SendMessageElement
|
||||
} from "../../ntqqapi/types";
|
||||
} from "../../../ntqqapi/types";
|
||||
import {
|
||||
friends,
|
||||
getFriend,
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
getGroupMember,
|
||||
getUidByUin,
|
||||
selfInfo,
|
||||
} from "../../common/data";
|
||||
} from "../../../common/data";
|
||||
import {
|
||||
OB11MessageCustomMusic,
|
||||
OB11MessageData,
|
||||
@@ -22,19 +22,19 @@ import {
|
||||
OB11MessageMixType,
|
||||
OB11MessageNode,
|
||||
OB11PostSendMsg
|
||||
} from '../types';
|
||||
import {Peer} from "../../ntqqapi/api/msg";
|
||||
import {SendMsgElementConstructor} from "../../ntqqapi/constructor";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName, BaseCheckResult} from "./types";
|
||||
} from '../../types';
|
||||
import {Peer} from "../../../ntqqapi/api/msg";
|
||||
import {SendMsgElementConstructor} from "../../../ntqqapi/constructor";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName, BaseCheckResult} from "../types";
|
||||
import * as fs from "node:fs";
|
||||
import {decodeCQCode} from "../cqcode";
|
||||
import {dbUtil} from "../../common/db";
|
||||
import {ALLOW_SEND_TEMP_MSG} from "../../common/config";
|
||||
import {NTQQMsgApi} from "../../ntqqapi/api/msg";
|
||||
import {log} from "../../common/utils/log";
|
||||
import {sleep} from "../../common/utils/helper";
|
||||
import {uri2local} from "../../common/utils";
|
||||
import {decodeCQCode} from "../../cqcode";
|
||||
import {dbUtil} from "../../../common/db";
|
||||
import {ALLOW_SEND_TEMP_MSG} from "../../../common/config";
|
||||
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||
import {log} from "../../../common/utils/log";
|
||||
import {sleep} from "../../../common/utils/helper";
|
||||
import {uri2local} from "../../../common/utils";
|
||||
|
||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||
function checkUri(uri: string): boolean {
|
||||
@@ -75,11 +75,156 @@ export interface ReturnDataType {
|
||||
message_id: number
|
||||
}
|
||||
|
||||
export function convertMessage2List(message: OB11MessageMixType, autoEscape = false) {
|
||||
if (typeof message === "string") {
|
||||
if (!autoEscape) {
|
||||
message = decodeCQCode(message.toString())
|
||||
} else {
|
||||
message = [{
|
||||
type: OB11MessageDataType.text,
|
||||
data: {
|
||||
text: message
|
||||
}
|
||||
}]
|
||||
}
|
||||
} else if (!Array.isArray(message)) {
|
||||
message = [message]
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
export async function createSendElements(messageData: OB11MessageData[], group: Group | undefined, ignoreTypes: OB11MessageDataType[] = []) {
|
||||
let sendElements: SendMessageElement[] = []
|
||||
let deleteAfterSentFiles: string[] = []
|
||||
for (let sendMsg of messageData) {
|
||||
if (ignoreTypes.includes(sendMsg.type)) {
|
||||
continue
|
||||
}
|
||||
switch (sendMsg.type) {
|
||||
case OB11MessageDataType.text: {
|
||||
const text = sendMsg.data?.text;
|
||||
if (text) {
|
||||
sendElements.push(SendMsgElementConstructor.text(sendMsg.data!.text))
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OB11MessageDataType.at: {
|
||||
if (!group) {
|
||||
continue
|
||||
}
|
||||
let atQQ = sendMsg.data?.qq;
|
||||
if (atQQ) {
|
||||
atQQ = atQQ.toString()
|
||||
if (atQQ === "all") {
|
||||
sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, "全体成员"))
|
||||
} else {
|
||||
// const atMember = group?.members.find(m => m.uin == atQQ)
|
||||
const atMember = await getGroupMember(group?.groupCode, atQQ);
|
||||
if (atMember) {
|
||||
sendElements.push(SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OB11MessageDataType.reply: {
|
||||
let replyMsgId = sendMsg.data.id;
|
||||
if (replyMsgId) {
|
||||
const replyMsg = await dbUtil.getMsgByShortId(parseInt(replyMsgId))
|
||||
if (replyMsg) {
|
||||
sendElements.push(SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin, replyMsg.senderUin))
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OB11MessageDataType.face: {
|
||||
const faceId = sendMsg.data?.id
|
||||
if (faceId) {
|
||||
sendElements.push(SendMsgElementConstructor.face(parseInt(faceId)))
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case OB11MessageDataType.image:
|
||||
case OB11MessageDataType.file:
|
||||
case OB11MessageDataType.video:
|
||||
case OB11MessageDataType.voice: {
|
||||
let file = sendMsg.data?.file
|
||||
const payloadFileName = sendMsg.data?.name
|
||||
if (file) {
|
||||
const cache = await dbUtil.getFileCache(file)
|
||||
if (cache) {
|
||||
if (fs.existsSync(cache.filePath)) {
|
||||
file = "file://" + cache.filePath
|
||||
} else if (cache.downloadFunc) {
|
||||
await cache.downloadFunc()
|
||||
file = cache.filePath;
|
||||
} else if (cache.url) {
|
||||
file = cache.url
|
||||
}
|
||||
log("找到文件缓存", file);
|
||||
}
|
||||
const {path, isLocal, fileName, errMsg} = (await uri2local(file))
|
||||
if (errMsg) {
|
||||
throw errMsg
|
||||
}
|
||||
if (path) {
|
||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||
deleteAfterSentFiles.push(path)
|
||||
}
|
||||
if (sendMsg.type === OB11MessageDataType.file) {
|
||||
log("发送文件", path, payloadFileName || fileName)
|
||||
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
|
||||
} else if (sendMsg.type === OB11MessageDataType.video) {
|
||||
log("发送视频", path, payloadFileName || fileName)
|
||||
let thumb = sendMsg.data?.thumb;
|
||||
if (thumb) {
|
||||
let uri2LocalRes = await uri2local(thumb)
|
||||
if (uri2LocalRes.success) {
|
||||
thumb = uri2LocalRes.path;
|
||||
}
|
||||
}
|
||||
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb));
|
||||
} else if (sendMsg.type === OB11MessageDataType.voice) {
|
||||
sendElements.push(await SendMsgElementConstructor.ptt(path));
|
||||
} else if (sendMsg.type === OB11MessageDataType.image) {
|
||||
sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || "", <PicSubType>parseInt(sendMsg.data?.subType?.toString()) || 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OB11MessageDataType.json: {
|
||||
sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data))
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
sendElements,
|
||||
deleteAfterSentFiles
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendMsg(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
||||
if (!sendElements.length) {
|
||||
throw ("消息体无法解析")
|
||||
}
|
||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
||||
log("消息发送结果", returnMsg)
|
||||
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||
}))
|
||||
return returnMsg
|
||||
}
|
||||
|
||||
export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
actionName = ActionName.SendMsg
|
||||
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
const messages = this.convertMessage2List(payload.message);
|
||||
const messages = convertMessage2List(payload.message);
|
||||
const fmNum = this.getSpecialMsgNum(payload, OB11MessageDataType.node)
|
||||
if (fmNum && fmNum != messages.length) {
|
||||
return {
|
||||
@@ -87,7 +232,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
message: "转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素"
|
||||
}
|
||||
}
|
||||
if (payload.group_id && !(await getGroup(payload.group_id))) {
|
||||
if (payload.message_type !== "private" && payload.group_id &&!(await getGroup(payload.group_id))) {
|
||||
return {
|
||||
valid: false,
|
||||
message: `群${payload.group_id}不存在`
|
||||
@@ -149,7 +294,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
} else {
|
||||
throw ("发送消息参数错误, 请指定group_id或user_id")
|
||||
}
|
||||
const messages = this.convertMessage2List(payload.message);
|
||||
const messages = convertMessage2List(payload.message);
|
||||
if (this.getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||
try {
|
||||
const returnMsg = await this.handleForwardNode(peer, messages as OB11MessageNode[], group)
|
||||
@@ -173,27 +318,13 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
}
|
||||
// log("send msg:", peer, sendElements)
|
||||
const {sendElements, deleteAfterSentFiles} = await this.createSendElements(messages, group)
|
||||
const returnMsg = await this.send(peer, sendElements, deleteAfterSentFiles)
|
||||
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}
|
||||
}
|
||||
|
||||
protected convertMessage2List(message: OB11MessageMixType) {
|
||||
if (typeof message === "string") {
|
||||
// message = [{
|
||||
// type: OB11MessageDataType.text,
|
||||
// data: {
|
||||
// text: message
|
||||
// }
|
||||
// }] as OB11MessageData[]
|
||||
message = decodeCQCode(message.toString())
|
||||
} else if (!Array.isArray(message)) {
|
||||
message = [message]
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
private getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
|
||||
if (Array.isArray(payload.message)) {
|
||||
@@ -262,7 +393,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
const {
|
||||
sendElements,
|
||||
deleteAfterSentFiles
|
||||
} = await this.createSendElements(this.convertMessage2List(messageNode.data.content), group);
|
||||
} = await createSendElements(convertMessage2List(messageNode.data.content), group);
|
||||
log("开始生成转发节点", sendElements);
|
||||
let sendElementsSplit: SendMessageElement[][] = []
|
||||
let splitIndex = 0;
|
||||
@@ -284,7 +415,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
// log("分割后的转发节点", sendElementsSplit)
|
||||
for (const eles of sendElementsSplit) {
|
||||
const nodeMsg = await this.send(selfPeer, eles, [], true);
|
||||
const nodeMsg = await sendMsg(selfPeer, eles, [], true);
|
||||
nodeMsgIds.push(nodeMsg.msgId)
|
||||
await sleep(500);
|
||||
log("转发节点生成成功", nodeMsg.msgId);
|
||||
@@ -346,130 +477,8 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
}
|
||||
|
||||
private async createSendElements(messageData: OB11MessageData[], group: Group | undefined, ignoreTypes: OB11MessageDataType[] = []) {
|
||||
let sendElements: SendMessageElement[] = []
|
||||
let deleteAfterSentFiles: string[] = []
|
||||
for (let sendMsg of messageData) {
|
||||
if (ignoreTypes.includes(sendMsg.type)) {
|
||||
continue
|
||||
}
|
||||
switch (sendMsg.type) {
|
||||
case OB11MessageDataType.text: {
|
||||
const text = sendMsg.data?.text;
|
||||
if (text) {
|
||||
sendElements.push(SendMsgElementConstructor.text(sendMsg.data!.text))
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OB11MessageDataType.at: {
|
||||
if (!group) {
|
||||
continue
|
||||
}
|
||||
let atQQ = sendMsg.data?.qq;
|
||||
if (atQQ) {
|
||||
atQQ = atQQ.toString()
|
||||
if (atQQ === "all") {
|
||||
sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, "全体成员"))
|
||||
} else {
|
||||
// const atMember = group?.members.find(m => m.uin == atQQ)
|
||||
const atMember = await getGroupMember(group?.groupCode, atQQ);
|
||||
if (atMember) {
|
||||
sendElements.push(SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OB11MessageDataType.reply: {
|
||||
let replyMsgId = sendMsg.data.id;
|
||||
if (replyMsgId) {
|
||||
const replyMsg = await dbUtil.getMsgByShortId(parseInt(replyMsgId))
|
||||
if (replyMsg) {
|
||||
sendElements.push(SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin, replyMsg.senderUin))
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OB11MessageDataType.face: {
|
||||
const faceId = sendMsg.data?.id
|
||||
if (faceId) {
|
||||
sendElements.push(SendMsgElementConstructor.face(parseInt(faceId)))
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case OB11MessageDataType.image:
|
||||
case OB11MessageDataType.file:
|
||||
case OB11MessageDataType.video:
|
||||
case OB11MessageDataType.voice: {
|
||||
let file = sendMsg.data?.file
|
||||
const payloadFileName = sendMsg.data?.name
|
||||
if (file) {
|
||||
const cache = await dbUtil.getFileCache(file)
|
||||
if (cache) {
|
||||
if (fs.existsSync(cache.filePath)) {
|
||||
file = "file://" + cache.filePath
|
||||
} else if (cache.downloadFunc) {
|
||||
await cache.downloadFunc()
|
||||
file = cache.filePath;
|
||||
} else if (cache.url) {
|
||||
file = cache.url
|
||||
}
|
||||
log("找到文件缓存", file);
|
||||
}
|
||||
const {path, isLocal, fileName, errMsg} = (await uri2local(file))
|
||||
if (errMsg) {
|
||||
throw errMsg
|
||||
}
|
||||
if (path) {
|
||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||
deleteAfterSentFiles.push(path)
|
||||
}
|
||||
if (sendMsg.type === OB11MessageDataType.file) {
|
||||
log("发送文件", path, payloadFileName || fileName)
|
||||
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
|
||||
} else if (sendMsg.type === OB11MessageDataType.video) {
|
||||
log("发送视频", path, payloadFileName || fileName)
|
||||
let thumb = sendMsg.data?.thumb;
|
||||
if (thumb){
|
||||
let uri2LocalRes = await uri2local(thumb)
|
||||
if (uri2LocalRes.success){
|
||||
thumb = uri2LocalRes.path;
|
||||
}
|
||||
}
|
||||
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb));
|
||||
} else if (sendMsg.type === OB11MessageDataType.voice) {
|
||||
sendElements.push(await SendMsgElementConstructor.ptt(path));
|
||||
}else if (sendMsg.type === OB11MessageDataType.image) {
|
||||
sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case OB11MessageDataType.json: {
|
||||
sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data))
|
||||
}break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
sendElements,
|
||||
deleteAfterSentFiles
|
||||
}
|
||||
}
|
||||
|
||||
private async send(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
||||
if (!sendElements.length) {
|
||||
throw ("消息体无法解析")
|
||||
}
|
||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
||||
log("消息发送结果", returnMsg)
|
||||
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||
}))
|
||||
return returnMsg
|
||||
}
|
||||
|
||||
private genMusicElement(url: string, audio: string, title: string, content: string, image: string): SendArkElement {
|
||||
const musicJson = {
|
@@ -1,6 +1,6 @@
|
||||
import SendMsg from "./SendMsg";
|
||||
import {ActionName, BaseCheckResult} from "./types";
|
||||
import {OB11PostSendMsg} from "../types";
|
||||
import {ActionName, BaseCheckResult} from "../types";
|
||||
import {OB11PostSendMsg} from "../../types";
|
||||
|
||||
class SendPrivateMsg extends SendMsg {
|
||||
actionName = ActionName.SendPrivateMsg
|
@@ -1,4 +1,4 @@
|
||||
import {ActionName} from "./types";
|
||||
import {ActionName} from "../types";
|
||||
import CanSendRecord from "./CanSendRecord";
|
||||
|
||||
interface ReturnType {
|
@@ -1,5 +1,5 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
interface ReturnType {
|
||||
yes: boolean
|
@@ -1,14 +1,14 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import fs from "fs";
|
||||
import Path from "path";
|
||||
import {
|
||||
ChatType,
|
||||
ChatCacheListItemBasic,
|
||||
CacheFileType
|
||||
} from '../../ntqqapi/types';
|
||||
import {dbUtil} from "../../common/db";
|
||||
import {NTQQFileApi, NTQQFileCacheApi} from "../../ntqqapi/api/file";
|
||||
} from '../../../ntqqapi/types';
|
||||
import {dbUtil} from "../../../common/db";
|
||||
import {NTQQFileApi, NTQQFileCacheApi} from "../../../ntqqapi/api/file";
|
||||
|
||||
export default class CleanCache extends BaseAction<void, void> {
|
||||
actionName = ActionName.CleanCache
|
@@ -1,8 +1,8 @@
|
||||
import {OB11User} from '../types';
|
||||
import {OB11Constructor} from "../constructor";
|
||||
import {selfInfo} from "../../common/data";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {OB11User} from '../../types';
|
||||
import {OB11Constructor} from "../../constructor";
|
||||
import {selfInfo} from "../../../common/data";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
|
||||
class GetLoginInfo extends BaseAction<null, OB11User> {
|
@@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {OB11Status} from "../types";
|
||||
import {ActionName} from "./types";
|
||||
import {selfInfo} from "../../common/data";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {OB11Status} from "../../types";
|
||||
import {ActionName} from "../types";
|
||||
import {selfInfo} from "../../../common/data";
|
||||
|
||||
|
||||
export default class GetStatus extends BaseAction<any, OB11Status> {
|
@@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {OB11Version} from "../types";
|
||||
import {ActionName} from "./types";
|
||||
import {version} from "../../version";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {OB11Version} from "../../types";
|
||||
import {ActionName} from "../types";
|
||||
import {version} from "../../../version";
|
||||
|
||||
export default class GetVersionInfo extends BaseAction<any, OB11Version> {
|
||||
actionName = ActionName.GetVersionInfo
|
@@ -51,6 +51,7 @@ export enum ActionName {
|
||||
GetRecord = "get_record",
|
||||
CleanCache = "clean_cache",
|
||||
// 以下为go-cqhttp api
|
||||
GoCQHTTP_SendForwardMsg = "send_forward_msg",
|
||||
GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg",
|
||||
GoCQHTTP_SendPrivateForwardMsg = "send_private_forward_msg",
|
||||
GoCQHTTP_GetStrangerInfo = "get_stranger_info",
|
||||
@@ -59,4 +60,5 @@ export enum ActionName {
|
||||
GoCQHTTP_UploadGroupFile = "upload_group_file",
|
||||
GoCQHTTP_DownloadFile = "download_file",
|
||||
GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history",
|
||||
GoCQHTTP_GetForwardMsg = "get_forward_msg",
|
||||
}
|
@@ -1,8 +1,8 @@
|
||||
import {OB11User} from '../types';
|
||||
import {OB11Constructor} from "../constructor";
|
||||
import {friends} from "../../common/data";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {OB11User} from '../../types';
|
||||
import {OB11Constructor} from "../../constructor";
|
||||
import {friends} from "../../../common/data";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
|
||||
class GetFriendList extends BaseAction<null, OB11User[]> {
|
@@ -1,8 +1,8 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {getFriend, getUidByUin, uidMaps} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQFriendApi} from "../../ntqqapi/api/friend";
|
||||
import {log} from "../../common/utils/log";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {getFriend, getUidByUin, uidMaps} from "../../../common/data";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQFriendApi} from "../../../ntqqapi/api/friend";
|
||||
import {log} from "../../../common/utils/log";
|
||||
|
||||
interface Payload {
|
||||
user_id: number,
|
@@ -1,6 +1,6 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQFriendApi} from "../../ntqqapi/api/friend";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQFriendApi} from "../../../ntqqapi/api/friend";
|
||||
|
||||
interface Payload {
|
||||
flag: string,
|
@@ -14,12 +14,13 @@ import {
|
||||
GrayTipElementSubType,
|
||||
Group,
|
||||
GroupMember,
|
||||
IMAGE_HTTP_HOST,
|
||||
IMAGE_HTTP_HOST, IMAGE_HTTP_HOST_NT,
|
||||
RawMessage,
|
||||
SelfInfo,
|
||||
Sex,
|
||||
TipGroupElementType,
|
||||
User
|
||||
User,
|
||||
VideoElement
|
||||
} from '../ntqqapi/types';
|
||||
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
||||
import {EventType} from "./event/OB11BaseEvent";
|
||||
@@ -35,12 +36,16 @@ import {calcQQLevel} from "../common/utils/qqlevel";
|
||||
import {log} from "../common/utils/log";
|
||||
import {sleep} from "../common/utils/helper";
|
||||
import {getConfigUtil} from "../common/config";
|
||||
import {OB11GroupTitleEvent} from "./event/notice/OB11GroupTitleEvent";
|
||||
import {OB11GroupCardEvent} from "./event/notice/OB11GroupCardEvent";
|
||||
import {OB11GroupDecreaseEvent} from "./event/notice/OB11GroupDecreaseEvent";
|
||||
|
||||
let lastRKeyUpdateTime = 0;
|
||||
|
||||
export class OB11Constructor {
|
||||
static async message(msg: RawMessage): Promise<OB11Message> {
|
||||
|
||||
const {enableLocalFile2Url, ob11: {messagePostFormat}} = getConfigUtil().getConfig()
|
||||
let config = getConfigUtil().getConfig();
|
||||
const {enableLocalFile2Url, ob11: {messagePostFormat}} = config;
|
||||
const message_type = msg.chatType == ChatType.group ? "group" : "private";
|
||||
const resMsg: OB11Message = {
|
||||
self_id: parseInt(selfInfo.uin),
|
||||
@@ -136,9 +141,30 @@ export class OB11Constructor {
|
||||
// message_data["data"]["path"] = element.picElement.sourcePath
|
||||
const url = element.picElement.originImageUrl
|
||||
const fileMd5 = element.picElement.md5HexStr
|
||||
// let currentRKey = config.imageRKey || "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
|
||||
let currentRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
|
||||
if (url) {
|
||||
message_data["data"]["url"] = IMAGE_HTTP_HOST + url
|
||||
} else if (fileMd5 && element.picElement.fileUuid.indexOf("_") === -1) { // fileuuid有下划线的是Linux发送的,这个url是另外的格式,目前尚未得知如何组装
|
||||
if (url.startsWith("/download")) {
|
||||
if (url.includes("&rkey=")) {
|
||||
// 正则提取rkey
|
||||
// const rkey = url.match(/&rkey=([^&]+)/)[1]
|
||||
// // log("图片url已有rkey", rkey)
|
||||
// if (rkey != currentRKey){
|
||||
// config.imageRKey = rkey
|
||||
// if (Date.now() - lastRKeyUpdateTime > 1000 * 60) {
|
||||
// lastRKeyUpdateTime = Date.now()
|
||||
// getConfigUtil().setConfig(config)
|
||||
// }
|
||||
// }
|
||||
message_data["data"]["url"] = IMAGE_HTTP_HOST_NT + url
|
||||
}
|
||||
else{
|
||||
message_data["data"]["url"] = IMAGE_HTTP_HOST_NT + url + "&rkey=" + currentRKey
|
||||
}
|
||||
} else {
|
||||
message_data["data"]["url"] = IMAGE_HTTP_HOST + url
|
||||
}
|
||||
} else if (fileMd5) {
|
||||
message_data["data"]["url"] = `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${fileMd5.toUpperCase()}/0`
|
||||
}
|
||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||
@@ -155,37 +181,25 @@ export class OB11Constructor {
|
||||
}).then()
|
||||
// 不在自动下载图片
|
||||
|
||||
} else if (element.videoElement) {
|
||||
message_data["type"] = OB11MessageDataType.video;
|
||||
message_data["data"]["file"] = element.videoElement.fileName
|
||||
message_data["data"]["path"] = element.videoElement.filePath
|
||||
// message_data["data"]["file_id"] = element.videoElement.fileUuid
|
||||
message_data["data"]["file_size"] = element.videoElement.fileSize
|
||||
dbUtil.addFileCache(element.videoElement.fileName, {
|
||||
fileName: element.videoElement.fileName,
|
||||
filePath: element.videoElement.filePath,
|
||||
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, {
|
||||
} else if (element.videoElement || element.fileElement) {
|
||||
const videoOrFileElement = element.videoElement || element.fileElement
|
||||
const ob11MessageDataType = element.videoElement ? OB11MessageDataType.video : OB11MessageDataType.file
|
||||
message_data["type"] = ob11MessageDataType;
|
||||
message_data["data"]["file"] = videoOrFileElement.fileName
|
||||
message_data["data"]["path"] = videoOrFileElement.filePath
|
||||
message_data["data"]["file_id"] = videoOrFileElement.fileUuid
|
||||
message_data["data"]["file_size"] = videoOrFileElement.fileSize
|
||||
dbUtil.addFileCache(videoOrFileElement.fileUuid, {
|
||||
msgId: msg.msgId,
|
||||
fileName: element.fileElement.fileName,
|
||||
fileUuid: element.fileElement.fileUuid,
|
||||
filePath: element.fileElement.filePath,
|
||||
fileSize: element.fileElement.fileSize,
|
||||
fileName: videoOrFileElement.fileName,
|
||||
filePath: videoOrFileElement.filePath,
|
||||
fileSize: videoOrFileElement.fileSize,
|
||||
downloadFunc: async () => {
|
||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
element.elementId, null, element.fileElement.filePath)
|
||||
await NTQQFileApi.downloadMedia(
|
||||
msg.msgId, msg.chatType, msg.peerUid,
|
||||
element.elementId,
|
||||
ob11MessageDataType == OB11MessageDataType.video ? (videoOrFileElement as VideoElement).thumbPath.get(0) : null,
|
||||
videoOrFileElement.filePath)
|
||||
}
|
||||
}).then()
|
||||
// 怎么拿到url呢
|
||||
@@ -213,6 +227,15 @@ export class OB11Constructor {
|
||||
} else if (element.faceElement) {
|
||||
message_data["type"] = OB11MessageDataType.face;
|
||||
message_data["data"]["id"] = element.faceElement.faceIndex.toString();
|
||||
} else if (element.marketFaceElement) {
|
||||
message_data["type"] = OB11MessageDataType.mface;
|
||||
message_data["data"]["text"] = element.marketFaceElement.faceName;
|
||||
} else if (element.markdownElement){
|
||||
message_data["type"] = OB11MessageDataType.markdown;
|
||||
message_data["data"]["data"] = element.markdownElement.content;
|
||||
} else if (element.multiForwardMsgElement){
|
||||
message_data["type"] = OB11MessageDataType.forward;
|
||||
message_data["data"]["id"] = msg.msgId
|
||||
}
|
||||
if (message_data.type !== "unknown" && message_data.data) {
|
||||
const cqCode = encodeCQCode(message_data);
|
||||
@@ -231,6 +254,14 @@ export class OB11Constructor {
|
||||
if (msg.chatType !== ChatType.group) {
|
||||
return;
|
||||
}
|
||||
if (msg.senderUin){
|
||||
let member = await getGroupMember(msg.peerUid, msg.senderUin);
|
||||
if (member && member.cardName !== msg.sendMemberName) {
|
||||
const event = new OB11GroupCardEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), msg.sendMemberName, member.cardName)
|
||||
member.cardName = msg.sendMemberName;
|
||||
return event
|
||||
}
|
||||
}
|
||||
// log("group msg", msg);
|
||||
for (let element of msg.elements) {
|
||||
const grayTipElement = element.grayTipElement
|
||||
@@ -274,11 +305,19 @@ export class OB11Constructor {
|
||||
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
||||
}
|
||||
}
|
||||
else if (groupElement.type == TipGroupElementType.kicked){
|
||||
log("收到我被踢出提示", groupElement)
|
||||
const adminUin = (await getGroupMember(msg.peerUid, groupElement.adminUid))?.uin || (await NTQQUserApi.getUserDetailInfo(groupElement.adminUid))?.uin
|
||||
if (adminUin) {
|
||||
return new OB11GroupDecreaseEvent(parseInt(msg.peerUid), parseInt(selfInfo.uin), parseInt(adminUin), "kick_me");
|
||||
}
|
||||
}
|
||||
} else if (element.fileElement) {
|
||||
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), {
|
||||
id: element.fileElement.fileUuid,
|
||||
name: element.fileElement.fileName,
|
||||
size: parseInt(element.fileElement.fileSize)
|
||||
size: parseInt(element.fileElement.fileSize),
|
||||
busid: element.fileElement.fileBizId || 0
|
||||
})
|
||||
}
|
||||
|
||||
@@ -295,11 +334,42 @@ export class OB11Constructor {
|
||||
while ((match = regex.exec(xmlElement.content)) !== null) {
|
||||
matches.push(match[1]);
|
||||
}
|
||||
// log("新人进群匹配到的QQ号", matches)
|
||||
if (matches.length === 2) {
|
||||
const [inviter, invitee] = matches;
|
||||
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
||||
}
|
||||
}
|
||||
} else if (grayTipElement.subElementType == GrayTipElementSubType.MEMBER_NEW_TITLE) {
|
||||
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr)
|
||||
/*
|
||||
{
|
||||
align: 'center',
|
||||
items: [
|
||||
{ txt: '恭喜', type: 'nor' },
|
||||
{
|
||||
col: '3',
|
||||
jp: '5',
|
||||
param: ["QQ号"],
|
||||
txt: '林雨辰',
|
||||
type: 'url'
|
||||
},
|
||||
{ txt: '获得群主授予的', type: 'nor' },
|
||||
{
|
||||
col: '3',
|
||||
jp: '',
|
||||
txt: '好好好',
|
||||
type: 'url'
|
||||
},
|
||||
{ txt: '头衔', type: 'nor' }
|
||||
]
|
||||
}
|
||||
|
||||
* */
|
||||
const memberUin = json.items[1].param[0]
|
||||
const title = json.items[3].txt
|
||||
log("收到群成员新头衔消息", json)
|
||||
return new OB11GroupTitleEvent(parseInt(msg.peerUid), parseInt(memberUin), title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
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;
|
||||
}
|
||||
}
|
@@ -1,14 +1,17 @@
|
||||
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||
|
||||
export type GroupDecreaseSubType = "leave" | "kick" | "kick_me";
|
||||
|
||||
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = "group_decrease";
|
||||
sub_type: "leave" | "kick" | "kick_me" = "leave"; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
|
||||
operate_id: number;
|
||||
sub_type: GroupDecreaseSubType = "leave"; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
|
||||
operator_id: number;
|
||||
|
||||
constructor(groupId: number, userId: number) {
|
||||
constructor(groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = "leave") {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operate_id = userId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
|
||||
this.operator_id = operatorId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
|
||||
this.user_id = userId;
|
||||
this.sub_type = subType;
|
||||
}
|
||||
}
|
||||
|
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;
|
||||
}
|
||||
}
|
@@ -3,7 +3,8 @@ import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||
export interface GroupUploadFile{
|
||||
id: string,
|
||||
name: string,
|
||||
size: number
|
||||
size: number,
|
||||
busid: number,
|
||||
}
|
||||
|
||||
export class OB11GroupUploadNoticeEvent extends OB11GroupNoticeEvent {
|
||||
|
@@ -7,7 +7,6 @@ class OB11PokeEvent extends OB11BaseNoticeEvent{
|
||||
sub_type = "poke"
|
||||
target_id = parseInt(selfInfo.uin)
|
||||
user_id: number
|
||||
|
||||
}
|
||||
|
||||
export class OB11FriendPokeEvent extends OB11PokeEvent{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import {Response} from "express";
|
||||
import {OB11Response} from "../action/utils";
|
||||
import {OB11Response} from "../action/OB11Response";
|
||||
import {HttpServerBase} from "../../common/server/http";
|
||||
import {actionHandlers} from "../action";
|
||||
import {getConfigUtil} from "../../common/config";
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import {OB11Message} from "../types";
|
||||
import {selfInfo} from "../../common/data";
|
||||
import {OB11Message, OB11MessageAt, OB11MessageData} from "../types";
|
||||
import {getGroup, selfInfo} from "../../common/data";
|
||||
import {OB11BaseMetaEvent} from "../event/meta/OB11BaseMetaEvent";
|
||||
import {OB11BaseNoticeEvent} from "../event/notice/OB11BaseNoticeEvent";
|
||||
import {WebSocket as WebSocketClass} from "ws";
|
||||
@@ -7,9 +7,47 @@ import {wsReply} from "./ws/reply";
|
||||
import {log} from "../../common/utils/log";
|
||||
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
|
||||
|
||||
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[] = [];
|
||||
|
||||
export function registerWsEventSender(ws: WebSocketClass) {
|
||||
@@ -35,7 +73,7 @@ export function postOB11Event(msg: PostEventType, reportSelf = false) {
|
||||
const config = getConfigUtil().getConfig();
|
||||
// 判断msg是否是event
|
||||
if (!config.reportSelfMessage && !reportSelf) {
|
||||
if ((msg as OB11Message).user_id.toString() == selfInfo.uin) {
|
||||
if (msg.post_type === "message" && (msg as OB11Message).user_id.toString() == selfInfo.uin) {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -56,8 +94,77 @@ export function postOB11Event(msg: PostEventType, reportSelf = false) {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: msgStr
|
||||
}).then((res: any) => {
|
||||
log(`新消息事件HTTP上报成功: ${host} ` + msgStr);
|
||||
}).then(async (res) => {
|
||||
log(`新消息事件HTTP上报成功: ${host} `, msgStr);
|
||||
// todo: 处理不够优雅,应该使用高级泛型进行QuickAction类型识别
|
||||
let resJson: QuickAction;
|
||||
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) => {
|
||||
log(`新消息事件HTTP上报失败: ${host} `, err, msg);
|
||||
});
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import {selfInfo} from "../../../common/data";
|
||||
import {LifeCycleSubType, OB11LifeCycleEvent} from "../../event/meta/OB11LifeCycleEvent";
|
||||
import {ActionName} from "../../action/types";
|
||||
import {OB11Response} from "../../action/utils";
|
||||
import {OB11Response} from "../../action/OB11Response";
|
||||
import BaseAction from "../../action/BaseAction";
|
||||
import {actionMap} from "../../action";
|
||||
import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import {WebSocket} from "ws";
|
||||
import {actionMap} from "../../action";
|
||||
import {OB11Response} from "../../action/utils";
|
||||
import {OB11Response} from "../../action/OB11Response";
|
||||
import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
||||
import {ActionName} from "../../action/types";
|
||||
import BaseAction from "../../action/BaseAction";
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import {WebSocket as WebSocketClass} from "ws";
|
||||
import {OB11Response} from "../../action/utils";
|
||||
import {OB11Response} from "../../action/OB11Response";
|
||||
import {PostEventType} from "../postOB11Event";
|
||||
import {log} from "../../../common/utils/log";
|
||||
import {isNull} from "../../../common/utils/helper";
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import {RawMessage} from "../ntqqapi/types";
|
||||
import {PicSubType, RawMessage} from "../ntqqapi/types";
|
||||
import {EventType} from "./event/OB11BaseEvent";
|
||||
|
||||
export interface OB11User {
|
||||
@@ -88,6 +88,10 @@ export interface OB11Message {
|
||||
raw?: RawMessage
|
||||
}
|
||||
|
||||
export interface OB11ForwardMessage extends OB11Message {
|
||||
content: OB11MessageData[] | string;
|
||||
}
|
||||
|
||||
export interface OB11Return<DataType> {
|
||||
status: string
|
||||
retcode: number
|
||||
@@ -108,9 +112,19 @@ export enum OB11MessageDataType {
|
||||
reply = "reply",
|
||||
json = "json",
|
||||
face = "face",
|
||||
node = "node", // 合并转发消息
|
||||
mface = "mface", // 商城表情
|
||||
markdown = "markdown",
|
||||
node = "node", // 合并转发消息节点
|
||||
forward = "forward", // 合并转发消息,用于上报
|
||||
xml = "xml"
|
||||
}
|
||||
|
||||
export interface OB11MessageMFace{
|
||||
type: OB11MessageDataType.mface,
|
||||
data: {
|
||||
text: string
|
||||
}
|
||||
}
|
||||
export interface OB11MessageText {
|
||||
type: OB11MessageDataType.text,
|
||||
data: {
|
||||
@@ -127,11 +141,13 @@ interface OB11MessageFileBase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export interface OB11MessageImage extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.image
|
||||
data: OB11MessageFileBase['data'] & {
|
||||
summary ? : string; // 图片摘要
|
||||
}
|
||||
subType?: PicSubType
|
||||
},
|
||||
}
|
||||
|
||||
export interface OB11MessageRecord extends OB11MessageFileBase {
|
||||
@@ -198,7 +214,7 @@ export interface OB11MessageJson {
|
||||
|
||||
export type OB11MessageData =
|
||||
OB11MessageText |
|
||||
OB11MessageFace |
|
||||
OB11MessageFace | OB11MessageMFace |
|
||||
OB11MessageAt | OB11MessageReply |
|
||||
OB11MessageImage | OB11MessageRecord | OB11MessageFile | OB11MessageVideo |
|
||||
OB11MessageNode | OB11MessageCustomMusic | OB11MessageJson
|
||||
|
@@ -24,8 +24,8 @@ const llonebot = {
|
||||
updateLLOneBot:async (): Promise<boolean> => {
|
||||
return ipcRenderer.invoke(CHANNEL_UPDATE);
|
||||
},
|
||||
setConfig: (config: Config) => {
|
||||
ipcRenderer.send(CHANNEL_SET_CONFIG, config);
|
||||
setConfig: (ask: boolean, config: Config) => {
|
||||
ipcRenderer.send(CHANNEL_SET_CONFIG, ask, config);
|
||||
},
|
||||
getConfig: async (): Promise<Config> => {
|
||||
return ipcRenderer.invoke(CHANNEL_GET_CONFIG);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
/// <reference path="../global.d.ts" />
|
||||
import { CheckVersion } from '../common/types';
|
||||
import {SettingButton, SettingItem, SettingList, SettingSwitch, SettingSelect} from './components';
|
||||
// @ts-ignore
|
||||
import StyleRaw from './style.css?raw';
|
||||
|
||||
// 打开设置界面时触发
|
||||
@@ -21,7 +22,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
else config[key] = value;
|
||||
|
||||
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([
|
||||
'<div>',
|
||||
`<style>${StyleRaw}</style>`,
|
||||
`<setting-section>
|
||||
<setting-panel>
|
||||
<setting-list data-direction="column" class="new">
|
||||
<setting-item data-direction="row">
|
||||
<setting-text class="llonebot-update-title">正在检查LLOneBot版本中</setting-text>
|
||||
<setting-button data-type="secondary" class="llonebot-update-button">请稍后</setting-button>
|
||||
</setting-item>
|
||||
</setting-list>
|
||||
</setting-panel>
|
||||
<setting-section>`,
|
||||
`<setting-section id="llonebot-error">
|
||||
<setting-panel><pre><code></code></pre></setting-panel>
|
||||
</setting-section>`,
|
||||
SettingList([
|
||||
'<div id="llonebot-error" class="llonebot-error"></div>',
|
||||
SettingItem(
|
||||
'<span id="llonebot-update-title">正在检查 LLOneBot 更新</span>', null,
|
||||
SettingButton('请稍候', 'llonebot-update-button', 'secondary'),
|
||||
),
|
||||
]),
|
||||
SettingList([
|
||||
SettingItem('启用 HTTP 服务', null,
|
||||
@@ -98,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>`,
|
||||
),
|
||||
SettingItem(
|
||||
'启用CQ码上报格式,不启用则为消息段格式',
|
||||
'新消息上报格式',
|
||||
'如客户端无特殊需求推荐保持默认设置,两者的详细差异可参考 <a href="javascript:LiteLoader.api.openExternal(\'https://github.com/botuniverse/onebot-11/tree/master/message#readme\');">OneBot v11 文档</a>',
|
||||
SettingSelect([
|
||||
{text: '消息段', value: 'array'},
|
||||
@@ -122,7 +119,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
),
|
||||
SettingItem(
|
||||
'使用 Base64 编码获取文件',
|
||||
'开启后,调用 /get_image、/get_record 时,获取不到 url 时添加一个 Base64 字段',
|
||||
'调用 /get_image、/get_record、/get_file 时,没有 url 时添加 Base64 字段',
|
||||
SettingSwitch('enableLocalFile2Url', config.enableLocalFile2Url),
|
||||
),
|
||||
SettingItem(
|
||||
@@ -153,7 +150,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
),
|
||||
SettingItem(
|
||||
'日志文件目录',
|
||||
`${window.LiteLoader.plugins['LLOneBot'].path.data}`,
|
||||
`${window.LiteLoader.plugins['LLOneBot'].path.data}/logs`,
|
||||
SettingButton('打开', 'config-open-log-path'),
|
||||
),
|
||||
]),
|
||||
@@ -182,18 +179,20 @@ async function onSettingWindowCreated(view: Element) {
|
||||
'</div>',
|
||||
].join(''), "text/html");
|
||||
|
||||
let errorEle = <HTMLElement>doc.querySelector("#llonebot-error");
|
||||
errorEle.style.display = 'none';
|
||||
const showError = async () => {
|
||||
setTimeout(async () => {
|
||||
let errMessage = await window.llonebot.getError();
|
||||
console.log(errMessage)
|
||||
errMessage = errMessage.replace(/\n/g, '<br>')
|
||||
errorEle.innerHTML = errMessage;
|
||||
errorEle.style.display = errMessage ? 'flex' : 'none';
|
||||
}, 1000)
|
||||
await (new Promise((res) => setTimeout(() => res(true), 1000)));
|
||||
|
||||
const errDom = doc.querySelector('#llonebot-error');
|
||||
const errCodeDom = errDom.querySelector('code');
|
||||
const errMsg = await window.llonebot.getError();
|
||||
|
||||
if (!errMsg) return;
|
||||
|
||||
errDom.classList.add('show');
|
||||
errCodeDom.innerHTML = errMsg;
|
||||
}
|
||||
showError().then()
|
||||
showError().then();
|
||||
|
||||
// 外链按钮
|
||||
doc.querySelector('#open-github').addEventListener('click', () => {
|
||||
window.LiteLoader.api.openExternal('https://github.com/LLOneBot/LLOneBot')
|
||||
@@ -324,7 +323,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
doc.querySelector('#config-ob11-save').addEventListener('click', () => {
|
||||
config.ob11 = ob11Config;
|
||||
|
||||
window.llonebot.setConfig(config);
|
||||
window.llonebot.setConfig(false, config);
|
||||
// window.location.reload();
|
||||
showError().then()
|
||||
alert('保存成功');
|
||||
@@ -335,36 +334,47 @@ async function onSettingWindowCreated(view: Element) {
|
||||
});
|
||||
// 更新逻辑
|
||||
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 === "") {
|
||||
view.querySelector(".llonebot-update-title").innerHTML = "检查更新失败";
|
||||
view.querySelector(".llonebot-update-button").innerHTML = "点击重试";
|
||||
view.querySelector(".llonebot-update-button").addEventListener("click", async () => {
|
||||
titleDom.innerHTML = "检查更新失败";
|
||||
buttonDom.innerHTML = "点击重试";
|
||||
|
||||
buttonDom.addEventListener("click", async () => {
|
||||
window.llonebot.checkVersion().then(checkVersionFunc);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
if (!ResultVersion.result) {
|
||||
view.querySelector(".llonebot-update-title").innerHTML = "当前已是最新版本 V" + ResultVersion.version;
|
||||
view.querySelector(".llonebot-update-button").innerHTML = "无需更新";
|
||||
titleDom.innerHTML = "当前已是最新版本 v" + ResultVersion.version;
|
||||
buttonDom.innerHTML = "无需更新";
|
||||
} else {
|
||||
view.querySelector(".llonebot-update-title").innerHTML = "已检测到最新版本 V" + ResultVersion.version;
|
||||
view.querySelector(".llonebot-update-button").innerHTML = "点击更新";
|
||||
titleDom.innerHTML = "已检测到最新版本 v" + ResultVersion.version;
|
||||
buttonDom.innerHTML = "点击更新";
|
||||
buttonDom.dataset.type = 'primary';
|
||||
|
||||
const update = async () => {
|
||||
view.querySelector(".llonebot-update-button").innerHTML = "正在更新中...";
|
||||
buttonDom.innerHTML = "正在更新中...";
|
||||
const result = await window.llonebot.updateLLOneBot();
|
||||
if (result) {
|
||||
view.querySelector(".llonebot-update-button").innerHTML = "更新完成请重启";
|
||||
view.querySelector(".llonebot-update-button").removeEventListener("click", update);
|
||||
buttonDom.innerHTML = "更新完成,请重启";
|
||||
} else {
|
||||
view.querySelector(".llonebot-update-button").innerHTML = "更新失败前往仓库下载";
|
||||
view.querySelector(".llonebot-update-button").removeEventListener("click", update);
|
||||
buttonDom.innerHTML = "更新失败,前往仓库下载";
|
||||
}
|
||||
|
||||
buttonDom.removeEventListener("click", update);
|
||||
}
|
||||
view.querySelector(".llonebot-update-button").addEventListener("click", update);
|
||||
buttonDom.addEventListener("click", update);
|
||||
}
|
||||
};
|
||||
}
|
||||
window.llonebot.checkVersion().then(checkVersionFunc);
|
||||
window.addEventListener('beforeunload', (event) => {
|
||||
if (JSON.stringify(ob11Config) === JSON.stringify(config.ob11)) return;
|
||||
config.ob11 = ob11Config;
|
||||
window.llonebot.setConfig(true, config);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
@@ -157,9 +157,24 @@ ob-setting-select::part(option-list) {
|
||||
}
|
||||
|
||||
#llonebot-error {
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
overflow: visible;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#llonebot-error setting-panel {
|
||||
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.18.0"
|
||||
export const version = "3.20.3"
|
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