mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-04 06:31:13 +00:00
Refactor action example imports and add example files
Moved action example data to dedicated 'examples.ts' files for each action category (extends, file, go-cqhttp, group, msg, system, user). Updated all action classes to import and use the new example modules, improving code organization and maintainability. Also added missing actionTags and actionDescription where appropriate.
This commit is contained in:
parent
fd1808e36a
commit
335c83a3d5
@ -4,7 +4,7 @@ import { checkFileExist, uriToLocalFile } from 'napcat-common/src/file';
|
||||
import fs from 'fs';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { ExtendsActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
image: Type.String({ description: '图片路径、URL或Base64' }),
|
||||
@ -21,8 +21,7 @@ class OCRImageBase extends OneBotAction<PayloadType, ReturnType> {
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '图片 OCR 识别';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ActionExamples.OCRImage.payload;
|
||||
override returnExample = ActionExamples.OCRImage.return;
|
||||
override payloadExample = ExtendsActionsExamples.OCRImage.payload;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const { path, success } = await uriToLocalFile(this.core.NapCatTempPath, payload.image);
|
||||
|
||||
38
packages/napcat-onebot/action/extends/examples.ts
Normal file
38
packages/napcat-onebot/action/extends/examples.ts
Normal file
@ -0,0 +1,38 @@
|
||||
export const ExtendsActionsExamples = {
|
||||
OCRImage: {
|
||||
payload: { image: 'image_id_123' },
|
||||
response: { texts: [{ text: '识别内容', coordinates: [] }] },
|
||||
},
|
||||
GetAiCharacters: {
|
||||
payload: { group_id: '123456' },
|
||||
response: { characters: [] },
|
||||
},
|
||||
GetClientkey: {
|
||||
payload: {},
|
||||
response: { clientkey: 'abcdef123456' },
|
||||
},
|
||||
SetQQAvatar: {
|
||||
payload: { file: 'base64://...' },
|
||||
response: {},
|
||||
},
|
||||
SetGroupKickMembers: {
|
||||
payload: { group_id: '123456', user_id: ['123456789'], reject_add_request: false },
|
||||
response: {},
|
||||
},
|
||||
TranslateEnWordToZn: {
|
||||
payload: { words: ['hello'] },
|
||||
response: { words: ['你好'] },
|
||||
},
|
||||
GetRkey: {
|
||||
payload: {},
|
||||
response: { rkey: '...' },
|
||||
},
|
||||
SetLongNick: {
|
||||
payload: { longNick: '个性签名' },
|
||||
response: {},
|
||||
},
|
||||
SetSpecialTitle: {
|
||||
payload: { group_id: '123456', user_id: '123456789', special_title: '头衔' },
|
||||
response: {},
|
||||
},
|
||||
};
|
||||
22
packages/napcat-onebot/action/file/examples.ts
Normal file
22
packages/napcat-onebot/action/file/examples.ts
Normal file
@ -0,0 +1,22 @@
|
||||
export const FileActionsExamples = {
|
||||
GetFile: {
|
||||
payload: { file: 'file_id_123' },
|
||||
response: { file: '/path/to/file', url: 'http://...', file_size: 1024, file_name: 'test.jpg' },
|
||||
},
|
||||
GetGroupFileUrl: {
|
||||
payload: { group_id: '123456', file_id: 'file_id_123', busid: 102 },
|
||||
response: { url: 'http://...' },
|
||||
},
|
||||
GetImage: {
|
||||
payload: { file: 'image_id_123' },
|
||||
response: { file: '/path/to/image', url: 'http://...' },
|
||||
},
|
||||
GetPrivateFileUrl: {
|
||||
payload: { user_id: '123456789', file_id: 'file_id_123' },
|
||||
response: { url: 'http://...' },
|
||||
},
|
||||
GetRecord: {
|
||||
payload: { file: 'record_id_123', out_format: 'mp3' },
|
||||
response: { file: '/path/to/record', url: 'http://...' },
|
||||
},
|
||||
};
|
||||
@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -23,6 +24,10 @@ export class CreateGroupFileFolder extends OneBotAction<PayloadType, ReturnType>
|
||||
override actionName = ActionName.GoCQHTTP_CreateGroupFileFolder;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '创建群文件目录';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.CreateGroupFileFolder.payload;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const folderName = payload.folder_name || payload.name;
|
||||
return (await this.core.apis.GroupApi.creatGroupFileFolder(payload.group_id.toString(), folderName!)).resultWithGroupItem;
|
||||
|
||||
@ -2,6 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from 'napcat-common/src/file-uuid';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -18,6 +19,10 @@ export class DeleteGroupFile extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GOCQHTTP_DeleteGroupFile;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '删除群文件';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.DeleteGroupFile.payload;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const data = FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
||||
if (!data || !data.fileId) throw new Error('Invalid file_id');
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -18,6 +19,10 @@ export class DeleteGroupFileFolder extends OneBotAction<PayloadType, ReturnType>
|
||||
override actionName = ActionName.GoCQHTTP_DeleteGroupFileFolder;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '删除群文件目录';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.DeleteGroupFileFolder.payload;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
return (await this.core.apis.GroupApi.delGroupFileFolder(
|
||||
payload.group_id.toString(), payload.folder ?? payload.folder_id ?? '')).groupFileCommonResult;
|
||||
|
||||
@ -5,6 +5,7 @@ import { join as joinPath } from 'node:path';
|
||||
import { calculateFileMD5, uriToLocalFile } from 'napcat-common/src/file';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
url: Type.Optional(Type.String({ description: '下载链接' })),
|
||||
@ -25,6 +26,9 @@ export default class GoCQHTTPDownloadFile extends OneBotAction<PayloadType, Retu
|
||||
override actionName = ActionName.GoCQHTTP_DownloadFile;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '下载文件';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.DownloadFile.payload;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const isRandomName = !payload.name;
|
||||
|
||||
@ -5,6 +5,7 @@ import { MessageUnique } from 'napcat-common/src/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { ChatType, ElementType, MsgSourceType, NTMsgType, RawMessage } from 'napcat-core';
|
||||
import { isNumeric } from 'napcat-common/src/helper';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
message_id: Type.Optional(Type.String({ description: '消息ID' })),
|
||||
@ -28,7 +29,8 @@ export class GoCQHTTPGetForwardMsgAction extends OneBotAction<PayloadType, Retur
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取合并转发消息';
|
||||
override actionTags = ['消息接口'];
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetForwardMsg.payload;
|
||||
|
||||
private createTemplateNode (message: OB11Message): OB11MessageNode {
|
||||
return {
|
||||
|
||||
@ -6,6 +6,7 @@ import { MessageUnique } from 'napcat-common/src/message-unique';
|
||||
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { NetworkAdapterConfig } from '@/napcat-onebot/config/config';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
user_id: Type.String({ description: '用户QQ' }),
|
||||
@ -30,6 +31,9 @@ export default class GetFriendMsgHistory extends OneBotAction<PayloadType, Retur
|
||||
override actionName = ActionName.GetFriendMsgHistory;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取好友历史消息';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetFriendMsgHistory.payload;
|
||||
|
||||
async _handle (payload: PayloadType, _adapter: string, config: NetworkAdapterConfig): Promise<ReturnType> {
|
||||
// 处理参数
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -21,7 +22,8 @@ export class GoCQHTTPGetGroupAtAllRemain extends OneBotAction<PayloadType, Retur
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取群艾特全体剩余次数';
|
||||
override actionTags = ['群组接口'];
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetGroupAtAllRemain.payload;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const ret = await this.core.apis.GroupApi.getGroupRemainAtTimes(payload.group_id.toString());
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -21,6 +22,9 @@ export class GetGroupFileSystemInfo extends OneBotAction<PayloadType, ReturnType
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupFileSystemInfo;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取群文件系统信息';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetGroupFileSystemInfo.payload;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const groupFileCount = (await this.core.apis.GroupApi.getGroupFileCount([payload.group_id.toString()])).groupFileCounts[0];
|
||||
|
||||
@ -2,6 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { OB11Construct } from '@/napcat-onebot/helper/data';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -23,6 +24,10 @@ export class GetGroupFilesByFolder extends OneBotAction<PayloadType, ReturnType>
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupFilesByFolder;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取群文件夹文件列表';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetGroupFilesByFolder.payload;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const retRaw = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
|
||||
sortType: 1,
|
||||
|
||||
@ -2,6 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { WebHonorType } from 'napcat-core/types';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -27,7 +28,8 @@ export class GetGroupHonorInfo extends OneBotAction<PayloadType, ReturnType> {
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取群荣誉信息';
|
||||
override actionTags = ['群组接口'];
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetGroupHonorInfo.payload;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
if (!payload.type) {
|
||||
|
||||
@ -5,6 +5,7 @@ import { ChatType, Peer } from 'napcat-core/types';
|
||||
import { MessageUnique } from 'napcat-common/src/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { NetworkAdapterConfig } from '@/napcat-onebot/config/config';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -29,6 +30,9 @@ export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction<PayloadType
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取群历史消息';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetGroupMsgHistory.payload;
|
||||
|
||||
async _handle (payload: PayloadType, _adapter: string, config: NetworkAdapterConfig): Promise<ReturnType> {
|
||||
const peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
|
||||
|
||||
@ -2,6 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { OB11Construct } from '@/napcat-onebot/helper/data';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -21,6 +22,10 @@ export class GetGroupRootFiles extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupRootFiles;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取群根目录文件列表';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetGroupRootFiles.payload;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
|
||||
sortType: 1,
|
||||
|
||||
@ -2,6 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { sleep } from 'napcat-common/src/helper';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({}, { description: '在线客户端负载' });
|
||||
|
||||
@ -15,6 +16,9 @@ export class GetOnlineClient extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GetOnlineClient;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取在线客户端';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetOnlineClient.payload;
|
||||
|
||||
async _handle () {
|
||||
// 注册监听
|
||||
|
||||
@ -4,8 +4,7 @@ import { OB11Construct } from '@/napcat-onebot/helper/data';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { calcQQLevel } from 'napcat-common/src/helper';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
user_id: Type.String({ description: '用户QQ' }),
|
||||
@ -39,9 +38,8 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction<PayloadType, R
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取陌生人信息';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = ActionExamples.GetStrangerInfo.payload;
|
||||
override returnExample = ActionExamples.GetStrangerInfo.return;
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GetStrangerInfo.payload;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const user_id = payload.user_id.toString();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
export const GoCQHTTPCheckUrlSafelyPayloadSchema = Type.Object({
|
||||
url: Type.String({ description: '要检查的 URL' }),
|
||||
@ -18,6 +19,9 @@ export class GoCQHTTPCheckUrlSafely extends OneBotAction<GoCQHTTPCheckUrlSafelyP
|
||||
override actionName = ActionName.GoCQHTTP_CheckUrlSafely;
|
||||
override payloadSchema = GoCQHTTPCheckUrlSafelyPayloadSchema;
|
||||
override returnSchema = GoCQHTTPCheckUrlSafelyReturnSchema;
|
||||
override actionDescription = '检查 URL 安全性';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GoCQHTTPCheckUrlSafely.payload;
|
||||
|
||||
async _handle () {
|
||||
return { level: 1 };
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
export const GoCQHTTPDeleteFriendPayloadSchema = Type.Object({
|
||||
friend_id: Type.Optional(Type.Union([Type.String(), Type.Number()], { description: '好友 QQ 号' })),
|
||||
@ -15,6 +16,9 @@ export class GoCQHTTPDeleteFriend extends OneBotAction<GoCQHTTPDeleteFriendPaylo
|
||||
override actionName = ActionName.GoCQHTTP_DeleteFriend;
|
||||
override payloadSchema = GoCQHTTPDeleteFriendPayloadSchema;
|
||||
override returnSchema = Type.Any();
|
||||
override actionDescription = '删除好友';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GoCQHTTPDeleteFriend.payload;
|
||||
|
||||
async _handle (payload: GoCQHTTPDeleteFriendPayload) {
|
||||
const uin = payload.friend_id ?? payload.user_id ?? '';
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
export const GoCQHTTPGetModelShowPayloadSchema = Type.Object({
|
||||
model: Type.Optional(Type.String({ description: '模型名称' })),
|
||||
@ -21,6 +22,9 @@ export class GoCQHTTPGetModelShow extends OneBotAction<GoCQHTTPGetModelShowPaylo
|
||||
override actionName = ActionName.GoCQHTTP_GetModelShow;
|
||||
override payloadSchema = GoCQHTTPGetModelShowPayloadSchema;
|
||||
override returnSchema = GoCQHTTPGetModelShowReturnSchema;
|
||||
override actionDescription = '获取模型显示';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GoCQHTTPGetModelShow.payload;
|
||||
|
||||
async _handle (payload: GoCQHTTPGetModelShowPayload) {
|
||||
if (!payload.model) {
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
// 兼容性代码
|
||||
export class GoCQHTTPSetModelShow extends OneBotAction<void, void> {
|
||||
override actionName = ActionName.GoCQHTTP_SetModelShow;
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = Type.Null();
|
||||
override actionDescription = '设置模型显示';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.GoCQHTTPSetModelShow.payload;
|
||||
|
||||
async _handle () {
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { QuickAction, QuickActionEvent } from '@/napcat-onebot/types';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
const SenderSchema = Type.Object({
|
||||
user_id: Type.String({ description: '用户ID' }),
|
||||
@ -62,6 +63,9 @@ export class GoCQHTTPHandleQuickAction extends OneBotAction<GoCQHTTPHandleQuickA
|
||||
override actionName = ActionName.GoCQHTTP_HandleQuickAction;
|
||||
override payloadSchema = GoCQHTTPHandleQuickActionPayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionDescription = '处理快速操作';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.QuickAction.payload;
|
||||
|
||||
async _handle (payload: GoCQHTTPHandleQuickActionPayload): Promise<void> {
|
||||
this.obContext.apis.QuickActionApi
|
||||
|
||||
@ -3,6 +3,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { unlink } from 'node:fs/promises';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
export const SendGroupNoticePayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -21,6 +22,10 @@ export class SendGroupNotice extends OneBotAction<SendGroupNoticePayload, void>
|
||||
override actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
||||
override payloadSchema = SendGroupNoticePayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionDescription = '发送群公告';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.SendGroupNotice.payload;
|
||||
|
||||
async _handle (payload: SendGroupNoticePayload) {
|
||||
let UploadImage: { id: string, width: number, height: number; } | undefined;
|
||||
if (payload.image) {
|
||||
|
||||
@ -3,6 +3,8 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { checkFileExistV2, uriToLocalFile } from 'napcat-common/src/file';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import fs from 'node:fs/promises';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
export const SetGroupPortraitPayloadSchema = Type.Object({
|
||||
file: Type.String({ description: '头像文件路径或 URL' }),
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -21,6 +23,9 @@ export default class SetGroupPortrait extends OneBotAction<SetGroupPortraitPaylo
|
||||
override actionName = ActionName.SetGroupPortrait;
|
||||
override payloadSchema = SetGroupPortraitPayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '设置群头像';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.SetGroupPortrait.payload;
|
||||
|
||||
async _handle (payload: SetGroupPortraitPayload): Promise<ReturnType> {
|
||||
const { path, success } = (await uriToLocalFile(this.core.NapCatTempPath, payload.file));
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
export const SetQQProfilePayloadSchema = Type.Object({
|
||||
nickname: Type.String({ description: '昵称' }),
|
||||
@ -13,6 +14,9 @@ export class SetQQProfile extends OneBotAction<SetQQProfilePayload, any> {
|
||||
override actionName = ActionName.SetQQProfile;
|
||||
override payloadSchema = SetQQProfilePayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '设置结果' });
|
||||
override actionDescription = '设置 QQ 资料';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.SetQQProfile.payload;
|
||||
|
||||
async _handle (payload: SetQQProfilePayload) {
|
||||
const self = this.core.selfInfo;
|
||||
|
||||
@ -5,6 +5,7 @@ import fs from 'fs';
|
||||
import { uriToLocalFile } from 'napcat-common/src/file';
|
||||
import { SendMessageContext } from '@/napcat-onebot/api';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
export const GoCQHTTPUploadGroupFilePayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -27,6 +28,9 @@ export default class GoCQHTTPUploadGroupFile extends OneBotAction<GoCQHTTPUpload
|
||||
override actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
||||
override payloadSchema = GoCQHTTPUploadGroupFilePayloadSchema;
|
||||
override returnSchema = GoCQHTTPUploadGroupFileReturnSchema;
|
||||
override actionDescription = '上传群文件';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.UploadGroupFile.payload;
|
||||
|
||||
async _handle (payload: GoCQHTTPUploadGroupFilePayload): Promise<GoCQHTTPUploadGroupFileResponse> {
|
||||
let file = payload.file;
|
||||
|
||||
@ -6,6 +6,7 @@ import { uriToLocalFile } from 'napcat-common/src/file';
|
||||
import { SendMessageContext } from '@/napcat-onebot/api';
|
||||
import { ContextMode, createContext } from '@/napcat-onebot/action/msg/SendMsg';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
export const GoCQHTTPUploadPrivateFilePayloadSchema = Type.Object({
|
||||
user_id: Type.String({ description: '用户 QQ' }),
|
||||
@ -26,6 +27,9 @@ export default class GoCQHTTPUploadPrivateFile extends OneBotAction<GoCQHTTPUplo
|
||||
override actionName = ActionName.GOCQHTTP_UploadPrivateFile;
|
||||
override payloadSchema = GoCQHTTPUploadPrivateFilePayloadSchema;
|
||||
override returnSchema = GoCQHTTPUploadPrivateFileReturnSchema;
|
||||
override actionDescription = '上传私聊文件';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.UploadPrivateFile.payload;
|
||||
|
||||
async getPeer (payload: GoCQHTTPUploadPrivateFilePayload): Promise<Peer> {
|
||||
if (payload.user_id) {
|
||||
|
||||
102
packages/napcat-onebot/action/go-cqhttp/examples.ts
Normal file
102
packages/napcat-onebot/action/go-cqhttp/examples.ts
Normal file
@ -0,0 +1,102 @@
|
||||
export const GoCQHTTPActionsExamples = {
|
||||
GetStrangerInfo: {
|
||||
payload: { user_id: '123456789' },
|
||||
response: { user_id: 123456789, nickname: '昵称', sex: 'unknown' },
|
||||
},
|
||||
GetGroupHonorInfo: {
|
||||
payload: { group_id: '123456', type: 'all' },
|
||||
response: { group_id: 123456, current_talkative: {}, talkative_list: [] },
|
||||
},
|
||||
GetForwardMsg: {
|
||||
payload: { message_id: '123456' },
|
||||
response: { messages: [] },
|
||||
},
|
||||
SendForwardMsg: {
|
||||
payload: { group_id: '123456', messages: [] },
|
||||
response: { message_id: 123456 },
|
||||
},
|
||||
GetGroupAtAllRemain: {
|
||||
payload: { group_id: '123456' },
|
||||
response: { can_at_all: true, remain_at_all_count_for_group: 10, remain_at_all_count_for_self: 10 },
|
||||
},
|
||||
CreateGroupFileFolder: {
|
||||
payload: { group_id: '123456', name: '测试目录' },
|
||||
response: { result: {}, groupItem: {} },
|
||||
},
|
||||
DeleteGroupFile: {
|
||||
payload: { group_id: '123456', file_id: 'file_uuid_123' },
|
||||
response: {},
|
||||
},
|
||||
DeleteGroupFileFolder: {
|
||||
payload: { group_id: '123456', folder_id: 'folder_uuid_123' },
|
||||
response: {},
|
||||
},
|
||||
DownloadFile: {
|
||||
payload: { url: 'https://example.com/file.png', thread_count: 1, headers: 'User-Agent: NapCat' },
|
||||
response: { file: '/path/to/downloaded/file' },
|
||||
},
|
||||
GetFriendMsgHistory: {
|
||||
payload: { user_id: '123456789', message_seq: 0, count: 20 },
|
||||
response: { messages: [] },
|
||||
},
|
||||
GetGroupFilesByFolder: {
|
||||
payload: { group_id: '123456', folder_id: 'folder_id' },
|
||||
response: { files: [], folders: [] },
|
||||
},
|
||||
GetGroupFileSystemInfo: {
|
||||
payload: { group_id: '123456' },
|
||||
response: { file_count: 10, limit_count: 10000, used_space: 1024, total_space: 10737418240 },
|
||||
},
|
||||
GetGroupMsgHistory: {
|
||||
payload: { group_id: '123456', message_seq: 0, count: 20 },
|
||||
response: { messages: [] },
|
||||
},
|
||||
GetGroupRootFiles: {
|
||||
payload: { group_id: '123456' },
|
||||
response: { files: [], folders: [] },
|
||||
},
|
||||
GetOnlineClient: {
|
||||
payload: { no_cache: false },
|
||||
response: { clients: [] },
|
||||
},
|
||||
GoCQHTTPCheckUrlSafely: {
|
||||
payload: { url: 'https://example.com' },
|
||||
response: { level: 1 },
|
||||
},
|
||||
GoCQHTTPDeleteFriend: {
|
||||
payload: { user_id: '123456789' },
|
||||
response: {},
|
||||
},
|
||||
GoCQHTTPGetModelShow: {
|
||||
payload: { model: 'iPhone 13' },
|
||||
response: { variants: [] },
|
||||
},
|
||||
GoCQHTTPSetModelShow: {
|
||||
payload: { model: 'iPhone 13', model_show: 'iPhone 13' },
|
||||
response: {},
|
||||
},
|
||||
QuickAction: {
|
||||
payload: { context: {}, operation: {} },
|
||||
response: {},
|
||||
},
|
||||
SendGroupNotice: {
|
||||
payload: { group_id: '123456', content: '公告内容', image: 'base64://...' },
|
||||
response: {},
|
||||
},
|
||||
SetGroupPortrait: {
|
||||
payload: { group_id: '123456', file: 'base64://...' },
|
||||
response: {},
|
||||
},
|
||||
SetQQProfile: {
|
||||
payload: { nickname: '新昵称', personal_note: '个性签名' },
|
||||
response: {},
|
||||
},
|
||||
UploadGroupFile: {
|
||||
payload: { group_id: '123456', file: '/path/to/file', name: 'test.txt' },
|
||||
response: { file_id: 'file_uuid_123' },
|
||||
},
|
||||
UploadPrivateFile: {
|
||||
payload: { user_id: '123456789', file: '/path/to/file', name: 'test.txt' },
|
||||
response: { file_id: 'file_uuid_123' },
|
||||
},
|
||||
};
|
||||
@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GroupActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
|
||||
@ -4,7 +4,7 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { OB11GroupSchema } from '../schemas';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { GroupActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -22,8 +22,7 @@ class GetGroupInfo extends OneBotAction<PayloadType, ReturnType> {
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取群信息';
|
||||
override actionTags = ['群组接口'];
|
||||
override payloadExample = ActionExamples.GetGroupInfo.payload;
|
||||
override returnExample = ActionExamples.GetGroupInfo.return;
|
||||
override payloadExample = GroupActionsExamples.GetGroupInfo.payload;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const group = (await this.core.apis.GroupApi.getGroups()).find(e => e.groupCode === payload.group_id.toString());
|
||||
|
||||
78
packages/napcat-onebot/action/group/examples.ts
Normal file
78
packages/napcat-onebot/action/group/examples.ts
Normal file
@ -0,0 +1,78 @@
|
||||
export const GroupActionsExamples = {
|
||||
DelEssenceMsg: {
|
||||
payload: { message_id: 123456 },
|
||||
response: {},
|
||||
},
|
||||
DelGroupNotice: {
|
||||
payload: { group_id: '123456', notice_id: 'notice_123' },
|
||||
response: {},
|
||||
},
|
||||
GetGroupDetailInfo: {
|
||||
payload: { group_id: '123456' },
|
||||
response: { group_id: 123456, group_name: '测试群', member_count: 100, max_member_count: 500 },
|
||||
},
|
||||
GetGroupEssence: {
|
||||
payload: { group_id: '123456' },
|
||||
response: [{ message_id: 123456, sender_id: 123456, sender_nick: '昵称', operator_id: 123456, operator_nick: '昵称', operator_time: 1710000000, content: '精华内容' }],
|
||||
},
|
||||
GetGroupInfo: {
|
||||
payload: { group_id: '123456' },
|
||||
response: { group_id: 123456, group_name: '测试群', member_count: 100, max_member_count: 500 },
|
||||
},
|
||||
GetGroupList: {
|
||||
payload: {},
|
||||
response: [{ group_id: 123456, group_name: '测试群', member_count: 100, max_member_count: 500 }],
|
||||
},
|
||||
GetGroupMemberInfo: {
|
||||
payload: { group_id: '123456', user_id: '123456789' },
|
||||
response: { group_id: 123456, user_id: 123456789, nickname: '昵称', card: '名片', role: 'member' },
|
||||
},
|
||||
GetGroupMemberList: {
|
||||
payload: { group_id: '123456' },
|
||||
response: [{ group_id: 123456, user_id: 123456789, nickname: '昵称', card: '名片', role: 'member' }],
|
||||
},
|
||||
GetGroupNotice: {
|
||||
payload: { group_id: '123456' },
|
||||
response: [{ notice_id: 'notice_123', sender_id: 123456, publish_time: 1710000000, message: { text: '公告内容', image: [] } }],
|
||||
},
|
||||
SendGroupMsg: {
|
||||
payload: { group_id: '123456', message: 'hello' },
|
||||
response: { message_id: 123456 },
|
||||
},
|
||||
SetEssenceMsg: {
|
||||
payload: { message_id: 123456 },
|
||||
response: {},
|
||||
},
|
||||
SetGroupAddRequest: {
|
||||
payload: { flag: 'flag_123', sub_type: 'add', approve: true },
|
||||
response: {},
|
||||
},
|
||||
SetGroupAdmin: {
|
||||
payload: { group_id: '123456', user_id: '123456789', enable: true },
|
||||
response: {},
|
||||
},
|
||||
SetGroupBan: {
|
||||
payload: { group_id: '123456', user_id: '123456789', duration: 1800 },
|
||||
response: {},
|
||||
},
|
||||
SetGroupCard: {
|
||||
payload: { group_id: '123456', user_id: '123456789', card: '新名片' },
|
||||
response: {},
|
||||
},
|
||||
SetGroupKick: {
|
||||
payload: { group_id: '123456', user_id: '123456789', reject_add_request: false },
|
||||
response: {},
|
||||
},
|
||||
SetGroupLeave: {
|
||||
payload: { group_id: '123456', is_dismiss: false },
|
||||
response: {},
|
||||
},
|
||||
SetGroupName: {
|
||||
payload: { group_id: '123456', group_name: '新群名' },
|
||||
response: {},
|
||||
},
|
||||
SetGroupWholeBan: {
|
||||
payload: { group_id: '123456', enable: true },
|
||||
response: {},
|
||||
},
|
||||
};
|
||||
33
packages/napcat-onebot/action/msg/examples.ts
Normal file
33
packages/napcat-onebot/action/msg/examples.ts
Normal file
@ -0,0 +1,33 @@
|
||||
export const MsgActionsExamples = {
|
||||
DeleteMsg: {
|
||||
payload: { message_id: 123456 },
|
||||
response: {},
|
||||
},
|
||||
GetMsg: {
|
||||
payload: { message_id: 123456 },
|
||||
response: {
|
||||
time: 1710000000,
|
||||
message_type: 'group',
|
||||
message_id: 123456,
|
||||
real_id: 123456,
|
||||
sender: { user_id: 123456789, nickname: '昵称' },
|
||||
message: 'hello',
|
||||
},
|
||||
},
|
||||
MarkMsgAsRead: {
|
||||
payload: { group_id: '123456' },
|
||||
response: {},
|
||||
},
|
||||
SendMsg: {
|
||||
payload: { message_type: 'group', group_id: '123456', message: 'hello' },
|
||||
response: { message_id: 123456 },
|
||||
},
|
||||
SendPrivateMsg: {
|
||||
payload: { user_id: '123456789', message: 'hello' },
|
||||
response: { message_id: 123456 },
|
||||
},
|
||||
SetMsgEmojiLike: {
|
||||
payload: { message_id: 123456, emoji_id: '12345' },
|
||||
response: {},
|
||||
},
|
||||
};
|
||||
@ -1,10 +1,10 @@
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { CanSend } from './CanSendRecord';
|
||||
import { ActionExamples } from '../examples';
|
||||
import { SystemActionsExamples } from './examples';
|
||||
|
||||
export default class CanSendImage extends CanSend {
|
||||
override actionName = ActionName.CanSendImage;
|
||||
override actionDescription = '检查是否可以发送图片';
|
||||
override payloadExample = ActionExamples.CanSendImage.payload;
|
||||
override returnExample = ActionExamples.CanSendImage.return;
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = SystemActionsExamples.CanSendImage.payload;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { SystemActionsExamples } from './examples';
|
||||
|
||||
export const CanSendReturnSchema = Type.Object({
|
||||
yes: Type.Boolean({ description: '是否可以发送' }),
|
||||
@ -25,6 +25,6 @@ export class CanSend extends OneBotAction<void, CanSendReturnType> {
|
||||
export default class CanSendRecord extends CanSend {
|
||||
override actionName = ActionName.CanSendRecord;
|
||||
override actionDescription = '检查是否可以发送语音';
|
||||
override payloadExample = ActionExamples.CanSendRecord.payload;
|
||||
override returnExample = ActionExamples.CanSendRecord.return;
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = SystemActionsExamples.CanSendRecord.payload;
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import { SystemActionsExamples } from './examples';
|
||||
|
||||
export const GetCSRFReturnSchema = Type.Object({
|
||||
token: Type.Number({ description: 'CSRF Token' }),
|
||||
@ -12,6 +13,9 @@ export class GetCSRF extends OneBotAction<void, GetCSRFReturnType> {
|
||||
override actionName = ActionName.GetCSRF;
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = GetCSRFReturnSchema;
|
||||
override actionDescription = '获取 CSRF Token';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = SystemActionsExamples.GetCSRF.payload;
|
||||
|
||||
async _handle () {
|
||||
const sKey = await this.core.apis.UserApi.getSKey();
|
||||
|
||||
42
packages/napcat-onebot/action/system/examples.ts
Normal file
42
packages/napcat-onebot/action/system/examples.ts
Normal file
@ -0,0 +1,42 @@
|
||||
export const SystemActionsExamples = {
|
||||
CanSendImage: {
|
||||
payload: {},
|
||||
response: { yes: true },
|
||||
},
|
||||
CanSendRecord: {
|
||||
payload: {},
|
||||
response: { yes: true },
|
||||
},
|
||||
CleanCache: {
|
||||
payload: {},
|
||||
response: {},
|
||||
},
|
||||
GetCredentials: {
|
||||
payload: {},
|
||||
response: { cookies: '...', csrf_token: 123456789 },
|
||||
},
|
||||
GetCSRF: {
|
||||
payload: {},
|
||||
response: { token: 123456789 },
|
||||
},
|
||||
GetLoginInfo: {
|
||||
payload: {},
|
||||
response: { user_id: 123456789, nickname: '机器人' },
|
||||
},
|
||||
GetStatus: {
|
||||
payload: {},
|
||||
response: { online: true, good: true },
|
||||
},
|
||||
GetSystemMsg: {
|
||||
payload: {},
|
||||
response: { invited_requests: [], join_requests: [] },
|
||||
},
|
||||
GetVersionInfo: {
|
||||
payload: {},
|
||||
response: { app_name: 'NapCatQQ', app_version: '1.0.0', protocol_version: 'v11' },
|
||||
},
|
||||
SetRestart: {
|
||||
payload: { delay: 0 },
|
||||
response: {},
|
||||
},
|
||||
};
|
||||
@ -2,6 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { NetworkAdapterConfig } from '@/napcat-onebot/config/config';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { UserActionsExamples } from './examples';
|
||||
|
||||
export const GetRecentContactPayloadSchema = Type.Object({
|
||||
count: Type.Union([Type.Number(), Type.String()], { default: 10, description: '获取的数量' }),
|
||||
@ -27,6 +28,9 @@ export default class GetRecentContact extends OneBotAction<GetRecentContactPaylo
|
||||
override actionName = ActionName.GetRecentContact;
|
||||
override payloadSchema = GetRecentContactPayloadSchema;
|
||||
override returnSchema = GetRecentContactReturnSchema;
|
||||
override actionDescription = '获取最近会话';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = UserActionsExamples.GetRecentContact.payload;
|
||||
|
||||
async _handle (payload: GetRecentContactPayload, _adapter: string, config: NetworkAdapterConfig): Promise<GetRecentContactReturn> {
|
||||
const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+payload.count);
|
||||
|
||||
38
packages/napcat-onebot/action/user/examples.ts
Normal file
38
packages/napcat-onebot/action/user/examples.ts
Normal file
@ -0,0 +1,38 @@
|
||||
export const UserActionsExamples = {
|
||||
GetCookies: {
|
||||
payload: { domain: 'qun.qq.com' },
|
||||
response: { cookies: 'p_skey=xxx; p_uin=o0123456789;' },
|
||||
},
|
||||
GetFriendList: {
|
||||
payload: {},
|
||||
response: [{ user_id: 123456789, nickname: '昵称', remark: '备注' }],
|
||||
},
|
||||
GetRecentContact: {
|
||||
payload: { count: 10 },
|
||||
response: [
|
||||
{
|
||||
lastestMsg: 'hello',
|
||||
peerUin: '123456789',
|
||||
remark: 'remark',
|
||||
msgTime: '1710000000',
|
||||
chatType: 1,
|
||||
msgId: '12345',
|
||||
sendNickName: 'nick',
|
||||
sendMemberName: 'card',
|
||||
peerName: 'name',
|
||||
},
|
||||
],
|
||||
},
|
||||
SendLike: {
|
||||
payload: { user_id: '123456789', times: 10 },
|
||||
response: {},
|
||||
},
|
||||
SetFriendAddRequest: {
|
||||
payload: { flag: 'flag_123', approve: true, remark: '好友' },
|
||||
response: {},
|
||||
},
|
||||
SetFriendRemark: {
|
||||
payload: { user_id: '123456789', remark: '新备注' },
|
||||
response: {},
|
||||
},
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user