From 7416e6caf669d3597d0bdd1db45ad46f310e53e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sat, 26 Oct 2024 10:36:41 +0800 Subject: [PATCH] feat: GoCQHTTPDeleteFriend --- src/core/apis/friend.ts | 8 +++- .../action/go-cqhttp/GoCQHTTPDeleteFriend.ts | 38 +++++++++++++++++++ src/onebot/action/index.ts | 2 + src/onebot/action/types.ts | 2 +- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/onebot/action/go-cqhttp/GoCQHTTPDeleteFriend.ts diff --git a/src/core/apis/friend.ts b/src/core/apis/friend.ts index facf487f..b805c729 100644 --- a/src/core/apis/friend.ts +++ b/src/core/apis/friend.ts @@ -34,7 +34,13 @@ export class NTQQFriendApi { data.forEach((value) => retMap.set(value.uin!, value.uid!)); return retMap; } - + async delBuudy(uid: string, tempBlock = false, tempBothDel = false) { + return this.context.session.getBuddyService().delBuddy({ + friendUid: uid, + tempBlock: tempBlock, + tempBothDel: tempBothDel + }); + } async getBuddyV2ExWithCate(refresh = false) { const categoryMap: Map = new Map(); const buddyService = this.context.session.getBuddyService(); diff --git a/src/onebot/action/go-cqhttp/GoCQHTTPDeleteFriend.ts b/src/onebot/action/go-cqhttp/GoCQHTTPDeleteFriend.ts new file mode 100644 index 00000000..8bdeb1fa --- /dev/null +++ b/src/onebot/action/go-cqhttp/GoCQHTTPDeleteFriend.ts @@ -0,0 +1,38 @@ +import BaseAction from '../BaseAction'; +import { ActionName } from '../types'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; + +const SchemaData = { + type: 'object', + properties: { + friend_id: { type: ['string', 'number'] }, + temp_block: { type: 'boolean' }, + temp_both_del: { type: 'boolean' }, + }, + required: ['friend_id'], +} as const satisfies JSONSchema; +type Payload = FromSchema; + +export class GoCQHTTPDeleteFriend extends BaseAction { + actionName = ActionName.GoCQHTTP_DeleteFriend; + payloadSchema = SchemaData; + + async _handle(payload: Payload) { + let uid = await this.core.apis.UserApi.getUidByUinV2(payload.friend_id.toString()); + + if (!uid) { + return { + valid: false, + message: '好友不存在', + }; + } + let isBuddy = this.core.apis.FriendApi.isBuddy(uid); + if (!isBuddy) { + return { + valid: false, + message: '不是好友', + }; + } + return await this.core.apis.FriendApi.delBuudy(uid, payload.temp_block, payload.temp_both_del); + } +} diff --git a/src/onebot/action/index.ts b/src/onebot/action/index.ts index e1698fba..aae77979 100644 --- a/src/onebot/action/index.ts +++ b/src/onebot/action/index.ts @@ -97,6 +97,7 @@ import { GoCQHTTPGetGroupAtAllRemain } from './go-cqhttp/GetGroupAtAllRemain'; import { GoCQHTTPCheckUrlSafely } from './go-cqhttp/GoCQHTTPCheckUrlSafely'; import { GoCQHTTPGetModelShow } from './go-cqhttp/GoCQHTTPGetModelShow'; import { GoCQHTTPSetModelShow } from './go-cqhttp/GoCQHTTPSetModelShow'; +import { GoCQHTTPDeleteFriend } from './go-cqhttp/GoCQHTTPDeleteFriend'; export type ActionMap = Map>; @@ -154,6 +155,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo new GetRobotUinRange(obContext, core), new GetFriendWithCategory(obContext, core), //以下为go-cqhttp api + new GoCQHTTPDeleteFriend(obContext, core), new GoCQHTTPCheckUrlSafely(obContext, core), new GetOnlineClient(obContext, core), new OCRImage(obContext, core), diff --git a/src/onebot/action/types.ts b/src/onebot/action/types.ts index 774a73ef..5a4e5fc9 100644 --- a/src/onebot/action/types.ts +++ b/src/onebot/action/types.ts @@ -61,7 +61,7 @@ export enum ActionName { GoCQHTTP_SetModelShow = '_set_model_show', GetOnlineClient = 'get_online_clients', // GetUnidirectionalFriendList = 'get_unidirectional_friend_list', - // DeleteFriend = 'delete_friend', + GoCQHTTP_DeleteFriend = 'delete_friend', // DeleteUnidirectionalFriendList = 'delete_unidirectional_friend', GoCQHTTP_MarkMsgAsRead = 'mark_msg_as_read', GoCQHTTP_SendGroupForwardMsg = 'send_group_forward_msg',