refactor: flag handle&onebot标准化

This commit is contained in:
手瓜一十雪
2024-12-05 14:17:09 +08:00
parent f492139d9e
commit 5dc0e0693a
9 changed files with 81 additions and 105 deletions

View File

@@ -4,9 +4,9 @@ import { ActionName } from '@/onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
flag: Type.String(),
flag: Type.Union([Type.String(), Type.Number()]),
approve: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
reason: Type.Union([Type.String({ default: ' ' }), Type.Null()]),
reason: Type.Optional(Type.Union([Type.String({ default: ' ' }), Type.Null()])),
});
type Payload = Static<typeof SchemaData>;
@@ -18,10 +18,26 @@ export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
async _handle(payload: Payload): Promise<null> {
const flag = payload.flag.toString();
const approve = payload.approve?.toString() !== 'false';
await this.core.apis.GroupApi.handleGroupRequest(flag,
const reason = payload.reason ?? ' ';
let notify = await this.findNotify(flag);
if (!notify) {
throw new Error('No such request');
}
await this.core.apis.GroupApi.handleGroupRequest(
notify,
approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
payload.reason ?? ' ',
reason,
);
return null;
}
}
private async findNotify(flag: string) {
let notify = (await this.core.apis.GroupApi.getSingleScreenNotifies(false, 100)).find(e => e.seq == flag);
if (!notify) {
notify = (await this.core.apis.GroupApi.getSingleScreenNotifies(true, 100)).find(e => e.seq == flag);
}
return notify;
}
}