feat(api): implement guild.member.mute

This commit is contained in:
Il Harper 2024-03-19 23:44:00 +08:00
parent 306552a0d8
commit 94cbc0dfac
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
7 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import type { ChronocatContext, GuildMemberMutePayload } from '@chronocat/shell'
import { setMemberShutUp } from '../../../definitions/groupService'
export const buildGuildMemberMute =
(ctx: ChronocatContext) =>
async ({ channel_id, user_id, duration }: GuildMemberMutePayload) => {
await setMemberShutUp({
groupCode: channel_id,
memList: [
{
uid: ctx.chronocat.uix.getUid(user_id),
timeStamp: Math.floor(duration / 1000),
},
],
})
return {}
}

View File

@ -14,6 +14,7 @@ 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 { buildGuildMemberMute } from './api/guild/member/mute'
import { buildGuildRemove } from './api/guild/remove'
import { buildAssetsGet } from './api/internal/assets/get'
import { qfaceGet, qfaceList } from './api/internal/qface'
@ -56,6 +57,7 @@ export const apply = async (ctx: ChronocatContext) => {
register('guild.member.get', buildGuildMemberGet(ctx))
register('guild.member.list', buildGuildMemberList(ctx))
register('guild.member.kick', buildGuildMemberKick(ctx))
register('guild.member.mute', buildGuildMemberMute(ctx))
register('message.create', buildMessageCreate(ctx))
register('chronocat.internal.message.create.forward', buildMessageCreate(ctx))
register('message.get', buildMessageGet(ctx))

View File

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

View File

@ -11,6 +11,7 @@ import { guildList } from './guild/list'
import { guildMemberGet } from './guild/member/get'
import { guildMemberKick } from './guild/member/kick'
import { guildMemberList } from './guild/member/list'
import { guildMemberMute } from './guild/member/mute'
import { guildRemove } from './guild/remove'
import { loginGet } from './login/get'
import { messageCreate } from './message/create'
@ -39,6 +40,7 @@ const routesIntl = {
'guild.member.list': guildMemberList,
'guild.member.kick': guildMemberKick,
'guild.member.approve': notImplemented,
'guild.member.mute': guildMemberMute,
'guild.member.role.set': notImplemented,
'guild.member.role.unset': notImplemented,
'guild.role.list': notImplemented,

View File

@ -102,6 +102,27 @@ export interface ChannelMemberMutePayload {
duration: number
}
export interface GuildMemberMutePayload {
channel_id: string
user_id: string
/**
* @title
*
* @description 0
* 30 259,200,000
*
*/
duration: number
/**
* @title
*
* @description
*/
comment?: string
}
export interface ChannelListPayload extends Next {
guild_id: string
}

View File

@ -15,6 +15,7 @@ export type {
GuildMemberKickPayload,
GuildMemberListPayload,
GuildMemberListResponse,
GuildMemberMutePayload,
GuildRemovePayload,
MessageDeletePayload,
MessageGetPayload,

View File

@ -21,6 +21,7 @@ import type {
GuildMemberKickPayload,
GuildMemberListPayload,
GuildMemberListResponse,
GuildMemberMutePayload,
GuildRemovePayload,
Login,
Message,
@ -113,6 +114,7 @@ export interface SatoriMethods {
'guild.member.get': [[GuildMemberGetPayload], GuildMember]
'guild.member.list': [[GuildMemberListPayload], GuildMemberListResponse]
'guild.member.kick': [[GuildMemberKickPayload], Record<string, never>]
'guild.member.mute': [[GuildMemberMutePayload], Record<string, never>]
'message.create': [
[MessageCreatePayload, ChronocatSatoriServerConfig],