mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: api /get_group_msg_history
This commit is contained in:
parent
9679f29f48
commit
eccf588569
@ -23,6 +23,17 @@ export class NTQQMsgApi {
|
|||||||
args: [{peer:{peerUid: groupCode, chatType: ChatType.group}, cnt: 20}, null]
|
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(){
|
static async fetchRecentContact(){
|
||||||
await callNTQQApi({
|
await callNTQQApi({
|
||||||
methodName: NTQQApiMethod.RECENT_CONTACT,
|
methodName: NTQQApiMethod.RECENT_CONTACT,
|
||||||
|
@ -17,7 +17,7 @@ export enum NTQQApiClass {
|
|||||||
export enum NTQQApiMethod {
|
export enum NTQQApiMethod {
|
||||||
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
|
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
|
||||||
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
||||||
ADD_ACTIVE_CHAT_2 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
||||||
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
||||||
SELF_INFO = "fetchAuthData",
|
SELF_INFO = "fetchAuthData",
|
||||||
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
||||||
|
34
src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts
Normal file
34
src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -37,6 +37,7 @@ import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
|||||||
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
||||||
import SetQQAvatar from './llonebot/SetQQAvatar'
|
import SetQQAvatar from './llonebot/SetQQAvatar'
|
||||||
import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
||||||
|
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new Debug(),
|
new Debug(),
|
||||||
@ -77,6 +78,7 @@ export const actionHandlers = [
|
|||||||
new GetGuildList(),
|
new GetGuildList(),
|
||||||
new GoCQHTTPMarkMsgAsRead(),
|
new GoCQHTTPMarkMsgAsRead(),
|
||||||
new GoCQHTTPUploadGroupFile(),
|
new GoCQHTTPUploadGroupFile(),
|
||||||
|
new GoCQHTTPGetGroupMsgHistory(),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -55,4 +55,5 @@ export enum ActionName {
|
|||||||
GoCQHTTP_MarkMsgAsRead = "mark_msg_as_read",
|
GoCQHTTP_MarkMsgAsRead = "mark_msg_as_read",
|
||||||
GoCQHTTP_UploadGroupFile = "upload_group_file",
|
GoCQHTTP_UploadGroupFile = "upload_group_file",
|
||||||
GoCQHTTP_DownloadFile = "download_file",
|
GoCQHTTP_DownloadFile = "download_file",
|
||||||
|
GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history",
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user