mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
chore: OBAPI
This commit is contained in:
@@ -20,9 +20,7 @@ export default class SetGroupKick extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupKick;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const rejectReq = payload.reject_add_request?.toString() == 'true';
|
||||
await NTQQGroupApi.kickMember(payload.group_id.toString(), [member.uid], rejectReq);
|
||||
return null;
|
||||
|
@@ -17,7 +17,7 @@ export default class SetGroupName extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupName;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name);
|
||||
return null;
|
||||
}
|
||||
|
@@ -1,8 +1,6 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/apis/group';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -19,6 +17,7 @@ export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const enable = payload.enable?.toString() !== 'false';
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
await NTQQGroupApi.banGroup(payload.group_id.toString(), enable);
|
||||
return null;
|
||||
}
|
||||
|
@@ -1,10 +1,7 @@
|
||||
import { NTQQMsgApi } from '@/core/apis';
|
||||
import { ActionName } from '../types';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
import { sleep } from '@/common/utils/helper';
|
||||
import { NTEventDispatch } from '@/common/utils/EventTask';
|
||||
import { NodeIKernelMsgListener } from '@/core';
|
||||
|
||||
const SchemaData = {
|
||||
@@ -26,9 +23,10 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
||||
actionName = ActionName.DeleteMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
|
||||
if (msg) {
|
||||
let ret = NTEventDispatch.RegisterListen<NodeIKernelMsgListener['onMsgInfoListUpdate']>
|
||||
let ret = this.CoreContext.eventWrapper.RegisterListen<NodeIKernelMsgListener['onMsgInfoListUpdate']>
|
||||
(
|
||||
'NodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
1,
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { NTQQMsgApi, NTQQUserApi } from '@/core/apis';
|
||||
import { ChatType, Peer } from '@/core/entities';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
@@ -19,6 +18,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
class ForwardSingleMsg extends BaseAction<Payload, null> {
|
||||
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
if (payload.user_id) {
|
||||
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!peerUid) {
|
||||
@@ -30,7 +30,8 @@ class ForwardSingleMsg extends BaseAction<Payload, null> {
|
||||
}
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const msg = await MessageUnique.getMsgIdAndPeerByShortId(payload.message_id);
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(payload.message_id);
|
||||
if (!msg) {
|
||||
throw new Error(`无法找到消息${payload.message_id}`);
|
||||
}
|
||||
|
@@ -1,10 +1,9 @@
|
||||
import { OB11Message } from '../../types';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import { OB11Constructor } from '../../helper/constructor';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
import { NTQQMsgApi } from '@/core';
|
||||
|
||||
|
||||
export type ReturnDataType = OB11Message
|
||||
@@ -23,6 +22,7 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
|
||||
actionName = ActionName.GetMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
// log("history msg ids", Object.keys(msgHistory));
|
||||
if (!payload.message_id) {
|
||||
throw Error('参数message_id不能为空');
|
||||
|
@@ -16,6 +16,7 @@ type PlayloadType = FromSchema<typeof SchemaData>;
|
||||
|
||||
class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
||||
async getPeer(payload: PlayloadType): Promise<Peer> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
if (payload.user_id) {
|
||||
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!peerUid) {
|
||||
@@ -30,6 +31,7 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
||||
return { chatType: ChatType.group, peerUid: payload.group_id.toString() };
|
||||
}
|
||||
protected async _handle(payload: PlayloadType): Promise<null> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
// 调用API
|
||||
const ret = await NTQQMsgApi.setMsgRead(await this.getPeer(payload));
|
||||
if (ret.result != 0) {
|
||||
@@ -65,6 +67,7 @@ export class MarkAllMsgAsRead extends BaseAction<Payload, null> {
|
||||
actionName = ActionName._MarkAllMsgAsRead;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
await NTQQMsgApi.markallMsgAsRead();
|
||||
return null;
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { OB11MessageData } from '@/onebot11/types';
|
||||
import { OB11MessageData } from '@/onebot/types';
|
||||
|
||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||
function checkUri(uri: string): boolean {
|
||||
|
@@ -19,6 +19,7 @@ export class SetMsgEmojiLike extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetMsgEmojiLike;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||
if (!msg) {
|
||||
throw new Error('msg not found');
|
||||
|
@@ -1,93 +0,0 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import fs from 'fs';
|
||||
import Path from 'path';
|
||||
import {
|
||||
ChatType,
|
||||
ChatCacheListItemBasic,
|
||||
CacheFileType
|
||||
} from '@/core/entities';
|
||||
import { NTQQFileApi, NTQQFileCacheApi } from '@/core/apis/file';
|
||||
import { logError } from '@/common/utils/log';
|
||||
|
||||
export default class CleanCache extends BaseAction<void, void> {
|
||||
actionName = ActionName.CleanCache;
|
||||
|
||||
protected _handle(): Promise<void> {
|
||||
return new Promise<void>(async (res, rej) => {
|
||||
try {
|
||||
// dbUtil.clearCache();
|
||||
const cacheFilePaths: string[] = [];
|
||||
|
||||
await NTQQFileCacheApi.setCacheSilentScan(false);
|
||||
|
||||
cacheFilePaths.push((await NTQQFileCacheApi.getHotUpdateCachePath()));
|
||||
cacheFilePaths.push((await NTQQFileCacheApi.getDesktopTmpPath()));
|
||||
(await NTQQFileCacheApi.getCacheSessionPathList()).forEach((e: { value: string; }) => cacheFilePaths.push(e.value));
|
||||
|
||||
// await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
|
||||
const cacheScanResult = await NTQQFileCacheApi.scanCache();
|
||||
const cacheSize = parseInt(cacheScanResult.size[6]);
|
||||
|
||||
if (cacheScanResult.result !== 0) {
|
||||
throw('Something went wrong while scanning cache. Code: ' + cacheScanResult.result);
|
||||
}
|
||||
|
||||
await NTQQFileCacheApi.setCacheSilentScan(true);
|
||||
if (cacheSize > 0 && cacheFilePaths.length > 2) { // 存在缓存文件且大小不为 0 时执行清理动作
|
||||
// await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
|
||||
deleteCachePath(cacheFilePaths);
|
||||
}
|
||||
|
||||
// 获取聊天记录列表
|
||||
// NOTE: 以防有人不需要删除聊天记录,暂时先注释掉,日后加个开关
|
||||
// const privateChatCache = await getCacheList(ChatType.friend); // 私聊消息
|
||||
// const groupChatCache = await getCacheList(ChatType.group); // 群聊消息
|
||||
// const chatCacheList = [ ...privateChatCache, ...groupChatCache ];
|
||||
const chatCacheList: ChatCacheListItemBasic[] = [];
|
||||
|
||||
// 获取聊天缓存文件列表
|
||||
const cacheFileList: string[] = [];
|
||||
|
||||
for (const name in CacheFileType) {
|
||||
if (!isNaN(parseInt(name))) continue;
|
||||
|
||||
const fileTypeAny: any = CacheFileType[name];
|
||||
const fileType: CacheFileType = fileTypeAny;
|
||||
|
||||
cacheFileList.push(...(await NTQQFileCacheApi.getFileCacheInfo(fileType)).infos.map((file: { fileKey: any; }) => file.fileKey));
|
||||
}
|
||||
|
||||
// 一并清除
|
||||
await NTQQFileCacheApi.clearChatCache(chatCacheList, cacheFileList);
|
||||
res();
|
||||
} catch(e) {
|
||||
logError('清理缓存时发生了错误');
|
||||
rej(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function deleteCachePath(pathList: string[]) {
|
||||
const emptyPath = (path: string) => {
|
||||
if (!fs.existsSync(path)) return;
|
||||
const files = fs.readdirSync(path);
|
||||
files.forEach(file => {
|
||||
const filePath = Path.resolve(path, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.isDirectory()) emptyPath(filePath);
|
||||
else fs.unlinkSync(filePath);
|
||||
});
|
||||
fs.rmdirSync(path);
|
||||
};
|
||||
|
||||
for (const path of pathList) {
|
||||
emptyPath(path);
|
||||
}
|
||||
}
|
||||
|
||||
function getCacheList(type: ChatType) { // NOTE: 做这个方法主要是因为目前还不支持针对频道消息的清理
|
||||
return new Promise<Array<ChatCacheListItemBasic>>((res, rej) => {
|
||||
});
|
||||
}
|
@@ -1,16 +1,14 @@
|
||||
import { selfInfo } from '@/core/data';
|
||||
|
||||
import { OB11User } from '../../types';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import { OB11Constructor } from '../../helper/constructor';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { napCatCore } from '@/core';
|
||||
|
||||
|
||||
class GetLoginInfo extends BaseAction<null, OB11User> {
|
||||
actionName = ActionName.GetLoginInfo;
|
||||
|
||||
protected async _handle(payload: null) {
|
||||
return OB11Constructor.selfInfo(selfInfo);
|
||||
return OB11Constructor.selfInfo(this.CoreContext.selfInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,17 +1,14 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11Status } from '../../types';
|
||||
import { ActionName } from '../types';
|
||||
import { selfInfo, stat } from '@/core/data';
|
||||
|
||||
|
||||
export default class GetStatus extends BaseAction<any, OB11Status> {
|
||||
export default class GetStatus extends BaseAction<any, any> {
|
||||
actionName = ActionName.GetStatus;
|
||||
|
||||
protected async _handle(payload: any): Promise<OB11Status> {
|
||||
protected async _handle(payload: any): Promise<any> {
|
||||
return {
|
||||
online: !!selfInfo.online,
|
||||
online: !!this.CoreContext.selfInfo.online,
|
||||
good: true,
|
||||
stat
|
||||
stat:{}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -1,43 +0,0 @@
|
||||
import { rebootWithNormolLogin, rebootWithQuickLogin } from '@/common/utils/reboot';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { selfInfo } from '@/core/data';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
delay: { type: 'number' }
|
||||
}
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class Reboot extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.Reboot;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
if (payload.delay) {
|
||||
setTimeout(() => {
|
||||
rebootWithQuickLogin(selfInfo.uin);
|
||||
}, payload.delay);
|
||||
} else {
|
||||
rebootWithQuickLogin(selfInfo.uin);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
export class RebootNormal extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.RebootNormal;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
if (payload.delay) {
|
||||
setTimeout(() => {
|
||||
rebootWithNormolLogin();
|
||||
}, payload.delay);
|
||||
} else {
|
||||
rebootWithNormolLogin();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi, WebApi } from '@/core/apis';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
interface Response {
|
||||
cookies: string,
|
||||
@@ -20,6 +20,8 @@ export class GetCookies extends BaseAction<Payload, Response> {
|
||||
actionName = ActionName.GetCookies;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
// if (!payload.domain) {
|
||||
// throw new Error('缺少参数 domain');
|
||||
// }
|
||||
@@ -63,7 +65,7 @@ export class GetCookies extends BaseAction<Payload, Response> {
|
||||
const cookiesObject = await NTQQUserApi.getCookies(payload.domain);
|
||||
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
|
||||
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
|
||||
const bkn = WebApi.genBkn(cookiesObject.p_skey);
|
||||
const bkn = NTQQWebApi.getBknFromCookie(cookiesObject.p_skey);
|
||||
return { cookies, bkn };
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { NTQQUserApi } from '@/core/apis';
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
@@ -18,6 +18,7 @@ export default class SendLike extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SendLike;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
//logDebug('点赞参数', payload);
|
||||
try {
|
||||
const qq = payload.user_id.toString();
|
||||
|
@@ -19,6 +19,7 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetFriendAddRequest;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
const approve = payload.approve?.toString() !== 'false';
|
||||
await NTQQFriendApi.handleFriendRequest(payload.flag, approve);
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user