mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: simplify the PacketClient availability check process & add action nc_get_packet_status
This commit is contained in:
parent
83bced82b1
commit
7a4a255a89
@ -1,23 +1,11 @@
|
|||||||
import BaseAction from '../BaseAction';
|
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
// no_cache get时传字符串
|
|
||||||
const SchemaData = {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
},
|
|
||||||
} as const satisfies JSONSchema;
|
|
||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
|
||||||
|
|
||||||
export class GetRkey extends BaseAction<Payload, Array<any>> {
|
export class GetRkey extends GetPacketStatusDepends<null, Array<any>> {
|
||||||
actionName = ActionName.GetRkey;
|
actionName = ActionName.GetRkey;
|
||||||
payloadSchema = SchemaData;
|
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle() {
|
||||||
if (!this.core.apis.PacketApi.available) {
|
|
||||||
throw new Error('PacketClient is not init');
|
|
||||||
}
|
|
||||||
return await this.core.apis.PacketApi.sendRkeyPacket();
|
return await this.core.apis.PacketApi.sendRkeyPacket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import BaseAction from '../BaseAction';
|
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
@ -13,14 +13,11 @@ const SchemaData = {
|
|||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
export class SetSpecialTittle extends BaseAction<Payload, any> {
|
export class SetSpecialTittle extends GetPacketStatusDepends<Payload, any> {
|
||||||
actionName = ActionName.SetSpecialTittle;
|
actionName = ActionName.SetSpecialTittle;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
if (!this.core.apis.PacketApi.available) {
|
|
||||||
throw new Error('PacketClient is not init');
|
|
||||||
}
|
|
||||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
if(!uid) throw new Error('User not found');
|
if(!uid) throw new Error('User not found');
|
||||||
await this.core.apis.PacketApi.sendSetSpecialTittlePacket(payload.group_id.toString(), uid, payload.special_title);
|
await this.core.apis.PacketApi.sendSetSpecialTittlePacket(payload.group_id.toString(), uid, payload.special_title);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import BaseAction from '../BaseAction';
|
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
import {FileNapCatOneBotUUID} from "@/common/helper";
|
import { FileNapCatOneBotUUID } from "@/common/helper";
|
||||||
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@ -18,14 +18,11 @@ interface GetGroupFileUrlResponse {
|
|||||||
url?: string;
|
url?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetGroupFileUrl extends BaseAction<Payload, GetGroupFileUrlResponse> {
|
export class GetGroupFileUrl extends GetPacketStatusDepends<Payload, GetGroupFileUrlResponse> {
|
||||||
actionName = ActionName.GOCQHTTP_GetGroupFileUrl;
|
actionName = ActionName.GOCQHTTP_GetGroupFileUrl;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
if (!this.core.apis.PacketApi.available) {
|
|
||||||
throw new Error('PacketClient is not init');
|
|
||||||
}
|
|
||||||
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file_id) || FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file_id) || FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
||||||
if (contextMsgFile?.fileUUID) {
|
if (contextMsgFile?.fileUUID) {
|
||||||
return {
|
return {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import BaseAction from '../BaseAction';
|
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
|
import {GetPacketStatusDepends} from "@/onebot/action/packet/GetPacketStatus";
|
||||||
// no_cache get时传字符串
|
// no_cache get时传字符串
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@ -13,14 +13,11 @@ const SchemaData = {
|
|||||||
|
|
||||||
type Payload = FromSchema<typeof SchemaData>;
|
type Payload = FromSchema<typeof SchemaData>;
|
||||||
|
|
||||||
export class GroupPoke extends BaseAction<Payload, any> {
|
export class GroupPoke extends GetPacketStatusDepends<Payload, any> {
|
||||||
actionName = ActionName.GroupPoke;
|
actionName = ActionName.GroupPoke;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
if (!this.core.apis.PacketApi.available) {
|
|
||||||
throw new Error('PacketClient is not init');
|
|
||||||
}
|
|
||||||
await this.core.apis.PacketApi.sendPokePacket(+payload.group_id, +payload.user_id);
|
await this.core.apis.PacketApi.sendPokePacket(+payload.group_id, +payload.user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ import { UploadForwardMsg } from "@/onebot/action/extends/UploadForwardMsg";
|
|||||||
import { GetGroupShutList } from './group/GetGroupShutList';
|
import { GetGroupShutList } from './group/GetGroupShutList';
|
||||||
import { GetGroupMemberList } from './group/GetGroupMemberList';
|
import { GetGroupMemberList } from './group/GetGroupMemberList';
|
||||||
import { GetGroupFileUrl } from "@/onebot/action/file/GetGroupFileUrl";
|
import { GetGroupFileUrl } from "@/onebot/action/file/GetGroupFileUrl";
|
||||||
|
import {GetPacketStatus} from "@/onebot/action/packet/GetPacketStatus";
|
||||||
|
|
||||||
|
|
||||||
export type ActionMap = Map<string, BaseAction<any, any>>;
|
export type ActionMap = Map<string, BaseAction<any, any>>;
|
||||||
@ -187,6 +188,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
|
|||||||
new GetGroupFilesByFolder(obContext, core),
|
new GetGroupFilesByFolder(obContext, core),
|
||||||
new GetGroupSystemMsg(obContext, core),
|
new GetGroupSystemMsg(obContext, core),
|
||||||
new FetchUserProfileLike(obContext, core),
|
new FetchUserProfileLike(obContext, core),
|
||||||
|
new GetPacketStatus(obContext, core),
|
||||||
new GroupPoke(obContext, core),
|
new GroupPoke(obContext, core),
|
||||||
new GetUserStatus(obContext, core),
|
new GetUserStatus(obContext, core),
|
||||||
new GetRkey(obContext, core),
|
new GetRkey(obContext, core),
|
||||||
|
25
src/onebot/action/packet/GetPacketStatus.ts
Normal file
25
src/onebot/action/packet/GetPacketStatus.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import BaseAction from '../BaseAction';
|
||||||
|
import {ActionName, BaseCheckResult} from '../types';
|
||||||
|
|
||||||
|
|
||||||
|
export abstract class GetPacketStatusDepends<PT, RT> extends BaseAction<PT, RT> {
|
||||||
|
actionName = ActionName.GetPacketStatus;
|
||||||
|
|
||||||
|
protected async check(): Promise<BaseCheckResult>{
|
||||||
|
if (!this.core.apis.PacketApi.available) {
|
||||||
|
return {
|
||||||
|
valid: false,
|
||||||
|
message: "PacketClient is not available!",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
valid: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GetPacketStatus extends GetPacketStatusDepends<any, null> {
|
||||||
|
async _handle(payload: any) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
@ -121,6 +121,7 @@ export enum ActionName {
|
|||||||
GetGroupInfoEx = "get_group_info_ex",
|
GetGroupInfoEx = "get_group_info_ex",
|
||||||
GetGroupSystemMsg = 'get_group_system_msg',
|
GetGroupSystemMsg = 'get_group_system_msg',
|
||||||
FetchUserProfileLike = "fetch_user_profile_like",
|
FetchUserProfileLike = "fetch_user_profile_like",
|
||||||
|
GetPacketStatus = 'nc_get_packet_status',
|
||||||
GetUserStatus = "nc_get_user_status",
|
GetUserStatus = "nc_get_user_status",
|
||||||
GetRkey = "nc_get_rkey",
|
GetRkey = "nc_get_rkey",
|
||||||
SetSpecialTittle = "set_group_special_title",
|
SetSpecialTittle = "set_group_special_title",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user