From 1bee811312f80d3c4e4b19f3610ed9b43f06fd9e Mon Sep 17 00:00:00 2001 From: Alen <33656288+cnxysoft@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:05:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8E=A5=E5=8F=A3=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整SetSelfProfile接口为SetQQProfile,使其兼容gocq标准 --- src/onebot/action/extends/SetSelfProfile.ts | 32 ------------------- src/onebot/action/go-cqhttp/SetQQProfile.ts | 34 +++++++++++++++++++++ src/onebot/action/index.ts | 4 +-- src/onebot/action/types.ts | 2 +- 4 files changed, 37 insertions(+), 35 deletions(-) delete mode 100644 src/onebot/action/extends/SetSelfProfile.ts create mode 100644 src/onebot/action/go-cqhttp/SetQQProfile.ts diff --git a/src/onebot/action/extends/SetSelfProfile.ts b/src/onebot/action/extends/SetSelfProfile.ts deleted file mode 100644 index 4c60f0ea..00000000 --- a/src/onebot/action/extends/SetSelfProfile.ts +++ /dev/null @@ -1,32 +0,0 @@ -import BaseAction from '../BaseAction'; -import { ActionName } from '../types'; -import { FromSchema, JSONSchema } from 'json-schema-to-ts'; - -const SchemaData = { - type: 'object', - properties: { - nick: { type: 'string' }, - longNick: { type: 'string' }, - sex: { type: ['number', 'string'] },//传Sex值?建议传0 - }, - required: ['nick', 'longNick', 'sex'], -} as const satisfies JSONSchema; - -type Payload = FromSchema; - -export class SetSelfProfile extends BaseAction { - actionName = ActionName.SetSelfProfile; - PayloadSchema = SchemaData; - - async _handle(payload: Payload) { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const ret = await NTQQUserApi.modifySelfProfile({ - nick: payload.nick, - longNick: payload.longNick, - sex: parseInt(payload.sex.toString()), - birthday: { birthday_year: '', birthday_month: '', birthday_day: '' }, - location: undefined, - }); - return ret; - } -} diff --git a/src/onebot/action/go-cqhttp/SetQQProfile.ts b/src/onebot/action/go-cqhttp/SetQQProfile.ts new file mode 100644 index 00000000..73334115 --- /dev/null +++ b/src/onebot/action/go-cqhttp/SetQQProfile.ts @@ -0,0 +1,34 @@ +import BaseAction from '../BaseAction'; +import { ActionName } from '../types'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; + +const SchemaData = { + type: 'object', + properties: { + nickname: { type: 'string' }, + personal_note: { type: 'string' }, + sex: { type: ['number', 'string'] },//传Sex值?建议传0 + }, + required: ['nickname'], +} as const satisfies JSONSchema; + +type Payload = FromSchema; + +export class SetQQProfile extends BaseAction { + actionName = ActionName.SetQQProfile; + PayloadSchema = SchemaData; + + async _handle(payload: Payload) { + const NTQQUserApi = this.CoreContext.apis.UserApi; + const self = this.CoreContext.selfInfo; + const OldProfile = await NTQQUserApi.getUserDetailInfo(self.uid); + const ret = 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() }, + location: undefined, + }); + return ret; + } +} diff --git a/src/onebot/action/index.ts b/src/onebot/action/index.ts index 7ff7da6d..d4d14a02 100644 --- a/src/onebot/action/index.ts +++ b/src/onebot/action/index.ts @@ -61,7 +61,7 @@ import { TranslateEnWordToZn } from './extends/TranslateEnWordToZn'; import { SetGroupFileFolder } from './file/SetGroupFileFolder'; import { DelGroupFile } from './file/DelGroupFile'; import { DelGroupFileFolder } from './file/DelGroupFileFolder'; -import { SetSelfProfile } from './extends/SetSelfProfile'; +import { SetQQProfile } from './go-cqhttp/SetQQProfile' import { ShareGroupEx, SharePeer } from './extends/ShareContact'; import { CreateCollection } from './extends/CreateCollection'; import { SetLongNick } from './extends/SetLongNick'; @@ -86,7 +86,7 @@ export function createActionMap(onebotContext: NapCatOneBot11Adapter, coreContex const actionHandlers = [ new FetchEmojiLike(onebotContext, coreContext), new GetFile(onebotContext, coreContext), - new SetSelfProfile(onebotContext, coreContext), + new SetQQProfile(onebotContext, coreContext), new ShareGroupEx(onebotContext, coreContext), new SharePeer(onebotContext, coreContext), new CreateCollection(onebotContext, coreContext), diff --git a/src/onebot/action/types.ts b/src/onebot/action/types.ts index 26204339..2cc84873 100644 --- a/src/onebot/action/types.ts +++ b/src/onebot/action/types.ts @@ -91,7 +91,7 @@ export enum ActionName { GetOnlineClient = 'get_online_clients', OCRImage = 'ocr_image', IOCRImage = '.ocr_image', - SetSelfProfile = 'set_self_profile', + SetQQProfile = 'set_qq_profile', CreateCollection = 'create_collection', GetCollectionList = 'get_collection_list', SetLongNick = 'set_self_longnick',