mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
refactor: class NTQQApi
This commit is contained in:
parent
c313fcd491
commit
d8e31985af
manifest.json
src
@ -1,10 +1,10 @@
|
||||
{
|
||||
"manifest_version": 4,
|
||||
"type": "extension",
|
||||
"name": "LLOneBot v3.15.2",
|
||||
"name": "LLOneBot v3.15.3",
|
||||
"slug": "LLOneBot",
|
||||
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
||||
"version": "3.15.2",
|
||||
"version": "3.15.3",
|
||||
"icon": "./icon.jpg",
|
||||
"authors": [
|
||||
{
|
||||
|
@ -1,17 +1,13 @@
|
||||
import {NTQQApi} from '../ntqqapi/ntcall'
|
||||
import {
|
||||
type Friend,
|
||||
type FriendRequest,
|
||||
type Group,
|
||||
type GroupMember,
|
||||
type GroupNotify,
|
||||
type RawMessage,
|
||||
type SelfInfo
|
||||
} from '../ntqqapi/types'
|
||||
import {type FileCache, type LLOneBotError} from './types'
|
||||
import {dbUtil} from "./db";
|
||||
import {raw} from "express";
|
||||
import {isNumeric, log} from "./utils";
|
||||
import {NTQQGroupApi} from "../ntqqapi/api/group";
|
||||
|
||||
export const selfInfo: SelfInfo = {
|
||||
uid: '',
|
||||
@ -47,7 +43,7 @@ export async function getGroup(qq: string): Promise<Group | undefined> {
|
||||
let group = groups.find(group => group.groupCode === qq.toString())
|
||||
if (!group) {
|
||||
try {
|
||||
const _groups = await NTQQApi.getGroups(true);
|
||||
const _groups = await NTQQGroupApi.getGroups(true);
|
||||
group = _groups.find(group => group.groupCode === qq.toString())
|
||||
if (group) {
|
||||
groups.push(group)
|
||||
@ -70,7 +66,7 @@ export async function getGroupMember(groupQQ: string | number, memberUinOrUid: s
|
||||
let member = group.members?.find(filterFunc)
|
||||
if (!member) {
|
||||
try {
|
||||
const _members = await NTQQApi.getGroupMembers(groupQQ)
|
||||
const _members = await NTQQGroupApi.getGroupMembers(groupQQ)
|
||||
if (_members.length > 0) {
|
||||
group.members = _members
|
||||
}
|
||||
@ -88,7 +84,7 @@ export async function getGroupMember(groupQQ: string | number, memberUinOrUid: s
|
||||
export async function refreshGroupMembers(groupQQ: string) {
|
||||
const group = groups.find(group => group.groupCode === groupQQ)
|
||||
if (group) {
|
||||
group.members = await NTQQApi.getGroupMembers(groupQQ)
|
||||
group.members = await NTQQGroupApi.getGroupMembers(groupQQ)
|
||||
}
|
||||
}
|
||||
|
||||
|
342
src/common/utils/index.ts
Normal file
342
src/common/utils/index.ts
Normal file
@ -0,0 +1,342 @@
|
||||
import * as path from "node:path";
|
||||
import {selfInfo} from "../data";
|
||||
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"
|
||||
|
||||
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
||||
|
||||
export function getConfigUtil() {
|
||||
const configFilePath = path.join(DATA_DIR, `config_${selfInfo.uin}.json`)
|
||||
return new ConfigUtil(configFilePath)
|
||||
}
|
||||
|
||||
function truncateString(obj: any, maxLength = 500) {
|
||||
if (obj !== null && typeof obj === 'object') {
|
||||
Object.keys(obj).forEach(key => {
|
||||
if (typeof obj[key] === 'string') {
|
||||
// 如果是字符串且超过指定长度,则截断
|
||||
if (obj[key].length > maxLength) {
|
||||
obj[key] = obj[key].substring(0, maxLength) + '...';
|
||||
}
|
||||
} else if (typeof obj[key] === 'object') {
|
||||
// 如果是对象或数组,则递归调用
|
||||
truncateString(obj[key], maxLength);
|
||||
}
|
||||
});
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
export function isNumeric(str: string) {
|
||||
return /^\d+$/.test(str);
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
// 判断是否是对象
|
||||
if (typeof msgItem === "object") {
|
||||
let obj = JSON.parse(JSON.stringify(msgItem));
|
||||
logMsg += JSON.stringify(truncateString(obj)) + " ";
|
||||
continue;
|
||||
}
|
||||
logMsg += msgItem + " ";
|
||||
}
|
||||
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
||||
// sendLog(...msg);
|
||||
// console.log(msg)
|
||||
fs.appendFile(path.join(DATA_DIR, `llonebot-${currentDate}.log`), logMsg, (err: any) => {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
export function isGIF(path: string) {
|
||||
const buffer = Buffer.alloc(4);
|
||||
const fd = fs.openSync(path, 'r');
|
||||
fs.readSync(fd, buffer, 0, 4, 0);
|
||||
fs.closeSync(fd);
|
||||
return buffer.toString() === 'GIF8'
|
||||
}
|
||||
|
||||
export function sleep(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
|
||||
// 定义一个异步函数来检查文件是否存在
|
||||
export function checkFileReceived(path: string, timeout: number = 3000): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const startTime = Date.now();
|
||||
|
||||
function check() {
|
||||
if (fs.existsSync(path)) {
|
||||
resolve();
|
||||
} else if (Date.now() - startTime > timeout) {
|
||||
reject(new Error(`文件不存在: ${path}`));
|
||||
} else {
|
||||
setTimeout(check, 100);
|
||||
}
|
||||
}
|
||||
|
||||
check();
|
||||
});
|
||||
}
|
||||
|
||||
export async function file2base64(path: string) {
|
||||
const readFile = util.promisify(fs.readFile);
|
||||
let result = {
|
||||
err: "",
|
||||
data: ""
|
||||
}
|
||||
try {
|
||||
// 读取文件内容
|
||||
// if (!fs.existsSync(path)){
|
||||
// path = path.replace("\\Ori\\", "\\Thumb\\");
|
||||
// }
|
||||
try {
|
||||
await checkFileReceived(path, 5000);
|
||||
} catch (e: any) {
|
||||
result.err = e.toString();
|
||||
return result;
|
||||
}
|
||||
const data = await readFile(path);
|
||||
// 转换为Base64编码
|
||||
result.data = data.toString('base64');
|
||||
} catch (err) {
|
||||
result.err = err.toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// 在保证老对象已有的属性不变化的情况下将新对象的属性复制到老对象
|
||||
export function mergeNewProperties(newObj: any, oldObj: any) {
|
||||
Object.keys(newObj).forEach(key => {
|
||||
// 如果老对象不存在当前属性,则直接复制
|
||||
if (!oldObj.hasOwnProperty(key)) {
|
||||
oldObj[key] = newObj[key];
|
||||
} else {
|
||||
// 如果老对象和新对象的当前属性都是对象,则递归合并
|
||||
if (typeof oldObj[key] === 'object' && typeof newObj[key] === 'object') {
|
||||
mergeNewProperties(newObj[key], oldObj[key]);
|
||||
} else if (typeof oldObj[key] === 'object' || typeof newObj[key] === 'object') {
|
||||
// 属性冲突,有一方不是对象,直接覆盖
|
||||
oldObj[key] = newObj[key];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function checkFfmpeg(newPath: string = null): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (newPath) {
|
||||
ffmpeg.setFfmpegPath(newPath);
|
||||
ffmpeg.getAvailableFormats((err, formats) => {
|
||||
if (err) {
|
||||
log('ffmpeg is not installed or not found in PATH:', err);
|
||||
resolve(false)
|
||||
} else {
|
||||
log('ffmpeg is installed.');
|
||||
resolve(true);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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 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(filePath).ffprobe( (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);
|
||||
});
|
||||
});
|
||||
}
|
10
src/common/utils/qqpkg.ts
Normal file
10
src/common/utils/qqpkg.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import path from "path";
|
||||
|
||||
type QQPkgInfo = {
|
||||
version: string;
|
||||
buildVersion: string;
|
||||
platform: string;
|
||||
eleArch: string;
|
||||
}
|
||||
|
||||
export const qqPkgInfo: QQPkgInfo = require(path.join(process.resourcesPath, "app/package.json"))
|
@ -21,9 +21,8 @@ import {
|
||||
refreshGroupMembers,
|
||||
selfInfo
|
||||
} from "../common/data";
|
||||
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmd, registerReceiveHook} from "../ntqqapi/hook";
|
||||
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook} from "../ntqqapi/hook";
|
||||
import {OB11Constructor} from "../onebot11/constructor";
|
||||
import {NTQQApi} from "../ntqqapi/ntcall";
|
||||
import {ChatType, FriendRequestNotify, GroupNotifies, GroupNotifyTypes, RawMessage} from "../ntqqapi/types";
|
||||
import {ob11HTTPServer} from "../onebot11/server/http";
|
||||
import {OB11FriendRecallNoticeEvent} from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
||||
@ -36,6 +35,8 @@ import {OB11FriendRequestEvent} from "../onebot11/event/request/OB11FriendReques
|
||||
import * as path from "node:path";
|
||||
import {dbUtil} from "../common/db";
|
||||
import {setConfig} from "./setConfig";
|
||||
import {NTQQUserApi} from "../ntqqapi/api/user";
|
||||
import {NTQQGroupApi} from "../ntqqapi/api/group";
|
||||
|
||||
|
||||
let running = false;
|
||||
@ -123,14 +124,14 @@ function onLoad() {
|
||||
}
|
||||
|
||||
async function startReceiveHook() {
|
||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, async (payload) => {
|
||||
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], async (payload) => {
|
||||
try {
|
||||
await postReceiveMsg(payload.msgList);
|
||||
} catch (e) {
|
||||
log("report message error: ", e.stack.toString());
|
||||
}
|
||||
})
|
||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.UPDATE_MSG, async (payload) => {
|
||||
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.UPDATE_MSG, ReceiveCmdS.UPDATE_ACTIVE_MSG], async (payload) => {
|
||||
for (const message of payload.msgList) {
|
||||
// log("message update", message.sendStatus, message.msgId, message.msgSeq)
|
||||
if (message.recallTime != "0") { //todo: 这个判断方法不太好,应该使用灰色消息元素来判断
|
||||
@ -166,7 +167,7 @@ function onLoad() {
|
||||
dbUtil.updateMsg(message).then();
|
||||
}
|
||||
})
|
||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, async (payload) => {
|
||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, async (payload) => {
|
||||
const {reportSelfMessage} = getConfigUtil().getConfig();
|
||||
if (!reportSelfMessage) {
|
||||
return
|
||||
@ -182,12 +183,12 @@ function onLoad() {
|
||||
"doubt": boolean,
|
||||
"oldestUnreadSeq": string,
|
||||
"unreadCount": number
|
||||
}>(ReceiveCmd.UNREAD_GROUP_NOTIFY, async (payload) => {
|
||||
}>(ReceiveCmdS.UNREAD_GROUP_NOTIFY, async (payload) => {
|
||||
if (payload.unreadCount) {
|
||||
// log("开始获取群通知详情")
|
||||
let notify: GroupNotifies;
|
||||
try {
|
||||
notify = await NTQQApi.getGroupNotifies();
|
||||
notify = await NTQQGroupApi.getGroupNotifies();
|
||||
} catch (e) {
|
||||
// log("获取群通知详情失败", e);
|
||||
return
|
||||
@ -240,7 +241,7 @@ function onLoad() {
|
||||
groupRequestEvent.group_id = parseInt(notify.group.groupCode);
|
||||
let requestQQ = ""
|
||||
try {
|
||||
requestQQ = (await NTQQApi.getUserDetailInfo(notify.user1.uid)).uin;
|
||||
requestQQ = (await NTQQUserApi.getUserDetailInfo(notify.user1.uid)).uin;
|
||||
} catch (e) {
|
||||
log("获取加群人QQ号失败", e)
|
||||
}
|
||||
@ -255,7 +256,7 @@ function onLoad() {
|
||||
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
||||
let user_id = (await getFriend(notify.user2.uid))?.uin
|
||||
if (!user_id) {
|
||||
user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin
|
||||
user_id = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))?.uin
|
||||
}
|
||||
groupInviteEvent.user_id = parseInt(user_id);
|
||||
groupInviteEvent.sub_type = "invite";
|
||||
@ -272,14 +273,14 @@ function onLoad() {
|
||||
}
|
||||
})
|
||||
|
||||
registerReceiveHook<FriendRequestNotify>(ReceiveCmd.FRIEND_REQUEST, async (payload) => {
|
||||
registerReceiveHook<FriendRequestNotify>(ReceiveCmdS.FRIEND_REQUEST, async (payload) => {
|
||||
for (const req of payload.data.buddyReqs) {
|
||||
if (req.isUnread && !friendRequests[req.sourceId] && (parseInt(req.reqTime) > startTime / 1000)) {
|
||||
friendRequests[req.sourceId] = req;
|
||||
log("有新的好友请求", req);
|
||||
let friendRequestEvent = new OB11FriendRequestEvent();
|
||||
try {
|
||||
let requester = await NTQQApi.getUserDetailInfo(req.friendUid)
|
||||
let requester = await NTQQUserApi.getUserDetailInfo(req.friendUid)
|
||||
friendRequestEvent.user_id = parseInt(requester.uin);
|
||||
} catch (e) {
|
||||
log("获取加好友者QQ号失败", e);
|
||||
@ -298,7 +299,7 @@ function onLoad() {
|
||||
log("llonebot pid", process.pid)
|
||||
startTime = Date.now();
|
||||
startReceiveHook().then();
|
||||
NTQQApi.getGroups(true).then()
|
||||
NTQQGroupApi.getGroups(true).then()
|
||||
const config = getConfigUtil().getConfig()
|
||||
// 检查ffmpeg
|
||||
checkFfmpeg(config.ffmpeg).then(exist => {
|
||||
@ -327,7 +328,7 @@ function onLoad() {
|
||||
const init = async () => {
|
||||
try {
|
||||
log("start get self info")
|
||||
const _ = await NTQQApi.getSelfInfo();
|
||||
const _ = await NTQQUserApi.getSelfInfo();
|
||||
log("get self info api result:", _);
|
||||
Object.assign(selfInfo, _);
|
||||
selfInfo.nick = selfInfo.uin;
|
||||
@ -337,7 +338,7 @@ function onLoad() {
|
||||
log("self info", selfInfo);
|
||||
if (selfInfo.uin) {
|
||||
try {
|
||||
const userInfo = (await NTQQApi.getUserDetailInfo(selfInfo.uid));
|
||||
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
||||
log("self info", userInfo);
|
||||
if (userInfo) {
|
||||
selfInfo.nick = userInfo.nick;
|
||||
|
217
src/ntqqapi/api/file.ts
Normal file
217
src/ntqqapi/api/file.ts
Normal file
@ -0,0 +1,217 @@
|
||||
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||
import {
|
||||
CacheFileList,
|
||||
CacheFileListItem,
|
||||
CacheFileType,
|
||||
CacheScanResult,
|
||||
ChatCacheList, ChatCacheListItemBasic,
|
||||
ChatType,
|
||||
ElementType
|
||||
} from "../types";
|
||||
import path from "path";
|
||||
import {log} from "../../common/utils";
|
||||
import fs from "fs";
|
||||
import {ReceiveCmdS} from "../hook";
|
||||
|
||||
export class NTQQFileApi{
|
||||
static async getFileType(filePath: string) {
|
||||
return await callNTQQApi<{ ext: string }>({
|
||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_TYPE, args: [filePath]
|
||||
})
|
||||
}
|
||||
static async getFileMd5(filePath: string) {
|
||||
return await callNTQQApi<string>({
|
||||
className: NTQQApiClass.FS_API,
|
||||
methodName: NTQQApiMethod.FILE_MD5,
|
||||
args: [filePath]
|
||||
})
|
||||
}
|
||||
static async copyFile(filePath: string, destPath: string) {
|
||||
return await callNTQQApi<string>({
|
||||
className: NTQQApiClass.FS_API,
|
||||
methodName: NTQQApiMethod.FILE_COPY,
|
||||
args: [{
|
||||
fromPath: filePath,
|
||||
toPath: destPath
|
||||
}]
|
||||
})
|
||||
}
|
||||
static async getFileSize(filePath: string) {
|
||||
return await callNTQQApi<number>({
|
||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_SIZE, args: [filePath]
|
||||
})
|
||||
}
|
||||
// 上传文件到QQ的文件夹
|
||||
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
||||
const md5 = await NTQQFileApi.getFileMd5(filePath);
|
||||
let ext = (await NTQQFileApi.getFileType(filePath))?.ext
|
||||
if (ext) {
|
||||
ext = "." + ext
|
||||
} else {
|
||||
ext = ""
|
||||
}
|
||||
let fileName = `${path.basename(filePath)}`;
|
||||
if (fileName.indexOf(".") === -1) {
|
||||
fileName += ext;
|
||||
}
|
||||
const mediaPath = await callNTQQApi<string>({
|
||||
methodName: NTQQApiMethod.MEDIA_FILE_PATH,
|
||||
args: [{
|
||||
path_info: {
|
||||
md5HexStr: md5,
|
||||
fileName: fileName,
|
||||
elementType: elementType,
|
||||
elementSubType: 0,
|
||||
thumbSize: 0,
|
||||
needCreate: true,
|
||||
downloadType: 1,
|
||||
file_uuid: ""
|
||||
}
|
||||
}]
|
||||
})
|
||||
log("media path", mediaPath)
|
||||
await NTQQFileApi.copyFile(filePath, mediaPath);
|
||||
const fileSize = await NTQQFileApi.getFileSize(filePath);
|
||||
return {
|
||||
md5,
|
||||
fileName,
|
||||
path: mediaPath,
|
||||
fileSize
|
||||
}
|
||||
}
|
||||
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string) {
|
||||
// 用于下载收到的消息中的图片等
|
||||
if (fs.existsSync(sourcePath)) {
|
||||
return sourcePath
|
||||
}
|
||||
const apiParams = [
|
||||
{
|
||||
getReq: {
|
||||
msgId: msgId,
|
||||
chatType: chatType,
|
||||
peerUid: peerUid,
|
||||
elementId: elementId,
|
||||
thumbSize: 0,
|
||||
downloadType: 1,
|
||||
filePath: thumbPath,
|
||||
},
|
||||
},
|
||||
undefined,
|
||||
]
|
||||
// log("需要下载media", sourcePath);
|
||||
await callNTQQApi({
|
||||
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
||||
args: apiParams,
|
||||
cbCmd: ReceiveCmdS.MEDIA_DOWNLOAD_COMPLETE,
|
||||
cmdCB: (payload: { notifyInfo: { filePath: string } }) => {
|
||||
// log("media 下载完成判断", payload.notifyInfo.filePath, sourcePath);
|
||||
return payload.notifyInfo.filePath == sourcePath;
|
||||
}
|
||||
})
|
||||
return sourcePath
|
||||
}
|
||||
static async getImageSize(filePath: string) {
|
||||
return await callNTQQApi<{ width: number, height: number }>({
|
||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.IMAGE_SIZE, args: [filePath]
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class NTQQFileCacheApi{
|
||||
static async setCacheSilentScan(isSilent: boolean = true) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
|
||||
args: [{
|
||||
isSilent
|
||||
}, null]
|
||||
});
|
||||
}
|
||||
static getCacheSessionPathList() {
|
||||
return callNTQQApi<{
|
||||
key: string,
|
||||
value: string
|
||||
}[]>({
|
||||
className: NTQQApiClass.OS_API,
|
||||
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
|
||||
});
|
||||
}
|
||||
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
|
||||
return callNTQQApi<any>({ // TODO: 目前还不知道真正的返回值是什么
|
||||
methodName: NTQQApiMethod.CACHE_CLEAR,
|
||||
args: [{
|
||||
keys: cacheKeys
|
||||
}, null]
|
||||
});
|
||||
}
|
||||
static addCacheScannedPaths(pathMap: object = {}) {
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
|
||||
args: [{
|
||||
pathMap: {...pathMap},
|
||||
}, null]
|
||||
});
|
||||
}
|
||||
static scanCache() {
|
||||
callNTQQApi<GeneralCallResult>({
|
||||
methodName: ReceiveCmdS.CACHE_SCAN_FINISH,
|
||||
classNameIsRegister: true,
|
||||
}).then();
|
||||
return callNTQQApi<CacheScanResult>({
|
||||
methodName: NTQQApiMethod.CACHE_SCAN,
|
||||
args: [null, null],
|
||||
timeoutSecond: 300,
|
||||
});
|
||||
}
|
||||
static getHotUpdateCachePath() {
|
||||
return callNTQQApi<string>({
|
||||
className: NTQQApiClass.HOTUPDATE_API,
|
||||
methodName: NTQQApiMethod.CACHE_PATH_HOT_UPDATE
|
||||
});
|
||||
}
|
||||
|
||||
static getDesktopTmpPath() {
|
||||
return callNTQQApi<string>({
|
||||
className: NTQQApiClass.BUSINESS_API,
|
||||
methodName: NTQQApiMethod.CACHE_PATH_DESKTOP_TEMP
|
||||
});
|
||||
}
|
||||
static getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) {
|
||||
return new Promise<ChatCacheList>((res, rej) => {
|
||||
callNTQQApi<ChatCacheList>({
|
||||
methodName: NTQQApiMethod.CACHE_CHAT_GET,
|
||||
args: [{
|
||||
chatType: type,
|
||||
pageSize,
|
||||
order: 1,
|
||||
pageIndex
|
||||
}, null]
|
||||
}).then(list => res(list))
|
||||
.catch(e => rej(e));
|
||||
});
|
||||
}
|
||||
static getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) {
|
||||
const _lastRecord = lastRecord ? lastRecord : {fileType: fileType};
|
||||
|
||||
return callNTQQApi<CacheFileList>({
|
||||
methodName: NTQQApiMethod.CACHE_FILE_GET,
|
||||
args: [{
|
||||
fileType: fileType,
|
||||
restart: true,
|
||||
pageSize: pageSize,
|
||||
order: 1,
|
||||
lastRecord: _lastRecord,
|
||||
}, null]
|
||||
})
|
||||
}
|
||||
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
|
||||
args: [{
|
||||
chats,
|
||||
fileKeys
|
||||
}, null]
|
||||
});
|
||||
}
|
||||
|
||||
}
|
61
src/ntqqapi/api/friend.ts
Normal file
61
src/ntqqapi/api/friend.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import {Friend, FriendRequest} from "../types";
|
||||
import {ReceiveCmdS} from "../hook";
|
||||
import {callNTQQApi, GeneralCallResult, NTQQApiMethod} from "../ntcall";
|
||||
import {friendRequests} from "../../common/data";
|
||||
|
||||
export class NTQQFriendApi{
|
||||
static async getFriends(forced = false) {
|
||||
const data = await callNTQQApi<{
|
||||
data: {
|
||||
categoryId: number,
|
||||
categroyName: string,
|
||||
categroyMbCount: number,
|
||||
buddyList: Friend[]
|
||||
}[]
|
||||
}>(
|
||||
{
|
||||
methodName: NTQQApiMethod.FRIENDS,
|
||||
args: [{force_update: forced}, undefined],
|
||||
cbCmd: ReceiveCmdS.FRIENDS
|
||||
})
|
||||
let _friends: Friend[] = [];
|
||||
for (const fData of data.data) {
|
||||
_friends.push(...fData.buddyList)
|
||||
}
|
||||
return _friends
|
||||
}
|
||||
static async likeFriend(uid: string, count = 1) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.LIKE_FRIEND,
|
||||
args: [{
|
||||
doLikeUserInfo: {
|
||||
friendUid: uid,
|
||||
sourceId: 71,
|
||||
doLikeCount: count,
|
||||
doLikeTollCount: 0
|
||||
}
|
||||
}, null]
|
||||
})
|
||||
}
|
||||
static async handleFriendRequest(sourceId: number, accept: boolean,) {
|
||||
const request: FriendRequest = friendRequests[sourceId]
|
||||
if (!request) {
|
||||
throw `sourceId ${sourceId}, 对应的好友请求不存在`
|
||||
}
|
||||
const result = await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.HANDLE_FRIEND_REQUEST,
|
||||
args: [
|
||||
{
|
||||
"approvalInfo": {
|
||||
"friendUid": request.friendUid,
|
||||
"reqTime": request.reqTime,
|
||||
accept
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
delete friendRequests[sourceId];
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
223
src/ntqqapi/api/group.ts
Normal file
223
src/ntqqapi/api/group.ts
Normal file
@ -0,0 +1,223 @@
|
||||
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 {log} from "../../common/utils";
|
||||
import {BrowserWindow} from "electron";
|
||||
import {dbUtil} from "../../common/db";
|
||||
|
||||
export class NTQQGroupApi{
|
||||
static async getGroups(forced = false) {
|
||||
let cbCmd = ReceiveCmdS.GROUPS
|
||||
if (process.platform != "win32") {
|
||||
cbCmd = ReceiveCmdS.GROUPS_UNIX
|
||||
}
|
||||
const result = await callNTQQApi<{
|
||||
updateType: number,
|
||||
groupList: Group[]
|
||||
}>({methodName: NTQQApiMethod.GROUPS, args: [{force_update: forced}, undefined], cbCmd})
|
||||
return result.groupList
|
||||
}
|
||||
static async getGroupMembers(groupQQ: string, num = 3000): Promise<GroupMember[]> {
|
||||
const sceneId = await callNTQQApi({
|
||||
methodName: NTQQApiMethod.GROUP_MEMBER_SCENE,
|
||||
args: [{
|
||||
groupCode: groupQQ,
|
||||
scene: "groupMemberList_MainWindow"
|
||||
}]
|
||||
})
|
||||
// log("get group member sceneId", sceneId);
|
||||
try {
|
||||
const result = await callNTQQApi<{
|
||||
result: { infos: any }
|
||||
}>({
|
||||
methodName: NTQQApiMethod.GROUP_MEMBERS,
|
||||
args: [{
|
||||
sceneId: sceneId,
|
||||
num: num
|
||||
},
|
||||
null
|
||||
]
|
||||
})
|
||||
// log("members info", typeof result.result.infos, Object.keys(result.result.infos))
|
||||
const values = result.result.infos.values()
|
||||
|
||||
const members: GroupMember[] = Array.from(values)
|
||||
for (const member of members) {
|
||||
uidMaps[member.uid] = member.uin;
|
||||
}
|
||||
// log(uidMaps);
|
||||
// log("members info", values);
|
||||
log(`get group ${groupQQ} members success`)
|
||||
return members
|
||||
} catch (e) {
|
||||
log(`get group ${groupQQ} members failed`, e)
|
||||
return []
|
||||
}
|
||||
}
|
||||
static async getGroupNotifies() {
|
||||
// 获取管理员变更
|
||||
// 加群通知,退出通知,需要管理员权限
|
||||
callNTQQApi<GeneralCallResult>({
|
||||
methodName: ReceiveCmdS.GROUP_NOTIFY,
|
||||
classNameIsRegister: true,
|
||||
}).then()
|
||||
return await callNTQQApi<GroupNotifies>({
|
||||
methodName: NTQQApiMethod.GET_GROUP_NOTICE,
|
||||
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
||||
afterFirstCmd: false,
|
||||
args: [
|
||||
{"doubt": false, "startSeq": "", "number": 14},
|
||||
null
|
||||
]
|
||||
});
|
||||
}
|
||||
static async getGroupIgnoreNotifies() {
|
||||
await NTQQGroupApi.getGroupNotifies();
|
||||
const result = callNTQQApi<GroupNotifies>({
|
||||
className: NTQQApiClass.WINDOW_API,
|
||||
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
|
||||
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
||||
afterFirstCmd: false,
|
||||
args: [
|
||||
"GroupNotifyFilterWindow"
|
||||
]
|
||||
})
|
||||
// 关闭窗口
|
||||
setTimeout(() => {
|
||||
for (const w of BrowserWindow.getAllWindows()) {
|
||||
// log("close window", w.webContents.getURL())
|
||||
if (w.webContents.getURL().indexOf("#/notify-filter/") != -1) {
|
||||
w.close();
|
||||
}
|
||||
}
|
||||
}, 2000);
|
||||
return result;
|
||||
}
|
||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
||||
if (!notify) {
|
||||
throw `${seq}对应的加群通知不存在`
|
||||
}
|
||||
// delete groupNotifies[seq];
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST,
|
||||
args: [
|
||||
{
|
||||
"doubt": false,
|
||||
"operateMsg": {
|
||||
"operateType": operateType, // 2 拒绝
|
||||
"targetMsg": {
|
||||
"seq": seq, // 通知序列号
|
||||
"type": notify.type,
|
||||
"groupCode": notify.group.groupCode,
|
||||
"postscript": reason
|
||||
}
|
||||
}
|
||||
},
|
||||
null
|
||||
]
|
||||
});
|
||||
}
|
||||
static async quitGroup(groupQQ: string) {
|
||||
await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.QUIT_GROUP,
|
||||
args: [
|
||||
{"groupCode": groupQQ},
|
||||
null
|
||||
]
|
||||
})
|
||||
}
|
||||
static async kickMember(groupQQ: string, kickUids: string[], refuseForever: boolean = false, kickReason: string = '') {
|
||||
return await callNTQQApi<GeneralCallResult>(
|
||||
{
|
||||
methodName: NTQQApiMethod.KICK_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
kickUids,
|
||||
refuseForever,
|
||||
kickReason,
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
static async banMember(groupQQ: string, memList: Array<{ uid: string, timeStamp: number }>) {
|
||||
// timeStamp为秒数, 0为解除禁言
|
||||
return await callNTQQApi<GeneralCallResult>(
|
||||
{
|
||||
methodName: NTQQApiMethod.MUTE_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
memList,
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
static async banGroup(groupQQ: string, shutUp: boolean) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.MUTE_GROUP,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
shutUp
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
cardName
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_ROLE,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
role
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
static async setGroupName(groupQQ: string, groupName: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_GROUP_NAME,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
groupName
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
// 头衔不可用
|
||||
static async setGroupTitle(groupQQ: string, uid: string, title: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_GROUP_TITLE,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid,
|
||||
title
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
static publishGroupBulletin(groupQQ: string, title: string, content: string) {
|
||||
|
||||
}
|
||||
}
|
163
src/ntqqapi/api/msg.ts
Normal file
163
src/ntqqapi/api/msg.ts
Normal file
@ -0,0 +1,163 @@
|
||||
import {callNTQQApi, GeneralCallResult, NTQQApiMethod} from "../ntcall";
|
||||
import {ChatType, RawMessage, SendMessageElement} from "../types";
|
||||
import {log, sleep} from "../../common/utils";
|
||||
import {dbUtil} from "../../common/db";
|
||||
import {selfInfo} from "../../common/data";
|
||||
import {ReceiveCmdS, registerReceiveHook} from "../hook";
|
||||
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {}// peerUid: callbackFunnc
|
||||
|
||||
export interface Peer {
|
||||
chatType: ChatType
|
||||
peerUid: string // 如果是群聊uid为群号,私聊uid就是加密的字符串
|
||||
guildId?: ""
|
||||
}
|
||||
|
||||
export class NTQQMsgApi {
|
||||
static async activateChat(peer: Peer) {
|
||||
return await callNTQQApi({
|
||||
methodName: NTQQApiMethod.ADD_ACTIVE_CHAT,
|
||||
args: [{peer, cnt: 20}]
|
||||
})
|
||||
}
|
||||
static async recallMsg(peer: Peer, msgIds: string[]) {
|
||||
return await callNTQQApi({
|
||||
methodName: NTQQApiMethod.RECALL_MSG,
|
||||
args: [{
|
||||
peer,
|
||||
msgIds
|
||||
}, null]
|
||||
})
|
||||
}
|
||||
|
||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[],
|
||||
waitComplete = true, timeout = 10000) {
|
||||
const peerUid = peer.peerUid
|
||||
|
||||
// 等待上一个相同的peer发送完
|
||||
let checkLastSendUsingTime = 0;
|
||||
const waitLastSend = async () => {
|
||||
if (checkLastSendUsingTime > timeout) {
|
||||
throw ("发送超时")
|
||||
}
|
||||
let lastSending = sendMessagePool[peer.peerUid]
|
||||
if (lastSending) {
|
||||
// log("有正在发送的消息,等待中...")
|
||||
await sleep(500);
|
||||
checkLastSendUsingTime += 500;
|
||||
return await waitLastSend();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await waitLastSend();
|
||||
|
||||
let sentMessage: RawMessage = null;
|
||||
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
||||
delete sendMessagePool[peerUid];
|
||||
sentMessage = rawMessage;
|
||||
}
|
||||
|
||||
let checkSendCompleteUsingTime = 0;
|
||||
const checkSendComplete = async (): Promise<RawMessage> => {
|
||||
if (sentMessage) {
|
||||
if (waitComplete) {
|
||||
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
||||
return sentMessage
|
||||
}
|
||||
} else {
|
||||
return sentMessage
|
||||
}
|
||||
// log(`给${peerUid}发送消息成功`)
|
||||
}
|
||||
checkSendCompleteUsingTime += 500
|
||||
if (checkSendCompleteUsingTime > timeout) {
|
||||
throw ('发送超时')
|
||||
}
|
||||
await sleep(500)
|
||||
return await checkSendComplete()
|
||||
}
|
||||
|
||||
callNTQQApi({
|
||||
methodName: NTQQApiMethod.SEND_MSG,
|
||||
args: [{
|
||||
msgId: "0",
|
||||
peer, msgElements,
|
||||
msgAttributeInfos: new Map(),
|
||||
}, null]
|
||||
}).then()
|
||||
return await checkSendComplete()
|
||||
}
|
||||
|
||||
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.FORWARD_MSG,
|
||||
args: [
|
||||
{
|
||||
msgIds: msgIds,
|
||||
srcContact: srcPeer,
|
||||
dstContacts: [
|
||||
destPeer
|
||||
],
|
||||
commentElements: [],
|
||||
msgAttributeInfos: new Map()
|
||||
},
|
||||
null,
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||
const msgInfos = msgIds.map(id => {
|
||||
return {msgId: id, senderShowName: selfInfo.nick}
|
||||
})
|
||||
const apiArgs = [
|
||||
{
|
||||
msgInfos,
|
||||
srcContact: srcPeer,
|
||||
dstContact: destPeer,
|
||||
commentElements: [],
|
||||
msgAttributeInfos: new Map()
|
||||
},
|
||||
null,
|
||||
]
|
||||
return await new Promise<RawMessage>((resolve, reject) => {
|
||||
let complete = false
|
||||
setTimeout(() => {
|
||||
if (!complete) {
|
||||
reject("转发消息超时");
|
||||
}
|
||||
}, 5000)
|
||||
registerReceiveHook(ReceiveCmdS.SELF_SEND_MSG, async (payload: { msgRecord: RawMessage }) => {
|
||||
const msg = payload.msgRecord
|
||||
// 需要判断它是转发的消息,并且识别到是当前转发的这一条
|
||||
const arkElement = msg.elements.find(ele => ele.arkElement)
|
||||
if (!arkElement) {
|
||||
// log("收到的不是转发消息")
|
||||
return
|
||||
}
|
||||
const forwardData: any = JSON.parse(arkElement.arkElement.bytesData)
|
||||
if (forwardData.app != 'com.tencent.multimsg') {
|
||||
return
|
||||
}
|
||||
if (msg.peerUid == destPeer.peerUid && msg.senderUid == selfInfo.uid) {
|
||||
complete = true
|
||||
await dbUtil.addMsg(msg)
|
||||
resolve(msg)
|
||||
log('转发消息成功:', payload)
|
||||
}
|
||||
})
|
||||
callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.MULTI_FORWARD_MSG,
|
||||
args: apiArgs
|
||||
}).then(result => {
|
||||
log("转发消息结果:", result, apiArgs)
|
||||
if (result.result !== 0) {
|
||||
complete = true;
|
||||
reject("转发消息失败," + JSON.stringify(result));
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
57
src/ntqqapi/api/user.ts
Normal file
57
src/ntqqapi/api/user.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||
import {SelfInfo, User} from "../types";
|
||||
import {ReceiveCmdS} from "../hook";
|
||||
import {uidMaps} from "../../common/data";
|
||||
|
||||
|
||||
export class NTQQUserApi{
|
||||
static async setQQAvatar(filePath: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_QQ_AVATAR,
|
||||
args: [{
|
||||
path:filePath
|
||||
}, null],
|
||||
timeoutSecond: 10 // 10秒不一定够
|
||||
});
|
||||
}
|
||||
|
||||
static async getSelfInfo() {
|
||||
return await callNTQQApi<SelfInfo>({
|
||||
className: NTQQApiClass.GLOBAL_DATA,
|
||||
methodName: NTQQApiMethod.SELF_INFO, timeoutSecond: 2
|
||||
})
|
||||
}
|
||||
static async getUserInfo(uid: string) {
|
||||
const result = await callNTQQApi<{ profiles: Map<string, User> }>({
|
||||
methodName: NTQQApiMethod.USER_INFO,
|
||||
args: [{force: true, uids: [uid]}, undefined],
|
||||
cbCmd: ReceiveCmdS.USER_INFO
|
||||
})
|
||||
return result.profiles.get(uid)
|
||||
}
|
||||
static async getUserDetailInfo(uid: string) {
|
||||
const result = await callNTQQApi<{ info: User }>({
|
||||
methodName: NTQQApiMethod.USER_DETAIL_INFO,
|
||||
cbCmd: ReceiveCmdS.USER_DETAIL_INFO,
|
||||
afterFirstCmd: false,
|
||||
cmdCB: (payload) => {
|
||||
const success = payload.info.uid == uid
|
||||
// log("get user detail info", success, uid, payload)
|
||||
return success
|
||||
},
|
||||
args: [
|
||||
{
|
||||
uid
|
||||
},
|
||||
null
|
||||
]
|
||||
})
|
||||
const info = result.info
|
||||
if (info?.uin) {
|
||||
uidMaps[info.uid] = info.uin
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -11,10 +11,10 @@ import {
|
||||
SendTextElement,
|
||||
SendVideoElement
|
||||
} from "./types";
|
||||
import {NTQQApi} from "./ntcall";
|
||||
import {calculateFileMD5, encodeSilk, getVideoInfo, isGIF, log, sleep} from "../common/utils";
|
||||
import {promises as fs} from "node:fs";
|
||||
import ffmpeg from "fluent-ffmpeg"
|
||||
import {NTQQFileApi} from "./api/file";
|
||||
|
||||
|
||||
export class SendMsgElementConstructor {
|
||||
@ -60,11 +60,11 @@ export class SendMsgElementConstructor {
|
||||
}
|
||||
|
||||
static async pic(picPath: string): Promise<SendPicElement> {
|
||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(picPath, ElementType.PIC);
|
||||
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC);
|
||||
if (fileSize === 0) {
|
||||
throw "文件异常,大小为0";
|
||||
}
|
||||
const imageSize = await NTQQApi.getImageSize(picPath);
|
||||
const imageSize = await NTQQFileApi.getImageSize(picPath);
|
||||
const picElement = {
|
||||
md5HexStr: md5,
|
||||
fileSize: fileSize,
|
||||
@ -89,7 +89,7 @@ export class SendMsgElementConstructor {
|
||||
}
|
||||
|
||||
static async file(filePath: string, fileName: string = ""): Promise<SendFileElement> {
|
||||
const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE);
|
||||
const {md5, fileName: _fileName, path, fileSize} = await NTQQFileApi.uploadFile(filePath, ElementType.FILE);
|
||||
if (fileSize === 0) {
|
||||
throw "文件异常,大小为0";
|
||||
}
|
||||
@ -107,7 +107,7 @@ export class SendMsgElementConstructor {
|
||||
}
|
||||
|
||||
static async video(filePath: string, fileName: string = ""): Promise<SendVideoElement> {
|
||||
let {fileName: _fileName, path, fileSize, md5} = await NTQQApi.uploadFile(filePath, ElementType.VIDEO);
|
||||
let {fileName: _fileName, path, fileSize, md5} = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO);
|
||||
if (fileSize === 0) {
|
||||
throw "文件异常,大小为0";
|
||||
}
|
||||
@ -177,7 +177,7 @@ export class SendMsgElementConstructor {
|
||||
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);
|
||||
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(silkPath, ElementType.PTT);
|
||||
if (fileSize === 0) {
|
||||
throw "文件异常,大小为0";
|
||||
}
|
||||
|
@ -1,36 +1,41 @@
|
||||
import {BrowserWindow} from 'electron';
|
||||
import {getConfigUtil, log, sleep} from "../common/utils";
|
||||
import {NTQQApi, NTQQApiClass, sendMessagePool} from "./ntcall";
|
||||
import {NTQQApiClass} from "./ntcall";
|
||||
import {sendMessagePool} from "./api/msg"
|
||||
import {Group, RawMessage, User} from "./types";
|
||||
import {friends, groups, selfInfo, tempGroupCodeMap} from "../common/data";
|
||||
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
||||
import {OB11GroupIncreaseEvent} from "../onebot11/event/notice/OB11GroupIncreaseEvent";
|
||||
import {v4 as uuidv4} from "uuid"
|
||||
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
||||
import {HOOK_LOG} from "../common/config";
|
||||
import fs from "fs";
|
||||
import {dbUtil} from "../common/db";
|
||||
import {NTQQGroupApi} from "./api/group";
|
||||
|
||||
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
||||
|
||||
export enum ReceiveCmd {
|
||||
UPDATE_MSG = "nodeIKernelMsgListener/onMsgInfoListUpdate",
|
||||
NEW_MSG = "nodeIKernelMsgListener/onRecvMsg",
|
||||
SELF_SEND_MSG = "nodeIKernelMsgListener/onAddSendMsg",
|
||||
USER_INFO = "nodeIKernelProfileListener/onProfileSimpleChanged",
|
||||
USER_DETAIL_INFO = "nodeIKernelProfileListener/onProfileDetailInfoChanged",
|
||||
GROUPS = "nodeIKernelGroupListener/onGroupListUpdate",
|
||||
GROUPS_UNIX = "onGroupListUpdate",
|
||||
FRIENDS = "onBuddyListChange",
|
||||
MEDIA_DOWNLOAD_COMPLETE = "nodeIKernelMsgListener/onRichMediaDownloadComplete",
|
||||
UNREAD_GROUP_NOTIFY = "nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated",
|
||||
GROUP_NOTIFY = "nodeIKernelGroupListener/onGroupSingleScreenNotifies",
|
||||
FRIEND_REQUEST = "nodeIKernelBuddyListener/onBuddyReqChange",
|
||||
SELF_STATUS = 'nodeIKernelProfileListener/onSelfStatusChanged',
|
||||
CACHE_SCAN_FINISH = "nodeIKernelStorageCleanListener/onFinishScan",
|
||||
MEDIA_UPLOAD_COMPLETE = "nodeIKernelMsgListener/onRichMediaUploadComplete",
|
||||
export let ReceiveCmdS = {
|
||||
UPDATE_MSG: "nodeIKernelMsgListener/onMsgInfoListUpdate",
|
||||
UPDATE_ACTIVE_MSG: "nodeIKernelMsgListener/onActiveMsgInfoUpdate",
|
||||
NEW_MSG: `nodeIKernelMsgListener/onRecvMsg`,
|
||||
NEW_ACTIVE_MSG: `nodeIKernelMsgListener/onRecvActiveMsg`,
|
||||
SELF_SEND_MSG: "nodeIKernelMsgListener/onAddSendMsg",
|
||||
USER_INFO: "nodeIKernelProfileListener/onProfileSimpleChanged",
|
||||
USER_DETAIL_INFO: "nodeIKernelProfileListener/onProfileDetailInfoChanged",
|
||||
GROUPS: "nodeIKernelGroupListener/onGroupListUpdate",
|
||||
GROUPS_UNIX: "onGroupListUpdate",
|
||||
FRIENDS: "onBuddyListChange",
|
||||
MEDIA_DOWNLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaDownloadComplete",
|
||||
UNREAD_GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated",
|
||||
GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupSingleScreenNotifies",
|
||||
FRIEND_REQUEST: "nodeIKernelBuddyListener/onBuddyReqChange",
|
||||
SELF_STATUS: 'nodeIKernelProfileListener/onSelfStatusChanged',
|
||||
CACHE_SCAN_FINISH: "nodeIKernelStorageCleanListener/onFinishScan",
|
||||
MEDIA_UPLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaUploadComplete",
|
||||
}
|
||||
|
||||
export type ReceiveCmd = typeof ReceiveCmdS[keyof typeof ReceiveCmdS]
|
||||
|
||||
interface NTQQApiReturnData<PayloadType = unknown> extends Array<any> {
|
||||
0: {
|
||||
"type": "request",
|
||||
@ -46,7 +51,7 @@ interface NTQQApiReturnData<PayloadType = unknown> extends Array<any> {
|
||||
}
|
||||
|
||||
let receiveHooks: Array<{
|
||||
method: ReceiveCmd,
|
||||
method: ReceiveCmd[],
|
||||
hookFunc: ((payload: any) => void | Promise<void>)
|
||||
id: string
|
||||
}> = []
|
||||
@ -66,7 +71,7 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
|
||||
const ntQQApiMethodName = receiveData.cmdName;
|
||||
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
||||
for (let hook of receiveHooks) {
|
||||
if (hook.method === ntQQApiMethodName) {
|
||||
if (hook.method.includes(ntQQApiMethodName)) {
|
||||
new Promise((resolve, reject) => {
|
||||
try {
|
||||
let _ = hook.hookFunc(receiveData.payload)
|
||||
@ -121,8 +126,11 @@ export function hookNTQQApiCall(window: BrowserWindow) {
|
||||
}
|
||||
}
|
||||
|
||||
export function registerReceiveHook<PayloadType>(method: ReceiveCmd, hookFunc: (payload: PayloadType) => void): string {
|
||||
export function registerReceiveHook<PayloadType>(method: ReceiveCmd | ReceiveCmd[], hookFunc: (payload: PayloadType) => void): string {
|
||||
const id = uuidv4()
|
||||
if (!Array.isArray(method)) {
|
||||
method = [method]
|
||||
}
|
||||
receiveHooks.push({
|
||||
method,
|
||||
hookFunc,
|
||||
@ -147,7 +155,7 @@ async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
||||
}
|
||||
|
||||
if (needUpdate) {
|
||||
const members = await NTQQApi.getGroupMembers(group.groupCode);
|
||||
const members = await NTQQGroupApi.getGroupMembers(group.groupCode);
|
||||
|
||||
if (members) {
|
||||
existGroup.members = members;
|
||||
@ -166,7 +174,7 @@ async function processGroupEvent(payload) {
|
||||
const oldMembers = existGroup.members;
|
||||
|
||||
await sleep(200); // 如果请求QQ API的速度过快,通常无法正确拉取到最新的群信息,因此这里人为引入一个延时
|
||||
const newMembers = await NTQQApi.getGroupMembers(group.groupCode);
|
||||
const newMembers = await NTQQGroupApi.getGroupMembers(group.groupCode);
|
||||
|
||||
group.members = newMembers;
|
||||
const newMembersSet = new Set<string>(); // 建立索引降低时间复杂度
|
||||
@ -193,7 +201,7 @@ async function processGroupEvent(payload) {
|
||||
}
|
||||
|
||||
// 群列表变动
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUPS, (payload) => {
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS, (payload) => {
|
||||
if (payload.updateType != 2) {
|
||||
updateGroups(payload.groupList).then();
|
||||
} else {
|
||||
@ -202,7 +210,7 @@ registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUP
|
||||
}
|
||||
}
|
||||
})
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUPS_UNIX, (payload) => {
|
||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS_UNIX, (payload) => {
|
||||
if (payload.updateType != 2) {
|
||||
updateGroups(payload.groupList).then();
|
||||
} else {
|
||||
@ -215,7 +223,7 @@ registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUP
|
||||
// 好友列表变动
|
||||
registerReceiveHook<{
|
||||
data: { categoryId: number, categroyName: string, categroyMbCount: number, buddyList: User[] }[]
|
||||
}>(ReceiveCmd.FRIENDS, payload => {
|
||||
}>(ReceiveCmdS.FRIENDS, payload => {
|
||||
for (const fData of payload.data) {
|
||||
const _friends = fData.buddyList;
|
||||
for (let friend of _friends) {
|
||||
@ -230,7 +238,7 @@ registerReceiveHook<{
|
||||
})
|
||||
|
||||
// 新消息
|
||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload) => {
|
||||
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => {
|
||||
const {autoDeleteFile} = getConfigUtil().getConfig();
|
||||
if (!autoDeleteFile) {
|
||||
return
|
||||
@ -270,7 +278,7 @@ registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload
|
||||
}
|
||||
})
|
||||
|
||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, ({msgRecord}) => {
|
||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, ({msgRecord}) => {
|
||||
const message = msgRecord;
|
||||
const peerUid = message.peerUid;
|
||||
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
||||
@ -286,6 +294,6 @@ registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, ({msgRe
|
||||
}
|
||||
})
|
||||
|
||||
registerReceiveHook<{ info: { status: number } }>(ReceiveCmd.SELF_STATUS, (info) => {
|
||||
registerReceiveHook<{ info: { status: number } }>(ReceiveCmdS.SELF_STATUS, (info) => {
|
||||
selfInfo.online = info.info.status !== 20
|
||||
})
|
||||
|
@ -1,42 +1,8 @@
|
||||
import {BrowserWindow, ipcMain} from "electron";
|
||||
import {ipcMain} from "electron";
|
||||
import {hookApiCallbacks, ReceiveCmd, registerReceiveHook, removeReceiveHook} from "./hook";
|
||||
import {log, sleep} from "../common/utils";
|
||||
import {
|
||||
ChatType,
|
||||
ElementType,
|
||||
Friend,
|
||||
FriendRequest,
|
||||
Group,
|
||||
GroupMember,
|
||||
GroupMemberRole,
|
||||
GroupNotifies,
|
||||
GroupNotify,
|
||||
GroupRequestOperateTypes,
|
||||
RawMessage,
|
||||
SelfInfo,
|
||||
SendMessageElement,
|
||||
User,
|
||||
CacheScanResult,
|
||||
ChatCacheList, ChatCacheListItemBasic,
|
||||
CacheFileList, CacheFileListItem, CacheFileType,
|
||||
} from "./types";
|
||||
import * as fs from "fs";
|
||||
import {friendRequests, selfInfo, uidMaps} from "../common/data";
|
||||
import {log} from "../common/utils";
|
||||
|
||||
import {v4 as uuidv4} from "uuid"
|
||||
import path from "path";
|
||||
import {dbUtil} from "../common/db";
|
||||
|
||||
interface IPCReceiveEvent {
|
||||
eventName: string
|
||||
callbackId: string
|
||||
}
|
||||
|
||||
export type IPCReceiveDetail = [
|
||||
{
|
||||
cmdName: NTQQApiMethod
|
||||
payload: unknown
|
||||
},
|
||||
]
|
||||
|
||||
export enum NTQQApiClass {
|
||||
NT_API = "ns-ntApi",
|
||||
@ -49,7 +15,7 @@ export enum NTQQApiClass {
|
||||
}
|
||||
|
||||
export enum NTQQApiMethod {
|
||||
SET_HEADER = "nodeIKernelProfileService/setHeader",
|
||||
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
||||
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
||||
SELF_INFO = "fetchAuthData",
|
||||
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
||||
@ -106,12 +72,6 @@ enum NTQQApiChannel {
|
||||
IPC_UP_1 = "IPC_UP_1",
|
||||
}
|
||||
|
||||
export interface Peer {
|
||||
chatType: ChatType
|
||||
peerUid: string // 如果是群聊uid为群号,私聊uid就是加密的字符串
|
||||
guildId?: ""
|
||||
}
|
||||
|
||||
interface NTQQApiParams {
|
||||
methodName: NTQQApiMethod | string,
|
||||
className?: NTQQApiClass,
|
||||
@ -124,7 +84,7 @@ interface NTQQApiParams {
|
||||
timeoutSecond?: number,
|
||||
}
|
||||
|
||||
function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
||||
export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
||||
let {
|
||||
className, methodName, channel, args,
|
||||
cbCmd, timeoutSecond: timeout,
|
||||
@ -199,574 +159,13 @@ function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
||||
}
|
||||
|
||||
|
||||
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {}// peerUid: callbackFunnc
|
||||
|
||||
interface GeneralCallResult {
|
||||
export interface GeneralCallResult {
|
||||
result: number, // 0: success
|
||||
errMsg: string
|
||||
}
|
||||
|
||||
|
||||
export class NTQQApi {
|
||||
static async setHeader(path: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_HEADER,
|
||||
args: [path]
|
||||
})
|
||||
}
|
||||
|
||||
static async likeFriend(uid: string, count = 1) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.LIKE_FRIEND,
|
||||
args: [{
|
||||
doLikeUserInfo: {
|
||||
friendUid: uid,
|
||||
sourceId: 71,
|
||||
doLikeCount: count,
|
||||
doLikeTollCount: 0
|
||||
}
|
||||
}, null]
|
||||
})
|
||||
}
|
||||
|
||||
static async getSelfInfo() {
|
||||
return await callNTQQApi<SelfInfo>({
|
||||
className: NTQQApiClass.GLOBAL_DATA,
|
||||
methodName: NTQQApiMethod.SELF_INFO, timeoutSecond: 2
|
||||
})
|
||||
}
|
||||
|
||||
static async getUserInfo(uid: string) {
|
||||
const result = await callNTQQApi<{ profiles: Map<string, User> }>({
|
||||
methodName: NTQQApiMethod.USER_INFO,
|
||||
args: [{force: true, uids: [uid]}, undefined],
|
||||
cbCmd: ReceiveCmd.USER_INFO
|
||||
})
|
||||
return result.profiles.get(uid)
|
||||
}
|
||||
|
||||
static async getUserDetailInfo(uid: string) {
|
||||
const result = await callNTQQApi<{ info: User }>({
|
||||
methodName: NTQQApiMethod.USER_DETAIL_INFO,
|
||||
cbCmd: ReceiveCmd.USER_DETAIL_INFO,
|
||||
afterFirstCmd: false,
|
||||
cmdCB: (payload) => {
|
||||
const success = payload.info.uid == uid
|
||||
// log("get user detail info", success, uid, payload)
|
||||
return success
|
||||
},
|
||||
args: [
|
||||
{
|
||||
uid
|
||||
},
|
||||
null
|
||||
]
|
||||
})
|
||||
const info = result.info
|
||||
if (info?.uin) {
|
||||
uidMaps[info.uid] = info.uin
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
static async getFriends(forced = false) {
|
||||
const data = await callNTQQApi<{
|
||||
data: {
|
||||
categoryId: number,
|
||||
categroyName: string,
|
||||
categroyMbCount: number,
|
||||
buddyList: Friend[]
|
||||
}[]
|
||||
}>(
|
||||
{
|
||||
methodName: NTQQApiMethod.FRIENDS,
|
||||
args: [{force_update: forced}, undefined],
|
||||
cbCmd: ReceiveCmd.FRIENDS
|
||||
})
|
||||
let _friends: Friend[] = [];
|
||||
for (const fData of data.data) {
|
||||
_friends.push(...fData.buddyList)
|
||||
}
|
||||
return _friends
|
||||
}
|
||||
|
||||
static async getGroups(forced = false) {
|
||||
let cbCmd = ReceiveCmd.GROUPS
|
||||
if (process.platform != "win32") {
|
||||
cbCmd = ReceiveCmd.GROUPS_UNIX
|
||||
}
|
||||
const result = await callNTQQApi<{
|
||||
updateType: number,
|
||||
groupList: Group[]
|
||||
}>({methodName: NTQQApiMethod.GROUPS, args: [{force_update: forced}, undefined], cbCmd})
|
||||
return result.groupList
|
||||
}
|
||||
|
||||
static async getGroupMembers(groupQQ: string, num = 3000): Promise<GroupMember[]> {
|
||||
const sceneId = await callNTQQApi({
|
||||
methodName: NTQQApiMethod.GROUP_MEMBER_SCENE,
|
||||
args: [{
|
||||
groupCode: groupQQ,
|
||||
scene: "groupMemberList_MainWindow"
|
||||
}]
|
||||
})
|
||||
// log("get group member sceneId", sceneId);
|
||||
try {
|
||||
const result = await callNTQQApi<{
|
||||
result: { infos: any }
|
||||
}>({
|
||||
methodName: NTQQApiMethod.GROUP_MEMBERS,
|
||||
args: [{
|
||||
sceneId: sceneId,
|
||||
num: num
|
||||
},
|
||||
null
|
||||
]
|
||||
})
|
||||
// log("members info", typeof result.result.infos, Object.keys(result.result.infos))
|
||||
const values = result.result.infos.values()
|
||||
|
||||
const members: GroupMember[] = Array.from(values)
|
||||
for (const member of members) {
|
||||
uidMaps[member.uid] = member.uin;
|
||||
}
|
||||
// log(uidMaps);
|
||||
// log("members info", values);
|
||||
log(`get group ${groupQQ} members success`)
|
||||
return members
|
||||
} catch (e) {
|
||||
log(`get group ${groupQQ} members failed`, e)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
static async getFileType(filePath: string) {
|
||||
return await callNTQQApi<{ ext: string }>({
|
||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_TYPE, args: [filePath]
|
||||
})
|
||||
}
|
||||
|
||||
static async getFileMd5(filePath: string) {
|
||||
return await callNTQQApi<string>({
|
||||
className: NTQQApiClass.FS_API,
|
||||
methodName: NTQQApiMethod.FILE_MD5,
|
||||
args: [filePath]
|
||||
})
|
||||
}
|
||||
|
||||
static async copyFile(filePath: string, destPath: string) {
|
||||
return await callNTQQApi<string>({
|
||||
className: NTQQApiClass.FS_API,
|
||||
methodName: NTQQApiMethod.FILE_COPY,
|
||||
args: [{
|
||||
fromPath: filePath,
|
||||
toPath: destPath
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
static async getImageSize(filePath: string) {
|
||||
return await callNTQQApi<{ width: number, height: number }>({
|
||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.IMAGE_SIZE, args: [filePath]
|
||||
})
|
||||
}
|
||||
|
||||
static async getFileSize(filePath: string) {
|
||||
return await callNTQQApi<number>({
|
||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_SIZE, args: [filePath]
|
||||
})
|
||||
}
|
||||
|
||||
// 上传文件到QQ的文件夹
|
||||
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
||||
const md5 = await NTQQApi.getFileMd5(filePath);
|
||||
let ext = (await NTQQApi.getFileType(filePath))?.ext
|
||||
if (ext) {
|
||||
ext = "." + ext
|
||||
} else {
|
||||
ext = ""
|
||||
}
|
||||
let fileName = `${path.basename(filePath)}`;
|
||||
if (fileName.indexOf(".") === -1) {
|
||||
fileName += ext;
|
||||
}
|
||||
const mediaPath = await callNTQQApi<string>({
|
||||
methodName: NTQQApiMethod.MEDIA_FILE_PATH,
|
||||
args: [{
|
||||
path_info: {
|
||||
md5HexStr: md5,
|
||||
fileName: fileName,
|
||||
elementType: elementType,
|
||||
elementSubType: 0,
|
||||
thumbSize: 0,
|
||||
needCreate: true,
|
||||
downloadType: 1,
|
||||
file_uuid: ""
|
||||
}
|
||||
}]
|
||||
})
|
||||
log("media path", mediaPath)
|
||||
await NTQQApi.copyFile(filePath, mediaPath);
|
||||
const fileSize = await NTQQApi.getFileSize(filePath);
|
||||
return {
|
||||
md5,
|
||||
fileName,
|
||||
path: mediaPath,
|
||||
fileSize
|
||||
}
|
||||
}
|
||||
|
||||
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string) {
|
||||
// 用于下载收到的消息中的图片等
|
||||
if (fs.existsSync(sourcePath)) {
|
||||
return sourcePath
|
||||
}
|
||||
const apiParams = [
|
||||
{
|
||||
getReq: {
|
||||
msgId: msgId,
|
||||
chatType: chatType,
|
||||
peerUid: peerUid,
|
||||
elementId: elementId,
|
||||
thumbSize: 0,
|
||||
downloadType: 1,
|
||||
filePath: thumbPath,
|
||||
},
|
||||
},
|
||||
undefined,
|
||||
]
|
||||
// log("需要下载media", sourcePath);
|
||||
await callNTQQApi({
|
||||
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
||||
args: apiParams,
|
||||
cbCmd: ReceiveCmd.MEDIA_DOWNLOAD_COMPLETE,
|
||||
cmdCB: (payload: { notifyInfo: { filePath: string } }) => {
|
||||
// log("media 下载完成判断", payload.notifyInfo.filePath, sourcePath);
|
||||
return payload.notifyInfo.filePath == sourcePath;
|
||||
}
|
||||
})
|
||||
return sourcePath
|
||||
}
|
||||
|
||||
static async recallMsg(peer: Peer, msgIds: string[]) {
|
||||
return await callNTQQApi({
|
||||
methodName: NTQQApiMethod.RECALL_MSG,
|
||||
args: [{
|
||||
peer,
|
||||
msgIds
|
||||
}, null]
|
||||
})
|
||||
}
|
||||
|
||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
||||
const peerUid = peer.peerUid
|
||||
|
||||
// 等待上一个相同的peer发送完
|
||||
let checkLastSendUsingTime = 0;
|
||||
const waitLastSend = async () => {
|
||||
if (checkLastSendUsingTime > timeout) {
|
||||
throw ("发送超时")
|
||||
}
|
||||
let lastSending = sendMessagePool[peer.peerUid]
|
||||
if (lastSending) {
|
||||
// log("有正在发送的消息,等待中...")
|
||||
await sleep(500);
|
||||
checkLastSendUsingTime += 500;
|
||||
return await waitLastSend();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await waitLastSend();
|
||||
|
||||
let sentMessage: RawMessage = null;
|
||||
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
||||
delete sendMessagePool[peerUid];
|
||||
sentMessage = rawMessage;
|
||||
}
|
||||
|
||||
let checkSendCompleteUsingTime = 0;
|
||||
const checkSendComplete = async (): Promise<RawMessage> => {
|
||||
if (sentMessage) {
|
||||
if (waitComplete) {
|
||||
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
||||
return sentMessage
|
||||
}
|
||||
} else {
|
||||
return sentMessage
|
||||
}
|
||||
// log(`给${peerUid}发送消息成功`)
|
||||
}
|
||||
checkSendCompleteUsingTime += 500
|
||||
if (checkSendCompleteUsingTime > timeout) {
|
||||
throw ('发送超时')
|
||||
}
|
||||
await sleep(500)
|
||||
return await checkSendComplete()
|
||||
}
|
||||
|
||||
callNTQQApi({
|
||||
methodName: NTQQApiMethod.SEND_MSG,
|
||||
args: [{
|
||||
msgId: "0",
|
||||
peer, msgElements,
|
||||
msgAttributeInfos: new Map(),
|
||||
}, null]
|
||||
}).then()
|
||||
return await checkSendComplete()
|
||||
}
|
||||
|
||||
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.FORWARD_MSG,
|
||||
args: [
|
||||
{
|
||||
msgIds: msgIds,
|
||||
srcContact: srcPeer,
|
||||
dstContacts: [
|
||||
destPeer
|
||||
],
|
||||
commentElements: [],
|
||||
msgAttributeInfos: new Map()
|
||||
},
|
||||
null,
|
||||
]
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||
const msgInfos = msgIds.map(id => {
|
||||
return {msgId: id, senderShowName: selfInfo.nick}
|
||||
})
|
||||
const apiArgs = [
|
||||
{
|
||||
msgInfos,
|
||||
srcContact: srcPeer,
|
||||
dstContact: destPeer,
|
||||
commentElements: [],
|
||||
msgAttributeInfos: new Map()
|
||||
},
|
||||
null,
|
||||
]
|
||||
return await new Promise<RawMessage>((resolve, reject) => {
|
||||
let complete = false
|
||||
setTimeout(() => {
|
||||
if (!complete) {
|
||||
reject("转发消息超时");
|
||||
}
|
||||
}, 5000)
|
||||
registerReceiveHook(ReceiveCmd.SELF_SEND_MSG, async (payload: { msgRecord: RawMessage }) => {
|
||||
const msg = payload.msgRecord
|
||||
// 需要判断它是转发的消息,并且识别到是当前转发的这一条
|
||||
const arkElement = msg.elements.find(ele => ele.arkElement)
|
||||
if (!arkElement) {
|
||||
// log("收到的不是转发消息")
|
||||
return
|
||||
}
|
||||
const forwardData: any = JSON.parse(arkElement.arkElement.bytesData)
|
||||
if (forwardData.app != 'com.tencent.multimsg') {
|
||||
return
|
||||
}
|
||||
if (msg.peerUid == destPeer.peerUid && msg.senderUid == selfInfo.uid) {
|
||||
complete = true
|
||||
await dbUtil.addMsg(msg)
|
||||
resolve(msg)
|
||||
log('转发消息成功:', payload)
|
||||
}
|
||||
})
|
||||
callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.MULTI_FORWARD_MSG,
|
||||
args: apiArgs
|
||||
}).then(result => {
|
||||
log("转发消息结果:", result, apiArgs)
|
||||
if (result.result !== 0) {
|
||||
complete = true;
|
||||
reject("转发消息失败," + JSON.stringify(result));
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
static async getGroupNotifies() {
|
||||
// 获取管理员变更
|
||||
// 加群通知,退出通知,需要管理员权限
|
||||
callNTQQApi<GeneralCallResult>({
|
||||
methodName: ReceiveCmd.GROUP_NOTIFY,
|
||||
classNameIsRegister: true,
|
||||
}).then()
|
||||
return await callNTQQApi<GroupNotifies>({
|
||||
methodName: NTQQApiMethod.GET_GROUP_NOTICE,
|
||||
cbCmd: ReceiveCmd.GROUP_NOTIFY,
|
||||
afterFirstCmd: false,
|
||||
args: [
|
||||
{"doubt": false, "startSeq": "", "number": 14},
|
||||
null
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
static async getGroupIgnoreNotifies() {
|
||||
await NTQQApi.getGroupNotifies();
|
||||
const result = callNTQQApi<GroupNotifies>({
|
||||
className: NTQQApiClass.WINDOW_API,
|
||||
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
|
||||
cbCmd: ReceiveCmd.GROUP_NOTIFY,
|
||||
afterFirstCmd: false,
|
||||
args: [
|
||||
"GroupNotifyFilterWindow"
|
||||
]
|
||||
})
|
||||
// 关闭窗口
|
||||
setTimeout(() => {
|
||||
for (const w of BrowserWindow.getAllWindows()) {
|
||||
// log("close window", w.webContents.getURL())
|
||||
if (w.webContents.getURL().indexOf("#/notify-filter/") != -1) {
|
||||
w.close();
|
||||
}
|
||||
}
|
||||
}, 2000);
|
||||
return result;
|
||||
}
|
||||
|
||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
||||
if (!notify) {
|
||||
throw `${seq}对应的加群通知不存在`
|
||||
}
|
||||
// delete groupNotifies[seq];
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST,
|
||||
args: [
|
||||
{
|
||||
"doubt": false,
|
||||
"operateMsg": {
|
||||
"operateType": operateType, // 2 拒绝
|
||||
"targetMsg": {
|
||||
"seq": seq, // 通知序列号
|
||||
"type": notify.type,
|
||||
"groupCode": notify.group.groupCode,
|
||||
"postscript": reason
|
||||
}
|
||||
}
|
||||
},
|
||||
null
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
static async quitGroup(groupQQ: string) {
|
||||
await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.QUIT_GROUP,
|
||||
args: [
|
||||
{"groupCode": groupQQ},
|
||||
null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static async handleFriendRequest(sourceId: number, accept: boolean,) {
|
||||
const request: FriendRequest = friendRequests[sourceId]
|
||||
if (!request) {
|
||||
throw `sourceId ${sourceId}, 对应的好友请求不存在`
|
||||
}
|
||||
const result = await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.HANDLE_FRIEND_REQUEST,
|
||||
args: [
|
||||
{
|
||||
"approvalInfo": {
|
||||
"friendUid": request.friendUid,
|
||||
"reqTime": request.reqTime,
|
||||
accept
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
delete friendRequests[sourceId];
|
||||
return result;
|
||||
}
|
||||
|
||||
static async kickMember(groupQQ: string, kickUids: string[], refuseForever: boolean = false, kickReason: string = '') {
|
||||
return await callNTQQApi<GeneralCallResult>(
|
||||
{
|
||||
methodName: NTQQApiMethod.KICK_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
kickUids,
|
||||
refuseForever,
|
||||
kickReason,
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
static async banMember(groupQQ: string, memList: Array<{ uid: string, timeStamp: number }>) {
|
||||
// timeStamp为秒数, 0为解除禁言
|
||||
return await callNTQQApi<GeneralCallResult>(
|
||||
{
|
||||
methodName: NTQQApiMethod.MUTE_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
memList,
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
static async banGroup(groupQQ: string, shutUp: boolean) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.MUTE_GROUP,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
shutUp
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
cardName
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_ROLE,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
role
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static async setGroupName(groupQQ: string, groupName: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_GROUP_NAME,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
groupName
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static async call(className: NTQQApiClass, cmdName: string, args: any[],) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
className,
|
||||
@ -777,133 +176,4 @@ export class NTQQApi {
|
||||
})
|
||||
}
|
||||
|
||||
static async setGroupTitle(groupQQ: string, uid: string, title: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_GROUP_TITLE,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid,
|
||||
title
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static publishGroupBulletin(groupQQ: string, title: string, content: string) {
|
||||
|
||||
}
|
||||
|
||||
static async setCacheSilentScan(isSilent: boolean = true) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
|
||||
args: [{
|
||||
isSilent
|
||||
}, null]
|
||||
});
|
||||
}
|
||||
|
||||
static addCacheScannedPaths(pathMap: object = {}) {
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
|
||||
args: [{
|
||||
pathMap: {...pathMap},
|
||||
}, null]
|
||||
});
|
||||
}
|
||||
|
||||
static scanCache() {
|
||||
callNTQQApi<GeneralCallResult>({
|
||||
methodName: ReceiveCmd.CACHE_SCAN_FINISH,
|
||||
classNameIsRegister: true,
|
||||
}).then();
|
||||
return callNTQQApi<CacheScanResult>({
|
||||
methodName: NTQQApiMethod.CACHE_SCAN,
|
||||
args: [null, null],
|
||||
timeoutSecond: 300,
|
||||
});
|
||||
}
|
||||
|
||||
static getHotUpdateCachePath() {
|
||||
return callNTQQApi<string>({
|
||||
className: NTQQApiClass.HOTUPDATE_API,
|
||||
methodName: NTQQApiMethod.CACHE_PATH_HOT_UPDATE
|
||||
});
|
||||
}
|
||||
|
||||
static getDesktopTmpPath() {
|
||||
return callNTQQApi<string>({
|
||||
className: NTQQApiClass.BUSINESS_API,
|
||||
methodName: NTQQApiMethod.CACHE_PATH_DESKTOP_TEMP
|
||||
});
|
||||
}
|
||||
|
||||
static getCacheSessionPathList() {
|
||||
return callNTQQApi<{
|
||||
key: string,
|
||||
value: string
|
||||
}[]>({
|
||||
className: NTQQApiClass.OS_API,
|
||||
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
|
||||
});
|
||||
}
|
||||
|
||||
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
|
||||
return callNTQQApi<any>({ // TODO: 目前还不知道真正的返回值是什么
|
||||
methodName: NTQQApiMethod.CACHE_CLEAR,
|
||||
args: [{
|
||||
keys: cacheKeys
|
||||
}, null]
|
||||
});
|
||||
}
|
||||
|
||||
static getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) {
|
||||
return new Promise<ChatCacheList>((res, rej) => {
|
||||
callNTQQApi<ChatCacheList>({
|
||||
methodName: NTQQApiMethod.CACHE_CHAT_GET,
|
||||
args: [{
|
||||
chatType: type,
|
||||
pageSize,
|
||||
order: 1,
|
||||
pageIndex
|
||||
}, null]
|
||||
}).then(list => res(list))
|
||||
.catch(e => rej(e));
|
||||
});
|
||||
}
|
||||
|
||||
static getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) {
|
||||
const _lastRecord = lastRecord ? lastRecord : {fileType: fileType};
|
||||
|
||||
return callNTQQApi<CacheFileList>({
|
||||
methodName: NTQQApiMethod.CACHE_FILE_GET,
|
||||
args: [{
|
||||
fileType: fileType,
|
||||
restart: true,
|
||||
pageSize: pageSize,
|
||||
order: 1,
|
||||
lastRecord: _lastRecord,
|
||||
}, null]
|
||||
})
|
||||
}
|
||||
|
||||
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
|
||||
args: [{
|
||||
chats,
|
||||
fileKeys
|
||||
}, null]
|
||||
});
|
||||
}
|
||||
|
||||
static async setQQAvatar(filePath: string) {
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_QQ_AVATAR,
|
||||
args: [{
|
||||
path:filePath
|
||||
}, null],
|
||||
timeoutSecond: 10 // 10秒不一定够
|
||||
});
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import fs from "fs";
|
||||
import Path from "path";
|
||||
import {
|
||||
@ -9,6 +8,7 @@ import {
|
||||
CacheFileType
|
||||
} 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
|
||||
@ -19,21 +19,21 @@ export default class CleanCache extends BaseAction<void, void> {
|
||||
// dbUtil.clearCache();
|
||||
const cacheFilePaths: string[] = [];
|
||||
|
||||
await NTQQApi.setCacheSilentScan(false);
|
||||
await NTQQFileCacheApi.setCacheSilentScan(false);
|
||||
|
||||
cacheFilePaths.push((await NTQQApi.getHotUpdateCachePath()));
|
||||
cacheFilePaths.push((await NTQQApi.getDesktopTmpPath()));
|
||||
(await NTQQApi.getCacheSessionPathList()).forEach(e => cacheFilePaths.push(e.value));
|
||||
cacheFilePaths.push((await NTQQFileCacheApi.getHotUpdateCachePath()));
|
||||
cacheFilePaths.push((await NTQQFileCacheApi.getDesktopTmpPath()));
|
||||
(await NTQQFileCacheApi.getCacheSessionPathList()).forEach(e => cacheFilePaths.push(e.value));
|
||||
|
||||
// await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
|
||||
const cacheScanResult = await NTQQApi.scanCache();
|
||||
const cacheScanResult = await NTQQFileCacheApi.scanCache();
|
||||
const cacheSize = parseInt(cacheScanResult.size[6]);
|
||||
|
||||
if (cacheScanResult.result !== 0) {
|
||||
throw('Something went wrong while scanning cache. Code: ' + cacheScanResult.result);
|
||||
}
|
||||
|
||||
await NTQQApi.setCacheSilentScan(true);
|
||||
await NTQQFileCacheApi.setCacheSilentScan(true);
|
||||
if (cacheSize > 0 && cacheFilePaths.length > 2) { // 存在缓存文件且大小不为 0 时执行清理动作
|
||||
// await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
|
||||
deleteCachePath(cacheFilePaths);
|
||||
@ -55,11 +55,11 @@ export default class CleanCache extends BaseAction<void, void> {
|
||||
const fileTypeAny: any = CacheFileType[name];
|
||||
const fileType: CacheFileType = fileTypeAny;
|
||||
|
||||
cacheFileList.push(...(await NTQQApi.getFileCacheInfo(fileType)).infos.map(file => file.fileKey));
|
||||
cacheFileList.push(...(await NTQQFileCacheApi.getFileCacheInfo(fileType)).infos.map(file => file.fileKey));
|
||||
}
|
||||
|
||||
// 一并清除
|
||||
await NTQQApi.clearChatCache(chatCacheList, cacheFileList);
|
||||
await NTQQFileCacheApi.clearChatCache(chatCacheList, cacheFileList);
|
||||
res();
|
||||
} catch(e) {
|
||||
console.error('清理缓存时发生了错误');
|
||||
@ -89,7 +89,7 @@ function deleteCachePath(pathList: string[]) {
|
||||
|
||||
function getCacheList(type: ChatType) { // NOTE: 做这个方法主要是因为目前还不支持针对频道消息的清理
|
||||
return new Promise<Array<ChatCacheListItemBasic>>((res, rej) => {
|
||||
NTQQApi.getChatCacheList(type, 1000, 0)
|
||||
NTQQFileCacheApi.getChatCacheList(type, 1000, 0)
|
||||
.then(data => {
|
||||
const list = data.infos.filter(e => e.chatType === type && parseInt(e.basicChatCacheInfo.chatSize) > 0);
|
||||
const result = list.map(e => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {ActionName} from "./types";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {dbUtil} from "../../common/db";
|
||||
import {NTQQMsgApi} from "../../ntqqapi/api/msg";
|
||||
|
||||
interface Payload {
|
||||
message_id: number
|
||||
@ -12,7 +12,7 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
||||
|
||||
protected async _handle(payload: Payload) {
|
||||
let msg = await dbUtil.getMsgByShortId(payload.message_id)
|
||||
await NTQQApi.recallMsg({
|
||||
await NTQQMsgApi.recallMsg({
|
||||
chatType: msg.chatType,
|
||||
peerUid: msg.peerUid
|
||||
}, [msg.msgId])
|
||||
|
@ -1,9 +1,9 @@
|
||||
import {OB11GroupMember} from '../types';
|
||||
import {getGroup} from "../../common/data";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {OB11Constructor} from "../constructor";
|
||||
import BaseAction from "./BaseAction";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
|
||||
export interface PayloadType {
|
||||
group_id: number
|
||||
@ -17,7 +17,7 @@ class GetGroupMemberList extends BaseAction<PayloadType, OB11GroupMember[]> {
|
||||
const group = await getGroup(payload.group_id.toString());
|
||||
if (group) {
|
||||
if (!group.members?.length) {
|
||||
group.members = await NTQQApi.getGroupMembers(payload.group_id.toString())
|
||||
group.members = await NTQQGroupApi.getGroupMembers(payload.group_id.toString())
|
||||
}
|
||||
return OB11Constructor.groupMembers(group);
|
||||
} else {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {getFriend, getUidByUin, uidMaps} from "../../common/data";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
import {log} from "../../common/utils";
|
||||
import {NTQQFriendApi} from "../../ntqqapi/api/friend";
|
||||
|
||||
interface Payload {
|
||||
user_id: number,
|
||||
@ -23,7 +23,7 @@ export default class SendLike extends BaseAction<Payload, null> {
|
||||
} else {
|
||||
uid = friend.uid
|
||||
}
|
||||
let result = await NTQQApi.likeFriend(uid, parseInt(payload.times?.toString()) || 1);
|
||||
let result = await NTQQFriendApi.likeFriend(uid, parseInt(payload.times?.toString()) || 1);
|
||||
if (result.result !== 0) {
|
||||
throw result.errMsg
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
OB11MessageNode,
|
||||
OB11PostSendMsg
|
||||
} from '../types';
|
||||
import {NTQQApi, Peer} from "../../ntqqapi/ntcall";
|
||||
import {Peer} from "../../ntqqapi/api/msg";
|
||||
import {SendMsgElementConstructor} from "../../ntqqapi/constructor";
|
||||
import {uri2local} from "../utils";
|
||||
import BaseAction from "./BaseAction";
|
||||
@ -26,6 +26,7 @@ import {log, sleep} 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";
|
||||
|
||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||
function checkUri(uri: string): boolean {
|
||||
@ -208,7 +209,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
log("克隆消息", sendElements)
|
||||
try {
|
||||
const nodeMsg = await NTQQApi.sendMsg({
|
||||
const nodeMsg = await NTQQMsgApi.sendMsg({
|
||||
chatType: ChatType.friend,
|
||||
peerUid: selfInfo.uid
|
||||
}, sendElements, true);
|
||||
@ -330,7 +331,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
// 开发转发
|
||||
try {
|
||||
log("开发转发", nodeMsgIds)
|
||||
return await NTQQApi.multiForwardMsg(srcPeer, destPeer, nodeMsgIds)
|
||||
return await NTQQMsgApi.multiForwardMsg(srcPeer, destPeer, nodeMsgIds)
|
||||
} catch (e) {
|
||||
log("forward failed", e)
|
||||
return null;
|
||||
@ -449,7 +450,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
if (!sendElements.length) {
|
||||
throw ("消息体无法解析")
|
||||
}
|
||||
const returnMsg = await NTQQApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
||||
log("消息发送结果", returnMsg)
|
||||
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQFriendApi} from "../../ntqqapi/api/friend";
|
||||
|
||||
interface Payload {
|
||||
flag: string,
|
||||
@ -12,7 +12,7 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetFriendAddRequest;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
await NTQQApi.handleFriendRequest(parseInt(payload.flag), payload.approve)
|
||||
await NTQQFriendApi.handleFriendRequest(parseInt(payload.flag), payload.approve)
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {GroupRequestOperateTypes} from "../../ntqqapi/types";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
flag: string,
|
||||
@ -16,7 +16,7 @@ export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const seq = payload.flag.toString();
|
||||
await NTQQApi.handleGroupRequest(seq,
|
||||
await NTQQGroupApi.handleGroupRequest(seq,
|
||||
payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||
payload.reason
|
||||
)
|
||||
|
@ -1,8 +1,8 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
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,
|
||||
@ -18,7 +18,7 @@ export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
||||
if (!member) {
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.setMemberRole(payload.group_id.toString(), member.uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
||||
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), member.uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
||||
return null
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
@ -17,7 +17,7 @@ export default class SetGroupBan extends BaseAction<Payload, null> {
|
||||
if (!member) {
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.banMember(payload.group_id.toString(),
|
||||
await NTQQGroupApi.banMember(payload.group_id.toString(),
|
||||
[{uid: member.uid, timeStamp: parseInt(payload.duration.toString())}])
|
||||
return null
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
@ -17,7 +17,7 @@ export default class SetGroupCard extends BaseAction<Payload, null> {
|
||||
if (!member) {
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || "")
|
||||
await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || "")
|
||||
return null
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
@ -17,7 +17,7 @@ export default class SetGroupKick extends BaseAction<Payload, null> {
|
||||
if (!member) {
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.kickMember(payload.group_id.toString(), [member.uid], !!payload.reject_add_request);
|
||||
await NTQQGroupApi.kickMember(payload.group_id.toString(), [member.uid], !!payload.reject_add_request);
|
||||
return null
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {log} from "../../common/utils";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
@ -13,7 +13,7 @@ export default class SetGroupLeave extends BaseAction<Payload, any> {
|
||||
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
try {
|
||||
await NTQQApi.quitGroup(payload.group_id.toString())
|
||||
await NTQQGroupApi.quitGroup(payload.group_id.toString())
|
||||
} catch (e) {
|
||||
log("退群失败", e)
|
||||
throw e
|
||||
|
@ -1,6 +1,6 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
@ -12,7 +12,7 @@ export default class SetGroupName extends BaseAction<Payload, null> {
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
await NTQQApi.setGroupName(payload.group_id.toString(), payload.group_name)
|
||||
await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name)
|
||||
return null
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
@ -12,7 +12,7 @@ export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
await NTQQApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
||||
await NTQQGroupApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
||||
return null
|
||||
}
|
||||
}
|
@ -3,9 +3,9 @@ import {getGroup} from "../../../common/data";
|
||||
import {ActionName} from "../types";
|
||||
import {SendMsgElementConstructor} from "../../../ntqqapi/constructor";
|
||||
import {ChatType, SendFileElement} from "../../../ntqqapi/types";
|
||||
import {NTQQApi} from "../../../ntqqapi/ntcall";
|
||||
import {uri2local} from "../../utils";
|
||||
import fs from "fs";
|
||||
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||
|
||||
interface Payload{
|
||||
group_id: number
|
||||
@ -31,7 +31,7 @@ export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
||||
throw new Error(downloadResult.errMsg)
|
||||
}
|
||||
let sendFileEle: SendFileElement = await SendMsgElementConstructor.file(downloadResult.path, payload.name);
|
||||
await NTQQApi.sendMsg({chatType: ChatType.group, peerUid: group.groupCode}, [sendFileEle]);
|
||||
await NTQQMsgApi.sendMsg({chatType: ChatType.group, peerUid: group.groupCode}, [sendFileEle]);
|
||||
return null
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import {GroupNotify, GroupNotifyStatus} from "../../../ntqqapi/types";
|
||||
import BaseAction from "../BaseAction";
|
||||
import {ActionName} from "../types";
|
||||
import {NTQQApi} from "../../../ntqqapi/ntcall";
|
||||
import {uidMaps} from "../../../common/data";
|
||||
import {log} from "../../../common/utils";
|
||||
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||
|
||||
interface OB11GroupRequestNotify {
|
||||
group_id: number,
|
||||
@ -15,12 +16,12 @@ export default class GetGroupAddRequest extends BaseAction<null, OB11GroupReques
|
||||
actionName = ActionName.GetGroupIgnoreAddRequest
|
||||
|
||||
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[]> {
|
||||
const data = await NTQQApi.getGroupIgnoreNotifies()
|
||||
const data = await NTQQGroupApi.getGroupIgnoreNotifies()
|
||||
log(data);
|
||||
let notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
|
||||
let returnData: OB11GroupRequestNotify[] = []
|
||||
for (const notify of notifies) {
|
||||
const uin = uidMaps[notify.user1.uid] || (await NTQQApi.getUserDetailInfo(notify.user1.uid))?.uin
|
||||
const uin = uidMaps[notify.user1.uid] || (await NTQQUserApi.getUserDetailInfo(notify.user1.uid))?.uin
|
||||
returnData.push({
|
||||
group_id: parseInt(notify.group.groupCode),
|
||||
user_id: parseInt(uin),
|
||||
|
@ -1,9 +1,9 @@
|
||||
import BaseAction from "../BaseAction";
|
||||
import {NTQQApi} from "../../../ntqqapi/ntcall";
|
||||
import {ActionName} from "../types";
|
||||
import { uri2local } from "../../utils";
|
||||
import * as fs from "node:fs";
|
||||
import { checkFileReceived } from "../../../common/utils";
|
||||
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||
// import { log } from "../../../common/utils";
|
||||
|
||||
interface Payload {
|
||||
@ -20,7 +20,7 @@ export default class SetAvatar extends BaseAction<Payload, null> {
|
||||
}
|
||||
if (path) {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQApi.setQQAvatar(path)
|
||||
const ret = await NTQQUserApi.setQQAvatar(path)
|
||||
if (!isLocal){
|
||||
fs.unlink(path, () => {})
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import {
|
||||
} from '../ntqqapi/types';
|
||||
import {getFriend, 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";
|
||||
@ -30,6 +29,8 @@ import {OB11GroupIncreaseEvent} from "./event/notice/OB11GroupIncreaseEvent";
|
||||
import {OB11GroupBanEvent} from "./event/notice/OB11GroupBanEvent";
|
||||
import {OB11GroupUploadNoticeEvent} from "./event/notice/OB11GroupUploadNoticeEvent";
|
||||
import {OB11GroupNoticeEvent} from "./event/notice/OB11GroupNoticeEvent";
|
||||
import {NTQQUserApi} from "../ntqqapi/api/user";
|
||||
import {NTQQFileApi} from "../ntqqapi/api/file";
|
||||
|
||||
|
||||
export class OB11Constructor {
|
||||
@ -144,7 +145,7 @@ export class OB11Constructor {
|
||||
fileSize: element.picElement.fileSize.toString(),
|
||||
url: message_data["data"]["url"],
|
||||
downloadFunc: async () => {
|
||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
element.elementId, element.picElement.thumbPath?.get(0) || "", element.picElement.sourcePath)
|
||||
}
|
||||
}).then()
|
||||
@ -161,7 +162,7 @@ export class OB11Constructor {
|
||||
filePath: element.videoElement.filePath,
|
||||
fileSize: element.videoElement.fileSize,
|
||||
downloadFunc: async () => {
|
||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
element.elementId, element.videoElement.thumbPath.get(0), element.videoElement.filePath)
|
||||
}
|
||||
}).then()
|
||||
@ -177,7 +178,7 @@ export class OB11Constructor {
|
||||
filePath: element.fileElement.filePath,
|
||||
fileSize: element.fileElement.fileSize,
|
||||
downloadFunc: async () => {
|
||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
element.elementId, null, element.fileElement.filePath)
|
||||
}
|
||||
}).then()
|
||||
@ -235,7 +236,7 @@ export class OB11Constructor {
|
||||
const member = await getGroupMember(msg.peerUid, groupElement.memberUid);
|
||||
let memberUin = member?.uin;
|
||||
if (!memberUin) {
|
||||
memberUin = (await NTQQApi.getUserDetailInfo(groupElement.memberUid)).uin
|
||||
memberUin = (await NTQQUserApi.getUserDetailInfo(groupElement.memberUid)).uin
|
||||
}
|
||||
// log("获取新群成员QQ", memberUin)
|
||||
const adminMember = await getGroupMember(msg.peerUid, groupElement.adminUid);
|
||||
@ -255,7 +256,7 @@ export class OB11Constructor {
|
||||
let duration = parseInt(groupElement.shutUp.duration)
|
||||
let sub_type: "ban" | "lift_ban" = duration > 0 ? "ban" : "lift_ban"
|
||||
if (memberUid){
|
||||
memberUin = (await getGroupMember(msg.peerUid, memberUid))?.uin || (await NTQQApi.getUserDetailInfo(memberUid))?.uin
|
||||
memberUin = (await getGroupMember(msg.peerUid, memberUid))?.uin || (await NTQQUserApi.getUserDetailInfo(memberUid))?.uin
|
||||
}
|
||||
else {
|
||||
memberUin = "0"; // 0表示全员禁言
|
||||
@ -263,7 +264,7 @@ export class OB11Constructor {
|
||||
duration = -1
|
||||
}
|
||||
}
|
||||
const adminUin = (await getGroupMember(msg.peerUid, adminUid))?.uin || (await NTQQApi.getUserDetailInfo(adminUid))?.uin
|
||||
const adminUin = (await getGroupMember(msg.peerUid, adminUid))?.uin || (await NTQQUserApi.getUserDetailInfo(adminUid))?.uin
|
||||
if (memberUin && adminUin) {
|
||||
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
export const version = "3.15.2"
|
||||
export const version = "3.15.3"
|
Loading…
x
Reference in New Issue
Block a user