mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-25 09:37:35 +00:00
feat(api): implement guild.member.approve
This commit is contained in:
parent
36cc8f89ea
commit
18c5be2098
@ -12,9 +12,10 @@ export const buildGuildApprove =
|
||||
},
|
||||
)
|
||||
|
||||
// TODO: 看下是否是真的不支持
|
||||
if (!approve) {
|
||||
ctx.chronocat.l.error('暂不支持拒绝群申请。', { code: 2145 })
|
||||
throw new Error('暂不支持拒绝群申请。')
|
||||
ctx.chronocat.l.error('暂不支持拒绝群邀请。', { code: 2145 })
|
||||
throw new Error('暂不支持拒绝群邀请。')
|
||||
}
|
||||
|
||||
// 这个是同意发过来的小卡片
|
||||
|
@ -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 {}
|
||||
}
|
@ -154,12 +154,12 @@ export const operateSysNotify = define<
|
||||
unknown,
|
||||
[
|
||||
{
|
||||
doubt: false
|
||||
doubt: boolean
|
||||
operateMsg: {
|
||||
operateType: 1
|
||||
operateType: 1 | 2
|
||||
targetMsg: {
|
||||
seq: ''
|
||||
type: 1
|
||||
seq: string
|
||||
type: 1 | 7
|
||||
groupCode: string
|
||||
postscript: ''
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import { buildFriendRemove } from './api/friend/remove'
|
||||
import { buildGuildApprove } from './api/guild/approve'
|
||||
import { buildGuildGet } from './api/guild/get'
|
||||
import { buildGuildList } from './api/guild/list'
|
||||
import { buildGuildMemberApprove } from './api/guild/member/approve'
|
||||
import { buildGuildMemberGet } from './api/guild/member/get'
|
||||
import { buildGuildMemberKick } from './api/guild/member/kick'
|
||||
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.kick', buildGuildMemberKick(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.forward',
|
||||
|
@ -218,7 +218,7 @@ const dispatcher = async (
|
||||
}
|
||||
|
||||
case 'nodeIKernelGroupListener/onGroupSingleScreenNotifies': {
|
||||
const { notifies } = payload as OnGroupSingleScreenNotifies
|
||||
const { doubt, notifies } = payload as OnGroupSingleScreenNotifies
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
notifies.forEach(async (x) => {
|
||||
@ -258,7 +258,9 @@ const dispatcher = async (
|
||||
|
||||
// x.actionUser 此时一定为空
|
||||
|
||||
ctx.chronocat.emit(new GuildMemberRequestDispatchMessage(x, uin))
|
||||
ctx.chronocat.emit(
|
||||
new GuildMemberRequestDispatchMessage(x, uin, doubt),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -97,6 +97,7 @@ export class GuildMemberRequestDispatchMessage
|
||||
constructor(
|
||||
private notify: GroupNotifyGuildMemberRequest,
|
||||
private uin: string,
|
||||
private doubt: boolean,
|
||||
) {}
|
||||
|
||||
type = 'satori' as const
|
||||
@ -131,7 +132,7 @@ export class GuildMemberRequestDispatchMessage
|
||||
member: {},
|
||||
|
||||
message: {
|
||||
id: '',
|
||||
id: `${this.notify.seq}:${this.notify.group.groupCode}:${this.doubt ? '1' : '2'}`,
|
||||
content: this.notify.postscript,
|
||||
},
|
||||
}
|
||||
|
29
packages/shell/src/satori/routes/guild/member/approve.ts
Normal file
29
packages/shell/src/satori/routes/guild/member/approve.ts
Normal 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)
|
||||
}
|
@ -8,6 +8,7 @@ import { friendRemove } from './friend/remove'
|
||||
import { guildApprove } from './guild/approve'
|
||||
import { guildGet } from './guild/get'
|
||||
import { guildList } from './guild/list'
|
||||
import { guildMemberApprove } from './guild/member/approve'
|
||||
import { guildMemberGet } from './guild/member/get'
|
||||
import { guildMemberKick } from './guild/member/kick'
|
||||
import { guildMemberList } from './guild/member/list'
|
||||
@ -41,7 +42,7 @@ const routesIntl = {
|
||||
'guild.member.get': guildMemberGet,
|
||||
'guild.member.list': guildMemberList,
|
||||
'guild.member.kick': guildMemberKick,
|
||||
'guild.member.approve': notImplemented,
|
||||
'guild.member.approve': guildMemberApprove,
|
||||
'guild.member.mute': guildMemberMute,
|
||||
'guild.member.role.set': notImplemented,
|
||||
'guild.member.role.unset': notImplemented,
|
||||
|
@ -129,6 +129,7 @@ export interface SatoriMethods {
|
||||
'guild.member.list': [[GuildMemberListPayload], GuildMemberListResponse]
|
||||
'guild.member.kick': [[GuildMemberKickPayload], Record<string, never>]
|
||||
'guild.member.mute': [[GuildMemberMutePayload], Record<string, never>]
|
||||
'guild.member.approve': [[ApprovePayload], Record<string, never>]
|
||||
|
||||
'chronocat.guild.member.title.set': [
|
||||
[GuildMemberTitleSetPayload],
|
||||
|
@ -287,6 +287,25 @@ paths:
|
||||
'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:
|
||||
post:
|
||||
operationId: loginGet
|
||||
|
Loading…
Reference in New Issue
Block a user