mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
712f0a8256 | ||
![]() |
a93220f9d2 | ||
![]() |
253cee7458 | ||
![]() |
82f9a4c63f | ||
![]() |
de6c8a5558 | ||
![]() |
c75337b8cb | ||
![]() |
2b796e33fe | ||
![]() |
175307d980 | ||
![]() |
993f8a9e8f | ||
![]() |
0130b8f6f7 | ||
![]() |
ba482d492f | ||
![]() |
6e71cd6064 | ||
![]() |
83dc1abd4a | ||
![]() |
4cabb9696e | ||
![]() |
75883e9cae | ||
![]() |
eeadaa12e9 | ||
![]() |
192736c8be | ||
![]() |
586fbb6518 |
15
README.md
15
README.md
@@ -29,17 +29,24 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
- [x] 群管理功能,禁言、踢人,改群名片等
|
||||
- [x] 视频消息
|
||||
- [x] 文件消息
|
||||
- [x] 群禁言事件上报
|
||||
- [x] 优化加群成功事件上报
|
||||
- [x] 清理缓存api
|
||||
- [ ] 无头模式
|
||||
- [ ] 群禁言事件上报
|
||||
- [ ] 优化加群成功事件上报
|
||||
- [ ] 清理缓存api
|
||||
- [ ] 框架对接文档
|
||||
|
||||
## onebot11文档
|
||||
<https://11.onebot.dev/>
|
||||
|
||||
## Stargazers over time
|
||||
[](https://starchart.cc/LLOneBot/LLOneBot)
|
||||
|
||||
|
||||
## 鸣谢
|
||||
* [LiteLoaderQQNT](https://liteloaderqqnt.github.io/guide/install.html)
|
||||
* [LLAPI](https://github.com/Night-stars-1/LiteLoaderQQNT-Plugin-LLAPI)
|
||||
* chronocat
|
||||
* [chronocat](https://github.com/chrononeko/chronocat/)
|
||||
* [koishi-plugin-adapter-onebot](https://github.com/koishijs/koishi-plugin-adapter-onebot)
|
||||
|
||||
## 友链
|
||||
* [Lagrange.Core](https://github.com/LagrangeDev/Lagrange.Core)(一款用C#实现的NTQQ纯协议跨平台QQ机器人框架)
|
||||
|
@@ -28,7 +28,9 @@ let config = {
|
||||
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg'
|
||||
},
|
||||
},
|
||||
plugins: [cp({ targets: [...external.map(genCpModule), { src: './manifest.json', dest: 'dist' }] })]
|
||||
plugins: [cp({ targets: [...external.map(genCpModule),
|
||||
{ src: './manifest.json', dest: 'dist' }, {src: './icon.jpg', dest: 'dist' }]
|
||||
})]
|
||||
},
|
||||
preload: {
|
||||
// vite config options
|
||||
|
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"manifest_version": 4,
|
||||
"type": "extension",
|
||||
"name": "LLOneBot v3.13.10",
|
||||
"name": "LLOneBot v3.14.1",
|
||||
"slug": "LLOneBot",
|
||||
"description": "LiteLoaderQQNT的OneBotApi",
|
||||
"version": "3.13.10",
|
||||
"thumbnail": "./icon.png",
|
||||
"version": "3.14.1",
|
||||
"icon": "./icon.jpg",
|
||||
"authors": [
|
||||
{
|
||||
"name": "linyuchen",
|
||||
|
17
scripts/test/test_db.ts
Normal file
17
scripts/test/test_db.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import {Level} from "level"
|
||||
|
||||
const db = new Level(process.env["level_db_path"], {valueEncoding: 'json'});
|
||||
|
||||
async function getGroupNotify() {
|
||||
let keys = await db.keys().all();
|
||||
let result = []
|
||||
for (const key of keys) {
|
||||
// console.log(key)
|
||||
if (key.startsWith("group_notify_")) {
|
||||
result.push(key)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
getGroupNotify().then(console.log)
|
@@ -21,7 +21,6 @@ export const selfInfo: SelfInfo = {
|
||||
}
|
||||
export let groups: Group[] = []
|
||||
export let friends: Friend[] = []
|
||||
export let groupNotifies: Map<string, GroupNotify> = new Map<string, GroupNotify>()
|
||||
export let friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>()
|
||||
export const llonebotError: LLOneBotError = {
|
||||
ffmpegError: '',
|
||||
|
137
src/common/db.ts
137
src/common/db.ts
@@ -1,17 +1,18 @@
|
||||
import {Level} from "level";
|
||||
import {RawMessage} from "../ntqqapi/types";
|
||||
import {type GroupNotify, RawMessage} from "../ntqqapi/types";
|
||||
import {DATA_DIR, log} from "./utils";
|
||||
import {selfInfo} from "./data";
|
||||
import {FileCache} from "./types";
|
||||
|
||||
|
||||
class DBUtil {
|
||||
private readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
||||
private readonly DB_KEY_PREFIX_MSG_SHORT_ID = "msg_short_id_";
|
||||
private readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
||||
private readonly DB_KEY_PREFIX_FILE = "file_";
|
||||
private db: Level;
|
||||
public cache: Record<string, RawMessage | string | FileCache> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
||||
public readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
||||
public readonly DB_KEY_PREFIX_MSG_SHORT_ID = "msg_short_id_";
|
||||
public readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
||||
public readonly DB_KEY_PREFIX_FILE = "file_";
|
||||
public readonly DB_KEY_PREFIX_GROUP_NOTIFY = "group_notify_";
|
||||
public db: Level;
|
||||
public cache: Record<string, RawMessage | string | FileCache | GroupNotify> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
||||
private currentShortId: number;
|
||||
|
||||
/*
|
||||
@@ -47,9 +48,23 @@ class DBUtil {
|
||||
}
|
||||
initDB();
|
||||
}).then()
|
||||
|
||||
const expiredMilliSecond = 1000 * 60 * 60;
|
||||
|
||||
setInterval(() => {
|
||||
this.cache = {}
|
||||
}, 1000 * 60 * 10)
|
||||
// this.cache = {}
|
||||
// 清理时间较久的缓存
|
||||
const now = Date.now()
|
||||
for (let key in this.cache) {
|
||||
let message: RawMessage = this.cache[key] as RawMessage;
|
||||
if (message?.msgTime){
|
||||
if ((now - (parseInt(message.msgTime) * 1000)) > expiredMilliSecond) {
|
||||
delete this.cache[key]
|
||||
// log("clear cache", key, message.msgTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, expiredMilliSecond)
|
||||
}
|
||||
|
||||
private addCache(msg: RawMessage) {
|
||||
@@ -59,15 +74,24 @@ class DBUtil {
|
||||
this.cache[longIdKey] = this.cache[shortIdKey] = msg
|
||||
}
|
||||
|
||||
public clearCache() {
|
||||
this.cache = {}
|
||||
}
|
||||
|
||||
async getMsgByShortId(shortMsgId: number): Promise<RawMessage> {
|
||||
const shortMsgIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
||||
if (this.cache[shortMsgIdKey]) {
|
||||
// log("getMsgByShortId cache", shortMsgIdKey, this.cache[shortMsgIdKey])
|
||||
return this.cache[shortMsgIdKey] as RawMessage
|
||||
}
|
||||
const longId = await this.db.get(shortMsgIdKey);
|
||||
const msg = await this.getMsgByLongId(longId)
|
||||
this.addCache(msg)
|
||||
return msg
|
||||
try {
|
||||
const longId = await this.db.get(shortMsgIdKey);
|
||||
const msg = await this.getMsgByLongId(longId)
|
||||
this.addCache(msg)
|
||||
return msg
|
||||
} catch (e) {
|
||||
log("getMsgByShortId db error", e.stack.toString())
|
||||
}
|
||||
}
|
||||
|
||||
async getMsgByLongId(longId: string): Promise<RawMessage> {
|
||||
@@ -75,10 +99,14 @@ class DBUtil {
|
||||
if (this.cache[longIdKey]) {
|
||||
return this.cache[longIdKey] as RawMessage
|
||||
}
|
||||
const data = await this.db.get(longIdKey)
|
||||
const msg = JSON.parse(data)
|
||||
this.addCache(msg)
|
||||
return msg
|
||||
try {
|
||||
const data = await this.db.get(longIdKey)
|
||||
const msg = JSON.parse(data)
|
||||
this.addCache(msg)
|
||||
return msg
|
||||
} catch (e) {
|
||||
// log("getMsgByLongId db error", e.stack.toString())
|
||||
}
|
||||
}
|
||||
|
||||
async getMsgBySeqId(seqId: string): Promise<RawMessage> {
|
||||
@@ -86,10 +114,14 @@ class DBUtil {
|
||||
if (this.cache[seqIdKey]) {
|
||||
return this.cache[seqIdKey] as RawMessage
|
||||
}
|
||||
const longId = await this.db.get(seqIdKey);
|
||||
const msg = await this.getMsgByLongId(longId)
|
||||
this.addCache(msg)
|
||||
return msg
|
||||
try {
|
||||
const longId = await this.db.get(seqIdKey);
|
||||
const msg = await this.getMsgByLongId(longId)
|
||||
this.addCache(msg)
|
||||
return msg
|
||||
} catch (e) {
|
||||
log("getMsgBySeqId db error", e.stack.toString())
|
||||
}
|
||||
}
|
||||
|
||||
async addMsg(msg: RawMessage) {
|
||||
@@ -110,28 +142,25 @@ class DBUtil {
|
||||
return existMsg.msgShortId
|
||||
}
|
||||
this.addCache(msg);
|
||||
// log("新增消息记录", msg.msgId)
|
||||
|
||||
const shortMsgId = await this.genMsgShortId();
|
||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
||||
msg.msgShortId = shortMsgId;
|
||||
// log("新增消息记录", msg.msgId)
|
||||
this.db.put(shortIdKey, msg.msgId).then().catch();
|
||||
this.db.put(longIdKey, JSON.stringify(msg)).then().catch();
|
||||
try {
|
||||
this.db.put(shortIdKey, msg.msgId).then();
|
||||
this.db.put(longIdKey, JSON.stringify(msg)).then();
|
||||
try {
|
||||
await this.db.get(seqIdKey)
|
||||
} catch (e) {
|
||||
// log("新的seqId", seqIdKey)
|
||||
this.db.put(seqIdKey, msg.msgId).then();
|
||||
}
|
||||
if (!this.cache[seqIdKey]) {
|
||||
this.cache[seqIdKey] = msg;
|
||||
}
|
||||
// log(`消息入库 ${seqIdKey}: ${msg.msgId}, ${shortMsgId}: ${msg.msgId}`);
|
||||
await this.db.get(seqIdKey)
|
||||
} catch (e) {
|
||||
// log("addMsg db error", e.stack.toString());
|
||||
// log("新的seqId", seqIdKey)
|
||||
this.db.put(seqIdKey, msg.msgId).then().catch();
|
||||
}
|
||||
if (!this.cache[seqIdKey]) {
|
||||
this.cache[seqIdKey] = msg;
|
||||
}
|
||||
return shortMsgId
|
||||
// log(`消息入库 ${seqIdKey}: ${msg.msgId}, ${shortMsgId}: ${msg.msgId}`);
|
||||
}
|
||||
|
||||
async updateMsg(msg: RawMessage) {
|
||||
@@ -146,17 +175,17 @@ class DBUtil {
|
||||
}
|
||||
|
||||
Object.assign(existMsg, msg)
|
||||
this.db.put(longIdKey, JSON.stringify(existMsg)).then();
|
||||
this.db.put(longIdKey, JSON.stringify(existMsg)).then().catch();
|
||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + existMsg.msgShortId;
|
||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
||||
if (!this.cache[seqIdKey]) {
|
||||
this.cache[seqIdKey] = existMsg;
|
||||
}
|
||||
this.db.put(shortIdKey, msg.msgId).then();
|
||||
this.db.put(shortIdKey, msg.msgId).then().catch();
|
||||
try {
|
||||
await this.db.get(seqIdKey)
|
||||
} catch (e) {
|
||||
this.db.put(seqIdKey, msg.msgId).then();
|
||||
this.db.put(seqIdKey, msg.msgId).then().catch();
|
||||
// log("更新seqId error", e.stack, seqIdKey);
|
||||
}
|
||||
// log("更新消息", existMsg.msgSeq, existMsg.msgShortId, existMsg.msgId);
|
||||
@@ -175,7 +204,7 @@ class DBUtil {
|
||||
}
|
||||
|
||||
this.currentShortId++;
|
||||
await this.db.put(key, this.currentShortId.toString());
|
||||
this.db.put(key, this.currentShortId.toString()).then().catch();
|
||||
return this.currentShortId;
|
||||
}
|
||||
|
||||
@@ -187,7 +216,11 @@ class DBUtil {
|
||||
let cacheDBData = {...data}
|
||||
delete cacheDBData['downloadFunc']
|
||||
this.cache[fileName] = data;
|
||||
await this.db.put(key, JSON.stringify(cacheDBData));
|
||||
try {
|
||||
await this.db.put(key, JSON.stringify(cacheDBData));
|
||||
} catch (e) {
|
||||
log("addFileCache db error", e.stack.toString())
|
||||
}
|
||||
}
|
||||
|
||||
async getFileCache(fileName: string): Promise<FileCache | undefined> {
|
||||
@@ -196,11 +229,33 @@ class DBUtil {
|
||||
return this.cache[key] as FileCache
|
||||
}
|
||||
try {
|
||||
|
||||
let data = await this.db.get(key);
|
||||
return JSON.parse(data);
|
||||
} catch (e) {
|
||||
// log("getFileCache db error", e.stack.toString())
|
||||
}
|
||||
}
|
||||
|
||||
async addGroupNotify(notify: GroupNotify) {
|
||||
const key = this.DB_KEY_PREFIX_GROUP_NOTIFY + notify.seq;
|
||||
let existNotify = this.cache[key] as GroupNotify
|
||||
if (existNotify) {
|
||||
return
|
||||
}
|
||||
this.cache[key] = notify;
|
||||
this.db.put(key, JSON.stringify(notify)).then().catch();
|
||||
}
|
||||
|
||||
async getGroupNotify(seq: string): Promise<GroupNotify | undefined> {
|
||||
const key = this.DB_KEY_PREFIX_GROUP_NOTIFY + seq;
|
||||
if (this.cache[key]) {
|
||||
return this.cache[key] as GroupNotify
|
||||
}
|
||||
try {
|
||||
let data = await this.db.get(key);
|
||||
return JSON.parse(data);
|
||||
} catch (e) {
|
||||
// log("getGroupNotify db error", e.stack.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,8 +11,21 @@ export abstract class HttpServerBase {
|
||||
|
||||
constructor() {
|
||||
this.expressAPP = express();
|
||||
this.expressAPP.use(express.urlencoded({extended: true, limit: "500mb"}));
|
||||
this.expressAPP.use(json({limit: "500mb"}));
|
||||
this.expressAPP.use(express.urlencoded({extended: true, limit: "5000mb"}));
|
||||
this.expressAPP.use((req, res, next) => {
|
||||
// 兼容处理没有带content-type的请求
|
||||
// log("req.headers['content-type']", req.headers['content-type'])
|
||||
req.headers['content-type'] = 'application/json';
|
||||
const originalJson = express.json({limit: "5000mb"});
|
||||
// 调用原始的express.json()处理器
|
||||
originalJson(req, res, (err) => {
|
||||
if (err) {
|
||||
log("Error parsing JSON:", err);
|
||||
return res.status(400).send("Invalid JSON");
|
||||
}
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
authorize(req: Request, res: Response, next: () => void) {
|
||||
|
@@ -4,6 +4,7 @@ import {ConfigUtil} from "./config";
|
||||
import util from "util";
|
||||
import {encode, getDuration, isWav} from "silk-wasm";
|
||||
import fs from 'fs';
|
||||
import * as crypto from 'crypto';
|
||||
import {v4 as uuidv4} from "uuid";
|
||||
import ffmpeg from "fluent-ffmpeg"
|
||||
|
||||
@@ -234,9 +235,9 @@ export async function encodeSilk(filePath: string) {
|
||||
} else {
|
||||
const pcm = fs.readFileSync(filePath);
|
||||
let duration = 0;
|
||||
try{
|
||||
try {
|
||||
duration = getDuration(pcm);
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
log("获取语音文件时长失败", filePath, e.stack)
|
||||
duration = fs.statSync(filePath).size / 1024 / 3 // 每3kb大约1s
|
||||
duration = Math.floor(duration)
|
||||
@@ -256,6 +257,80 @@ export async function encodeSilk(filePath: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getVideoInfo(filePath: string) {
|
||||
const size = fs.statSync(filePath).size;
|
||||
return new Promise<{ width: number, height: number, time: number, format: string, size: number, filePath: string }>((resolve, reject) => {
|
||||
ffmpeg.ffprobe(filePath, (err, metadata) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
const videoStream = metadata.streams.find(s => s.codec_type === 'video');
|
||||
if (videoStream) {
|
||||
console.log(`视频尺寸: ${videoStream.width}x${videoStream.height}`);
|
||||
} else {
|
||||
console.log('未找到视频流信息。');
|
||||
}
|
||||
resolve({
|
||||
width: videoStream.width, height: videoStream.height,
|
||||
time: parseInt(videoStream.duration),
|
||||
format: metadata.format.format_name,
|
||||
size,
|
||||
filePath
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export async function encodeMp4(filePath: string) {
|
||||
let videoInfo = await getVideoInfo(filePath);
|
||||
log("视频信息", videoInfo)
|
||||
if (videoInfo.format.indexOf("mp4") === -1) {
|
||||
log("视频需要转换为MP4格式", filePath)
|
||||
// 转成mp4
|
||||
const newPath: string = await new Promise<string>((resolve, reject) => {
|
||||
const newPath = filePath + ".mp4"
|
||||
ffmpeg(filePath)
|
||||
.toFormat('mp4')
|
||||
.on('error', (err) => {
|
||||
reject(`转换视频格式失败: ${err.message}`);
|
||||
})
|
||||
.on('end', () => {
|
||||
log('视频转换为MP4格式完成');
|
||||
resolve(newPath); // 返回转换后的文件路径
|
||||
})
|
||||
.save(newPath);
|
||||
});
|
||||
return await getVideoInfo(newPath)
|
||||
}
|
||||
return videoInfo
|
||||
}
|
||||
|
||||
export function isNull(value: any) {
|
||||
return value === undefined || value === null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function calculateFileMD5(filePath: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 创建一个流式读取器
|
||||
const stream = fs.createReadStream(filePath);
|
||||
const hash = crypto.createHash('md5');
|
||||
|
||||
stream.on('data', (data: Buffer) => {
|
||||
// 当读取到数据时,更新哈希对象的状态
|
||||
hash.update(data);
|
||||
});
|
||||
|
||||
stream.on('end', () => {
|
||||
// 文件读取完成,计算哈希
|
||||
const md5 = hash.digest('hex');
|
||||
resolve(md5);
|
||||
});
|
||||
|
||||
stream.on('error', (err: Error) => {
|
||||
// 处理可能的读取错误
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@ import {
|
||||
friendRequests, getFriend,
|
||||
getGroup,
|
||||
getGroupMember,
|
||||
groupNotifies,
|
||||
llonebotError, refreshGroupMembers,
|
||||
selfInfo
|
||||
} from "../common/data";
|
||||
@@ -152,9 +151,19 @@ function onLoad() {
|
||||
log(arg);
|
||||
})
|
||||
|
||||
let postedMsgIds: Record<string, any> = {}
|
||||
async function postReceiveMsg(msgList: RawMessage[]) {
|
||||
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
||||
for (let message of msgList) {
|
||||
if (postedMsgIds[message.msgId]) { // 如果QQ开启了独立窗口,会导致消息重复上报,这里加个记录避免重复上报
|
||||
continue
|
||||
}
|
||||
postedMsgIds[message.msgId] = true
|
||||
// 超过容量清空
|
||||
if (Object.keys(postedMsgIds).length > 10000) {
|
||||
postedMsgIds = {}
|
||||
}
|
||||
|
||||
// log("收到新消息", message.msgId, message.msgSeq)
|
||||
// if (message.senderUin !== selfInfo.uin){
|
||||
message.msgShortId = await dbUtil.addMsg(message);
|
||||
@@ -171,6 +180,12 @@ function onLoad() {
|
||||
postOB11Event(msg);
|
||||
// log("post msg", msg)
|
||||
}).catch(e => log("constructMessage error: ", e.stack.toString()));
|
||||
OB11Constructor.GroupEvent(message).then(groupEvent=>{
|
||||
if (groupEvent){
|
||||
// log("post group event", groupEvent);
|
||||
postOB11Event(groupEvent);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,19 +266,17 @@ function onLoad() {
|
||||
for (const notify of notifies) {
|
||||
try {
|
||||
notify.time = Date.now();
|
||||
const notifyTime = parseInt(notify.seq) / 1000
|
||||
// const notifyTime = parseInt(notify.seq) / 1000
|
||||
// log(`加群通知时间${notifyTime}`, `LLOneBot启动时间${startTime}`);
|
||||
// if (notifyTime < startTime) {
|
||||
// continue;
|
||||
// }
|
||||
let existNotify = groupNotifies[notify.seq];
|
||||
let existNotify = await dbUtil.getGroupNotify(notify.seq);
|
||||
if (existNotify) {
|
||||
if (Date.now() - existNotify.time < 3000) {
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
log("收到群通知", notify);
|
||||
groupNotifies[notify.seq] = notify;
|
||||
await dbUtil.addGroupNotify(notify);
|
||||
// let member2: GroupMember;
|
||||
// if (notify.user2.uid) {
|
||||
// member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
|
||||
|
@@ -1,16 +1,20 @@
|
||||
import {
|
||||
AtType,
|
||||
ElementType, PicType, SendArkElement,
|
||||
ElementType,
|
||||
PicType,
|
||||
SendArkElement,
|
||||
SendFaceElement,
|
||||
SendFileElement,
|
||||
SendPicElement,
|
||||
SendPttElement,
|
||||
SendReplyElement,
|
||||
SendTextElement
|
||||
SendTextElement,
|
||||
SendVideoElement
|
||||
} from "./types";
|
||||
import {NTQQApi} from "./ntcall";
|
||||
import {encodeSilk, isGIF} from "../common/utils";
|
||||
import * as fs from "node:fs";
|
||||
import {calculateFileMD5, encodeSilk, getVideoInfo, isGIF, log, sleep} from "../common/utils";
|
||||
import {promises as fs} from "node:fs";
|
||||
import ffmpeg from "fluent-ffmpeg"
|
||||
|
||||
|
||||
export class SendMsgElementConstructor {
|
||||
@@ -57,7 +61,7 @@ export class SendMsgElementConstructor {
|
||||
|
||||
static async pic(picPath: string): Promise<SendPicElement> {
|
||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(picPath, ElementType.PIC);
|
||||
if (fileSize === 0){
|
||||
if (fileSize === 0) {
|
||||
throw "文件异常,大小为0";
|
||||
}
|
||||
const imageSize = await NTQQApi.getImageSize(picPath);
|
||||
@@ -84,15 +88,9 @@ export class SendMsgElementConstructor {
|
||||
};
|
||||
}
|
||||
|
||||
static async file(filePath: string, showPreview: boolean = false, fileName: string = ""): Promise<SendFileElement> {
|
||||
let picHeight = 0;
|
||||
let picWidth = 0;
|
||||
if (showPreview) {
|
||||
picHeight = 1024;
|
||||
picWidth = 768;
|
||||
}
|
||||
static async file(filePath: string, fileName: string = ""): Promise<SendFileElement> {
|
||||
const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE);
|
||||
if (fileSize === 0){
|
||||
if (fileSize === 0) {
|
||||
throw "文件异常,大小为0";
|
||||
}
|
||||
let element: SendFileElement = {
|
||||
@@ -102,28 +100,89 @@ export class SendMsgElementConstructor {
|
||||
fileName: fileName || _fileName,
|
||||
"filePath": path,
|
||||
"fileSize": (fileSize).toString(),
|
||||
picHeight,
|
||||
picWidth
|
||||
}
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
static video(filePath: string, fileName: string=""): Promise<SendFileElement> {
|
||||
return SendMsgElementConstructor.file(filePath, true, fileName);
|
||||
static async video(filePath: string, fileName: string = ""): Promise<SendVideoElement> {
|
||||
let {fileName: _fileName, path, fileSize, md5} = await NTQQApi.uploadFile(filePath, ElementType.VIDEO);
|
||||
if (fileSize === 0) {
|
||||
throw "文件异常,大小为0";
|
||||
}
|
||||
// const videoInfo = await encodeMp4(path);
|
||||
// path = videoInfo.filePath
|
||||
// md5 = videoInfo.md5;
|
||||
// fileSize = videoInfo.size;
|
||||
// log("上传视频", md5, path, fileSize, fileName || _fileName)
|
||||
const pathLib = require("path");
|
||||
let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
|
||||
thumb = pathLib.dirname(thumb)
|
||||
// log("thumb 目录", thumb)
|
||||
const videoInfo = await getVideoInfo(path);
|
||||
// log("视频信息", videoInfo)
|
||||
const createThumb = new Promise<string>((resolve, reject) => {
|
||||
const thumbFileName = `${md5}_0.png`
|
||||
ffmpeg(filePath)
|
||||
.on("end", () => {
|
||||
})
|
||||
.on("error", (err) => {
|
||||
reject(err);
|
||||
})
|
||||
.screenshots({
|
||||
timestamps: [0],
|
||||
filename: thumbFileName,
|
||||
folder: thumb,
|
||||
size: videoInfo.width + "x" + videoInfo.height
|
||||
}).on("end", () => {
|
||||
resolve(pathLib.join(thumb, thumbFileName));
|
||||
});
|
||||
})
|
||||
let thumbPath = new Map()
|
||||
const _thumbPath = await createThumb;
|
||||
const thumbSize = (await fs.stat(_thumbPath)).size;
|
||||
// log("生成缩略图", _thumbPath)
|
||||
thumbPath.set(0, _thumbPath)
|
||||
const thumbMd5 = await calculateFileMD5(_thumbPath);
|
||||
let element: SendVideoElement = {
|
||||
elementType: ElementType.VIDEO,
|
||||
elementId: "",
|
||||
videoElement: {
|
||||
fileName: fileName || _fileName,
|
||||
filePath: path,
|
||||
videoMd5: md5,
|
||||
thumbMd5,
|
||||
fileTime: videoInfo.time,
|
||||
thumbPath: thumbPath,
|
||||
thumbSize,
|
||||
thumbWidth: videoInfo.width,
|
||||
thumbHeight: videoInfo.height,
|
||||
fileSize: "" + fileSize,
|
||||
// fileUuid: "",
|
||||
// transferStatus: 0,
|
||||
// progress: 0,
|
||||
// invalidState: 0,
|
||||
// fileSubId: "",
|
||||
// fileBizId: null,
|
||||
// originVideoMd5: "",
|
||||
// fileFormat: 2,
|
||||
// import_rich_media_context: null,
|
||||
// sourceVideoCodecFormat: 2
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
static async ptt(pttPath: string): Promise<SendPttElement> {
|
||||
const {converted, path: silkPath, duration} = await encodeSilk(pttPath);
|
||||
// log("生成语音", silkPath, duration);
|
||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(silkPath, ElementType.PTT);
|
||||
if (fileSize === 0){
|
||||
if (fileSize === 0) {
|
||||
throw "文件异常,大小为0";
|
||||
}
|
||||
if (converted) {
|
||||
fs.unlink(silkPath, () => {
|
||||
});
|
||||
fs.unlink(silkPath).then();
|
||||
}
|
||||
return {
|
||||
elementType: ElementType.PTT,
|
||||
|
@@ -28,6 +28,7 @@ export enum ReceiveCmd {
|
||||
FRIEND_REQUEST = "nodeIKernelBuddyListener/onBuddyReqChange",
|
||||
SELF_STATUS = 'nodeIKernelProfileListener/onSelfStatusChanged',
|
||||
CACHE_SCAN_FINISH = "nodeIKernelStorageCleanListener/onFinishScan",
|
||||
MEDIA_UPLOAD_COMPLETE = "nodeIKernelMsgListener/onRichMediaUploadComplete",
|
||||
}
|
||||
|
||||
interface NTQQApiReturnData<PayloadType = unknown> extends Array<any> {
|
||||
@@ -168,24 +169,6 @@ async function processGroupEvent(payload) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (existGroup.memberCount < group.memberCount) {
|
||||
const oldMembers = existGroup.members;
|
||||
const oldMembersSet = new Set<string>();
|
||||
for (const member of oldMembers) {
|
||||
oldMembersSet.add(member.uin);
|
||||
}
|
||||
|
||||
await sleep(200);
|
||||
const newMembers = await NTQQApi.getGroupMembers(group.groupCode);
|
||||
|
||||
group.members = newMembers;
|
||||
for (const member of newMembers) {
|
||||
if (!oldMembersSet.has(member.uin)) {
|
||||
postOB11Event(new OB11GroupIncreaseEvent(group.groupCode, parseInt(member.uin)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,6 +180,7 @@ async function processGroupEvent(payload) {
|
||||
}
|
||||
}
|
||||
|
||||
// 群列表变动
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUPS, (payload) => {
|
||||
if (payload.updateType != 2) {
|
||||
updateGroups(payload.groupList).then();
|
||||
@@ -216,6 +200,7 @@ registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUP
|
||||
}
|
||||
})
|
||||
|
||||
// 好友列表变动
|
||||
registerReceiveHook<{
|
||||
data: { categoryId: number, categroyName: string, categroyMbCount: number, buddyList: User[] }[]
|
||||
}>(ReceiveCmd.FRIENDS, payload => {
|
||||
@@ -232,6 +217,7 @@ registerReceiveHook<{
|
||||
}
|
||||
})
|
||||
|
||||
// 新消息
|
||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload) => {
|
||||
const {autoDeleteFile} = getConfigUtil().getConfig();
|
||||
for (const message of payload.msgList) {
|
||||
@@ -242,10 +228,16 @@ registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload
|
||||
continue
|
||||
}
|
||||
for (const msgElement of message.elements) {
|
||||
if (msgElement.videoElement) {
|
||||
log("收到视频消息", msgElement.videoElement)
|
||||
log("視頻缩略图", msgElement.videoElement.thumbPath.get(0));
|
||||
}
|
||||
setTimeout(() => {
|
||||
const picPath = msgElement.picElement?.sourcePath
|
||||
const pttPath = msgElement.pttElement?.filePath
|
||||
const pathList = [picPath, pttPath]
|
||||
const filePath = msgElement.fileElement?.filePath
|
||||
const videoPath = msgElement.videoElement?.filePath
|
||||
const pathList = [picPath, pttPath, filePath, videoPath]
|
||||
if (msgElement.picElement) {
|
||||
pathList.push(...Object.values(msgElement.picElement.thumbPath))
|
||||
}
|
||||
@@ -253,6 +245,7 @@ registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload
|
||||
if (aioOpGrayTipElement){
|
||||
tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat;
|
||||
}
|
||||
|
||||
// log("需要清理的文件", pathList);
|
||||
for (const path of pathList) {
|
||||
if (path) {
|
||||
@@ -261,7 +254,7 @@ registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 60 * 1000)
|
||||
}, getConfigUtil().getConfig().autoDeleteFileSecond * 1000)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@@ -21,7 +21,7 @@ import {
|
||||
CacheFileList, CacheFileListItem, CacheFileType,
|
||||
} from "./types";
|
||||
import * as fs from "fs";
|
||||
import {friendRequests, groupNotifies, selfInfo, uidMaps} from "../common/data";
|
||||
import {friendRequests, selfInfo, uidMaps} from "../common/data";
|
||||
import {v4 as uuidv4} from "uuid"
|
||||
import path from "path";
|
||||
import {dbUtil} from "../common/db";
|
||||
@@ -590,11 +590,11 @@ export class NTQQApi {
|
||||
}
|
||||
|
||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||
const notify: GroupNotify = groupNotifies[seq];
|
||||
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
||||
if (!notify) {
|
||||
throw `${seq}对应的加群通知不存在`
|
||||
}
|
||||
delete groupNotifies[seq];
|
||||
// delete groupNotifies[seq];
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST,
|
||||
args: [
|
||||
|
@@ -71,6 +71,7 @@ export enum ElementType {
|
||||
PIC = 2,
|
||||
FILE = 3,
|
||||
PTT = 4,
|
||||
VIDEO = 5,
|
||||
FACE = 6,
|
||||
REPLY = 7,
|
||||
ARK = 10,
|
||||
@@ -112,6 +113,7 @@ export enum PicType {
|
||||
gif = 2000,
|
||||
jpg = 1000
|
||||
}
|
||||
|
||||
export interface SendPicElement {
|
||||
elementType: ElementType.PIC,
|
||||
elementId: "",
|
||||
@@ -166,11 +168,16 @@ export interface FileElement {
|
||||
}
|
||||
|
||||
export interface SendFileElement {
|
||||
elementType: ElementType.FILE,
|
||||
elementType: ElementType.FILE
|
||||
elementId: "",
|
||||
fileElement: FileElement
|
||||
}
|
||||
|
||||
export interface SendVideoElement {
|
||||
elementType: ElementType.VIDEO
|
||||
elementId: "",
|
||||
videoElement: VideoElement
|
||||
}
|
||||
export interface SendArkElement {
|
||||
elementType: ElementType.ARK,
|
||||
elementId: "",
|
||||
@@ -179,7 +186,7 @@ export interface SendArkElement {
|
||||
}
|
||||
|
||||
export type SendMessageElement = SendTextElement | SendPttElement |
|
||||
SendPicElement | SendReplyElement | SendFaceElement | SendFileElement | SendArkElement
|
||||
SendPicElement | SendReplyElement | SendFaceElement | SendFileElement | SendVideoElement | SendArkElement
|
||||
|
||||
export enum AtType {
|
||||
notAt = 0,
|
||||
@@ -218,8 +225,8 @@ export interface PttElement {
|
||||
|
||||
export interface ArkElement {
|
||||
bytesData: string;
|
||||
linkInfo:null,
|
||||
subElementType:null
|
||||
linkInfo: null,
|
||||
subElementType: null
|
||||
}
|
||||
|
||||
export const IMAGE_HTTP_HOST = "https://gchat.qpic.cn"
|
||||
@@ -245,7 +252,8 @@ export interface GrayTipElement {
|
||||
operatorMemRemark?: string;
|
||||
wording: string; // 自定义的撤回提示语
|
||||
}
|
||||
aioOpGrayTipElement: TipAioOpGrayTipElement
|
||||
aioOpGrayTipElement: TipAioOpGrayTipElement,
|
||||
groupElement: TipGroupElement
|
||||
}
|
||||
|
||||
export interface FaceElement {
|
||||
@@ -256,37 +264,42 @@ export interface FaceElement {
|
||||
export interface VideoElement {
|
||||
"filePath": string,
|
||||
"fileName": string,
|
||||
"videoMd5": string,
|
||||
"thumbMd5": string
|
||||
"fileTime": 87, // second
|
||||
"thumbSize": 314235, // byte
|
||||
"fileFormat": 2, // 2表示mp4?
|
||||
"fileSize": string, // byte
|
||||
"thumbWidth": number,
|
||||
"thumbHeight": number,
|
||||
"busiType": 0, // 未知
|
||||
"subBusiType": 0, // 未知
|
||||
"thumbPath": Map<number, any>,
|
||||
"transferStatus": 0, // 未知
|
||||
"progress": 0, // 下载进度?
|
||||
"invalidState": 0, // 未知
|
||||
"fileUuid": string, // 可以用于下载链接?
|
||||
"fileSubId": "",
|
||||
"fileBizId": null,
|
||||
"originVideoMd5": "",
|
||||
"import_rich_media_context": null,
|
||||
"sourceVideoCodecFormat": 0
|
||||
"videoMd5"?: string,
|
||||
"thumbMd5"?: string
|
||||
"fileTime"?: number, // second
|
||||
"thumbSize"?: number, // byte
|
||||
"fileFormat"?: number, // 2表示mp4?
|
||||
"fileSize"?: string, // byte
|
||||
"thumbWidth"?: number,
|
||||
"thumbHeight"?: number,
|
||||
"busiType"?: 0, // 未知
|
||||
"subBusiType"?: 0, // 未知
|
||||
"thumbPath"?: Map<number, any>,
|
||||
"transferStatus"?: 0, // 未知
|
||||
"progress"?: 0, // 下载进度?
|
||||
"invalidState"?: 0, // 未知
|
||||
"fileUuid"?: string, // 可以用于下载链接?
|
||||
"fileSubId"?: "",
|
||||
"fileBizId"?: null,
|
||||
"originVideoMd5"?: "",
|
||||
"import_rich_media_context"?: null,
|
||||
"sourceVideoCodecFormat"?: number
|
||||
}
|
||||
|
||||
export interface TipAioOpGrayTipElement{
|
||||
export interface TipAioOpGrayTipElement { // 这是什么提示来着?
|
||||
operateType: number,
|
||||
peerUid: string,
|
||||
fromGrpCodeOfTmpChat: string,
|
||||
}
|
||||
|
||||
export enum TipGroupElementType {
|
||||
memberIncrease = 1,
|
||||
ban = 8
|
||||
}
|
||||
|
||||
export interface TipGroupElement {
|
||||
"type": 1, // 1是表示有人加入群, 自己加入群也会收到这个
|
||||
"role": 0,
|
||||
"type": TipGroupElementType, // 1是表示有人加入群, 自己加入群也会收到这个
|
||||
"role": 0, // 暂时不知
|
||||
"groupName": string, // 暂时获取不到
|
||||
"memberUid": string,
|
||||
"memberNick": string,
|
||||
@@ -295,7 +308,7 @@ export interface TipGroupElement {
|
||||
"adminNick": string,
|
||||
"adminRemark": string,
|
||||
"createGroup": null,
|
||||
"memberAdd": {
|
||||
"memberAdd"?: {
|
||||
"showType": 1,
|
||||
"otherAdd": null,
|
||||
"otherAddByOtherQRCode": null,
|
||||
@@ -305,7 +318,22 @@ export interface TipGroupElement {
|
||||
"otherInviteYou": null,
|
||||
"youInviteOther": null
|
||||
},
|
||||
"shutUp": null
|
||||
"shutUp"?: {
|
||||
"curTime": string,
|
||||
"duration": string, // 禁言时间,秒
|
||||
"admin": {
|
||||
"uid": string,
|
||||
"card": string,
|
||||
"name": string,
|
||||
"role": GroupMemberRole
|
||||
},
|
||||
"member": {
|
||||
"uid": string
|
||||
"card": string,
|
||||
"name": string,
|
||||
"role": GroupMemberRole
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -366,7 +394,7 @@ export interface GroupNotifies {
|
||||
|
||||
export interface GroupNotify {
|
||||
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
||||
seq: string, // 转成数字,再除以1000应该就是时间戳?
|
||||
seq: string, // 唯一标识符,转成数字再除以1000应该就是时间戳?
|
||||
type: GroupNotifyTypes,
|
||||
status: 0, // 未知
|
||||
group: { groupCode: string, groupName: string },
|
||||
|
@@ -22,7 +22,7 @@ class BaseAction<PayloadType, ReturnDataType> {
|
||||
return OB11Response.ok(resData);
|
||||
} catch (e) {
|
||||
log("发生错误", e)
|
||||
return OB11Response.error(e.toString(), 200);
|
||||
return OB11Response.error(e?.toString() || e?.stack?.toString() || "未知错误,可能操作超时", 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class BaseAction<PayloadType, ReturnDataType> {
|
||||
return OB11Response.ok(resData, echo);
|
||||
} catch (e) {
|
||||
log("发生错误", e)
|
||||
return OB11Response.error(e.toString(), 1200, echo)
|
||||
return OB11Response.error(e.stack?.toString() || e.toString(), 1200, echo)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,7 @@ import {
|
||||
ChatCacheListItemBasic,
|
||||
CacheFileType
|
||||
} from '../../ntqqapi/types';
|
||||
import {dbUtil} from "../../common/db";
|
||||
|
||||
export default class CleanCache extends BaseAction<void, void> {
|
||||
actionName = ActionName.CleanCache
|
||||
@@ -15,6 +16,7 @@ export default class CleanCache extends BaseAction<void, void> {
|
||||
protected _handle(): Promise<void> {
|
||||
return new Promise<void>(async (res, rej) => {
|
||||
try {
|
||||
// dbUtil.clearCache();
|
||||
const cacheFilePaths: string[] = [];
|
||||
|
||||
await NTQQApi.setCacheSilentScan(false);
|
||||
|
@@ -157,14 +157,9 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
// log("send msg:", peer, sendElements)
|
||||
const {sendElements, deleteAfterSentFiles} = await this.createSendElements(messages, group)
|
||||
try {
|
||||
const returnMsg = await this.send(peer, sendElements, deleteAfterSentFiles)
|
||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {}));
|
||||
return {message_id: returnMsg.msgShortId}
|
||||
} catch (e) {
|
||||
log("发送消息失败", e.stack.toString())
|
||||
throw (e.toString())
|
||||
}
|
||||
}
|
||||
|
||||
protected convertMessage2List(message: OB11MessageMixType) {
|
||||
@@ -372,7 +367,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
if (sendMsg.type === OB11MessageDataType.file) {
|
||||
log("发送文件", path, payloadFileName || fileName)
|
||||
sendElements.push(await SendMsgElementConstructor.file(path, false, payloadFileName || fileName));
|
||||
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
|
||||
} else if (sendMsg.type === OB11MessageDataType.video) {
|
||||
log("发送视频", path, payloadFileName || fileName)
|
||||
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName));
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {groupNotifies} from "../../common/data";
|
||||
import {GroupNotify, GroupRequestOperateTypes} from "../../ntqqapi/types";
|
||||
import {GroupRequestOperateTypes} from "../../ntqqapi/types";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
@@ -17,15 +16,10 @@ export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const seq = payload.flag.toString();
|
||||
const notify: GroupNotify = groupNotifies[seq]
|
||||
try {
|
||||
await NTQQApi.handleGroupRequest(seq,
|
||||
payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||
payload.reason
|
||||
)
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
await NTQQApi.handleGroupRequest(seq,
|
||||
payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||
payload.reason
|
||||
)
|
||||
return null
|
||||
}
|
||||
}
|
@@ -8,13 +8,25 @@ import {
|
||||
OB11User,
|
||||
OB11UserSex
|
||||
} from "./types";
|
||||
import {AtType, ChatType, Group, GroupMember, IMAGE_HTTP_HOST, RawMessage, SelfInfo, User} from '../ntqqapi/types';
|
||||
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
||||
import {getConfigUtil, log} from "../common/utils";
|
||||
import {
|
||||
AtType,
|
||||
ChatType,
|
||||
Group,
|
||||
GroupMember,
|
||||
IMAGE_HTTP_HOST,
|
||||
RawMessage,
|
||||
SelfInfo,
|
||||
TipGroupElementType,
|
||||
User
|
||||
} from '../ntqqapi/types';
|
||||
import {getFriend, getGroup, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
||||
import {getConfigUtil, log, sleep} from "../common/utils";
|
||||
import {NTQQApi} from "../ntqqapi/ntcall";
|
||||
import {EventType} from "./event/OB11BaseEvent";
|
||||
import {encodeCQCode} from "./cqcode";
|
||||
import {dbUtil} from "../common/db";
|
||||
import {OB11GroupIncreaseEvent} from "./event/notice/OB11GroupIncreaseEvent";
|
||||
import {OB11GroupBanEvent} from "./event/notice/OB11GroupBanEvent";
|
||||
|
||||
|
||||
export class OB11Constructor {
|
||||
@@ -97,7 +109,7 @@ export class OB11Constructor {
|
||||
} else if (element.replyElement) {
|
||||
message_data["type"] = "reply"
|
||||
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
||||
try{
|
||||
try {
|
||||
const replyMsg = await dbUtil.getMsgBySeqId(element.replyElement.replayMsgSeq)
|
||||
// log("找到回复消息", replyMsg.msgShortId, replyMsg.msgId)
|
||||
if (replyMsg) {
|
||||
@@ -105,7 +117,7 @@ export class OB11Constructor {
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
log("获取不到引用的消息", e.stack, element.replyElement.replayMsgSeq)
|
||||
}
|
||||
|
||||
@@ -116,10 +128,9 @@ export class OB11Constructor {
|
||||
// message_data["data"]["path"] = element.picElement.sourcePath
|
||||
const url = element.picElement.originImageUrl
|
||||
const fileMd5 = element.picElement.md5HexStr
|
||||
if (url){
|
||||
if (url) {
|
||||
message_data["data"]["url"] = IMAGE_HTTP_HOST + url
|
||||
}
|
||||
else if (fileMd5 && element.picElement.fileUuid.indexOf("_") === -1){ // fileuuid有下划线的是Linux发送的,这个url是另外的格式,目前尚未得知如何组装
|
||||
} else if (fileMd5 && element.picElement.fileUuid.indexOf("_") === -1) { // fileuuid有下划线的是Linux发送的,这个url是另外的格式,目前尚未得知如何组装
|
||||
message_data["data"]["url"] = `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${fileMd5.toUpperCase()}/0`
|
||||
}
|
||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||
@@ -193,7 +204,10 @@ export class OB11Constructor {
|
||||
message_data["type"] = OB11MessageDataType.face;
|
||||
message_data["data"]["id"] = element.faceElement.faceIndex.toString();
|
||||
}
|
||||
|
||||
// todo: 解析入群grayTipElement
|
||||
else if (element.grayTipElement?.aioOpGrayTipElement) {
|
||||
log("收到 group gray tip 消息", element.grayTipElement.aioOpGrayTipElement)
|
||||
}
|
||||
// if (message_data.data.file) {
|
||||
// let filePath: string = message_data.data.file;
|
||||
// if (!enableLocalFile2Url) {
|
||||
@@ -230,6 +244,54 @@ export class OB11Constructor {
|
||||
return resMsg;
|
||||
}
|
||||
|
||||
static async GroupEvent(msg: RawMessage): Promise<OB11GroupIncreaseEvent> {
|
||||
for (let element of msg.elements) {
|
||||
const groupElement = element.grayTipElement?.groupElement
|
||||
if (groupElement) {
|
||||
// log("收到群提示消息", groupElement)
|
||||
if (groupElement.type == TipGroupElementType.memberIncrease) {
|
||||
log("收到群成员增加消息", groupElement)
|
||||
await sleep(1000);
|
||||
const member = await getGroupMember(msg.peerUid, null, groupElement.memberUid);
|
||||
let memberUin = member?.uin;
|
||||
if (!memberUin) {
|
||||
memberUin = (await NTQQApi.getUserDetailInfo(groupElement.memberUid)).uin
|
||||
}
|
||||
// log("获取新群成员QQ", memberUin)
|
||||
const adminMember = await getGroupMember(msg.peerUid, null, groupElement.adminUid);
|
||||
// log("获取同意新成员入群的管理员", adminMember)
|
||||
if (memberUin) {
|
||||
const operatorUin = adminMember?.uin || memberUin
|
||||
let event = new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(operatorUin));
|
||||
// log("构造群增加事件", event)
|
||||
return event;
|
||||
}
|
||||
}
|
||||
else if (groupElement.type === TipGroupElementType.ban) {
|
||||
log("收到群群员禁言提示", groupElement)
|
||||
const memberUid = groupElement.shutUp.member.uid
|
||||
const adminUid = groupElement.shutUp.admin.uid
|
||||
let memberUin: string = ""
|
||||
let duration = parseInt(groupElement.shutUp.duration)
|
||||
let sub_type: "ban" | "lift_ban" = duration > 0 ? "ban" : "lift_ban"
|
||||
if (memberUid){
|
||||
memberUin = (await getGroupMember(msg.peerUid, null, memberUid))?.uin || (await NTQQApi.getUserDetailInfo(memberUid))?.uin
|
||||
}
|
||||
else {
|
||||
memberUin = "0"; // 0表示全员禁言
|
||||
if (duration > 0) {
|
||||
duration = -1
|
||||
}
|
||||
}
|
||||
const adminUin = (await getGroupMember(msg.peerUid, null, adminUid))?.uin || (await NTQQApi.getUserDetailInfo(adminUid))?.uin
|
||||
if (memberUin && adminUin) {
|
||||
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static friend(friend: User): OB11User {
|
||||
return {
|
||||
user_id: parseInt(friend.uin),
|
||||
|
17
src/onebot11/event/notice/OB11GroupBanEvent.ts
Normal file
17
src/onebot11/event/notice/OB11GroupBanEvent.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||
|
||||
export class OB11GroupBanEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = "group_ban";
|
||||
operator_id: number;
|
||||
duration: number;
|
||||
sub_type: "ban" | "lift_ban";
|
||||
|
||||
constructor(groupId: number, userId: number, operatorId: number, duration: number, sub_type: "ban" | "lift_ban") {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId;
|
||||
this.user_id = userId;
|
||||
this.duration = duration;
|
||||
this.sub_type = sub_type;
|
||||
}
|
||||
}
|
@@ -5,10 +5,10 @@ export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent {
|
||||
sub_type = "approve"; // TODO: 实现其他几种子类型的识别 ("approve" | "invite")
|
||||
operator_id: number;
|
||||
|
||||
constructor(groupId: number, userId: number) {
|
||||
constructor(groupId: number, userId: number, operatorId: number) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operator_id = userId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被邀请的,还是主动加入的
|
||||
this.operator_id = operatorId;
|
||||
this.user_id = userId;
|
||||
}
|
||||
}
|
||||
|
@@ -90,7 +90,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
], 'ob11.messagePostFormat', config.ob11.messagePostFormat),
|
||||
),
|
||||
SettingItem(
|
||||
'ffmpeg 路径', `<span id="config-ffmpeg-path-text">${!isEmpty(config.ffmpeg) ? config.ffmpeg : '未指定'}</span>`,
|
||||
'ffmpeg 路径, 用于发送语音时进行转码', `<span id="config-ffmpeg-path-text">${!isEmpty(config.ffmpeg) ? config.ffmpeg : '未指定'}</span>`,
|
||||
SettingButton('选择', 'config-ffmpeg-select'),
|
||||
),
|
||||
SettingItem(
|
||||
@@ -138,7 +138,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
]),
|
||||
SettingList([
|
||||
SettingItem(
|
||||
'GitHub',
|
||||
'GitHub和文档',
|
||||
`https://github.com/LLOneBot/LLOneBot`,
|
||||
SettingButton('点个Star', 'open-github'),
|
||||
),
|
||||
@@ -167,17 +167,16 @@ async function onSettingWindowCreated(view: Element) {
|
||||
window.LiteLoader.api.openExternal('https://qm.qq.com/q/bDnHRG38aI')
|
||||
})
|
||||
// 生成反向地址列表
|
||||
const buildHostListItem = (type: string, host: string, index: number) => {
|
||||
const buildHostListItem = (type: string, host: string, index: number, inputAttrs: any={}) => {
|
||||
const dom = {
|
||||
container: document.createElement('setting-item'),
|
||||
input: document.createElement('input'),
|
||||
inputContainer: document.createElement('div'),
|
||||
deleteBtn: document.createElement('setting-button'),
|
||||
};
|
||||
|
||||
dom.container.classList.add('setting-host-list-item');
|
||||
dom.container.dataset.direction = 'row';
|
||||
|
||||
Object.assign(dom.input, inputAttrs);
|
||||
dom.input.classList.add('q-input__inner');
|
||||
dom.input.type = 'url';
|
||||
dom.input.value = host;
|
||||
@@ -200,18 +199,18 @@ async function onSettingWindowCreated(view: Element) {
|
||||
|
||||
return dom.container;
|
||||
};
|
||||
const buildHostList = (hosts: string[], type: string) => {
|
||||
const buildHostList = (hosts: string[], type: string, inputAttr: any={}) => {
|
||||
const result: HTMLElement[] = [];
|
||||
|
||||
hosts.forEach((host, index) => {
|
||||
result.push(buildHostListItem(type, host, index));
|
||||
result.push(buildHostListItem(type, host, index, inputAttr));
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
const addReverseHost = (type: string, doc: Document = document) => {
|
||||
const addReverseHost = (type: string, doc: Document = document, inputAttr: any={}) => {
|
||||
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`);
|
||||
hostContainerDom.appendChild(buildHostListItem(type, '', ob11Config[type].length));
|
||||
hostContainerDom.appendChild(buildHostListItem(type, '', ob11Config[type].length, inputAttr));
|
||||
ob11Config[type].push('');
|
||||
};
|
||||
const initReverseHost = (type: string, doc: Document = document) => {
|
||||
@@ -224,8 +223,8 @@ async function onSettingWindowCreated(view: Element) {
|
||||
initReverseHost('httpHosts', doc);
|
||||
initReverseHost('wsHosts', doc);
|
||||
|
||||
doc.querySelector('#config-ob11-httpHosts-add').addEventListener('click', () => addReverseHost('httpHosts'));
|
||||
doc.querySelector('#config-ob11-wsHosts-add').addEventListener('click', () => addReverseHost('wsHosts'));
|
||||
doc.querySelector('#config-ob11-httpHosts-add').addEventListener('click', () => addReverseHost('httpHosts', document, {'placeholder': '如:http://127.0.0.1:5140/onebot' }));
|
||||
doc.querySelector('#config-ob11-wsHosts-add').addEventListener('click', () => addReverseHost('wsHosts', document, {'placeholder': '如:ws://127.0.0.1:5140/onebot' }));
|
||||
|
||||
doc.querySelector('#config-ffmpeg-select').addEventListener('click', () => {
|
||||
window.llonebot.selectFile()
|
||||
|
@@ -1 +1 @@
|
||||
export const version = "3.13.10"
|
||||
export const version = "3.14.1"
|
Reference in New Issue
Block a user