From 27ecf7837237130d7e429c4228ba4a86f5f54044 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Thu, 25 Apr 2024 15:12:53 +0800 Subject: [PATCH 1/5] refactor: mark msg as read --- src/onebot11/action/msg/MarkMsgAsRead.ts | 52 +++++++++++++++--------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/onebot11/action/msg/MarkMsgAsRead.ts b/src/onebot11/action/msg/MarkMsgAsRead.ts index 88de0b92..7eb82458 100644 --- a/src/onebot11/action/msg/MarkMsgAsRead.ts +++ b/src/onebot11/action/msg/MarkMsgAsRead.ts @@ -1,41 +1,55 @@ -import { ChatType, Peer, RawMessage, SendMessageElement } from '@/core/qqnt/entities'; +import { ChatType, Peer } from '@/core/qqnt/entities'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQMsgApi } from '@/core/qqnt/apis'; import { getFriend, getUidByUin } from '@/common/data'; interface Payload { - uin: string, + user_id: number; + group_id?: number; } class MarkMsgAsRead extends BaseAction { - ReqChatType = 0; - protected async _handle(payload: Payload): Promise { - let uid: string | undefined = payload.uin; - if (this.ReqChatType != ChatType.group) { - uid = getUidByUin(payload.uin.toString()); - if (!uid) { - throw `记录${payload.uin}不存在`; + + async getPeer(payload: Payload): Promise { + if (payload.user_id) { + const peerUid = getUidByUin(payload.user_id.toString()); + if (!peerUid) { + throw `私聊${payload.user_id}不存在`; } - const friend = await getFriend(uid); - this.ReqChatType = friend ? ChatType.friend : ChatType.temp;//重写 + const friend = await getFriend(peerUid); + return { chatType: friend ? ChatType.friend: ChatType.temp, peerUid }; } - // 获取UID 组装Peer - // GuildId: string 留空 - const ReqPeer: Peer = { chatType: this.ReqChatType, peerUid: uid, guildId: '' }; + if (!payload.group_id) { + throw '缺少参数 group_id 或 user_id'; + } + return { chatType: ChatType.group, peerUid: payload.group_id.toString() }; + } + protected async _handle(payload: Payload): Promise { // 调用API - const ret = await NTQQMsgApi.setMsgRead(ReqPeer); + const ret = await NTQQMsgApi.setMsgRead(await this.getPeer(payload)); if (ret.result != 0) { - throw ('设置已读失败'); + throw ('设置已读失败,' + ret.errMsg); } return null; } } export class MarkPrivateMsgAsRead extends MarkMsgAsRead { actionName = ActionName.MarkPrivateMsgAsRead; - ReqChatType = ChatType.friend; } export class MarkGroupMsgAsRead extends MarkMsgAsRead { actionName = ActionName.MarkGroupMsgAsRead; - ReqChatType = ChatType.group; -} \ No newline at end of file +} + + +interface Payload{ + message_id: number +} + +export class GoCQHTTPMarkMsgAsRead extends BaseAction{ + actionName = ActionName.GoCQHTTP_MarkMsgAsRead; + + protected async _handle(payload: Payload): Promise { + return null; + } +} From 759adc45e3cdd2d10a3d4b5601523b5c0c833ee1 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Thu, 25 Apr 2024 15:13:11 +0800 Subject: [PATCH 2/5] refactor: mark msg as read --- src/onebot11/action/index.ts | 7 ++++--- src/onebot11/action/types.ts | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 5166f92d..45a8016b 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -34,7 +34,7 @@ import SetGroupAdmin from './group/SetGroupAdmin'; import SetGroupCard from './group/SetGroupCard'; import GetImage from './file/GetImage'; import GetRecord from './file/GetRecord'; -import { MarkGroupMsgAsRead, MarkPrivateMsgAsRead } from './msg/MarkMsgAsRead'; +import { GoCQHTTPMarkMsgAsRead, MarkGroupMsgAsRead, MarkPrivateMsgAsRead } from './msg/MarkMsgAsRead'; import CleanCache from './system/CleanCache'; import GoCQHTTPUploadGroupFile from './go-cqhttp/UploadGroupFile'; import { GetConfigAction, SetConfigAction } from '@/onebot11/action/extends/Config'; @@ -52,6 +52,8 @@ export const actionHandlers = [ // new GetConfigAction(), // new SetConfigAction(), // new GetGroupAddRequest(), + new MarkGroupMsgAsRead(), + new MarkPrivateMsgAsRead(), new SetQQAvatar(), // onebot11 new SendLike(), @@ -86,8 +88,7 @@ export const actionHandlers = [ new GoCQHTTPGetStrangerInfo(), new GoCQHTTPDownloadFile(), new GetGuildList(), - new MarkGroupMsgAsRead(), - new MarkPrivateMsgAsRead(), + new GoCQHTTPMarkMsgAsRead(), new GoCQHTTPUploadGroupFile(), new GoCQHTTPGetGroupMsgHistory(), new GoCQHTTGetForwardMsgAction(), diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index fd59eacf..138a5468 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -55,6 +55,7 @@ export enum ActionName { GoCQHTTP_SendGroupForwardMsg = 'send_group_forward_msg', GoCQHTTP_SendPrivateForwardMsg = 'send_private_forward_msg', GoCQHTTP_GetStrangerInfo = 'get_stranger_info', + GoCQHTTP_MarkMsgAsRead = 'mark_msg_as_read', GetGuildList = 'get_guild_list', MarkPrivateMsgAsRead = 'mark_private_msg_as_read', MarkGroupMsgAsRead = 'mark_group_msg_as_read', @@ -63,4 +64,4 @@ export enum ActionName { GoCQHTTP_GetGroupMsgHistory = 'get_group_msg_history', GoCQHTTP_GetForwardMsg = 'get_forward_msg', GetFriendMsgHistory = 'get_friend_msg_history' -} \ No newline at end of file +} From f00933969dd980373d04328dc892394f6d4087c0 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Thu, 25 Apr 2024 15:13:26 +0800 Subject: [PATCH 3/5] refactor: get image rkey --- src/onebot11/index.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/onebot11/index.ts b/src/onebot11/index.ts index c7495bdd..c68651c8 100644 --- a/src/onebot11/index.ts +++ b/src/onebot11/index.ts @@ -1,4 +1,3 @@ -import { rkeyManager } from '@/core/qqnt/extends/rkey'; import { napCatCore } from '@/core'; import { MsgListener } from '@/core/qqnt/listeners'; import { NapCatOnebot11 } from '@/onebot11/main'; @@ -39,12 +38,6 @@ checkVersion().then((remoteVersion: string) => { new NapCatOnebot11(); napCatCore.addLoginSuccessCallback(() => { console.log('login success'); - try{ - - console.log(rkeyManager.HookRkey()); - }catch (e) { - console.error(); - } postLoginStatus(); const msgListener = new MsgListener(); msgListener.onRecvMsg = (msg) => { From a1bb6cc1b1bbb3d77f8fe6a03876553b87c07314 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Fri, 26 Apr 2024 00:16:36 +0800 Subject: [PATCH 4/5] refactor: mface url --- src/onebot11/constructor.ts | 3 ++- src/onebot11/index.ts | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/onebot11/constructor.ts b/src/onebot11/constructor.ts index 119dd7bf..b4119fb0 100644 --- a/src/onebot11/constructor.ts +++ b/src/onebot11/constructor.ts @@ -217,7 +217,8 @@ export class OB11Constructor { // 取md5的前两位 const dir = md5.substring(0, 2); // 获取组装url - const url = `https://p.qpic.cn/CDN_STATIC/0/data/imgcache/htdocs/club/item/parcel/item/${dir}/${md5}/300x300.png?max_age=31536000`; + // const url = `https://p.qpic.cn/CDN_STATIC/0/data/imgcache/htdocs/club/item/parcel/item/${dir}/${md5}/300x300.gif?max_age=31536000`; + const url = `https://gxh.vip.qq.com/club/item/parcel/item/${dir}/${md5}/raw300.gif`; message_data['data']['url'] = url; } else if (element.markdownElement) { message_data['type'] = OB11MessageDataType.markdown; diff --git a/src/onebot11/index.ts b/src/onebot11/index.ts index c68651c8..b04b9dd6 100644 --- a/src/onebot11/index.ts +++ b/src/onebot11/index.ts @@ -41,6 +41,9 @@ napCatCore.addLoginSuccessCallback(() => { postLoginStatus(); const msgListener = new MsgListener(); msgListener.onRecvMsg = (msg) => { + // console.log(JSON.stringify(Array.from(msg[0].msgAttrs.values()))); + // napCatCore.service.msg.kernelService?.getMsgsByMsgId(msg[0].msgId, 20).then(res=>console.log(res)); + // console.log("onRecvMsg", msg) }; // napCatCore.getGroupService().getGroupExtList(true).then((res) => { From 6594b33bccda7d8b9871f2a7268dea59cdd93777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 26 Apr 2024 08:09:15 +0800 Subject: [PATCH 5/5] docs: change --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 278c11e3..6891e30b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ 1. 修复图片URL,支持Win X64获取Rkey 2. 支持了设置已读群/私聊消息接口 3. 支持了好友添加上报事件 +4. 重构了商城表情URL拼接