feat(api): implement guild.member.approve

This commit is contained in:
Il Harper 2024-09-22 21:50:49 +08:00
parent 36cc8f89ea
commit 18c5be2098
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
10 changed files with 101 additions and 10 deletions

View File

@ -12,9 +12,10 @@ export const buildGuildApprove =
}, },
) )
// TODO: 看下是否是真的不支持
if (!approve) { if (!approve) {
ctx.chronocat.l.error('暂不支持拒绝群请。', { code: 2145 }) ctx.chronocat.l.error('暂不支持拒绝群请。', { code: 2145 })
throw new Error('暂不支持拒绝群请。') throw new Error('暂不支持拒绝群请。')
} }
// 这个是同意发过来的小卡片 // 这个是同意发过来的小卡片

View File

@ -0,0 +1,35 @@
import type { ApprovePayload, ChronocatContext } from '@chronocat/shell'
import { operateSysNotify } from '../../../definitions/groupService'
export const buildGuildMemberApprove =
(ctx: ChronocatContext) =>
async ({ message_id, approve, comment }: ApprovePayload) => {
if (comment)
ctx.chronocat.l.warn(
'不支持处理群申请时附加备注消息。备注消息将会被忽略。',
{
code: 2144,
},
)
const [seq, groupCode, doubt] = message_id.split(':')
if (!seq || !groupCode || !doubt)
ctx.chronocat.l.warn('message_id 不合法。将仍然尝试处理加群请求。')
// 这个是同意发过来的小卡片
await operateSysNotify({
doubt: doubt! === '1',
operateMsg: {
operateType: approve ? 1 : 2,
targetMsg: {
seq: seq!,
type: 7,
groupCode: groupCode!,
postscript: '',
},
},
})
return {}
}

View File

@ -154,12 +154,12 @@ export const operateSysNotify = define<
unknown, unknown,
[ [
{ {
doubt: false doubt: boolean
operateMsg: { operateMsg: {
operateType: 1 operateType: 1 | 2
targetMsg: { targetMsg: {
seq: '' seq: string
type: 1 type: 1 | 7
groupCode: string groupCode: string
postscript: '' postscript: ''
} }

View File

@ -11,6 +11,7 @@ import { buildFriendRemove } from './api/friend/remove'
import { buildGuildApprove } from './api/guild/approve' 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 { buildGuildMemberApprove } from './api/guild/member/approve'
import { buildGuildMemberGet } from './api/guild/member/get' import { buildGuildMemberGet } from './api/guild/member/get'
import { buildGuildMemberKick } from './api/guild/member/kick' import { buildGuildMemberKick } from './api/guild/member/kick'
import { buildGuildMemberList } from './api/guild/member/list' import { buildGuildMemberList } from './api/guild/member/list'
@ -61,6 +62,7 @@ export const apply = async (ctx: ChronocatContext) => {
register('guild.member.list', buildGuildMemberList(ctx)) register('guild.member.list', buildGuildMemberList(ctx))
register('guild.member.kick', buildGuildMemberKick(ctx)) register('guild.member.kick', buildGuildMemberKick(ctx))
register('guild.member.mute', buildGuildMemberMute(ctx)) register('guild.member.mute', buildGuildMemberMute(ctx))
register('guild.member.approve', buildGuildMemberApprove(ctx))
register('chronocat.internal.message.create2.normal', buildMessageCreate(ctx)) register('chronocat.internal.message.create2.normal', buildMessageCreate(ctx))
register( register(
'chronocat.internal.message.create2.forward', 'chronocat.internal.message.create2.forward',

View File

@ -218,7 +218,7 @@ const dispatcher = async (
} }
case 'nodeIKernelGroupListener/onGroupSingleScreenNotifies': { case 'nodeIKernelGroupListener/onGroupSingleScreenNotifies': {
const { notifies } = payload as OnGroupSingleScreenNotifies const { doubt, notifies } = payload as OnGroupSingleScreenNotifies
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises
notifies.forEach(async (x) => { notifies.forEach(async (x) => {
@ -258,7 +258,9 @@ const dispatcher = async (
// x.actionUser 此时一定为空 // x.actionUser 此时一定为空
ctx.chronocat.emit(new GuildMemberRequestDispatchMessage(x, uin)) ctx.chronocat.emit(
new GuildMemberRequestDispatchMessage(x, uin, doubt),
)
return return
} }

View File

@ -97,6 +97,7 @@ export class GuildMemberRequestDispatchMessage
constructor( constructor(
private notify: GroupNotifyGuildMemberRequest, private notify: GroupNotifyGuildMemberRequest,
private uin: string, private uin: string,
private doubt: boolean,
) {} ) {}
type = 'satori' as const type = 'satori' as const
@ -131,7 +132,7 @@ export class GuildMemberRequestDispatchMessage
member: {}, member: {},
message: { message: {
id: '', id: `${this.notify.seq}:${this.notify.group.groupCode}:${this.doubt ? '1' : '2'}`,
content: this.notify.postscript, content: this.notify.postscript,
}, },
} }

View File

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

View File

@ -8,6 +8,7 @@ import { friendRemove } from './friend/remove'
import { guildApprove } from './guild/approve' 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 { guildMemberApprove } from './guild/member/approve'
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'
@ -41,7 +42,7 @@ const routesIntl = {
'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': guildMemberApprove,
'guild.member.mute': guildMemberMute, 'guild.member.mute': guildMemberMute,
'guild.member.role.set': notImplemented, 'guild.member.role.set': notImplemented,
'guild.member.role.unset': notImplemented, 'guild.member.role.unset': notImplemented,

View File

@ -129,6 +129,7 @@ export interface SatoriMethods {
'guild.member.list': [[GuildMemberListPayload], GuildMemberListResponse] 'guild.member.list': [[GuildMemberListPayload], GuildMemberListResponse]
'guild.member.kick': [[GuildMemberKickPayload], Record<string, never>] 'guild.member.kick': [[GuildMemberKickPayload], Record<string, never>]
'guild.member.mute': [[GuildMemberMutePayload], Record<string, never>] 'guild.member.mute': [[GuildMemberMutePayload], Record<string, never>]
'guild.member.approve': [[ApprovePayload], Record<string, never>]
'chronocat.guild.member.title.set': [ 'chronocat.guild.member.title.set': [
[GuildMemberTitleSetPayload], [GuildMemberTitleSetPayload],

View File

@ -287,6 +287,25 @@ paths:
'500': '500':
$ref: '#/components/responses/500' $ref: '#/components/responses/500'
/guild.member.approve:
post:
operationId: guildMemberApprove
tags:
- GuildMember
summary: 通过群组成员申请
description: 处理加群请求。
requestBody:
description: 处理加群请求
content:
application/json:
schema:
$ref: '#/components/schemas/ApprovePayload'
responses:
'200':
description: 成功处理加群请求
'500':
$ref: '#/components/responses/500'
/login.get: /login.get:
post: post:
operationId: loginGet operationId: loginGet