feat(api): implement guild.member.kick

This commit is contained in:
Il Harper 2024-03-08 16:19:53 +08:00
parent d0df894c10
commit cff63fd29f
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
5 changed files with 51 additions and 2 deletions

View File

@ -0,0 +1,15 @@
import type { ChronocatContext, GuildMemberKickPayload } from '@chronocat/shell'
import { kickMember } from '../../../definitions/groupService'
export const buildGuildMemberKick =
(ctx: ChronocatContext) =>
async ({ guild_id, user_id, permanent }: GuildMemberKickPayload) => {
await kickMember({
groupCode: guild_id,
kickUids: [ctx.chronocat.uix.getUid(user_id)!],
refuseForever: permanent as boolean,
kickReason: '',
})
return {}
}

View File

@ -9,6 +9,7 @@ import { buildGuildApprove } from './api/guild/approve'
import { buildGuildGet } from './api/guild/get'
import { buildGuildList } from './api/guild/list'
import { buildGuildMemberGet } from './api/guild/member/get'
import { buildGuildMemberKick } from './api/guild/member/kick'
import { buildGuildMemberList } from './api/guild/member/list'
import { buildGuildRemove } from './api/guild/remove'
import { buildAssetsGet } from './api/internal/assets/get'
@ -42,6 +43,7 @@ export const apply = async (ctx: ChronocatContext) => {
register('guild.remove', buildGuildRemove(ctx))
register('guild.member.get', buildGuildMemberGet(ctx))
register('guild.member.list', buildGuildMemberList(ctx))
register('guild.member.kick', buildGuildMemberKick(ctx))
register('message.create', buildMessageCreate(ctx))
register('login.get', buildLoginGet(ctx))
register('chronocat.internal.message.create.forward', buildMessageCreate(ctx))

View File

@ -0,0 +1,30 @@
import type { GuildMemberKickPayload } from '../../../types'
import type { RouteContext } from '../../types'
export const guildMemberKick = async ({
cctx,
path,
req,
res,
json,
}: RouteContext) => {
const payload = (await json()) as GuildMemberKickPayload
const validateResult = await cctx.chronocat.validate(
'GuildMemberKickPayload',
)(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.member.kick'](payload)
}

View File

@ -9,7 +9,7 @@ import { guildApprove } from './guild/approve'
import { guildGet } from './guild/get'
import { guildList } from './guild/list'
import { guildMemberGet } from './guild/member/get'
// import { guildMemberKick } from './guild/member/kick'
import { guildMemberKick } from './guild/member/kick'
import { guildMemberList } from './guild/member/list'
import { guildRemove } from './guild/remove'
// import { loginGet } from './login/get'
@ -37,7 +37,7 @@ const routesIntl = {
'unsafe.guild.remove': guildRemove,
'guild.member.get': guildMemberGet,
'guild.member.list': guildMemberList,
// 'guild.member.kick': guildMemberKick,
'guild.member.kick': guildMemberKick,
'guild.member.approve': notImplemented,
'guild.member.role.set': notImplemented,
'guild.member.role.unset': notImplemented,

View File

@ -18,6 +18,7 @@ import type {
GuildListResponse,
GuildMember,
GuildMemberGetPayload,
GuildMemberKickPayload,
GuildMemberListPayload,
GuildMemberListResponse,
GuildRemovePayload,
@ -107,6 +108,7 @@ export interface Methods {
'guild.remove': [[GuildRemovePayload], Record<string, never>]
'guild.member.get': [[GuildMemberGetPayload], GuildMember]
'guild.member.list': [[GuildMemberListPayload], GuildMemberListResponse]
'guild.member.kick': [[GuildMemberKickPayload], Record<string, never>]
'message.create': [
[MessageCreatePayload, ChronocatSatoriServerConfig],