mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
33 lines
843 B
TypeScript
33 lines
843 B
TypeScript
import { OB11Return } from '../types';
|
|
|
|
import { isNull } from '../../common/helper';
|
|
|
|
export class OB11Response {
|
|
static res<T>(data: T, status: string, retcode: number, message: string = ''): OB11Return<T> {
|
|
return {
|
|
status: status,
|
|
retcode: retcode,
|
|
data: data,
|
|
message: message,
|
|
wording: message,
|
|
echo: null,
|
|
};
|
|
}
|
|
|
|
static ok<T>(data: T, echo: any = null) {
|
|
const res = OB11Response.res<T>(data, 'ok', 0);
|
|
if (!isNull(echo)) {
|
|
res.echo = echo;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
static error(err: string, retcode: number, echo: any = null) {
|
|
const res = OB11Response.res(null, 'failed', retcode, err);
|
|
if (!isNull(echo)) {
|
|
res.echo = echo;
|
|
}
|
|
return res;
|
|
}
|
|
}
|