mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-04 14:41:14 +00:00
Add action metadata to OneBot action classes
Added or updated actionSummary, actionTags, payloadExample, and returnExample properties for all OneBot action classes in the napcat-onebot package. This improves API documentation and discoverability by providing concise summaries, categorization tags, and usage examples for each action.
This commit is contained in:
parent
5b80a8576f
commit
60a9114495
@ -6,6 +6,10 @@ export class BotExit extends OneBotAction<void, void> {
|
||||
override actionName = ActionName.Exit;
|
||||
override payloadSchema = Type.Void();
|
||||
override returnSchema = Type.Void();
|
||||
override actionSummary = '退出登录';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle () {
|
||||
process.exit(0);
|
||||
|
||||
@ -19,8 +19,15 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
export class ClickInlineKeyboardButton extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.ClickInlineKeyboardButton;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
override returnSchema = ReturnSchema; override actionSummary = '点击内联键盘按钮';
|
||||
override actionTags = ['消息扩展'];
|
||||
override payloadExample = {
|
||||
message_id: 12345,
|
||||
button_id: 'btn_1'
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
async _handle (payload: PayloadType) {
|
||||
return await this.core.apis.MsgApi.clickInlineKeyboardButton({
|
||||
buttonId: payload.button_id,
|
||||
|
||||
@ -17,6 +17,16 @@ export class CreateCollection extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.CreateCollection;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '创建收藏';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = {
|
||||
rawData: '收藏内容',
|
||||
brief: '收藏标题'
|
||||
};
|
||||
override returnExample = {
|
||||
result: 0,
|
||||
errMsg: ''
|
||||
};
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
return await this.core.apis.CollectionApi.createCollection(
|
||||
|
||||
@ -16,6 +16,15 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class DelGroupAlbumMedia extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.DelGroupAlbumMedia;
|
||||
override actionSummary = '删除群相册媒体';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_code: 123456,
|
||||
media_id_list: ['media_id_1', 'media_id_2']
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -13,6 +13,16 @@ export type DoGroupAlbumCommentPayload = Static<typeof DoGroupAlbumCommentPayloa
|
||||
|
||||
export class DoGroupAlbumComment extends OneBotAction<DoGroupAlbumCommentPayload, any> {
|
||||
override actionName = ActionName.DoGroupAlbumComment;
|
||||
override actionSummary = '发表群相册评论';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_code: 123456,
|
||||
media_id: 'media_id_1',
|
||||
content: '很有意思'
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = DoGroupAlbumCommentPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '评论结果' });
|
||||
|
||||
|
||||
@ -16,6 +16,14 @@ export class FetchCustomFace extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.FetchCustomFace;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取自定义表情';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {
|
||||
count: 10
|
||||
};
|
||||
override returnExample = [
|
||||
'http://example.com/face1.png'
|
||||
];
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const ret = await this.core.apis.MsgApi.fetchFavEmojiList(+payload.count);
|
||||
|
||||
@ -30,6 +30,14 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class FetchEmojiLike extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.FetchEmojiLike;
|
||||
override actionSummary = '获取表情点赞详情';
|
||||
override actionTags = ['消息扩展'];
|
||||
override payloadExample = {
|
||||
message_id: 12345
|
||||
};
|
||||
override returnExample = {
|
||||
likes: [{ emoji_id: '123', count: 10 }]
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -2,8 +2,6 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
category: Type.String({ description: '分类ID' }),
|
||||
count: Type.String({ default: '1', description: '获取数量' }),
|
||||
@ -19,10 +17,18 @@ export class GetCollectionList extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GetCollectionList;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '获取收藏列表';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ActionExamples.GetCollectionList.payload;
|
||||
override returnExample = ActionExamples.GetCollectionList.return;
|
||||
override actionSummary = '获取收藏列表';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {
|
||||
category: '1',
|
||||
count: '10'
|
||||
};
|
||||
override returnExample = [
|
||||
{
|
||||
collection_id: '123',
|
||||
title: '收藏标题'
|
||||
}
|
||||
];
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
return await this.core.apis.CollectionApi.getAllCollection(+payload.category, +payload.count);
|
||||
|
||||
@ -26,6 +26,14 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class GetEmojiLikes extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GetEmojiLikes;
|
||||
override actionSummary = '获取消息表情点赞列表';
|
||||
override actionTags = ['消息扩展'];
|
||||
override payloadExample = {
|
||||
message_id: 12345
|
||||
};
|
||||
override returnExample = {
|
||||
likes: [{ emoji_id: '123', user_id: 654321 }]
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -20,6 +20,17 @@ export class GetFriendWithCategory extends OneBotAction<void, ReturnType> {
|
||||
override actionName = ActionName.GetFriendsWithCategory;
|
||||
override payloadSchema = Type.Void();
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取带分组的好友列表';
|
||||
override actionTags = ['用户扩展'];
|
||||
override payloadExample = {};
|
||||
override returnExample = [
|
||||
{
|
||||
categoryId: 1,
|
||||
categoryName: '我的好友',
|
||||
categoryMbCount: 1,
|
||||
buddyList: []
|
||||
}
|
||||
];
|
||||
|
||||
async _handle () {
|
||||
const categories = await this.core.apis.FriendApi.getBuddyV2ExWithCate();
|
||||
|
||||
@ -24,6 +24,22 @@ export default class GetGroupAddRequest extends OneBotAction<void, ReturnType> {
|
||||
override actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||
override payloadSchema = Type.Void();
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取群被忽略的加群请求';
|
||||
override actionTags = ['群组接口'];
|
||||
override payloadExample = {};
|
||||
override returnExample = [
|
||||
{
|
||||
request_id: 12345,
|
||||
invitor_uin: 123456789,
|
||||
invitor_nick: '邀请者',
|
||||
group_id: 123456789,
|
||||
message: '加群请求',
|
||||
group_name: '群名称',
|
||||
checked: false,
|
||||
actor: 0,
|
||||
requester_nick: '请求者'
|
||||
}
|
||||
];
|
||||
|
||||
async _handle (): Promise<ReturnType> {
|
||||
const NTQQUserApi = this.core.apis.UserApi;
|
||||
|
||||
@ -16,6 +16,17 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class GetGroupAlbumMediaList extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GetGroupAlbumMediaList;
|
||||
override actionSummary = '获取群相册媒体列表';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_code: 123456,
|
||||
album_id: 'album_id_1'
|
||||
};
|
||||
override returnExample = {
|
||||
media_list: [
|
||||
{ media_id: 'media_id_1', url: 'http://example.com/1.jpg' }
|
||||
]
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -13,6 +13,16 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class GetGroupInfoEx extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GetGroupInfoEx;
|
||||
override actionSummary = '获取群详细信息 (扩展)';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_id: 123456
|
||||
};
|
||||
override returnExample = {
|
||||
group_id: 123456,
|
||||
group_name: '测试群',
|
||||
member_count: 100
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -45,8 +45,14 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
export class GetMiniAppArk extends GetPacketStatusDepends<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GetMiniAppArk;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
override returnSchema = ReturnSchema; override actionSummary = '获取小程序 Ark';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {
|
||||
app_id: 'wx123456'
|
||||
};
|
||||
override returnExample = {
|
||||
ark: 'ark_content'
|
||||
};
|
||||
async _handle (payload: PayloadType) {
|
||||
let reqParam: MiniAppReqParams;
|
||||
const customParams: MiniAppReqCustomParams = {
|
||||
|
||||
@ -34,6 +34,31 @@ export class GetProfileLike extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GetProfileLike;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取资料点赞';
|
||||
override actionTags = ['用户扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789',
|
||||
start: 0,
|
||||
count: 10
|
||||
};
|
||||
override returnExample = {
|
||||
uid: 'u_123',
|
||||
time: '1734567890',
|
||||
favoriteInfo: {
|
||||
userInfos: [],
|
||||
total_count: 10,
|
||||
last_time: 1734567890,
|
||||
today_count: 5
|
||||
},
|
||||
voteInfo: {
|
||||
total_count: 100,
|
||||
new_count: 2,
|
||||
new_nearby_count: 0,
|
||||
last_visit_time: 1734567890,
|
||||
userInfos: []
|
||||
}
|
||||
};
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const isSelf = this.core.selfInfo.uin === payload.user_id || !payload.user_id;
|
||||
const userUid = isSelf || !payload.user_id ? this.core.selfInfo.uid : await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
|
||||
@ -15,6 +15,16 @@ type GetQunAlbumListReturn = Awaited<globalThis.ReturnType<NTQQWebApi['getAlbumL
|
||||
|
||||
export class GetQunAlbumList extends OneBotAction<PayloadType, GetQunAlbumListReturn> {
|
||||
override actionName = ActionName.GetQunAlbumList;
|
||||
override actionSummary = '获取群相册列表';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_code: 123456
|
||||
};
|
||||
override returnExample = {
|
||||
album_list: [
|
||||
{ album_id: 'album_id_1', album_name: '相册1' }
|
||||
]
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -2,8 +2,6 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
|
||||
import { ExtendsActionsExamples } from './examples';
|
||||
|
||||
const ReturnSchema = Type.Array(Type.Any(), { description: 'Rkey列表' });
|
||||
|
||||
type ReturnType = Static<typeof ReturnSchema>;
|
||||
@ -12,11 +10,15 @@ export class GetRkey extends GetPacketStatusDepends<void, ReturnType> {
|
||||
override actionName = ActionName.GetRkey;
|
||||
override payloadSchema = Type.Void();
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取Rkey';
|
||||
override actionDescription = '获取用于媒体资源的Rkey列表';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ExtendsActionsExamples.GetRkey.payload;
|
||||
override returnExample = ExtendsActionsExamples.GetRkey.response;
|
||||
override actionSummary = '获取 RKey';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {};
|
||||
override returnExample = [
|
||||
{
|
||||
"key": "rkey_value",
|
||||
"expired": 1734567890
|
||||
}
|
||||
];
|
||||
|
||||
async _handle () {
|
||||
return await this.core.apis.PacketApi.pkt.operation.FetchRkey();
|
||||
|
||||
@ -8,6 +8,12 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class GetRobotUinRange extends OneBotAction<void, ReturnType> {
|
||||
override actionName = ActionName.GetRobotUinRange;
|
||||
override actionSummary = '获取机器人 UIN 范围';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {};
|
||||
override returnExample = [
|
||||
{ minUin: '12345678', maxUin: '87654321' }
|
||||
];
|
||||
override payloadSchema = Type.Void();
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -21,6 +21,18 @@ export class GetUnidirectionalFriendList extends OneBotAction<void, ReturnType>
|
||||
override actionName = ActionName.GetUnidirectionalFriendList;
|
||||
override payloadSchema = Type.Void();
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取单向好友列表';
|
||||
override actionTags = ['用户扩展'];
|
||||
override payloadExample = {};
|
||||
override returnExample = [
|
||||
{
|
||||
uin: 123456789,
|
||||
uid: 'u_123',
|
||||
nick_name: '单向好友',
|
||||
age: 20,
|
||||
source: '来源'
|
||||
}
|
||||
];
|
||||
|
||||
async pack_data (data: string): Promise<Uint8Array> {
|
||||
return ProtoBuf(class extends ProtoBufBase {
|
||||
|
||||
@ -19,6 +19,15 @@ export class GetUserStatus extends GetPacketStatusDepends<PayloadType, ReturnTyp
|
||||
override actionName = ActionName.GetUserStatus;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取用户在线状态';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789'
|
||||
};
|
||||
override returnExample = {
|
||||
status: 10,
|
||||
ext_status: 0
|
||||
};
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const res = await this.core.apis.PacketApi.pkt.operation.GetStrangerStatus(+payload.user_id);
|
||||
|
||||
@ -20,6 +20,16 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class MoveGroupFile extends GetPacketStatusDepends<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.MoveGroupFile;
|
||||
override actionSummary = '移动群文件';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
group_id: 123456,
|
||||
file_id: '/file_id',
|
||||
parent_id: '/target_folder_id'
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -20,6 +20,16 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class RenameGroupFile extends GetPacketStatusDepends<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.RenameGroupFile;
|
||||
override actionSummary = '重命名群文件';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
group_id: 123456,
|
||||
file_id: '/file_id',
|
||||
name: 'new_name.jpg'
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -19,6 +19,15 @@ export class SendPacket extends GetPacketStatusDepends<PayloadType, ReturnType>
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionName = ActionName.SendPacket;
|
||||
override actionSummary = '发送原始数据包';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {
|
||||
cmd: 'Example.Cmd',
|
||||
data: '123456',
|
||||
rsp: true
|
||||
};
|
||||
override returnExample = '123456';
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const rsp = typeof payload.rsp === 'boolean' ? payload.rsp : payload.rsp === 'true';
|
||||
const packetData = Buffer.from(payload.data, 'hex') as unknown as PacketBuf;
|
||||
|
||||
@ -17,8 +17,15 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
export class SetDiyOnlineStatus extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetDiyOnlineStatus;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
override returnSchema = ReturnSchema; override actionSummary = '设置自定义在线状态';
|
||||
override actionDescription = '设置自定义在线状态';
|
||||
override actionTags = ['用户扩展'];
|
||||
override payloadExample = {
|
||||
status: 11
|
||||
};
|
||||
override returnExample = {
|
||||
result: 0
|
||||
};
|
||||
async _handle (payload: PayloadType) {
|
||||
const ret = await this.core.apis.UserApi.setDiySelfOnlineStatus(
|
||||
payload.face_id.toString(),
|
||||
|
||||
@ -17,6 +17,15 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export default class SetGroupAddOption extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetGroupAddOption;
|
||||
override actionSummary = '设置群加群选项';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_id: 123456,
|
||||
option: 1
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
|
||||
@ -18,6 +18,15 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class SetGroupAlbumMediaLike extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetGroupAlbumMediaLike;
|
||||
override actionSummary = '点赞群相册媒体';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_code: 123456,
|
||||
media_id: 'media_id_1'
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -2,8 +2,6 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
remark: Type.String({ description: '备注' }),
|
||||
@ -19,9 +17,14 @@ export default class SetGroupRemark extends OneBotAction<PayloadType, ReturnType
|
||||
override actionName = ActionName.SetGroupRemark;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '设置群备注';
|
||||
override actionDescription = '设置群备注';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ActionExamples.SetGroupRemark.payload;
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_id: '123456',
|
||||
remark: '测试群备注'
|
||||
};
|
||||
override returnExample = {};
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const ret = await this.core.apis.GroupApi.setGroupRemark(payload.group_id, payload.remark);
|
||||
|
||||
@ -16,6 +16,15 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export default class SetGroupRobotAddOption extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetGroupRobotAddOption;
|
||||
override actionSummary = '设置群机器人加群选项';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_id: 123456,
|
||||
option: 1
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
|
||||
@ -16,6 +16,15 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export default class SetGroupSearch extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetGroupSearch;
|
||||
override actionSummary = '设置群搜索选项';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_id: 123456,
|
||||
is_searchable: true
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
|
||||
@ -15,6 +15,12 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
class SetGroupSignBase extends GetPacketStatusDepends<PayloadType, ReturnType> {
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '设置群签名';
|
||||
override actionTags = ['群扩展'];
|
||||
override payloadExample = {
|
||||
group_id: '123456789'
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
return await this.core.apis.PacketApi.pkt.operation.GroupSign(+payload.group_id);
|
||||
|
||||
@ -18,6 +18,14 @@ export class SetInputStatus extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetInputStatus;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '设置输入状态';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789',
|
||||
event_type: 1
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
if (!uid) throw new Error('uid is empty');
|
||||
|
||||
@ -2,8 +2,6 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
status: Type.Union([Type.Number(), Type.String()], { description: '在线状态' }),
|
||||
ext_status: Type.Union([Type.Number(), Type.String()], { description: '扩展状态' }),
|
||||
@ -20,9 +18,15 @@ export class SetOnlineStatus extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetOnlineStatus;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '设置在线状态';
|
||||
override actionDescription = '设置在线状态';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ActionExamples.SetOnlineStatus.payload;
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {
|
||||
status: 11,
|
||||
ext_status: 0,
|
||||
battery_status: 100
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const ret = await this.core.apis.UserApi.setSelfOnlineStatus(
|
||||
|
||||
@ -18,6 +18,16 @@ export class SharePeerBase extends OneBotAction<PayloadType, ReturnType> {
|
||||
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '分享用户 (Ark)';
|
||||
override actionDescription = '获取用户推荐的 Ark 内容';
|
||||
override actionTags = ['消息扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456',
|
||||
phone_number: ''
|
||||
};
|
||||
override returnExample = {
|
||||
ark: '...'
|
||||
};
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
if (payload.group_id) {
|
||||
@ -44,6 +54,13 @@ type ReturnTypeGroupEx = Static<typeof ReturnSchemaGroupEx>;
|
||||
export class ShareGroupExBase extends OneBotAction<PayloadTypeGroupEx, ReturnTypeGroupEx> {
|
||||
override payloadSchema = PayloadSchemaGroupEx;
|
||||
override returnSchema = ReturnSchemaGroupEx;
|
||||
override actionSummary = '分享群 (Ark)';
|
||||
override actionDescription = '获取群分享的 Ark 内容';
|
||||
override actionTags = ['消息扩展'];
|
||||
override payloadExample = {
|
||||
group_id: '123456'
|
||||
};
|
||||
override returnExample = '{"app": "com.tencent.structmsg", ...}';
|
||||
|
||||
async _handle (payload: PayloadTypeGroupEx) {
|
||||
return await this.core.apis.GroupApi.getArkJsonGroupShare(payload.group_id.toString());
|
||||
|
||||
@ -18,6 +18,16 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class TransGroupFile extends GetPacketStatusDepends<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.TransGroupFile;
|
||||
override actionSummary = '传输群文件';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
group_id: 123456,
|
||||
file_id: '/file_id',
|
||||
target_group_id: 654321
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -20,6 +20,16 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class UploadImageToQunAlbum extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.UploadImageToQunAlbum;
|
||||
override actionSummary = '上传图片到群相册';
|
||||
override actionTags = ['群组扩展'];
|
||||
override payloadExample = {
|
||||
group_code: 123456,
|
||||
album_id: 'album_id_1',
|
||||
file: '/path/to/image.jpg'
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -22,6 +22,15 @@ export class CreateFlashTask extends OneBotAction<CreateFlashTaskPayload, any> {
|
||||
override actionName = ActionName.CreateFlashTask;
|
||||
override payloadSchema = CreateFlashTaskPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '任务创建结果' });
|
||||
override actionSummary = '创建闪照任务';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
files: 'C:\\test.jpg',
|
||||
name: 'test_task'
|
||||
};
|
||||
override returnExample = {
|
||||
task_id: 'task_123'
|
||||
};
|
||||
|
||||
async _handle (payload: CreateFlashTaskPayload) {
|
||||
const fileList = Array.isArray(payload.files) ? payload.files : [payload.files];
|
||||
|
||||
@ -12,6 +12,12 @@ export class DownloadFileset extends OneBotAction<DownloadFilesetPayload, any> {
|
||||
override actionName = ActionName.DownloadFileset;
|
||||
override payloadSchema = DownloadFilesetPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '下载结果' });
|
||||
override actionSummary = '下载文件集';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
fileset_id: 'set_123'
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: DownloadFilesetPayload) {
|
||||
// 默认路径 / fileset_id /为下载路径
|
||||
|
||||
@ -12,6 +12,14 @@ export class GetFilesetId extends OneBotAction<GetFilesetIdPayload, any> {
|
||||
override actionName = ActionName.GetFilesetId;
|
||||
override payloadSchema = GetFilesetIdPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '文件集 ID' });
|
||||
override actionSummary = '获取文件集 ID';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
share_code: '123456'
|
||||
};
|
||||
override returnExample = {
|
||||
fileset_id: 'set_123'
|
||||
};
|
||||
|
||||
async _handle (payload: GetFilesetIdPayload) {
|
||||
// 适配share_link 防止被传 Link无法解析
|
||||
|
||||
@ -12,6 +12,15 @@ export class GetFilesetInfo extends OneBotAction<GetFilesetInfoPayload, any> {
|
||||
override actionName = ActionName.GetFilesetInfo;
|
||||
override payloadSchema = GetFilesetInfoPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '文件集信息' });
|
||||
override actionSummary = '获取文件集信息';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
fileset_id: 'set_123'
|
||||
};
|
||||
override returnExample = {
|
||||
fileset_id: 'set_123',
|
||||
file_list: []
|
||||
};
|
||||
|
||||
async _handle (payload: GetFilesetInfoPayload) {
|
||||
return await this.core.apis.FlashApi.getFileSetIndoBySetId(payload.fileset_id);
|
||||
|
||||
@ -12,6 +12,17 @@ export class GetFlashFileList extends OneBotAction<GetFlashFileListPayload, any>
|
||||
override actionName = ActionName.GetFlashFileList;
|
||||
override payloadSchema = GetFlashFileListPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '文件列表' });
|
||||
override actionSummary = '获取闪照文件列表';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
fileset_id: 'set_123'
|
||||
};
|
||||
override returnExample = [
|
||||
{
|
||||
file_name: 'test.jpg',
|
||||
size: 1024
|
||||
}
|
||||
];
|
||||
|
||||
async _handle (payload: GetFlashFileListPayload) {
|
||||
return await this.core.apis.FlashApi.getFileListBySetId(payload.fileset_id);
|
||||
|
||||
@ -14,6 +14,14 @@ export class GetFlashFileUrl extends OneBotAction<GetFlashFileUrlPayload, any> {
|
||||
override actionName = ActionName.GetFlashFileUrl;
|
||||
override payloadSchema = GetFlashFileUrlPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '文件下载链接' });
|
||||
override actionSummary = '获取闪照文件链接';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
fileset_id: 'set_123'
|
||||
};
|
||||
override returnExample = {
|
||||
url: 'http://example.com/flash.jpg'
|
||||
};
|
||||
|
||||
async _handle (payload: GetFlashFileUrlPayload) {
|
||||
// 文件的索引依旧从0开始
|
||||
|
||||
@ -12,6 +12,12 @@ export class GetShareLink extends OneBotAction<GetShareLinkPayload, any> {
|
||||
override actionName = ActionName.GetShareLink;
|
||||
override payloadSchema = GetShareLinkPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '分享链接' });
|
||||
override actionSummary = '获取文件分享链接';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
fileset_id: 'set_123'
|
||||
};
|
||||
override returnExample = 'http://example.com/share';
|
||||
|
||||
async _handle (payload: GetShareLinkPayload) {
|
||||
return await this.core.apis.FlashApi.getShareLinkBySetId(payload.fileset_id);
|
||||
|
||||
@ -15,6 +15,15 @@ export class SendFlashMsg extends OneBotAction<SendFlashMsgPayload, any> {
|
||||
override actionName = ActionName.SendFlashMsg;
|
||||
override payloadSchema = SendFlashMsgPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '发送结果' });
|
||||
override actionSummary = '发送闪照消息';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
fileset_id: 'set_123',
|
||||
user_id: '123456789'
|
||||
};
|
||||
override returnExample = {
|
||||
message_id: 123456
|
||||
};
|
||||
|
||||
async _handle (payload: SendFlashMsgPayload) {
|
||||
let peer: Peer;
|
||||
|
||||
@ -14,6 +14,13 @@ export class CancelOnlineFile extends OneBotAction<CancelOnlineFilePayload, any>
|
||||
override actionName = ActionName.CancelOnlineFile;
|
||||
override payloadSchema = CancelOnlineFilePayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '取消结果' });
|
||||
override actionSummary = '取消在线文件';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789',
|
||||
msg_id: '123'
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: CancelOnlineFilePayload) {
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
|
||||
@ -13,6 +13,12 @@ export class GetOnlineFileMessages extends OneBotAction<GetOnlineFileMessagesPay
|
||||
override actionName = ActionName.GetOnlineFileMessages;
|
||||
override payloadSchema = GetOnlineFileMessagesPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '在线文件消息列表' });
|
||||
override actionSummary = '获取在线文件消息';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789'
|
||||
};
|
||||
override returnExample = [];
|
||||
|
||||
async _handle (payload: GetOnlineFileMessagesPayload) {
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
|
||||
@ -15,6 +15,14 @@ export class ReceiveOnlineFile extends OneBotAction<ReceiveOnlineFilePayload, an
|
||||
override actionName = ActionName.ReceiveOnlineFile;
|
||||
override payloadSchema = ReceiveOnlineFilePayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '接收结果' });
|
||||
override actionSummary = '接收在线文件';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789',
|
||||
msg_id: '123',
|
||||
save_path: 'C:\\save'
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: ReceiveOnlineFilePayload) {
|
||||
// 默认下载路径
|
||||
|
||||
@ -15,6 +15,13 @@ export class RefuseOnlineFile extends OneBotAction<RefuseOnlineFilePayload, any>
|
||||
override actionName = ActionName.RefuseOnlineFile;
|
||||
override payloadSchema = RefuseOnlineFilePayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '拒绝结果' });
|
||||
override actionSummary = '拒绝在线文件';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789',
|
||||
msg_id: '123'
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: RefuseOnlineFilePayload) {
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
|
||||
@ -15,6 +15,14 @@ export class SendOnlineFile extends OneBotAction<SendOnlineFilePayload, any> {
|
||||
override actionName = ActionName.SendOnlineFile;
|
||||
override payloadSchema = SendOnlineFilePayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '发送结果' });
|
||||
override actionSummary = '发送在线文件';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789',
|
||||
file_path: 'C:\\path\\to\\file.txt',
|
||||
file_name: 'test.txt'
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: SendOnlineFilePayload) {
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
|
||||
@ -15,6 +15,13 @@ export class SendOnlineFolder extends OneBotAction<SendOnlineFolderPayload, any>
|
||||
override actionName = ActionName.SendOnlineFolder;
|
||||
override payloadSchema = SendOnlineFolderPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '发送结果' });
|
||||
override actionSummary = '发送在线文件夹';
|
||||
override actionTags = ['文件扩展'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789',
|
||||
folder_path: 'C:\\path\\to\\folder'
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: SendOnlineFolderPayload) {
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
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: '群号' }),
|
||||
@ -27,7 +26,14 @@ export class CreateGroupFileFolder extends OneBotAction<PayloadType, ReturnType>
|
||||
override actionSummary = '创建群文件目录';
|
||||
override actionDescription = '在群文件系统中创建新的文件夹';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.CreateGroupFileFolder.payload;
|
||||
override payloadExample = {
|
||||
group_id: '123456789',
|
||||
folder_name: '新建文件夹'
|
||||
};
|
||||
override returnExample = {
|
||||
result: {},
|
||||
groupItem: {}
|
||||
};
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const folderName = payload.folder_name || payload.name;
|
||||
|
||||
@ -2,8 +2,6 @@ import { OB11MessageMixType } from '@/napcat-onebot/types';
|
||||
import { ContextMode, normalize, ReturnDataType, SendMsgBase, SendMsgPayload } from '@/napcat-onebot/action/msg/SendMsg';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
|
||||
import { GoCQHTTPActionsExamples } from './examples';
|
||||
|
||||
// 未验证
|
||||
type GoCQHTTPSendForwardMsgPayload = SendMsgPayload & { messages?: OB11MessageMixType; };
|
||||
|
||||
@ -18,8 +16,13 @@ export class GoCQHTTPSendForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||
override actionSummary = '发送合并转发消息';
|
||||
override actionDescription = '发送合并转发消息';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = GoCQHTTPActionsExamples.SendForwardMsg.payload;
|
||||
override returnExample = GoCQHTTPActionsExamples.SendForwardMsg.response;
|
||||
override payloadExample = {
|
||||
group_id: '123456789',
|
||||
messages: []
|
||||
};
|
||||
override returnExample = {
|
||||
message_id: 123456
|
||||
};
|
||||
|
||||
protected override async check (payload: GoCQHTTPSendForwardMsgPayload) {
|
||||
if (payload.messages) payload.message = normalize(payload.messages);
|
||||
@ -28,6 +31,15 @@ export class GoCQHTTPSendForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||
}
|
||||
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||
override actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
|
||||
override actionSummary = '发送私聊合并转发消息';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = {
|
||||
user_id: '123456789',
|
||||
messages: []
|
||||
};
|
||||
override returnExample = {
|
||||
message_id: 123456
|
||||
};
|
||||
override async _handle (payload: GoCQHTTPSendForwardMsgPayload): Promise<ReturnDataType> {
|
||||
return this.base_handle(payload, ContextMode.Private);
|
||||
}
|
||||
@ -35,6 +47,15 @@ export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||
|
||||
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||
override actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||
override actionSummary = '发送群合并转发消息';
|
||||
override actionTags = ['Go-CQHTTP'];
|
||||
override payloadExample = {
|
||||
group_id: '123456789',
|
||||
messages: []
|
||||
};
|
||||
override returnExample = {
|
||||
message_id: 123456
|
||||
};
|
||||
override async _handle (payload: GoCQHTTPSendForwardMsgPayload): Promise<ReturnDataType> {
|
||||
return this.base_handle(payload, ContextMode.Group);
|
||||
}
|
||||
|
||||
@ -19,9 +19,15 @@ export class GetAiRecord extends GetPacketStatusDepends<PayloadType, ReturnType>
|
||||
override actionName = ActionName.GetAiRecord;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取AI语音';
|
||||
override actionDescription = '通过AI语音引擎获取指定文本的语音URL';
|
||||
override actionTags = ['群组接口'];
|
||||
override actionSummary = '获取 AI 语音';
|
||||
override actionDescription = '通过 AI 语音引擎获取指定文本的语音 URL';
|
||||
override actionTags = ['AI 扩展'];
|
||||
override payloadExample = {
|
||||
character: 'ai_char_1',
|
||||
group_id: '123456',
|
||||
text: '你好'
|
||||
};
|
||||
override returnExample = 'http://example.com/ai_voice.silk';
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const rawRsp = await this.core.apis.PacketApi.pkt.operation.GetAiVoice(+payload.group_id, payload.character, payload.text, AIVoiceChatType.Sound);
|
||||
|
||||
@ -22,6 +22,12 @@ export class GetGroupIgnoredNotifies extends OneBotAction<PayloadType, ReturnTyp
|
||||
override actionSummary = '获取群忽略通知';
|
||||
override actionDescription = '获取被忽略的入群申请和邀请通知';
|
||||
override actionTags = ['群组接口'];
|
||||
override payloadExample = {};
|
||||
override returnExample = {
|
||||
invited_requests: [],
|
||||
InvitedRequest: [],
|
||||
join_requests: []
|
||||
};
|
||||
|
||||
async _handle (): Promise<ReturnType> {
|
||||
const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, 50);
|
||||
|
||||
@ -17,8 +17,17 @@ export class GetGroupShutList extends OneBotAction<PayloadType, ReturnType> {
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取群禁言列表';
|
||||
override actionDescription = '获取指定群聊中被禁言的成员列表';
|
||||
override actionTags = ['群组接口'];
|
||||
override payloadExample = {
|
||||
group_id: '123456789'
|
||||
};
|
||||
override returnExample = [
|
||||
{
|
||||
user_id: 123456789,
|
||||
nickname: '禁言用户',
|
||||
shut_up_time: 1734567890
|
||||
}
|
||||
];
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
return await this.core.apis.GroupApi.getGroupShutUpMemberList(payload.group_id.toString());
|
||||
|
||||
@ -21,9 +21,15 @@ export class SendGroupAiRecord extends GetPacketStatusDepends<PayloadType, Retur
|
||||
override actionName = ActionName.SendGroupAiRecord;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '发送群AI语音';
|
||||
override actionDescription = '在群聊中发送由AI引擎生成的语音';
|
||||
override actionTags = ['群组接口'];
|
||||
override actionSummary = '发送群 AI 语音';
|
||||
override actionDescription = '发送 AI 生成的语音到指定群聊';
|
||||
override actionTags = ['AI 扩展'];
|
||||
override payloadExample = {
|
||||
character: 'ai_char_1',
|
||||
group_id: '123456',
|
||||
text: '你好'
|
||||
};
|
||||
override returnExample = {};
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
await this.core.apis.PacketApi.pkt.operation.GetAiVoice(+payload.group_id, payload.character, payload.text, AIVoiceChatType.Sound);
|
||||
|
||||
@ -3,8 +3,6 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { MessageUnique } from 'napcat-common/src/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()], { description: '消息ID' }),
|
||||
});
|
||||
@ -22,7 +20,10 @@ class DeleteMsg extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionSummary = '撤回消息';
|
||||
override actionDescription = '撤回已发送的消息';
|
||||
override actionTags = ['消息接口'];
|
||||
override payloadExample = ActionExamples.DeleteMsg.payload;
|
||||
override payloadExample = {
|
||||
message_id: 12345
|
||||
};
|
||||
override returnExample = {};
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
|
||||
|
||||
@ -4,8 +4,6 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { MessageUnique } from 'napcat-common/src/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()], { description: '消息ID' }),
|
||||
group_id: Type.Optional(Type.String({ description: '目标群号' })),
|
||||
@ -19,9 +17,14 @@ const ReturnSchema = Type.Null({ description: '操作结果' });
|
||||
type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
class ForwardSingleMsg extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionSummary = '转发单条消息';
|
||||
override actionDescription = '转发单条消息';
|
||||
override actionTags = ['消息接口'];
|
||||
override payloadExample = ActionExamples.ForwardSingleMsg.payload;
|
||||
override payloadExample = {
|
||||
message_id: 12345,
|
||||
group_id: '123456'
|
||||
};
|
||||
override returnExample = {};
|
||||
|
||||
protected async getTargetPeer (payload: PayloadType): Promise<Peer> {
|
||||
if (payload.user_id) {
|
||||
|
||||
@ -4,8 +4,6 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { MessageUnique } from 'napcat-common/src/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
user_id: Type.Optional(Type.Union([Type.String(), Type.Number()], { description: '用户QQ' })),
|
||||
group_id: Type.Optional(Type.Union([Type.String(), Type.Number()], { description: '群号' })),
|
||||
@ -22,7 +20,10 @@ class MarkMsgAsRead extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionSummary = '标记消息已读';
|
||||
override actionDescription = '标记指定渠道的消息为已读';
|
||||
override actionTags = ['消息接口'];
|
||||
override payloadExample = ActionExamples.MarkMsgAsRead.payload;
|
||||
override payloadExample = {
|
||||
message_id: 12345
|
||||
};
|
||||
override returnExample = {};
|
||||
|
||||
async getPeer (payload: PayloadType): Promise<Peer> {
|
||||
if (payload.message_id) {
|
||||
@ -82,6 +83,10 @@ export class GoCQHTTPMarkMsgAsRead extends MarkMsgAsRead {
|
||||
|
||||
export class MarkAllMsgAsRead extends OneBotAction<void, null> {
|
||||
override actionName = ActionName._MarkAllMsgAsRead;
|
||||
override actionSummary = '标记所有消息已读';
|
||||
override actionTags = ['消息接口'];
|
||||
override payloadExample = {};
|
||||
override returnExample = {};
|
||||
|
||||
async _handle (): Promise<null> {
|
||||
await this.core.apis.MsgApi.markAllMsgAsRead();
|
||||
|
||||
@ -1,15 +1,19 @@
|
||||
import { ContextMode, ReturnDataType, SendMsgBase, SendMsgPayload } from './SendMsg';
|
||||
import { ActionName, BaseCheckResult } from '@/napcat-onebot/action/router';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
// 未检测参数
|
||||
class SendPrivateMsg extends SendMsgBase {
|
||||
override actionName = ActionName.SendPrivateMsg;
|
||||
override actionSummary = '发送私聊消息';
|
||||
override actionDescription = '发送私聊消息';
|
||||
override actionTags = ['消息接口'];
|
||||
override payloadExample = ActionExamples.SendPrivateMsg.payload;
|
||||
override returnExample = ActionExamples.SendPrivateMsg.return;
|
||||
override payloadExample = {
|
||||
user_id: '123456789',
|
||||
message: 'hello'
|
||||
};
|
||||
override returnExample = {
|
||||
message_id: 123456
|
||||
};
|
||||
|
||||
protected override async check (payload: SendMsgPayload): Promise<BaseCheckResult> {
|
||||
payload.message_type = 'private';
|
||||
|
||||
@ -17,6 +17,16 @@ type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export class SetMsgEmojiLike extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetMsgEmojiLike;
|
||||
override actionSummary = '设置消息表情点赞';
|
||||
override actionTags = ['消息扩展'];
|
||||
override payloadExample = {
|
||||
message_id: 12345,
|
||||
emoji_id: '123',
|
||||
set: true
|
||||
};
|
||||
override returnExample = {
|
||||
result: true
|
||||
};
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { NewActionsExamples } from './examples';
|
||||
|
||||
export const SetDoubtFriendsAddRequestPayloadSchema = Type.Object({
|
||||
flag: Type.String({ description: '请求 flag' }),
|
||||
@ -19,7 +18,11 @@ export class SetDoubtFriendsAddRequest extends OneBotAction<SetDoubtFriendsAddRe
|
||||
override actionSummary = '处理可疑好友申请';
|
||||
override actionDescription = '同意或拒绝系统的可疑好友申请';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = NewActionsExamples.SetDoubtFriendsAddRequest.payload;
|
||||
override payloadExample = {
|
||||
flag: '12345',
|
||||
approve: true
|
||||
};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle (payload: SetDoubtFriendsAddRequestPayload) {
|
||||
return await this.core.apis.FriendApi.handleDoubtFriendRequest(payload.flag);
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName, BaseCheckResult } from '@/napcat-onebot/action/router';
|
||||
import { Type } from '@sinclair/typebox';
|
||||
import { PacketActionsExamples } from './examples';
|
||||
|
||||
export abstract class GetPacketStatusDepends<PT, RT> extends OneBotAction<PT, RT> {
|
||||
protected override async check (payload: PT): Promise<BaseCheckResult> {
|
||||
@ -23,8 +22,8 @@ export class GetPacketStatus extends GetPacketStatusDepends<void, void> {
|
||||
override actionSummary = '获取Packet状态';
|
||||
override actionDescription = '获取底层Packet服务的运行状态';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = PacketActionsExamples.GetPacketStatus.payload;
|
||||
override returnExample = PacketActionsExamples.GetPacketStatus.response;
|
||||
override payloadExample = {};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle () {
|
||||
|
||||
|
||||
@ -15,6 +15,17 @@ export class GetRkeyEx extends GetPacketStatusDepends<void, GetRkeyExReturn> {
|
||||
override actionName = ActionName.GetRkeyEx;
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = GetRkeyExReturnSchema;
|
||||
override actionSummary = '获取扩展 RKey';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {};
|
||||
override returnExample = [
|
||||
{
|
||||
type: 'private',
|
||||
rkey: 'rkey_123',
|
||||
created_at: 1734567890,
|
||||
ttl: 3600
|
||||
}
|
||||
];
|
||||
|
||||
async _handle () {
|
||||
const rkeys = await this.core.apis.PacketApi.pkt.operation.FetchRkey();
|
||||
|
||||
@ -13,6 +13,12 @@ export type GetRkeyServerReturn = Static<typeof GetRkeyServerReturnSchema>;
|
||||
|
||||
export class GetRkeyServer extends GetPacketStatusDepends<void, GetRkeyServerReturn> {
|
||||
override actionName = ActionName.GetRkeyServer;
|
||||
override actionSummary = '获取 RKey 服务器';
|
||||
override actionTags = ['系统扩展'];
|
||||
override payloadExample = {};
|
||||
override returnExample = {
|
||||
server: 'http://rkey-server.com'
|
||||
};
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = GetRkeyServerReturnSchema;
|
||||
|
||||
|
||||
@ -6,6 +6,12 @@ import { Type } from '@sinclair/typebox';
|
||||
|
||||
export class CleanStreamTempFile extends OneBotAction<void, void> {
|
||||
override actionName = ActionName.CleanStreamTempFile;
|
||||
override actionSummary = '清理流式传输临时文件';
|
||||
override actionTags = ['流式传输扩展'];
|
||||
override payloadExample = {};
|
||||
override returnExample = {
|
||||
message: 'success'
|
||||
};
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = Type.Null();
|
||||
|
||||
|
||||
@ -17,6 +17,14 @@ export type DownloadFileImageStreamPayload = Static<typeof DownloadFileImageStre
|
||||
|
||||
export class DownloadFileImageStream extends BaseDownloadStream<DownloadFileImageStreamPayload, DownloadResult> {
|
||||
override actionName = ActionName.DownloadFileImageStream;
|
||||
override actionSummary = '下载图片文件流';
|
||||
override actionTags = ['流式传输扩展'];
|
||||
override payloadExample = {
|
||||
file: 'image_file_id'
|
||||
};
|
||||
override returnExample = {
|
||||
file: 'temp_image_path'
|
||||
};
|
||||
override payloadSchema = DownloadFileImageStreamPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '下载结果 (流式)' });
|
||||
override useStream = true;
|
||||
|
||||
@ -20,6 +20,14 @@ export type DownloadFileRecordStreamPayload = Static<typeof DownloadFileRecordSt
|
||||
|
||||
export class DownloadFileRecordStream extends BaseDownloadStream<DownloadFileRecordStreamPayload, DownloadResult> {
|
||||
override actionName = ActionName.DownloadFileRecordStream;
|
||||
override actionSummary = '下载语音文件流';
|
||||
override actionTags = ['流式传输扩展'];
|
||||
override payloadExample = {
|
||||
file: 'record_file_id'
|
||||
};
|
||||
override returnExample = {
|
||||
file: 'temp_record_path'
|
||||
};
|
||||
override payloadSchema = DownloadFileRecordStreamPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '下载结果 (流式)' });
|
||||
override useStream = true;
|
||||
|
||||
@ -20,6 +20,15 @@ export class DownloadFileStream extends BaseDownloadStream<DownloadFileStreamPay
|
||||
override actionSummary = '下载文件流';
|
||||
override actionDescription = '以流式方式从网络或本地下载文件';
|
||||
override actionTags = ['流式接口'];
|
||||
override payloadExample = {
|
||||
file: 'http://example.com/file.png'
|
||||
};
|
||||
override returnExample = {
|
||||
type: 'stream',
|
||||
data_type: 'file_info',
|
||||
file_name: 'file.png',
|
||||
file_size: 1024
|
||||
};
|
||||
override useStream = true;
|
||||
|
||||
async _handle (payload: DownloadFileStreamPayload, _adaptername: string, _config: NetworkAdapterConfig, req: OneBotRequestToolkit): Promise<StreamPacket<DownloadResult>> {
|
||||
|
||||
@ -12,6 +12,14 @@ export type TestDownloadStreamPayload = Static<typeof TestDownloadStreamPayloadS
|
||||
|
||||
export class TestDownloadStream extends OneBotAction<TestDownloadStreamPayload, StreamPacket<{ data: string; }>> {
|
||||
override actionName = ActionName.TestDownloadStream;
|
||||
override actionSummary = '测试下载流';
|
||||
override actionTags = ['流式传输扩展'];
|
||||
override payloadExample = {
|
||||
url: 'http://example.com/file'
|
||||
};
|
||||
override returnExample = {
|
||||
success: true
|
||||
};
|
||||
override payloadSchema = TestDownloadStreamPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '测试流数据' });
|
||||
override useStream = true;
|
||||
|
||||
@ -73,6 +73,20 @@ export class UploadFileStream extends OneBotAction<UploadFileStreamPayload, Stre
|
||||
override actionSummary = '上传文件流';
|
||||
override actionDescription = '以流式方式上传文件数据到机器人';
|
||||
override actionTags = ['流式接口'];
|
||||
override payloadExample = {
|
||||
stream_id: 'uuid-1234-5678',
|
||||
chunk_data: 'SGVsbG8gV29ybGQ=',
|
||||
chunk_index: 0,
|
||||
total_chunks: 1,
|
||||
file_size: 11
|
||||
};
|
||||
override returnExample = {
|
||||
type: 'stream',
|
||||
stream_id: 'uuid-1234-5678',
|
||||
status: 'chunk_received',
|
||||
received_chunks: 1,
|
||||
total_chunks: 1
|
||||
};
|
||||
override useStream = true;
|
||||
|
||||
private static streams = new Map<string, StreamState>();
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { CanSend } from './CanSendRecord';
|
||||
import { SystemActionsExamples } from './examples';
|
||||
|
||||
export default class CanSendImage extends CanSend {
|
||||
override actionName = ActionName.CanSendImage;
|
||||
override actionSummary = '是否可以发送图片';
|
||||
override actionDescription = '检查是否可以发送图片';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = SystemActionsExamples.CanSendImage.payload;
|
||||
override payloadExample = {};
|
||||
override returnExample = { yes: true };
|
||||
}
|
||||
|
||||
@ -2,8 +2,6 @@ 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 CanSendReturnSchema = Type.Object({
|
||||
yes: Type.Boolean({ description: '是否可以发送' }),
|
||||
});
|
||||
@ -24,7 +22,9 @@ export class CanSend extends OneBotAction<void, CanSendReturnType> {
|
||||
|
||||
export default class CanSendRecord extends CanSend {
|
||||
override actionName = ActionName.CanSendRecord;
|
||||
override actionSummary = '是否可以发送语音';
|
||||
override actionDescription = '检查是否可以发送语音';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = SystemActionsExamples.CanSendRecord.payload;
|
||||
override payloadExample = {};
|
||||
override returnExample = { yes: true };
|
||||
}
|
||||
|
||||
@ -8,8 +8,11 @@ export class CleanCache extends OneBotAction<void, void> {
|
||||
override actionName = ActionName.CleanCache;
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = Type.Null();
|
||||
override actionSummary = '清理缓存';
|
||||
override actionDescription = '清理缓存';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = {};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle () {
|
||||
try {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
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' }),
|
||||
@ -13,9 +12,13 @@ export class GetCSRF extends OneBotAction<void, GetCSRFReturnType> {
|
||||
override actionName = ActionName.GetCSRF;
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = GetCSRFReturnSchema;
|
||||
override actionSummary = '获取 CSRF Token';
|
||||
override actionDescription = '获取 CSRF Token';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = SystemActionsExamples.GetCSRF.payload;
|
||||
override payloadExample = {};
|
||||
override returnExample = {
|
||||
token: 123456789
|
||||
};
|
||||
|
||||
async _handle () {
|
||||
const sKey = await this.core.apis.UserApi.getSKey();
|
||||
|
||||
@ -2,8 +2,6 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
export const GetCredentialsPayloadSchema = Type.Object({
|
||||
domain: Type.String({ description: '需要获取 cookies 的域名' }),
|
||||
});
|
||||
@ -21,10 +19,16 @@ export class GetCredentials extends OneBotAction<GetCredentialsPayload, GetCrede
|
||||
override actionName = ActionName.GetCredentials;
|
||||
override payloadSchema = GetCredentialsPayloadSchema;
|
||||
override returnSchema = GetCredentialsReturnSchema;
|
||||
override actionDescription = '获取身份信息';
|
||||
override actionSummary = '获取登录凭证';
|
||||
override actionDescription = '获取登录凭证';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = ActionExamples.GetCredentials.payload;
|
||||
override returnExample = ActionExamples.GetCredentials.return;
|
||||
override payloadExample = {
|
||||
domain: 'qun.qq.com'
|
||||
};
|
||||
override returnExample = {
|
||||
cookies: 'uin=o123456789; skey=@abc12345;',
|
||||
token: 123456789
|
||||
};
|
||||
|
||||
async _handle (payload: GetCredentialsPayload) {
|
||||
const cookiesObject = await this.core.apis.UserApi.getCookies(payload.domain);
|
||||
|
||||
@ -2,8 +2,6 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
export const GetStatusReturnSchema = Type.Object({
|
||||
online: Type.Boolean({ description: '是否在线' }),
|
||||
good: Type.Boolean({ description: '状态是否良好' }),
|
||||
@ -16,10 +14,15 @@ export default class GetStatus extends OneBotAction<void, GetStatusReturnType> {
|
||||
override actionName = ActionName.GetStatus;
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = GetStatusReturnSchema;
|
||||
override actionSummary = '获取运行状态';
|
||||
override actionDescription = '获取运行状态';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = ActionExamples.GetStatus.payload;
|
||||
override returnExample = ActionExamples.GetStatus.return;
|
||||
override payloadExample = {};
|
||||
override returnExample = {
|
||||
online: true,
|
||||
good: true,
|
||||
stat: {}
|
||||
};
|
||||
|
||||
async _handle (): Promise<GetStatusReturnType> {
|
||||
return {
|
||||
|
||||
@ -4,8 +4,6 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { OB11NotifySchema } from '../schemas';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
export const GetGroupSystemMsgPayloadSchema = Type.Object({
|
||||
count: Type.Union([Type.Number(), Type.String()], { default: 50, description: '获取的消息数量' }),
|
||||
});
|
||||
@ -24,10 +22,17 @@ export class GetGroupSystemMsg extends OneBotAction<GetGroupSystemMsgPayload, Ge
|
||||
override actionName = ActionName.GetGroupSystemMsg;
|
||||
override payloadSchema = GetGroupSystemMsgPayloadSchema;
|
||||
override returnSchema = GetGroupSystemMsgReturnSchema;
|
||||
override actionSummary = '获取群系统消息';
|
||||
override actionDescription = '获取群系统消息';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = ActionExamples.GetGroupSystemMsg.payload;
|
||||
override returnExample = ActionExamples.GetGroupSystemMsg.return;
|
||||
override payloadExample = {
|
||||
count: 50
|
||||
};
|
||||
override returnExample = {
|
||||
invited_requests: [],
|
||||
InvitedRequest: [],
|
||||
join_requests: []
|
||||
};
|
||||
|
||||
async _handle (params: GetGroupSystemMsgPayload): Promise<GetGroupSystemMsgReturn> {
|
||||
const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, +params.count);
|
||||
|
||||
@ -11,15 +11,18 @@ const ReturnSchema = Type.Object({
|
||||
|
||||
type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
export default class GetVersionInfo extends OneBotAction<void, ReturnType> {
|
||||
override actionName = ActionName.GetVersionInfo;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取版本信息';
|
||||
override actionDescription = '获取版本信息';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = ActionExamples.GetVersionInfo.payload;
|
||||
override returnExample = ActionExamples.GetVersionInfo.return;
|
||||
override payloadExample = {};
|
||||
override returnExample = {
|
||||
app_name: 'NapCat.Onebot',
|
||||
protocol_version: 'v11',
|
||||
app_version: '1.0.0'
|
||||
};
|
||||
|
||||
async _handle (): Promise<ReturnType> {
|
||||
return {
|
||||
|
||||
@ -7,8 +7,11 @@ export class SetRestart extends OneBotAction<void, void> {
|
||||
override actionName = ActionName.Reboot;
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = Type.Null();
|
||||
override actionSummary = '重启服务';
|
||||
override actionDescription = '重启服务';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = {};
|
||||
override returnExample = null;
|
||||
|
||||
async _handle () {
|
||||
const result = await WebUiDataRuntime.requestRestartProcess();
|
||||
|
||||
@ -2,8 +2,6 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
export const GetCookiesPayloadSchema = Type.Object({
|
||||
domain: Type.String({ description: '需要获取 cookies 的域名' }),
|
||||
});
|
||||
@ -21,10 +19,16 @@ export class GetCookies extends OneBotAction<GetCookiesPayload, GetCookiesRespon
|
||||
override actionName = ActionName.GetCookies;
|
||||
override payloadSchema = GetCookiesPayloadSchema;
|
||||
override returnSchema = GetCookiesReturnSchema;
|
||||
override actionDescription = '获取 Cookies';
|
||||
override actionSummary = '获取 Cookies';
|
||||
override actionDescription = '获取指定域名的 Cookies';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = ActionExamples.GetCookies.payload;
|
||||
override returnExample = ActionExamples.GetCookies.return;
|
||||
override payloadExample = {
|
||||
domain: 'qun.qq.com'
|
||||
};
|
||||
override returnExample = {
|
||||
cookies: 'uin=o123456789; skey=@abc12345;',
|
||||
bkn: '123456789'
|
||||
};
|
||||
|
||||
async _handle (payload: GetCookiesPayload) {
|
||||
const cookiesObject = await this.core.apis.UserApi.getCookies(payload.domain);
|
||||
|
||||
@ -2,7 +2,6 @@ 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: '获取的数量' }),
|
||||
@ -28,9 +27,21 @@ export default class GetRecentContact extends OneBotAction<GetRecentContactPaylo
|
||||
override actionName = ActionName.GetRecentContact;
|
||||
override payloadSchema = GetRecentContactPayloadSchema;
|
||||
override returnSchema = GetRecentContactReturnSchema;
|
||||
override actionSummary = '获取最近会话';
|
||||
override actionDescription = '获取最近会话';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = UserActionsExamples.GetRecentContact.payload;
|
||||
override payloadExample = {
|
||||
count: 10
|
||||
};
|
||||
override returnExample = [
|
||||
{
|
||||
peerUin: '123456',
|
||||
peerName: '测试',
|
||||
msgTime: '1734567890',
|
||||
msgId: '12345',
|
||||
lastestMsg: []
|
||||
}
|
||||
];
|
||||
|
||||
async _handle (payload: GetRecentContactPayload, _adapter: string, config: NetworkAdapterConfig): Promise<GetRecentContactReturn> {
|
||||
const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+payload.count);
|
||||
|
||||
@ -18,7 +18,11 @@ export default class SendLike extends OneBotAction<SendLikePayload, void> {
|
||||
override actionSummary = '点赞';
|
||||
override actionDescription = '给指定用户点赞';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = ActionExamples.SendLike.payload;
|
||||
override payloadExample = {
|
||||
user_id: '123456',
|
||||
times: 10
|
||||
};
|
||||
override returnExample = {};
|
||||
override errorExamples = [
|
||||
...ActionExamples.Common.errors,
|
||||
{ code: 1400, description: '点赞失败(频率过快或用户不存在)' }
|
||||
|
||||
@ -10,15 +10,19 @@ export const SetFriendAddRequestPayloadSchema = Type.Object({
|
||||
|
||||
export type SetFriendAddRequestPayload = Static<typeof SetFriendAddRequestPayloadSchema>;
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
|
||||
export default class SetFriendAddRequest extends OneBotAction<SetFriendAddRequestPayload, void> {
|
||||
override actionName = ActionName.SetFriendAddRequest;
|
||||
override payloadSchema = SetFriendAddRequestPayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionDescription = '处理加好友请求';
|
||||
override actionSummary = '处理加好友请求';
|
||||
override actionDescription = '同意或拒绝加好友请求';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = ActionExamples.SetFriendAddRequest.payload;
|
||||
override payloadExample = {
|
||||
flag: 'flag_12345',
|
||||
approve: true,
|
||||
remark: '新朋友'
|
||||
};
|
||||
override returnExample = {};
|
||||
|
||||
async _handle (payload: SetFriendAddRequestPayload): Promise<void> {
|
||||
const approve = payload.approve?.toString() !== 'false';
|
||||
|
||||
@ -15,9 +15,14 @@ export default class SetFriendRemark extends OneBotAction<SetFriendRemarkPayload
|
||||
override actionName = ActionName.SetFriendRemark;
|
||||
override payloadSchema = SetFriendRemarkPayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionSummary = '设置好友备注';
|
||||
override actionDescription = '设置好友备注';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = ActionExamples.SetFriendRemark.payload;
|
||||
override payloadExample = {
|
||||
user_id: '123456',
|
||||
remark: '测试备注'
|
||||
};
|
||||
override returnExample = {};
|
||||
override errorExamples = [
|
||||
...ActionExamples.Common.errors,
|
||||
{ code: 1400, description: '备注设置失败(好友不存在或非法输入)' }
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { getAllHandlers } from '@/napcat-onebot/action/index';
|
||||
import { AutoRegisterRouter } from '@/napcat-onebot/action/auto-register';
|
||||
import { writeFileSync } from 'node:fs';
|
||||
import { writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
||||
import { resolve, dirname } from 'node:path';
|
||||
import { TSchema } from '@sinclair/typebox';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
@ -22,7 +22,6 @@ interface ActionSchemaInfo {
|
||||
|
||||
export const actionSchemas: Record<string, ActionSchemaInfo> = {};
|
||||
|
||||
|
||||
export function initSchemas () {
|
||||
const handlers = getAllHandlers(null as any, null as any);
|
||||
handlers.forEach(handler => {
|
||||
@ -62,63 +61,75 @@ export function generateOpenAPI () {
|
||||
try {
|
||||
initSchemas();
|
||||
} catch (e) {
|
||||
console.warn('Init schemas partial failure (expected due to complex imports), proceeding with collected data...');
|
||||
console.warn('Init schemas partial failure, proceeding with collected data...');
|
||||
}
|
||||
|
||||
const openapi: Record<string, unknown> = {
|
||||
openapi: '3.1.0',
|
||||
info: {
|
||||
title: 'NapCat OneBot 11 接口文档',
|
||||
description: 'NapCatOneBot11 旨在提供更先进、更统一、更美观的 OneBot 11 协议实现。',
|
||||
title: 'NapCat OneBot 11 HTTP API',
|
||||
description: '本文档描述 NapCat OneBot 11 的 HTTP POST 接口协议。所有接口均通过 POST 请求调用,请求体为 JSON 格式。',
|
||||
version: '1.0.0'
|
||||
},
|
||||
tags: [
|
||||
{ name: '消息接口', description: '发送、删除、获取消息相关接口' },
|
||||
{ name: '群组接口', description: '群组管理、成员管理相关接口' },
|
||||
{ name: '用户接口', description: '好友管理、个人信息相关接口' },
|
||||
{ name: '系统接口', description: '状态获取、重启、缓存清理相关接口' },
|
||||
{ name: '文件接口', description: '文件上传下载、预览相关接口' },
|
||||
{ name: '系统扩展', description: 'NapCat 特有的系统级扩展功能' },
|
||||
{ name: '群扩展', description: 'NapCat 特有的群组级扩展功能' },
|
||||
{ name: '用户扩展', description: 'NapCat 特有的用户级扩展功能' },
|
||||
{ name: '文件扩展', description: 'NapCat 特有的文件级扩展功能' },
|
||||
{ name: 'Go-CQHTTP', description: '兼容 Go-CQHTTP 的特定接口' }
|
||||
],
|
||||
paths: {} as Record<string, unknown>
|
||||
};
|
||||
|
||||
for (const [actionName, schemas] of Object.entries(actionSchemas)) {
|
||||
if (!schemas.payload) continue;
|
||||
const path = `/${actionName}`;
|
||||
// 忽略没有定义参数且没有 Summary 的占位接口
|
||||
if (!schemas.payload && !schemas.summary) continue;
|
||||
|
||||
const cleanPayload = JSON.parse(JSON.stringify(schemas.payload || { type: 'object', properties: {} }));
|
||||
const cleanReturn = JSON.parse(JSON.stringify(schemas.return || { type: 'object', properties: {} }));
|
||||
const path = '/' + actionName;
|
||||
const cleanPayload = schemas.payload ? JSON.parse(JSON.stringify(schemas.payload)) : { type: 'object', properties: {} };
|
||||
const cleanReturn = schemas.return ? JSON.parse(JSON.stringify(schemas.return)) : { type: 'object', properties: {} };
|
||||
|
||||
const wrappedPayload = {
|
||||
// HTTP 响应结构: {"status": "ok", "retcode": 0, "data": ...}
|
||||
const httpResponseSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
action: { type: 'string', example: actionName },
|
||||
params: cleanPayload,
|
||||
echo: { type: 'string', example: `${actionName}:1234567890` }
|
||||
}
|
||||
};
|
||||
|
||||
const wrappedReturn = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
status: { type: 'string', example: 'ok' },
|
||||
retcode: { type: 'number', example: 0 },
|
||||
data: cleanReturn,
|
||||
message: { type: 'string', example: '' },
|
||||
wording: { type: 'string', example: '' },
|
||||
echo: { type: 'string', example: `${actionName}:1234567890` }
|
||||
status: { type: 'string', enum: ['ok', 'async', 'failed'], description: '执行状态', example: 'ok' },
|
||||
retcode: { type: 'number', description: '响应码 (0 为成功)', example: 0 },
|
||||
data: { ...cleanReturn, description: '响应数据' },
|
||||
message: { type: 'string', description: '错误消息', example: '' },
|
||||
wording: { type: 'string', description: '提示消息', example: '' }
|
||||
},
|
||||
required: ['status', 'retcode', 'data', 'message', 'wording']
|
||||
required: ['status', 'retcode', 'data']
|
||||
};
|
||||
|
||||
const paths = openapi['paths'] as Record<string, any>;
|
||||
const responses: Record<string, unknown> = {
|
||||
'200': {
|
||||
description: '成功',
|
||||
description: '成功响应',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: wrappedReturn
|
||||
schema: httpResponseSchema,
|
||||
example: {
|
||||
status: 'ok',
|
||||
retcode: 0,
|
||||
data: schemas.returnExample || {},
|
||||
message: '',
|
||||
wording: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 处理错误示例
|
||||
if (schemas.errorExamples) {
|
||||
schemas.errorExamples.forEach(error => {
|
||||
responses[error.code.toString()] = {
|
||||
const codeStr = error.code.toString();
|
||||
responses[codeStr] = {
|
||||
description: error.description,
|
||||
content: {
|
||||
'application/json': {
|
||||
@ -137,20 +148,18 @@ export function generateOpenAPI () {
|
||||
});
|
||||
}
|
||||
|
||||
const paths = openapi['paths'] as Record<string, any>;
|
||||
paths[path] = {
|
||||
post: {
|
||||
summary: schemas.summary || actionName,
|
||||
description: schemas.description || schemas.summary || actionName,
|
||||
description: schemas.description || 'API Action: ' + actionName,
|
||||
tags: schemas.tags || ['Default'],
|
||||
requestBody: {
|
||||
description: 'API 请求参数',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: wrappedPayload,
|
||||
example: {
|
||||
action: actionName,
|
||||
params: schemas.payloadExample || {},
|
||||
echo: `${actionName}:1234567890`
|
||||
}
|
||||
schema: cleanPayload,
|
||||
example: schemas.payloadExample || {}
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -158,8 +167,42 @@ export function generateOpenAPI () {
|
||||
}
|
||||
};
|
||||
}
|
||||
const outputPath = resolve(__dirname, 'openapi.json');
|
||||
|
||||
const outputDir = resolve(__dirname, 'dist');
|
||||
if (!existsSync(outputDir)) {
|
||||
mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
|
||||
const outputPath = resolve(outputDir, 'openapi.json');
|
||||
writeFileSync(outputPath, JSON.stringify(openapi, null, 2));
|
||||
console.log(`OpenAPI schema generated at: ${outputPath}`);
|
||||
console.log('OpenAPI schema (HTTP Format) generated at: ' + outputPath);
|
||||
|
||||
// 生成审计报告
|
||||
generateMissingReport();
|
||||
}
|
||||
generateOpenAPI();
|
||||
|
||||
function generateMissingReport() {
|
||||
const missingReport: string[] = [];
|
||||
for (const [actionName, schemas] of Object.entries(actionSchemas)) {
|
||||
const missing: string[] = [];
|
||||
if (!schemas.summary) missing.push('actionSummary');
|
||||
if (!schemas.tags || schemas.tags.length === 0) missing.push('actionTags');
|
||||
if (schemas.payloadExample === undefined && schemas.payload) missing.push('payloadExample');
|
||||
if (schemas.returnExample === undefined) missing.push('returnExample');
|
||||
|
||||
if (missing.length > 0) {
|
||||
missingReport.push('[' + actionName + '] 缺失属性: ' + missing.join(', '));
|
||||
}
|
||||
}
|
||||
|
||||
const reportPath = resolve(__dirname, 'dist', 'missing_props.log');
|
||||
if (missingReport.length > 0) {
|
||||
writeFileSync(reportPath, missingReport.join('\n'));
|
||||
console.warn('\n检查到 ' + missingReport.length + ' 个接口存在元数据缺失,报告已保存至: ' + reportPath);
|
||||
} else {
|
||||
if (existsSync(reportPath)) writeFileSync(reportPath, '');
|
||||
console.log('\n所有接口元数据已完整!');
|
||||
}
|
||||
}
|
||||
|
||||
generateOpenAPI();
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"generate:openapi": "node ./dist/schemas.mjs",
|
||||
"build:schema": "vite build"
|
||||
"build:schema": "vite build",
|
||||
"run": "vite build & node ./dist/schemas.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sinclair/typebox": "^0.34.38",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user