mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-12 07:50:25 +00:00
style: 强类型大法
This commit is contained in:
@@ -9,9 +9,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class CreateCollection extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.CreateCollection;
|
||||
payloadSchema = SchemaData;
|
||||
export class CreateCollection extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.CreateCollection;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
return await this.core.apis.CollectionApi.createCollection(
|
||||
|
||||
@@ -9,8 +9,8 @@ const SchemaData = Type.Object({
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class FetchCustomFace extends OneBotAction<Payload, string[]> {
|
||||
actionName = ActionName.FetchCustomFace;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.FetchCustomFace;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const ret = await this.core.apis.MsgApi.fetchFavEmojiList(+payload.count);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Type, Static } from '@sinclair/typebox';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { type NTQQMsgApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||
@@ -12,14 +13,15 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class FetchEmojiLike extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.FetchEmojiLike;
|
||||
payloadSchema = SchemaData;
|
||||
export class FetchEmojiLike extends OneBotAction<Payload, Awaited<ReturnType<NTQQMsgApi['getMsgEmojiLikesList']>>> {
|
||||
override actionName = ActionName.FetchEmojiLike;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
|
||||
if (!msgIdPeer) throw new Error('消息不存在');
|
||||
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
||||
if (!msg) throw new Error('消息不存在');
|
||||
return await this.core.apis.MsgApi.getMsgEmojiLikesList(
|
||||
msgIdPeer.Peer, msg.msgSeq, payload.emojiId.toString(), payload.emojiType.toString(), +payload.count
|
||||
);
|
||||
|
||||
@@ -20,8 +20,8 @@ interface GetAiCharactersResponse {
|
||||
}
|
||||
|
||||
export class GetAiCharacters extends GetPacketStatusDepends<Payload, GetAiCharactersResponse[]> {
|
||||
actionName = ActionName.GetAiCharacters;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GetAiCharacters;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const rawList = await this.core.apis.PacketApi.pkt.operation.FetchAiVoiceList(+payload.group_id, +payload.chat_type as AIVoiceChatType);
|
||||
|
||||
@@ -6,7 +6,7 @@ interface GetClientkeyResponse {
|
||||
}
|
||||
|
||||
export class GetClientkey extends OneBotAction<void, GetClientkeyResponse> {
|
||||
actionName = ActionName.GetClientkey;
|
||||
override actionName = ActionName.GetClientkey;
|
||||
|
||||
async _handle() {
|
||||
return { clientkey: (await this.core.apis.UserApi.forceFetchClientKey()).clientKey };
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { type NTQQCollectionApi } from '@/core/apis/collection';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
@@ -9,9 +10,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GetCollectionList extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GetCollectionList;
|
||||
payloadSchema = SchemaData;
|
||||
export class GetCollectionList extends OneBotAction<Payload, Awaited<ReturnType<NTQQCollectionApi['getAllCollection']>>> {
|
||||
override actionName = ActionName.GetCollectionList;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
return await this.core.apis.CollectionApi.getAllCollection(+payload.category, +payload.count);
|
||||
|
||||
@@ -2,10 +2,10 @@ import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
|
||||
export class GetFriendWithCategory extends OneBotAction<void, any> {
|
||||
actionName = ActionName.GetFriendsWithCategory;
|
||||
export class GetFriendWithCategory extends OneBotAction<void, unknown> {
|
||||
override actionName = ActionName.GetFriendsWithCategory;
|
||||
|
||||
async _handle(payload: void) {
|
||||
async _handle() {
|
||||
return (await this.core.apis.FriendApi.getBuddyV2ExWithCate()).map(category => ({
|
||||
...category,
|
||||
buddyList: OB11Construct.friends(category.buddyList),
|
||||
|
||||
@@ -4,9 +4,9 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { Notify } from '@/onebot/types';
|
||||
|
||||
export default class GetGroupAddRequest extends OneBotAction<null, Notify[] | null> {
|
||||
actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||
override actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||
|
||||
async _handle(payload: null): Promise<Notify[] | null> {
|
||||
async _handle(): Promise<Notify[] | null> {
|
||||
const NTQQUserApi = this.core.apis.UserApi;
|
||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||
const ignoredNotifies = await NTQQGroupApi.getSingleScreenNotifies(true, 10);
|
||||
|
||||
@@ -7,9 +7,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GetGroupInfoEx extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GetGroupInfoEx;
|
||||
payloadSchema = SchemaData;
|
||||
export class GetGroupInfoEx extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.GetGroupInfoEx;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
return (await this.core.apis.GroupApi.getGroupExtFE0Info([payload.group_id.toString()])).result.groupExtInfos.get(payload.group_id.toString());
|
||||
|
||||
@@ -38,8 +38,8 @@ type Payload = Static<typeof SchemaData>;
|
||||
export class GetMiniAppArk extends GetPacketStatusDepends<Payload, {
|
||||
data: MiniAppData | MiniAppRawData
|
||||
}> {
|
||||
actionName = ActionName.GetMiniAppArk;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GetMiniAppArk;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
let reqParam: MiniAppReqParams;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { NTVoteInfo } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
@@ -10,9 +11,25 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GetProfileLike extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GetProfileLike;
|
||||
payloadSchema = SchemaData;
|
||||
export class GetProfileLike extends OneBotAction<Payload, {
|
||||
uid: string;
|
||||
time: string;
|
||||
favoriteInfo: {
|
||||
userInfos: Array<NTVoteInfo>;
|
||||
total_count: number;
|
||||
last_time: number;
|
||||
today_count: number;
|
||||
};
|
||||
voteInfo: {
|
||||
total_count: number;
|
||||
new_count: number;
|
||||
new_nearby_count: number;
|
||||
last_visit_time: number;
|
||||
userInfos: Array<NTVoteInfo>;
|
||||
};
|
||||
}> {
|
||||
override actionName = ActionName.GetProfileLike;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload) {
|
||||
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());
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
|
||||
export class GetRkey extends GetPacketStatusDepends<void, Array<any>> {
|
||||
actionName = ActionName.GetRkey;
|
||||
export class GetRkey extends GetPacketStatusDepends<void, Array<unknown>> {
|
||||
override actionName = ActionName.GetRkey;
|
||||
|
||||
async _handle() {
|
||||
return await this.core.apis.PacketApi.pkt.operation.FetchRkey();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
|
||||
export class GetRobotUinRange extends OneBotAction<void, Array<any>> {
|
||||
actionName = ActionName.GetRobotUinRange;
|
||||
export class GetRobotUinRange extends OneBotAction<void, Array<unknown>> {
|
||||
override actionName = ActionName.GetRobotUinRange;
|
||||
|
||||
async _handle() {
|
||||
return await this.core.apis.UserApi.getRobotUinRange();
|
||||
|
||||
@@ -9,8 +9,8 @@ const SchemaData = Type.Object({
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GetUserStatus extends GetPacketStatusDepends<Payload, { status: number; ext_status: number; } | undefined> {
|
||||
actionName = ActionName.GetUserStatus;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GetUserStatus;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
return await this.core.apis.PacketApi.pkt.operation.GetStrangerStatus(+payload.user_id);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { checkFileExist, uriToLocalFile } from '@/common/file';
|
||||
import fs from 'fs';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { GeneralCallResultStatus } from '@/core';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
image: Type.String(),
|
||||
@@ -10,8 +11,8 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
class OCRImageBase extends OneBotAction<Payload, any> {
|
||||
payloadSchema = SchemaData;
|
||||
class OCRImageBase extends OneBotAction<Payload, GeneralCallResultStatus> {
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const { path, success } = await uriToLocalFile(this.core.NapCatTempPath, payload.image);
|
||||
@@ -35,9 +36,9 @@ class OCRImageBase extends OneBotAction<Payload, any> {
|
||||
}
|
||||
|
||||
export class OCRImage extends OCRImageBase {
|
||||
actionName = ActionName.OCRImage;
|
||||
override actionName = ActionName.OCRImage;
|
||||
}
|
||||
|
||||
export class IOCRImage extends OCRImageBase {
|
||||
actionName = ActionName.IOCRImage;
|
||||
override actionName = ActionName.IOCRImage;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { PacketHexStr } from '@/core/packet/transformer/base';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
@@ -10,12 +11,12 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class SendPacket extends GetPacketStatusDepends<Payload, any> {
|
||||
payloadSchema = SchemaData;
|
||||
actionName = ActionName.SendPacket;
|
||||
export class SendPacket extends GetPacketStatusDepends<Payload, string | undefined> {
|
||||
override payloadSchema = SchemaData;
|
||||
override actionName = ActionName.SendPacket;
|
||||
async _handle(payload: Payload) {
|
||||
const rsp = typeof payload.rsp === 'boolean' ? payload.rsp : payload.rsp === 'true';
|
||||
const data = await this.core.apis.PacketApi.pkt.operation.sendPacket({ cmd: payload.cmd, data: payload.data as any }, rsp);
|
||||
const data = await this.core.apis.PacketApi.pkt.operation.sendPacket({ cmd: payload.cmd, data: payload.data as PacketHexStr }, rsp);
|
||||
return typeof data === 'object' ? data.toString('hex') : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
class SetGroupSignBase extends GetPacketStatusDepends<Payload, any> {
|
||||
payloadSchema = SchemaData;
|
||||
class SetGroupSignBase extends GetPacketStatusDepends<Payload, void> {
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
return await this.core.apis.PacketApi.pkt.operation.GroupSign(+payload.group_id);
|
||||
@@ -17,9 +17,9 @@ class SetGroupSignBase extends GetPacketStatusDepends<Payload, any> {
|
||||
}
|
||||
|
||||
export class SetGroupSign extends SetGroupSignBase {
|
||||
actionName = ActionName.SetGroupSign;
|
||||
override actionName = ActionName.SetGroupSign;
|
||||
}
|
||||
|
||||
export class SendGroupSign extends SetGroupSignBase {
|
||||
actionName = ActionName.SendGroupSign;
|
||||
override actionName = ActionName.SendGroupSign;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class SetInputStatus extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.SetInputStatus;
|
||||
|
||||
export class SetInputStatus extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.SetInputStatus;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload) {
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
if (!uid) throw new Error('uid is empty');
|
||||
|
||||
@@ -8,9 +8,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class SetLongNick extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.SetLongNick;
|
||||
payloadSchema = SchemaData;
|
||||
export class SetLongNick extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.SetLongNick;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
return await this.core.apis.UserApi.setLongNick(payload.longNick);
|
||||
|
||||
@@ -11,8 +11,8 @@ const SchemaData = Type.Object({
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class SetOnlineStatus extends OneBotAction<Payload, null> {
|
||||
actionName = ActionName.SetOnlineStatus;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.SetOnlineStatus;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const ret = await this.core.apis.UserApi.setSelfOnlineStatus(
|
||||
|
||||
@@ -11,8 +11,8 @@ const SchemaData = Type.Object({
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export default class SetAvatar extends OneBotAction<Payload, null> {
|
||||
actionName = ActionName.SetQQAvatar;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.SetQQAvatar;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload): Promise<null> {
|
||||
const { path, success } = (await uriToLocalFile(this.core.NapCatTempPath, payload.file));
|
||||
if (!success) {
|
||||
|
||||
@@ -10,9 +10,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class SetSpecialTittle extends GetPacketStatusDepends<Payload, any> {
|
||||
actionName = ActionName.SetSpecialTittle;
|
||||
payloadSchema = SchemaData;
|
||||
export class SetSpecialTittle extends GetPacketStatusDepends<Payload, void> {
|
||||
override actionName = ActionName.SetSpecialTittle;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { GeneralCallResult } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
@@ -10,9 +11,12 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class SharePeer extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.SharePeer;
|
||||
payloadSchema = SchemaData;
|
||||
export class SharePeer extends OneBotAction<Payload, GeneralCallResult & {
|
||||
arkMsg?: string;
|
||||
arkJson?: string;
|
||||
}> {
|
||||
override actionName = ActionName.SharePeer;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
if (payload.group_id) {
|
||||
@@ -20,6 +24,7 @@ export class SharePeer extends OneBotAction<Payload, any> {
|
||||
} else if (payload.user_id) {
|
||||
return await this.core.apis.UserApi.getBuddyRecommendContactArkJson(payload.user_id.toString(), payload.phoneNumber);
|
||||
}
|
||||
throw new Error('group_id or user_id is required');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +34,9 @@ const SchemaDataGroupEx = Type.Object({
|
||||
|
||||
type PayloadGroupEx = Static<typeof SchemaDataGroupEx>;
|
||||
|
||||
export class ShareGroupEx extends OneBotAction<PayloadGroupEx, any> {
|
||||
actionName = ActionName.ShareGroupEx;
|
||||
payloadSchema = SchemaDataGroupEx;
|
||||
export class ShareGroupEx extends OneBotAction<PayloadGroupEx, string> {
|
||||
override actionName = ActionName.ShareGroupEx;
|
||||
override payloadSchema = SchemaDataGroupEx;
|
||||
|
||||
async _handle(payload: PayloadGroupEx) {
|
||||
return await this.core.apis.GroupApi.getArkJsonGroupShare(payload.group_id.toString());
|
||||
|
||||
@@ -8,9 +8,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class TranslateEnWordToZn extends OneBotAction<Payload, Array<any> | null> {
|
||||
actionName = ActionName.TranslateEnWordToZn;
|
||||
payloadSchema = SchemaData;
|
||||
export class TranslateEnWordToZn extends OneBotAction<Payload, Array<unknown> | null> {
|
||||
override actionName = ActionName.TranslateEnWordToZn;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const ret = await this.core.apis.SystemApi.translateEnWordToZn(payload.words);
|
||||
|
||||
Reference in New Issue
Block a user