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",
|
||||
"slug": "LLOneBot",
|
||||
"description": "LiteLoaderQQNT的OneBotApi",
|
||||
"version": "2.5.0",
|
||||
"version": "3.0.1",
|
||||
"thumbnail": "./icon.png",
|
||||
"authors": [{
|
||||
"name": "linyuchen",
|
||||
|
@ -32,7 +32,7 @@ function onLoad() {
|
||||
|
||||
|
||||
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) => {
|
||||
return getConfigUtil().getConfig()
|
||||
@ -47,7 +47,7 @@ function onLoad() {
|
||||
|
||||
|
||||
function postRawMsg(msgList: RawMessage[]) {
|
||||
const { debug, reportSelfMessage } = getConfigUtil().getConfig();
|
||||
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
||||
for (const message of msgList) {
|
||||
OB11Constructor.message(message).then((msg) => {
|
||||
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) => {
|
||||
const { reportSelfMessage } = getConfigUtil().getConfig()
|
||||
if (!reportSelfMessage) {
|
||||
return
|
||||
}
|
||||
log("reportSelfMessage", payload)
|
||||
try {
|
||||
postRawMsg([payload.msgRecord]);
|
||||
} catch (e) {
|
||||
log("report self message error: ", e.toString())
|
||||
}
|
||||
})
|
||||
function start() {
|
||||
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) => {
|
||||
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() {
|
||||
try{
|
||||
try {
|
||||
const _ = await NTQQApi.getSelfInfo()
|
||||
Object.assign(selfInfo, _)
|
||||
selfInfo.nick = selfInfo.uin
|
||||
log("get self simple info", _)
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
log("retry get self info")
|
||||
|
||||
}
|
||||
@ -97,11 +101,15 @@ function onLoad() {
|
||||
const userInfo = (await NTQQApi.getUserInfo(selfInfo.uid))
|
||||
if (userInfo) {
|
||||
selfInfo.nick = userInfo.nick
|
||||
} else {
|
||||
return setTimeout(() => {
|
||||
getSelfInfo().then()
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
log("get self nickname failed", e.toString())
|
||||
}
|
||||
start();
|
||||
// try {
|
||||
// friends.push(...(await NTQQApi.getFriends(true)))
|
||||
// log("get friends", friends)
|
||||
@ -124,14 +132,13 @@ function onLoad() {
|
||||
// } catch (e) {
|
||||
// log("!!!初始化失败", e.stack.toString())
|
||||
// }
|
||||
startExpress(getConfigUtil().getConfig().port)
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
getSelfInfo().then()
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
|
||||
getSelfInfo().then()
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,12 @@ import { ipcMain } from "electron";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { ReceiveCmd, hookApiCallbacks, registerReceiveHook, removeReceiveHook } from "./hook";
|
||||
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 { GroupMember } from "./types";
|
||||
import { RawMessage } from "./types";
|
||||
import { SendMessageElement } from "./types";
|
||||
import * as fs from "fs";
|
||||
|
||||
interface IPCReceiveEvent {
|
||||
eventName: string
|
||||
@ -43,6 +44,7 @@ export enum NTQQApiMethod {
|
||||
MEDIA_FILE_PATH = "nodeIKernelMsgService/getRichMediaFilePathForGuild",
|
||||
RECALL_MSG = "nodeIKernelMsgService/recallMsg",
|
||||
SEND_MSG = "nodeIKernelMsgService/sendMsg",
|
||||
DOWNLOAD_MEDIA = "nodeIKernelMsgService/downloadRichMedia"
|
||||
}
|
||||
|
||||
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[]) {
|
||||
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;
|
||||
}
|
||||
|
||||
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 {
|
||||
msgId: string;
|
||||
msgTime: string;
|
||||
@ -178,6 +191,7 @@ export interface RawMessage {
|
||||
sendMemberName?: string; // 发送者群名片
|
||||
chatType: ChatType;
|
||||
elements: {
|
||||
elementId: string,
|
||||
replyElement: {
|
||||
senderUid: string; // 原消息发送者QQ号
|
||||
sourceMsgIsIncPic: boolean; // 原消息是否有图片
|
||||
@ -186,18 +200,11 @@ export interface RawMessage {
|
||||
};
|
||||
textElement: {
|
||||
atType: AtType;
|
||||
atUid: string;
|
||||
atUid: string; // QQ号
|
||||
content: string;
|
||||
atNtUid: string;
|
||||
};
|
||||
picElement: {
|
||||
sourcePath: string; // 图片本地路径
|
||||
picWidth: number;
|
||||
picHeight: number;
|
||||
fileSize: number;
|
||||
fileName: string;
|
||||
fileUuid: string;
|
||||
atNtUid: string; // uid号
|
||||
};
|
||||
picElement: PicElement;
|
||||
pttElement: PttElement;
|
||||
arkElement: ArkElement;
|
||||
}[];
|
||||
|
@ -1,7 +1,8 @@
|
||||
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 {file2base64, getConfigUtil, log} from "../common/utils";
|
||||
import { NTQQApi } from "../ntqqapi/ntcall";
|
||||
|
||||
|
||||
export class OB11Constructor {
|
||||
@ -53,10 +54,10 @@ export class OB11Constructor {
|
||||
message_data["data"]["mention"] = "all"
|
||||
message_data["data"]["qq"] = "all"
|
||||
} else {
|
||||
let uid = element.textElement.atUid
|
||||
let atMember = await getGroupMember(msg.peerUin, uid)
|
||||
message_data["data"]["mention"] = atMember?.uin
|
||||
message_data["data"]["qq"] = atMember?.uin
|
||||
let atQQ = element.textElement.atUid
|
||||
// let atMember = await getGroupMember(msg.peerUin, uid)
|
||||
message_data["data"]["mention"] = atQQ
|
||||
message_data["data"]["qq"] = atQQ
|
||||
}
|
||||
} else if (element.textElement) {
|
||||
message_data["type"] = "text"
|
||||
@ -66,6 +67,12 @@ export class OB11Constructor {
|
||||
message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||
message_data["data"]["path"] = 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) {
|
||||
message_data["type"] = "reply"
|
||||
const replyMsg = getHistoryMsgBySeq(element.replyElement.replayMsgSeq)
|
||||
@ -89,7 +96,10 @@ export class OB11Constructor {
|
||||
message_data["type"] = OB11MessageDataType.json;
|
||||
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;
|
||||
message_data.data.file = "file://" + filePath
|
||||
if (enableBase64) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user