mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-16 12:51:39 +00:00
feat(api): implement guild.approve
This commit is contained in:
parent
991f654b49
commit
b71a61a430
33
packages/engine-chronocat-api/src/api/guild/approve.ts
Normal file
33
packages/engine-chronocat-api/src/api/guild/approve.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import type { ApprovePayload, ChronocatContext } from '@chronocat/shell'
|
||||||
|
import { operateSysNotify } from '../../definitions/groupService'
|
||||||
|
|
||||||
|
export const buildGuildApprove =
|
||||||
|
(ctx: ChronocatContext) =>
|
||||||
|
async ({ message_id, approve, comment }: ApprovePayload) => {
|
||||||
|
if (comment)
|
||||||
|
ctx.chronocat.l.warn(
|
||||||
|
'不支持处理群申请时附加备注消息。备注消息将会被忽略。',
|
||||||
|
{
|
||||||
|
code: 2144,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!approve) {
|
||||||
|
ctx.chronocat.l.error('暂不支持拒绝群申请。', { code: 2145 })
|
||||||
|
throw new Error('暂不支持拒绝群申请。')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 这个是同意发过来的小卡片
|
||||||
|
await operateSysNotify({
|
||||||
|
doubt: false,
|
||||||
|
operateMsg: {
|
||||||
|
operateType: 1,
|
||||||
|
targetMsg: {
|
||||||
|
seq: '',
|
||||||
|
type: 1,
|
||||||
|
groupCode: message_id,
|
||||||
|
postscript: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@ -5,6 +5,7 @@ import { buildChannelGet } from './api/channel/get'
|
|||||||
import { buildChannelList } from './api/channel/list'
|
import { buildChannelList } from './api/channel/list'
|
||||||
import { buildChannelMemberMute } from './api/channel/member/mute'
|
import { buildChannelMemberMute } from './api/channel/member/mute'
|
||||||
import { buildChannelMute } from './api/channel/mute'
|
import { buildChannelMute } from './api/channel/mute'
|
||||||
|
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 { buildAssetsGet } from './api/internal/assets/get'
|
import { buildAssetsGet } from './api/internal/assets/get'
|
||||||
@ -34,6 +35,7 @@ export const apply = async (ctx: ChronocatContext) => {
|
|||||||
register('user.channel.create', buildUserChannelCreate(ctx))
|
register('user.channel.create', buildUserChannelCreate(ctx))
|
||||||
register('guild.get', buildGuildGet(ctx))
|
register('guild.get', buildGuildGet(ctx))
|
||||||
register('guild.list', buildGuildList(ctx))
|
register('guild.list', buildGuildList(ctx))
|
||||||
|
register('guild.approve', buildGuildApprove(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))
|
||||||
|
29
packages/shell/src/satori/routes/guild/approve.ts
Normal file
29
packages/shell/src/satori/routes/guild/approve.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import type { ApprovePayload } from '../../types'
|
||||||
|
import type { RouteContext } from '../types'
|
||||||
|
|
||||||
|
export const guildApprove = 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.approve'](payload)
|
||||||
|
}
|
@ -5,7 +5,7 @@ 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'
|
||||||
// import { friendRemove } from './friend/remove'
|
// 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 { guildMemberGet } from './guild/member/get'
|
// import { guildMemberGet } from './guild/member/get'
|
||||||
@ -33,7 +33,7 @@ const routesIntl = {
|
|||||||
'user.channel.create': userChannelCreate,
|
'user.channel.create': userChannelCreate,
|
||||||
'guild.get': guildGet,
|
'guild.get': guildGet,
|
||||||
'guild.list': guildList,
|
'guild.list': guildList,
|
||||||
// 'guild.approve': guildApprove,
|
'guild.approve': guildApprove,
|
||||||
// 'unsafe.guild.remove': guildRemove,
|
// 'unsafe.guild.remove': guildRemove,
|
||||||
// 'guild.member.get': guildMemberGet,
|
// 'guild.member.get': guildMemberGet,
|
||||||
// 'guild.member.list': guildMemberList,
|
// 'guild.member.list': guildMemberList,
|
||||||
|
@ -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 {
|
||||||
|
ApprovePayload,
|
||||||
Channel,
|
Channel,
|
||||||
ChannelGetPayload,
|
ChannelGetPayload,
|
||||||
ChannelListPayload,
|
ChannelListPayload,
|
||||||
@ -95,6 +96,7 @@ export interface Methods {
|
|||||||
|
|
||||||
'guild.get': [[GuildGetPayload], Guild]
|
'guild.get': [[GuildGetPayload], Guild]
|
||||||
'guild.list': [[], GuildListResponse]
|
'guild.list': [[], GuildListResponse]
|
||||||
|
'guild.approve': [[ApprovePayload], never]
|
||||||
|
|
||||||
'message.create': [
|
'message.create': [
|
||||||
[MessageCreatePayload, ChronocatSatoriServerConfig],
|
[MessageCreatePayload, ChronocatSatoriServerConfig],
|
||||||
|
Loading…
Reference in New Issue
Block a user