mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-11 23:40:24 +00:00
refactor: rename extends api folder
This commit is contained in:
20
src/onebot11/action/extends/Config.ts
Normal file
20
src/onebot11/action/extends/Config.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11Config, ob11Config } from '@/onebot11/config';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
|
||||
export class GetConfigAction extends BaseAction<null, OB11Config> {
|
||||
actionName = ActionName.GetConfig;
|
||||
|
||||
protected async _handle(payload: null): Promise<OB11Config> {
|
||||
return ob11Config;
|
||||
}
|
||||
}
|
||||
|
||||
export class SetConfigAction extends BaseAction<OB11Config, void> {
|
||||
actionName = ActionName.SetConfig;
|
||||
|
||||
protected async _handle(payload: OB11Config): Promise<void> {
|
||||
ob11Config.save(payload);
|
||||
}
|
||||
}
|
||||
44
src/onebot11/action/extends/Debug.ts
Normal file
44
src/onebot11/action/extends/Debug.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
// import * as ntqqApi from "../../../ntqqapi/api";
|
||||
import {
|
||||
NTQQMsgApi,
|
||||
NTQQFriendApi,
|
||||
NTQQGroupApi,
|
||||
NTQQUserApi,
|
||||
NTQQFileApi,
|
||||
// NTQQFileCacheApi,
|
||||
NTQQWindowApi,
|
||||
} from '@/core/qqnt/apis';
|
||||
import { ActionName } from '../types';
|
||||
import { log } from '../../../common/utils/log';
|
||||
|
||||
interface Payload {
|
||||
method: string,
|
||||
args: any[],
|
||||
}
|
||||
|
||||
export default class Debug extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.Debug;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
log('debug call ntqq api', payload);
|
||||
const ntqqApi = [NTQQMsgApi, NTQQFriendApi, NTQQGroupApi, NTQQUserApi, NTQQFileApi,
|
||||
// NTQQFileCacheApi,
|
||||
NTQQWindowApi];
|
||||
for (const ntqqApiClass of ntqqApi) {
|
||||
log('ntqqApiClass', ntqqApiClass);
|
||||
const method = (<any>ntqqApiClass)[payload.method];
|
||||
if (method) {
|
||||
const result = method(...payload.args);
|
||||
if (method.constructor.name === 'AsyncFunction') {
|
||||
return await result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
throw `${payload.method}方法 不存在`;
|
||||
|
||||
// const info = await NTQQApi.getUserDetailInfo(friends[0].uid);
|
||||
// return info
|
||||
}
|
||||
}
|
||||
33
src/onebot11/action/extends/GetGroupAddRequest.ts
Normal file
33
src/onebot11/action/extends/GetGroupAddRequest.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { GroupNotify, GroupNotifyStatus } from '../../../ntqqapi/types';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { uid2UinMap } from '../../../common/data';
|
||||
import { NTQQUserApi } from '@/core/qqnt/apis/user';
|
||||
import { NTQQGroupApi } from '@/core/qqnt/apis/group';
|
||||
import { log } from '../../../common/utils/log';
|
||||
|
||||
interface OB11GroupRequestNotify {
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
flag: string
|
||||
}
|
||||
|
||||
export default class GetGroupAddRequest extends BaseAction<null, OB11GroupRequestNotify[]> {
|
||||
actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||
|
||||
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[]> {
|
||||
const data = await NTQQGroupApi.getGroupIgnoreNotifies();
|
||||
// log(data);
|
||||
const notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
|
||||
const returnData: OB11GroupRequestNotify[] = [];
|
||||
for (const notify of notifies) {
|
||||
const uin = uid2UinMap[notify.user1.uid] || (await NTQQUserApi.getUserDetailInfo(notify.user1.uid))?.uin;
|
||||
returnData.push({
|
||||
group_id: parseInt(notify.group.groupCode),
|
||||
user_id: parseInt(uin),
|
||||
flag: notify.seq
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
}
|
||||
43
src/onebot11/action/extends/SetQQAvatar.ts
Normal file
43
src/onebot11/action/extends/SetQQAvatar.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import * as fs from 'node:fs';
|
||||
import { NTQQUserApi } from '@/core/qqnt/apis/user';
|
||||
import { checkFileReceived, uri2local } from '../../../common/utils/file';
|
||||
// import { log } from "../../../common/utils";
|
||||
|
||||
interface Payload {
|
||||
file: string
|
||||
}
|
||||
|
||||
export default class SetAvatar extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetQQAvatar;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const { path, isLocal, errMsg } = (await uri2local(payload.file));
|
||||
if (errMsg){
|
||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||
}
|
||||
if (path) {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQUserApi.setQQAvatar(path);
|
||||
if (!isLocal){
|
||||
fs.unlink(path, () => {});
|
||||
}
|
||||
if (!ret) {
|
||||
throw `头像${payload.file}设置失败,api无返回`;
|
||||
}
|
||||
// log(`头像设置返回:${JSON.stringify(ret)}`)
|
||||
if (ret['result'] == 1004022) {
|
||||
throw `头像${payload.file}设置失败,文件可能不是图片格式`;
|
||||
} else if(ret['result'] != 0) {
|
||||
throw `头像${payload.file}设置失败,未知的错误,${ret['result']}:${ret['errMsg']}`;
|
||||
}
|
||||
} else {
|
||||
if (!isLocal){
|
||||
fs.unlink(path, () => {});
|
||||
}
|
||||
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user