mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 16:20:25 +00:00
style: 强类型大法
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import CanSendRecord, { CanSend } from './CanSendRecord';
|
||||
|
||||
interface ReturnType {
|
||||
yes: boolean;
|
||||
}
|
||||
import { CanSend } from './CanSendRecord';
|
||||
|
||||
export default class CanSendImage extends CanSend {
|
||||
actionName = ActionName.CanSendImage;
|
||||
override actionName = ActionName.CanSendImage;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ interface ReturnType {
|
||||
yes: boolean;
|
||||
}
|
||||
|
||||
export class CanSend extends OneBotAction<any, ReturnType> {
|
||||
async _handle(_payload: void): Promise<ReturnType> {
|
||||
export class CanSend extends OneBotAction<void, ReturnType> {
|
||||
async _handle(): Promise<ReturnType> {
|
||||
return {
|
||||
yes: true,
|
||||
};
|
||||
@@ -15,5 +15,5 @@ export class CanSend extends OneBotAction<any, ReturnType> {
|
||||
|
||||
|
||||
export default class CanSendRecord extends CanSend{
|
||||
actionName = ActionName.CanSendRecord;
|
||||
override actionName = ActionName.CanSendRecord;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
|
||||
export class GetCSRF extends OneBotAction<any, any> {
|
||||
actionName = ActionName.GetCSRF;
|
||||
export class GetCSRF extends OneBotAction<void, { token: number }> {
|
||||
override actionName = ActionName.GetCSRF;
|
||||
|
||||
async _handle(payload: any) {
|
||||
async _handle() {
|
||||
const sKey = await this.core.apis.UserApi.getSKey();
|
||||
if (!sKey) {
|
||||
throw new Error('SKey is undefined');
|
||||
|
||||
@@ -15,14 +15,14 @@ type Payload = Static<typeof SchemaData>;
|
||||
|
||||
|
||||
export class GetCredentials extends OneBotAction<Payload, Response> {
|
||||
actionName = ActionName.GetCredentials;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GetCredentials;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const cookiesObject = await this.core.apis.UserApi.getCookies(payload.domain);
|
||||
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
|
||||
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
|
||||
const bkn = cookiesObject?.skey ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : '';
|
||||
const bkn = cookiesObject?.['skey'] ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : '';
|
||||
return { cookies: cookies, token: +bkn };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
|
||||
class GetLoginInfo extends OneBotAction<null, OB11User> {
|
||||
actionName = ActionName.GetLoginInfo;
|
||||
override actionName = ActionName.GetLoginInfo;
|
||||
|
||||
async _handle(payload: null) {
|
||||
async _handle() {
|
||||
return OB11Construct.selfInfo(this.core.selfInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
|
||||
export default class GetStatus extends OneBotAction<any, any> {
|
||||
actionName = ActionName.GetStatus;
|
||||
interface ResponseType{
|
||||
online: boolean;
|
||||
good: boolean;
|
||||
stat: unknown;
|
||||
}
|
||||
export default class GetStatus extends OneBotAction<void, ResponseType> {
|
||||
override actionName = ActionName.GetStatus;
|
||||
|
||||
async _handle(payload: any): Promise<any> {
|
||||
async _handle(): Promise<ResponseType> {
|
||||
return {
|
||||
online: !!this.core.selfInfo.online,
|
||||
good: true,
|
||||
|
||||
@@ -9,7 +9,7 @@ interface RetData {
|
||||
}
|
||||
|
||||
export class GetGroupSystemMsg extends OneBotAction<void, RetData> {
|
||||
actionName = ActionName.GetGroupSystemMsg;
|
||||
override actionName = ActionName.GetGroupSystemMsg;
|
||||
|
||||
async _handle(): Promise<RetData> {
|
||||
const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, 50);
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
|
||||
import { napCatVersion } from '@/common/version';
|
||||
interface ResponseType {
|
||||
app_name: string;
|
||||
protocol_version: string;
|
||||
app_version: string;
|
||||
}
|
||||
export default class GetVersionInfo extends OneBotAction<void, ResponseType> {
|
||||
override actionName = ActionName.GetVersionInfo;
|
||||
|
||||
export default class GetVersionInfo extends OneBotAction<any, any> {
|
||||
actionName = ActionName.GetVersionInfo;
|
||||
|
||||
async _handle(payload: any): Promise<any> {
|
||||
async _handle(): Promise<ResponseType> {
|
||||
return {
|
||||
app_name: 'NapCat.Onebot',
|
||||
protocol_version: 'v11',
|
||||
|
||||
Reference in New Issue
Block a user