From 557864395b7825f64c6aa163099796bc37fd598c 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, 20 Jul 2024 16:09:44 +0800 Subject: [PATCH] feat: support essence --- docs/changelogs/CHANGELOG.v1.6.7.md | 3 +-- src/onebot11/action/group/DelEssenceMsg.ts | 31 ++++++++++++++++++++++ src/onebot11/action/group/SetEssenceMsg.ts | 30 +++++++++++++++++++++ src/onebot11/action/types.ts | 4 ++- 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/onebot11/action/group/DelEssenceMsg.ts create mode 100644 src/onebot11/action/group/SetEssenceMsg.ts diff --git a/docs/changelogs/CHANGELOG.v1.6.7.md b/docs/changelogs/CHANGELOG.v1.6.7.md index 4516cfbc..8cd25cea 100644 --- a/docs/changelogs/CHANGELOG.v1.6.7.md +++ b/docs/changelogs/CHANGELOG.v1.6.7.md @@ -10,12 +10,11 @@ QQ Version: Windows 9.9.12-26000 / Linux 3.2.9-26000 ## 修复与优化 1. 尝试修复卡顿问题 -2. 修复精华消息设置时的报错 +2. 修复 精华消息被设置/一起听 接受时的报错 ## 新增与调整 1. 戳一戳上报raw 2. 精华消息设置通知事件 3. 新增设置/删除群精华API -4. 表情回应事件 新增的 API 详细见[API文档](https://napneko.github.io/zh-CN/develop/extends_api) diff --git a/src/onebot11/action/group/DelEssenceMsg.ts b/src/onebot11/action/group/DelEssenceMsg.ts new file mode 100644 index 00000000..c8dbb2d9 --- /dev/null +++ b/src/onebot11/action/group/DelEssenceMsg.ts @@ -0,0 +1,31 @@ + +import { dbUtil } from '@/common/utils/db'; +import BaseAction from '../BaseAction'; +import { ActionName } from '../types'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +import { NTQQGroupApi } from '@/core'; + +const SchemaData = { + type: 'object', + properties: { + message_id: { type: ['number', 'string'] } + }, + required: ['message_id'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; + +export default class DelEssenceMsg extends BaseAction { + actionName = ActionName.DelEssenceMsg; + PayloadSchema = SchemaData; + protected async _handle(payload: Payload): Promise { + const msg = await dbUtil.getMsgByShortId(parseInt(payload.message_id.toString())); + if (!msg) { + throw new Error('msg not found'); + } + return await NTQQGroupApi.removeGroupEssence( + msg.peerUin, + msg.msgId + ); + } +} diff --git a/src/onebot11/action/group/SetEssenceMsg.ts b/src/onebot11/action/group/SetEssenceMsg.ts new file mode 100644 index 00000000..dc788338 --- /dev/null +++ b/src/onebot11/action/group/SetEssenceMsg.ts @@ -0,0 +1,30 @@ +import { dbUtil } from '@/common/utils/db'; +import BaseAction from '../BaseAction'; +import { ActionName } from '../types'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +import { NTQQGroupApi, NTQQMsgApi } from '@/core'; + +const SchemaData = { + type: 'object', + properties: { + message_id: { type: ['number', 'string'] } + }, + required: ['message_id'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; + +export default class SetEssenceMsg extends BaseAction { + actionName = ActionName.SetEssenceMsg; + PayloadSchema = SchemaData; + protected async _handle(payload: Payload): Promise { + const msg = await dbUtil.getMsgByShortId(parseInt(payload.message_id.toString())); + if (!msg) { + throw new Error('msg not found'); + } + return await NTQQGroupApi.addGroupEssence( + msg.peerUin, + msg.msgId + ); + } +} diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 76b32493..aefd3d26 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -93,5 +93,7 @@ export enum ActionName { SetSelfProfile = 'set_self_profile', CreateCollection = 'create_collection', GetCollectionList = 'get_collection_list', - SetLongNick = 'set_self_longnick' + SetLongNick = 'set_self_longnick', + SetEssenceMsg = "set_essence_msg", + DelEssenceMsg = "delete_essence_msg" }