koishi-plugin-equery
Version:
34 lines (33 loc) • 827 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.success = success;
exports.failure = failure;
exports.formatResponse = formatResponse;
function success(message, data) {
return {
success: true,
message,
data,
};
}
function failure(message, error) {
return {
success: false,
message,
error,
};
}
function formatResponse(response) {
if (!response.success) {
return `${response.error ? `错误详情: ${response.error}` : response.message}`;
}
if (response.data &&
typeof response.data === "object" &&
"type" in response.data) {
return response.data;
}
if (response.data && typeof response.data === "string") {
return response.data;
}
return response.message;
}