feat(api): implement guild.get

This commit is contained in:
Il Harper 2024-03-08 15:36:37 +08:00
parent 8e38e33069
commit 6e499f499f
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
6 changed files with 52 additions and 2 deletions

View File

@ -0,0 +1,11 @@
import type { ChronocatContext, Guild, GuildGetPayload } from '@chronocat/shell'
export const buildGuildGet =
(_ctx: ChronocatContext) =>
async ({ guild_id }: GuildGetPayload): Promise<Guild> => {
return {
id: guild_id,
name: undefined as unknown as string,
avatar: `https://p.qlogo.cn/gh/${guild_id}/${guild_id}/640`,
}
}

View File

@ -5,6 +5,7 @@ import { buildChannelGet } from './api/channel/get'
import { buildChannelList } from './api/channel/list'
import { buildChannelMemberMute } from './api/channel/member/mute'
import { buildChannelMute } from './api/channel/mute'
import { buildGuildGet } from './api/guild/get'
import { buildAssetsGet } from './api/internal/assets/get'
import { qfaceGet, qfaceList } from './api/internal/qface'
import { buildLoginGet } from './api/login/get'
@ -30,6 +31,7 @@ export const apply = async (ctx: ChronocatContext) => {
register('unsafe.channel.mute', buildChannelMute(ctx))
register('unsafe.channel.member.mute', buildChannelMemberMute(ctx))
register('user.channel.create', buildUserChannelCreate(ctx))
register('guild.get', buildGuildGet(ctx))
register('message.create', buildMessageCreate(ctx))
register('login.get', buildLoginGet(ctx))
register('chronocat.internal.message.create.forward', buildMessageCreate(ctx))

View File

@ -0,0 +1,29 @@
import type { GuildGetPayload } from '../../types'
import type { RouteContext } from '../types'
export const guildGet = async ({
cctx,
path,
req,
res,
json,
}: RouteContext) => {
const payload = (await json()) as GuildGetPayload
const validateResult =
await cctx.chronocat.validate('GuildGetPayload')(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['guild.get'](payload)
}

View File

@ -6,7 +6,7 @@ import { channelMute } from './channel/mute'
// import { friendList } from './friend/list'
// import { friendRemove } from './friend/remove'
// import { guildApprove } from './guild/approve'
// import { guildGet } from './guild/get'
import { guildGet } from './guild/get'
// import { guildList } from './guild/list'
// import { guildMemberGet } from './guild/member/get'
// import { guildMemberKick } from './guild/member/kick'
@ -31,7 +31,7 @@ const routesIntl = {
'unsafe.channel.mute': channelMute,
'unsafe.channel.member.mute': channelMemberMute,
'user.channel.create': userChannelCreate,
// 'guild.get': guildGet,
'guild.get': guildGet,
// 'guild.list': guildList,
// 'guild.approve': guildApprove,
// 'unsafe.guild.remove': guildRemove,

View File

@ -9,13 +9,17 @@ export type {
ChannelMemberMutePayload,
ChannelMutePayload,
FriendListResponse,
GuildGetPayload,
GuildListResponse,
GuildMemberGetPayload,
GuildMemberKickPayload,
GuildMemberListPayload,
GuildMemberListResponse,
GuildRemovePayload,
MessageDeletePayload,
MessageGetPayload,
Next,
UserGetPayload,
UserPayload,
} from './satoriPayloadEntity'

View File

@ -10,6 +10,8 @@ import type {
ChannelMemberMutePayload,
ChannelMutePayload,
Event,
Guild,
GuildGetPayload,
Login,
Message,
MessageCreatePayload,
@ -90,6 +92,8 @@ export interface Methods {
]
'user.channel.create': [[UserPayload], Channel]
'guild.get': [[GuildGetPayload], Guild]
'message.create': [
[MessageCreatePayload, ChronocatSatoriServerConfig],
Message[],