feat(api): implement unsafe.channel.member.mute

This commit is contained in:
Il Harper 2024-03-08 12:32:35 +08:00
parent ae9b642ed5
commit 10b7362656
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
6 changed files with 64 additions and 2 deletions

View File

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

View File

@ -1,6 +1,7 @@
import type { RedIpcArgs } from '@chronocat/red' import type { RedIpcArgs } from '@chronocat/red'
import type { ChronocatContext } from '@chronocat/shell' import type { ChronocatContext } from '@chronocat/shell'
import { ipcMan } from 'ipcman' import { ipcMan } from 'ipcman'
import { buildChannelMemberMute } from './api/channel/member/mute'
import { buildAssetsGet } from './api/internal/assets/get' import { buildAssetsGet } from './api/internal/assets/get'
import { qfaceGet, qfaceList } from './api/internal/qface' import { qfaceGet, qfaceList } from './api/internal/qface'
import { buildLoginGet } from './api/login/get' import { buildLoginGet } from './api/login/get'
@ -20,6 +21,7 @@ export const apply = async (ctx: ChronocatContext) => {
const register = ctx.chronocat.api.register(name) const register = ctx.chronocat.api.register(name)
register('chronocat.internal.assets.get', buildAssetsGet(ctx)) register('chronocat.internal.assets.get', buildAssetsGet(ctx))
register('unsafe.channel.member.mute', buildChannelMemberMute(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))

View File

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

View File

@ -1,6 +1,6 @@
// import { channelGet } from './channel/get' // import { channelGet } from './channel/get'
// import { channelList } from './channel/list' // import { channelList } from './channel/list'
// import { channelMemberMute } from './channel/member/mute' import { channelMemberMute } from './channel/member/mute'
// import { channelMute } from './channel/mute' // import { channelMute } from './channel/mute'
// import { friendApprove } from './friend/approve' // import { friendApprove } from './friend/approve'
// import { friendList } from './friend/list' // import { friendList } from './friend/list'
@ -29,7 +29,7 @@ const routesIntl = {
'channel.update': notImplemented, 'channel.update': notImplemented,
'channel.delete': notImplemented, 'channel.delete': notImplemented,
// 'unsafe.channel.mute': channelMute, // 'unsafe.channel.mute': channelMute,
// 'unsafe.channel.member.mute': channelMemberMute, 'unsafe.channel.member.mute': channelMemberMute,
// 'user.channel.create': userChannelCreate, // 'user.channel.create': userChannelCreate,
// 'guild.get': guildGet, // 'guild.get': guildGet,
// 'guild.list': guildList, // 'guild.list': guildList,

View File

@ -3,6 +3,8 @@ import type { Op } from './satoriEntity'
export type { export type {
ApprovePayload, ApprovePayload,
ChannelMemberMutePayload,
ChannelMutePayload,
FriendListResponse, FriendListResponse,
GuildListResponse, GuildListResponse,
GuildMemberListPayload, GuildMemberListPayload,

View File

@ -3,6 +3,7 @@ import type h from '@satorijs/element'
import type styles from 'ansi-styles' import type styles from 'ansi-styles'
import type { O } from 'ts-toolbelt' import type { O } from 'ts-toolbelt'
import type { import type {
ChannelMemberMutePayload,
Event, Event,
Login, Login,
Message, Message,
@ -74,6 +75,11 @@ export interface SelfProfileDispatchMessage {
export interface Methods { export interface Methods {
// Satori // Satori
'unsafe.channel.member.mute': [
[ChannelMemberMutePayload],
Record<string, never>,
]
'message.create': [ 'message.create': [
[MessageCreatePayload, ChronocatSatoriServerConfig], [MessageCreatePayload, ChronocatSatoriServerConfig],
Message[], Message[],