mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: get_friend_msg_history
API
This commit is contained in:
parent
f39a9aeafb
commit
6c485634e1
@ -31,7 +31,6 @@ const config: ElectronViteConfig = {
|
|||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, './src'),
|
'@': path.resolve(__dirname, './src'),
|
||||||
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
@ -65,6 +65,7 @@ import { SendGroupNotice } from './go-cqhttp/SendGroupNotice'
|
|||||||
import { GetProfileLike } from './llonebot/GetProfileLike'
|
import { GetProfileLike } from './llonebot/GetProfileLike'
|
||||||
import { FetchEmojiLike } from './llonebot/FetchEmojiLike'
|
import { FetchEmojiLike } from './llonebot/FetchEmojiLike'
|
||||||
import { FetchCustomFace } from './llonebot/FetchCustomFace'
|
import { FetchCustomFace } from './llonebot/FetchCustomFace'
|
||||||
|
import { GetFriendMsgHistory } from './llonebot/GetFriendMsgHistory'
|
||||||
|
|
||||||
export function initActionMap(adapter: Adapter) {
|
export function initActionMap(adapter: Adapter) {
|
||||||
const actionHandlers = [
|
const actionHandlers = [
|
||||||
@ -78,6 +79,7 @@ export function initActionMap(adapter: Adapter) {
|
|||||||
new GetEvent(adapter),
|
new GetEvent(adapter),
|
||||||
new SetOnlineStatus(adapter),
|
new SetOnlineStatus(adapter),
|
||||||
new GetProfileLike(adapter),
|
new GetProfileLike(adapter),
|
||||||
|
new GetFriendMsgHistory(adapter),
|
||||||
// onebot11
|
// onebot11
|
||||||
new SendLike(adapter),
|
new SendLike(adapter),
|
||||||
new GetMsg(adapter),
|
new GetMsg(adapter),
|
||||||
|
53
src/onebot11/action/llonebot/GetFriendMsgHistory.ts
Normal file
53
src/onebot11/action/llonebot/GetFriendMsgHistory.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { BaseAction, Schema } from '../BaseAction'
|
||||||
|
import { OB11Message } from '@/onebot11/types'
|
||||||
|
import { ActionName } from '../types'
|
||||||
|
import { ChatType, RawMessage } from '@/ntqqapi/types'
|
||||||
|
import { MessageUnique } from '@/common/utils/messageUnique'
|
||||||
|
import { OB11Entities } from '@/onebot11/entities'
|
||||||
|
import { filterNullable } from '@/common/utils/misc'
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
user_id: number | string
|
||||||
|
message_seq?: number | string
|
||||||
|
message_id?: number | string
|
||||||
|
count: number | string
|
||||||
|
reverseOrder: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Response {
|
||||||
|
messages: OB11Message[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
||||||
|
actionName = ActionName.GetFriendMsgHistory
|
||||||
|
payloadSchema = Schema.object({
|
||||||
|
user_id: Schema.union([Number, String]).required(),
|
||||||
|
message_seq: Schema.union([Number, String]),
|
||||||
|
message_id: Schema.union([Number, String]),
|
||||||
|
count: Schema.union([Number, String]).default(20),
|
||||||
|
reverseOrder: Schema.boolean().default(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
async _handle(payload: Payload): Promise<Response> {
|
||||||
|
const startMsgId = payload.message_seq ?? payload.message_id
|
||||||
|
let msgList: RawMessage[]
|
||||||
|
if (startMsgId) {
|
||||||
|
const msgInfo = await MessageUnique.getMsgIdAndPeerByShortId(+startMsgId)
|
||||||
|
if (!msgInfo) throw new Error(`消息${startMsgId}不存在`)
|
||||||
|
msgList = (await this.ctx.ntMsgApi.getMsgHistory(msgInfo.Peer, msgInfo.MsgId, +payload.count)).msgList
|
||||||
|
} else {
|
||||||
|
const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString())
|
||||||
|
if (!uid) throw new Error(`记录${payload.user_id}不存在`)
|
||||||
|
const isBuddy = await this.ctx.ntFriendApi.isBuddy(uid)
|
||||||
|
const peer = { chatType: isBuddy ? ChatType.friend : ChatType.temp, peerUid: uid }
|
||||||
|
msgList = (await this.ctx.ntMsgApi.getAioFirstViewLatestMsgs(peer, +payload.count)).msgList
|
||||||
|
}
|
||||||
|
if (msgList.length === 0) throw new Error('未找到消息')
|
||||||
|
if (payload.reverseOrder) msgList.reverse()
|
||||||
|
msgList.map(msg => {
|
||||||
|
msg.msgShortId = MessageUnique.createMsg({ chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)
|
||||||
|
})
|
||||||
|
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Entities.message(this.ctx, msg)))
|
||||||
|
return { messages: filterNullable(ob11MsgList) }
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@ export enum ActionName {
|
|||||||
GetProfileLike = 'get_profile_like',
|
GetProfileLike = 'get_profile_like',
|
||||||
FetchEmojiLike = 'fetch_emoji_like',
|
FetchEmojiLike = 'fetch_emoji_like',
|
||||||
FetchCustomFace = 'fetch_custom_face',
|
FetchCustomFace = 'fetch_custom_face',
|
||||||
|
GetFriendMsgHistory = 'get_friend_msg_history',
|
||||||
// onebot 11
|
// onebot 11
|
||||||
SendLike = 'send_like',
|
SendLike = 'send_like',
|
||||||
GetLoginInfo = 'get_login_info',
|
GetLoginInfo = 'get_login_info',
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"./src/common/*"
|
"./src/common/*"
|
||||||
],
|
],
|
||||||
"@/onebot11/*": [
|
"@/onebot11/*": [
|
||||||
"./src/onebot11"
|
"./src/onebot11/*"
|
||||||
],
|
],
|
||||||
"@/ntqqapi/*": [
|
"@/ntqqapi/*": [
|
||||||
"./src/ntqqapi/*"
|
"./src/ntqqapi/*"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user