chore: reformat code style

This commit is contained in:
Seijo Cecilia
2024-08-26 14:52:05 +08:00
parent 3ec0edfc60
commit 7671174a96
60 changed files with 295 additions and 237 deletions

View File

@@ -22,6 +22,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class FetchEmojiLike extends BaseAction<Payload, any> {
actionName = ActionName.FetchEmojiLike;
payloadSchema = SchemaData;
async _handle(payload: Payload) {
const NTQQMsgApi = this.core.apis.MsgApi;
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));

View File

@@ -16,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class GetCollectionList extends BaseAction<Payload, any> {
actionName = ActionName.GetCollectionList;
payloadSchema = SchemaData;
async _handle(payload: Payload) {
const NTQQCollectionApi = this.core.apis.CollectionApi;
return await NTQQCollectionApi.getAllCollection(parseInt(payload.category.toString()), +(payload.count ?? 1));

View File

@@ -4,6 +4,7 @@ import { ActionName } from '../types';
export class GetFriendWithCategory extends BaseAction<void, any> {
actionName = ActionName.GetFriendsWithCategory;
async _handle(payload: void) {
return (await this.core.apis.FriendApi.getBuddyV2ExWithCate(true)).map(category => ({
...category,

View File

@@ -3,6 +3,7 @@ import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { checkFileReceived, uri2local } from '@/common/utils/file';
import fs from 'fs';
const SchemaData = {
type: 'object',
properties: {
@@ -19,7 +20,7 @@ export class OCRImage extends BaseAction<Payload, any> {
async _handle(payload: Payload) {
const NTQQSystemApi = this.core.apis.SystemApi;
const { path, isLocal, errMsg, success } = (await uri2local(this.core.NapCatTempPath, payload.image));
const { path, isLocal, success } = (await uri2local(this.core.NapCatTempPath, payload.image));
if (!success) {
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
}

View File

@@ -8,7 +8,7 @@ const SchemaData = {
properties: {
eventType: { type: 'string' },
group_id: { type: 'string' },
user_id: { type: 'string' }
user_id: { type: 'string' },
},
required: ['eventType'],
} as const satisfies JSONSchema;
@@ -25,20 +25,19 @@ export class SetInputStatus extends BaseAction<Payload, any> {
if (payload.group_id) {
peer = {
chatType: ChatType.KCHATTYPEGROUP,
peerUid: payload.group_id
peerUid: payload.group_id,
};
} else if (payload.user_id) {
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id);
if (!uid) throw new Error('uid is empty');
peer = {
chatType: ChatType.KCHATTYPEC2C,
peerUid: uid
peerUid: uid,
};
} else {
throw new Error('请指定 group_id 或 user_id');
}
const ret = await NTQQMsgApi.sendShowInputStatusReq(peer, parseInt(payload.eventType));
return ret;
return await NTQQMsgApi.sendShowInputStatusReq(peer, parseInt(payload.eventType));
}
}

View File

@@ -24,7 +24,7 @@ export class SetOnlineStatus extends BaseAction<Payload, null> {
const ret = await NTQQUserApi.setSelfOnlineStatus(
parseInt(payload.status.toString()),
parseInt(payload.extStatus.toString()),
parseInt(payload.batteryStatus.toString())
parseInt(payload.batteryStatus.toString()),
);
if (ret.result !== 0) {
throw new Error('设置在线状态失败');

View File

@@ -24,7 +24,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
const extendData = await NTQQUserApi.getUserDetailInfoByUinV2(user_id);
const uid = (await NTQQUserApi.getUidByUinV2(user_id))!;
if (!uid || uid.indexOf('*') != -1) {
const ret = {
return {
...extendData.detail.simpleInfo.coreInfo,
...extendData.detail.commonExt,
...extendData.detail.simpleInfo.baseInfo,
@@ -36,9 +36,8 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
qid: extendData.detail.simpleInfo.baseInfo.qid,
level: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? 0) || 0,
login_days: 0,
uid: ''
uid: '',
};
return ret;
}
const data = { ...extendData, ...(await NTQQUserApi.getUserDetailInfo(uid)) };
return OB11Entities.stranger(data);

View File

@@ -22,13 +22,16 @@ export class SetQQProfile extends BaseAction<Payload, any | null> {
const NTQQUserApi = this.core.apis.UserApi;
const self = this.core.selfInfo;
const OldProfile = await NTQQUserApi.getUserDetailInfo(self.uid);
const ret = await NTQQUserApi.modifySelfProfile({
return await NTQQUserApi.modifySelfProfile({
nick: payload.nickname,
longNick: (payload?.personal_note ?? OldProfile?.longNick) || '',
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.sex!.toString()),
birthday: { birthday_year: OldProfile?.birthday_year!.toString(), birthday_month: OldProfile?.birthday_month!.toString(), birthday_day: OldProfile?.birthday_day!.toString() },
birthday: {
birthday_year: OldProfile?.birthday_year!.toString(),
birthday_month: OldProfile?.birthday_month!.toString(),
birthday_day: OldProfile?.birthday_day!.toString(),
},
location: undefined,
});
return ret;
}
}

View File

@@ -32,7 +32,7 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
const isBuddy = await NTQQFriendApi.isBuddy(peerUid);
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
}
throw new Error( '缺少参数 user_id');
throw new Error('缺少参数 user_id');
}
async _handle(payload: Payload): Promise<null> {

View File

@@ -1,4 +1,3 @@
import { WebApiGroupNoticeFeed } from '@/core';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -10,7 +9,7 @@ const SchemaData = {
group_id: { type: ['number', 'string'] },
notice_id: { type: 'string' },
},
required: ['group_id','notice_id'],
required: ['group_id', 'notice_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;

View File

@@ -26,14 +26,14 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
const NTQQGroupApi = this.core.apis.GroupApi;
const isNocache = typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache;
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error (`Uin2Uid Error ${payload.user_id}不存在`);
if (!uid) throw new Error(`Uin2Uid Error ${payload.user_id}不存在`);
const [member, info] = await Promise.allSettled([
NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache),
NTQQUserApi.getUserDetailInfo(uid),
]);
if (member.status !== 'fulfilled') throw new Error (`群(${payload.group_id})成员${payload.user_id}不存在 ${member.reason}`);
if (member.status !== 'fulfilled') throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在 ${member.reason}`);
if (info.status === 'fulfilled') {
this.core.context.logger.logDebug("群成员详细信息结果", info.value);
this.core.context.logger.logDebug('群成员详细信息结果', info.value);
Object.assign(member, info.value);
} else {
this.core.context.logger.logDebug(`获取群成员详细信息失败, 只能返回基础信息 ${info.reason}`);

View File

@@ -63,7 +63,7 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
}
}
}
_groupMembers = Array.from(MemberMap.values());
return _groupMembers;
}

View File

@@ -32,7 +32,7 @@ class DeleteMsg extends BaseAction<Payload, void> {
'NodeIKernelMsgListener/onMsgInfoListUpdate',
1,
5000,
(msgs) => !!msgs.find(m => m.msgId === msg.MsgId && m.recallTime !== '0')
(msgs) => !!msgs.find(m => m.msgId === msg.MsgId && m.recallTime !== '0'),
).catch(() => new Promise<undefined>((resolve) => {
resolve(undefined);
}));

View File

@@ -26,7 +26,7 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
return { chatType: isBuddy ? ChatType.KCHATTYPEC2C : ChatType.KCHATTYPETEMPC2CFROMGROUP, peerUid };
}
if (!payload.group_id) {
throw new Error( '缺少参数 group_id 或 user_id');
throw new Error('缺少参数 group_id 或 user_id');
}
return { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
}

View File

@@ -113,7 +113,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
const messages = normalize(
payload.message,
typeof payload.auto_escape === 'string' ? payload.auto_escape === 'true' : !!payload.auto_escape
typeof payload.auto_escape === 'string' ? payload.auto_escape === 'true' : !!payload.auto_escape,
);
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {

View File

@@ -4,6 +4,7 @@ import CanSendRecord from './CanSendRecord';
interface ReturnType {
yes: boolean;
}
export default class CanSendImage extends CanSendRecord {
actionName = ActionName.CanSendImage;
}

View File

@@ -6,7 +6,7 @@ export class GetCSRF extends BaseAction<any, any> {
async _handle(payload: any) {
return {
token: "",
token: '',
};
}
}

View File

@@ -105,9 +105,9 @@ export enum ActionName {
GOCQHTTP_UploadPrivateFile = 'upload_private_file',
TestApi01 = 'test_api_01',
FetchEmojiLike = 'fetch_emoji_like',
GetGuildProfile = "get_guild_service_profile",
SetModelShow = "_set_model_show",
SetInputStatus = "set_input_status",
GetCSRF = "get_csrf_token",
DelGroupNotice = "_del_group_notice",
GetGuildProfile = 'get_guild_service_profile',
SetModelShow = '_set_model_show',
SetInputStatus = 'set_input_status',
GetCSRF = 'get_csrf_token',
DelGroupNotice = '_del_group_notice',
}