-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): implement
guild.member.approve
- Loading branch information
Showing
10 changed files
with
101 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/engine-chronocat-api/src/api/guild/member/approve.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters