mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
refactor: inline all NTQQXxxApi uses
This commit is contained in:
@@ -24,10 +24,9 @@ export class FetchEmojiLike extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||||
if (!msgIdPeer) throw new Error('消息不存在');
|
if (!msgIdPeer) throw new Error('消息不存在');
|
||||||
const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
||||||
return await NTQQMsgApi.getMsgEmojiLikesList(msgIdPeer.Peer, msg.msgSeq, payload.emojiId, payload.emojiType, +(payload.count ?? 20));
|
return await this.core.apis.MsgApi.getMsgEmojiLikesList(msgIdPeer.Peer, msg.msgSeq, payload.emojiId, payload.emojiType, +(payload.count ?? 20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,6 @@ export class GetCollectionList extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQCollectionApi = this.core.apis.CollectionApi;
|
return await this.core.apis.CollectionApi.getAllCollection(parseInt(payload.category.toString()), +(payload.count ?? 1));
|
||||||
return await NTQQCollectionApi.getAllCollection(parseInt(payload.category.toString()), +(payload.count ?? 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,8 +17,6 @@ export class GetGroupInfoEx extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
return (await this.core.apis.GroupApi.getGroupExtFE0Info([payload.group_id.toString()])).result.groupExtInfos.get(payload.group_id.toString());
|
||||||
const groupInfoEx = (await NTQQGroupApi.getGroupExtFE0Info([payload.group_id.toString()])).result.groupExtInfos.get(payload.group_id.toString());
|
|
||||||
return groupInfoEx;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,11 +5,10 @@ export class GetProfileLike extends BaseAction<void, any> {
|
|||||||
actionName = ActionName.GetProfileLike;
|
actionName = ActionName.GetProfileLike;
|
||||||
|
|
||||||
async _handle(payload: void) {
|
async _handle(payload: void) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const ret = await this.core.apis.UserApi.getProfileLike(this.core.selfInfo.uid);
|
||||||
const ret = await NTQQUserApi.getProfileLike(this.core.selfInfo.uid);
|
|
||||||
const listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos;
|
const listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos;
|
||||||
for (let i = 0; i < listdata.length; i++) {
|
for (let i = 0; i < listdata.length; i++) {
|
||||||
listdata[i].uin = parseInt((await NTQQUserApi.getUinByUidV2(listdata[i].uid)) || '');
|
listdata[i].uin = parseInt((await this.core.apis.UserApi.getUinByUidV2(listdata[i].uid)) || '');
|
||||||
}
|
}
|
||||||
return listdata;
|
return listdata;
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,6 @@ export class GetRobotUinRange extends BaseAction<void, Array<any>> {
|
|||||||
actionName = ActionName.GetRobotUinRange;
|
actionName = ActionName.GetRobotUinRange;
|
||||||
|
|
||||||
async _handle(payload: void) {
|
async _handle(payload: void) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
return await this.core.apis.UserApi.getRobotUinRange();
|
||||||
return await NTQQUserApi.getRobotUinRange();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,14 +19,13 @@ export class OCRImage extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQSystemApi = this.core.apis.SystemApi;
|
|
||||||
const { path, isLocal, success } = (await uri2local(this.core.NapCatTempPath, payload.image));
|
const { path, isLocal, success } = (await uri2local(this.core.NapCatTempPath, payload.image));
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
|
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||||
const ret = await NTQQSystemApi.ocrImage(path);
|
const ret = await this.core.apis.SystemApi.ocrImage(path);
|
||||||
if (!isLocal) {
|
if (!isLocal) {
|
||||||
fs.unlink(path, () => {
|
fs.unlink(path, () => {
|
||||||
});
|
});
|
||||||
|
@@ -19,8 +19,6 @@ export class SetInputStatus extends BaseAction<Payload, any> {
|
|||||||
actionName = ActionName.SetInputStatus;
|
actionName = ActionName.SetInputStatus;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
let peer: Peer;
|
let peer: Peer;
|
||||||
if (payload.group_id) {
|
if (payload.group_id) {
|
||||||
peer = {
|
peer = {
|
||||||
@@ -28,7 +26,7 @@ export class SetInputStatus extends BaseAction<Payload, any> {
|
|||||||
peerUid: payload.group_id,
|
peerUid: payload.group_id,
|
||||||
};
|
};
|
||||||
} else if (payload.user_id) {
|
} else if (payload.user_id) {
|
||||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id);
|
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id);
|
||||||
if (!uid) throw new Error('uid is empty');
|
if (!uid) throw new Error('uid is empty');
|
||||||
peer = {
|
peer = {
|
||||||
chatType: ChatType.KCHATTYPEC2C,
|
chatType: ChatType.KCHATTYPEC2C,
|
||||||
@@ -38,6 +36,6 @@ export class SetInputStatus extends BaseAction<Payload, any> {
|
|||||||
throw new Error('请指定 group_id 或 user_id');
|
throw new Error('请指定 group_id 或 user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await NTQQMsgApi.sendShowInputStatusReq(peer, parseInt(payload.eventType));
|
return await this.core.apis.MsgApi.sendShowInputStatusReq(peer, parseInt(payload.eventType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,8 +17,6 @@ export class SetLongNick extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
return await this.core.apis.UserApi.setLongNick(payload.longNick);
|
||||||
const ret = await NTQQUserApi.setLongNick(payload.longNick);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,8 +20,7 @@ export class SetOnlineStatus extends BaseAction<Payload, null> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const ret = await this.core.apis.UserApi.setSelfOnlineStatus(
|
||||||
const ret = await NTQQUserApi.setSelfOnlineStatus(
|
|
||||||
parseInt(payload.status.toString()),
|
parseInt(payload.status.toString()),
|
||||||
parseInt(payload.ext_status.toString()),
|
parseInt(payload.ext_status.toString()),
|
||||||
parseInt(payload.battery_status.toString()),
|
parseInt(payload.battery_status.toString()),
|
||||||
|
@@ -24,14 +24,13 @@ export default class SetAvatar extends BaseAction<Payload, null> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const { path, isLocal, success } = (await uri2local(this.core.NapCatTempPath, payload.file));
|
||||||
const { path, isLocal, errMsg, success } = (await uri2local(this.core.NapCatTempPath, payload.file));
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||||
const ret = await NTQQUserApi.setQQAvatar(path);
|
const ret = await this.core.apis.UserApi.setQQAvatar(path);
|
||||||
if (!isLocal) {
|
if (!isLocal) {
|
||||||
fs.unlink(path, () => {
|
fs.unlink(path, () => {
|
||||||
});
|
});
|
||||||
|
@@ -19,12 +19,10 @@ export class SharePeer extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
if (payload.group_id) {
|
if (payload.group_id) {
|
||||||
return await NTQQGroupApi.getGroupRecommendContactArkJson(payload.group_id);
|
return await this.core.apis.GroupApi.getGroupRecommendContactArkJson(payload.group_id);
|
||||||
} else if (payload.user_id) {
|
} else if (payload.user_id) {
|
||||||
return await NTQQUserApi.getBuddyRecommendContactArkJson(payload.user_id, payload.phoneNumber || '');
|
return await this.core.apis.UserApi.getBuddyRecommendContactArkJson(payload.user_id, payload.phoneNumber || '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,7 +42,6 @@ export class ShareGroupEx extends BaseAction<PayloadGroupEx, any> {
|
|||||||
payloadSchema = SchemaDataGroupEx;
|
payloadSchema = SchemaDataGroupEx;
|
||||||
|
|
||||||
async _handle(payload: PayloadGroupEx) {
|
async _handle(payload: PayloadGroupEx) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
return await this.core.apis.GroupApi.getArkJsonGroupShare(payload.group_id);
|
||||||
return await NTQQGroupApi.getArkJsonGroupShare(payload.group_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,8 +20,7 @@ export class TranslateEnWordToZn extends BaseAction<Payload, Array<any> | null>
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQSystemApi = this.core.apis.SystemApi;
|
const ret = await this.core.apis.SystemApi.translateEnWordToZn(payload.words);
|
||||||
const ret = await NTQQSystemApi.translateEnWordToZn(payload.words);
|
|
||||||
if (ret.result !== 0) {
|
if (ret.result !== 0) {
|
||||||
throw new Error('翻译失败');
|
throw new Error('翻译失败');
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,6 @@ export class DelGroupFile extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
return await this.core.apis.GroupApi.DelGroupFile(payload.group_id.toString(), [payload.file_id]);
|
||||||
return await NTQQGroupApi.DelGroupFile(payload.group_id.toString(), [payload.file_id]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@ export class DelGroupFileFolder extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
return (await this.core.apis.GroupApi.DelGroupFileFolder(
|
||||||
return (await NTQQGroupApi.DelGroupFileFolder(payload.group_id.toString(), payload.folder_id)).groupFileCommonResult;
|
payload.group_id.toString(), payload.folder_id)).groupFileCommonResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,15 +28,12 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|||||||
payloadSchema: any = GetFileBase_PayloadSchema;
|
payloadSchema: any = GetFileBase_PayloadSchema;
|
||||||
|
|
||||||
async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const NTQQFileApi = this.core.apis.FileApi;
|
|
||||||
|
|
||||||
//接收消息标记模式
|
//接收消息标记模式
|
||||||
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file);
|
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file);
|
||||||
if (contextMsgFile) {
|
if (contextMsgFile) {
|
||||||
const { peer, msgId, elementId } = contextMsgFile;
|
const { peer, msgId, elementId } = contextMsgFile;
|
||||||
const downloadPath = await NTQQFileApi.downloadMedia(msgId, peer.chatType, peer.peerUid, elementId, '', '');
|
const downloadPath = await this.core.apis.FileApi.downloadMedia(msgId, peer.chatType, peer.peerUid, elementId, '', '');
|
||||||
const mixElement = (await NTQQMsgApi.getMsgsByMsgId(peer, [msgId]))?.msgList
|
const mixElement = (await this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgId]))?.msgList
|
||||||
.find(msg => msg.msgId === msgId)?.elements.find(e => e.elementId === elementId);
|
.find(msg => msg.msgId === msgId)?.elements.find(e => e.elementId === elementId);
|
||||||
const mixElementInner = mixElement?.videoElement ?? mixElement?.fileElement ?? mixElement?.pttElement ?? mixElement?.picElement;
|
const mixElementInner = mixElement?.videoElement ?? mixElement?.fileElement ?? mixElement?.pttElement ?? mixElement?.picElement;
|
||||||
if (!mixElementInner) throw new Error('element not found');
|
if (!mixElementInner) throw new Error('element not found');
|
||||||
@@ -64,7 +61,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|||||||
const contextModelIdFile = FileNapCatOneBotUUID.decodeModelId(payload.file);
|
const contextModelIdFile = FileNapCatOneBotUUID.decodeModelId(payload.file);
|
||||||
if (contextModelIdFile) {
|
if (contextModelIdFile) {
|
||||||
const { peer, modelId } = contextModelIdFile;
|
const { peer, modelId } = contextModelIdFile;
|
||||||
const downloadPath = await NTQQFileApi.downloadFileForModelId(peer, modelId, '');
|
const downloadPath = await this.core.apis.FileApi.downloadFileForModelId(peer, modelId, '');
|
||||||
const res: GetFileResponse = {
|
const res: GetFileResponse = {
|
||||||
file: downloadPath,
|
file: downloadPath,
|
||||||
url: downloadPath,
|
url: downloadPath,
|
||||||
@@ -83,9 +80,9 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//搜索名字模式
|
//搜索名字模式
|
||||||
const searchResult = (await NTQQFileApi.searchForFile([payload.file]));
|
const searchResult = (await this.core.apis.FileApi.searchForFile([payload.file]));
|
||||||
if (searchResult) {
|
if (searchResult) {
|
||||||
const downloadPath = await NTQQFileApi.downloadFileById(searchResult.id, parseInt(searchResult.fileSize));
|
const downloadPath = await this.core.apis.FileApi.downloadFileById(searchResult.id, parseInt(searchResult.fileSize));
|
||||||
const res: GetFileResponse = {
|
const res: GetFileResponse = {
|
||||||
file: downloadPath,
|
file: downloadPath,
|
||||||
url: downloadPath,
|
url: downloadPath,
|
||||||
|
@@ -21,14 +21,13 @@ export class GetGroupFileList extends BaseAction<Payload, { FileList: Array<any>
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
let param = {};
|
let param = {};
|
||||||
if (payload.folder_id) {
|
if (payload.folder_id) {
|
||||||
param = {
|
param = {
|
||||||
folderId: payload.folder_id.toString(),
|
folderId: payload.folder_id.toString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const ret = await NTQQMsgApi.getGroupFileList(payload.group_id.toString(), {
|
const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
|
||||||
sortType: 1,
|
sortType: 1,
|
||||||
fileCount: +payload.file_count,
|
fileCount: +payload.file_count,
|
||||||
startIndex: +payload.start_index,
|
startIndex: +payload.start_index,
|
||||||
|
@@ -18,7 +18,6 @@ export class SetGroupFileFolder extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
return (await this.core.apis.GroupApi.CreatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem;
|
||||||
return (await NTQQGroupApi.CreatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<any> {
|
async _handle(payload: Payload): Promise<any> {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const msgId = payload.message_id || payload.id;
|
const msgId = payload.message_id || payload.id;
|
||||||
if (!msgId) {
|
if (!msgId) {
|
||||||
throw Error('message_id is required');
|
throw Error('message_id is required');
|
||||||
@@ -29,7 +28,7 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
|
|||||||
if (!rootMsg) {
|
if (!rootMsg) {
|
||||||
throw Error('msg not found');
|
throw Error('msg not found');
|
||||||
}
|
}
|
||||||
const data = await NTQQMsgApi.getMultiMsg(rootMsg.Peer, rootMsg.MsgId, rootMsg.MsgId);
|
const data = await this.core.apis.MsgApi.getMultiMsg(rootMsg.Peer, rootMsg.MsgId, rootMsg.MsgId);
|
||||||
if (!data || data.result !== 0) {
|
if (!data || data.result !== 0) {
|
||||||
throw Error('找不到相关的聊天记录' + data?.errMsg);
|
throw Error('找不到相关的聊天记录' + data?.errMsg);
|
||||||
}
|
}
|
||||||
|
@@ -27,21 +27,17 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<Response> {
|
async _handle(payload: Payload): Promise<Response> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const NTQQFriendApi = this.core.apis.FriendApi;
|
|
||||||
//处理参数
|
//处理参数
|
||||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
const MsgCount = +(payload.count ?? 20);
|
const MsgCount = +(payload.count ?? 20);
|
||||||
const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder;
|
const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder;
|
||||||
if (!uid) throw `记录${payload.user_id}不存在`;
|
if (!uid) throw `记录${payload.user_id}不存在`;
|
||||||
const friend = await NTQQFriendApi.isBuddy(uid);
|
const friend = await this.core.apis.FriendApi.isBuddy(uid);
|
||||||
const peer = { chatType: friend ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid: uid };
|
const peer = { chatType: friend ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid: uid };
|
||||||
const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0');
|
const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0');
|
||||||
//拉取消息
|
|
||||||
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
|
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
|
||||||
const msgList = hasMessageSeq ?
|
const msgList = hasMessageSeq ?
|
||||||
(await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList : (await NTQQMsgApi.getAioFirstViewLatestMsgs(peer, MsgCount)).msgList;
|
(await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList : (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, MsgCount)).msgList;
|
||||||
if (msgList.length === 0) throw `消息${payload.message_seq}不存在`;
|
if (msgList.length === 0) throw `消息${payload.message_seq}不存在`;
|
||||||
//翻转消息
|
//翻转消息
|
||||||
if (isReverseOrder) msgList.reverse();
|
if (isReverseOrder) msgList.reverse();
|
||||||
|
@@ -22,7 +22,6 @@ export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
|
|||||||
if (!payload.type) {
|
if (!payload.type) {
|
||||||
payload.type = WebHonorType.ALL;
|
payload.type = WebHonorType.ALL;
|
||||||
}
|
}
|
||||||
const NTQQWebApi = this.core.apis.WebApi;
|
return await this.core.apis.WebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type);
|
||||||
return await NTQQWebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,6 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<Response> {
|
async _handle(payload: Payload): Promise<Response> {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
//处理参数
|
//处理参数
|
||||||
const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder;
|
const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder;
|
||||||
const MsgCount = +(payload.count ?? 20);
|
const MsgCount = +(payload.count ?? 20);
|
||||||
@@ -36,7 +35,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
|||||||
//拉取消息
|
//拉取消息
|
||||||
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
|
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
|
||||||
const msgList = hasMessageSeq ?
|
const msgList = hasMessageSeq ?
|
||||||
(await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList : (await NTQQMsgApi.getAioFirstViewLatestMsgs(peer, MsgCount)).msgList;
|
(await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList : (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, MsgCount)).msgList;
|
||||||
if (msgList.length === 0) throw `消息${payload.message_seq}不存在`;
|
if (msgList.length === 0) throw `消息${payload.message_seq}不存在`;
|
||||||
//翻转消息
|
//翻转消息
|
||||||
if (isReverseOrder) msgList.reverse();
|
if (isReverseOrder) msgList.reverse();
|
||||||
|
@@ -15,8 +15,7 @@ export class GetOnlineClient extends BaseAction<void, Array<any>> {
|
|||||||
|
|
||||||
async _handle(payload: void) {
|
async _handle(payload: void) {
|
||||||
//注册监听
|
//注册监听
|
||||||
const NTQQSystemApi = this.core.apis.SystemApi;
|
this.core.apis.SystemApi.getOnlineDev();
|
||||||
NTQQSystemApi.getOnlineDev();
|
|
||||||
await sleep(500);
|
await sleep(500);
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
|
@@ -19,10 +19,9 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
|||||||
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<OB11User> {
|
async _handle(payload: Payload): Promise<OB11User> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const user_id = payload.user_id.toString();
|
const user_id = payload.user_id.toString();
|
||||||
const extendData = await NTQQUserApi.getUserDetailInfoByUinV2(user_id);
|
const extendData = await this.core.apis.UserApi.getUserDetailInfoByUinV2(user_id);
|
||||||
const uid = (await NTQQUserApi.getUidByUinV2(user_id))!;
|
const uid = (await this.core.apis.UserApi.getUidByUinV2(user_id))!;
|
||||||
if (!uid || uid.indexOf('*') != -1) {
|
if (!uid || uid.indexOf('*') != -1) {
|
||||||
return {
|
return {
|
||||||
...extendData.detail.simpleInfo.coreInfo,
|
...extendData.detail.simpleInfo.coreInfo,
|
||||||
@@ -38,7 +37,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
|||||||
login_days: 0,
|
login_days: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const data = { ...extendData, ...(await NTQQUserApi.getUserDetailInfo(uid)) };
|
const data = { ...extendData, ...(await this.core.apis.UserApi.getUserDetailInfo(uid)) };
|
||||||
return OB11Entities.stranger(data);
|
return OB11Entities.stranger(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,6 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
|
let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
|
||||||
if (payload.image) {
|
if (payload.image) {
|
||||||
//公告图逻辑
|
//公告图逻辑
|
||||||
@@ -38,7 +37,7 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
|
|||||||
throw `群公告${payload.image}设置失败,获取资源失败`;
|
throw `群公告${payload.image}设置失败,获取资源失败`;
|
||||||
}
|
}
|
||||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||||
const ImageUploadResult = await NTQQGroupApi.uploadGroupBulletinPic(payload.group_id.toString(), path);
|
const ImageUploadResult = await this.core.apis.GroupApi.uploadGroupBulletinPic(payload.group_id.toString(), path);
|
||||||
if (ImageUploadResult.errCode != 0) {
|
if (ImageUploadResult.errCode != 0) {
|
||||||
throw `群公告${payload.image}设置失败,图片上传失败`;
|
throw `群公告${payload.image}设置失败,图片上传失败`;
|
||||||
}
|
}
|
||||||
@@ -50,7 +49,7 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
|
|||||||
}
|
}
|
||||||
const noticePinned = +(payload.pinned ?? 0);
|
const noticePinned = +(payload.pinned ?? 0);
|
||||||
const noticeConfirmRequired = +(payload.confirm_required ?? 0);
|
const noticeConfirmRequired = +(payload.confirm_required ?? 0);
|
||||||
const publishGroupBulletinResult = await NTQQGroupApi.publishGroupBulletin(payload.group_id.toString(), payload.content, UploadImage, noticePinned, noticeConfirmRequired);
|
const publishGroupBulletinResult = await this.core.apis.GroupApi.publishGroupBulletin(payload.group_id.toString(), payload.content, UploadImage, noticePinned, noticeConfirmRequired);
|
||||||
|
|
||||||
if (publishGroupBulletinResult.result != 0) {
|
if (publishGroupBulletinResult.result != 0) {
|
||||||
throw `设置群公告失败,错误信息:${publishGroupBulletinResult.errMsg}`;
|
throw `设置群公告失败,错误信息:${publishGroupBulletinResult.errMsg}`;
|
||||||
|
@@ -25,14 +25,13 @@ export default class SetGroupPortrait extends BaseAction<Payload, any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<any> {
|
async _handle(payload: Payload): Promise<any> {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const { path, isLocal, success } = (await uri2local(this.core.NapCatTempPath, payload.file));
|
||||||
const { path, isLocal, errMsg, success } = (await uri2local(this.core.NapCatTempPath, payload.file));
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||||
const ret = await NTQQGroupApi.setGroupAvatar(payload.group_id.toString(), path) as any;
|
const ret = await this.core.apis.GroupApi.setGroupAvatar(payload.group_id.toString(), path) as any;
|
||||||
if (!isLocal) {
|
if (!isLocal) {
|
||||||
fs.unlink(path, () => {
|
fs.unlink(path, () => {
|
||||||
});
|
});
|
||||||
|
@@ -19,10 +19,9 @@ export class SetQQProfile extends BaseAction<Payload, any | null> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const self = this.core.selfInfo;
|
const self = this.core.selfInfo;
|
||||||
const OldProfile = await NTQQUserApi.getUserDetailInfo(self.uid);
|
const OldProfile = await this.core.apis.UserApi.getUserDetailInfo(self.uid);
|
||||||
return await NTQQUserApi.modifySelfProfile({
|
return await this.core.apis.UserApi.modifySelfProfile({
|
||||||
nick: payload.nickname,
|
nick: payload.nickname,
|
||||||
longNick: (payload?.personal_note ?? OldProfile?.longNick) || '',
|
longNick: (payload?.personal_note ?? OldProfile?.longNick) || '',
|
||||||
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.sex!.toString()),
|
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.sex!.toString()),
|
||||||
|
@@ -22,14 +22,12 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async getPeer(payload: Payload): Promise<Peer> {
|
async getPeer(payload: Payload): Promise<Peer> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const NTQQFriendApi = this.core.apis.FriendApi;
|
|
||||||
if (payload.user_id) {
|
if (payload.user_id) {
|
||||||
const peerUid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
const peerUid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
if (!peerUid) {
|
if (!peerUid) {
|
||||||
throw `私聊${payload.user_id}不存在`;
|
throw `私聊${payload.user_id}不存在`;
|
||||||
}
|
}
|
||||||
const isBuddy = await NTQQFriendApi.isBuddy(peerUid);
|
const isBuddy = await this.core.apis.FriendApi.isBuddy(peerUid);
|
||||||
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
|
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
|
||||||
}
|
}
|
||||||
throw new Error('缺少参数 user_id');
|
throw new Error('缺少参数 user_id');
|
||||||
|
@@ -18,16 +18,14 @@ export default class DelEssenceMsg extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<any> {
|
async _handle(payload: Payload): Promise<any> {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
|
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
|
||||||
const NTQQWebApi = this.core.apis.WebApi;
|
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
const data = NTQQGroupApi.essenceLRU.getValue(+payload.message_id);
|
const data = this.core.apis.GroupApi.essenceLRU.getValue(+payload.message_id);
|
||||||
if(!data) throw new Error('消息不存在');
|
if(!data) throw new Error('消息不存在');
|
||||||
const { msg_seq, msg_random, group_id } = JSON.parse(data) as { msg_seq: string, msg_random: string, group_id: string };
|
const { msg_seq, msg_random, group_id } = JSON.parse(data) as { msg_seq: string, msg_random: string, group_id: string };
|
||||||
return await NTQQGroupApi.removeGroupEssenceBySeq(group_id, msg_seq, msg_random);
|
return await this.core.apis.GroupApi.removeGroupEssenceBySeq(group_id, msg_seq, msg_random);
|
||||||
}
|
}
|
||||||
return await NTQQGroupApi.removeGroupEssence(
|
return await this.core.apis.GroupApi.removeGroupEssence(
|
||||||
msg.Peer.peerUid,
|
msg.Peer.peerUid,
|
||||||
msg.MsgId,
|
msg.MsgId,
|
||||||
);
|
);
|
||||||
|
@@ -19,9 +19,8 @@ export class DelGroupNotice extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const group = payload.group_id.toString();
|
const group = payload.group_id.toString();
|
||||||
const noticeId = payload.notice_id;
|
const noticeId = payload.notice_id;
|
||||||
return await NTQQGroupApi.deleteGroupBulletin(group, noticeId);
|
return await this.core.apis.GroupApi.deleteGroupBulletin(group, noticeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,9 +31,7 @@ export class GetGroupEssence extends BaseAction<Payload, any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQWebApi = this.core.apis.WebApi;
|
const msglist = (await this.core.apis.WebApi.getGroupEssenceMsgAll(payload.group_id.toString())).flatMap((e) => e.data.msg_list);
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const msglist = (await NTQQWebApi.getGroupEssenceMsgAll(payload.group_id.toString())).flatMap((e) => e.data.msg_list);
|
|
||||||
if (!msglist) {
|
if (!msglist) {
|
||||||
throw new Error('获取失败');
|
throw new Error('获取失败');
|
||||||
}
|
}
|
||||||
@@ -65,7 +63,7 @@ export class GetGroupEssence extends BaseAction<Payload, any> {
|
|||||||
//设置第一个bit为0 保证shortId为正数
|
//设置第一个bit为0 保证shortId为正数
|
||||||
hash[0] &= 0x7f;
|
hash[0] &= 0x7f;
|
||||||
const shortId = hash.readInt32BE(0);
|
const shortId = hash.readInt32BE(0);
|
||||||
NTQQGroupApi.essenceLRU.set(shortId, msgTempData);
|
this.core.apis.GroupApi.essenceLRU.set(shortId, msgTempData);
|
||||||
return {
|
return {
|
||||||
msg_seq: msg.msg_seq,
|
msg_seq: msg.msg_seq,
|
||||||
msg_random: msg.msg_random,
|
msg_random: msg.msg_random,
|
||||||
|
@@ -16,21 +16,19 @@ export class GetGroupIgnoredNotifies extends BaseAction<void, any> {
|
|||||||
actionName = ActionName.GetGroupIgnoredNotifies;
|
actionName = ActionName.GetGroupIgnoredNotifies;
|
||||||
|
|
||||||
async _handle(payload: void) {
|
async _handle(payload: void) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const ignoredNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(true, 10);
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const ignoredNotifies = await NTQQGroupApi.getSingleScreenNotifies(true, 10);
|
|
||||||
const retData: any = {
|
const retData: any = {
|
||||||
join_requests: await Promise.all(
|
join_requests: await Promise.all(
|
||||||
ignoredNotifies
|
ignoredNotifies
|
||||||
.filter(notify => notify.type === 7)
|
.filter(notify => notify.type === 7)
|
||||||
.map(async SSNotify => ({
|
.map(async SSNotify => ({
|
||||||
request_id: SSNotify.seq,
|
request_id: SSNotify.seq,
|
||||||
requester_uin: await NTQQUserApi.getUinByUidV2(SSNotify.user1?.uid),
|
requester_uin: await this.core.apis.UserApi.getUinByUidV2(SSNotify.user1?.uid),
|
||||||
requester_nick: SSNotify.user1?.nickName,
|
requester_nick: SSNotify.user1?.nickName,
|
||||||
group_id: SSNotify.group?.groupCode,
|
group_id: SSNotify.group?.groupCode,
|
||||||
group_name: SSNotify.group?.groupName,
|
group_name: SSNotify.group?.groupName,
|
||||||
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
checked: SSNotify.status !== GroupNotifyMsgStatus.KUNHANDLE,
|
||||||
actor: await NTQQUserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
actor: await this.core.apis.UserApi.getUinByUidV2(SSNotify.user2?.uid) || 0,
|
||||||
}))),
|
}))),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -19,8 +19,7 @@ class GetGroupInfo extends BaseAction<Payload, OB11Group> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const group = (await this.core.apis.GroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString());
|
||||||
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString());
|
|
||||||
if (!group) throw `群${payload.group_id}不存在`;
|
if (!group) throw `群${payload.group_id}不存在`;
|
||||||
return OB11Entities.group(group);
|
return OB11Entities.group(group);
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@ import { OB11Group } from '@/onebot';
|
|||||||
import { OB11Entities } from '@/onebot/entities';
|
import { OB11Entities } from '@/onebot/entities';
|
||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { Group } from '@/core/entities';
|
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
// no_cache get时传字符串
|
// no_cache get时传字符串
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
@@ -19,9 +18,9 @@ class GetGroupList extends BaseAction<Payload, OB11Group[]> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
return OB11Entities.groups(
|
||||||
const groupList: Group[] = await NTQQGroupApi.getGroups(typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache);
|
await this.core.apis.GroupApi.getGroups(
|
||||||
return OB11Entities.groups(groupList);
|
typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,14 +22,12 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const isNocache = typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache;
|
const isNocache = typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache;
|
||||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
if (!uid) throw new Error(`Uin2Uid Error ${payload.user_id}不存在`);
|
if (!uid) throw new Error(`Uin2Uid Error ${payload.user_id}不存在`);
|
||||||
const [member, info] = await Promise.allSettled([
|
const [member, info] = await Promise.allSettled([
|
||||||
NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache),
|
this.core.apis.GroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache),
|
||||||
NTQQUserApi.getUserDetailInfo(uid),
|
this.core.apis.UserApi.getUserDetailInfo(uid),
|
||||||
]);
|
]);
|
||||||
if (member.status !== 'fulfilled') throw new Error(`群(${payload.group_id})成员${payload.user_id}获取失败 ${member.reason}`);
|
if (member.status !== 'fulfilled') throw new Error(`群(${payload.group_id})成员${payload.user_id}获取失败 ${member.reason}`);
|
||||||
if (!member.value) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`);
|
if (!member.value) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`);
|
||||||
|
@@ -20,9 +20,7 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const groupMembers = await this.core.apis.GroupApi.getGroupMembersV2(payload.group_id.toString());
|
||||||
const NTQQWebApi = this.core.apis.WebApi;
|
|
||||||
const groupMembers = await NTQQGroupApi.getGroupMembersV2(payload.group_id.toString());
|
|
||||||
const groupMembersArr = Array.from(groupMembers.values());
|
const groupMembersArr = Array.from(groupMembers.values());
|
||||||
|
|
||||||
let _groupMembers = groupMembersArr.map(item => {
|
let _groupMembers = groupMembersArr.map(item => {
|
||||||
@@ -48,7 +46,7 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isPrivilege) {
|
if (isPrivilege) {
|
||||||
const webGroupMembers = await NTQQWebApi.getGroupMembers(payload.group_id.toString());
|
const webGroupMembers = await this.core.apis.WebApi.getGroupMembers(payload.group_id.toString());
|
||||||
for (let i = 0, len = webGroupMembers.length; i < len; i++) {
|
for (let i = 0, len = webGroupMembers.length; i < len; i++) {
|
||||||
if (!webGroupMembers[i]?.uin) {
|
if (!webGroupMembers[i]?.uin) {
|
||||||
continue;
|
continue;
|
||||||
|
@@ -34,10 +34,8 @@ export class GetGroupNotice extends BaseAction<Payload, GroupNotice[]> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQWebApi = this.core.apis.WebApi;
|
|
||||||
|
|
||||||
const group = payload.group_id.toString();
|
const group = payload.group_id.toString();
|
||||||
const ret = await NTQQWebApi.getGroupNotice(group);
|
const ret = await this.core.apis.WebApi.getGroupNotice(group);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
throw new Error('获取公告失败');
|
throw new Error('获取公告失败');
|
||||||
}
|
}
|
||||||
|
@@ -18,12 +18,11 @@ export default class SetEssenceMsg extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<any> {
|
async _handle(payload: Payload): Promise<any> {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw new Error('msg not found');
|
throw new Error('msg not found');
|
||||||
}
|
}
|
||||||
return await NTQQGroupApi.addGroupEssence(
|
return await this.core.apis.GroupApi.addGroupEssence(
|
||||||
msg.Peer.peerUid,
|
msg.Peer.peerUid,
|
||||||
msg.MsgId,
|
msg.MsgId,
|
||||||
);
|
);
|
||||||
|
@@ -20,10 +20,9 @@ export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const flag = payload.flag.toString();
|
const flag = payload.flag.toString();
|
||||||
const approve = payload.approve?.toString() !== 'false';
|
const approve = payload.approve?.toString() !== 'false';
|
||||||
await NTQQGroupApi.handleGroupRequest(flag,
|
await this.core.apis.GroupApi.handleGroupRequest(flag,
|
||||||
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||||
payload.reason ?? ' ',
|
payload.reason ?? ' ',
|
||||||
);
|
);
|
||||||
|
@@ -21,11 +21,9 @@ export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
|||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const enable = typeof payload.enable === 'string' ? payload.enable === 'true' : !!payload.enable;
|
const enable = typeof payload.enable === 'string' ? payload.enable === 'true' : !!payload.enable;
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
|
||||||
if (!uid) throw new Error('get Uid Error');
|
if (!uid) throw new Error('get Uid Error');
|
||||||
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, enable ? GroupMemberRole.admin : GroupMemberRole.normal);
|
await this.core.apis.GroupApi.setMemberRole(payload.group_id.toString(), uid, enable ? GroupMemberRole.admin : GroupMemberRole.normal);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,11 +19,9 @@ export default class SetGroupBan extends BaseAction<Payload, null> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
|
||||||
if (!uid) throw new Error('uid error');
|
if (!uid) throw new Error('uid error');
|
||||||
await NTQQGroupApi.banMember(payload.group_id.toString(),
|
await this.core.apis.GroupApi.banMember(payload.group_id.toString(),
|
||||||
[{ uid: uid, timeStamp: parseInt(payload.duration.toString()) }]);
|
[{ uid: uid, timeStamp: parseInt(payload.duration.toString()) }]);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -19,9 +19,8 @@ export default class SetGroupCard extends BaseAction<Payload, null> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const member = await this.core.apis.GroupApi.getGroupMember(payload.group_id.toString(), payload.user_id.toString());
|
||||||
const member = await NTQQGroupApi.getGroupMember(payload.group_id.toString(), payload.user_id.toString());
|
if (member) await this.core.apis.GroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || '');
|
||||||
member && await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || '');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,12 +20,10 @@ export default class SetGroupKick extends BaseAction<Payload, null> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const rejectReq = payload.reject_add_request?.toString() == 'true';
|
const rejectReq = payload.reject_add_request?.toString() == 'true';
|
||||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
if (!uid) throw new Error('get Uid Error');
|
if (!uid) throw new Error('get Uid Error');
|
||||||
await NTQQGroupApi.kickMember(payload.group_id.toString(), [uid], rejectReq);
|
await this.core.apis.GroupApi.kickMember(payload.group_id.toString(), [uid], rejectReq);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,6 @@ export default class SetGroupLeave extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<any> {
|
async _handle(payload: Payload): Promise<any> {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
await this.core.apis.GroupApi.quitGroup(payload.group_id.toString());
|
||||||
await NTQQGroupApi.quitGroup(payload.group_id.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,8 +17,7 @@ export default class SetGroupName extends BaseAction<Payload, null> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
await this.core.apis.GroupApi.setGroupName(payload.group_id.toString(), payload.group_name);
|
||||||
await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,8 +19,7 @@ export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
|||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const enable = payload.enable?.toString() !== 'false';
|
const enable = payload.enable?.toString() !== 'false';
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
await this.core.apis.GroupApi.banGroup(payload.group_id.toString(), enable);
|
||||||
await NTQQGroupApi.banGroup(payload.group_id.toString(), enable);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,6 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
|
const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
|
||||||
if (msg) {
|
if (msg) {
|
||||||
const ret = this.core.eventWrapper.registerListen(
|
const ret = this.core.eventWrapper.registerListen(
|
||||||
@@ -34,7 +33,7 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
|||||||
).catch(() => new Promise<undefined>((resolve) => {
|
).catch(() => new Promise<undefined>((resolve) => {
|
||||||
resolve(undefined);
|
resolve(undefined);
|
||||||
}));
|
}));
|
||||||
await NTQQMsgApi.recallMsg(msg.Peer, [msg.MsgId]);
|
await this.core.apis.MsgApi.recallMsg(msg.Peer, [msg.MsgId]);
|
||||||
const data = await ret;
|
const data = await ret;
|
||||||
if (!data) {
|
if (!data) {
|
||||||
//throw new Error('Recall failed');
|
//throw new Error('Recall failed');
|
||||||
|
@@ -18,9 +18,8 @@ type Payload = FromSchema<typeof SchemaData>;
|
|||||||
|
|
||||||
class ForwardSingleMsg extends BaseAction<Payload, null> {
|
class ForwardSingleMsg extends BaseAction<Payload, null> {
|
||||||
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
if (payload.user_id) {
|
if (payload.user_id) {
|
||||||
const peerUid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
const peerUid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
if (!peerUid) {
|
if (!peerUid) {
|
||||||
throw new Error(`无法找到私聊对象${payload.user_id}`);
|
throw new Error(`无法找到私聊对象${payload.user_id}`);
|
||||||
}
|
}
|
||||||
@@ -30,13 +29,12 @@ class ForwardSingleMsg extends BaseAction<Payload, null> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw new Error(`无法找到消息${payload.message_id}`);
|
throw new Error(`无法找到消息${payload.message_id}`);
|
||||||
}
|
}
|
||||||
const peer = await this.getTargetPeer(payload);
|
const peer = await this.getTargetPeer(payload);
|
||||||
const ret = await NTQQMsgApi.forwardMsg(msg.Peer,
|
const ret = await this.core.apis.MsgApi.forwardMsg(msg.Peer,
|
||||||
peer,
|
peer,
|
||||||
[msg.MsgId],
|
[msg.MsgId],
|
||||||
);
|
);
|
||||||
|
@@ -22,7 +22,6 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
// log("history msg ids", Object.keys(msgHistory));
|
// log("history msg ids", Object.keys(msgHistory));
|
||||||
if (!payload.message_id) {
|
if (!payload.message_id) {
|
||||||
throw Error('参数message_id不能为空');
|
throw Error('参数message_id不能为空');
|
||||||
@@ -33,7 +32,7 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
|
|||||||
throw new Error('消息不存在');
|
throw new Error('消息不存在');
|
||||||
}
|
}
|
||||||
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
|
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
|
||||||
const msg = await NTQQMsgApi.getMsgsByMsgId(
|
const msg = await this.core.apis.MsgApi.getMsgsByMsgId(
|
||||||
peer,
|
peer,
|
||||||
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
||||||
const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg.msgList[0], 'array');
|
const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg.msgList[0], 'array');
|
||||||
|
@@ -15,14 +15,12 @@ type PlayloadType = FromSchema<typeof SchemaData>;
|
|||||||
|
|
||||||
class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
||||||
async getPeer(payload: PlayloadType): Promise<Peer> {
|
async getPeer(payload: PlayloadType): Promise<Peer> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const NTQQFriendApi = this.core.apis.FriendApi;
|
|
||||||
if (payload.user_id) {
|
if (payload.user_id) {
|
||||||
const peerUid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
const peerUid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
if (!peerUid) {
|
if (!peerUid) {
|
||||||
throw `私聊${payload.user_id}不存在`;
|
throw `私聊${payload.user_id}不存在`;
|
||||||
}
|
}
|
||||||
const isBuddy = await NTQQFriendApi.isBuddy(peerUid);
|
const isBuddy = await this.core.apis.FriendApi.isBuddy(peerUid);
|
||||||
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
|
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
|
||||||
}
|
}
|
||||||
if (!payload.group_id) {
|
if (!payload.group_id) {
|
||||||
@@ -32,9 +30,7 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _handle(payload: PlayloadType): Promise<null> {
|
async _handle(payload: PlayloadType): Promise<null> {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
const ret = await this.core.apis.MsgApi.setMsgRead(await this.getPeer(payload));
|
||||||
// 调用API
|
|
||||||
const ret = await NTQQMsgApi.setMsgRead(await this.getPeer(payload));
|
|
||||||
if (ret.result != 0) {
|
if (ret.result != 0) {
|
||||||
throw new Error('设置已读失败,' + ret.errMsg);
|
throw new Error('设置已读失败,' + ret.errMsg);
|
||||||
}
|
}
|
||||||
@@ -70,8 +66,7 @@ export class MarkAllMsgAsRead extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName._MarkAllMsgAsRead;
|
actionName = ActionName._MarkAllMsgAsRead;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
await this.core.apis.MsgApi.markAllMsgAsRead();
|
||||||
await NTQQMsgApi.markAllMsgAsRead();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,9 +34,6 @@ export async function createContext(core: NapCatCore, payload: OB11PostSendMsg,
|
|||||||
// This function determines the type of message by the existence of user_id / group_id,
|
// This function determines the type of message by the existence of user_id / group_id,
|
||||||
// not message_type.
|
// not message_type.
|
||||||
// This redundant design of Ob11 here should be blamed.
|
// This redundant design of Ob11 here should be blamed.
|
||||||
const NTQQFriendApi = core.apis.FriendApi;
|
|
||||||
const NTQQUserApi = core.apis.UserApi;
|
|
||||||
const NTQQMsgApi = core.apis.MsgApi;
|
|
||||||
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
||||||
return {
|
return {
|
||||||
chatType: ChatType.KCHATTYPEGROUP,
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
@@ -44,11 +41,11 @@ export async function createContext(core: NapCatCore, payload: OB11PostSendMsg,
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
||||||
const Uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
const Uid = await core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
if (!Uid) throw new Error('无法获取用户信息');
|
if (!Uid) throw new Error('无法获取用户信息');
|
||||||
const isBuddy = await NTQQFriendApi.isBuddy(Uid);
|
const isBuddy = await core.apis.FriendApi.isBuddy(Uid);
|
||||||
if (!isBuddy) {
|
if (!isBuddy) {
|
||||||
const ret = await NTQQMsgApi.getTempChatInfo(ChatType.KCHATTYPETEMPC2CFROMGROUP, Uid);
|
const ret = await core.apis.MsgApi.getTempChatInfo(ChatType.KCHATTYPETEMPC2CFROMGROUP, Uid);
|
||||||
if (ret.tmpChatInfo?.groupCode) {
|
if (ret.tmpChatInfo?.groupCode) {
|
||||||
return {
|
return {
|
||||||
chatType: ChatType.KCHATTYPETEMPC2CFROMGROUP,
|
chatType: ChatType.KCHATTYPETEMPC2CFROMGROUP,
|
||||||
@@ -139,7 +136,6 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleForwardedNodes(destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<RawMessage | null> {
|
private async handleForwardedNodes(destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<RawMessage | null> {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const selfPeer = {
|
const selfPeer = {
|
||||||
chatType: ChatType.KCHATTYPEC2C,
|
chatType: ChatType.KCHATTYPEC2C,
|
||||||
peerUid: this.core.selfInfo.uid,
|
peerUid: this.core.selfInfo.uid,
|
||||||
@@ -206,7 +202,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
logger.logError('转发消息失败,未找到消息', msgId);
|
logger.logError('转发消息失败,未找到消息', msgId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0];
|
const nodeMsg = (await this.core.apis.MsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0];
|
||||||
srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid };
|
srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid };
|
||||||
if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||||
needSendSelf = true;
|
needSendSelf = true;
|
||||||
@@ -230,7 +226,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
if (retMsgIds.length === 0) throw Error('转发消息失败,生成节点为空');
|
if (retMsgIds.length === 0) throw Error('转发消息失败,生成节点为空');
|
||||||
try {
|
try {
|
||||||
logger.logDebug('开发转发', srcPeer, destPeer, retMsgIds);
|
logger.logDebug('开发转发', srcPeer, destPeer, retMsgIds);
|
||||||
return await NTQQMsgApi.multiForwardMsg(srcPeer!, destPeer, retMsgIds);
|
return await this.core.apis.MsgApi.multiForwardMsg(srcPeer!, destPeer, retMsgIds);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.logError('forward failed', e);
|
logger.logError('forward failed', e);
|
||||||
return null;
|
return null;
|
||||||
@@ -243,9 +239,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
peerUid: this.core.selfInfo.uid,
|
peerUid: this.core.selfInfo.uid,
|
||||||
};
|
};
|
||||||
const logger = this.core.context.logger;
|
const logger = this.core.context.logger;
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
//msg 为待克隆消息
|
//msg 为待克隆消息
|
||||||
|
|
||||||
const sendElements: SendMessageElement[] = [];
|
const sendElements: SendMessageElement[] = [];
|
||||||
|
|
||||||
for (const element of msg.elements) {
|
for (const element of msg.elements) {
|
||||||
@@ -256,7 +250,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
logger.logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
logger.logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return await NTQQMsgApi.sendMsg(selfPeer, sendElements, true);
|
return await this.core.apis.MsgApi.sendMsg(selfPeer, sendElements, true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.logError(e, '克隆转发消息失败,将忽略本条消息', msg);
|
logger.logError(e, '克隆转发消息失败,将忽略本条消息', msg);
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@ export class SetMsgEmojiLike extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw new Error('msg not found');
|
throw new Error('msg not found');
|
||||||
@@ -27,10 +26,10 @@ export class SetMsgEmojiLike extends BaseAction<Payload, any> {
|
|||||||
if (!payload.emoji_id) {
|
if (!payload.emoji_id) {
|
||||||
throw new Error('emojiId not found');
|
throw new Error('emojiId not found');
|
||||||
}
|
}
|
||||||
const msgData = (await NTQQMsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId])).msgList;
|
const msgData = (await this.core.apis.MsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId])).msgList;
|
||||||
if (!msgData || msgData.length == 0 || !msgData[0].msgSeq) {
|
if (!msgData || msgData.length == 0 || !msgData[0].msgSeq) {
|
||||||
throw new Error('find msg by msgid error');
|
throw new Error('find msg by msgid error');
|
||||||
}
|
}
|
||||||
return await NTQQMsgApi.setEmojiLike(msg.Peer, msgData[0].msgSeq, payload.emoji_id.toString(), true);
|
return await this.core.apis.MsgApi.setEmojiLike(msg.Peer, msgData[0].msgSeq, payload.emoji_id.toString(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,52 +22,10 @@ export class GetCookies extends BaseAction<Payload, Response> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const cookiesObject = await this.core.apis.UserApi.getCookies(payload.domain);
|
||||||
const NTQQWebApi = this.core.apis.WebApi;
|
|
||||||
// if (!payload.domain) {
|
|
||||||
// throw new Error('缺少参数 domain');
|
|
||||||
// }
|
|
||||||
// if (payload.domain.endsWith('qzone.qq.com')) {
|
|
||||||
// // 兼容整个 *.qzone.qq.com
|
|
||||||
// const data = (await NTQQUserApi.getQzoneCookies());
|
|
||||||
// const Bkn = WebApi.genBkn(data.p_skey);
|
|
||||||
// const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin;
|
|
||||||
// return { cookies: CookieValue };
|
|
||||||
// }
|
|
||||||
// // 取Skey
|
|
||||||
// // 先NodeIKernelTicketService.forceFetchClientKey('')
|
|
||||||
// // 返回值
|
|
||||||
// // {
|
|
||||||
// // result: 0,
|
|
||||||
// // errMsg: '',
|
|
||||||
// // url: '',
|
|
||||||
// // keyIndex: '19',
|
|
||||||
// // clientKey: 'clientKey',
|
|
||||||
// // expireTime: '7200'
|
|
||||||
// // }
|
|
||||||
// // request https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=1627126029&clientkey=key
|
|
||||||
// // &u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=keyIndex
|
|
||||||
// const _PSkey = (await NTQQUserApi.getPSkey([payload.domain]))[payload.domain];
|
|
||||||
// // 取Pskey
|
|
||||||
// // NodeIKernelTipOffService.getPskey([ 'qun.qq.com' ], true )
|
|
||||||
// // {
|
|
||||||
// // domainPskeyMap: 0,
|
|
||||||
// // errMsg: 'success',
|
|
||||||
// // domainPskeyMap: Map(1) {
|
|
||||||
// // 'qun.qq.com' => 'pskey'
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// if (!_PSkey || !_Skey) {
|
|
||||||
// throw new Error('获取Cookies失败');
|
|
||||||
// }
|
|
||||||
// const cookies = `p_skey=${_PSkey}; skey=${_Skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}`;
|
|
||||||
// return {
|
|
||||||
// cookies
|
|
||||||
// };
|
|
||||||
const cookiesObject = await NTQQUserApi.getCookies(payload.domain);
|
|
||||||
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
|
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
|
||||||
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
|
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
|
||||||
const bkn = cookiesObject?.skey ? NTQQWebApi.getBknFromCookie(cookiesObject) : '';
|
const bkn = cookiesObject?.skey ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : '';
|
||||||
return { cookies, bkn };
|
return { cookies, bkn };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@ export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
|
|||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
//全新逻辑
|
//全新逻辑
|
||||||
const NTQQFriendApi = this.core.apis.FriendApi;
|
return OB11Entities.friendsV2(await this.core.apis.FriendApi.getBuddyV2(typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache));
|
||||||
return OB11Entities.friendsV2(await NTQQFriendApi.getBuddyV2(typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,11 +16,9 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+(payload.count || 10));
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const ret = await NTQQUserApi.getRecentContactListSnapShot(+(payload.count || 10));
|
|
||||||
return await Promise.all(ret.info.changedList.map(async (t) => {
|
return await Promise.all(ret.info.changedList.map(async (t) => {
|
||||||
const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
|
const FastMsg = await this.core.apis.MsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
|
||||||
if (FastMsg.msgList.length > 0) {
|
if (FastMsg.msgList.length > 0) {
|
||||||
//扩展ret.info.changedList
|
//扩展ret.info.changedList
|
||||||
const lastestMsg = await this.obContext.apis.MsgApi.parseMessage(FastMsg.msgList[0], 'array');
|
const lastestMsg = await this.obContext.apis.MsgApi.parseMessage(FastMsg.msgList[0], 'array');
|
||||||
|
@@ -18,11 +18,10 @@ export default class SendLike extends BaseAction<Payload, null> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
//logDebug('点赞参数', payload);
|
//logDebug('点赞参数', payload);
|
||||||
const qq = payload.user_id.toString();
|
const qq = payload.user_id.toString();
|
||||||
const uid: string = await NTQQUserApi.getUidByUinV2(qq) || '';
|
const uid: string = await this.core.apis.UserApi.getUidByUinV2(qq) || '';
|
||||||
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1);
|
const result = await this.core.apis.UserApi.like(uid, parseInt(payload.times?.toString()) || 1);
|
||||||
//logDebug('点赞结果', result);
|
//logDebug('点赞结果', result);
|
||||||
if (result.result !== 0) {
|
if (result.result !== 0) {
|
||||||
throw `点赞失败 ${result.errMsg}`;
|
throw `点赞失败 ${result.errMsg}`;
|
||||||
|
@@ -19,9 +19,8 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
|
|||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
const NTQQFriendApi = this.core.apis.FriendApi;
|
|
||||||
const approve = payload.approve?.toString() !== 'false';
|
const approve = payload.approve?.toString() !== 'false';
|
||||||
await NTQQFriendApi.handleFriendRequest(payload.flag, approve);
|
await this.core.apis.FriendApi.handleFriendRequest(payload.flag, approve);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,6 @@ export class OneBotFriendApi {
|
|||||||
|
|
||||||
//使用前预先判断 busiId 1061
|
//使用前预先判断 busiId 1061
|
||||||
async parsePrivatePokeEvent(grayTipElement: GrayTipElement) {
|
async parsePrivatePokeEvent(grayTipElement: GrayTipElement) {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr);
|
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr);
|
||||||
let pokedetail: any[] = json.items;
|
let pokedetail: any[] = json.items;
|
||||||
//筛选item带有uid的元素
|
//筛选item带有uid的元素
|
||||||
@@ -23,8 +22,8 @@ export class OneBotFriendApi {
|
|||||||
if (pokedetail.length == 2) {
|
if (pokedetail.length == 2) {
|
||||||
return new OB11FriendPokeEvent(
|
return new OB11FriendPokeEvent(
|
||||||
this.core,
|
this.core,
|
||||||
parseInt((await NTQQUserApi.getUinByUidV2(pokedetail[0].uid))!),
|
parseInt((await this.core.apis.UserApi.getUinByUidV2(pokedetail[0].uid))!),
|
||||||
parseInt((await NTQQUserApi.getUinByUidV2(pokedetail[1].uid))!),
|
parseInt((await this.core.apis.UserApi.getUinByUidV2(pokedetail[1].uid))!),
|
||||||
pokedetail,
|
pokedetail,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -30,16 +30,13 @@ export class OneBotGroupApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async parseGroupEvent(msg: RawMessage) {
|
async parseGroupEvent(msg: RawMessage) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const logger = this.core.context.logger;
|
const logger = this.core.context.logger;
|
||||||
if (msg.chatType !== ChatType.KCHATTYPEGROUP) {
|
if (msg.chatType !== ChatType.KCHATTYPEGROUP) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//log("group msg", msg);
|
//log("group msg", msg);
|
||||||
if (msg.senderUin && msg.senderUin !== '0') {
|
if (msg.senderUin && msg.senderUin !== '0') {
|
||||||
const member = await NTQQGroupApi.getGroupMember(msg.peerUid, msg.senderUin);
|
const member = await this.core.apis.GroupApi.getGroupMember(msg.peerUid, msg.senderUin);
|
||||||
if (member && member.cardName !== msg.sendMemberName) {
|
if (member && member.cardName !== msg.sendMemberName) {
|
||||||
const newCardName = msg.sendMemberName || '';
|
const newCardName = msg.sendMemberName || '';
|
||||||
const event = new OB11GroupCardEvent(this.core, parseInt(msg.peerUid), parseInt(msg.senderUin), newCardName, member.cardName);
|
const event = new OB11GroupCardEvent(this.core, parseInt(msg.peerUid), parseInt(msg.senderUin), newCardName, member.cardName);
|
||||||
@@ -58,7 +55,7 @@ export class OneBotGroupApi {
|
|||||||
const BanEvent = await this.obContext.apis.GroupApi.parseGroupBanEvent(msg.peerUid, element.grayTipElement);
|
const BanEvent = await this.obContext.apis.GroupApi.parseGroupBanEvent(msg.peerUid, element.grayTipElement);
|
||||||
if (BanEvent) return BanEvent;
|
if (BanEvent) return BanEvent;
|
||||||
} else if (groupElement.type == TipGroupElementType.kicked) {
|
} else if (groupElement.type == TipGroupElementType.kicked) {
|
||||||
NTQQGroupApi.quitGroup(msg.peerUid).then();
|
this.core.apis.GroupApi.quitGroup(msg.peerUid).then();
|
||||||
try {
|
try {
|
||||||
const KickEvent = await this.obContext.apis.GroupApi.parseGroupKickEvent(msg.peerUid, element.grayTipElement);
|
const KickEvent = await this.obContext.apis.GroupApi.parseGroupKickEvent(msg.peerUid, element.grayTipElement);
|
||||||
if (KickEvent) return KickEvent;
|
if (KickEvent) return KickEvent;
|
||||||
@@ -110,8 +107,8 @@ export class OneBotGroupApi {
|
|||||||
return new OB11GroupPokeEvent(
|
return new OB11GroupPokeEvent(
|
||||||
this.core,
|
this.core,
|
||||||
parseInt(msg.peerUid),
|
parseInt(msg.peerUid),
|
||||||
parseInt((await NTQQUserApi.getUinByUidV2(poke_uid[0].uid))!),
|
parseInt((await this.core.apis.UserApi.getUinByUidV2(poke_uid[0].uid))!),
|
||||||
parseInt((await NTQQUserApi.getUinByUidV2(poke_uid[1].uid))!),
|
parseInt((await this.core.apis.UserApi.getUinByUidV2(poke_uid[1].uid))!),
|
||||||
pokedetail,
|
pokedetail,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -127,7 +124,7 @@ export class OneBotGroupApi {
|
|||||||
chatType: ChatType.KCHATTYPEGROUP,
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
peerUid: Group,
|
peerUid: Group,
|
||||||
};
|
};
|
||||||
const msgData = await NTQQMsgApi.getMsgsBySeqAndCount(Peer, msgSeq.toString(), 1, true, true);
|
const msgData = await this.core.apis.MsgApi.getMsgsBySeqAndCount(Peer, msgSeq.toString(), 1, true, true);
|
||||||
const msgList = (await this.core.apis.WebApi.getGroupEssenceMsgAll(Group)).flatMap((e) => e.data.msg_list);
|
const msgList = (await this.core.apis.WebApi.getGroupEssenceMsgAll(Group)).flatMap((e) => e.data.msg_list);
|
||||||
const realMsg = msgList.find((e) => e.msg_seq.toString() == msgSeq);
|
const realMsg = msgList.find((e) => e.msg_seq.toString() == msgSeq);
|
||||||
return new OB11GroupEssenceEvent(
|
return new OB11GroupEssenceEvent(
|
||||||
@@ -158,7 +155,6 @@ export class OneBotGroupApi {
|
|||||||
|
|
||||||
async parseGroupBanEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
async parseGroupBanEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
||||||
const groupElement = grayTipElement?.groupElement;
|
const groupElement = grayTipElement?.groupElement;
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
if (!groupElement?.shutUp) return undefined;
|
if (!groupElement?.shutUp) return undefined;
|
||||||
const memberUid = groupElement.shutUp!.member.uid;
|
const memberUid = groupElement.shutUp!.member.uid;
|
||||||
const adminUid = groupElement.shutUp!.admin.uid;
|
const adminUid = groupElement.shutUp!.admin.uid;
|
||||||
@@ -166,14 +162,14 @@ export class OneBotGroupApi {
|
|||||||
let duration = parseInt(groupElement.shutUp!.duration);
|
let duration = parseInt(groupElement.shutUp!.duration);
|
||||||
const subType: 'ban' | 'lift_ban' = duration > 0 ? 'ban' : 'lift_ban';
|
const subType: 'ban' | 'lift_ban' = duration > 0 ? 'ban' : 'lift_ban';
|
||||||
if (memberUid) {
|
if (memberUid) {
|
||||||
memberUin = (await NTQQGroupApi.getGroupMember(GroupCode, memberUid))?.uin || '';
|
memberUin = (await this.core.apis.GroupApi.getGroupMember(GroupCode, memberUid))?.uin || '';
|
||||||
} else {
|
} else {
|
||||||
memberUin = '0'; // 0表示全员禁言
|
memberUin = '0'; // 0表示全员禁言
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
duration = -1;
|
duration = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const adminUin = (await NTQQGroupApi.getGroupMember(GroupCode, adminUid))?.uin;
|
const adminUin = (await this.core.apis.GroupApi.getGroupMember(GroupCode, adminUid))?.uin;
|
||||||
if (memberUin && adminUin) {
|
if (memberUin && adminUin) {
|
||||||
return new OB11GroupBanEvent(
|
return new OB11GroupBanEvent(
|
||||||
this.core,
|
this.core,
|
||||||
@@ -215,12 +211,11 @@ export class OneBotGroupApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async parseGroupMemberIncreaseEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
async parseGroupMemberIncreaseEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const groupElement = grayTipElement?.groupElement;
|
const groupElement = grayTipElement?.groupElement;
|
||||||
if (!groupElement) return undefined;
|
if (!groupElement) return undefined;
|
||||||
const member = await NTQQGroupApi.getGroupMember(GroupCode, groupElement.memberUid);
|
const member = await this.core.apis.GroupApi.getGroupMember(GroupCode, groupElement.memberUid);
|
||||||
const memberUin = member?.uin;
|
const memberUin = member?.uin;
|
||||||
const adminMember = await NTQQGroupApi.getGroupMember(GroupCode, groupElement.adminUid);
|
const adminMember = await this.core.apis.GroupApi.getGroupMember(GroupCode, groupElement.adminUid);
|
||||||
if (memberUin) {
|
if (memberUin) {
|
||||||
const operatorUin = adminMember?.uin || memberUin;
|
const operatorUin = adminMember?.uin || memberUin;
|
||||||
return new OB11GroupIncreaseEvent(
|
return new OB11GroupIncreaseEvent(
|
||||||
@@ -235,11 +230,9 @@ export class OneBotGroupApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const groupElement = grayTipElement?.groupElement;
|
const groupElement = grayTipElement?.groupElement;
|
||||||
if (!groupElement) return undefined;
|
if (!groupElement) return undefined;
|
||||||
const adminUin = (await NTQQGroupApi.getGroupMember(GroupCode, groupElement.adminUid))?.uin || (await NTQQUserApi.getUidByUinV2(groupElement.adminUid));
|
const adminUin = (await this.core.apis.GroupApi.getGroupMember(GroupCode, groupElement.adminUid))?.uin || (await this.core.apis.UserApi.getUidByUinV2(groupElement.adminUid));
|
||||||
if (adminUin) {
|
if (adminUin) {
|
||||||
return new OB11GroupDecreaseEvent(
|
return new OB11GroupDecreaseEvent(
|
||||||
this.core,
|
this.core,
|
||||||
|
@@ -212,7 +212,6 @@ export class OneBotMsgApi {
|
|||||||
},
|
},
|
||||||
|
|
||||||
replyElement: async (element, msg) => {
|
replyElement: async (element, msg) => {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const records = msg.records.find(msgRecord => msgRecord.msgId === element?.sourceMsgIdInRecords);
|
const records = msg.records.find(msgRecord => msgRecord.msgId === element?.sourceMsgIdInRecords);
|
||||||
const peer = {
|
const peer = {
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
@@ -237,17 +236,17 @@ export class OneBotMsgApi {
|
|||||||
|
|
||||||
let replyMsg: RawMessage | undefined;
|
let replyMsg: RawMessage | undefined;
|
||||||
// Attempt 1
|
// Attempt 1
|
||||||
replyMsg = (await NTQQMsgApi.getMsgsBySeqAndCount(peer,element.replayMsgSeq, 1, true, true))
|
replyMsg = (await this.core.apis.MsgApi.getMsgsBySeqAndCount(peer,element.replayMsgSeq, 1, true, true))
|
||||||
.msgList
|
.msgList
|
||||||
.find(msg => msg.msgRandom === records.msgRandom);
|
.find(msg => msg.msgRandom === records.msgRandom);
|
||||||
|
|
||||||
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
||||||
// Attempt 2
|
// Attempt 2
|
||||||
replyMsg = (await NTQQMsgApi.getSingleMsg(peer, element.replayMsgSeq)).msgList[0];
|
replyMsg = (await this.core.apis.MsgApi.getSingleMsg(peer, element.replayMsgSeq)).msgList[0];
|
||||||
|
|
||||||
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
||||||
// Attempt 3
|
// Attempt 3
|
||||||
const replyMsgList = (await NTQQMsgApi.getMsgExBySeq(peer, records.msgSeq)).msgList;
|
const replyMsgList = (await this.core.apis.MsgApi.getMsgExBySeq(peer, records.msgSeq)).msgList;
|
||||||
if (replyMsgList.length < 1) {
|
if (replyMsgList.length < 1) {
|
||||||
this.core.context.logger.logError('回复消息消息验证失败', element.replayMsgSeq);
|
this.core.context.logger.logError('回复消息消息验证失败', element.replayMsgSeq);
|
||||||
return null;
|
return null;
|
||||||
@@ -261,20 +260,19 @@ export class OneBotMsgApi {
|
|||||||
},
|
},
|
||||||
|
|
||||||
videoElement: async (element, msg, elementWrapper) => {
|
videoElement: async (element, msg, elementWrapper) => {
|
||||||
const NTQQFileApi = this.core.apis.FileApi;
|
|
||||||
const peer = {
|
const peer = {
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
guildId: '',
|
guildId: '',
|
||||||
};
|
};
|
||||||
//读取视频链接并兜底
|
//读取视频链接并兜底
|
||||||
let videoUrlWrappers: Awaited<ReturnType<typeof NTQQFileApi.getVideoUrl>> | undefined;
|
let videoUrlWrappers: Awaited<ReturnType<typeof this.core.apis.FileApi.getVideoUrl>> | undefined;
|
||||||
|
|
||||||
if (msg.peerUin === '284840486') {
|
if (msg.peerUin === '284840486') {
|
||||||
//TODO: 合并消息内部 应该进行特殊处理 可能需要重写peer 待测试与研究 Mlikiowa Tagged
|
//TODO: 合并消息内部 应该进行特殊处理 可能需要重写peer 待测试与研究 Mlikiowa Tagged
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
videoUrlWrappers = await NTQQFileApi.getVideoUrl({
|
videoUrlWrappers = await this.core.apis.FileApi.getVideoUrl({
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
guildId: '0',
|
guildId: '0',
|
||||||
@@ -300,7 +298,7 @@ export class OneBotMsgApi {
|
|||||||
videoDownUrl = element.filePath;
|
videoDownUrl = element.filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
await NTQQFileApi.addFileCache(
|
await this.core.apis.FileApi.addFileCache(
|
||||||
{
|
{
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
@@ -359,7 +357,6 @@ export class OneBotMsgApi {
|
|||||||
},
|
},
|
||||||
|
|
||||||
multiForwardMsgElement: async (_, msg) => {
|
multiForwardMsgElement: async (_, msg) => {
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const message_data: OB11MessageForward = {
|
const message_data: OB11MessageForward = {
|
||||||
data: {} as any,
|
data: {} as any,
|
||||||
type: OB11MessageDataType.forward,
|
type: OB11MessageDataType.forward,
|
||||||
@@ -376,7 +373,7 @@ export class OneBotMsgApi {
|
|||||||
msg.parentMsgIdList.push(msg.msgId);
|
msg.parentMsgIdList.push(msg.msgId);
|
||||||
//let parentMsgId = msg.parentMsgIdList[msg.parentMsgIdList.length - 2 < 0 ? 0 : msg.parentMsgIdList.length - 2];
|
//let parentMsgId = msg.parentMsgIdList[msg.parentMsgIdList.length - 2 < 0 ? 0 : msg.parentMsgIdList.length - 2];
|
||||||
//加入自身MsgId
|
//加入自身MsgId
|
||||||
const multiMsgs = (await NTQQMsgApi.getMultiMsg(parentMsgPeer, msg.parentMsgIdList[0], msg.msgId))?.msgList;
|
const multiMsgs = (await this.core.apis.MsgApi.getMultiMsg(parentMsgPeer, msg.parentMsgIdList[0], msg.msgId))?.msgList;
|
||||||
//拉取下级消息
|
//拉取下级消息
|
||||||
if (!multiMsgs) return null;
|
if (!multiMsgs) return null;
|
||||||
//拉取失败则跳过
|
//拉取失败则跳过
|
||||||
@@ -446,15 +443,13 @@ export class OneBotMsgApi {
|
|||||||
|
|
||||||
if (!context.peer || context.peer.chatType == ChatType.KCHATTYPEC2C) return undefined;
|
if (!context.peer || context.peer.chatType == ChatType.KCHATTYPEC2C) return undefined;
|
||||||
if (atQQ === 'all') return at(atQQ, atQQ, AtType.atAll, '全体成员');
|
if (atQQ === 'all') return at(atQQ, atQQ, AtType.atAll, '全体成员');
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const atMember = await this.core.apis.GroupApi.getGroupMember(context.peer.peerUid, atQQ);
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const atMember = await NTQQGroupApi.getGroupMember(context.peer.peerUid, atQQ);
|
|
||||||
if (atMember) {
|
if (atMember) {
|
||||||
return at(atQQ, atMember.uid, AtType.atUser, atMember.nick || atMember.cardName);
|
return at(atQQ, atMember.uid, AtType.atUser, atMember.nick || atMember.cardName);
|
||||||
}
|
}
|
||||||
const uid = await NTQQUserApi.getUidByUinV2(`${atQQ}`);
|
const uid = await this.core.apis.UserApi.getUidByUinV2(`${atQQ}`);
|
||||||
if (!uid) throw new Error('Get Uid Error');
|
if (!uid) throw new Error('Get Uid Error');
|
||||||
const info = await NTQQUserApi.getUserDetailInfo(uid);
|
const info = await this.core.apis.UserApi.getUserDetailInfo(uid);
|
||||||
return at(atQQ, uid, AtType.atUser, info.nick || '');
|
return at(atQQ, uid, AtType.atUser, info.nick || '');
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -464,8 +459,7 @@ export class OneBotMsgApi {
|
|||||||
this.core.context.logger.logWarn('回复消息不存在', id);
|
this.core.context.logger.logWarn('回复消息不存在', id);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
const replyMsg = (await this.core.apis.MsgApi.getMsgsByMsgId(
|
||||||
const replyMsg = (await NTQQMsgApi.getMsgsByMsgId(
|
|
||||||
replyMsgM.Peer, [replyMsgM.MsgId])).msgList[0];
|
replyMsgM.Peer, [replyMsgM.MsgId])).msgList[0];
|
||||||
return replyMsg ?
|
return replyMsg ?
|
||||||
{
|
{
|
||||||
@@ -710,9 +704,6 @@ export class OneBotMsgApi {
|
|||||||
if (msg.senderUin == '0' || msg.senderUin == '') return;
|
if (msg.senderUin == '0' || msg.senderUin == '') return;
|
||||||
if (msg.peerUin == '0' || msg.peerUin == '') return;
|
if (msg.peerUin == '0' || msg.peerUin == '') return;
|
||||||
//跳过空消息
|
//跳过空消息
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const resMsg: OB11Message = {
|
const resMsg: OB11Message = {
|
||||||
self_id: parseInt(this.core.selfInfo.uin),
|
self_id: parseInt(this.core.selfInfo.uin),
|
||||||
user_id: parseInt(msg.senderUin!),
|
user_id: parseInt(msg.senderUin!),
|
||||||
@@ -736,18 +727,18 @@ export class OneBotMsgApi {
|
|||||||
if (msg.chatType == ChatType.KCHATTYPEGROUP) {
|
if (msg.chatType == ChatType.KCHATTYPEGROUP) {
|
||||||
resMsg.sub_type = 'normal'; // 这里go-cqhttp是group,而onebot11标准是normal, 蛋疼
|
resMsg.sub_type = 'normal'; // 这里go-cqhttp是group,而onebot11标准是normal, 蛋疼
|
||||||
resMsg.group_id = parseInt(msg.peerUin);
|
resMsg.group_id = parseInt(msg.peerUin);
|
||||||
let member = await NTQQGroupApi.getGroupMember(msg.peerUin, msg.senderUin);
|
let member = await this.core.apis.GroupApi.getGroupMember(msg.peerUin, msg.senderUin);
|
||||||
if (!member) member = await NTQQGroupApi.getGroupMember(msg.peerUin, msg.senderUin);
|
if (!member) member = await this.core.apis.GroupApi.getGroupMember(msg.peerUin, msg.senderUin);
|
||||||
if (member) {
|
if (member) {
|
||||||
resMsg.sender.role = OB11Entities.groupMemberRole(member.role);
|
resMsg.sender.role = OB11Entities.groupMemberRole(member.role);
|
||||||
resMsg.sender.nickname = member.nick;
|
resMsg.sender.nickname = member.nick;
|
||||||
}
|
}
|
||||||
} else if (msg.chatType == ChatType.KCHATTYPEC2C) {
|
} else if (msg.chatType == ChatType.KCHATTYPEC2C) {
|
||||||
resMsg.sub_type = 'friend';
|
resMsg.sub_type = 'friend';
|
||||||
resMsg.sender.nickname = (await NTQQUserApi.getUserDetailInfo(msg.senderUid)).nick;
|
resMsg.sender.nickname = (await this.core.apis.UserApi.getUserDetailInfo(msg.senderUid)).nick;
|
||||||
} else if (msg.chatType == ChatType.KCHATTYPETEMPC2CFROMGROUP) {
|
} else if (msg.chatType == ChatType.KCHATTYPETEMPC2CFROMGROUP) {
|
||||||
resMsg.sub_type = 'group';
|
resMsg.sub_type = 'group';
|
||||||
const ret = await NTQQMsgApi.getTempChatInfo(ChatType.KCHATTYPETEMPC2CFROMGROUP, msg.senderUid);
|
const ret = await this.core.apis.MsgApi.getTempChatInfo(ChatType.KCHATTYPETEMPC2CFROMGROUP, msg.senderUid);
|
||||||
if (ret.result === 0) {
|
if (ret.result === 0) {
|
||||||
resMsg.group_id = parseInt(ret.tmpChatInfo!.groupCode);
|
resMsg.group_id = parseInt(ret.tmpChatInfo!.groupCode);
|
||||||
resMsg.sender.nickname = ret.tmpChatInfo!.fromNick;
|
resMsg.sender.nickname = ret.tmpChatInfo!.fromNick;
|
||||||
|
@@ -77,7 +77,6 @@ export class NapCatOneBot11Adapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async InitOneBot() {
|
async InitOneBot() {
|
||||||
const NTQQUserApi = this.core.apis.UserApi;
|
|
||||||
const selfInfo = this.core.selfInfo;
|
const selfInfo = this.core.selfInfo;
|
||||||
const ob11Config = this.configLoader.configData;
|
const ob11Config = this.configLoader.configData;
|
||||||
|
|
||||||
@@ -87,7 +86,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
WebSocket服务 ${ob11Config.ws.enable ? '已启动' : '未启动'}, ${ob11Config.ws.host}:${ob11Config.ws.port}
|
WebSocket服务 ${ob11Config.ws.enable ? '已启动' : '未启动'}, ${ob11Config.ws.host}:${ob11Config.ws.port}
|
||||||
WebSocket反向服务 ${ob11Config.reverseWs.enable ? '已启动' : '未启动'}, 反向地址: ${ob11Config.reverseWs.urls}`;
|
WebSocket反向服务 ${ob11Config.reverseWs.enable ? '已启动' : '未启动'}, 反向地址: ${ob11Config.reverseWs.urls}`;
|
||||||
|
|
||||||
NTQQUserApi.getUserDetailInfo(selfInfo.uid).then(user => {
|
this.core.apis.UserApi.getUserDetailInfo(selfInfo.uid).then(user => {
|
||||||
selfInfo.nick = user.nick;
|
selfInfo.nick = user.nick;
|
||||||
this.context.logger.setLogSelfInfo(selfInfo);
|
this.context.logger.setLogSelfInfo(selfInfo);
|
||||||
}).catch(this.context.logger.logError);
|
}).catch(this.context.logger.logError);
|
||||||
@@ -341,12 +340,6 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.core.apis.FriendApi.clearBuddyReqUnreadCnt();
|
this.core.apis.FriendApi.clearBuddyReqUnreadCnt();
|
||||||
for (let i = 0; i < reqs.unreadNums; i++) {
|
for (let i = 0; i < reqs.unreadNums; i++) {
|
||||||
const req = reqs.buddyReqs[i];
|
const req = reqs.buddyReqs[i];
|
||||||
//req.isBuddy === false是单向好友 null为常规情况
|
|
||||||
// if (req.isBuddy === false && ) {
|
|
||||||
// const NTQQFriendApi = this.core.apis.FriendApi;
|
|
||||||
// await NTQQFriendApi.handleFriendRequest(req.friendUid + '|' + req.reqTime, true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM)) {
|
if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user