mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
79090d764f | ||
![]() |
6ab0cd7f4b | ||
![]() |
bb3bce203d | ||
![]() |
36f7f1b026 | ||
![]() |
5a0dbdb5ce | ||
![]() |
48d62be2d6 | ||
![]() |
b314e2f3a0 | ||
![]() |
63b9204a4b | ||
![]() |
bf701c2110 | ||
![]() |
95b4b11f02 | ||
![]() |
1735babb7d | ||
![]() |
89c3f07cba | ||
![]() |
5cf45a452b | ||
![]() |
23d5fa7218 | ||
![]() |
983d2462d4 | ||
![]() |
3c68bc77ce | ||
![]() |
501211fb57 | ||
![]() |
0cd41a8a52 | ||
![]() |
d339a778df | ||
![]() |
dc843f77a3 | ||
![]() |
b103f2015c | ||
![]() |
baf35d5496 | ||
![]() |
5c34afc228 | ||
![]() |
a8a6290b70 | ||
![]() |
9d50c6d4fd | ||
![]() |
175a8ceb3d | ||
![]() |
31601981f2 | ||
![]() |
6a8c5ec24a | ||
![]() |
ebca6a07c5 | ||
![]() |
4f9345e4e5 | ||
![]() |
ac17dbefe0 | ||
![]() |
c9486b4f55 | ||
![]() |
35951fd61a | ||
![]() |
fdc23d7721 | ||
![]() |
560428a5f9 |
20
.github/ISSUE_TEMPLATE/bug_report.md
vendored
20
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,20 +0,0 @@
|
||||
---
|
||||
name: Bug反馈
|
||||
about: 报个Bug
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
QQ版本:
|
||||
|
||||
LLOneBot版本:
|
||||
|
||||
调用LLOneBot的方式或者应用端(如postman直接调用,或NoneBot2、Koishi):
|
||||
|
||||
BUG描述:
|
||||
|
||||
复现步骤:
|
||||
|
||||
LLOneBot日志:
|
81
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
81
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
name: Bug 反馈
|
||||
description: 报告可能的 LLOneBot 异常行为
|
||||
title: '[BUG] '
|
||||
labels: bug
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
欢迎来到 LLOneBot 的 Issue Tracker!请填写以下表格来提交 Bug。
|
||||
在提交新的 Bug 反馈前,请确保您:
|
||||
* 已经搜索了现有的 issues,并且没有找到可以解决您问题的方法
|
||||
* 不与现有的某一 issue 重复
|
||||
- type: input
|
||||
id: system-version
|
||||
attributes:
|
||||
label: 系统版本
|
||||
description: 运行 QQNT 的系统版本
|
||||
placeholder: Windows 10 Pro Workstation 22H2
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: qqnt-version
|
||||
attributes:
|
||||
label: QQNT 版本
|
||||
description: 可在 QQNT 的「关于」或是在 LiteLoaderQQNT 的设置页中找到
|
||||
placeholder: 9.9.7-21804
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: llonebot-version
|
||||
attributes:
|
||||
label: LLOneBot 版本
|
||||
description: 可在 LiteLoaderQQNT 的设置页或是 QQNT 的设置页侧栏中找到
|
||||
placeholder: 3.18.0
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: onebot-client-version
|
||||
attributes:
|
||||
label: OneBot 客户端
|
||||
description: 连接至 LLOneBot 的客户端版本信息
|
||||
placeholder: Overflow 2.16.0-2cf7991-SNAPSHOT
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: 发生了什么?
|
||||
description: 填写你认为的 LLOneBot 的不正常行为
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: how-reproduce
|
||||
attributes:
|
||||
label: 如何复现
|
||||
description: 填写应当如何操作才能触发这个不正常行为
|
||||
placeholder: |
|
||||
1. xxx
|
||||
2. xxx
|
||||
3. xxx
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: what-expected
|
||||
attributes:
|
||||
label: 期望的结果?
|
||||
description: 填写你认为 LLOneBot 应当执行的正常行为
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: llonebot-log
|
||||
attributes:
|
||||
label: LLOneBot 运行日志
|
||||
description: 在 LLOneBot 的设置页中打开「写入日志」然后粘贴相关日志内容到此处
|
||||
render: shell
|
||||
- type: textarea
|
||||
id: onebot-client-log
|
||||
attributes:
|
||||
label: OneBot 客户端运行日志
|
||||
description: 粘贴 OneBot 客户端的相关日志内容到此处
|
||||
render: shell
|
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"manifest_version": 4,
|
||||
"type": "extension",
|
||||
"name": "LLOneBot v3.17.0",
|
||||
"name": "LLOneBot v3.19.0",
|
||||
"slug": "LLOneBot",
|
||||
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
||||
"version": "3.17.0",
|
||||
"version": "3.19.0",
|
||||
"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.3",
|
||||
"silk-wasm": "^3.3.3",
|
||||
"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.3",
|
||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.2.3.tgz",
|
||||
"integrity": "sha512-zZ3hgMpiPR6cFnKvCPgPpCwx6n5RoJCbEGIFlge2kAxAmgzBTf0b2F2xIPG5W4obUhQPQXXTTH074eGZJK01xw=="
|
||||
"version": "3.3.3",
|
||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.3.3.tgz",
|
||||
"integrity": "sha512-9Qj93EtiIuBNkDyEwlPntabEtrm6Xu6LE4y9qZvomvo5+IsXFcXSy+N55kV22OehUTBYlZqOZYtRggA8G9IDGg=="
|
||||
},
|
||||
"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.3",
|
||||
"silk-wasm": "^3.3.3",
|
||||
"utf-8-validate": "^6.0.3",
|
||||
"uuid": "^9.0.1",
|
||||
"ws": "^8.16.0"
|
||||
|
@@ -30,6 +30,7 @@ export class ConfigUtil {
|
||||
let ob11Default: OB11Config = {
|
||||
httpPort: 3000,
|
||||
httpHosts: [],
|
||||
httpSecret: "",
|
||||
wsPort: 3001,
|
||||
wsHosts: [],
|
||||
enableHttp: true,
|
||||
|
@@ -1,6 +1,7 @@
|
||||
export interface OB11Config {
|
||||
httpPort: number
|
||||
httpHosts: string[]
|
||||
httpSecret?: string
|
||||
wsPort: number
|
||||
wsHosts: string[]
|
||||
enableHttp?: boolean
|
||||
|
137
src/common/utils/audio.ts
Normal file
137
src/common/utils/audio.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
import fs from "fs";
|
||||
import {encode, getDuration, getWavFileInfo, isWav} from "silk-wasm";
|
||||
import fsPromise from "fs/promises";
|
||||
import {log} from "./log";
|
||||
import path from "node:path";
|
||||
import {DATA_DIR, TEMP_DIR} from "./index";
|
||||
import {v4 as uuidv4} from "uuid";
|
||||
import {getConfigUtil} from "../config";
|
||||
import ffmpeg from "fluent-ffmpeg";
|
||||
|
||||
export async function encodeSilk(filePath: string) {
|
||||
function getFileHeader(filePath: string) {
|
||||
// 定义要读取的字节数
|
||||
const bytesToRead = 7;
|
||||
try {
|
||||
const buffer = fs.readFileSync(filePath, {
|
||||
encoding: null,
|
||||
flag: "r",
|
||||
});
|
||||
|
||||
const fileHeader = buffer.toString("hex", 0, bytesToRead);
|
||||
return fileHeader;
|
||||
} catch (err) {
|
||||
console.error("读取文件错误:", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async function isWavFile(filePath: string) {
|
||||
return isWav(fs.readFileSync(filePath));
|
||||
}
|
||||
|
||||
async function guessDuration(pttPath: string) {
|
||||
const pttFileInfo = await fsPromise.stat(pttPath)
|
||||
let duration = pttFileInfo.size / 1024 / 3 // 3kb/s
|
||||
duration = Math.floor(duration)
|
||||
duration = Math.max(1, duration)
|
||||
log(`通过文件大小估算语音的时长:`, duration)
|
||||
return duration
|
||||
}
|
||||
|
||||
// function verifyDuration(oriDuration: number, guessDuration: number) {
|
||||
// // 单位都是秒
|
||||
// if (oriDuration - guessDuration > 10) {
|
||||
// return guessDuration
|
||||
// }
|
||||
// oriDuration = Math.max(1, oriDuration)
|
||||
// return oriDuration
|
||||
// }
|
||||
// async function getAudioSampleRate(filePath: string) {
|
||||
// try {
|
||||
// const mm = await import('music-metadata');
|
||||
// const metadata = await mm.parseFile(filePath);
|
||||
// log(`${filePath}采样率`, metadata.format.sampleRate);
|
||||
// return metadata.format.sampleRate;
|
||||
// } catch (error) {
|
||||
// log(`${filePath}采样率获取失败`, error.stack);
|
||||
// // console.error(error);
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
const pttPath = path.join(TEMP_DIR, uuidv4());
|
||||
if (getFileHeader(filePath) !== "02232153494c4b") {
|
||||
log(`语音文件${filePath}需要转换成silk`)
|
||||
const _isWav = await isWavFile(filePath);
|
||||
const wavPath = pttPath + ".wav"
|
||||
const convert = async () => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
const ffmpegPath = getConfigUtil().getConfig().ffmpeg;
|
||||
if (ffmpegPath) {
|
||||
ffmpeg.setFfmpegPath(ffmpegPath);
|
||||
}
|
||||
ffmpeg(filePath).toFormat("wav")
|
||||
.audioChannels(1)
|
||||
.audioFrequency(24000)
|
||||
.on('end', function () {
|
||||
log('wav转换完成');
|
||||
})
|
||||
.on('error', function (err) {
|
||||
log(`wav转换出错: `, err.message,);
|
||||
reject(err);
|
||||
})
|
||||
.save(wavPath)
|
||||
.on("end", () => {
|
||||
filePath = wavPath
|
||||
resolve(wavPath);
|
||||
});
|
||||
})
|
||||
}
|
||||
let wav: Buffer
|
||||
if (!_isWav) {
|
||||
log(`语音文件${filePath}正在转换成wav`)
|
||||
await convert()
|
||||
} else {
|
||||
wav = fs.readFileSync(filePath)
|
||||
const allowSampleRate = [8000, 12000, 16000, 24000, 32000, 44100, 48000]
|
||||
const {fmt} = getWavFileInfo(wav)
|
||||
// log(`wav文件信息`, fmt)
|
||||
if (!allowSampleRate.includes(fmt.sampleRate)) {
|
||||
wav = undefined
|
||||
await convert()
|
||||
}
|
||||
}
|
||||
wav ||= fs.readFileSync(filePath);
|
||||
const silk = await encode(wav, 0);
|
||||
fs.writeFileSync(pttPath, silk.data);
|
||||
fs.unlink(wavPath, (err) => {
|
||||
});
|
||||
// const gDuration = await guessDuration(pttPath)
|
||||
log(`语音文件${filePath}转换成功!`, pttPath, `时长:`, silk.duration)
|
||||
return {
|
||||
converted: true,
|
||||
path: pttPath,
|
||||
duration: silk.duration / 1000
|
||||
};
|
||||
} else {
|
||||
const silk = fs.readFileSync(filePath);
|
||||
let duration = 0;
|
||||
try {
|
||||
duration = getDuration(silk) / 1000
|
||||
} catch (e) {
|
||||
log("获取语音文件时长失败, 使用文件大小推测时长", filePath, e.stack)
|
||||
duration = await guessDuration(filePath);
|
||||
}
|
||||
|
||||
return {
|
||||
converted: false,
|
||||
path: filePath,
|
||||
duration: duration,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
log("convert silk failed", error.stack);
|
||||
return {};
|
||||
}
|
||||
}
|
@@ -1,17 +1,13 @@
|
||||
import fs from "fs";
|
||||
import 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,109 +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 getAudioSampleRate(filePath: string) {
|
||||
// try {
|
||||
// const mm = await import('music-metadata');
|
||||
// const metadata = await mm.parseFile(filePath);
|
||||
// log(`${filePath}采样率`, metadata.format.sampleRate);
|
||||
// return metadata.format.sampleRate;
|
||||
// } catch (error) {
|
||||
// log(`${filePath}采样率获取失败`, error.stack);
|
||||
// // console.error(error);
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
const fileName = path.basename(filePath);
|
||||
const pttPath = path.join(DATA_DIR, uuidv4());
|
||||
if (getFileHeader(filePath) !== "02232153494c4b") {
|
||||
log(`语音文件${filePath}需要转换成silk`)
|
||||
const _isWav = await isWavFile(filePath);
|
||||
const wavPath = pttPath + ".wav"
|
||||
if (!_isWav) {
|
||||
log(`语音文件${filePath}正在转换成wav`)
|
||||
// let voiceData = await fsp.readFile(filePath)
|
||||
await new Promise((resolve, reject) => {
|
||||
const ffmpegPath = getConfigUtil().getConfig().ffmpeg;
|
||||
if (ffmpegPath) {
|
||||
ffmpeg.setFfmpegPath(ffmpegPath);
|
||||
}
|
||||
ffmpeg(filePath).toFormat("wav").audioChannels(2).on('end', function () {
|
||||
log('wav转换完成');
|
||||
})
|
||||
.on('error', function (err) {
|
||||
log(`wav转换出错: `, err.message,);
|
||||
reject(err);
|
||||
})
|
||||
.save(wavPath)
|
||||
.on("end", () => {
|
||||
filePath = wavPath
|
||||
resolve(wavPath);
|
||||
});
|
||||
})
|
||||
}
|
||||
// const sampleRate = await getAudioSampleRate(filePath) || 0;
|
||||
// log("音频采样率", sampleRate)
|
||||
const pcm = fs.readFileSync(filePath);
|
||||
const silk = await encode(pcm, 0);
|
||||
fs.writeFileSync(pttPath, silk.data);
|
||||
fs.unlink(wavPath, (err) => {
|
||||
});
|
||||
log(`语音文件${filePath}转换成功!`, pttPath)
|
||||
return {
|
||||
converted: true,
|
||||
path: pttPath,
|
||||
duration: silk.duration,
|
||||
};
|
||||
} else {
|
||||
const pcm = fs.readFileSync(filePath);
|
||||
let duration = 0;
|
||||
try {
|
||||
duration = getDuration(pcm);
|
||||
} catch (e) {
|
||||
log("获取语音文件时长失败", filePath, e.stack)
|
||||
duration = fs.statSync(filePath).size / 1024 / 3 // 每3kb大约1s
|
||||
duration = Math.floor(duration)
|
||||
duration = Math.max(1, duration)
|
||||
log("使用文件大小估算时长", duration)
|
||||
}
|
||||
|
||||
return {
|
||||
converted: false,
|
||||
path: filePath,
|
||||
duration: duration,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
log("convert silk failed", error.stack);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function calculateFileMD5(filePath: string): Promise<string> {
|
||||
@@ -271,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
|
||||
}
|
||||
|
@@ -11,7 +11,8 @@ export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
||||
export const TEMP_DIR = path.join(DATA_DIR, "temp");
|
||||
export const PLUGIN_DIR = global.LiteLoader.plugins["LLOneBot"].path.plugin;
|
||||
if (!fs.existsSync(TEMP_DIR)) {
|
||||
fs.mkdirSync(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"
|
@@ -49,11 +49,13 @@ import {checkFfmpeg} from "../common/utils/video";
|
||||
|
||||
let running = false;
|
||||
|
||||
let mainWindow: BrowserWindow | null = null;
|
||||
|
||||
// 加载插件时触发
|
||||
function onLoad() {
|
||||
log("llonebot main onLoad");
|
||||
ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => {
|
||||
|
||||
return checkNewVersion();
|
||||
});
|
||||
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
|
||||
@@ -105,8 +107,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 +218,6 @@ function onLoad() {
|
||||
parseInt(operatorId),
|
||||
oriMessage.msgShortId
|
||||
)
|
||||
|
||||
postOB11Event(groupRecallEvent);
|
||||
}
|
||||
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
||||
@@ -370,24 +389,29 @@ function onLoad() {
|
||||
selfInfo.nick = selfInfo.uin;
|
||||
} catch (e) {
|
||||
log("retry get self info", e);
|
||||
selfInfo.uin = globalThis.authData?.uin;
|
||||
selfInfo.uid = globalThis.authData?.uid;
|
||||
selfInfo.nick = selfInfo.uin;
|
||||
}
|
||||
log("self info", selfInfo);
|
||||
log("self info", selfInfo, globalThis.authData);
|
||||
if (selfInfo.uin) {
|
||||
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 +426,7 @@ function onBrowserWindowCreated(window: BrowserWindow) {
|
||||
if (selfInfo.uid) {
|
||||
return
|
||||
}
|
||||
mainWindow = window;
|
||||
log("window create", window.webContents.getURL().toString())
|
||||
try {
|
||||
hookNTQQApiCall(window);
|
||||
@@ -417,6 +442,7 @@ try {
|
||||
console.log(e.toString())
|
||||
}
|
||||
|
||||
|
||||
// 这两个函数都是可选的
|
||||
export {
|
||||
onBrowserWindowCreated
|
||||
|
@@ -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";
|
||||
|
@@ -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
|
||||
|
||||
@@ -25,7 +26,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,6 +2,7 @@ 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";
|
||||
|
||||
|
||||
export class NTQQUserApi{
|
||||
@@ -53,4 +54,50 @@ export class NTQQUserApi{
|
||||
return info
|
||||
}
|
||||
|
||||
static async getPSkey() {
|
||||
return await callNTQQApi<string>({
|
||||
className: NTQQApiClass.GROUP_HOME_WORK,
|
||||
methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||
args: [
|
||||
{
|
||||
domain: "qun.qq.com"
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
static async getSkey(groupName: string, groupCode: string): Promise<{data: string}> {
|
||||
return await NTQQWindowApi.openWindow<{data: string}>(NTQQWindows.GroupHomeWorkWindow, [{
|
||||
groupName,
|
||||
groupCode,
|
||||
"source": "funcbar"
|
||||
}], ReceiveCmdS.SKEY_UPDATE, 1);
|
||||
// return await callNTQQApi<string>({
|
||||
// className: NTQQApiClass.GROUP_HOME_WORK,
|
||||
// methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||
// args: [
|
||||
// {
|
||||
// domain: "qun.qq.com"
|
||||
// }
|
||||
// ]
|
||||
// })
|
||||
// return await callNTQQApi<GeneralCallResult>({
|
||||
// methodName: NTQQApiMethod.GET_SKEY,
|
||||
// args: [
|
||||
// {
|
||||
// "domains": [
|
||||
// "qzone.qq.com",
|
||||
// "qlive.qq.com",
|
||||
// "qun.qq.com",
|
||||
// "gamecenter.qq.com",
|
||||
// "vip.qq.com",
|
||||
// "qianbao.qq.com",
|
||||
// "qidian.qq.com"
|
||||
// ],
|
||||
// "isForNewPCQQ": false
|
||||
// },
|
||||
// null
|
||||
// ]
|
||||
// })
|
||||
}
|
||||
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
import {net, session} from "electron";
|
||||
import {NTQQApi} from "../ntcall";
|
||||
import {groups} from "../../common/data";
|
||||
import {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 {
|
||||
@@ -211,7 +212,7 @@ export class SendMsgElementConstructor {
|
||||
md5HexStr: md5,
|
||||
fileSize: fileSize,
|
||||
// duration: Math.max(1, Math.round(fileSize / 1024 / 3)), // 一秒钟大概是3kb大小, 小于1秒的按1秒算
|
||||
duration: duration / 1000,
|
||||
duration: duration,
|
||||
formatType: 1,
|
||||
voiceType: 1,
|
||||
voiceChangeType: 0,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import {BrowserWindow} from 'electron';
|
||||
import {NTQQApiClass} from "./ntcall";
|
||||
import {NTQQMsgApi, sendMessagePool} from "./api/msg"
|
||||
import {ChatType, Group, RawMessage, User} from "./types";
|
||||
import {ChatType, Group, GroupMember, RawMessage, User} from "./types";
|
||||
import {friends, groups, selfInfo, tempGroupCodeMap, uidMaps} from "../common/data";
|
||||
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
||||
import {v4 as uuidv4} from "uuid"
|
||||
@@ -12,6 +12,7 @@ import {dbUtil} from "../common/db";
|
||||
import {NTQQGroupApi} from "./api/group";
|
||||
import {log} from "../common/utils/log";
|
||||
import {sleep} from "../common/utils/helper";
|
||||
import {OB11GroupCardEvent} from "../onebot11/event/notice/OB11GroupCardEvent";
|
||||
|
||||
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
||||
|
||||
@@ -25,6 +26,7 @@ export let ReceiveCmdS = {
|
||||
USER_DETAIL_INFO: "nodeIKernelProfileListener/onProfileDetailInfoChanged",
|
||||
GROUPS: "nodeIKernelGroupListener/onGroupListUpdate",
|
||||
GROUPS_UNIX: "onGroupListUpdate",
|
||||
GROUP_MEMBER_INFO_UPDATE: "nodeIKernelGroupListener/onMemberInfoChange",
|
||||
FRIENDS: "onBuddyListChange",
|
||||
MEDIA_DOWNLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaDownloadComplete",
|
||||
UNREAD_GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated",
|
||||
@@ -192,7 +194,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,12 +223,13 @@ 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) {
|
||||
const oldMembers = existGroup.members;
|
||||
|
||||
@@ -242,39 +245,50 @@ async function processGroupEvent(payload) {
|
||||
|
||||
for (const member of oldMembers) {
|
||||
if (!newMembersSet.has(member.uin)) {
|
||||
postOB11Event(new OB11GroupDecreaseEvent(group.groupCode, parseInt(member.uin)));
|
||||
postOB11Event(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin)));
|
||||
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) => {
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>([ReceiveCmdS.GROUPS, ReceiveCmdS.GROUPS_UNIX], (payload) => {
|
||||
log("群列表变动", payload)
|
||||
if (payload.updateType != 2) {
|
||||
updateGroups(payload.groupList).then();
|
||||
} else {
|
||||
if (process.platform == "win32") {
|
||||
processGroupEvent(payload).then();
|
||||
}
|
||||
processGroupEvent(payload).then();
|
||||
}
|
||||
})
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS_UNIX, (payload) => {
|
||||
if (payload.updateType != 2) {
|
||||
updateGroups(payload.groupList).then();
|
||||
} else {
|
||||
if (process.platform != "win32") {
|
||||
processGroupEvent(payload).then();
|
||||
}
|
||||
}
|
||||
|
||||
registerReceiveHook<{groupCode: string, dataSource: number, members: Set<GroupMember>}>(ReceiveCmdS.GROUP_MEMBER_INFO_UPDATE, (payload) => {
|
||||
const groupCode = payload.groupCode;
|
||||
const members = Array.from(payload.members.values());
|
||||
// log("群成员变动", groupCode, payload.members.keys(), payload.members.values())
|
||||
// const existGroup = groups.find(g => g.groupCode == groupCode);
|
||||
// if (existGroup) {
|
||||
// log("对比群成员", existGroup.members, members)
|
||||
// for (const member of members) {
|
||||
// const existMember = existGroup.members.find(m => m.uin == member.uin);
|
||||
// if (existMember) {
|
||||
// log("对比群名片", existMember.cardName, member.cardName)
|
||||
// if (existMember.cardName != member.cardName) {
|
||||
// postOB11Event(new OB11GroupCardEvent(parseInt(existGroup.groupCode), parseInt(member.uin), member.cardName, existMember.cardName));
|
||||
// }
|
||||
// Object.assign(existMember, member);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
})
|
||||
|
||||
// 好友列表变动
|
||||
|
@@ -23,7 +23,8 @@ 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",
|
||||
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
||||
SELF_INFO = "fetchAuthData",
|
||||
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
||||
@@ -117,7 +118,7 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
||||
}
|
||||
const apiArgs = [methodName, ...args]
|
||||
if (!cbCmd) {
|
||||
// QQ后端会返回结果,并且可以插根据uuid识别
|
||||
// QQ后端会返回结果,并且可以根据uuid识别
|
||||
hookApiCallbacks[uuid] = (r: ReturnType) => {
|
||||
success = true
|
||||
resolve(r)
|
||||
@@ -185,59 +186,4 @@ export class NTQQApi {
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static async getSkey(groupName: string, groupCode: string): Promise<{data: string}> {
|
||||
return await NTQQWindowApi.openWindow<{data: string}>(NTQQWindows.GroupHomeWorkWindow, [{
|
||||
groupName,
|
||||
groupCode,
|
||||
"source": "funcbar"
|
||||
}], ReceiveCmdS.SKEY_UPDATE, 1);
|
||||
// return await callNTQQApi<string>({
|
||||
// className: NTQQApiClass.GROUP_HOME_WORK,
|
||||
// methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||
// args: [
|
||||
// {
|
||||
// domain: "qun.qq.com"
|
||||
// }
|
||||
// ]
|
||||
// })
|
||||
// return await callNTQQApi<GeneralCallResult>({
|
||||
// methodName: NTQQApiMethod.GET_SKEY,
|
||||
// args: [
|
||||
// {
|
||||
// "domains": [
|
||||
// "qzone.qq.com",
|
||||
// "qlive.qq.com",
|
||||
// "qun.qq.com",
|
||||
// "gamecenter.qq.com",
|
||||
// "vip.qq.com",
|
||||
// "qianbao.qq.com",
|
||||
// "qidian.qq.com"
|
||||
// ],
|
||||
// "isForNewPCQQ": false
|
||||
// },
|
||||
// null
|
||||
// ]
|
||||
// })
|
||||
}
|
||||
|
||||
static async getPSkey() {
|
||||
return await callNTQQApi<string>({
|
||||
className: NTQQApiClass.GROUP_HOME_WORK,
|
||||
methodName: NTQQApiMethod.UPDATE_SKEY,
|
||||
args: [
|
||||
{
|
||||
domain: "qun.qq.com"
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static async addGroupDigest(groupCode: string, msgSeq: string) {
|
||||
return await new WebApi().addGroupDigest(groupCode, msgSeq);
|
||||
}
|
||||
|
||||
static async getGroupDigest(groupCode: string) {
|
||||
return await new WebApi().getGroupDigest(groupCode);
|
||||
}
|
||||
}
|
@@ -180,6 +180,7 @@ export interface PicElement {
|
||||
|
||||
export enum GrayTipElementSubType {
|
||||
INVITE_NEW_MEMBER = 12,
|
||||
MEMBER_NEW_TITLE = 17
|
||||
}
|
||||
|
||||
export interface GrayTipElement {
|
||||
@@ -196,6 +197,9 @@ export interface GrayTipElement {
|
||||
groupElement: TipGroupElement,
|
||||
xmlElement: {
|
||||
content: string;
|
||||
},
|
||||
jsonGrayTipElement:{
|
||||
jsonStr: string;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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,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'
|
@@ -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}
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
import SendMsg from "../SendMsg";
|
||||
import SendMsg from "../msg/SendMsg";
|
||||
import {OB11PostSendMsg} from "../../types";
|
||||
import {ActionName} from "../types";
|
||||
|
||||
@@ -6,7 +6,9 @@ export class GoCQHTTPSendGroupForwardMsg extends SendMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||
|
||||
protected async check(payload: OB11PostSendMsg) {
|
||||
payload.message = this.convertMessage2List(payload.messages);
|
||||
if (payload.messages){
|
||||
payload.message = this.convertMessage2List(payload.messages);
|
||||
}
|
||||
return super.check(payload);
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
@@ -1,8 +1,8 @@
|
||||
import {OB11Group} from '../types';
|
||||
import {OB11Constructor} from "../constructor";
|
||||
import {groups} from "../../common/data";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
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[]> {
|
@@ -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 {
|
@@ -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,
|
||||
@@ -16,8 +16,9 @@ export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const seq = payload.flag.toString();
|
||||
const approve = payload.approve.toString() === "true";
|
||||
await NTQQGroupApi.handleGroupRequest(seq,
|
||||
payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||
payload.reason
|
||||
)
|
||||
return null
|
@@ -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,
|
||||
@@ -15,10 +15,11 @@ export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||
const enable = payload.enable.toString() === "true"
|
||||
if (!member) {
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), member.uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
||||
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), member.uid, enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
||||
return null
|
||||
}
|
||||
}
|
@@ -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,
|
||||
@@ -11,8 +11,8 @@ export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupWholeBan
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
await NTQQGroupApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
||||
const enable = payload.enable.toString() === "true"
|
||||
await NTQQGroupApi.banGroup(payload.group_id.toString(), enable)
|
||||
return null
|
||||
}
|
||||
}
|
@@ -1,44 +1,44 @@
|
||||
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 GetVersionInfo from "./system/GetVersionInfo";
|
||||
import CanSendRecord from "./system/CanSendRecord";
|
||||
import CanSendImage from "./system/CanSendImage";
|
||||
import GetStatus from "./system/GetStatus";
|
||||
import {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";
|
||||
|
||||
export const actionHandlers = [
|
||||
new GetFile(),
|
||||
|
@@ -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
|
@@ -6,7 +6,7 @@ import {
|
||||
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 || ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
@@ -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
|
@@ -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,
|
||||
@@ -12,7 +12,8 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetFriendAddRequest;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
await NTQQFriendApi.handleFriendRequest(parseInt(payload.flag), payload.approve)
|
||||
const approve = payload.approve.toString() === "true";
|
||||
await NTQQFriendApi.handleFriendRequest(parseInt(payload.flag), approve)
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -19,7 +19,7 @@ import {
|
||||
SelfInfo,
|
||||
Sex,
|
||||
TipGroupElementType,
|
||||
User
|
||||
User, VideoElement
|
||||
} from '../ntqqapi/types';
|
||||
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
||||
import {EventType} from "./event/OB11BaseEvent";
|
||||
@@ -35,6 +35,8 @@ import {calcQQLevel} from "../common/utils/qqlevel";
|
||||
import {log} from "../common/utils/log";
|
||||
import {sleep} from "../common/utils/helper";
|
||||
import {getConfigUtil} from "../common/config";
|
||||
import {OB11GroupTitleEvent} from "./event/notice/OB11GroupTitleEvent";
|
||||
import {OB11GroupCardEvent} from "./event/notice/OB11GroupCardEvent";
|
||||
|
||||
|
||||
export class OB11Constructor {
|
||||
@@ -155,37 +157,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呢
|
||||
@@ -231,6 +221,13 @@ 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) {
|
||||
member.cardName = msg.sendMemberName;
|
||||
return new OB11GroupCardEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), msg.sendMemberName, member.cardName)
|
||||
}
|
||||
}
|
||||
// log("group msg", msg);
|
||||
for (let element of msg.elements) {
|
||||
const grayTipElement = element.grayTipElement
|
||||
@@ -300,6 +297,36 @@ export class OB11Constructor {
|
||||
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
||||
}
|
||||
}
|
||||
} else if (grayTipElement.subElementType == GrayTipElementSubType.MEMBER_NEW_TITLE) {
|
||||
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr)
|
||||
/*
|
||||
{
|
||||
align: 'center',
|
||||
items: [
|
||||
{ txt: '恭喜', type: 'nor' },
|
||||
{
|
||||
col: '3',
|
||||
jp: '5',
|
||||
param: ["QQ号"],
|
||||
txt: '林雨辰',
|
||||
type: 'url'
|
||||
},
|
||||
{ txt: '获得群主授予的', type: 'nor' },
|
||||
{
|
||||
col: '3',
|
||||
jp: '',
|
||||
txt: '好好好',
|
||||
type: 'url'
|
||||
},
|
||||
{ txt: '头衔', type: 'nor' }
|
||||
]
|
||||
}
|
||||
|
||||
* */
|
||||
const memberUin = json.items[1].param[0]
|
||||
const title = json.items[3].txt
|
||||
log("收到群成员新头衔消息", json)
|
||||
return new OB11GroupTitleEvent(parseInt(msg.peerUid), parseInt(memberUin), title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
src/onebot11/event/notice/OB11GroupCardEvent.ts
Normal file
16
src/onebot11/event/notice/OB11GroupCardEvent.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||
|
||||
export class OB11GroupCardEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = "group_card";
|
||||
card_new: string;
|
||||
card_old: string;
|
||||
|
||||
|
||||
constructor(groupId: number, userId: number, cardNew: string, cardOld: string) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.card_new = cardNew;
|
||||
this.card_old = cardOld;
|
||||
}
|
||||
}
|
15
src/onebot11/event/notice/OB11GroupTitleEvent.ts
Normal file
15
src/onebot11/event/notice/OB11GroupTitleEvent.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||
|
||||
export class OB11GroupTitleEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = "notify";
|
||||
sub_type = "title";
|
||||
title: string
|
||||
|
||||
|
||||
constructor(groupId: number, userId: number, title: string) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.title = title;
|
||||
}
|
||||
}
|
@@ -7,7 +7,6 @@ class OB11PokeEvent extends OB11BaseNoticeEvent{
|
||||
sub_type = "poke"
|
||||
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,14 +1,53 @@
|
||||
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";
|
||||
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) {
|
||||
@@ -39,18 +78,95 @@ export function postOB11Event(msg: PostEventType, reportSelf = false) {
|
||||
}
|
||||
}
|
||||
if (config.ob11.enableHttpPost) {
|
||||
const msgStr = JSON.stringify(msg);
|
||||
const hmac = crypto.createHmac('sha1', config.ob11.httpSecret);
|
||||
hmac.update(msgStr);
|
||||
const sig = hmac.digest('hex');
|
||||
let headers = {
|
||||
"Content-Type": "application/json",
|
||||
"x-self-id": selfInfo.uin
|
||||
}
|
||||
if (config.ob11.httpSecret) {
|
||||
headers["x-signature"] = "sha1=" + sig;
|
||||
}
|
||||
for (const host of config.ob11.httpHosts) {
|
||||
fetch(host, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-self-id": selfInfo.uin
|
||||
},
|
||||
body: JSON.stringify(msg)
|
||||
}).then((res: any) => {
|
||||
log(`新消息事件HTTP上报成功: ${host} ` + JSON.stringify(msg));
|
||||
headers,
|
||||
body: 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 + JSON.stringify(msg));
|
||||
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";
|
||||
|
@@ -108,6 +108,7 @@ export enum OB11MessageDataType {
|
||||
reply = "reply",
|
||||
json = "json",
|
||||
face = "face",
|
||||
mface = "face", // 商城表情
|
||||
node = "node", // 合并转发消息
|
||||
}
|
||||
|
||||
|
@@ -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,
|
||||
@@ -55,6 +52,14 @@ async function onSettingWindowCreated(view: Element) {
|
||||
SettingSwitch('ob11.enableHttpPost', config.ob11.enableHttpPost, {'control-display-id': 'config-ob11-httpHosts'}),
|
||||
),
|
||||
`<div class="config-host-list" id="config-ob11-httpHosts" ${config.ob11.enableHttpPost ? '' : 'is-hidden'}>
|
||||
<setting-item data-direction="row">
|
||||
<div>
|
||||
<setting-text>HTTP 事件上报密钥</setting-text>
|
||||
</div>
|
||||
<div class="q-input">
|
||||
<input id="config-ob11-httpSecret" class="q-input__inner" data-config-key="ob11.httpSecret" type="text" value="${config.ob11.httpSecret}" placeholder="未设置" />
|
||||
</div>
|
||||
</setting-item>
|
||||
<setting-item data-direction="row">
|
||||
<div>
|
||||
<setting-text>HTTP 事件上报地址</setting-text>
|
||||
@@ -90,7 +95,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="token" type="text" value="${config.token}" placeholder="未设置" /></div>`,
|
||||
),
|
||||
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'},
|
||||
@@ -114,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(
|
||||
@@ -174,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')
|
||||
@@ -316,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('保存成功');
|
||||
@@ -327,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.17.0"
|
||||
export const version = "3.19.0"
|
29
test/quick_action/server.py
Normal file
29
test/quick_action/server.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import uvicorn
|
||||
from fastapi import FastAPI, Request
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.post("/")
|
||||
async def root(request: Request):
|
||||
data = await request.json()
|
||||
print(data)
|
||||
if (data["post_type"] == "message"):
|
||||
text = list(filter(lambda x: x["type"] == "text", data["message"]))[0]["data"]["text"]
|
||||
if text == "禁言":
|
||||
return {"ban": True, "ban_duration": 10}
|
||||
elif text == "踢我":
|
||||
return {"kick": True}
|
||||
elif text == "撤回":
|
||||
return {"delete": True}
|
||||
# print(data["message"])
|
||||
return {"reply": "[CQ:at,qq=]Hello World", "auto_escape": True}
|
||||
elif data["post_type"] == "request":
|
||||
if data["request_type"] == "group":
|
||||
return {"approve": False, "reason": "不让你进群"}
|
||||
else:
|
||||
# 加好友
|
||||
return {"approve": True}
|
||||
return {}
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app, host="", port=8000)
|
Reference in New Issue
Block a user