mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Merge branch 'main' of https://github.com/disymayufei/LiteLoaderQQNT-OneBotApi
This commit is contained in:
commit
f02b0bdcad
@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "3.0.7",
|
"version": "3.0.8",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"authors": [{
|
"authors": [{
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
|
@ -78,8 +78,7 @@ function callNTQQApi<ReturnType>(channel: NTQQApiChannel, className: NTQQApiClas
|
|||||||
success = true
|
success = true
|
||||||
resolve(r)
|
resolve(r)
|
||||||
};
|
};
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// 这里的callback比较特殊,QQ后端先返回是否调用成功,再返回一条结果数据
|
// 这里的callback比较特殊,QQ后端先返回是否调用成功,再返回一条结果数据
|
||||||
hookApiCallbacks[uuid] = (result: GeneralCallResult) => {
|
hookApiCallbacks[uuid] = (result: GeneralCallResult) => {
|
||||||
log(`${methodName} callback`, result)
|
log(`${methodName} callback`, result)
|
||||||
@ -90,8 +89,7 @@ function callNTQQApi<ReturnType>(channel: NTQQApiChannel, className: NTQQApiClas
|
|||||||
success = true
|
success = true
|
||||||
resolve(payload);
|
resolve(payload);
|
||||||
})
|
})
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
success = true
|
success = true
|
||||||
reject(`ntqq api call failed, ${result.errMsg}`);
|
reject(`ntqq api call failed, ${result.errMsg}`);
|
||||||
}
|
}
|
||||||
@ -108,7 +106,7 @@ function callNTQQApi<ReturnType>(channel: NTQQApiChannel, className: NTQQApiClas
|
|||||||
ipcMain.emit(
|
ipcMain.emit(
|
||||||
channel,
|
channel,
|
||||||
{},
|
{},
|
||||||
{ type: 'request', callbackId: uuid, eventName: className + "-" + channel[channel.length - 1] },
|
{type: 'request', callbackId: uuid, eventName: className + "-" + channel[channel.length - 1]},
|
||||||
[methodName, ...args],
|
[methodName, ...args],
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -142,13 +140,17 @@ export class NTQQApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getUserInfo(uid: string) {
|
static async getUserInfo(uid: string) {
|
||||||
const result = await callNTQQApi<{ profiles: Map<string, User> }>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.USER_INFO,
|
const result = await callNTQQApi<{
|
||||||
[{ force: true, uids: [uid] }, undefined], ReceiveCmd.USER_INFO)
|
profiles: Map<string, User>
|
||||||
|
}>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.USER_INFO,
|
||||||
|
[{force: true, uids: [uid]}, undefined], ReceiveCmd.USER_INFO)
|
||||||
return result.profiles.get(uid)
|
return result.profiles.get(uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getFriends(forced = false) {
|
static async getFriends(forced = false) {
|
||||||
const data = await callNTQQApi<{ data: { categoryId: number, categroyName: string, categroyMbCount: number, buddyList: Friend[] }[] }>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.FRIENDS, [{ force_update: forced }, undefined], ReceiveCmd.FRIENDS)
|
const data = await callNTQQApi<{
|
||||||
|
data: { categoryId: number, categroyName: string, categroyMbCount: number, buddyList: Friend[] }[]
|
||||||
|
}>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.FRIENDS, [{force_update: forced}, undefined], ReceiveCmd.FRIENDS)
|
||||||
let _friends: Friend[] = [];
|
let _friends: Friend[] = [];
|
||||||
for (const fData of data.data) {
|
for (const fData of data.data) {
|
||||||
_friends.push(...fData.buddyList)
|
_friends.push(...fData.buddyList)
|
||||||
@ -161,7 +163,10 @@ export class NTQQApi {
|
|||||||
if (process.platform != "win32") {
|
if (process.platform != "win32") {
|
||||||
cbCmd = ReceiveCmd.GROUPS_UNIX
|
cbCmd = ReceiveCmd.GROUPS_UNIX
|
||||||
}
|
}
|
||||||
const result = await callNTQQApi<{ updateType: number, groupList: Group[] }>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.GROUPS, [{ force_update: forced }, undefined], cbCmd)
|
const result = await callNTQQApi<{
|
||||||
|
updateType: number,
|
||||||
|
groupList: Group[]
|
||||||
|
}>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.GROUPS, [{force_update: forced}, undefined], cbCmd)
|
||||||
return result.groupList
|
return result.groupList
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +177,9 @@ export class NTQQApi {
|
|||||||
}])
|
}])
|
||||||
// log("get group member sceneId", sceneId);
|
// log("get group member sceneId", sceneId);
|
||||||
try {
|
try {
|
||||||
const result = await callNTQQApi<{result:{infos: any}}>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.GROUP_MEMBERS,
|
const result = await callNTQQApi<{
|
||||||
|
result: { infos: any }
|
||||||
|
}>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.GROUP_MEMBERS,
|
||||||
[{
|
[{
|
||||||
sceneId: sceneId,
|
sceneId: sceneId,
|
||||||
num: num
|
num: num
|
||||||
@ -182,7 +189,7 @@ export class NTQQApi {
|
|||||||
// log("members info", typeof result.result.infos, Object.keys(result.result.infos))
|
// log("members info", typeof result.result.infos, Object.keys(result.result.infos))
|
||||||
let values = result.result.infos.values()
|
let values = result.result.infos.values()
|
||||||
|
|
||||||
values = Array.from(values) as GroupMember[]
|
values = Array.from(values) as GroupMember[]
|
||||||
// log("members info", values);
|
// log("members info", values);
|
||||||
return values
|
return values
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -192,7 +199,6 @@ export class NTQQApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static getFileType(filePath: string) {
|
static getFileType(filePath: string) {
|
||||||
return callNTQQApi<{
|
return callNTQQApi<{
|
||||||
ext: string
|
ext: string
|
||||||
@ -204,7 +210,10 @@ export class NTQQApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static copyFile(filePath: string, destPath: string) {
|
static copyFile(filePath: string, destPath: string) {
|
||||||
return callNTQQApi<string>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.FS_API, NTQQApiMethod.FILE_COPY, [{ fromPath: filePath, toPath: destPath }])
|
return callNTQQApi<string>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.FS_API, NTQQApiMethod.FILE_COPY, [{
|
||||||
|
fromPath: filePath,
|
||||||
|
toPath: destPath
|
||||||
|
}])
|
||||||
}
|
}
|
||||||
|
|
||||||
static getImageSize(filePath: string) {
|
static getImageSize(filePath: string) {
|
||||||
@ -221,7 +230,14 @@ export class NTQQApi {
|
|||||||
// 上传文件到QQ的文件夹
|
// 上传文件到QQ的文件夹
|
||||||
static async uploadFile(filePath: string) {
|
static async uploadFile(filePath: string) {
|
||||||
const md5 = await NTQQApi.getFileMd5(filePath);
|
const md5 = await NTQQApi.getFileMd5(filePath);
|
||||||
const fileName = `${md5}.${(await NTQQApi.getFileType(filePath)).ext}`;
|
let ext = (await NTQQApi.getFileType(filePath))?.ext
|
||||||
|
if (ext) {
|
||||||
|
ext = "." + ext
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
ext = ""
|
||||||
|
}
|
||||||
|
const fileName = `${md5}${ext}`;
|
||||||
const mediaPath = await callNTQQApi<string>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.MEDIA_FILE_PATH, [{
|
const mediaPath = await callNTQQApi<string>(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.MEDIA_FILE_PATH, [{
|
||||||
path_info: {
|
path_info: {
|
||||||
md5HexStr: md5,
|
md5HexStr: md5,
|
||||||
@ -245,9 +261,9 @@ export class NTQQApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string){
|
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string) {
|
||||||
// 用于下载收到的消息中的图片等
|
// 用于下载收到的消息中的图片等
|
||||||
if (fs.existsSync(sourcePath)){
|
if (fs.existsSync(sourcePath)) {
|
||||||
return sourcePath
|
return sourcePath
|
||||||
}
|
}
|
||||||
const apiParams = [
|
const apiParams = [
|
||||||
@ -267,8 +283,12 @@ export class NTQQApi {
|
|||||||
await callNTQQApi(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.DOWNLOAD_MEDIA, apiParams)
|
await callNTQQApi(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.DOWNLOAD_MEDIA, apiParams)
|
||||||
return sourcePath
|
return sourcePath
|
||||||
}
|
}
|
||||||
|
|
||||||
static recallMsg(peer: Peer, msgIds: string[]) {
|
static recallMsg(peer: Peer, msgIds: string[]) {
|
||||||
return callNTQQApi(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.RECALL_MSG, [{ peer, msgIds }, null])
|
return callNTQQApi(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.RECALL_MSG, [{
|
||||||
|
peer,
|
||||||
|
msgIds
|
||||||
|
}, null])
|
||||||
}
|
}
|
||||||
|
|
||||||
static sendMsg(peer: Peer, msgElements: SendMessageElement[]) {
|
static sendMsg(peer: Peer, msgElements: SendMessageElement[]) {
|
||||||
@ -297,8 +317,7 @@ export class NTQQApi {
|
|||||||
// log("有正在发送的消息,等待中...")
|
// log("有正在发送的消息,等待中...")
|
||||||
usingTime += 100;
|
usingTime += 100;
|
||||||
setTimeout(checkLastSend, 100);
|
setTimeout(checkLastSend, 100);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
log("可以进行发送消息,设置发送成功回调", sendMessagePool)
|
log("可以进行发送消息,设置发送成功回调", sendMessagePool)
|
||||||
sendMessagePool[peerUid] = (rawMessage: RawMessage) => {
|
sendMessagePool[peerUid] = (rawMessage: RawMessage) => {
|
||||||
success = true;
|
success = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user