feat: api /get_group_msg_history

This commit is contained in:
linyuchen 2024-03-19 12:33:08 +08:00
parent 9679f29f48
commit eccf588569
5 changed files with 49 additions and 1 deletions

View File

@ -23,6 +23,17 @@ export class NTQQMsgApi {
args: [{peer:{peerUid: groupCode, chatType: ChatType.group}, cnt: 20}, null]
})
}
static async getMsgHistory(peer: Peer, msgId: string, count: number) {
return await callNTQQApi<GeneralCallResult & {msgList: RawMessage[]}>({
methodName: NTQQApiMethod.HISTORY_MSG,
args: [{
peer,
msgId,
cnt: count,
queryOrder: true,
}, null]
})
}
static async fetchRecentContact(){
await callNTQQApi({
methodName: NTQQApiMethod.RECENT_CONTACT,

View File

@ -17,7 +17,7 @@ export enum NTQQApiClass {
export enum NTQQApiMethod {
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
ADD_ACTIVE_CHAT_2 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
SELF_INFO = "fetchAuthData",
FRIENDS = "nodeIKernelBuddyService/getBuddyList",

View File

@ -0,0 +1,34 @@
import BaseAction from "../BaseAction";
import {OB11Message, OB11User} from "../../types";
import {groups} from "../../../common/data";
import {ActionName} from "../types";
import {ChatType} from "../../../ntqqapi/types";
import {dbUtil} from "../../../common/db";
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
import {OB11Constructor} from "../../constructor";
import {log} from "../../../common/utils";
interface Payload {
group_id: number
message_seq: number
}
export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, OB11Message[]> {
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory
protected async _handle(payload: Payload): Promise<OB11Message[]> {
const group = groups.find(group => group.groupCode === payload.group_id.toString())
if (!group) {
throw `${payload.group_id}不存在`
}
const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || "0"
// log("startMsgId", startMsgId)
let msgList = (await NTQQMsgApi.getMsgHistory({chatType: ChatType.group, peerUid: group.groupCode}, startMsgId, 20)).msgList
await Promise.all(msgList.map(async msg => {
msg.msgShortId = await dbUtil.addMsg(msg)
}))
const ob11MsgList = await Promise.all(msgList.map(msg=>OB11Constructor.message(msg)))
return ob11MsgList
}
}

View File

@ -37,6 +37,7 @@ import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
import SetQQAvatar from './llonebot/SetQQAvatar'
import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
export const actionHandlers = [
new Debug(),
@ -77,6 +78,7 @@ export const actionHandlers = [
new GetGuildList(),
new GoCQHTTPMarkMsgAsRead(),
new GoCQHTTPUploadGroupFile(),
new GoCQHTTPGetGroupMsgHistory(),
]

View File

@ -55,4 +55,5 @@ export enum ActionName {
GoCQHTTP_MarkMsgAsRead = "mark_msg_as_read",
GoCQHTTP_UploadGroupFile = "upload_group_file",
GoCQHTTP_DownloadFile = "download_file",
GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history",
}