mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-13 00:10:27 +00:00
chore: run a full eslint
This commit is contained in:
@@ -5,9 +5,11 @@ import { join as joinPath } from 'node:path';
|
||||
import { calculateFileMD5, httpDownload } from '@/common/utils/file';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
interface FileResponse {
|
||||
file: string;
|
||||
file: string;
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -18,9 +20,9 @@ const SchemaData = {
|
||||
headers: {
|
||||
type: ['string', 'array'],
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
@@ -29,6 +31,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GoCQHTTPDownloadFile extends BaseAction<Payload, FileResponse> {
|
||||
actionName = ActionName.GoCQHTTP_DownloadFile;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<FileResponse> {
|
||||
const isRandomName = !payload.name;
|
||||
const name = payload.name || randomUUID();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11ForwardMessage, OB11Message, OB11MessageData } from '../../types';
|
||||
import { NTQQMsgApi } from '@/core/apis';
|
||||
import { OB11Constructor } from '../../helper/data';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
@@ -10,19 +9,20 @@ const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: 'string' },
|
||||
id: { type: 'string' }
|
||||
id: { type: 'string' },
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
interface Response {
|
||||
messages: (OB11Message & { content: OB11MessageData })[];
|
||||
messages: (OB11Message & { content: OB11MessageData })[];
|
||||
}
|
||||
|
||||
export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_GetForwardMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msgId = payload.message_id || payload.id;
|
||||
@@ -40,8 +40,12 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
|
||||
}
|
||||
const msgList = data.msgList;
|
||||
const messages = await Promise.all(msgList.map(async msg => {
|
||||
const resMsg = await OB11Constructor.message(this.CoreContext, msg, "array");
|
||||
resMsg.message_id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)!;
|
||||
const resMsg = await OB11Constructor.message(this.CoreContext, msg, 'array');
|
||||
resMsg.message_id = MessageUnique.createMsg({
|
||||
guildId: '',
|
||||
chatType: msg.chatType,
|
||||
peerUid: msg.peerUid,
|
||||
}, msg.msgId)!;
|
||||
return resMsg;
|
||||
}));
|
||||
messages.map(msg => {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11Message, OB11User } from '../../types';
|
||||
import { OB11Message } from '../../types';
|
||||
import { ActionName } from '../types';
|
||||
import { ChatType, RawMessage } from '@/core/entities';
|
||||
import { NTQQMsgApi } from '@/core/apis/msg';
|
||||
import { OB11Constructor } from '../../helper/data';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
interface Response {
|
||||
messages: OB11Message[];
|
||||
messages: OB11Message[];
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
@@ -17,9 +16,9 @@ const SchemaData = {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
message_seq: { type: 'number' },
|
||||
count: { type: 'number' },
|
||||
reverseOrder: { type: 'boolean' }
|
||||
reverseOrder: { type: 'boolean' },
|
||||
},
|
||||
required: ['user_id']
|
||||
required: ['user_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -27,6 +26,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
||||
actionName = ActionName.GetFriendMsgHistory;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
@@ -53,7 +53,7 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
||||
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
||||
}));
|
||||
//转换消息
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, "array")));
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
|
||||
return { 'messages': ob11MsgList };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { WebHonorType } from '@/core/entities';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
type: { enum: [WebHonorType.ALL, WebHonorType.EMOTION, WebHonorType.LEGEND, WebHonorType.PERFORMER, WebHonorType.STRONG_NEWBIE, WebHonorType.TALKATIVE] }
|
||||
group_id: { type: ['number', 'string'] },
|
||||
type: { enum: [WebHonorType.ALL, WebHonorType.EMOTION, WebHonorType.LEGEND, WebHonorType.PERFORMER, WebHonorType.STRONG_NEWBIE, WebHonorType.TALKATIVE] },
|
||||
},
|
||||
required: ['group_id']
|
||||
required: ['group_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
// enum是不是有点抽象
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
|
||||
actionName = ActionName.GetGroupHonorInfo;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload) {
|
||||
if (!payload.type) {
|
||||
payload.type = WebHonorType.ALL;
|
||||
|
||||
@@ -5,8 +5,9 @@ import { ChatType, Peer, RawMessage } from '@/core/entities';
|
||||
import { OB11Constructor } from '../../helper/data';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
interface Response {
|
||||
messages: OB11Message[];
|
||||
messages: OB11Message[];
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
@@ -15,9 +16,9 @@ const SchemaData = {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
message_seq: { type: 'number' },
|
||||
count: { type: 'number' },
|
||||
reverseOrder: { type: 'boolean' }
|
||||
reverseOrder: { type: 'boolean' },
|
||||
},
|
||||
required: ['group_id']
|
||||
required: ['group_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -25,6 +26,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Response> {
|
||||
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
//处理参数
|
||||
@@ -46,7 +48,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
||||
}));
|
||||
|
||||
//转换消息
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, "array")));
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
|
||||
return { 'messages': ob11MsgList };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,18 +7,18 @@ const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
no_cache: { type: 'boolean' },
|
||||
}
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
export class GetOnlineClient extends BaseAction<void, Array<any>> {
|
||||
actionName = ActionName.GetOnlineClient;
|
||||
|
||||
protected async _handle(payload: void) {
|
||||
//注册监听
|
||||
//注册监听
|
||||
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
|
||||
NTQQSystemApi.getOnlineDev();
|
||||
await sleep(500);
|
||||
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@ import { OB11Constructor } from '../../helper/data';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { calcQQLevel } from '@/common/utils/helper';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['user_id']
|
||||
required: ['user_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -32,7 +33,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
||||
qid: extendData.info.qid,
|
||||
level: extendData.info.qqLevel && calcQQLevel(extendData.info.qqLevel) || 0,
|
||||
login_days: 0,
|
||||
uid: ''
|
||||
uid: '',
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -3,15 +3,16 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { QuickAction, QuickActionEvent } from '@/onebot/types';
|
||||
|
||||
interface Payload{
|
||||
context: QuickActionEvent,
|
||||
operation: QuickAction
|
||||
interface Payload {
|
||||
context: QuickActionEvent,
|
||||
operation: QuickAction
|
||||
}
|
||||
|
||||
export class GoCQHTTPHandleQuickAction extends BaseAction<Payload, null>{
|
||||
export class GoCQHTTPHandleQuickAction extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_HandleQuickAction;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
handleQuickOperation(this.CoreContext,payload.context, payload.operation).then().catch(this.CoreContext.context.logger.logError);
|
||||
handleQuickOperation(this.CoreContext, payload.context, payload.operation).then().catch(this.CoreContext.context.logger.logError);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import SendMsg, { normalize } from '../msg/SendMsg';
|
||||
import { OB11PostSendMsg } from '../../types';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
// 未验证
|
||||
export class GoCQHTTPSendForwardMsg extends SendMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendForwardMsg;
|
||||
|
||||
@@ -3,6 +3,7 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { unlink } from 'node:fs';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -10,21 +11,27 @@ const SchemaData = {
|
||||
content: { type: 'string' },
|
||||
image: { type: 'string' },
|
||||
pinned: { type: 'number' },
|
||||
confirmRequired: { type: 'number' }
|
||||
confirmRequired: { type: 'number' },
|
||||
},
|
||||
required: ['group_id', 'content']
|
||||
required: ['group_id', 'content'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SendGroupNotice extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
||||
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
|
||||
if (payload.image) {
|
||||
//公告图逻辑
|
||||
const { errMsg, path, isLocal, success } = (await uri2local(this.CoreContext.NapCatTempPath,payload.image));
|
||||
const {
|
||||
errMsg,
|
||||
path,
|
||||
isLocal,
|
||||
success,
|
||||
} = (await uri2local(this.CoreContext.NapCatTempPath, payload.image));
|
||||
if (!success) {
|
||||
throw `群公告${payload.image}设置失败,image字段可能格式不正确`;
|
||||
}
|
||||
@@ -37,7 +44,8 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
|
||||
throw `群公告${payload.image}设置失败,图片上传失败`;
|
||||
}
|
||||
if (!isLocal) {
|
||||
unlink(path, () => { });
|
||||
unlink(path, () => {
|
||||
});
|
||||
}
|
||||
UploadImage = ImageUploadResult.picInfo;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { sendMsg } from '@/onebot/action/msg/SendMsg';
|
||||
import { uri2local } from '@/common/utils/file';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -13,9 +14,9 @@ const SchemaData = {
|
||||
file: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
folder: { type: 'string' },
|
||||
folder_id: { type: 'string' }//临时扩展
|
||||
folder_id: { type: 'string' },//临时扩展
|
||||
},
|
||||
required: ['group_id', 'file', 'name']
|
||||
required: ['group_id', 'file', 'name'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -23,6 +24,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
let file = payload.file;
|
||||
if (fs.existsSync(file)) {
|
||||
@@ -33,7 +35,10 @@ export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
||||
throw new Error(downloadResult.errMsg);
|
||||
}
|
||||
const sendFileEle: SendFileElement = await SendMsgElementConstructor.file(this.CoreContext, downloadResult.path, payload.name, payload.folder_id);
|
||||
await sendMsg(this.CoreContext, { chatType: ChatType.group, peerUid: payload.group_id.toString() }, [sendFileEle], [], true);
|
||||
await sendMsg(this.CoreContext, {
|
||||
chatType: ChatType.group,
|
||||
peerUid: payload.group_id.toString(),
|
||||
}, [sendFileEle], [], true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,15 @@ import { sendMsg } from '@/onebot/action/msg/SendMsg';
|
||||
import { uri2local } from '@/common/utils/file';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
file: { type: 'string' },
|
||||
name: { type: 'string' }
|
||||
name: { type: 'string' },
|
||||
},
|
||||
required: ['user_id', 'file', 'name']
|
||||
required: ['user_id', 'file', 'name'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -21,6 +22,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GOCQHTTP_UploadPrivateFile;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
async getPeer(payload: Payload): Promise<Peer> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
@@ -34,6 +36,7 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
|
||||
}
|
||||
throw '缺少参数 user_id';
|
||||
}
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const peer = await this.getPeer(payload);
|
||||
let file = payload.file;
|
||||
|
||||
Reference in New Issue
Block a user