mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-04 14:41:14 +00:00
Refactor extends actions to use new examples module
Replaced imports of ActionExamples with ExtendsActionsExamples in all extends actions. Updated action summary, description, tags, and example references for consistency and clarity across actions. This improves maintainability and aligns with the new examples structure.
This commit is contained in:
parent
8623fb1df0
commit
5b80a8576f
@ -2,7 +2,7 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { ExtendsActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -32,11 +32,11 @@ export class GetAiCharacters extends GetPacketStatusDepends<PayloadType, ReturnT
|
||||
override actionName = ActionName.GetAiCharacters;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取 AI 角色列表';
|
||||
override actionDescription = '获取群聊中的 AI 角色列表';
|
||||
override actionSummary = '获取AI角色列表';
|
||||
override actionDescription = '获取群聊中的AI角色列表';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ActionExamples.GetAiCharacters.payload;
|
||||
override returnExample = ActionExamples.GetAiCharacters.return;
|
||||
override payloadExample = ExtendsActionsExamples.GetAiCharacters.payload;
|
||||
override returnExample = ExtendsActionsExamples.GetAiCharacters.response;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const chatTypeNum = Number(payload.chat_type);
|
||||
|
||||
@ -2,7 +2,7 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { OneBotAction } from '../OneBotAction';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { ExtendsActionsExamples } from './examples';
|
||||
|
||||
const ReturnSchema = Type.Object({
|
||||
clientkey: Type.Optional(Type.String({ description: '客户端Key' })),
|
||||
@ -14,11 +14,11 @@ export class GetClientkey extends OneBotAction<void, ReturnType> {
|
||||
override actionName = ActionName.GetClientkey;
|
||||
override payloadSchema = Type.Void();
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取 ClientKey';
|
||||
override actionDescription = '获取当前登录帐号的 ClientKey';
|
||||
override actionSummary = '获取ClientKey';
|
||||
override actionDescription = '获取当前登录帐号的ClientKey';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ActionExamples.GetClientkey.payload;
|
||||
override returnExample = ActionExamples.GetClientkey.return;
|
||||
override payloadExample = ExtendsActionsExamples.GetClientkey.payload;
|
||||
override returnExample = ExtendsActionsExamples.GetClientkey.response;
|
||||
|
||||
async _handle () {
|
||||
return { clientkey: (await this.core.apis.UserApi.forceFetchClientKey()).clientKey };
|
||||
|
||||
@ -2,6 +2,8 @@ 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>;
|
||||
@ -10,6 +12,11 @@ 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;
|
||||
|
||||
async _handle () {
|
||||
return await this.core.apis.PacketApi.pkt.operation.FetchRkey();
|
||||
|
||||
@ -23,6 +23,7 @@ class OCRImageBase extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionDescription = '识别图片中的文字内容';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ExtendsActionsExamples.OCRImage.payload;
|
||||
override returnExample = ExtendsActionsExamples.OCRImage.response;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const { path, success } = await uriToLocalFile(this.core.NapCatTempPath, payload.image);
|
||||
|
||||
@ -2,7 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { ExtendsActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -20,9 +20,11 @@ export default class SetGroupKickMembers extends OneBotAction<PayloadType, Retur
|
||||
override actionName = ActionName.SetGroupKickMembers;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '批量踢出群成员';
|
||||
override actionSummary = '批量踢出群成员';
|
||||
override actionDescription = '从指定群聊中批量踢出多个成员';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ActionExamples.SetGroupKickMembers.payload;
|
||||
override payloadExample = ExtendsActionsExamples.SetGroupKickMembers.payload;
|
||||
override returnExample = ExtendsActionsExamples.SetGroupKickMembers.response;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const rejectReq = payload.reject_add_request?.toString() === 'true';
|
||||
|
||||
@ -2,6 +2,8 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ExtendsActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
longNick: Type.String({ description: '签名内容' }),
|
||||
});
|
||||
@ -16,6 +18,11 @@ export class SetLongNick extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetLongNick;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '设置个性签名';
|
||||
override actionDescription = '修改当前登录帐号的个性签名';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ExtendsActionsExamples.SetLongNick.payload;
|
||||
override returnExample = ExtendsActionsExamples.SetLongNick.response;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
return await this.core.apis.UserApi.setLongNick(payload.longNick);
|
||||
|
||||
@ -4,7 +4,7 @@ import fs from 'node:fs/promises';
|
||||
import { checkFileExist, uriToLocalFile } from 'napcat-common/src/file';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { ExtendsActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
file: Type.String({ description: '图片路径、URL或Base64' }),
|
||||
@ -20,10 +20,11 @@ export default class SetAvatar extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetQQAvatar;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '设置 QQ 头像';
|
||||
override actionDescription = '设置当前帐号的 QQ 头像';
|
||||
override actionSummary = '设置QQ头像';
|
||||
override actionDescription = '修改当前账号的QQ头像';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ActionExamples.SetQQAvatar.payload;
|
||||
override payloadExample = ExtendsActionsExamples.SetQQAvatar.payload;
|
||||
override returnExample = ExtendsActionsExamples.SetQQAvatar.response;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const { path, success } = (await uriToLocalFile(this.core.NapCatTempPath, payload.file));
|
||||
|
||||
@ -2,7 +2,7 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { ExtendsActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
@ -20,9 +20,11 @@ export class SetSpecialTitle extends GetPacketStatusDepends<PayloadType, ReturnT
|
||||
override actionName = ActionName.SetSpecialTitle;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionDescription = '设置专属头衔';
|
||||
override actionSummary = '设置专属头衔';
|
||||
override actionDescription = '设置群聊中指定成员的专属头衔';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ActionExamples.SetSpecialTitle.payload;
|
||||
override payloadExample = ExtendsActionsExamples.SetSpecialTitle.payload;
|
||||
override returnExample = ExtendsActionsExamples.SetSpecialTitle.response;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
|
||||
@ -2,6 +2,8 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ExtendsActionsExamples } from './examples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
words: Type.Array(Type.String(), { description: '待翻译单词列表' }),
|
||||
});
|
||||
@ -16,6 +18,11 @@ export class TranslateEnWordToZn extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.TranslateEnWordToZn;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '英文单词翻译';
|
||||
override actionDescription = '将英文单词列表翻译为中文';
|
||||
override actionTags = ['扩展接口'];
|
||||
override payloadExample = ExtendsActionsExamples.TranslateEnWordToZn.payload;
|
||||
override returnExample = ExtendsActionsExamples.TranslateEnWordToZn.response;
|
||||
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const ret = await this.core.apis.SystemApi.translateEnWordToZn(payload.words);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
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> {
|
||||
@ -19,8 +20,11 @@ export class GetPacketStatus extends GetPacketStatusDepends<void, void> {
|
||||
override actionName = ActionName.GetPacketStatus;
|
||||
override payloadSchema = Type.Object({});
|
||||
override returnSchema = Type.Null();
|
||||
override actionDescription = '获取 Packet 状态';
|
||||
override actionSummary = '获取Packet状态';
|
||||
override actionDescription = '获取底层Packet服务的运行状态';
|
||||
override actionTags = ['系统接口'];
|
||||
override payloadExample = PacketActionsExamples.GetPacketStatus.payload;
|
||||
override returnExample = PacketActionsExamples.GetPacketStatus.response;
|
||||
|
||||
async _handle () {
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { PacketActionsExamples } from './examples';
|
||||
|
||||
export const SendPokePayloadSchema = Type.Object({
|
||||
group_id: Type.Optional(Type.Union([Type.String(), Type.Number()], { description: '群号' })),
|
||||
@ -14,9 +14,11 @@ export type SendPokePayload = Static<typeof SendPokePayloadSchema>;
|
||||
export class SendPokeBase extends GetPacketStatusDepends<SendPokePayload, void> {
|
||||
override payloadSchema = SendPokePayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionDescription = '发送戳一戳';
|
||||
override actionSummary = '发送戳一戳';
|
||||
override actionDescription = '在群聊或私聊中发送戳一戳动作';
|
||||
override actionTags = ['核心接口'];
|
||||
override payloadExample = ActionExamples.SendPoke.payload;
|
||||
override payloadExample = PacketActionsExamples.SendPoke.payload;
|
||||
override returnExample = PacketActionsExamples.SendPoke.response;
|
||||
|
||||
async _handle (payload: SendPokePayload) {
|
||||
// 这里的 !! 可以传入空字符串 忽略这些数据有利用接口统一接口
|
||||
|
||||
@ -4,7 +4,7 @@ import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketS
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { ActionName } from '../router';
|
||||
|
||||
import { ActionExamples } from '../examples';
|
||||
import { PacketActionsExamples } from './examples';
|
||||
|
||||
export const SetGroupTodoPayloadSchema = Type.Object({
|
||||
group_id: Type.Union([Type.String(), Type.Number()], { description: '群号' }),
|
||||
@ -14,12 +14,14 @@ export const SetGroupTodoPayloadSchema = Type.Object({
|
||||
|
||||
export type SetGroupTodoPayload = Static<typeof SetGroupTodoPayloadSchema>;
|
||||
export class SetGroupTodo extends GetPacketStatusDepends<SetGroupTodoPayload, void> {
|
||||
override actionName = ActionName.SetGroupTodo;
|
||||
override payloadSchema = SetGroupTodoPayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionName = ActionName.SetGroupTodo;
|
||||
override actionDescription = '设置群待办';
|
||||
override actionSummary = '设置群待办';
|
||||
override actionDescription = '将指定消息设置为群待办';
|
||||
override actionTags = ['核心接口'];
|
||||
override payloadExample = ActionExamples.SetGroupTodo.payload;
|
||||
override payloadExample = PacketActionsExamples.SetGroupTodo.payload;
|
||||
override returnExample = PacketActionsExamples.SetGroupTodo.response;
|
||||
|
||||
async _handle (payload: SetGroupTodoPayload) {
|
||||
if (payload.message_seq) {
|
||||
|
||||
@ -17,6 +17,9 @@ export class DownloadFileStream extends BaseDownloadStream<DownloadFileStreamPay
|
||||
override actionName = ActionName.DownloadFileStream;
|
||||
override payloadSchema = DownloadFileStreamPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '下载结果 (流式)' });
|
||||
override actionSummary = '下载文件流';
|
||||
override actionDescription = '以流式方式从网络或本地下载文件';
|
||||
override actionTags = ['流式接口'];
|
||||
override useStream = true;
|
||||
|
||||
async _handle (payload: DownloadFileStreamPayload, _adaptername: string, _config: NetworkAdapterConfig, req: OneBotRequestToolkit): Promise<StreamPacket<DownloadResult>> {
|
||||
|
||||
@ -70,6 +70,9 @@ export class UploadFileStream extends OneBotAction<UploadFileStreamPayload, Stre
|
||||
override actionName = ActionName.UploadFileStream;
|
||||
override payloadSchema = UploadFileStreamPayloadSchema;
|
||||
override returnSchema = Type.Any({ description: '上传结果 (流式)' });
|
||||
override actionSummary = '上传文件流';
|
||||
override actionDescription = '以流式方式上传文件数据到机器人';
|
||||
override actionTags = ['流式接口'];
|
||||
override useStream = true;
|
||||
|
||||
private static streams = new Map<string, StreamState>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user