mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-16 12:51:39 +00:00
feat(api): implement guild.member.kick
This commit is contained in:
parent
d0df894c10
commit
cff63fd29f
15
packages/engine-chronocat-api/src/api/guild/member/kick.ts
Normal file
15
packages/engine-chronocat-api/src/api/guild/member/kick.ts
Normal 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 {}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import { buildGuildApprove } from './api/guild/approve'
|
|||||||
import { buildGuildGet } from './api/guild/get'
|
import { buildGuildGet } from './api/guild/get'
|
||||||
import { buildGuildList } from './api/guild/list'
|
import { buildGuildList } from './api/guild/list'
|
||||||
import { buildGuildMemberGet } from './api/guild/member/get'
|
import { buildGuildMemberGet } from './api/guild/member/get'
|
||||||
|
import { buildGuildMemberKick } from './api/guild/member/kick'
|
||||||
import { buildGuildMemberList } from './api/guild/member/list'
|
import { buildGuildMemberList } from './api/guild/member/list'
|
||||||
import { buildGuildRemove } from './api/guild/remove'
|
import { buildGuildRemove } from './api/guild/remove'
|
||||||
import { buildAssetsGet } from './api/internal/assets/get'
|
import { buildAssetsGet } from './api/internal/assets/get'
|
||||||
@ -42,6 +43,7 @@ export const apply = async (ctx: ChronocatContext) => {
|
|||||||
register('guild.remove', buildGuildRemove(ctx))
|
register('guild.remove', buildGuildRemove(ctx))
|
||||||
register('guild.member.get', buildGuildMemberGet(ctx))
|
register('guild.member.get', buildGuildMemberGet(ctx))
|
||||||
register('guild.member.list', buildGuildMemberList(ctx))
|
register('guild.member.list', buildGuildMemberList(ctx))
|
||||||
|
register('guild.member.kick', buildGuildMemberKick(ctx))
|
||||||
register('message.create', buildMessageCreate(ctx))
|
register('message.create', buildMessageCreate(ctx))
|
||||||
register('login.get', buildLoginGet(ctx))
|
register('login.get', buildLoginGet(ctx))
|
||||||
register('chronocat.internal.message.create.forward', buildMessageCreate(ctx))
|
register('chronocat.internal.message.create.forward', buildMessageCreate(ctx))
|
||||||
|
30
packages/shell/src/satori/routes/guild/member/kick.ts
Normal file
30
packages/shell/src/satori/routes/guild/member/kick.ts
Normal 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)
|
||||||
|
}
|
@ -9,7 +9,7 @@ import { guildApprove } from './guild/approve'
|
|||||||
import { guildGet } from './guild/get'
|
import { guildGet } from './guild/get'
|
||||||
import { guildList } from './guild/list'
|
import { guildList } from './guild/list'
|
||||||
import { guildMemberGet } from './guild/member/get'
|
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 { guildMemberList } from './guild/member/list'
|
||||||
import { guildRemove } from './guild/remove'
|
import { guildRemove } from './guild/remove'
|
||||||
// import { loginGet } from './login/get'
|
// import { loginGet } from './login/get'
|
||||||
@ -37,7 +37,7 @@ const routesIntl = {
|
|||||||
'unsafe.guild.remove': guildRemove,
|
'unsafe.guild.remove': guildRemove,
|
||||||
'guild.member.get': guildMemberGet,
|
'guild.member.get': guildMemberGet,
|
||||||
'guild.member.list': guildMemberList,
|
'guild.member.list': guildMemberList,
|
||||||
// 'guild.member.kick': guildMemberKick,
|
'guild.member.kick': guildMemberKick,
|
||||||
'guild.member.approve': notImplemented,
|
'guild.member.approve': notImplemented,
|
||||||
'guild.member.role.set': notImplemented,
|
'guild.member.role.set': notImplemented,
|
||||||
'guild.member.role.unset': notImplemented,
|
'guild.member.role.unset': notImplemented,
|
||||||
|
@ -18,6 +18,7 @@ import type {
|
|||||||
GuildListResponse,
|
GuildListResponse,
|
||||||
GuildMember,
|
GuildMember,
|
||||||
GuildMemberGetPayload,
|
GuildMemberGetPayload,
|
||||||
|
GuildMemberKickPayload,
|
||||||
GuildMemberListPayload,
|
GuildMemberListPayload,
|
||||||
GuildMemberListResponse,
|
GuildMemberListResponse,
|
||||||
GuildRemovePayload,
|
GuildRemovePayload,
|
||||||
@ -107,6 +108,7 @@ export interface Methods {
|
|||||||
'guild.remove': [[GuildRemovePayload], Record<string, never>]
|
'guild.remove': [[GuildRemovePayload], Record<string, never>]
|
||||||
'guild.member.get': [[GuildMemberGetPayload], GuildMember]
|
'guild.member.get': [[GuildMemberGetPayload], GuildMember]
|
||||||
'guild.member.list': [[GuildMemberListPayload], GuildMemberListResponse]
|
'guild.member.list': [[GuildMemberListPayload], GuildMemberListResponse]
|
||||||
|
'guild.member.kick': [[GuildMemberKickPayload], Record<string, never>]
|
||||||
|
|
||||||
'message.create': [
|
'message.create': [
|
||||||
[MessageCreatePayload, ChronocatSatoriServerConfig],
|
[MessageCreatePayload, ChronocatSatoriServerConfig],
|
||||||
|
Loading…
Reference in New Issue
Block a user