mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-16 12:51:39 +00:00
feat(api): implement message.list
This commit is contained in:
parent
bf14ad477f
commit
df371ce674
13
packages/engine-chronocat-api/src/api/message/list.ts
Normal file
13
packages/engine-chronocat-api/src/api/message/list.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import type {
|
||||
ChronocatContext,
|
||||
MessageListPayload,
|
||||
MessageListResponse,
|
||||
} from '@chronocat/shell'
|
||||
|
||||
export const buildMessageList =
|
||||
(_ctx: ChronocatContext) =>
|
||||
async (_: MessageListPayload): Promise<MessageListResponse> => {
|
||||
return {
|
||||
data: [],
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import { buildLoginGet } from './api/login/get'
|
||||
import { buildMessageCreate } from './api/message/create'
|
||||
import { buildMessageDelete } from './api/message/delete'
|
||||
import { buildMessageGet } from './api/message/get'
|
||||
import { buildMessageList } from './api/message/list'
|
||||
import { buildUserChannelCreate } from './api/user/channel/create'
|
||||
import { buildHandler } from './handler'
|
||||
|
||||
@ -49,6 +50,7 @@ export const apply = async (ctx: ChronocatContext) => {
|
||||
register('message.create', buildMessageCreate(ctx))
|
||||
register('message.get', buildMessageGet(ctx))
|
||||
register('message.delete', buildMessageDelete(ctx))
|
||||
register('message.list', buildMessageList(ctx))
|
||||
register('login.get', buildLoginGet(ctx))
|
||||
register('chronocat.internal.message.create.forward', buildMessageCreate(ctx))
|
||||
|
||||
|
@ -16,7 +16,7 @@ import { guildRemove } from './guild/remove'
|
||||
import { messageCreate } from './message/create'
|
||||
import { messageDelete } from './message/delete'
|
||||
import { messageGet } from './message/get'
|
||||
// import { messageList } from './message/list'
|
||||
import { messageList } from './message/list'
|
||||
import { notImplemented } from './notimpl'
|
||||
import type { Route } from './types'
|
||||
import { userChannelCreate } from './user/channel/create'
|
||||
@ -50,7 +50,7 @@ const routesIntl = {
|
||||
'message.get': messageGet,
|
||||
'message.delete': messageDelete,
|
||||
'message.update': notImplemented,
|
||||
// 'message.list': messageList,
|
||||
'message.list': messageList,
|
||||
'reaction.create': notImplemented,
|
||||
'reaction.delete': notImplemented,
|
||||
'reaction.clear': notImplemented,
|
||||
|
29
packages/shell/src/satori/routes/message/list.ts
Normal file
29
packages/shell/src/satori/routes/message/list.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import type { MessageListPayload } from '../../types'
|
||||
import type { RouteContext } from '../types'
|
||||
|
||||
export const messageList = async ({
|
||||
cctx,
|
||||
path,
|
||||
req,
|
||||
res,
|
||||
json,
|
||||
}: RouteContext) => {
|
||||
const payload = (await json()) as MessageListPayload
|
||||
|
||||
const validateResult =
|
||||
await cctx.chronocat.validate('MessageListPayload')(payload)
|
||||
|
||||
if (validateResult) {
|
||||
const err = `解析 ${path} 请求时出现问题,来自 ${req.socket.remoteAddress}。${validateResult}`
|
||||
|
||||
cctx.chronocat.l.error(err, {
|
||||
code: 400,
|
||||
})
|
||||
|
||||
res.writeHead(400)
|
||||
res.end(`400 bad request\n${err}`)
|
||||
return
|
||||
}
|
||||
|
||||
return await cctx.chronocat.api['message.list'](payload)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import type { Channel, Guild, GuildMember, User } from './satoriEntity'
|
||||
import type { Channel, Guild, GuildMember, Message, User } from './satoriEntity'
|
||||
|
||||
export interface Next {
|
||||
/**
|
||||
@ -83,6 +83,14 @@ export interface MessageGetPayload {
|
||||
message_id: string
|
||||
}
|
||||
|
||||
export interface MessageListPayload extends Next {
|
||||
channel_id: string
|
||||
}
|
||||
|
||||
export interface MessageListResponse extends Next {
|
||||
data: Message[]
|
||||
}
|
||||
|
||||
export interface ChannelMutePayload {
|
||||
channel_id: string
|
||||
enable: boolean
|
||||
|
@ -18,6 +18,8 @@ export type {
|
||||
GuildRemovePayload,
|
||||
MessageDeletePayload,
|
||||
MessageGetPayload,
|
||||
MessageListPayload,
|
||||
MessageListResponse,
|
||||
Next,
|
||||
UserGetPayload,
|
||||
UserPayload,
|
||||
|
@ -27,6 +27,8 @@ import type {
|
||||
MessageCreatePayload,
|
||||
MessageDeletePayload,
|
||||
MessageGetPayload,
|
||||
MessageListPayload,
|
||||
MessageListResponse,
|
||||
UserPayload,
|
||||
} from './satori/types'
|
||||
import type { api } from './services/api'
|
||||
@ -118,6 +120,7 @@ export interface Methods {
|
||||
]
|
||||
'message.get': [[MessageGetPayload], Message]
|
||||
'message.delete': [[MessageDeletePayload], Record<string, never>]
|
||||
'message.list': [[MessageListPayload], MessageListResponse]
|
||||
|
||||
'login.get': [[], Login]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user