mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: self nickname
fix: auto download receive image fix: @member msg report ver: 3.0.1
This commit is contained in:
parent
64c4798117
commit
6a8d67a8ae
@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "2.5.0",
|
"version": "3.0.1",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"authors": [{
|
"authors": [{
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
|
@ -32,7 +32,7 @@ function onLoad() {
|
|||||||
|
|
||||||
|
|
||||||
if (!fs.existsSync(CONFIG_DIR)) {
|
if (!fs.existsSync(CONFIG_DIR)) {
|
||||||
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
fs.mkdirSync(CONFIG_DIR, {recursive: true});
|
||||||
}
|
}
|
||||||
ipcMain.handle(CHANNEL_GET_CONFIG, (event: any, arg: any) => {
|
ipcMain.handle(CHANNEL_GET_CONFIG, (event: any, arg: any) => {
|
||||||
return getConfigUtil().getConfig()
|
return getConfigUtil().getConfig()
|
||||||
@ -47,7 +47,7 @@ function onLoad() {
|
|||||||
|
|
||||||
|
|
||||||
function postRawMsg(msgList: RawMessage[]) {
|
function postRawMsg(msgList: RawMessage[]) {
|
||||||
const { debug, reportSelfMessage } = getConfigUtil().getConfig();
|
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
||||||
for (const message of msgList) {
|
for (const message of msgList) {
|
||||||
OB11Constructor.message(message).then((msg) => {
|
OB11Constructor.message(message).then((msg) => {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@ -61,34 +61,38 @@ function onLoad() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload) => {
|
|
||||||
try {
|
|
||||||
postRawMsg(payload.msgList);
|
|
||||||
} catch (e) {
|
|
||||||
log("report message error: ", e.toString())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, (payload) => {
|
function start() {
|
||||||
const { reportSelfMessage } = getConfigUtil().getConfig()
|
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload) => {
|
||||||
if (!reportSelfMessage) {
|
try {
|
||||||
return
|
postRawMsg(payload.msgList);
|
||||||
}
|
} catch (e) {
|
||||||
log("reportSelfMessage", payload)
|
log("report message error: ", e.toString())
|
||||||
try {
|
}
|
||||||
postRawMsg([payload.msgRecord]);
|
})
|
||||||
} catch (e) {
|
|
||||||
log("report self message error: ", e.toString())
|
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, (payload) => {
|
||||||
}
|
const {reportSelfMessage} = getConfigUtil().getConfig()
|
||||||
})
|
if (!reportSelfMessage) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log("reportSelfMessage", payload)
|
||||||
|
try {
|
||||||
|
postRawMsg([payload.msgRecord]);
|
||||||
|
} catch (e) {
|
||||||
|
log("report self message error: ", e.toString())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
startExpress(getConfigUtil().getConfig().port)
|
||||||
|
}
|
||||||
|
|
||||||
async function getSelfInfo() {
|
async function getSelfInfo() {
|
||||||
try{
|
try {
|
||||||
const _ = await NTQQApi.getSelfInfo()
|
const _ = await NTQQApi.getSelfInfo()
|
||||||
Object.assign(selfInfo, _)
|
Object.assign(selfInfo, _)
|
||||||
selfInfo.nick = selfInfo.uin
|
selfInfo.nick = selfInfo.uin
|
||||||
log("get self simple info", _)
|
log("get self simple info", _)
|
||||||
}catch(e){
|
} catch (e) {
|
||||||
log("retry get self info")
|
log("retry get self info")
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -97,11 +101,15 @@ function onLoad() {
|
|||||||
const userInfo = (await NTQQApi.getUserInfo(selfInfo.uid))
|
const userInfo = (await NTQQApi.getUserInfo(selfInfo.uid))
|
||||||
if (userInfo) {
|
if (userInfo) {
|
||||||
selfInfo.nick = userInfo.nick
|
selfInfo.nick = userInfo.nick
|
||||||
|
} else {
|
||||||
|
return setTimeout(() => {
|
||||||
|
getSelfInfo().then()
|
||||||
|
}, 100)
|
||||||
}
|
}
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
log("get self nickname failed", e.toString())
|
log("get self nickname failed", e.toString())
|
||||||
}
|
}
|
||||||
|
start();
|
||||||
// try {
|
// try {
|
||||||
// friends.push(...(await NTQQApi.getFriends(true)))
|
// friends.push(...(await NTQQApi.getFriends(true)))
|
||||||
// log("get friends", friends)
|
// log("get friends", friends)
|
||||||
@ -124,14 +132,13 @@ function onLoad() {
|
|||||||
// } catch (e) {
|
// } catch (e) {
|
||||||
// log("!!!初始化失败", e.stack.toString())
|
// log("!!!初始化失败", e.stack.toString())
|
||||||
// }
|
// }
|
||||||
startExpress(getConfigUtil().getConfig().port)
|
} else {
|
||||||
}
|
|
||||||
else{
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
getSelfInfo().then()
|
getSelfInfo().then()
|
||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSelfInfo().then()
|
getSelfInfo().then()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,11 +2,12 @@ import { ipcMain } from "electron";
|
|||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import { ReceiveCmd, hookApiCallbacks, registerReceiveHook, removeReceiveHook } from "./hook";
|
import { ReceiveCmd, hookApiCallbacks, registerReceiveHook, removeReceiveHook } from "./hook";
|
||||||
import { log } from "../common/utils";
|
import { log } from "../common/utils";
|
||||||
import { ChatType, Friend, SelfInfo, User } from "./types";
|
import { ChatType, Friend, PicElement, SelfInfo, User } from "./types";
|
||||||
import { Group } from "./types";
|
import { Group } from "./types";
|
||||||
import { GroupMember } from "./types";
|
import { GroupMember } from "./types";
|
||||||
import { RawMessage } from "./types";
|
import { RawMessage } from "./types";
|
||||||
import { SendMessageElement } from "./types";
|
import { SendMessageElement } from "./types";
|
||||||
|
import * as fs from "fs";
|
||||||
|
|
||||||
interface IPCReceiveEvent {
|
interface IPCReceiveEvent {
|
||||||
eventName: string
|
eventName: string
|
||||||
@ -43,6 +44,7 @@ export enum NTQQApiMethod {
|
|||||||
MEDIA_FILE_PATH = "nodeIKernelMsgService/getRichMediaFilePathForGuild",
|
MEDIA_FILE_PATH = "nodeIKernelMsgService/getRichMediaFilePathForGuild",
|
||||||
RECALL_MSG = "nodeIKernelMsgService/recallMsg",
|
RECALL_MSG = "nodeIKernelMsgService/recallMsg",
|
||||||
SEND_MSG = "nodeIKernelMsgService/sendMsg",
|
SEND_MSG = "nodeIKernelMsgService/sendMsg",
|
||||||
|
DOWNLOAD_MEDIA = "nodeIKernelMsgService/downloadRichMedia"
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NTQQApiChannel {
|
enum NTQQApiChannel {
|
||||||
@ -244,6 +246,28 @@ export class NTQQApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
]
|
||||||
|
await callNTQQApi(NTQQApiChannel.IPC_UP_2, NTQQApiClass.NT_API, NTQQApiMethod.DOWNLOAD_MEDIA, apiParams)
|
||||||
|
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])
|
||||||
}
|
}
|
||||||
@ -293,4 +317,5 @@ export class NTQQApi {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -167,6 +167,19 @@ export interface ArkElement {
|
|||||||
bytesData: string;
|
bytesData: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const IMAGE_HTTP_HOST = "https://gchat.qpic.cn"
|
||||||
|
|
||||||
|
export interface PicElement {
|
||||||
|
originImageUrl: string; // http url, 没有host,host是https://gchat.qpic.cn/
|
||||||
|
sourcePath: string; // 图片本地路径
|
||||||
|
thumbPath: Map<number, string>;
|
||||||
|
picWidth: number;
|
||||||
|
picHeight: number;
|
||||||
|
fileSize: number;
|
||||||
|
fileName: string;
|
||||||
|
fileUuid: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface RawMessage {
|
export interface RawMessage {
|
||||||
msgId: string;
|
msgId: string;
|
||||||
msgTime: string;
|
msgTime: string;
|
||||||
@ -178,6 +191,7 @@ export interface RawMessage {
|
|||||||
sendMemberName?: string; // 发送者群名片
|
sendMemberName?: string; // 发送者群名片
|
||||||
chatType: ChatType;
|
chatType: ChatType;
|
||||||
elements: {
|
elements: {
|
||||||
|
elementId: string,
|
||||||
replyElement: {
|
replyElement: {
|
||||||
senderUid: string; // 原消息发送者QQ号
|
senderUid: string; // 原消息发送者QQ号
|
||||||
sourceMsgIsIncPic: boolean; // 原消息是否有图片
|
sourceMsgIsIncPic: boolean; // 原消息是否有图片
|
||||||
@ -186,18 +200,11 @@ export interface RawMessage {
|
|||||||
};
|
};
|
||||||
textElement: {
|
textElement: {
|
||||||
atType: AtType;
|
atType: AtType;
|
||||||
atUid: string;
|
atUid: string; // QQ号
|
||||||
content: string;
|
content: string;
|
||||||
atNtUid: string;
|
atNtUid: string; // uid号
|
||||||
};
|
|
||||||
picElement: {
|
|
||||||
sourcePath: string; // 图片本地路径
|
|
||||||
picWidth: number;
|
|
||||||
picHeight: number;
|
|
||||||
fileSize: number;
|
|
||||||
fileName: string;
|
|
||||||
fileUuid: string;
|
|
||||||
};
|
};
|
||||||
|
picElement: PicElement;
|
||||||
pttElement: PttElement;
|
pttElement: PttElement;
|
||||||
arkElement: ArkElement;
|
arkElement: ArkElement;
|
||||||
}[];
|
}[];
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import {OB11MessageDataType, OB11GroupMemberRole, OB11Message, OB11MessageData, OB11Group, OB11GroupMember, OB11User} from "./types";
|
import {OB11MessageDataType, OB11GroupMemberRole, OB11Message, OB11MessageData, OB11Group, OB11GroupMember, OB11User} from "./types";
|
||||||
import { AtType, ChatType, Group, GroupMember, RawMessage, SelfInfo, User } from '../ntqqapi/types';
|
import { AtType, ChatType, Group, GroupMember, IMAGE_HTTP_HOST, RawMessage, SelfInfo, User } from '../ntqqapi/types';
|
||||||
import { getFriend, getGroupMember, getHistoryMsgBySeq, selfInfo } from '../common/data';
|
import { getFriend, getGroupMember, getHistoryMsgBySeq, selfInfo } from '../common/data';
|
||||||
import {file2base64, getConfigUtil, log} from "../common/utils";
|
import {file2base64, getConfigUtil, log} from "../common/utils";
|
||||||
|
import { NTQQApi } from "../ntqqapi/ntcall";
|
||||||
|
|
||||||
|
|
||||||
export class OB11Constructor {
|
export class OB11Constructor {
|
||||||
@ -53,10 +54,10 @@ export class OB11Constructor {
|
|||||||
message_data["data"]["mention"] = "all"
|
message_data["data"]["mention"] = "all"
|
||||||
message_data["data"]["qq"] = "all"
|
message_data["data"]["qq"] = "all"
|
||||||
} else {
|
} else {
|
||||||
let uid = element.textElement.atUid
|
let atQQ = element.textElement.atUid
|
||||||
let atMember = await getGroupMember(msg.peerUin, uid)
|
// let atMember = await getGroupMember(msg.peerUin, uid)
|
||||||
message_data["data"]["mention"] = atMember?.uin
|
message_data["data"]["mention"] = atQQ
|
||||||
message_data["data"]["qq"] = atMember?.uin
|
message_data["data"]["qq"] = atQQ
|
||||||
}
|
}
|
||||||
} else if (element.textElement) {
|
} else if (element.textElement) {
|
||||||
message_data["type"] = "text"
|
message_data["type"] = "text"
|
||||||
@ -66,6 +67,12 @@ export class OB11Constructor {
|
|||||||
message_data["data"]["file_id"] = element.picElement.fileUuid
|
message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||||
message_data["data"]["path"] = element.picElement.sourcePath
|
message_data["data"]["path"] = element.picElement.sourcePath
|
||||||
message_data["data"]["file"] = element.picElement.sourcePath
|
message_data["data"]["file"] = element.picElement.sourcePath
|
||||||
|
try {
|
||||||
|
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
|
element.elementId, element.picElement.thumbPath.get(0), element.picElement.sourcePath)
|
||||||
|
}catch (e) {
|
||||||
|
message_data["data"]["http_file"] = IMAGE_HTTP_HOST + element.picElement.originImageUrl
|
||||||
|
}
|
||||||
} else if (element.replyElement) {
|
} else if (element.replyElement) {
|
||||||
message_data["type"] = "reply"
|
message_data["type"] = "reply"
|
||||||
const replyMsg = getHistoryMsgBySeq(element.replyElement.replayMsgSeq)
|
const replyMsg = getHistoryMsgBySeq(element.replyElement.replayMsgSeq)
|
||||||
@ -89,7 +96,10 @@ export class OB11Constructor {
|
|||||||
message_data["type"] = OB11MessageDataType.json;
|
message_data["type"] = OB11MessageDataType.json;
|
||||||
message_data["data"]["data"] = element.arkElement.bytesData;
|
message_data["data"]["data"] = element.arkElement.bytesData;
|
||||||
}
|
}
|
||||||
if (message_data.data.file) {
|
if (message_data.data.http_file){
|
||||||
|
message_data.data.file = message_data.data.http_file
|
||||||
|
}
|
||||||
|
else if (message_data.data.file) {
|
||||||
let filePath: string = message_data.data.file;
|
let filePath: string = message_data.data.file;
|
||||||
message_data.data.file = "file://" + filePath
|
message_data.data.file = "file://" + filePath
|
||||||
if (enableBase64) {
|
if (enableBase64) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user