mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
chore: run eslint --fix in onebot module
This commit is contained in:
@@ -5,64 +5,64 @@ import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
class BaseAction<PayloadType, ReturnDataType> {
|
||||
actionName: ActionName = ActionName.Unknown;
|
||||
CoreContext: NapCatCore;
|
||||
private validate: undefined | ValidateFunction<any> = undefined;
|
||||
PayloadSchema: any = undefined;
|
||||
constructor(context: NapCatCore) {
|
||||
actionName: ActionName = ActionName.Unknown;
|
||||
CoreContext: NapCatCore;
|
||||
private validate: undefined | ValidateFunction<any> = undefined;
|
||||
PayloadSchema: any = undefined;
|
||||
constructor(context: NapCatCore) {
|
||||
//注入上下文
|
||||
this.CoreContext = context;
|
||||
}
|
||||
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
||||
if (this.PayloadSchema) {
|
||||
this.validate = new Ajv({ allowUnionTypes: true }).compile(this.PayloadSchema);
|
||||
this.CoreContext = context;
|
||||
}
|
||||
if (this.validate && !this.validate(payload)) {
|
||||
const errors = this.validate.errors as ErrorObject[];
|
||||
const errorMessages: string[] = errors.map((e) => {
|
||||
return `Key: ${e.instancePath.split('/').slice(1).join('.')}, Message: ${e.message}`;
|
||||
});
|
||||
return {
|
||||
valid: false,
|
||||
message: errorMessages.join('\n') as string || '未知错误'
|
||||
};
|
||||
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
||||
if (this.PayloadSchema) {
|
||||
this.validate = new Ajv({ allowUnionTypes: true }).compile(this.PayloadSchema);
|
||||
}
|
||||
if (this.validate && !this.validate(payload)) {
|
||||
const errors = this.validate.errors as ErrorObject[];
|
||||
const errorMessages: string[] = errors.map((e) => {
|
||||
return `Key: ${e.instancePath.split('/').slice(1).join('.')}, Message: ${e.message}`;
|
||||
});
|
||||
return {
|
||||
valid: false,
|
||||
message: errorMessages.join('\n') as string || '未知错误'
|
||||
};
|
||||
}
|
||||
return {
|
||||
valid: true
|
||||
};
|
||||
}
|
||||
return {
|
||||
valid: true
|
||||
};
|
||||
}
|
||||
|
||||
public async handle(payload: PayloadType): Promise<OB11Return<ReturnDataType | null>> {
|
||||
const result = await this.check(payload);
|
||||
if (!result.valid) {
|
||||
return OB11Response.error(result.message, 400);
|
||||
public async handle(payload: PayloadType): Promise<OB11Return<ReturnDataType | null>> {
|
||||
const result = await this.check(payload);
|
||||
if (!result.valid) {
|
||||
return OB11Response.error(result.message, 400);
|
||||
}
|
||||
try {
|
||||
const resData = await this._handle(payload);
|
||||
return OB11Response.ok(resData);
|
||||
} catch (e: any) {
|
||||
this.CoreContext.context.logger.logError('发生错误', e);
|
||||
return OB11Response.error(e?.toString() || e?.stack?.toString() || '未知错误,可能操作超时', 200);
|
||||
}
|
||||
}
|
||||
try {
|
||||
const resData = await this._handle(payload);
|
||||
return OB11Response.ok(resData);
|
||||
} catch (e: any) {
|
||||
this.CoreContext.context.logger.logError('发生错误', e);
|
||||
return OB11Response.error(e?.toString() || e?.stack?.toString() || '未知错误,可能操作超时', 200);
|
||||
}
|
||||
}
|
||||
|
||||
public async websocketHandle(payload: PayloadType, echo: any): Promise<OB11Return<ReturnDataType | null>> {
|
||||
const result = await this.check(payload);
|
||||
if (!result.valid) {
|
||||
return OB11Response.error(result.message, 1400);
|
||||
public async websocketHandle(payload: PayloadType, echo: any): Promise<OB11Return<ReturnDataType | null>> {
|
||||
const result = await this.check(payload);
|
||||
if (!result.valid) {
|
||||
return OB11Response.error(result.message, 1400);
|
||||
}
|
||||
try {
|
||||
const resData = await this._handle(payload);
|
||||
return OB11Response.ok(resData, echo);
|
||||
} catch (e: any) {
|
||||
this.CoreContext.context.logger.logError('发生错误', e);
|
||||
return OB11Response.error(e.stack?.toString() || e.toString(), 1200, echo);
|
||||
}
|
||||
}
|
||||
try {
|
||||
const resData = await this._handle(payload);
|
||||
return OB11Response.ok(resData, echo);
|
||||
} catch (e: any) {
|
||||
this.CoreContext.context.logger.logError('发生错误', e);
|
||||
return OB11Response.error(e.stack?.toString() || e.toString(), 1200, echo);
|
||||
}
|
||||
}
|
||||
|
||||
protected async _handle(payload: PayloadType): Promise<ReturnDataType> {
|
||||
throw `pleas override ${this.actionName} _handle`;
|
||||
}
|
||||
protected async _handle(payload: PayloadType): Promise<ReturnDataType> {
|
||||
throw `pleas override ${this.actionName} _handle`;
|
||||
}
|
||||
}
|
||||
|
||||
export default BaseAction;
|
||||
|
@@ -3,30 +3,30 @@ import { OB11Return } from '../types';
|
||||
import { isNull } from '../../common/utils/helper';
|
||||
|
||||
export class OB11Response {
|
||||
static res<T>(data: T, status: string, retcode: number, message: string = ''): OB11Return<T> {
|
||||
return {
|
||||
status: status,
|
||||
retcode: retcode,
|
||||
data: data,
|
||||
message: message,
|
||||
wording: message,
|
||||
echo: null
|
||||
};
|
||||
}
|
||||
|
||||
static ok<T>(data: T, echo: any = null) {
|
||||
const res = OB11Response.res<T>(data, 'ok', 0);
|
||||
if (!isNull(echo)) {
|
||||
res.echo = echo;
|
||||
static res<T>(data: T, status: string, retcode: number, message: string = ''): OB11Return<T> {
|
||||
return {
|
||||
status: status,
|
||||
retcode: retcode,
|
||||
data: data,
|
||||
message: message,
|
||||
wording: message,
|
||||
echo: null
|
||||
};
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static error(err: string, retcode: number, echo: any = null) {
|
||||
const res = OB11Response.res(null, 'failed', retcode, err);
|
||||
if (!isNull(echo)) {
|
||||
res.echo = echo;
|
||||
static ok<T>(data: T, echo: any = null) {
|
||||
const res = OB11Response.res<T>(data, 'ok', 0);
|
||||
if (!isNull(echo)) {
|
||||
res.echo = echo;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static error(err: string, retcode: number, echo: any = null) {
|
||||
const res = OB11Response.res(null, 'failed', retcode, err);
|
||||
if (!isNull(echo)) {
|
||||
res.echo = echo;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@@ -2,25 +2,25 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
rawData: { type: 'string' },
|
||||
brief: { type: 'string' }
|
||||
},
|
||||
required: ['brief', 'rawData'],
|
||||
type: 'object',
|
||||
properties: {
|
||||
rawData: { type: 'string' },
|
||||
brief: { type: 'string' }
|
||||
},
|
||||
required: ['brief', 'rawData'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class CreateCollection extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.CreateCollection;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
return await this.CoreContext.getApiContext().CollectionApi.createCollection(
|
||||
this.CoreContext.selfInfo.uin,
|
||||
this.CoreContext.selfInfo.uid,
|
||||
this.CoreContext.selfInfo.nick,
|
||||
payload.brief, payload.rawData
|
||||
);
|
||||
}
|
||||
actionName = ActionName.CreateCollection;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
return await this.CoreContext.getApiContext().CollectionApi.createCollection(
|
||||
this.CoreContext.selfInfo.uin,
|
||||
this.CoreContext.selfInfo.uid,
|
||||
this.CoreContext.selfInfo.nick,
|
||||
payload.brief, payload.rawData
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -2,20 +2,20 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
count: { type: 'number' },
|
||||
}
|
||||
type: 'object',
|
||||
properties: {
|
||||
count: { type: 'number' },
|
||||
}
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class FetchCustomFace extends BaseAction<Payload, string[]> {
|
||||
actionName = ActionName.FetchCustomFace;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
actionName = ActionName.FetchCustomFace;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
|
||||
const ret = await this.CoreContext.getApiContext().MsgApi.fetchFavEmojiList(payload.count || 48);
|
||||
return ret.emojiInfoList.map(e => e.url);
|
||||
}
|
||||
const ret = await this.CoreContext.getApiContext().MsgApi.fetchFavEmojiList(payload.count || 48);
|
||||
return ret.emojiInfoList.map(e => e.url);
|
||||
}
|
||||
}
|
||||
|
@@ -4,29 +4,29 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: 'string' },
|
||||
group_id: { type: 'string' },
|
||||
emojiId: { type: 'string' },
|
||||
emojiType: { type: 'string' },
|
||||
message_id: { type: ['string', 'number'] },
|
||||
count: { type: 'number' }
|
||||
},
|
||||
required: ['emojiId', 'emojiType', 'message_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: 'string' },
|
||||
group_id: { type: 'string' },
|
||||
emojiId: { type: 'string' },
|
||||
emojiType: { type: 'string' },
|
||||
message_id: { type: ['string', 'number'] },
|
||||
count: { type: 'number' }
|
||||
},
|
||||
required: ['emojiId', 'emojiType', 'message_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class FetchEmojioLike extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.FetchEmojioLike;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||
if(!msgIdPeer) throw new Error('消息不存在');
|
||||
const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
||||
const ret = await NTQQMsgApi.getMsgEmojiLikesList(msgIdPeer.Peer,msg.msgSeq,payload.emojiId,payload.emojiType,payload.count);
|
||||
return ret;
|
||||
}
|
||||
actionName = ActionName.FetchEmojioLike;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||
if(!msgIdPeer) throw new Error('消息不存在');
|
||||
const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
||||
const ret = await NTQQMsgApi.getMsgEmojiLikesList(msgIdPeer.Peer,msg.msgSeq,payload.emojiId,payload.emojiType,payload.count);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@@ -4,21 +4,21 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
category: { type: 'number' },
|
||||
count: { type: 'number' }
|
||||
},
|
||||
required: ['category', 'count'],
|
||||
type: 'object',
|
||||
properties: {
|
||||
category: { type: 'number' },
|
||||
count: { type: 'number' }
|
||||
},
|
||||
required: ['category', 'count'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class GetCollectionList extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.GetCollectionList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQCollectionApi = this.CoreContext.getApiContext().CollectionApi;
|
||||
return await NTQQCollectionApi.getAllCollection(payload.category, payload.count);
|
||||
}
|
||||
actionName = ActionName.GetCollectionList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQCollectionApi = this.CoreContext.getApiContext().CollectionApi;
|
||||
return await NTQQCollectionApi.getAllCollection(payload.category, payload.count);
|
||||
}
|
||||
}
|
||||
|
@@ -4,14 +4,14 @@ import { ActionName } from '../types';
|
||||
import { OB11Constructor } from '@/onebot/helper/constructor';
|
||||
|
||||
export class GetFriendWithCategory extends BaseAction<void, any> {
|
||||
actionName = ActionName.GetFriendsWithCategory;
|
||||
actionName = ActionName.GetFriendsWithCategory;
|
||||
|
||||
protected async _handle(payload: void) {
|
||||
if (this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) {
|
||||
//全新逻辑
|
||||
return OB11Constructor.friendsV2(await this.CoreContext.getApiContext().FriendApi.getBuddyV2ExWithCate(true));
|
||||
} else {
|
||||
throw new Error('this ntqq version not support, must be 26702 or later');
|
||||
protected async _handle(payload: void) {
|
||||
if (this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) {
|
||||
//全新逻辑
|
||||
return OB11Constructor.friendsV2(await this.CoreContext.getApiContext().FriendApi.getBuddyV2ExWithCate(true));
|
||||
} else {
|
||||
throw new Error('this ntqq version not support, must be 26702 or later');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,21 +9,21 @@ interface OB11GroupRequestNotify {
|
||||
}
|
||||
|
||||
export default class GetGroupAddRequest extends BaseAction<null, OB11GroupRequestNotify[] | null> {
|
||||
actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||
actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||
|
||||
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[] | null> {
|
||||
const data = await this.CoreContext.getApiContext().GroupApi.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 = || (await NTQQUserApi.getUserDetailInfo(notify.user1.uid))?.uin;
|
||||
// returnData.push({
|
||||
// group_id: parseInt(notify.group.groupCode),
|
||||
// user_id: parseInt(uin),
|
||||
// flag: notify.seq
|
||||
// });
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[] | null> {
|
||||
const data = await this.CoreContext.getApiContext().GroupApi.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 = || (await NTQQUserApi.getUserDetailInfo(notify.user1.uid))?.uin;
|
||||
// returnData.push({
|
||||
// group_id: parseInt(notify.group.groupCode),
|
||||
// user_id: parseInt(uin),
|
||||
// flag: notify.seq
|
||||
// });
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
export class GetProfileLike extends BaseAction<void, any> {
|
||||
actionName = ActionName.GetProfileLike;
|
||||
protected async _handle(payload: void) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.getProfileLike(this.CoreContext.selfInfo.uid);
|
||||
const listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos;
|
||||
for (let i = 0; i < listdata.length; i++) {
|
||||
listdata[i].uin = parseInt((await NTQQUserApi.getUinByUid(listdata[i].uid)) || '');
|
||||
actionName = ActionName.GetProfileLike;
|
||||
protected async _handle(payload: void) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.getProfileLike(this.CoreContext.selfInfo.uid);
|
||||
const listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos;
|
||||
for (let i = 0; i < listdata.length; i++) {
|
||||
listdata[i].uin = parseInt((await NTQQUserApi.getUinByUid(listdata[i].uid)) || '');
|
||||
}
|
||||
return listdata;
|
||||
}
|
||||
return listdata;
|
||||
}
|
||||
}
|
||||
|
@@ -2,11 +2,11 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi } from '@/core/apis';
|
||||
export class GetRobotUinRange extends BaseAction<void, Array<any>> {
|
||||
actionName = ActionName.GetRobotUinRange;
|
||||
actionName = ActionName.GetRobotUinRange;
|
||||
|
||||
protected async _handle(payload: void) {
|
||||
protected async _handle(payload: void) {
|
||||
// console.log(await NTQQUserApi.getRobotUinRange());
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
return await NTQQUserApi.getRobotUinRange();
|
||||
}
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
return await NTQQUserApi.getRobotUinRange();
|
||||
}
|
||||
}
|
||||
|
@@ -5,41 +5,41 @@ import { checkFileReceived, uri2local } from '@/common/utils/file';
|
||||
import fs from 'fs';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
image: { type: 'string' },
|
||||
},
|
||||
required: ['image']
|
||||
type: 'object',
|
||||
properties: {
|
||||
image: { type: 'string' },
|
||||
},
|
||||
required: ['image']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class OCRImage extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.OCRImage;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
|
||||
const { path, isLocal, errMsg,success } = (await uri2local(this.CoreContext.NapCatTempPath,payload.image));
|
||||
if (!success) {
|
||||
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
|
||||
actionName = ActionName.OCRImage;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
|
||||
const { path, isLocal, errMsg,success } = (await uri2local(this.CoreContext.NapCatTempPath,payload.image));
|
||||
if (!success) {
|
||||
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
|
||||
}
|
||||
if (path) {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQSystemApi.ORCImage(path);
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
}
|
||||
if (!ret) {
|
||||
throw `OCR ${payload.file}失败`;
|
||||
}
|
||||
return ret.result;
|
||||
}
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
}
|
||||
throw `OCR ${payload.file}失败,文件可能不存在`;
|
||||
}
|
||||
if (path) {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQSystemApi.ORCImage(path);
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
}
|
||||
if (!ret) {
|
||||
throw `OCR ${payload.file}失败`;
|
||||
}
|
||||
return ret.result;
|
||||
}
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
}
|
||||
throw `OCR ${payload.file}失败,文件可能不存在`;
|
||||
}
|
||||
}
|
||||
export class IOCRImage extends OCRImage {
|
||||
actionName = ActionName.IOCRImage;
|
||||
actionName = ActionName.IOCRImage;
|
||||
}
|
||||
|
@@ -11,47 +11,47 @@ interface Payload {
|
||||
}
|
||||
|
||||
export default class SetGroupHeader extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetGroupHeader;
|
||||
// 用不着复杂检测
|
||||
protected async check(payload: Payload): Promise<BaseCheckResult> {
|
||||
if (!payload.file || typeof payload.file != 'string' || !payload.groupCode || typeof payload.groupCode != 'string') {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'file和groupCode字段不能为空或者类型错误',
|
||||
};
|
||||
actionName = ActionName.SetGroupHeader;
|
||||
// 用不着复杂检测
|
||||
protected async check(payload: Payload): Promise<BaseCheckResult> {
|
||||
if (!payload.file || typeof payload.file != 'string' || !payload.groupCode || typeof payload.groupCode != 'string') {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'file和groupCode字段不能为空或者类型错误',
|
||||
};
|
||||
}
|
||||
return {
|
||||
valid: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
valid: true,
|
||||
};
|
||||
}
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
|
||||
if (!success) {
|
||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
|
||||
if (!success) {
|
||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||
}
|
||||
if (path) {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQGroupApi.setGroupAvatar(payload.groupCode, 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']}`;
|
||||
// }
|
||||
return ret;
|
||||
} else {
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
}
|
||||
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (path) {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQGroupApi.setGroupAvatar(payload.groupCode, 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']}`;
|
||||
// }
|
||||
return ret;
|
||||
} else {
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
}
|
||||
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -5,21 +5,21 @@ import { NTQQUserApi } from '@/core/apis';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
longNick: { type: 'string' },
|
||||
},
|
||||
required: [ 'longNick'],
|
||||
type: 'object',
|
||||
properties: {
|
||||
longNick: { type: 'string' },
|
||||
},
|
||||
required: [ 'longNick'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SetLongNick extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetLongNick;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.setLongNick(payload.longNick);
|
||||
return ret;
|
||||
}
|
||||
actionName = ActionName.SetLongNick;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.setLongNick(payload.longNick);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@@ -5,32 +5,32 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
// 设置在线状态
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
status: { type: 'number' },
|
||||
extStatus: { type: 'number' },
|
||||
batteryStatus: { type: 'number' }
|
||||
},
|
||||
required: ['status', 'extStatus', 'batteryStatus'],
|
||||
type: 'object',
|
||||
properties: {
|
||||
status: { type: 'number' },
|
||||
extStatus: { type: 'number' },
|
||||
batteryStatus: { type: 'number' }
|
||||
},
|
||||
required: ['status', 'extStatus', 'batteryStatus'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SetOnlineStatus extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetOnlineStatus;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
actionName = ActionName.SetOnlineStatus;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
// 可设置状态
|
||||
// { status: 10, extStatus: 1027, batteryStatus: 0 }
|
||||
// { status: 30, extStatus: 0, batteryStatus: 0 }
|
||||
// { status: 50, extStatus: 0, batteryStatus: 0 }
|
||||
// { status: 60, extStatus: 0, batteryStatus: 0 }
|
||||
// { status: 70, extStatus: 0, batteryStatus: 0 }
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.setSelfOnlineStatus(payload.status, payload.extStatus, payload.batteryStatus);
|
||||
if (ret.result !== 0) {
|
||||
throw new Error('设置在线状态失败');
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.setSelfOnlineStatus(payload.status, payload.extStatus, payload.batteryStatus);
|
||||
if (ret.result !== 0) {
|
||||
throw new Error('设置在线状态失败');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -7,46 +7,46 @@ interface Payload {
|
||||
}
|
||||
|
||||
export default class SetAvatar extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetQQAvatar;
|
||||
// 用不着复杂检测
|
||||
protected async check(payload: Payload): Promise<BaseCheckResult> {
|
||||
if (!payload.file || typeof payload.file != 'string') {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'file字段不能为空或者类型错误',
|
||||
};
|
||||
actionName = ActionName.SetQQAvatar;
|
||||
// 用不着复杂检测
|
||||
protected async check(payload: Payload): Promise<BaseCheckResult> {
|
||||
if (!payload.file || typeof payload.file != 'string') {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'file字段不能为空或者类型错误',
|
||||
};
|
||||
}
|
||||
return {
|
||||
valid: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
valid: true,
|
||||
};
|
||||
}
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
|
||||
if (!success) {
|
||||
throw `头像${payload.file}设置失败,file字段可能格式不正确`;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
|
||||
if (!success) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -4,29 +4,29 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
nick: { type: 'string' },
|
||||
longNick: { type: 'string' },
|
||||
sex: { type: 'number' }//传Sex值?建议传0
|
||||
},
|
||||
required: ['nick', 'longNick', 'sex'],
|
||||
type: 'object',
|
||||
properties: {
|
||||
nick: { type: 'string' },
|
||||
longNick: { type: 'string' },
|
||||
sex: { type: 'number' }//传Sex值?建议传0
|
||||
},
|
||||
required: ['nick', 'longNick', 'sex'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SetSelfProfile extends BaseAction<Payload, any | null> {
|
||||
actionName = ActionName.SetSelfProfile;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.modifySelfProfile({
|
||||
nick: payload.nick,
|
||||
longNick: payload.longNick,
|
||||
sex: payload.sex,
|
||||
birthday: { birthday_year: '', birthday_month: '', birthday_day: '' },
|
||||
location: undefined
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
actionName = ActionName.SetSelfProfile;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const ret = await NTQQUserApi.modifySelfProfile({
|
||||
nick: payload.nick,
|
||||
longNick: payload.longNick,
|
||||
sex: payload.sex,
|
||||
birthday: { birthday_year: '', birthday_month: '', birthday_day: '' },
|
||||
location: undefined
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@@ -4,27 +4,27 @@ import { NTQQSystemApi } from '@/core/apis';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
words: {
|
||||
type: 'array',
|
||||
items: { type: 'string' }
|
||||
}
|
||||
},
|
||||
required: ['words'],
|
||||
type: 'object',
|
||||
properties: {
|
||||
words: {
|
||||
type: 'array',
|
||||
items: { type: 'string' }
|
||||
}
|
||||
},
|
||||
required: ['words'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class TranslateEnWordToZn extends BaseAction<Payload, Array<any> | null> {
|
||||
actionName = ActionName.TranslateEnWordToZn;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
|
||||
const ret = await NTQQSystemApi.translateEnWordToZn(payload.words);
|
||||
if (ret.result !== 0) {
|
||||
throw new Error('翻译失败');
|
||||
actionName = ActionName.TranslateEnWordToZn;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
|
||||
const ret = await NTQQSystemApi.translateEnWordToZn(payload.words);
|
||||
if (ret.result !== 0) {
|
||||
throw new Error('翻译失败');
|
||||
}
|
||||
return ret.words;
|
||||
}
|
||||
return ret.words;
|
||||
}
|
||||
}
|
||||
|
@@ -3,44 +3,44 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: 'string' },
|
||||
group_id: { type: 'string' },
|
||||
phoneNumber: { type: 'string' },
|
||||
},
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: 'string' },
|
||||
group_id: { type: 'string' },
|
||||
phoneNumber: { type: 'string' },
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
|
||||
export class sharePeer extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SharePeer;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
if (payload.group_id) {
|
||||
return await NTQQGroupApi.getGroupRecommendContactArkJson(payload.group_id);
|
||||
} else if (payload.user_id) {
|
||||
return await NTQQUserApi.getBuddyRecommendContactArkJson(payload.user_id, payload.phoneNumber || '');
|
||||
actionName = ActionName.SharePeer;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
if (payload.group_id) {
|
||||
return await NTQQGroupApi.getGroupRecommendContactArkJson(payload.group_id);
|
||||
} else if (payload.user_id) {
|
||||
return await NTQQUserApi.getBuddyRecommendContactArkJson(payload.user_id, payload.phoneNumber || '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const SchemaDataGroupEx = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: 'string' },
|
||||
},
|
||||
required: ['group_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: 'string' },
|
||||
},
|
||||
required: ['group_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type PayloadGroupEx = FromSchema<typeof SchemaDataGroupEx>;
|
||||
export class shareGroupEx extends BaseAction<PayloadGroupEx, any> {
|
||||
actionName = ActionName.ShareGroupEx;
|
||||
PayloadSchema = SchemaDataGroupEx;
|
||||
protected async _handle(payload: PayloadGroupEx) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
return await NTQQGroupApi.getArkJsonGroupShare(payload.group_id);
|
||||
}
|
||||
actionName = ActionName.ShareGroupEx;
|
||||
PayloadSchema = SchemaDataGroupEx;
|
||||
protected async _handle(payload: PayloadGroupEx) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
return await NTQQGroupApi.getArkJsonGroupShare(payload.group_id);
|
||||
}
|
||||
}
|
@@ -2,21 +2,21 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
file_id: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'file_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
file_id: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'file_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class DelGroupFile extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.DelGroupFile;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
return await NTQQGroupApi.DelGroupFile(payload.group_id.toString(), [payload.file_id]);
|
||||
}
|
||||
actionName = ActionName.DelGroupFile;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
return await NTQQGroupApi.DelGroupFile(payload.group_id.toString(), [payload.file_id]);
|
||||
}
|
||||
}
|
||||
|
@@ -4,21 +4,21 @@ import { ActionName } from '../types';
|
||||
import { NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
folder_id: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'folder_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
folder_id: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'folder_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class DelGroupFileFolder extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.DelGroupFileFolder;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
return (await NTQQGroupApi.DelGroupFileFolder(payload.group_id.toString(), payload.folder_id)).groupFileCommonResult;
|
||||
}
|
||||
actionName = ActionName.DelGroupFileFolder;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
return (await NTQQGroupApi.DelGroupFileFolder(payload.group_id.toString(), payload.folder_id)).groupFileCommonResult;
|
||||
}
|
||||
}
|
||||
|
@@ -17,170 +17,170 @@ export interface GetFileResponse {
|
||||
base64?: string;
|
||||
}
|
||||
const GetFileBase_PayloadSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
file: { type: 'string' }
|
||||
},
|
||||
required: ['file']
|
||||
type: 'object',
|
||||
properties: {
|
||||
file: { type: 'string' }
|
||||
},
|
||||
required: ['file']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
PayloadSchema: any = GetFileBase_PayloadSchema;
|
||||
private getElement(msg: RawMessage): { id: string, element: VideoElement | FileElement } {
|
||||
let element = msg.elements.find(e => e.fileElement);
|
||||
if (!element) {
|
||||
element = msg.elements.find(e => e.videoElement);
|
||||
if (element) {
|
||||
return { id: element.elementId, element: element.videoElement };
|
||||
} else {
|
||||
throw new Error('找不到文件');
|
||||
}
|
||||
PayloadSchema: any = GetFileBase_PayloadSchema;
|
||||
private getElement(msg: RawMessage): { id: string, element: VideoElement | FileElement } {
|
||||
let element = msg.elements.find(e => e.fileElement);
|
||||
if (!element) {
|
||||
element = msg.elements.find(e => e.videoElement);
|
||||
if (element) {
|
||||
return { id: element.elementId, element: element.videoElement };
|
||||
} else {
|
||||
throw new Error('找不到文件');
|
||||
}
|
||||
}
|
||||
return { id: element.elementId, element: element.fileElement };
|
||||
}
|
||||
return { id: element.elementId, element: element.fileElement };
|
||||
}
|
||||
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQFileApi = this.CoreContext.getApiContext().FileApi;
|
||||
let UuidData: {
|
||||
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQFileApi = this.CoreContext.getApiContext().FileApi;
|
||||
let UuidData: {
|
||||
high: string;
|
||||
low: string;
|
||||
} | undefined;
|
||||
try {
|
||||
UuidData = UUIDConverter.decode(payload.file);
|
||||
if (UuidData) {
|
||||
const peerUin = UuidData.high;
|
||||
const msgId = UuidData.low;
|
||||
const isGroup: boolean = !!(await NTQQGroupApi.getGroups(false)).find(e => e.groupCode == peerUin);
|
||||
let peer: Peer | undefined;
|
||||
//识别Peer
|
||||
if (isGroup) {
|
||||
peer = { chatType: ChatType.group, peerUid: peerUin };
|
||||
}
|
||||
const PeerUid = await NTQQUserApi.getUidByUin(peerUin);
|
||||
if (PeerUid) {
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(PeerUid);
|
||||
if (isBuddy) {
|
||||
peer = { chatType: ChatType.friend, peerUid: PeerUid };
|
||||
} else {
|
||||
peer = { chatType: ChatType.temp, peerUid: PeerUid };
|
||||
}
|
||||
}
|
||||
if (!peer) {
|
||||
throw new Error('chattype not support');
|
||||
}
|
||||
const msgList = await NTQQMsgApi.getMsgsByMsgId(peer, [msgId]);
|
||||
if (msgList.msgList.length == 0) {
|
||||
throw new Error('msg not found');
|
||||
}
|
||||
const msg = msgList.msgList[0];
|
||||
const findEle = msg.elements.find(e => e.elementType == ElementType.VIDEO || e.elementType == ElementType.FILE || e.elementType == ElementType.PTT);
|
||||
if (!findEle) {
|
||||
throw new Error('element not found');
|
||||
}
|
||||
const downloadPath = await NTQQFileApi.downloadMedia(msgId, msg.chatType, msg.peerUid, findEle.elementId, '', '');
|
||||
const fileSize = findEle?.videoElement?.fileSize || findEle?.fileElement?.fileSize || findEle?.pttElement?.fileSize || '0';
|
||||
const fileName = findEle?.videoElement?.fileName || findEle?.fileElement?.fileName || findEle?.pttElement?.fileName || '';
|
||||
const res: GetFileResponse = {
|
||||
file: downloadPath,
|
||||
url: downloadPath,
|
||||
file_size: fileSize,
|
||||
file_name: fileName
|
||||
};
|
||||
if (true/*enableLocalFile2Url*/) {
|
||||
try {
|
||||
res.base64 = await fs.readFile(downloadPath, 'base64');
|
||||
} catch (e) {
|
||||
throw new Error('文件下载失败. ' + e);
|
||||
}
|
||||
}
|
||||
//不手动删除?文件持久化了
|
||||
return res;
|
||||
}
|
||||
} catch {
|
||||
|
||||
}
|
||||
|
||||
const NTSearchNameResult = (await NTQQFileApi.searchfile([payload.file])).resultItems;
|
||||
if (NTSearchNameResult.length !== 0) {
|
||||
const MsgId = NTSearchNameResult[0].msgId;
|
||||
let peer: Peer | undefined = undefined;
|
||||
if (NTSearchNameResult[0].chatType == ChatType.group) {
|
||||
peer = { chatType: ChatType.group, peerUid: NTSearchNameResult[0].groupChatInfo[0].groupCode };
|
||||
}
|
||||
if (!peer) {
|
||||
throw new Error('chattype not support');
|
||||
}
|
||||
const msgList: RawMessage[] = (await NTQQMsgApi.getMsgsByMsgId(peer, [MsgId]))?.msgList;
|
||||
if (!msgList || msgList.length == 0) {
|
||||
throw new Error('msg not found');
|
||||
}
|
||||
const msg = msgList[0];
|
||||
const file = msg.elements.filter(e => e.elementType == NTSearchNameResult[0].elemType);
|
||||
if (file.length == 0) {
|
||||
throw new Error('file not found');
|
||||
}
|
||||
const downloadPath = await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, file[0].elementId, '', '');
|
||||
const res: GetFileResponse = {
|
||||
file: downloadPath,
|
||||
url: downloadPath,
|
||||
file_size: NTSearchNameResult[0].fileSize.toString(),
|
||||
file_name: NTSearchNameResult[0].fileName
|
||||
};
|
||||
if (true/*enableLocalFile2Url*/) {
|
||||
try {
|
||||
res.base64 = await fs.readFile(downloadPath, 'base64');
|
||||
} catch (e) {
|
||||
throw new Error('文件下载失败. ' + e);
|
||||
}
|
||||
}
|
||||
//不手动删除?文件持久化了
|
||||
return res;
|
||||
}
|
||||
throw new Error('file not found');
|
||||
// let cache = await dbUtil.getFileCacheByName(payload.file);
|
||||
// if (!cache) {
|
||||
// cache = await dbUtil.getFileCacheByUuid(payload.file);
|
||||
// }
|
||||
// if (!cache) {
|
||||
// throw new Error('file not found');
|
||||
// }
|
||||
// const { enableLocalFile2Url } = ob11Config;
|
||||
// try {
|
||||
// await fs.access(cache.path, fs.constants.F_OK);
|
||||
// } catch (e) {
|
||||
// logDebug('local file not found, start download...');
|
||||
// // if (cache.url) {
|
||||
// // const downloadResult = await uri2local(cache.url);
|
||||
// // if (downloadResult.success) {
|
||||
// // cache.path = downloadResult.path;
|
||||
// // dbUtil.updateFileCache(cache).then();
|
||||
// // } else {
|
||||
// // throw new Error('file download failed. ' + downloadResult.errMsg);
|
||||
// // }
|
||||
// // } else {
|
||||
// // // 没有url的可能是私聊文件或者群文件,需要自己下载
|
||||
// // log('需要调用 NTQQ 下载文件api');
|
||||
// let peer = MessageUnique.getPeerByMsgId(cache.msgId);
|
||||
// let msg = await NTQQMsgApi.getMsgsByMsgId(peer?.Peer!,cache.msgId);
|
||||
// // log('文件 msg', msg);
|
||||
// if (msg) {
|
||||
// // 构建下载函数
|
||||
// const downloadPath = await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
// cache.elementId, '', '');
|
||||
// // await sleep(1000);
|
||||
UuidData = UUIDConverter.decode(payload.file);
|
||||
if (UuidData) {
|
||||
const peerUin = UuidData.high;
|
||||
const msgId = UuidData.low;
|
||||
const isGroup: boolean = !!(await NTQQGroupApi.getGroups(false)).find(e => e.groupCode == peerUin);
|
||||
let peer: Peer | undefined;
|
||||
//识别Peer
|
||||
if (isGroup) {
|
||||
peer = { chatType: ChatType.group, peerUid: peerUin };
|
||||
}
|
||||
const PeerUid = await NTQQUserApi.getUidByUin(peerUin);
|
||||
if (PeerUid) {
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(PeerUid);
|
||||
if (isBuddy) {
|
||||
peer = { chatType: ChatType.friend, peerUid: PeerUid };
|
||||
} else {
|
||||
peer = { chatType: ChatType.temp, peerUid: PeerUid };
|
||||
}
|
||||
}
|
||||
if (!peer) {
|
||||
throw new Error('chattype not support');
|
||||
}
|
||||
const msgList = await NTQQMsgApi.getMsgsByMsgId(peer, [msgId]);
|
||||
if (msgList.msgList.length == 0) {
|
||||
throw new Error('msg not found');
|
||||
}
|
||||
const msg = msgList.msgList[0];
|
||||
const findEle = msg.elements.find(e => e.elementType == ElementType.VIDEO || e.elementType == ElementType.FILE || e.elementType == ElementType.PTT);
|
||||
if (!findEle) {
|
||||
throw new Error('element not found');
|
||||
}
|
||||
const downloadPath = await NTQQFileApi.downloadMedia(msgId, msg.chatType, msg.peerUid, findEle.elementId, '', '');
|
||||
const fileSize = findEle?.videoElement?.fileSize || findEle?.fileElement?.fileSize || findEle?.pttElement?.fileSize || '0';
|
||||
const fileName = findEle?.videoElement?.fileName || findEle?.fileElement?.fileName || findEle?.pttElement?.fileName || '';
|
||||
const res: GetFileResponse = {
|
||||
file: downloadPath,
|
||||
url: downloadPath,
|
||||
file_size: fileSize,
|
||||
file_name: fileName
|
||||
};
|
||||
if (true/*enableLocalFile2Url*/) {
|
||||
try {
|
||||
res.base64 = await fs.readFile(downloadPath, 'base64');
|
||||
} catch (e) {
|
||||
throw new Error('文件下载失败. ' + e);
|
||||
}
|
||||
}
|
||||
//不手动删除?文件持久化了
|
||||
return res;
|
||||
}
|
||||
} catch {
|
||||
|
||||
// // log('download result', downloadPath);
|
||||
// let peer = MessageUnique.getPeerByMsgId(cache.msgId);
|
||||
// msg = await NTQQMsgApi.getMsgsByMsgId(peer?.Peer!,cache.msgId);
|
||||
// // log('下载完成后的msg', msg);
|
||||
// cache.path = downloadPath!;
|
||||
// dbUtil.updateFileCache(cache).then();
|
||||
// // log('下载完成后的msg', msg);
|
||||
// // }
|
||||
// }
|
||||
}
|
||||
|
||||
const NTSearchNameResult = (await NTQQFileApi.searchfile([payload.file])).resultItems;
|
||||
if (NTSearchNameResult.length !== 0) {
|
||||
const MsgId = NTSearchNameResult[0].msgId;
|
||||
let peer: Peer | undefined = undefined;
|
||||
if (NTSearchNameResult[0].chatType == ChatType.group) {
|
||||
peer = { chatType: ChatType.group, peerUid: NTSearchNameResult[0].groupChatInfo[0].groupCode };
|
||||
}
|
||||
if (!peer) {
|
||||
throw new Error('chattype not support');
|
||||
}
|
||||
const msgList: RawMessage[] = (await NTQQMsgApi.getMsgsByMsgId(peer, [MsgId]))?.msgList;
|
||||
if (!msgList || msgList.length == 0) {
|
||||
throw new Error('msg not found');
|
||||
}
|
||||
const msg = msgList[0];
|
||||
const file = msg.elements.filter(e => e.elementType == NTSearchNameResult[0].elemType);
|
||||
if (file.length == 0) {
|
||||
throw new Error('file not found');
|
||||
}
|
||||
const downloadPath = await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, file[0].elementId, '', '');
|
||||
const res: GetFileResponse = {
|
||||
file: downloadPath,
|
||||
url: downloadPath,
|
||||
file_size: NTSearchNameResult[0].fileSize.toString(),
|
||||
file_name: NTSearchNameResult[0].fileName
|
||||
};
|
||||
if (true/*enableLocalFile2Url*/) {
|
||||
try {
|
||||
res.base64 = await fs.readFile(downloadPath, 'base64');
|
||||
} catch (e) {
|
||||
throw new Error('文件下载失败. ' + e);
|
||||
}
|
||||
}
|
||||
//不手动删除?文件持久化了
|
||||
return res;
|
||||
}
|
||||
throw new Error('file not found');
|
||||
// let cache = await dbUtil.getFileCacheByName(payload.file);
|
||||
// if (!cache) {
|
||||
// cache = await dbUtil.getFileCacheByUuid(payload.file);
|
||||
// }
|
||||
// if (!cache) {
|
||||
// throw new Error('file not found');
|
||||
// }
|
||||
// const { enableLocalFile2Url } = ob11Config;
|
||||
// try {
|
||||
// await fs.access(cache.path, fs.constants.F_OK);
|
||||
// } catch (e) {
|
||||
// logDebug('local file not found, start download...');
|
||||
// // if (cache.url) {
|
||||
// // const downloadResult = await uri2local(cache.url);
|
||||
// // if (downloadResult.success) {
|
||||
// // cache.path = downloadResult.path;
|
||||
// // dbUtil.updateFileCache(cache).then();
|
||||
// // } else {
|
||||
// // throw new Error('file download failed. ' + downloadResult.errMsg);
|
||||
// // }
|
||||
// // } else {
|
||||
// // // 没有url的可能是私聊文件或者群文件,需要自己下载
|
||||
// // log('需要调用 NTQQ 下载文件api');
|
||||
// let peer = MessageUnique.getPeerByMsgId(cache.msgId);
|
||||
// let msg = await NTQQMsgApi.getMsgsByMsgId(peer?.Peer!,cache.msgId);
|
||||
// // log('文件 msg', msg);
|
||||
// if (msg) {
|
||||
// // 构建下载函数
|
||||
// const downloadPath = await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||
// cache.elementId, '', '');
|
||||
// // await sleep(1000);
|
||||
|
||||
// // log('download result', downloadPath);
|
||||
// let peer = MessageUnique.getPeerByMsgId(cache.msgId);
|
||||
// msg = await NTQQMsgApi.getMsgsByMsgId(peer?.Peer!,cache.msgId);
|
||||
// // log('下载完成后的msg', msg);
|
||||
// cache.path = downloadPath!;
|
||||
// dbUtil.updateFileCache(cache).then();
|
||||
// // log('下载完成后的msg', msg);
|
||||
// // }
|
||||
// }
|
||||
|
||||
// }
|
||||
// // log('file found', cache);
|
||||
@@ -200,16 +200,16 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
// }
|
||||
// }
|
||||
//return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const GetFile_PayloadSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
file_id: { type: 'string' },
|
||||
file: { type: 'string' }
|
||||
},
|
||||
required: ['file_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
file_id: { type: 'string' },
|
||||
file: { type: 'string' }
|
||||
},
|
||||
required: ['file_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type GetFile_Payload_Internal = FromSchema<typeof GetFile_PayloadSchema>;
|
||||
@@ -219,10 +219,10 @@ interface GetFile_Payload extends GetFile_Payload_Internal {
|
||||
}
|
||||
|
||||
export default class GetFile extends GetFileBase {
|
||||
actionName = ActionName.GetFile;
|
||||
PayloadSchema = GetFile_PayloadSchema;
|
||||
protected async _handle(payload: GetFile_Payload): Promise<GetFileResponse> {
|
||||
payload.file = payload.file_id;
|
||||
return super._handle(payload);
|
||||
}
|
||||
actionName = ActionName.GetFile;
|
||||
PayloadSchema = GetFile_PayloadSchema;
|
||||
protected async _handle(payload: GetFile_Payload): Promise<GetFileResponse> {
|
||||
payload.file = payload.file_id;
|
||||
return super._handle(payload);
|
||||
}
|
||||
}
|
||||
|
@@ -4,21 +4,21 @@ import { ActionName } from '../types';
|
||||
import { NTQQGroupApi, NTQQUserApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class GetGroupFileCount extends BaseAction<Payload, { count: number }> {
|
||||
actionName = ActionName.GetGroupFileCount;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const ret = await NTQQGroupApi.GetGroupFileCount([payload.group_id?.toString()]);
|
||||
return { count: ret.groupFileCounts[0] };
|
||||
}
|
||||
actionName = ActionName.GetGroupFileCount;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const ret = await NTQQGroupApi.GetGroupFileCount([payload.group_id?.toString()]);
|
||||
return { count: ret.groupFileCounts[0] };
|
||||
}
|
||||
}
|
||||
|
@@ -2,29 +2,29 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
start_index: { type: 'number' },
|
||||
file_count: { type: 'number' },
|
||||
},
|
||||
required: ['group_id', 'start_index', 'file_count']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
start_index: { type: 'number' },
|
||||
file_count: { type: 'number' },
|
||||
},
|
||||
required: ['group_id', 'start_index', 'file_count']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class GetGroupFileList extends BaseAction<Payload, { FileList: Array<any> }> {
|
||||
actionName = ActionName.GetGroupFileList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const ret = await NTQQMsgApi.getGroupFileList(payload.group_id.toString(), {
|
||||
sortType: 1,
|
||||
fileCount: payload.file_count,
|
||||
startIndex: payload.start_index,
|
||||
sortOrder: 2,
|
||||
showOnlinedocFolder: 0
|
||||
}).catch((e) => { return []; });
|
||||
return { FileList: ret };
|
||||
}
|
||||
actionName = ActionName.GetGroupFileList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const ret = await NTQQMsgApi.getGroupFileList(payload.group_id.toString(), {
|
||||
sortType: 1,
|
||||
fileCount: payload.file_count,
|
||||
startIndex: payload.start_index,
|
||||
sortOrder: 2,
|
||||
showOnlinedocFolder: 0
|
||||
}).catch((e) => { return []; });
|
||||
return { FileList: ret };
|
||||
}
|
||||
}
|
||||
|
@@ -3,5 +3,5 @@ import { ActionName } from '../types';
|
||||
|
||||
|
||||
export default class GetImage extends GetFileBase {
|
||||
actionName = ActionName.GetImage;
|
||||
actionName = ActionName.GetImage;
|
||||
}
|
@@ -6,10 +6,10 @@ interface Payload extends GetFilePayload {
|
||||
}
|
||||
|
||||
export default class GetRecord extends GetFileBase {
|
||||
actionName = ActionName.GetRecord;
|
||||
actionName = ActionName.GetRecord;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<GetFileResponse> {
|
||||
const res = super._handle(payload);
|
||||
return res;
|
||||
}
|
||||
protected async _handle(payload: Payload): Promise<GetFileResponse> {
|
||||
const res = super._handle(payload);
|
||||
return res;
|
||||
}
|
||||
}
|
@@ -2,21 +2,21 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
folder_name: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'folder_name']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
folder_name: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'folder_name']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SetGroupFileFolder extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetGroupFileFolder;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
return (await NTQQGroupApi.CreatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem;
|
||||
}
|
||||
actionName = ActionName.SetGroupFileFolder;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
return (await NTQQGroupApi.CreatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem;
|
||||
}
|
||||
}
|
||||
|
@@ -9,74 +9,74 @@ interface FileResponse {
|
||||
file: string;
|
||||
}
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
thread_count: { type: 'number' },
|
||||
url: { type: 'string' },
|
||||
base64: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
headers: {
|
||||
type: ['string', 'array'],
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
},
|
||||
type: 'object',
|
||||
properties: {
|
||||
thread_count: { type: 'number' },
|
||||
url: { type: 'string' },
|
||||
base64: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
headers: {
|
||||
type: ['string', 'array'],
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
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();
|
||||
const filePath = joinPath(this.CoreContext.NapCatTempPath, name);
|
||||
actionName = ActionName.GoCQHTTP_DownloadFile;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<FileResponse> {
|
||||
const isRandomName = !payload.name;
|
||||
const name = payload.name || randomUUID();
|
||||
const filePath = joinPath(this.CoreContext.NapCatTempPath, name);
|
||||
|
||||
if (payload.base64) {
|
||||
fs.writeFileSync(filePath, payload.base64, 'base64');
|
||||
} else if (payload.url) {
|
||||
const headers = this.getHeaders(payload.headers);
|
||||
const buffer = await httpDownload({ url: payload.url, headers: headers });
|
||||
fs.writeFileSync(filePath, Buffer.from(buffer), 'binary');
|
||||
} else {
|
||||
throw new Error('不存在任何文件, 无法下载');
|
||||
}
|
||||
if (fs.existsSync(filePath)) {
|
||||
|
||||
if (isRandomName) {
|
||||
// 默认实现要名称未填写时文件名为文件 md5
|
||||
const md5 = await calculateFileMD5(filePath);
|
||||
const newPath = joinPath(this.CoreContext.NapCatTempPath, md5);
|
||||
fs.renameSync(filePath, newPath);
|
||||
return { file: newPath };
|
||||
}
|
||||
return { file: filePath };
|
||||
} else {
|
||||
throw new Error('文件写入失败, 检查权限');
|
||||
}
|
||||
}
|
||||
|
||||
getHeaders(headersIn?: string | string[]): Record<string, string> {
|
||||
const headers: Record<string, string> = {};
|
||||
if (typeof headersIn == 'string') {
|
||||
headersIn = headersIn.split('[\\r\\n]');
|
||||
}
|
||||
if (Array.isArray(headersIn)) {
|
||||
for (const headerItem of headersIn) {
|
||||
const spilt = headerItem.indexOf('=');
|
||||
if (spilt < 0) {
|
||||
headers[headerItem] = '';
|
||||
if (payload.base64) {
|
||||
fs.writeFileSync(filePath, payload.base64, 'base64');
|
||||
} else if (payload.url) {
|
||||
const headers = this.getHeaders(payload.headers);
|
||||
const buffer = await httpDownload({ url: payload.url, headers: headers });
|
||||
fs.writeFileSync(filePath, Buffer.from(buffer), 'binary');
|
||||
} else {
|
||||
const key = headerItem.substring(0, spilt);
|
||||
headers[key] = headerItem.substring(0, spilt + 1);
|
||||
throw new Error('不存在任何文件, 无法下载');
|
||||
}
|
||||
if (fs.existsSync(filePath)) {
|
||||
|
||||
if (isRandomName) {
|
||||
// 默认实现要名称未填写时文件名为文件 md5
|
||||
const md5 = await calculateFileMD5(filePath);
|
||||
const newPath = joinPath(this.CoreContext.NapCatTempPath, md5);
|
||||
fs.renameSync(filePath, newPath);
|
||||
return { file: newPath };
|
||||
}
|
||||
return { file: filePath };
|
||||
} else {
|
||||
throw new Error('文件写入失败, 检查权限');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!headers['Content-Type']) {
|
||||
headers['Content-Type'] = 'application/octet-stream';
|
||||
|
||||
getHeaders(headersIn?: string | string[]): Record<string, string> {
|
||||
const headers: Record<string, string> = {};
|
||||
if (typeof headersIn == 'string') {
|
||||
headersIn = headersIn.split('[\\r\\n]');
|
||||
}
|
||||
if (Array.isArray(headersIn)) {
|
||||
for (const headerItem of headersIn) {
|
||||
const spilt = headerItem.indexOf('=');
|
||||
if (spilt < 0) {
|
||||
headers[headerItem] = '';
|
||||
} else {
|
||||
const key = headerItem.substring(0, spilt);
|
||||
headers[key] = headerItem.substring(0, spilt + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!headers['Content-Type']) {
|
||||
headers['Content-Type'] = 'application/octet-stream';
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
@@ -7,11 +7,11 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: 'string' },
|
||||
id: { type: 'string' }
|
||||
},
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: 'string' },
|
||||
id: { type: 'string' }
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -21,33 +21,33 @@ interface Response {
|
||||
}
|
||||
|
||||
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;
|
||||
if (!msgId) {
|
||||
throw Error('message_id is required');
|
||||
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;
|
||||
if (!msgId) {
|
||||
throw Error('message_id is required');
|
||||
}
|
||||
const rootMsgId = MessageUnique.getShortIdByMsgId(msgId);
|
||||
const rootMsg = MessageUnique.getMsgIdAndPeerByShortId(rootMsgId || parseInt(msgId));
|
||||
if (!rootMsg) {
|
||||
throw Error('msg not found');
|
||||
}
|
||||
const data = await NTQQMsgApi.getMultiMsg(rootMsg.Peer, rootMsg.MsgId, rootMsg.MsgId);
|
||||
if (!data || data.result !== 0) {
|
||||
throw Error('找不到相关的聊天记录' + data?.errMsg);
|
||||
}
|
||||
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)!;
|
||||
return resMsg;
|
||||
}));
|
||||
messages.map(msg => {
|
||||
(<OB11ForwardMessage>msg).content = msg.message;
|
||||
delete (<any>msg).message;
|
||||
});
|
||||
return { messages };
|
||||
}
|
||||
const rootMsgId = MessageUnique.getShortIdByMsgId(msgId);
|
||||
const rootMsg = MessageUnique.getMsgIdAndPeerByShortId(rootMsgId || parseInt(msgId));
|
||||
if (!rootMsg) {
|
||||
throw Error('msg not found');
|
||||
}
|
||||
const data = await NTQQMsgApi.getMultiMsg(rootMsg.Peer, rootMsg.MsgId, rootMsg.MsgId);
|
||||
if (!data || data.result !== 0) {
|
||||
throw Error('找不到相关的聊天记录' + data?.errMsg);
|
||||
}
|
||||
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)!;
|
||||
return resMsg;
|
||||
}));
|
||||
messages.map(msg => {
|
||||
(<OB11ForwardMessage>msg).content = msg.message;
|
||||
delete (<any>msg).message;
|
||||
});
|
||||
return { messages };
|
||||
}
|
||||
}
|
||||
|
@@ -12,48 +12,48 @@ interface Response {
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
message_seq: { type: 'number' },
|
||||
count: { type: 'number' },
|
||||
reverseOrder: { type: 'boolean' }
|
||||
},
|
||||
required: ['user_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
message_seq: { type: 'number' },
|
||||
count: { type: 'number' },
|
||||
reverseOrder: { type: 'boolean' }
|
||||
},
|
||||
required: ['user_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
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;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
//处理参数
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const MsgCount = payload.count || 20;
|
||||
const isReverseOrder = payload.reverseOrder || true;
|
||||
if (!uid) throw `记录${payload.user_id}不存在`;
|
||||
const friend = await NTQQFriendApi.isBuddy(uid);
|
||||
const peer = { chatType: friend ? ChatType.friend : ChatType.temp, peerUid: uid };
|
||||
actionName = ActionName.GetFriendMsgHistory;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
//处理参数
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const MsgCount = payload.count || 20;
|
||||
const isReverseOrder = payload.reverseOrder || true;
|
||||
if (!uid) throw `记录${payload.user_id}不存在`;
|
||||
const friend = await NTQQFriendApi.isBuddy(uid);
|
||||
const peer = { chatType: friend ? ChatType.friend : ChatType.temp, peerUid: uid };
|
||||
|
||||
//拉取消息
|
||||
let msgList: RawMessage[];
|
||||
if (!payload.message_seq || payload.message_seq == 0) {
|
||||
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, MsgCount)).msgList;
|
||||
} else {
|
||||
const startMsgId = MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq)?.MsgId;
|
||||
if (!startMsgId) throw `消息${payload.message_seq}不存在`;
|
||||
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList;
|
||||
//拉取消息
|
||||
let msgList: RawMessage[];
|
||||
if (!payload.message_seq || payload.message_seq == 0) {
|
||||
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, MsgCount)).msgList;
|
||||
} else {
|
||||
const startMsgId = MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq)?.MsgId;
|
||||
if (!startMsgId) throw `消息${payload.message_seq}不存在`;
|
||||
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList;
|
||||
}
|
||||
if (isReverseOrder) msgList.reverse();
|
||||
await Promise.all(msgList.map(async msg => {
|
||||
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")));
|
||||
return { 'messages': ob11MsgList };
|
||||
}
|
||||
if (isReverseOrder) msgList.reverse();
|
||||
await Promise.all(msgList.map(async msg => {
|
||||
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")));
|
||||
return { 'messages': ob11MsgList };
|
||||
}
|
||||
}
|
||||
|
@@ -4,24 +4,24 @@ 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] }
|
||||
},
|
||||
required: ['group_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
type: { enum: [WebHonorType.ALL, WebHonorType.EMOTION, WebHonorType.LEGEND, WebHonorType.PERFORMER, WebHonorType.STRONG_NEWBIE, WebHonorType.TALKATIVE] }
|
||||
},
|
||||
required: ['group_id']
|
||||
} as const satisfies JSONSchema;
|
||||
// enum是不是有点抽象
|
||||
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;
|
||||
actionName = ActionName.GetGroupHonorInfo;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
if (!payload.type) {
|
||||
payload.type = WebHonorType.ALL;
|
||||
}
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
return await NTQQWebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type);
|
||||
}
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
return await NTQQWebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type);
|
||||
}
|
||||
}
|
||||
|
@@ -10,43 +10,43 @@ interface Response {
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
message_seq: { type: 'number' },
|
||||
count: { type: 'number' },
|
||||
reverseOrder: { type: 'boolean' }
|
||||
},
|
||||
required: ['group_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
message_seq: { type: 'number' },
|
||||
count: { type: 'number' },
|
||||
reverseOrder: { type: 'boolean' }
|
||||
},
|
||||
required: ['group_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
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;
|
||||
//处理参数
|
||||
const isReverseOrder = payload.reverseOrder || true;
|
||||
const MsgCount = payload.count || 20;
|
||||
const peer: Peer = { chatType: ChatType.group, peerUid: payload.group_id.toString() };
|
||||
//拉取消息
|
||||
let msgList: RawMessage[];
|
||||
if (!payload.message_seq || payload.message_seq == 0) {
|
||||
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, MsgCount)).msgList;
|
||||
} else {
|
||||
const startMsgId = MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq)?.MsgId;
|
||||
if (!startMsgId) throw `消息${payload.message_seq}不存在`;
|
||||
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList;
|
||||
}
|
||||
if (isReverseOrder) msgList.reverse();
|
||||
await Promise.all(msgList.map(async msg => {
|
||||
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
||||
}));
|
||||
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
//处理参数
|
||||
const isReverseOrder = payload.reverseOrder || true;
|
||||
const MsgCount = payload.count || 20;
|
||||
const peer: Peer = { chatType: ChatType.group, peerUid: payload.group_id.toString() };
|
||||
//拉取消息
|
||||
let msgList: RawMessage[];
|
||||
if (!payload.message_seq || payload.message_seq == 0) {
|
||||
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, MsgCount)).msgList;
|
||||
} else {
|
||||
const startMsgId = MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq)?.MsgId;
|
||||
if (!startMsgId) throw `消息${payload.message_seq}不存在`;
|
||||
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, MsgCount)).msgList;
|
||||
}
|
||||
if (isReverseOrder) msgList.reverse();
|
||||
await Promise.all(msgList.map(async msg => {
|
||||
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")));
|
||||
return { 'messages': ob11MsgList };
|
||||
}
|
||||
//转换消息
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, "array")));
|
||||
return { 'messages': ob11MsgList };
|
||||
}
|
||||
}
|
||||
|
@@ -4,21 +4,21 @@ import { JSONSchema } from 'json-schema-to-ts';
|
||||
import { sleep } from '@/common/utils/helper';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
no_cache: { type: 'boolean' },
|
||||
}
|
||||
type: 'object',
|
||||
properties: {
|
||||
no_cache: { type: 'boolean' },
|
||||
}
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
export class GetOnlineClient extends BaseAction<void, Array<any>> {
|
||||
actionName = ActionName.GetOnlineClient;
|
||||
actionName = ActionName.GetOnlineClient;
|
||||
|
||||
protected async _handle(payload: void) {
|
||||
protected async _handle(payload: void) {
|
||||
//注册监听
|
||||
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
|
||||
NTQQSystemApi.getOnlineDev();
|
||||
await sleep(500);
|
||||
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
|
||||
NTQQSystemApi.getOnlineDev();
|
||||
await sleep(500);
|
||||
|
||||
return [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@@ -5,38 +5,38 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { calcQQLevel } from '@/common/utils/qqlevel';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['user_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['user_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11User> {
|
||||
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<OB11User> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const user_id = payload.user_id.toString();
|
||||
const extendData = await NTQQUserApi.getUserDetailInfoByUin(user_id);
|
||||
const uid = (await NTQQUserApi.getUidByUin(user_id))!;
|
||||
if (!uid || uid.indexOf('*') != -1) {
|
||||
const ret = {
|
||||
...extendData,
|
||||
user_id: parseInt(extendData.info.uin) || 0,
|
||||
nickname: extendData.info.nick,
|
||||
sex: OB11UserSex.unknown,
|
||||
age: (extendData.info.birthday_year == 0) ? 0 : new Date().getFullYear() - extendData.info.birthday_year,
|
||||
qid: extendData.info.qid,
|
||||
level: extendData.info.qqLevel && calcQQLevel(extendData.info.qqLevel) || 0,
|
||||
login_days: 0,
|
||||
uid: ''
|
||||
};
|
||||
return ret;
|
||||
protected async _handle(payload: Payload): Promise<OB11User> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const user_id = payload.user_id.toString();
|
||||
const extendData = await NTQQUserApi.getUserDetailInfoByUin(user_id);
|
||||
const uid = (await NTQQUserApi.getUidByUin(user_id))!;
|
||||
if (!uid || uid.indexOf('*') != -1) {
|
||||
const ret = {
|
||||
...extendData,
|
||||
user_id: parseInt(extendData.info.uin) || 0,
|
||||
nickname: extendData.info.nick,
|
||||
sex: OB11UserSex.unknown,
|
||||
age: (extendData.info.birthday_year == 0) ? 0 : new Date().getFullYear() - extendData.info.birthday_year,
|
||||
qid: extendData.info.qid,
|
||||
level: extendData.info.qqLevel && calcQQLevel(extendData.info.qqLevel) || 0,
|
||||
login_days: 0,
|
||||
uid: ''
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
const data = { ...extendData, ...(await NTQQUserApi.getUserDetailInfo(uid)) };
|
||||
return OB11Constructor.stranger(data);
|
||||
}
|
||||
const data = { ...extendData, ...(await NTQQUserApi.getUserDetailInfo(uid)) };
|
||||
return OB11Constructor.stranger(data);
|
||||
}
|
||||
}
|
||||
|
@@ -8,9 +8,9 @@ interface Payload{
|
||||
}
|
||||
|
||||
export class GoCQHTTPHandleQuickAction extends BaseAction<Payload, null>{
|
||||
actionName = ActionName.GoCQHTTP_HandleQuickAction;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
handleQuickOperation(payload.context, payload.operation,this.CoreContext).then().catch(this.CoreContext.context.logger.logError);
|
||||
return null;
|
||||
}
|
||||
actionName = ActionName.GoCQHTTP_HandleQuickAction;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
handleQuickOperation(payload.context, payload.operation,this.CoreContext).then().catch(this.CoreContext.context.logger.logError);
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -3,18 +3,18 @@ import { OB11PostSendMsg } from '../../types';
|
||||
import { ActionName } from '../types';
|
||||
// 未验证
|
||||
export class GoCQHTTPSendForwardMsg extends SendMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendForwardMsg;
|
||||
actionName = ActionName.GoCQHTTP_SendForwardMsg;
|
||||
|
||||
protected async check(payload: OB11PostSendMsg) {
|
||||
if (payload.messages) payload.message = normalize(payload.messages);
|
||||
return super.check(payload);
|
||||
}
|
||||
protected async check(payload: OB11PostSendMsg) {
|
||||
if (payload.messages) payload.message = normalize(payload.messages);
|
||||
return super.check(payload);
|
||||
}
|
||||
}
|
||||
|
||||
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
|
||||
actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
|
||||
}
|
||||
|
||||
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||
}
|
||||
|
@@ -4,58 +4,58 @@ import { ActionName } from '../types';
|
||||
import { unlink } from 'node:fs';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
content: { type: 'string' },
|
||||
image: { type: 'string' },
|
||||
pinned: { type: 'number' },
|
||||
confirmRequired: { type: 'number' }
|
||||
},
|
||||
required: ['group_id', 'content']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
content: { type: 'string' },
|
||||
image: { type: 'string' },
|
||||
pinned: { type: 'number' },
|
||||
confirmRequired: { type: 'number' }
|
||||
},
|
||||
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));
|
||||
if (!success) {
|
||||
throw `群公告${payload.image}设置失败,image字段可能格式不正确`;
|
||||
}
|
||||
if (!path) {
|
||||
throw `群公告${payload.image}设置失败,获取资源失败`;
|
||||
}
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ImageUploadResult = await NTQQGroupApi.uploadGroupBulletinPic(payload.group_id.toString(), path);
|
||||
if (ImageUploadResult.errCode != 0) {
|
||||
throw `群公告${payload.image}设置失败,图片上传失败`;
|
||||
}
|
||||
if (!isLocal) {
|
||||
unlink(path, () => { });
|
||||
}
|
||||
UploadImage = ImageUploadResult.picInfo;
|
||||
}
|
||||
let Notice_Pinned = 0;
|
||||
let Notice_confirmRequired = 0;
|
||||
if (!payload.pinned) {
|
||||
Notice_Pinned = 0;
|
||||
}
|
||||
if (!payload.confirmRequired) {
|
||||
Notice_confirmRequired = 0;
|
||||
}
|
||||
const PublishGroupBulletinResult = await NTQQGroupApi.publishGroupBulletin(payload.group_id.toString(), payload.content, UploadImage, Notice_Pinned, Notice_confirmRequired);
|
||||
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));
|
||||
if (!success) {
|
||||
throw `群公告${payload.image}设置失败,image字段可能格式不正确`;
|
||||
}
|
||||
if (!path) {
|
||||
throw `群公告${payload.image}设置失败,获取资源失败`;
|
||||
}
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ImageUploadResult = await NTQQGroupApi.uploadGroupBulletinPic(payload.group_id.toString(), path);
|
||||
if (ImageUploadResult.errCode != 0) {
|
||||
throw `群公告${payload.image}设置失败,图片上传失败`;
|
||||
}
|
||||
if (!isLocal) {
|
||||
unlink(path, () => { });
|
||||
}
|
||||
UploadImage = ImageUploadResult.picInfo;
|
||||
}
|
||||
let Notice_Pinned = 0;
|
||||
let Notice_confirmRequired = 0;
|
||||
if (!payload.pinned) {
|
||||
Notice_Pinned = 0;
|
||||
}
|
||||
if (!payload.confirmRequired) {
|
||||
Notice_confirmRequired = 0;
|
||||
}
|
||||
const PublishGroupBulletinResult = await NTQQGroupApi.publishGroupBulletin(payload.group_id.toString(), payload.content, UploadImage, Notice_Pinned, Notice_confirmRequired);
|
||||
|
||||
if (PublishGroupBulletinResult.result != 0) {
|
||||
throw `设置群公告失败,错误信息:${PublishGroupBulletinResult.errMsg}`;
|
||||
if (PublishGroupBulletinResult.result != 0) {
|
||||
throw `设置群公告失败,错误信息:${PublishGroupBulletinResult.errMsg}`;
|
||||
}
|
||||
// 下面实现扬了
|
||||
//await WebApi.setGroupNotice(payload.group_id, payload.content) ;
|
||||
return null;
|
||||
}
|
||||
// 下面实现扬了
|
||||
//await WebApi.setGroupNotice(payload.group_id, payload.content) ;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -7,33 +7,33 @@ 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: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
file: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
folder: { type: 'string' },
|
||||
folder_id: { type: 'string' }//临时扩展
|
||||
},
|
||||
required: ['group_id', 'file', 'name']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
file: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
folder: { type: 'string' },
|
||||
folder_id: { type: 'string' }//临时扩展
|
||||
},
|
||||
required: ['group_id', 'file', 'name']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
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)) {
|
||||
file = `file://${file}`;
|
||||
actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
let file = payload.file;
|
||||
if (fs.existsSync(file)) {
|
||||
file = `file://${file}`;
|
||||
}
|
||||
const downloadResult = await uri2local(this.CoreContext.NapCatTempPath, file);
|
||||
if (!downloadResult.success) {
|
||||
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);
|
||||
return null;
|
||||
}
|
||||
const downloadResult = await uri2local(this.CoreContext.NapCatTempPath, file);
|
||||
if (!downloadResult.success) {
|
||||
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);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import BaseAction from '../BaseAction';;
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { ChatType, Peer, SendFileElement } from '@/core/entities';
|
||||
import fs from 'fs';
|
||||
@@ -7,45 +7,45 @@ 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' }
|
||||
},
|
||||
required: ['user_id', 'file', 'name']
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
file: { type: 'string' },
|
||||
name: { type: 'string' }
|
||||
},
|
||||
required: ['user_id', 'file', 'name']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
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;
|
||||
if (payload.user_id) {
|
||||
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!peerUid) {
|
||||
throw `私聊${payload.user_id}不存在`;
|
||||
}
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(peerUid);
|
||||
return { chatType: isBuddy ? ChatType.friend : ChatType.temp, peerUid };
|
||||
actionName = ActionName.GOCQHTTP_UploadPrivateFile;
|
||||
PayloadSchema = SchemaData;
|
||||
async getPeer(payload: Payload): Promise<Peer> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
if (payload.user_id) {
|
||||
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!peerUid) {
|
||||
throw `私聊${payload.user_id}不存在`;
|
||||
}
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(peerUid);
|
||||
return { chatType: isBuddy ? ChatType.friend : ChatType.temp, peerUid };
|
||||
}
|
||||
throw '缺少参数 user_id';
|
||||
}
|
||||
throw '缺少参数 user_id';
|
||||
}
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const peer = await this.getPeer(payload);
|
||||
let file = payload.file;
|
||||
if (fs.existsSync(file)) {
|
||||
file = `file://${file}`;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const peer = await this.getPeer(payload);
|
||||
let file = payload.file;
|
||||
if (fs.existsSync(file)) {
|
||||
file = `file://${file}`;
|
||||
}
|
||||
const downloadResult = await uri2local(this.CoreContext.NapCatTempPath, file);
|
||||
if (!downloadResult.success) {
|
||||
throw new Error(downloadResult.errMsg);
|
||||
}
|
||||
const sendFileEle: SendFileElement = await SendMsgElementConstructor.file(this.CoreContext, downloadResult.path, payload.name);
|
||||
await sendMsg(this.CoreContext, peer, [sendFileEle], [], true);
|
||||
return null;
|
||||
}
|
||||
const downloadResult = await uri2local(this.CoreContext.NapCatTempPath, file);
|
||||
if (!downloadResult.success) {
|
||||
throw new Error(downloadResult.errMsg);
|
||||
}
|
||||
const sendFileEle: SendFileElement = await SendMsgElementConstructor.file(this.CoreContext, downloadResult.path, payload.name);
|
||||
await sendMsg(this.CoreContext, peer, [sendFileEle], [], true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -5,27 +5,27 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['message_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['message_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class DelEssenceMsg extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.DelEssenceMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||
if (!msg) {
|
||||
throw new Error('msg not found');
|
||||
actionName = ActionName.DelEssenceMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||
if (!msg) {
|
||||
throw new Error('msg not found');
|
||||
}
|
||||
return await NTQQGroupApi.removeGroupEssence(
|
||||
msg.Peer.peerUid,
|
||||
msg.MsgId
|
||||
);
|
||||
}
|
||||
return await NTQQGroupApi.removeGroupEssence(
|
||||
msg.Peer.peerUid,
|
||||
msg.MsgId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -4,25 +4,25 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
pages: { type: 'number' },
|
||||
},
|
||||
required: ['group_id', 'pages']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
pages: { type: 'number' },
|
||||
},
|
||||
required: ['group_id', 'pages']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class GetGroupEssence extends BaseAction<Payload, GroupEssenceMsgRet> {
|
||||
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
const ret = await NTQQWebApi.getGroupEssenceMsg(payload.group_id.toString(), payload.pages.toString());
|
||||
if (!ret) {
|
||||
throw new Error('获取失败');
|
||||
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
const ret = await NTQQWebApi.getGroupEssenceMsg(payload.group_id.toString(), payload.pages.toString());
|
||||
if (!ret) {
|
||||
throw new Error('获取失败');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@@ -5,27 +5,27 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
class GetGroupInfo extends BaseAction<Payload, OB11Group> {
|
||||
actionName = ActionName.GetGroupInfo;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString());
|
||||
if (group) {
|
||||
return OB11Constructor.group(group);
|
||||
} else {
|
||||
throw `群${payload.group_id}不存在`;
|
||||
actionName = ActionName.GetGroupInfo;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString());
|
||||
if (group) {
|
||||
return OB11Constructor.group(group);
|
||||
} else {
|
||||
throw `群${payload.group_id}不存在`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default GetGroupInfo;
|
||||
|
@@ -6,22 +6,22 @@ import { Group } from '@/core/entities';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
// no_cache get时传字符串
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
}
|
||||
type: 'object',
|
||||
properties: {
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
}
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
class GetGroupList extends BaseAction<Payload, OB11Group[]> {
|
||||
actionName = ActionName.GetGroupList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const groupList: Group[] = await NTQQGroupApi.getGroups(payload?.no_cache === true || payload.no_cache === 'true');
|
||||
return OB11Constructor.groups(groupList);
|
||||
}
|
||||
actionName = ActionName.GetGroupList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const groupList: Group[] = await NTQQGroupApi.getGroups(payload?.no_cache === true || payload.no_cache === 'true');
|
||||
return OB11Constructor.groups(groupList);
|
||||
}
|
||||
}
|
||||
|
||||
export default GetGroupList;
|
||||
|
@@ -4,74 +4,74 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] },
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
},
|
||||
required: ['group_id', 'user_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] },
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
},
|
||||
required: ['group_id', 'user_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
||||
actionName = ActionName.GetGroupMemberInfo;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
const isNocache = payload.no_cache == true || payload.no_cache === 'true';
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!uid) {
|
||||
throw (`Uin2Uid Error ${payload.user_id}不存在`);
|
||||
}
|
||||
const member = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache);
|
||||
if (!member) {
|
||||
throw (`群(${payload.group_id})成员${payload.user_id}不存在`);
|
||||
}
|
||||
try {
|
||||
const info = (await NTQQUserApi.getUserDetailInfo(member.uid));
|
||||
this.CoreContext.context.logger.logDebug('群成员详细信息结果', info);
|
||||
Object.assign(member, info);
|
||||
} catch (e) {
|
||||
this.CoreContext.context.logger.logDebug('获取群成员详细信息失败, 只能返回基础信息', e);
|
||||
}
|
||||
const date = Math.round(Date.now() / 1000);
|
||||
const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member);
|
||||
if (!this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) {
|
||||
const SelfInfoInGroup = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), this.CoreContext.selfInfo.uid, isNocache);
|
||||
let isPrivilege = false;
|
||||
if (SelfInfoInGroup) {
|
||||
isPrivilege = SelfInfoInGroup.role === 3 || SelfInfoInGroup.role === 4;
|
||||
}
|
||||
if (isPrivilege) {
|
||||
const webGroupMembers = await NTQQWebApi.getGroupMembers(payload.group_id.toString());
|
||||
for (let i = 0, len = webGroupMembers.length; i < len; i++) {
|
||||
if (webGroupMembers[i]?.uin && webGroupMembers[i].uin === retMember.user_id) {
|
||||
retMember.join_time = webGroupMembers[i]?.join_time;
|
||||
retMember.last_sent_time = webGroupMembers[i]?.last_speak_time;
|
||||
retMember.qage = webGroupMembers[i]?.qage;
|
||||
retMember.level = webGroupMembers[i]?.lv.level.toString();
|
||||
}
|
||||
actionName = ActionName.GetGroupMemberInfo;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
const isNocache = payload.no_cache == true || payload.no_cache === 'true';
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!uid) {
|
||||
throw (`Uin2Uid Error ${payload.user_id}不存在`);
|
||||
}
|
||||
} else {
|
||||
const LastestMsgList = await NTQQGroupApi.getLatestMsg(payload.group_id.toString(), [payload.user_id.toString()]);
|
||||
if (LastestMsgList?.msgList?.length && LastestMsgList?.msgList?.length > 0) {
|
||||
const last_send_time = LastestMsgList.msgList[0].msgTime;
|
||||
if (last_send_time && last_send_time != '0' && last_send_time != '') {
|
||||
retMember.last_sent_time = parseInt(last_send_time);
|
||||
retMember.join_time = Math.round(Date.now() / 1000);//兜底数据 防止群管乱杀
|
||||
}
|
||||
const member = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), uid, isNocache);
|
||||
if (!member) {
|
||||
throw (`群(${payload.group_id})成员${payload.user_id}不存在`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
// retMember.last_sent_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.lastSpeakTime || date.toString());
|
||||
// retMember.join_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.joinTime || date.toString());
|
||||
try {
|
||||
const info = (await NTQQUserApi.getUserDetailInfo(member.uid));
|
||||
this.CoreContext.context.logger.logDebug('群成员详细信息结果', info);
|
||||
Object.assign(member, info);
|
||||
} catch (e) {
|
||||
this.CoreContext.context.logger.logDebug('获取群成员详细信息失败, 只能返回基础信息', e);
|
||||
}
|
||||
const date = Math.round(Date.now() / 1000);
|
||||
const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member);
|
||||
if (!this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) {
|
||||
const SelfInfoInGroup = await NTQQGroupApi.getGroupMemberV2(payload.group_id.toString(), this.CoreContext.selfInfo.uid, isNocache);
|
||||
let isPrivilege = false;
|
||||
if (SelfInfoInGroup) {
|
||||
isPrivilege = SelfInfoInGroup.role === 3 || SelfInfoInGroup.role === 4;
|
||||
}
|
||||
if (isPrivilege) {
|
||||
const webGroupMembers = await NTQQWebApi.getGroupMembers(payload.group_id.toString());
|
||||
for (let i = 0, len = webGroupMembers.length; i < len; i++) {
|
||||
if (webGroupMembers[i]?.uin && webGroupMembers[i].uin === retMember.user_id) {
|
||||
retMember.join_time = webGroupMembers[i]?.join_time;
|
||||
retMember.last_sent_time = webGroupMembers[i]?.last_speak_time;
|
||||
retMember.qage = webGroupMembers[i]?.qage;
|
||||
retMember.level = webGroupMembers[i]?.lv.level.toString();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const LastestMsgList = await NTQQGroupApi.getLatestMsg(payload.group_id.toString(), [payload.user_id.toString()]);
|
||||
if (LastestMsgList?.msgList?.length && LastestMsgList?.msgList?.length > 0) {
|
||||
const last_send_time = LastestMsgList.msgList[0].msgTime;
|
||||
if (last_send_time && last_send_time != '0' && last_send_time != '') {
|
||||
retMember.last_sent_time = parseInt(last_send_time);
|
||||
retMember.join_time = Math.round(Date.now() / 1000);//兜底数据 防止群管乱杀
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
// retMember.last_sent_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.lastSpeakTime || date.toString());
|
||||
// retMember.join_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.joinTime || date.toString());
|
||||
}
|
||||
return retMember;
|
||||
}
|
||||
return retMember;
|
||||
}
|
||||
}
|
||||
export default GetGroupMemberInfo;
|
@@ -5,101 +5,101 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
||||
actionName = ActionName.GetGroupMemberList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
const isNocache = payload.no_cache == true || payload.no_cache === 'true';
|
||||
actionName = ActionName.GetGroupMemberList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
const isNocache = payload.no_cache == true || payload.no_cache === 'true';
|
||||
|
||||
const GroupList = await NTQQGroupApi.getGroups(isNocache);
|
||||
const group = GroupList.find(item => item.groupCode == payload.group_id);
|
||||
if (!group) {
|
||||
throw (`群${payload.group_id}不存在`);
|
||||
}
|
||||
const groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString());
|
||||
const groupMembersArr = Array.from(groupMembers.values());
|
||||
const groupMembersUids = groupMembersArr.map(e => e.uid);
|
||||
let _groupMembers = groupMembersArr.map(item => { return OB11Constructor.groupMember(group.groupCode, item); });
|
||||
|
||||
const MemberMap: Map<number, OB11GroupMember> = new Map<number, OB11GroupMember>();
|
||||
// 转为Map 方便索引
|
||||
let GroupMemberUids: string[] = [];
|
||||
const date = Math.round(Date.now() / 1000);
|
||||
for (let i = 0, len = _groupMembers.length; i < len; i++) {
|
||||
// 保证基础数据有这个 同时避免群管插件过于依赖这个杀了
|
||||
_groupMembers[i].join_time = date;
|
||||
_groupMembers[i].last_sent_time = date;
|
||||
MemberMap.set(_groupMembers[i].user_id, _groupMembers[i]);
|
||||
}
|
||||
|
||||
if (!this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) {
|
||||
const selfRole = groupMembers.get(this.CoreContext.selfInfo.uid)?.role;
|
||||
const isPrivilege = selfRole === 3 || selfRole === 4;
|
||||
|
||||
if (isPrivilege) {
|
||||
const webGroupMembers = await NTQQWebApi.getGroupMembers(payload.group_id.toString());
|
||||
for (let i = 0, len = webGroupMembers.length; i < len; i++) {
|
||||
if (!webGroupMembers[i]?.uin) {
|
||||
continue;
|
||||
}
|
||||
const MemberData = MemberMap.get(webGroupMembers[i]?.uin);
|
||||
if (MemberData) {
|
||||
MemberData.join_time = webGroupMembers[i]?.join_time;
|
||||
MemberData.last_sent_time = webGroupMembers[i]?.last_speak_time;
|
||||
MemberData.qage = webGroupMembers[i]?.qage;
|
||||
MemberData.level = webGroupMembers[i]?.lv.level.toString();
|
||||
MemberMap.set(webGroupMembers[i]?.uin, MemberData);
|
||||
}
|
||||
const GroupList = await NTQQGroupApi.getGroups(isNocache);
|
||||
const group = GroupList.find(item => item.groupCode == payload.group_id);
|
||||
if (!group) {
|
||||
throw (`群${payload.group_id}不存在`);
|
||||
}
|
||||
} else {
|
||||
if (isNocache) {
|
||||
const DateMap = await NTQQGroupApi.getGroupMemberLatestSendTimeCache(payload.group_id.toString(), groupMembersUids);//开始从本地拉取
|
||||
for (const DateUin of DateMap.keys()) {
|
||||
const MemberData = MemberMap.get(parseInt(DateUin));
|
||||
if (MemberData) {
|
||||
MemberData.last_sent_time = parseInt(DateMap.get(DateUin)!);
|
||||
//join_time 有基础数据兜底
|
||||
const groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString());
|
||||
const groupMembersArr = Array.from(groupMembers.values());
|
||||
const groupMembersUids = groupMembersArr.map(e => e.uid);
|
||||
let _groupMembers = groupMembersArr.map(item => { return OB11Constructor.groupMember(group.groupCode, item); });
|
||||
|
||||
const MemberMap: Map<number, OB11GroupMember> = new Map<number, OB11GroupMember>();
|
||||
// 转为Map 方便索引
|
||||
const GroupMemberUids: string[] = [];
|
||||
const date = Math.round(Date.now() / 1000);
|
||||
for (let i = 0, len = _groupMembers.length; i < len; i++) {
|
||||
// 保证基础数据有这个 同时避免群管插件过于依赖这个杀了
|
||||
_groupMembers[i].join_time = date;
|
||||
_groupMembers[i].last_sent_time = date;
|
||||
MemberMap.set(_groupMembers[i].user_id, _groupMembers[i]);
|
||||
}
|
||||
|
||||
if (!this.CoreContext.context.basicInfoWrapper.requireMinNTQQBuild('26702')) {
|
||||
const selfRole = groupMembers.get(this.CoreContext.selfInfo.uid)?.role;
|
||||
const isPrivilege = selfRole === 3 || selfRole === 4;
|
||||
|
||||
if (isPrivilege) {
|
||||
const webGroupMembers = await NTQQWebApi.getGroupMembers(payload.group_id.toString());
|
||||
for (let i = 0, len = webGroupMembers.length; i < len; i++) {
|
||||
if (!webGroupMembers[i]?.uin) {
|
||||
continue;
|
||||
}
|
||||
const MemberData = MemberMap.get(webGroupMembers[i]?.uin);
|
||||
if (MemberData) {
|
||||
MemberData.join_time = webGroupMembers[i]?.join_time;
|
||||
MemberData.last_sent_time = webGroupMembers[i]?.last_speak_time;
|
||||
MemberData.qage = webGroupMembers[i]?.qage;
|
||||
MemberData.level = webGroupMembers[i]?.lv.level.toString();
|
||||
MemberMap.set(webGroupMembers[i]?.uin, MemberData);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isNocache) {
|
||||
const DateMap = await NTQQGroupApi.getGroupMemberLatestSendTimeCache(payload.group_id.toString(), groupMembersUids);//开始从本地拉取
|
||||
for (const DateUin of DateMap.keys()) {
|
||||
const MemberData = MemberMap.get(parseInt(DateUin));
|
||||
if (MemberData) {
|
||||
MemberData.last_sent_time = parseInt(DateMap.get(DateUin)!);
|
||||
//join_time 有基础数据兜底
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_groupMembers.forEach(item => {
|
||||
item.last_sent_time = date;
|
||||
item.join_time = date;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_groupMembers.forEach(item => {
|
||||
item.last_sent_time = date;
|
||||
item.join_time = date;
|
||||
});
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
// _groupMembers.forEach(async item => {
|
||||
// item.last_sent_time = parseInt((await getGroupMember(payload.group_id.toString(), item.user_id))?.lastSpeakTime || date.toString());
|
||||
// item.join_time = parseInt((await getGroupMember(payload.group_id.toString(), item.user_id))?.joinTime || date.toString());
|
||||
// });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
// _groupMembers.forEach(async item => {
|
||||
// item.last_sent_time = parseInt((await getGroupMember(payload.group_id.toString(), item.user_id))?.lastSpeakTime || date.toString());
|
||||
// item.join_time = parseInt((await getGroupMember(payload.group_id.toString(), item.user_id))?.joinTime || date.toString());
|
||||
// });
|
||||
// 还原索引到Array 一同返回
|
||||
|
||||
// let retData: any[] = [];
|
||||
// for (let retMem of MemberMap.values()) {
|
||||
// retMem.level = TypeConvert.toString(retMem.level) as any;
|
||||
// retData.push(retMem)
|
||||
// }
|
||||
|
||||
// _groupMembers = Array.from(retData);
|
||||
|
||||
_groupMembers = Array.from(MemberMap.values());
|
||||
return _groupMembers;
|
||||
}
|
||||
// 还原索引到Array 一同返回
|
||||
|
||||
// let retData: any[] = [];
|
||||
// for (let retMem of MemberMap.values()) {
|
||||
// retMem.level = TypeConvert.toString(retMem.level) as any;
|
||||
// retData.push(retMem)
|
||||
// }
|
||||
|
||||
// _groupMembers = Array.from(retData);
|
||||
|
||||
_groupMembers = Array.from(MemberMap.values());
|
||||
return _groupMembers;
|
||||
}
|
||||
}
|
||||
|
||||
export default GetGroupMemberList;
|
||||
|
@@ -16,11 +16,11 @@ interface GroupNotice {
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
},
|
||||
required: ['group_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
},
|
||||
required: ['group_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -28,33 +28,33 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed;
|
||||
|
||||
export class GetGroupNotice extends BaseAction<Payload, GroupNotice[]> {
|
||||
actionName = ActionName.GoCQHTTP_GetGroupNotice;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
actionName = ActionName.GoCQHTTP_GetGroupNotice;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
|
||||
|
||||
const group = payload.group_id.toString();
|
||||
const ret = await NTQQWebApi.getGroupNotice(group);
|
||||
if (!ret) {
|
||||
throw new Error('获取公告失败');
|
||||
}
|
||||
const retNotices: GroupNotice[] = new Array<ApiGroupNotice>();
|
||||
for (const key in ret.feeds) {
|
||||
const retApiNotice: WebApiGroupNoticeFeed = ret.feeds[key];
|
||||
const retNotice: GroupNotice = {
|
||||
// ...ret.feeds[key],
|
||||
sender_id: retApiNotice.u,
|
||||
publish_time: retApiNotice.pubt,
|
||||
message: {
|
||||
text: retApiNotice.msg.text,
|
||||
image: retApiNotice.msg.pics?.map((pic) => {
|
||||
return { id: pic.id, height: pic.h, width: pic.w };
|
||||
}) || []
|
||||
const group = payload.group_id.toString();
|
||||
const ret = await NTQQWebApi.getGroupNotice(group);
|
||||
if (!ret) {
|
||||
throw new Error('获取公告失败');
|
||||
}
|
||||
const retNotices: GroupNotice[] = new Array<ApiGroupNotice>();
|
||||
for (const key in ret.feeds) {
|
||||
const retApiNotice: WebApiGroupNoticeFeed = ret.feeds[key];
|
||||
const retNotice: GroupNotice = {
|
||||
// ...ret.feeds[key],
|
||||
sender_id: retApiNotice.u,
|
||||
publish_time: retApiNotice.pubt,
|
||||
message: {
|
||||
text: retApiNotice.msg.text,
|
||||
image: retApiNotice.msg.pics?.map((pic) => {
|
||||
return { id: pic.id, height: pic.h, width: pic.w };
|
||||
}) || []
|
||||
}
|
||||
};
|
||||
retNotices.push(retNotice);
|
||||
}
|
||||
};
|
||||
retNotices.push(retNotice);
|
||||
}
|
||||
|
||||
return retNotices;
|
||||
}
|
||||
return retNotices;
|
||||
}
|
||||
}
|
||||
|
@@ -3,46 +3,46 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] }
|
||||
},
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] }
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class GetGroupSystemMsg extends BaseAction<void, any> {
|
||||
actionName = ActionName.GetGroupSystemMsg;
|
||||
protected async _handle(payload: void) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
// 默认10条 该api未完整实现 包括响应数据规范化 类型规范化
|
||||
const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(10);
|
||||
const retData: any = { InvitedRequest: [], join_requests: [] };
|
||||
for (const SSNotify of SingleScreenNotifies) {
|
||||
if (SSNotify.type == 1) {
|
||||
retData.InvitedRequest.push({
|
||||
request_id: SSNotify.seq,
|
||||
invitor_uin: await NTQQUserApi.getUinByUid(SSNotify.user1?.uid),
|
||||
invitor_nick: SSNotify.user1?.nickName,
|
||||
group_id: SSNotify.group?.groupCode,
|
||||
group_name: SSNotify.group?.groupName,
|
||||
checked: SSNotify.status === 1 ? false : true,
|
||||
actor: await NTQQUserApi.getUinByUid(SSNotify.user2?.uid) || 0,
|
||||
});
|
||||
} else if (SSNotify.type == 7) {
|
||||
retData.join_requests.push({
|
||||
request_id: SSNotify.seq,
|
||||
requester_uin: await NTQQUserApi.getUinByUid(SSNotify.user1?.uid),
|
||||
requester_nick: SSNotify.user1?.nickName,
|
||||
group_id: SSNotify.group?.groupCode,
|
||||
group_name: SSNotify.group?.groupName,
|
||||
checked: SSNotify.status === 1 ? false : true,
|
||||
actor: await NTQQUserApi.getUinByUid(SSNotify.user2?.uid) || 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
actionName = ActionName.GetGroupSystemMsg;
|
||||
protected async _handle(payload: void) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
// 默认10条 该api未完整实现 包括响应数据规范化 类型规范化
|
||||
const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(10);
|
||||
const retData: any = { InvitedRequest: [], join_requests: [] };
|
||||
for (const SSNotify of SingleScreenNotifies) {
|
||||
if (SSNotify.type == 1) {
|
||||
retData.InvitedRequest.push({
|
||||
request_id: SSNotify.seq,
|
||||
invitor_uin: await NTQQUserApi.getUinByUid(SSNotify.user1?.uid),
|
||||
invitor_nick: SSNotify.user1?.nickName,
|
||||
group_id: SSNotify.group?.groupCode,
|
||||
group_name: SSNotify.group?.groupName,
|
||||
checked: SSNotify.status === 1 ? false : true,
|
||||
actor: await NTQQUserApi.getUinByUid(SSNotify.user2?.uid) || 0,
|
||||
});
|
||||
} else if (SSNotify.type == 7) {
|
||||
retData.join_requests.push({
|
||||
request_id: SSNotify.seq,
|
||||
requester_uin: await NTQQUserApi.getUinByUid(SSNotify.user1?.uid),
|
||||
requester_nick: SSNotify.user1?.nickName,
|
||||
group_id: SSNotify.group?.groupCode,
|
||||
group_name: SSNotify.group?.groupName,
|
||||
checked: SSNotify.status === 1 ? false : true,
|
||||
actor: await NTQQUserApi.getUinByUid(SSNotify.user2?.uid) || 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return retData;
|
||||
}
|
||||
return retData;
|
||||
}
|
||||
}
|
||||
|
@@ -2,9 +2,9 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
export default class GetGuildList extends BaseAction<null, null> {
|
||||
actionName = ActionName.GetGuildList;
|
||||
actionName = ActionName.GetGuildList;
|
||||
|
||||
protected async _handle(payload: null): Promise<null> {
|
||||
return null;
|
||||
}
|
||||
protected async _handle(payload: null): Promise<null> {
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -4,14 +4,14 @@ import { OB11PostSendMsg } from '../../types';
|
||||
|
||||
// 未检测参数
|
||||
class SendGroupMsg extends SendMsg {
|
||||
actionName = ActionName.SendGroupMsg;
|
||||
contextMode: ContextMode = ContextMode.Group;
|
||||
actionName = ActionName.SendGroupMsg;
|
||||
contextMode: ContextMode = ContextMode.Group;
|
||||
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
delete payload.user_id;
|
||||
payload.message_type = 'group';
|
||||
return super.check(payload);
|
||||
}
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
delete payload.user_id;
|
||||
payload.message_type = 'group';
|
||||
return super.check(payload);
|
||||
}
|
||||
}
|
||||
|
||||
export default SendGroupMsg;
|
||||
|
@@ -4,27 +4,27 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['message_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['message_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class SetEssenceMsg extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetEssenceMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||
if (!msg) {
|
||||
throw new Error('msg not found');
|
||||
actionName = ActionName.SetEssenceMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
||||
if (!msg) {
|
||||
throw new Error('msg not found');
|
||||
}
|
||||
return await NTQQGroupApi.addGroupEssence(
|
||||
msg.Peer.peerUid,
|
||||
msg.MsgId
|
||||
);
|
||||
}
|
||||
return await NTQQGroupApi.addGroupEssence(
|
||||
msg.Peer.peerUid,
|
||||
msg.MsgId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -5,28 +5,28 @@ import { NTQQGroupApi } from '@/core/apis/group';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flag: { type: 'string' },
|
||||
approve: { type: ['string', 'boolean'] },
|
||||
reason: { type: 'string', nullable: true, }
|
||||
},
|
||||
required: ['flag'],
|
||||
type: 'object',
|
||||
properties: {
|
||||
flag: { type: 'string' },
|
||||
approve: { type: ['string', 'boolean'] },
|
||||
reason: { type: 'string', nullable: true, }
|
||||
},
|
||||
required: ['flag'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupAddRequest;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const flag = payload.flag.toString();
|
||||
const approve = payload.approve?.toString() !== 'false';
|
||||
await NTQQGroupApi.handleGroupRequest(flag,
|
||||
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||
payload.reason || " "
|
||||
);
|
||||
return null;
|
||||
}
|
||||
actionName = ActionName.SetGroupAddRequest;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const flag = payload.flag.toString();
|
||||
const approve = payload.approve?.toString() !== 'false';
|
||||
await NTQQGroupApi.handleGroupRequest(flag,
|
||||
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||
payload.reason || " "
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -5,26 +5,26 @@ import { NTQQGroupApi } from '@/core/apis/group';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
user_id: { type: [ 'number' , 'string' ] },
|
||||
enable: { type: 'boolean' }
|
||||
},
|
||||
required: ['group_id', 'user_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
user_id: { type: [ 'number' , 'string' ] },
|
||||
enable: { type: 'boolean' }
|
||||
},
|
||||
required: ['group_id', 'user_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupAdmin;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
let uid = await NTQQUserApi.getUidByUin(payload.user_id.toString())
|
||||
if(!uid) throw new Error('get Uid Error')
|
||||
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal);
|
||||
return null;
|
||||
}
|
||||
actionName = ActionName.SetGroupAdmin;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if(!uid) throw new Error('get Uid Error');
|
||||
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -3,27 +3,27 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] },
|
||||
duration: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['group_id', 'user_id', 'duration']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] },
|
||||
duration: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['group_id', 'user_id', 'duration']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupBan extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupBan;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if(!uid) throw new Error('uid error');
|
||||
await NTQQGroupApi.banMember(payload.group_id.toString(),
|
||||
[{ uid: uid, timeStamp: parseInt(payload.duration.toString()) }]);
|
||||
return null;
|
||||
}
|
||||
actionName = ActionName.SetGroupBan;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if(!uid) throw new Error('uid error');
|
||||
await NTQQGroupApi.banMember(payload.group_id.toString(),
|
||||
[{ uid: uid, timeStamp: parseInt(payload.duration.toString()) }]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -3,23 +3,23 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
user_id: { type: [ 'number' , 'string' ] },
|
||||
card: { type: 'string' }
|
||||
},
|
||||
required: ['group_id', 'user_id', 'card']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
user_id: { type: [ 'number' , 'string' ] },
|
||||
card: { type: 'string' }
|
||||
},
|
||||
required: ['group_id', 'user_id', 'card']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupCard extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupCard;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || '');
|
||||
return null;
|
||||
}
|
||||
actionName = ActionName.SetGroupCard;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || '');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -5,27 +5,27 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
user_id: { type: [ 'number' , 'string' ] },
|
||||
reject_add_request: { type: [ 'boolean' , 'string' ] }
|
||||
},
|
||||
required: ['group_id', 'user_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
user_id: { type: [ 'number' , 'string' ] },
|
||||
reject_add_request: { type: [ 'boolean' , 'string' ] }
|
||||
},
|
||||
required: ['group_id', 'user_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupKick extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupKick;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const rejectReq = payload.reject_add_request?.toString() == 'true';
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if(!uid) throw new Error('get Uid Error')
|
||||
await NTQQGroupApi.kickMember(payload.group_id.toString(), [uid], rejectReq);
|
||||
return null;
|
||||
}
|
||||
actionName = ActionName.SetGroupKick;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const rejectReq = payload.reject_add_request?.toString() == 'true';
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if(!uid) throw new Error('get Uid Error');
|
||||
await NTQQGroupApi.kickMember(payload.group_id.toString(), [uid], rejectReq);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -2,24 +2,20 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
is_dismiss: { type: 'boolean' }
|
||||
},
|
||||
required: ['group_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
is_dismiss: { type: 'boolean' }
|
||||
},
|
||||
required: ['group_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class SetGroupLeave extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetGroupLeave;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
try {
|
||||
await NTQQGroupApi.quitGroup(payload.group_id.toString());
|
||||
} catch (e) {
|
||||
throw e;
|
||||
actionName = ActionName.SetGroupLeave;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
await NTQQGroupApi.quitGroup(payload.group_id.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,21 +4,21 @@ import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/apis/group';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
group_name: { type: 'string' }
|
||||
},
|
||||
required: ['group_id', 'group_name']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
group_name: { type: 'string' }
|
||||
},
|
||||
required: ['group_id', 'group_name']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -2,23 +2,23 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
enable: { type: ['boolean','string'] }
|
||||
},
|
||||
required: ['group_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
enable: { type: ['boolean','string'] }
|
||||
},
|
||||
required: ['group_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupWholeBan;
|
||||
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;
|
||||
}
|
||||
actionName = ActionName.SetGroupWholeBan;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -15,9 +15,9 @@ import CanSendRecord from './system/CanSendRecord';
|
||||
import CanSendImage from './system/CanSendImage';
|
||||
import GetStatus from './system/GetStatus';
|
||||
import {
|
||||
GoCQHTTPSendForwardMsg,
|
||||
GoCQHTTPSendGroupForwardMsg,
|
||||
GoCQHTTPSendPrivateForwardMsg
|
||||
GoCQHTTPSendForwardMsg,
|
||||
GoCQHTTPSendGroupForwardMsg,
|
||||
GoCQHTTPSendPrivateForwardMsg
|
||||
} from './go-cqhttp/SendForwardMsg';
|
||||
import GoCQHTTPGetStrangerInfo from './go-cqhttp/GetStrangerInfo';
|
||||
import SendLike from './user/SendLike';
|
||||
@@ -77,94 +77,94 @@ import { FetchEmojioLike } from './extends/FetchEmojioLike';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
export function createActionMap(context: NapCatCore) {
|
||||
let actionHandlers = [
|
||||
new FetchEmojioLike(context),
|
||||
new GetFile(context),
|
||||
new SetSelfProfile(context),
|
||||
new shareGroupEx(context),
|
||||
new sharePeer(context),
|
||||
new CreateCollection(context),
|
||||
new SetLongNick(context),
|
||||
new ForwardFriendSingleMsg(context),
|
||||
new ForwardGroupSingleMsg(context),
|
||||
new MarkGroupMsgAsRead(context),
|
||||
new MarkPrivateMsgAsRead(context),
|
||||
new SetQQAvatar(context),
|
||||
new TranslateEnWordToZn(context),
|
||||
new GetGroupFileCount(context),
|
||||
new GetGroupFileList(context),
|
||||
new SetGroupFileFolder(context),
|
||||
new DelGroupFile(context),
|
||||
new DelGroupFileFolder(context),
|
||||
// onebot11
|
||||
new SendLike(context),
|
||||
new GetMsg(context),
|
||||
new GetLoginInfo(context),
|
||||
new GetFriendList(context),
|
||||
new GetGroupList(context),
|
||||
new GetGroupInfo(context),
|
||||
new GetGroupMemberList(context),
|
||||
new GetGroupMemberInfo(context),
|
||||
new SendGroupMsg(context),
|
||||
new SendPrivateMsg(context),
|
||||
new SendMsg(context),
|
||||
new DeleteMsg(context),
|
||||
new SetGroupAddRequest(context),
|
||||
new SetFriendAddRequest(context),
|
||||
new SetGroupLeave(context),
|
||||
new GetVersionInfo(context),
|
||||
new CanSendRecord(context),
|
||||
new CanSendImage(context),
|
||||
new GetStatus(context),
|
||||
new SetGroupWholeBan(context),
|
||||
new SetGroupBan(context),
|
||||
new SetGroupKick(context),
|
||||
new SetGroupAdmin(context),
|
||||
new SetGroupName(context),
|
||||
new SetGroupCard(context),
|
||||
new GetImage(context),
|
||||
new GetRecord(context),
|
||||
new SetMsgEmojiLike(context),
|
||||
new GetCookies(context),
|
||||
new SetOnlineStatus(context),
|
||||
new GetRobotUinRange(context),
|
||||
new GetFriendWithCategory(context),
|
||||
//以下为go-cqhttp api
|
||||
new GetOnlineClient(context),
|
||||
new OCRImage(context),
|
||||
new IOCRImage(context),
|
||||
new GetGroupHonorInfo(context),
|
||||
new SendGroupNotice(context),
|
||||
new GetGroupNotice(context),
|
||||
new GetGroupEssence(context),
|
||||
new GoCQHTTPSendForwardMsg(context),
|
||||
new GoCQHTTPSendGroupForwardMsg(context),
|
||||
new GoCQHTTPSendPrivateForwardMsg(context),
|
||||
new GoCQHTTPGetStrangerInfo(context),
|
||||
new GoCQHTTPDownloadFile(context),
|
||||
new GetGuildList(context),
|
||||
new GoCQHTTPMarkMsgAsRead(context),
|
||||
new GoCQHTTPUploadGroupFile(context),
|
||||
new GoCQHTTPGetGroupMsgHistory(context),
|
||||
new GoCQHTTPGetForwardMsgAction(context),
|
||||
new GetFriendMsgHistory(context),
|
||||
new GoCQHTTPHandleQuickAction(context),
|
||||
new GetGroupSystemMsg(context),
|
||||
new DelEssenceMsg(context),
|
||||
new SetEssenceMsg(context),
|
||||
new GetRecentContact(context),
|
||||
new MarkAllMsgAsRead(context),
|
||||
new GetProfileLike(context),
|
||||
new SetGroupHeader(context),
|
||||
new FetchCustomFace(context),
|
||||
new GoCQHTTPUploadPrivateFile(context)
|
||||
];
|
||||
const actionMap = new Map<string, BaseAction<any, any>>();
|
||||
for (const action of actionHandlers) {
|
||||
actionMap.set(action.actionName, action);
|
||||
actionMap.set(action.actionName + '_async', action);
|
||||
actionMap.set(action.actionName + '_rate_limited', action);
|
||||
}
|
||||
const actionHandlers = [
|
||||
new FetchEmojioLike(context),
|
||||
new GetFile(context),
|
||||
new SetSelfProfile(context),
|
||||
new shareGroupEx(context),
|
||||
new sharePeer(context),
|
||||
new CreateCollection(context),
|
||||
new SetLongNick(context),
|
||||
new ForwardFriendSingleMsg(context),
|
||||
new ForwardGroupSingleMsg(context),
|
||||
new MarkGroupMsgAsRead(context),
|
||||
new MarkPrivateMsgAsRead(context),
|
||||
new SetQQAvatar(context),
|
||||
new TranslateEnWordToZn(context),
|
||||
new GetGroupFileCount(context),
|
||||
new GetGroupFileList(context),
|
||||
new SetGroupFileFolder(context),
|
||||
new DelGroupFile(context),
|
||||
new DelGroupFileFolder(context),
|
||||
// onebot11
|
||||
new SendLike(context),
|
||||
new GetMsg(context),
|
||||
new GetLoginInfo(context),
|
||||
new GetFriendList(context),
|
||||
new GetGroupList(context),
|
||||
new GetGroupInfo(context),
|
||||
new GetGroupMemberList(context),
|
||||
new GetGroupMemberInfo(context),
|
||||
new SendGroupMsg(context),
|
||||
new SendPrivateMsg(context),
|
||||
new SendMsg(context),
|
||||
new DeleteMsg(context),
|
||||
new SetGroupAddRequest(context),
|
||||
new SetFriendAddRequest(context),
|
||||
new SetGroupLeave(context),
|
||||
new GetVersionInfo(context),
|
||||
new CanSendRecord(context),
|
||||
new CanSendImage(context),
|
||||
new GetStatus(context),
|
||||
new SetGroupWholeBan(context),
|
||||
new SetGroupBan(context),
|
||||
new SetGroupKick(context),
|
||||
new SetGroupAdmin(context),
|
||||
new SetGroupName(context),
|
||||
new SetGroupCard(context),
|
||||
new GetImage(context),
|
||||
new GetRecord(context),
|
||||
new SetMsgEmojiLike(context),
|
||||
new GetCookies(context),
|
||||
new SetOnlineStatus(context),
|
||||
new GetRobotUinRange(context),
|
||||
new GetFriendWithCategory(context),
|
||||
//以下为go-cqhttp api
|
||||
new GetOnlineClient(context),
|
||||
new OCRImage(context),
|
||||
new IOCRImage(context),
|
||||
new GetGroupHonorInfo(context),
|
||||
new SendGroupNotice(context),
|
||||
new GetGroupNotice(context),
|
||||
new GetGroupEssence(context),
|
||||
new GoCQHTTPSendForwardMsg(context),
|
||||
new GoCQHTTPSendGroupForwardMsg(context),
|
||||
new GoCQHTTPSendPrivateForwardMsg(context),
|
||||
new GoCQHTTPGetStrangerInfo(context),
|
||||
new GoCQHTTPDownloadFile(context),
|
||||
new GetGuildList(context),
|
||||
new GoCQHTTPMarkMsgAsRead(context),
|
||||
new GoCQHTTPUploadGroupFile(context),
|
||||
new GoCQHTTPGetGroupMsgHistory(context),
|
||||
new GoCQHTTPGetForwardMsgAction(context),
|
||||
new GetFriendMsgHistory(context),
|
||||
new GoCQHTTPHandleQuickAction(context),
|
||||
new GetGroupSystemMsg(context),
|
||||
new DelEssenceMsg(context),
|
||||
new SetEssenceMsg(context),
|
||||
new GetRecentContact(context),
|
||||
new MarkAllMsgAsRead(context),
|
||||
new GetProfileLike(context),
|
||||
new SetGroupHeader(context),
|
||||
new FetchCustomFace(context),
|
||||
new GoCQHTTPUploadPrivateFile(context)
|
||||
];
|
||||
const actionMap = new Map<string, BaseAction<any, any>>();
|
||||
for (const action of actionHandlers) {
|
||||
actionMap.set(action.actionName, action);
|
||||
actionMap.set(action.actionName + '_async', action);
|
||||
actionMap.set(action.actionName + '_rate_limited', action);
|
||||
}
|
||||
|
||||
return actionMap;
|
||||
return actionMap;
|
||||
}
|
||||
|
@@ -5,48 +5,48 @@ import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
import { NodeIKernelMsgListener } from '@/core';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: {
|
||||
oneOf: [
|
||||
{ type: 'number' },
|
||||
{ type: 'string' }
|
||||
]
|
||||
}
|
||||
},
|
||||
required: ['message_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: {
|
||||
oneOf: [
|
||||
{ type: 'number' },
|
||||
{ type: 'string' }
|
||||
]
|
||||
}
|
||||
},
|
||||
required: ['message_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
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 = this.CoreContext.eventWrapper.RegisterListen<NodeIKernelMsgListener['onMsgInfoListUpdate']>
|
||||
(
|
||||
'NodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
1,
|
||||
5000,
|
||||
(msgs) => {
|
||||
if (msgs.find(m => m.msgId === msg.MsgId && m.recallTime !== '0')) {
|
||||
return true;
|
||||
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) {
|
||||
const ret = this.CoreContext.eventWrapper.RegisterListen<NodeIKernelMsgListener['onMsgInfoListUpdate']>
|
||||
(
|
||||
'NodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
1,
|
||||
5000,
|
||||
(msgs) => {
|
||||
if (msgs.find(m => m.msgId === msg.MsgId && m.recallTime !== '0')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
).catch(e => new Promise<undefined>((resolve, reject) => { resolve(undefined); }));
|
||||
await NTQQMsgApi.recallMsg(msg.Peer, [msg.MsgId]);
|
||||
const data = await ret;
|
||||
if (!data) {
|
||||
throw new Error('Recall failed');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
).catch(e => new Promise<undefined>((resolve, reject) => { resolve(undefined) }));
|
||||
await NTQQMsgApi.recallMsg(msg.Peer, [msg.MsgId]);
|
||||
let data = await ret;
|
||||
if (!data) {
|
||||
throw new Error('Recall failed');
|
||||
}
|
||||
//await sleep(100);
|
||||
//await NTQQMsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId]);
|
||||
//await sleep(100);
|
||||
//await NTQQMsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default DeleteMsg;
|
||||
|
@@ -5,54 +5,54 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: 'number' },
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['message_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: 'number' },
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['message_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
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) {
|
||||
throw new Error(`无法找到私聊对象${payload.user_id}`);
|
||||
}
|
||||
return { chatType: ChatType.friend, peerUid };
|
||||
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) {
|
||||
throw new Error(`无法找到私聊对象${payload.user_id}`);
|
||||
}
|
||||
return { chatType: ChatType.friend, peerUid };
|
||||
}
|
||||
return { chatType: ChatType.group, peerUid: payload.group_id!.toString() };
|
||||
}
|
||||
return { chatType: ChatType.group, peerUid: payload.group_id!.toString() };
|
||||
}
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(payload.message_id);
|
||||
if (!msg) {
|
||||
throw new Error(`无法找到消息${payload.message_id}`);
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(payload.message_id);
|
||||
if (!msg) {
|
||||
throw new Error(`无法找到消息${payload.message_id}`);
|
||||
}
|
||||
const peer = await this.getTargetPeer(payload);
|
||||
const ret = await NTQQMsgApi.forwardMsg(msg.Peer,
|
||||
peer,
|
||||
[msg.MsgId],
|
||||
);
|
||||
if (ret.result !== 0) {
|
||||
throw new Error(`转发消息失败 ${ret.errMsg}`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const peer = await this.getTargetPeer(payload);
|
||||
const ret = await NTQQMsgApi.forwardMsg(msg.Peer,
|
||||
peer,
|
||||
[msg.MsgId],
|
||||
);
|
||||
if (ret.result !== 0) {
|
||||
throw new Error(`转发消息失败 ${ret.errMsg}`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export class ForwardFriendSingleMsg extends ForwardSingleMsg {
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.ForwardFriendSingleMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.ForwardFriendSingleMsg;
|
||||
}
|
||||
|
||||
export class ForwardGroupSingleMsg extends ForwardSingleMsg {
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.ForwardGroupSingleMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.ForwardGroupSingleMsg;
|
||||
}
|
||||
|
@@ -9,42 +9,42 @@ import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
export type ReturnDataType = OB11Message
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['message_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['message_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
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不能为空');
|
||||
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不能为空');
|
||||
}
|
||||
const MsgShortId = await MessageUnique.getShortIdByMsgId(payload.message_id.toString());
|
||||
const msgIdWithPeer = await MessageUnique.getMsgIdAndPeerByShortId(MsgShortId || parseInt(payload.message_id.toString()));
|
||||
if (!msgIdWithPeer) {
|
||||
throw ('消息不存在');
|
||||
}
|
||||
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
|
||||
const msg = await NTQQMsgApi.getMsgsByMsgId(
|
||||
peer,
|
||||
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
||||
const retMsg = await OB11Constructor.message(this.CoreContext, msg.msgList[0], "array");
|
||||
try {
|
||||
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!;
|
||||
retMsg.message_seq = retMsg.message_id;
|
||||
retMsg.real_id = retMsg.message_id;
|
||||
} catch (e) {
|
||||
}
|
||||
return retMsg;
|
||||
}
|
||||
const MsgShortId = await MessageUnique.getShortIdByMsgId(payload.message_id.toString());
|
||||
const msgIdWithPeer = await MessageUnique.getMsgIdAndPeerByShortId(MsgShortId || parseInt(payload.message_id.toString()));
|
||||
if (!msgIdWithPeer) {
|
||||
throw ('消息不存在');
|
||||
}
|
||||
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
|
||||
const msg = await NTQQMsgApi.getMsgsByMsgId(
|
||||
peer,
|
||||
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
||||
const retMsg = await OB11Constructor.message(this.CoreContext, msg.msgList[0], "array");
|
||||
try {
|
||||
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!;
|
||||
retMsg.message_seq = retMsg.message_id;
|
||||
retMsg.real_id = retMsg.message_id;
|
||||
} catch (e) {
|
||||
}
|
||||
return retMsg;
|
||||
}
|
||||
}
|
||||
|
||||
export default GetMsg;
|
||||
|
@@ -5,50 +5,50 @@ import { NTQQFriendApi, NTQQMsgApi, NTQQUserApi } from '@/core/apis';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
group_id: { type: ['number', 'string'] }
|
||||
}
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
group_id: { type: ['number', 'string'] }
|
||||
}
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type PlayloadType = FromSchema<typeof SchemaData>;
|
||||
|
||||
class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
||||
async getPeer(payload: PlayloadType): Promise<Peer> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
if (payload.user_id) {
|
||||
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!peerUid) {
|
||||
throw `私聊${payload.user_id}不存在`;
|
||||
}
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(peerUid);
|
||||
return { chatType: isBuddy ? ChatType.friend : ChatType.temp, peerUid };
|
||||
async getPeer(payload: PlayloadType): Promise<Peer> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
if (payload.user_id) {
|
||||
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!peerUid) {
|
||||
throw `私聊${payload.user_id}不存在`;
|
||||
}
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(peerUid);
|
||||
return { chatType: isBuddy ? ChatType.friend : ChatType.temp, peerUid };
|
||||
}
|
||||
if (!payload.group_id) {
|
||||
throw '缺少参数 group_id 或 user_id';
|
||||
}
|
||||
return { chatType: ChatType.group, peerUid: payload.group_id.toString() };
|
||||
}
|
||||
if (!payload.group_id) {
|
||||
throw '缺少参数 group_id 或 user_id';
|
||||
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) {
|
||||
throw ('设置已读失败,' + ret.errMsg);
|
||||
}
|
||||
return 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) {
|
||||
throw ('设置已读失败,' + ret.errMsg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 以下为非标准实现
|
||||
export class MarkPrivateMsgAsRead extends MarkMsgAsRead {
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.MarkPrivateMsgAsRead;
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.MarkPrivateMsgAsRead;
|
||||
}
|
||||
export class MarkGroupMsgAsRead extends MarkMsgAsRead {
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.MarkGroupMsgAsRead;
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.MarkGroupMsgAsRead;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,19 +57,19 @@ interface Payload {
|
||||
}
|
||||
|
||||
export class GoCQHTTPMarkMsgAsRead extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_MarkMsgAsRead;
|
||||
actionName = ActionName.GoCQHTTP_MarkMsgAsRead;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
return null;
|
||||
}
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export class MarkAllMsgAsRead extends BaseAction<Payload, null> {
|
||||
actionName = ActionName._MarkAllMsgAsRead;
|
||||
actionName = ActionName._MarkAllMsgAsRead;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
await NTQQMsgApi.markallMsgAsRead();
|
||||
return null;
|
||||
}
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
await NTQQMsgApi.markallMsgAsRead();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,36 +1,36 @@
|
||||
import { OB11MessageData } from '@/onebot/types';
|
||||
|
||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||
function checkUri(uri: string): boolean {
|
||||
const pattern = /^(file:\/\/|http:\/\/|https:\/\/|base64:\/\/)/;
|
||||
return pattern.test(uri);
|
||||
}
|
||||
|
||||
for (const msg of sendMsgList) {
|
||||
if (msg['type'] && msg['data']) {
|
||||
const type = msg['type'];
|
||||
const data = msg['data'];
|
||||
if (type === 'text' && !data['text']) {
|
||||
return 400;
|
||||
} else if (['image', 'voice', 'record'].includes(type)) {
|
||||
if (!data['file']) {
|
||||
return 400;
|
||||
} else {
|
||||
if (checkUri(data['file'])) {
|
||||
return 200;
|
||||
} else {
|
||||
return 400;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (type === 'at' && !data['qq']) {
|
||||
return 400;
|
||||
} else if (type === 'reply' && !data['id']) {
|
||||
return 400;
|
||||
}
|
||||
} else {
|
||||
return 400;
|
||||
function checkUri(uri: string): boolean {
|
||||
const pattern = /^(file:\/\/|http:\/\/|https:\/\/|base64:\/\/)/;
|
||||
return pattern.test(uri);
|
||||
}
|
||||
}
|
||||
return 200;
|
||||
|
||||
for (const msg of sendMsgList) {
|
||||
if (msg['type'] && msg['data']) {
|
||||
const type = msg['type'];
|
||||
const data = msg['data'];
|
||||
if (type === 'text' && !data['text']) {
|
||||
return 400;
|
||||
} else if (['image', 'voice', 'record'].includes(type)) {
|
||||
if (!data['file']) {
|
||||
return 400;
|
||||
} else {
|
||||
if (checkUri(data['file'])) {
|
||||
return 200;
|
||||
} else {
|
||||
return 400;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (type === 'at' && !data['qq']) {
|
||||
return 400;
|
||||
} else if (type === 'reply' && !data['id']) {
|
||||
return 400;
|
||||
}
|
||||
} else {
|
||||
return 400;
|
||||
}
|
||||
}
|
||||
return 200;
|
||||
}
|
||||
|
@@ -10,23 +10,23 @@ export type MessageContext = {
|
||||
peer: Peer
|
||||
}
|
||||
async function handleOb11FileLikeMessage(
|
||||
coreContext: NapCatCore,
|
||||
{ data: inputdata }: OB11MessageFileBase,
|
||||
{ deleteAfterSentFiles }: MessageContext
|
||||
coreContext: NapCatCore,
|
||||
{ data: inputdata }: OB11MessageFileBase,
|
||||
{ deleteAfterSentFiles }: MessageContext
|
||||
) {
|
||||
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
|
||||
const { path, isLocal, fileName, errMsg, success } = (await uri2local(coreContext.NapCatTempPath, inputdata?.url || inputdata.file));
|
||||
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
|
||||
const { path, isLocal, fileName, errMsg, success } = (await uri2local(coreContext.NapCatTempPath, inputdata?.url || inputdata.file));
|
||||
|
||||
if (!success) {
|
||||
coreContext.context.logger.logError('文件下载失败', errMsg);
|
||||
throw Error('文件下载失败' + errMsg);
|
||||
}
|
||||
if (!success) {
|
||||
coreContext.context.logger.logError('文件下载失败', errMsg);
|
||||
throw Error('文件下载失败' + errMsg);
|
||||
}
|
||||
|
||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||
deleteAfterSentFiles.push(path);
|
||||
}
|
||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||
deleteAfterSentFiles.push(path);
|
||||
}
|
||||
|
||||
return { path, fileName: inputdata.name || fileName };
|
||||
return { path, fileName: inputdata.name || fileName };
|
||||
}
|
||||
|
||||
const _handlers: {
|
||||
@@ -38,149 +38,150 @@ const _handlers: {
|
||||
context: MessageContext
|
||||
) => Promise<SendMessageElement | undefined>
|
||||
} = {
|
||||
[OB11MessageDataType.text]: async (coreContext, { data: { text } }) => SendMsgElementConstructor.text(coreContext, text),
|
||||
[OB11MessageDataType.text]: async (coreContext, { data: { text } }) => SendMsgElementConstructor.text(coreContext, text),
|
||||
|
||||
[OB11MessageDataType.at]: async (coreContext, { data: { qq: atQQ } }, context) => {
|
||||
if (!context.peer) return undefined;
|
||||
[OB11MessageDataType.at]: async (coreContext, { data: { qq: atQQ } }, context) => {
|
||||
if (!context.peer) return undefined;
|
||||
|
||||
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
||||
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
||||
|
||||
// then the qq is a group member
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
let uid = await coreContext.getApiContext().UserApi.getUidByUin(atQQ);
|
||||
if (!uid) throw new Error('Get Uid Error')
|
||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, "");
|
||||
},
|
||||
[OB11MessageDataType.reply]: async (coreContext, { data: { id } }) => {
|
||||
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
|
||||
if (!replyMsgM) {
|
||||
coreContext.context.logger.logWarn('回复消息不存在', id);
|
||||
return undefined;
|
||||
}
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const replyMsg = (await NTQQMsgApi.getMsgsByMsgId(replyMsgM?.Peer!, [replyMsgM?.MsgId!])).msgList[0];
|
||||
return replyMsg ?
|
||||
SendMsgElementConstructor.reply(coreContext, replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!) :
|
||||
undefined;
|
||||
},
|
||||
// then the qq is a group member
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
const uid = await coreContext.getApiContext().UserApi.getUidByUin(atQQ);
|
||||
if (!uid) throw new Error('Get Uid Error');
|
||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, "");
|
||||
},
|
||||
[OB11MessageDataType.reply]: async (coreContext, { data: { id } }) => {
|
||||
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
|
||||
if (!replyMsgM) {
|
||||
coreContext.context.logger.logWarn('回复消息不存在', id);
|
||||
return undefined;
|
||||
}
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const replyMsg = (await NTQQMsgApi.getMsgsByMsgId(
|
||||
replyMsgM.Peer, [replyMsgM.MsgId!])).msgList[0];
|
||||
return replyMsg ?
|
||||
SendMsgElementConstructor.reply(coreContext, replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!) :
|
||||
undefined;
|
||||
},
|
||||
|
||||
[OB11MessageDataType.face]: async (coreContext, { data: { id } }) => SendMsgElementConstructor.face(coreContext, parseInt(id)),
|
||||
[OB11MessageDataType.face]: async (coreContext, { data: { id } }) => SendMsgElementConstructor.face(coreContext, parseInt(id)),
|
||||
|
||||
[OB11MessageDataType.mface]: async (coreContext, {
|
||||
data: {
|
||||
emoji_package_id, emoji_id, key, summary
|
||||
}
|
||||
}) => SendMsgElementConstructor.mface(coreContext, emoji_package_id, emoji_id, key, summary),
|
||||
[OB11MessageDataType.mface]: async (coreContext, {
|
||||
data: {
|
||||
emoji_package_id, emoji_id, key, summary
|
||||
}
|
||||
}) => SendMsgElementConstructor.mface(coreContext, emoji_package_id, emoji_id, key, summary),
|
||||
|
||||
// File service
|
||||
[OB11MessageDataType.image]: async (coreContext, sendMsg, context) => {
|
||||
const PicEle = await SendMsgElementConstructor.pic(
|
||||
coreContext,
|
||||
(await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path,
|
||||
sendMsg.data.summary || '',
|
||||
sendMsg.data.subType || 0
|
||||
);
|
||||
context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath);
|
||||
return PicEle;
|
||||
}, // currently not supported
|
||||
[OB11MessageDataType.file]: async (coreContext, sendMsg, context) => {
|
||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
||||
//logDebug('发送文件', path, fileName);
|
||||
const FileEle = await SendMsgElementConstructor.file(coreContext, path, fileName);
|
||||
// 清除Upload的应该
|
||||
// context.deleteAfterSentFiles.push(fileName || FileEle.fileElement.filePath);
|
||||
return FileEle;
|
||||
},
|
||||
// File service
|
||||
[OB11MessageDataType.image]: async (coreContext, sendMsg, context) => {
|
||||
const PicEle = await SendMsgElementConstructor.pic(
|
||||
coreContext,
|
||||
(await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path,
|
||||
sendMsg.data.summary || '',
|
||||
sendMsg.data.subType || 0
|
||||
);
|
||||
context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath);
|
||||
return PicEle;
|
||||
}, // currently not supported
|
||||
[OB11MessageDataType.file]: async (coreContext, sendMsg, context) => {
|
||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
||||
//logDebug('发送文件', path, fileName);
|
||||
const FileEle = await SendMsgElementConstructor.file(coreContext, path, fileName);
|
||||
// 清除Upload的应该
|
||||
// context.deleteAfterSentFiles.push(fileName || FileEle.fileElement.filePath);
|
||||
return FileEle;
|
||||
},
|
||||
|
||||
[OB11MessageDataType.video]: async (coreContext, sendMsg, context) => {
|
||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
||||
[OB11MessageDataType.video]: async (coreContext, sendMsg, context) => {
|
||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
||||
|
||||
//logDebug('发送视频', path, fileName);
|
||||
let thumb = sendMsg.data.thumb;
|
||||
if (thumb) {
|
||||
const uri2LocalRes = await uri2local(coreContext.NapCatTempPath, thumb);
|
||||
if (uri2LocalRes.success) thumb = uri2LocalRes.path;
|
||||
}
|
||||
const videoEle = await SendMsgElementConstructor.video(coreContext, path, fileName, thumb);
|
||||
//未测试
|
||||
context.deleteAfterSentFiles.push(videoEle.videoElement.filePath);
|
||||
return videoEle;
|
||||
},
|
||||
//logDebug('发送视频', path, fileName);
|
||||
let thumb = sendMsg.data.thumb;
|
||||
if (thumb) {
|
||||
const uri2LocalRes = await uri2local(coreContext.NapCatTempPath, thumb);
|
||||
if (uri2LocalRes.success) thumb = uri2LocalRes.path;
|
||||
}
|
||||
const videoEle = await SendMsgElementConstructor.video(coreContext, path, fileName, thumb);
|
||||
//未测试
|
||||
context.deleteAfterSentFiles.push(videoEle.videoElement.filePath);
|
||||
return videoEle;
|
||||
},
|
||||
|
||||
[OB11MessageDataType.voice]: async (coreContext, sendMsg, context) => SendMsgElementConstructor.ptt(coreContext, (await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path),
|
||||
[OB11MessageDataType.voice]: async (coreContext, sendMsg, context) => SendMsgElementConstructor.ptt(coreContext, (await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path),
|
||||
|
||||
[OB11MessageDataType.json]: async (coreContext, { data: { data } }) => SendMsgElementConstructor.ark(coreContext, data),
|
||||
[OB11MessageDataType.json]: async (coreContext, { data: { data } }) => SendMsgElementConstructor.ark(coreContext, data),
|
||||
|
||||
[OB11MessageDataType.dice]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.dice(coreContext, result),
|
||||
[OB11MessageDataType.dice]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.dice(coreContext, result),
|
||||
|
||||
[OB11MessageDataType.RPS]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.rps(coreContext, result),
|
||||
[OB11MessageDataType.RPS]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.rps(coreContext, result),
|
||||
|
||||
[OB11MessageDataType.markdown]: async (coreContext, { data: { content } }) => SendMsgElementConstructor.markdown(coreContext, content),
|
||||
[OB11MessageDataType.markdown]: async (coreContext, { data: { content } }) => SendMsgElementConstructor.markdown(coreContext, content),
|
||||
|
||||
[OB11MessageDataType.music]: async (coreContext, { data }) => {
|
||||
[OB11MessageDataType.music]: async (coreContext, { data }) => {
|
||||
// 保留, 直到...找到更好的解决方案
|
||||
if (data.type === 'custom') {
|
||||
if (!data.url) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数url');
|
||||
return undefined;
|
||||
}
|
||||
if (!data.audio) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数audio');
|
||||
return undefined;
|
||||
}
|
||||
if (!data.title) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数title');
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
if (!['qq', '163'].includes(data.type)) {
|
||||
coreContext.context.logger.logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type);
|
||||
return undefined;
|
||||
}
|
||||
if (!data.id) {
|
||||
coreContext.context.logger.logError('音乐卡片缺少参数id');
|
||||
return undefined;
|
||||
}
|
||||
if (data.type === 'custom') {
|
||||
if (!data.url) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数url');
|
||||
return undefined;
|
||||
}
|
||||
if (!data.audio) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数audio');
|
||||
return undefined;
|
||||
}
|
||||
if (!data.title) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数title');
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
if (!['qq', '163'].includes(data.type)) {
|
||||
coreContext.context.logger.logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type);
|
||||
return undefined;
|
||||
}
|
||||
if (!data.id) {
|
||||
coreContext.context.logger.logError('音乐卡片缺少参数id');
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
let postData: IdMusicSignPostData | CustomMusicSignPostData;
|
||||
if (data.type === 'custom' && data.content) {
|
||||
const { content, ...others } = data;
|
||||
postData = { singer: content, ...others };
|
||||
} else {
|
||||
postData = data;
|
||||
}
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
const signUrl = "";
|
||||
if (!signUrl) {
|
||||
if (data.type === 'qq') {
|
||||
//const musicJson = (await SignMusicWrapper(data.id.toString())).data.arkResult.slice(0, -1);
|
||||
//return SendMsgElementConstructor.ark(musicJson);
|
||||
}
|
||||
throw Error('音乐消息签名地址未配置');
|
||||
}
|
||||
try {
|
||||
const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData);
|
||||
return SendMsgElementConstructor.ark(coreContext, musicJson);
|
||||
} catch (e) {
|
||||
coreContext.context.logger.logError('生成音乐消息失败', e);
|
||||
}
|
||||
},
|
||||
|
||||
[OB11MessageDataType.node]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.forward]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.xml]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.poke]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.Location]: async (coreContext) => {
|
||||
return SendMsgElementConstructor.location(coreContext);
|
||||
},
|
||||
[OB11MessageDataType.miniapp]: function (CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
|
||||
throw new Error('Function not implemented.');
|
||||
}
|
||||
|
||||
let postData: IdMusicSignPostData | CustomMusicSignPostData;
|
||||
if (data.type === 'custom' && data.content) {
|
||||
const { content, ...others } = data;
|
||||
postData = { singer: content, ...others };
|
||||
} else {
|
||||
postData = data;
|
||||
}
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
const signUrl = "";
|
||||
if (!signUrl) {
|
||||
if (data.type === 'qq') {
|
||||
//const musicJson = (await SignMusicWrapper(data.id.toString())).data.arkResult.slice(0, -1);
|
||||
//return SendMsgElementConstructor.ark(musicJson);
|
||||
}
|
||||
throw Error('音乐消息签名地址未配置');
|
||||
}
|
||||
try {
|
||||
const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData);
|
||||
return SendMsgElementConstructor.ark(coreContext, musicJson);
|
||||
} catch (e) {
|
||||
coreContext.context.logger.logError('生成音乐消息失败', e);
|
||||
}
|
||||
},
|
||||
|
||||
[OB11MessageDataType.node]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.forward]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.xml]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.poke]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.Location]: async (coreContext) => {
|
||||
return SendMsgElementConstructor.location(coreContext);
|
||||
},
|
||||
[OB11MessageDataType.miniapp]: function (CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
|
||||
throw new Error('Function not implemented.');
|
||||
}
|
||||
};
|
||||
|
||||
const handlers = <{
|
||||
@@ -192,46 +193,46 @@ const handlers = <{
|
||||
}>_handlers;
|
||||
|
||||
export default async function createSendElements(
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
) {
|
||||
const deleteAfterSentFiles: string[] = [];
|
||||
const callResultList: Array<Promise<SendMessageElement | undefined>> = [];
|
||||
for (const sendMsg of messageData) {
|
||||
if (ignoreTypes.includes(sendMsg.type)) {
|
||||
continue;
|
||||
const deleteAfterSentFiles: string[] = [];
|
||||
const callResultList: Array<Promise<SendMessageElement | undefined>> = [];
|
||||
for (const sendMsg of messageData) {
|
||||
if (ignoreTypes.includes(sendMsg.type)) {
|
||||
continue;
|
||||
}
|
||||
const callResult = handlers[sendMsg.type](
|
||||
CoreContext,
|
||||
sendMsg,
|
||||
{ peer, deleteAfterSentFiles }
|
||||
)?.catch(undefined);
|
||||
callResultList.push(callResult);
|
||||
}
|
||||
const callResult = handlers[sendMsg.type](
|
||||
CoreContext,
|
||||
sendMsg,
|
||||
{ peer, deleteAfterSentFiles }
|
||||
)?.catch(undefined);
|
||||
callResultList.push(callResult);
|
||||
}
|
||||
const ret = await Promise.all(callResultList);
|
||||
const sendElements: SendMessageElement[] = ret.filter(ele => ele) as SendMessageElement[];
|
||||
return { sendElements, deleteAfterSentFiles };
|
||||
const ret = await Promise.all(callResultList);
|
||||
const sendElements: SendMessageElement[] = ret.filter(ele => ele) as SendMessageElement[];
|
||||
return { sendElements, deleteAfterSentFiles };
|
||||
}
|
||||
|
||||
export async function createSendElementsParallel(
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
) {
|
||||
const deleteAfterSentFiles: string[] = [];
|
||||
const sendElements = <SendMessageElement[]>(
|
||||
const deleteAfterSentFiles: string[] = [];
|
||||
const sendElements = <SendMessageElement[]>(
|
||||
await Promise.all(
|
||||
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
||||
undefined :
|
||||
handlers[sendMsg.type](CoreContext, sendMsg, { peer, deleteAfterSentFiles }))
|
||||
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
||||
undefined :
|
||||
handlers[sendMsg.type](CoreContext, sendMsg, { peer, deleteAfterSentFiles }))
|
||||
).then(
|
||||
results => results.filter(
|
||||
element => element !== undefined
|
||||
)
|
||||
results => results.filter(
|
||||
element => element !== undefined
|
||||
)
|
||||
)
|
||||
);
|
||||
return { sendElements, deleteAfterSentFiles };
|
||||
return { sendElements, deleteAfterSentFiles };
|
||||
}
|
||||
|
@@ -2,118 +2,118 @@ import { ChatType, ElementType, NapCatCore, Peer, RawMessage, SendMessageElement
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
import { OB11MessageDataType, OB11MessageNode } from '@/onebot/types';
|
||||
import createSendElements from './create-send-elements';
|
||||
import { normalize, sendMsg } from "../SendMsg/index"
|
||||
import { normalize, sendMsg } from "../SendMsg/index";
|
||||
async function cloneMsg(coreContext: NapCatCore, msg: RawMessage): Promise<RawMessage | undefined> {
|
||||
const selfPeer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: coreContext.selfInfo.uid
|
||||
};
|
||||
const logger = coreContext.context.logger;
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
//logDebug('克隆的目标消息', msg);
|
||||
const selfPeer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: coreContext.selfInfo.uid
|
||||
};
|
||||
const logger = coreContext.context.logger;
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
//logDebug('克隆的目标消息', msg);
|
||||
|
||||
const sendElements: SendMessageElement[] = [];
|
||||
const sendElements: SendMessageElement[] = [];
|
||||
|
||||
for (const element of msg.elements) {
|
||||
sendElements.push(element as SendMessageElement);
|
||||
}
|
||||
for (const element of msg.elements) {
|
||||
sendElements.push(element as SendMessageElement);
|
||||
}
|
||||
|
||||
if (sendElements.length === 0) {
|
||||
logger.logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
||||
}
|
||||
try {
|
||||
const nodeMsg = await NTQQMsgApi.sendMsg(selfPeer, sendElements, true);
|
||||
return nodeMsg;
|
||||
} catch (e) {
|
||||
logger.logError(e, '克隆转发消息失败,将忽略本条消息', msg);
|
||||
}
|
||||
if (sendElements.length === 0) {
|
||||
logger.logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
||||
}
|
||||
try {
|
||||
const nodeMsg = await NTQQMsgApi.sendMsg(selfPeer, sendElements, true);
|
||||
return nodeMsg;
|
||||
} catch (e) {
|
||||
logger.logError(e, '克隆转发消息失败,将忽略本条消息', msg);
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<RawMessage | null> {
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const selfPeer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: coreContext.selfInfo.uid
|
||||
};
|
||||
let nodeMsgIds: string[] = [];
|
||||
const logger = coreContext.context.logger;
|
||||
for (const messageNode of messageNodes) {
|
||||
const nodeId = messageNode.data.id;
|
||||
if (nodeId) {
|
||||
//对Mgsid和OB11ID混用情况兜底
|
||||
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(nodeId)) || MessageUnique.getPeerByMsgId(nodeId);
|
||||
if (!nodeMsg) {
|
||||
logger.logError('转发消息失败,未找到消息', nodeId);
|
||||
continue;
|
||||
}
|
||||
nodeMsgIds.push(nodeMsg.MsgId);
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const selfPeer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: coreContext.selfInfo.uid
|
||||
};
|
||||
let nodeMsgIds: string[] = [];
|
||||
const logger = coreContext.context.logger;
|
||||
for (const messageNode of messageNodes) {
|
||||
const nodeId = messageNode.data.id;
|
||||
if (nodeId) {
|
||||
//对Mgsid和OB11ID混用情况兜底
|
||||
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(nodeId)) || MessageUnique.getPeerByMsgId(nodeId);
|
||||
if (!nodeMsg) {
|
||||
logger.logError('转发消息失败,未找到消息', nodeId);
|
||||
continue;
|
||||
}
|
||||
nodeMsgIds.push(nodeMsg.MsgId);
|
||||
} else {
|
||||
// 自定义的消息
|
||||
try {
|
||||
const OB11Data = normalize(messageNode.data.content);
|
||||
//筛选node消息
|
||||
const isNodeMsg = OB11Data.filter(e => e.type === OB11MessageDataType.node).length;//找到子转发消息
|
||||
if (isNodeMsg !== 0) {
|
||||
if (isNodeMsg !== OB11Data.length) { logger.logError('子消息中包含非node消息 跳过不合法部分'); continue; }
|
||||
const nodeMsg = await handleForwardNode(coreContext, selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
|
||||
if (nodeMsg) { nodeMsgIds.push(nodeMsg.msgId); MessageUnique.createMsg(selfPeer, nodeMsg.msgId); }
|
||||
//完成子卡片生成跳过后续
|
||||
continue;
|
||||
}
|
||||
const { sendElements } = await createSendElements(coreContext,OB11Data, destPeer);
|
||||
//拆分消息
|
||||
const MixElement = sendElements.filter(element => element.elementType !== ElementType.FILE && element.elementType !== ElementType.VIDEO);
|
||||
const SingleElement = sendElements.filter(element => element.elementType === ElementType.FILE || element.elementType === ElementType.VIDEO).map(e => [e]);
|
||||
const AllElement: SendMessageElement[][] = [MixElement, ...SingleElement].filter(e => e !== undefined && e.length !== 0);
|
||||
const MsgNodeList: Promise<RawMessage | undefined>[] = [];
|
||||
for (const sendElementsSplitElement of AllElement) {
|
||||
MsgNodeList.push(sendMsg(coreContext,selfPeer, sendElementsSplitElement, [], true).catch(e => new Promise((resolve, reject) => { resolve(undefined); })));
|
||||
}
|
||||
(await Promise.allSettled(MsgNodeList)).map((result) => {
|
||||
if (result.status === 'fulfilled' && result.value) {
|
||||
nodeMsgIds.push(result.value.msgId);
|
||||
MessageUnique.createMsg(selfPeer, result.value.msgId);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
logger.logDebug('生成转发消息节点失败', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
const nodeMsgArray: Array<RawMessage> = [];
|
||||
let srcPeer: Peer | undefined = undefined;
|
||||
let needSendSelf = false;
|
||||
//检测是否处于同一个Peer 不在同一个peer则全部消息由自身发送
|
||||
for (const msgId of nodeMsgIds) {
|
||||
const nodeMsgPeer = MessageUnique.getPeerByMsgId(msgId);
|
||||
if (!nodeMsgPeer) {
|
||||
logger.logError('转发消息失败,未找到消息', msgId);
|
||||
continue;
|
||||
}
|
||||
const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0];
|
||||
srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid };
|
||||
if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||
needSendSelf = true;
|
||||
}
|
||||
nodeMsgArray.push(nodeMsg);
|
||||
}
|
||||
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
||||
let retMsgIds: string[] = [];
|
||||
if (needSendSelf) {
|
||||
for (const [index, msg] of nodeMsgArray.entries()) {
|
||||
if (msg.peerUid === coreContext.selfInfo.uid) continue;
|
||||
const ClonedMsg = await cloneMsg(coreContext, msg);
|
||||
if (ClonedMsg) retMsgIds.push(ClonedMsg.msgId);
|
||||
}
|
||||
} else {
|
||||
// 自定义的消息
|
||||
try {
|
||||
let OB11Data = normalize(messageNode.data.content);
|
||||
//筛选node消息
|
||||
let isNodeMsg = OB11Data.filter(e => e.type === OB11MessageDataType.node).length;//找到子转发消息
|
||||
if (isNodeMsg !== 0) {
|
||||
if (isNodeMsg !== OB11Data.length) { logger.logError('子消息中包含非node消息 跳过不合法部分'); continue; }
|
||||
const nodeMsg = await handleForwardNode(coreContext, selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
|
||||
if (nodeMsg) { nodeMsgIds.push(nodeMsg.msgId); MessageUnique.createMsg(selfPeer, nodeMsg.msgId) };
|
||||
//完成子卡片生成跳过后续
|
||||
continue;
|
||||
}
|
||||
const { sendElements } = await createSendElements(coreContext,OB11Data, destPeer);
|
||||
//拆分消息
|
||||
let MixElement = sendElements.filter(element => element.elementType !== ElementType.FILE && element.elementType !== ElementType.VIDEO);
|
||||
let SingleElement = sendElements.filter(element => element.elementType === ElementType.FILE || element.elementType === ElementType.VIDEO).map(e => [e]);
|
||||
let AllElement: SendMessageElement[][] = [MixElement, ...SingleElement].filter(e => e !== undefined && e.length !== 0);
|
||||
const MsgNodeList: Promise<RawMessage | undefined>[] = [];
|
||||
for (const sendElementsSplitElement of AllElement) {
|
||||
MsgNodeList.push(sendMsg(coreContext,selfPeer, sendElementsSplitElement, [], true).catch(e => new Promise((resolve, reject) => { resolve(undefined) })));
|
||||
}
|
||||
(await Promise.allSettled(MsgNodeList)).map((result) => {
|
||||
if (result.status === 'fulfilled' && result.value) {
|
||||
nodeMsgIds.push(result.value.msgId);
|
||||
MessageUnique.createMsg(selfPeer, result.value.msgId);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
logger.logDebug('生成转发消息节点失败', e);
|
||||
}
|
||||
retMsgIds = nodeMsgIds;
|
||||
}
|
||||
}
|
||||
const nodeMsgArray: Array<RawMessage> = [];
|
||||
let srcPeer: Peer | undefined = undefined;
|
||||
let needSendSelf = false;
|
||||
//检测是否处于同一个Peer 不在同一个peer则全部消息由自身发送
|
||||
for (let msgId of nodeMsgIds) {
|
||||
const nodeMsgPeer = MessageUnique.getPeerByMsgId(msgId);
|
||||
if (!nodeMsgPeer) {
|
||||
logger.logError('转发消息失败,未找到消息', msgId);
|
||||
continue;
|
||||
if (nodeMsgIds.length === 0) throw Error('转发消息失败,生成节点为空');
|
||||
try {
|
||||
logger.logDebug('开发转发', srcPeer, destPeer, nodeMsgIds);
|
||||
return await NTQQMsgApi.multiForwardMsg(srcPeer!, destPeer, nodeMsgIds);
|
||||
} catch (e) {
|
||||
logger.logError('forward failed', e);
|
||||
return null;
|
||||
}
|
||||
const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0];
|
||||
srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid };
|
||||
if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||
needSendSelf = true;
|
||||
}
|
||||
nodeMsgArray.push(nodeMsg);
|
||||
}
|
||||
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
||||
let retMsgIds: string[] = [];
|
||||
if (needSendSelf) {
|
||||
for (const [index, msg] of nodeMsgArray.entries()) {
|
||||
if (msg.peerUid === coreContext.selfInfo.uid) continue;
|
||||
const ClonedMsg = await cloneMsg(coreContext, msg);
|
||||
if (ClonedMsg) retMsgIds.push(ClonedMsg.msgId);
|
||||
}
|
||||
} else {
|
||||
retMsgIds = nodeMsgIds;
|
||||
}
|
||||
if (nodeMsgIds.length === 0) throw Error('转发消息失败,生成节点为空');
|
||||
try {
|
||||
logger.logDebug('开发转发', srcPeer, destPeer, nodeMsgIds);
|
||||
return await NTQQMsgApi.multiForwardMsg(srcPeer!, destPeer, nodeMsgIds);
|
||||
} catch (e) {
|
||||
logger.logError('forward failed', e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
|
||||
import {
|
||||
OB11MessageData,
|
||||
OB11MessageDataType,
|
||||
OB11MessageMixType,
|
||||
OB11MessageNode,
|
||||
OB11PostSendMsg
|
||||
OB11MessageData,
|
||||
OB11MessageDataType,
|
||||
OB11MessageMixType,
|
||||
OB11MessageNode,
|
||||
OB11PostSendMsg
|
||||
} from '@/onebot/types';
|
||||
import { ActionName, BaseCheckResult } from '@/onebot/action/types';
|
||||
import fs from 'node:fs';
|
||||
@@ -26,147 +26,147 @@ export enum ContextMode {
|
||||
}
|
||||
// Normalizes a mixed type (CQCode/a single segment/segment array) into a segment array.
|
||||
export function normalize(message: OB11MessageMixType, autoEscape = false): OB11MessageData[] {
|
||||
return typeof message === 'string' ? (
|
||||
autoEscape ?
|
||||
[{ type: OB11MessageDataType.text, data: { text: message } }] :
|
||||
decodeCQCode(message)
|
||||
) : Array.isArray(message) ? message : [message];
|
||||
return typeof message === 'string' ? (
|
||||
autoEscape ?
|
||||
[{ type: OB11MessageDataType.text, data: { text: message } }] :
|
||||
decodeCQCode(message)
|
||||
) : Array.isArray(message) ? message : [message];
|
||||
}
|
||||
|
||||
export { createSendElements };
|
||||
|
||||
export async function sendMsg(coreContext: NapCatCore, peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const logger = coreContext.context.logger;
|
||||
if (!sendElements.length) {
|
||||
throw ('消息体无法解析, 请检查是否发送了不支持的消息类型');
|
||||
}
|
||||
let totalSize = 0;
|
||||
let timeout = 10000;
|
||||
try {
|
||||
for (const fileElement of sendElements) {
|
||||
if (fileElement.elementType === ElementType.PTT) {
|
||||
totalSize += fs.statSync(fileElement.pttElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.FILE) {
|
||||
totalSize += fs.statSync(fileElement.fileElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.VIDEO) {
|
||||
totalSize += fs.statSync(fileElement.videoElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.PIC) {
|
||||
totalSize += fs.statSync(fileElement.picElement.sourcePath).size;
|
||||
}
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const logger = coreContext.context.logger;
|
||||
if (!sendElements.length) {
|
||||
throw ('消息体无法解析, 请检查是否发送了不支持的消息类型');
|
||||
}
|
||||
//且 PredictTime ((totalSize / 1024 / 512) * 1000)不等于Nan
|
||||
const PredictTime = totalSize / 1024 / 256 * 1000;
|
||||
if (!Number.isNaN(PredictTime)) {
|
||||
timeout += PredictTime;// 10S Basic Timeout + PredictTime( For File 512kb/s )
|
||||
let totalSize = 0;
|
||||
let timeout = 10000;
|
||||
try {
|
||||
for (const fileElement of sendElements) {
|
||||
if (fileElement.elementType === ElementType.PTT) {
|
||||
totalSize += fs.statSync(fileElement.pttElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.FILE) {
|
||||
totalSize += fs.statSync(fileElement.fileElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.VIDEO) {
|
||||
totalSize += fs.statSync(fileElement.videoElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.PIC) {
|
||||
totalSize += fs.statSync(fileElement.picElement.sourcePath).size;
|
||||
}
|
||||
}
|
||||
//且 PredictTime ((totalSize / 1024 / 512) * 1000)不等于Nan
|
||||
const PredictTime = totalSize / 1024 / 256 * 1000;
|
||||
if (!Number.isNaN(PredictTime)) {
|
||||
timeout += PredictTime;// 10S Basic Timeout + PredictTime( For File 512kb/s )
|
||||
}
|
||||
} catch (e) {
|
||||
logger.logError('发送消息计算预计时间异常', e);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.logError('发送消息计算预计时间异常', e);
|
||||
}
|
||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout);
|
||||
try {
|
||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout);
|
||||
try {
|
||||
returnMsg!.id = MessageUnique.createMsg({ chatType: peer.chatType, guildId: '', peerUid: peer.peerUid }, returnMsg!.msgId);
|
||||
} catch (e: any) {
|
||||
logger.logDebug('发送消息id获取失败', e);
|
||||
} catch (e: any) {
|
||||
logger.logDebug('发送消息id获取失败', e);
|
||||
returnMsg!.id = 0;
|
||||
}
|
||||
deleteAfterSentFiles.map((f) => { fsPromise.unlink(f).then().catch(e => logger.logError('发送消息删除文件失败', e)); });
|
||||
return returnMsg;
|
||||
}
|
||||
deleteAfterSentFiles.map((f) => { fsPromise.unlink(f).then().catch(e => logger.logError('发送消息删除文件失败', e)); });
|
||||
return returnMsg;
|
||||
}
|
||||
|
||||
async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg, contextMode: ContextMode): Promise<Peer> {
|
||||
// This function determines the type of message by the existence of user_id / group_id,
|
||||
// not message_type.
|
||||
// This redundant design of Ob11 here should be blamed.
|
||||
const NTQQGroupApi = coreContext.getApiContext().GroupApi;
|
||||
const NTQQFriendApi = coreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = coreContext.getApiContext().UserApi;
|
||||
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
||||
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id?.toString())
|
||||
return {
|
||||
chatType: ChatType.group,
|
||||
peerUid: payload.group_id.toString()
|
||||
};
|
||||
}
|
||||
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
||||
const Uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(Uid!);
|
||||
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
|
||||
return {
|
||||
chatType: isBuddy ? ChatType.friend : ChatType.temp,
|
||||
peerUid: Uid!
|
||||
};
|
||||
}
|
||||
throw '请指定 group_id 或 user_id';
|
||||
// This function determines the type of message by the existence of user_id / group_id,
|
||||
// not message_type.
|
||||
// This redundant design of Ob11 here should be blamed.
|
||||
const NTQQGroupApi = coreContext.getApiContext().GroupApi;
|
||||
const NTQQFriendApi = coreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = coreContext.getApiContext().UserApi;
|
||||
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
||||
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id?.toString());
|
||||
return {
|
||||
chatType: ChatType.group,
|
||||
peerUid: payload.group_id.toString()
|
||||
};
|
||||
}
|
||||
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
||||
const Uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(Uid!);
|
||||
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
|
||||
return {
|
||||
chatType: isBuddy ? ChatType.friend : ChatType.temp,
|
||||
peerUid: Uid!
|
||||
};
|
||||
}
|
||||
throw '请指定 group_id 或 user_id';
|
||||
}
|
||||
|
||||
function getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
|
||||
if (Array.isArray(payload.message)) {
|
||||
return payload.message.filter(msg => msg.type == msgType).length;
|
||||
}
|
||||
return 0;
|
||||
if (Array.isArray(payload.message)) {
|
||||
return payload.message.filter(msg => msg.type == msgType).length;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
actionName = ActionName.SendMsg;
|
||||
contextMode = ContextMode.Normal;
|
||||
actionName = ActionName.SendMsg;
|
||||
contextMode = ContextMode.Normal;
|
||||
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const messages = normalize(payload.message);
|
||||
const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node);
|
||||
if (nodeElementLength > 0 && nodeElementLength != messages.length) {
|
||||
return { valid: false, message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素' };
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const messages = normalize(payload.message);
|
||||
const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node);
|
||||
if (nodeElementLength > 0 && nodeElementLength != messages.length) {
|
||||
return { valid: false, message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素' };
|
||||
}
|
||||
// if (payload.message_type !== 'private' && payload.group_id && !(await getGroup(payload.group_id))) {
|
||||
// return { valid: false, message: `群${payload.group_id}不存在` };
|
||||
// }
|
||||
if (payload.user_id && payload.message_type !== 'group') {
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(uid!);
|
||||
// 此处有问题
|
||||
if (!isBuddy) {
|
||||
//return { valid: false, message: '异常消息' };
|
||||
}
|
||||
}
|
||||
return { valid: true };
|
||||
}
|
||||
// if (payload.message_type !== 'private' && payload.group_id && !(await getGroup(payload.group_id))) {
|
||||
// return { valid: false, message: `群${payload.group_id}不存在` };
|
||||
// }
|
||||
if (payload.user_id && payload.message_type !== 'group') {
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(uid!);
|
||||
// 此处有问题
|
||||
if (!isBuddy) {
|
||||
//return { valid: false, message: '异常消息' };
|
||||
}
|
||||
|
||||
protected async _handle(payload: OB11PostSendMsg): Promise<{ message_id: number }> {
|
||||
const peer = await createContext(this.CoreContext, payload, this.contextMode);
|
||||
|
||||
const messages = normalize(
|
||||
payload.message,
|
||||
payload.auto_escape === true || payload.auto_escape === 'true'
|
||||
);
|
||||
|
||||
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||
const returnMsg = await handleForwardNode(this.CoreContext,peer, messages as OB11MessageNode[]);
|
||||
if (returnMsg) {
|
||||
const msgShortId = MessageUnique.createMsg({ guildId: '', peerUid: peer.peerUid, chatType: peer.chatType }, returnMsg!.msgId);
|
||||
return { message_id: msgShortId! };
|
||||
} else {
|
||||
throw Error('发送转发消息失败');
|
||||
}
|
||||
} else {
|
||||
// if (getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
||||
// const music: OB11MessageCustomMusic = messages[0] as OB11MessageCustomMusic;
|
||||
// if (music) {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// log("send msg:", peer, sendElements)
|
||||
|
||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(this.CoreContext, messages, peer);
|
||||
//console.log(peer, JSON.stringify(sendElements,null,2));
|
||||
const returnMsg = await sendMsg(this.CoreContext, peer, sendElements, deleteAfterSentFiles);
|
||||
return { message_id: returnMsg!.id! };
|
||||
}
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
protected async _handle(payload: OB11PostSendMsg): Promise<{ message_id: number }> {
|
||||
const peer = await createContext(this.CoreContext, payload, this.contextMode);
|
||||
|
||||
const messages = normalize(
|
||||
payload.message,
|
||||
payload.auto_escape === true || payload.auto_escape === 'true'
|
||||
);
|
||||
|
||||
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||
const returnMsg = await handleForwardNode(this.CoreContext,peer, messages as OB11MessageNode[]);
|
||||
if (returnMsg) {
|
||||
const msgShortId = MessageUnique.createMsg({ guildId: '', peerUid: peer.peerUid, chatType: peer.chatType }, returnMsg!.msgId);
|
||||
return { message_id: msgShortId! };
|
||||
} else {
|
||||
throw Error('发送转发消息失败');
|
||||
}
|
||||
} else {
|
||||
// if (getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
||||
// const music: OB11MessageCustomMusic = messages[0] as OB11MessageCustomMusic;
|
||||
// if (music) {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// log("send msg:", peer, sendElements)
|
||||
|
||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(this.CoreContext, messages, peer);
|
||||
//console.log(peer, JSON.stringify(sendElements,null,2));
|
||||
const returnMsg = await sendMsg(this.CoreContext, peer, sendElements, deleteAfterSentFiles);
|
||||
return { message_id: returnMsg!.id! };
|
||||
}
|
||||
}
|
||||
|
||||
export default SendMsg;
|
||||
|
@@ -3,13 +3,13 @@ import { ActionName, BaseCheckResult } from '../types';
|
||||
import { OB11PostSendMsg } from '../../types';
|
||||
// 未检测参数
|
||||
class SendPrivateMsg extends SendMsg {
|
||||
actionName = ActionName.SendPrivateMsg;
|
||||
contextMode: ContextMode = ContextMode.Private;
|
||||
actionName = ActionName.SendPrivateMsg;
|
||||
contextMode: ContextMode = ContextMode.Private;
|
||||
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
payload.message_type = 'private';
|
||||
return super.check(payload);
|
||||
}
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
payload.message_type = 'private';
|
||||
return super.check(payload);
|
||||
}
|
||||
}
|
||||
|
||||
export default SendPrivateMsg;
|
||||
|
@@ -5,32 +5,32 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['string', 'number'] },
|
||||
emoji_id: { type: ['string', 'number'] }
|
||||
},
|
||||
required: ['message_id', 'emoji_id']
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['string', 'number'] },
|
||||
emoji_id: { type: ['string', 'number'] }
|
||||
},
|
||||
required: ['message_id', 'emoji_id']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
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');
|
||||
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');
|
||||
}
|
||||
if (!payload.emoji_id) {
|
||||
throw new Error('emojiId not found');
|
||||
}
|
||||
const msgData = (await NTQQMsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId])).msgList;
|
||||
if (!msgData || msgData.length == 0 || !msgData[0].msgSeq) {
|
||||
throw new Error('find msg by msgid error');
|
||||
}
|
||||
return await NTQQMsgApi.setEmojiLike(msg.Peer, msgData[0].msgSeq, payload.emoji_id.toString(), true);
|
||||
}
|
||||
if (!payload.emoji_id) {
|
||||
throw new Error('emojiId not found');
|
||||
}
|
||||
const msgData = (await NTQQMsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId])).msgList;
|
||||
if (!msgData || msgData.length == 0 || !msgData[0].msgSeq) {
|
||||
throw new Error('find msg by msgid error');
|
||||
}
|
||||
return await NTQQMsgApi.setEmojiLike(msg.Peer, msgData[0].msgSeq, payload.emoji_id.toString(), true);
|
||||
}
|
||||
}
|
||||
|
@@ -6,5 +6,5 @@ interface ReturnType {
|
||||
}
|
||||
|
||||
export default class CanSendImage extends CanSendRecord {
|
||||
actionName = ActionName.CanSendImage;
|
||||
actionName = ActionName.CanSendImage;
|
||||
}
|
||||
|
@@ -6,11 +6,11 @@ interface ReturnType {
|
||||
}
|
||||
|
||||
export default class CanSendRecord extends BaseAction<any, ReturnType> {
|
||||
actionName = ActionName.CanSendRecord;
|
||||
actionName = ActionName.CanSendRecord;
|
||||
|
||||
protected async _handle(_payload: void): Promise<ReturnType> {
|
||||
return {
|
||||
yes: true
|
||||
};
|
||||
}
|
||||
protected async _handle(_payload: void): Promise<ReturnType> {
|
||||
return {
|
||||
yes: true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -5,11 +5,11 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
class GetLoginInfo extends BaseAction<null, OB11User> {
|
||||
actionName = ActionName.GetLoginInfo;
|
||||
actionName = ActionName.GetLoginInfo;
|
||||
|
||||
protected async _handle(payload: null) {
|
||||
return OB11Constructor.selfInfo(this.CoreContext.selfInfo);
|
||||
}
|
||||
protected async _handle(payload: null) {
|
||||
return OB11Constructor.selfInfo(this.CoreContext.selfInfo);
|
||||
}
|
||||
}
|
||||
|
||||
export default GetLoginInfo;
|
||||
|
@@ -2,13 +2,13 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
export default class GetStatus extends BaseAction<any, any> {
|
||||
actionName = ActionName.GetStatus;
|
||||
actionName = ActionName.GetStatus;
|
||||
|
||||
protected async _handle(payload: any): Promise<any> {
|
||||
return {
|
||||
online: !!this.CoreContext.selfInfo.online,
|
||||
good: true,
|
||||
stat:{}
|
||||
};
|
||||
}
|
||||
protected async _handle(payload: any): Promise<any> {
|
||||
return {
|
||||
online: !!this.CoreContext.selfInfo.online,
|
||||
good: true,
|
||||
stat:{}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -3,13 +3,13 @@ import { ActionName } from '../types';
|
||||
import { napcat_version } from '@/common/framework/napcat';
|
||||
|
||||
export default class GetVersionInfo extends BaseAction<any, any> {
|
||||
actionName = ActionName.GetVersionInfo;
|
||||
actionName = ActionName.GetVersionInfo;
|
||||
|
||||
protected async _handle(payload: any): Promise<any> {
|
||||
return {
|
||||
app_name: 'NapCat.Onebot',
|
||||
protocol_version: 'v11',
|
||||
app_version: napcat_version
|
||||
};
|
||||
}
|
||||
protected async _handle(payload: any): Promise<any> {
|
||||
return {
|
||||
app_name: 'NapCat.Onebot',
|
||||
protocol_version: 'v11',
|
||||
app_version: napcat_version
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -7,65 +7,65 @@ interface Response {
|
||||
bkn: string
|
||||
}
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
domain: { type: 'string' }
|
||||
},
|
||||
required: ['domain']
|
||||
type: 'object',
|
||||
properties: {
|
||||
domain: { type: 'string' }
|
||||
},
|
||||
required: ['domain']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
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');
|
||||
// }
|
||||
// if (payload.domain.endsWith('qzone.qq.com')) {
|
||||
// // 兼容整个 *.qzone.qq.com
|
||||
// const data = (await NTQQUserApi.getQzoneCookies());
|
||||
// const Bkn = WebApi.genBkn(data.p_skey);
|
||||
// const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin;
|
||||
// return { cookies: CookieValue };
|
||||
// }
|
||||
// // 取Skey
|
||||
// // 先NodeIKernelTicketService.forceFetchClientKey('')
|
||||
// // 返回值
|
||||
// // {
|
||||
// // result: 0,
|
||||
// // errMsg: '',
|
||||
// // url: '',
|
||||
// // keyIndex: '19',
|
||||
// // clientKey: 'clientKey',
|
||||
// // expireTime: '7200'
|
||||
// // }
|
||||
// // request https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=1627126029&clientkey=key
|
||||
// // &u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=keyIndex
|
||||
// const _PSkey = (await NTQQUserApi.getPSkey([payload.domain]))[payload.domain];
|
||||
// // 取Pskey
|
||||
// // NodeIKernelTipOffService.getPskey([ 'qun.qq.com' ], true )
|
||||
// // {
|
||||
// // domainPskeyMap: 0,
|
||||
// // errMsg: 'success',
|
||||
// // domainPskeyMap: Map(1) {
|
||||
// // 'qun.qq.com' => 'pskey'
|
||||
// // }
|
||||
// // }
|
||||
// if (!_PSkey || !_Skey) {
|
||||
// throw new Error('获取Cookies失败');
|
||||
// }
|
||||
// const cookies = `p_skey=${_PSkey}; skey=${_Skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}`;
|
||||
// return {
|
||||
// cookies
|
||||
// };
|
||||
const cookiesObject = await NTQQUserApi.getCookies(payload.domain);
|
||||
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
|
||||
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
|
||||
const bkn = NTQQWebApi.getBknFromCookie(cookiesObject.p_skey);
|
||||
return { cookies, bkn };
|
||||
}
|
||||
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');
|
||||
// }
|
||||
// if (payload.domain.endsWith('qzone.qq.com')) {
|
||||
// // 兼容整个 *.qzone.qq.com
|
||||
// const data = (await NTQQUserApi.getQzoneCookies());
|
||||
// const Bkn = WebApi.genBkn(data.p_skey);
|
||||
// const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin;
|
||||
// return { cookies: CookieValue };
|
||||
// }
|
||||
// // 取Skey
|
||||
// // 先NodeIKernelTicketService.forceFetchClientKey('')
|
||||
// // 返回值
|
||||
// // {
|
||||
// // result: 0,
|
||||
// // errMsg: '',
|
||||
// // url: '',
|
||||
// // keyIndex: '19',
|
||||
// // clientKey: 'clientKey',
|
||||
// // expireTime: '7200'
|
||||
// // }
|
||||
// // request https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=1627126029&clientkey=key
|
||||
// // &u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=keyIndex
|
||||
// const _PSkey = (await NTQQUserApi.getPSkey([payload.domain]))[payload.domain];
|
||||
// // 取Pskey
|
||||
// // NodeIKernelTipOffService.getPskey([ 'qun.qq.com' ], true )
|
||||
// // {
|
||||
// // domainPskeyMap: 0,
|
||||
// // errMsg: 'success',
|
||||
// // domainPskeyMap: Map(1) {
|
||||
// // 'qun.qq.com' => 'pskey'
|
||||
// // }
|
||||
// // }
|
||||
// if (!_PSkey || !_Skey) {
|
||||
// throw new Error('获取Cookies失败');
|
||||
// }
|
||||
// const cookies = `p_skey=${_PSkey}; skey=${_Skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}`;
|
||||
// return {
|
||||
// cookies
|
||||
// };
|
||||
const cookiesObject = await NTQQUserApi.getCookies(payload.domain);
|
||||
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
|
||||
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
|
||||
const bkn = NTQQWebApi.getBknFromCookie(cookiesObject.p_skey);
|
||||
return { cookies, bkn };
|
||||
}
|
||||
}
|
||||
|
@@ -6,19 +6,19 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
// no_cache get时传字符串
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
}
|
||||
type: 'object',
|
||||
properties: {
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
}
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
|
||||
actionName = ActionName.GetFriendList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
//全新逻辑
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache === 'true'));
|
||||
}
|
||||
actionName = ActionName.GetFriendList;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
//全新逻辑
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache === 'true'));
|
||||
}
|
||||
}
|
||||
|
@@ -5,49 +5,49 @@ import { ActionName } from '../types';
|
||||
import { OB11Constructor } from '@/onebot/helper/data';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
count: { type: ['number', 'string'] }
|
||||
}
|
||||
type: 'object',
|
||||
properties: {
|
||||
count: { type: ['number', 'string'] }
|
||||
}
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export default class GetRecentContact extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.GetRecentContact;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const ret = await NTQQUserApi.getRecentContactListSnapShot(parseInt((payload.count || 10).toString()));
|
||||
const data = await Promise.all(ret.info.changedList.map(async (t) => {
|
||||
const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
|
||||
if (FastMsg.msgList.length > 0) {
|
||||
//扩展ret.info.changedList
|
||||
const lastestMsg = await OB11Constructor.message(this.CoreContext, FastMsg.msgList[0], "array");
|
||||
return {
|
||||
lastestMsg: lastestMsg,
|
||||
peerUin: t.peerUin,
|
||||
remark: t.remark,
|
||||
msgTime: t.msgTime,
|
||||
chatType: t.chatType,
|
||||
msgId: t.msgId,
|
||||
sendNickName: t.sendNickName,
|
||||
sendMemberName: t.sendMemberName,
|
||||
peerName: t.peerName
|
||||
};
|
||||
}
|
||||
return {
|
||||
peerUin: t.peerUin,
|
||||
remark: t.remark,
|
||||
msgTime: t.msgTime,
|
||||
chatType: t.chatType,
|
||||
msgId: t.msgId,
|
||||
sendNickName: t.sendNickName,
|
||||
sendMemberName: t.sendMemberName,
|
||||
peerName: t.peerName
|
||||
};
|
||||
}));
|
||||
return data;
|
||||
}
|
||||
actionName = ActionName.GetRecentContact;
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const ret = await NTQQUserApi.getRecentContactListSnapShot(parseInt((payload.count || 10).toString()));
|
||||
const data = await Promise.all(ret.info.changedList.map(async (t) => {
|
||||
const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
|
||||
if (FastMsg.msgList.length > 0) {
|
||||
//扩展ret.info.changedList
|
||||
const lastestMsg = await OB11Constructor.message(this.CoreContext, FastMsg.msgList[0], "array");
|
||||
return {
|
||||
lastestMsg: lastestMsg,
|
||||
peerUin: t.peerUin,
|
||||
remark: t.remark,
|
||||
msgTime: t.msgTime,
|
||||
chatType: t.chatType,
|
||||
msgId: t.msgId,
|
||||
sendNickName: t.sendNickName,
|
||||
sendMemberName: t.sendMemberName,
|
||||
peerName: t.peerName
|
||||
};
|
||||
}
|
||||
return {
|
||||
peerUin: t.peerUin,
|
||||
remark: t.remark,
|
||||
msgTime: t.msgTime,
|
||||
chatType: t.chatType,
|
||||
msgId: t.msgId,
|
||||
sendNickName: t.sendNickName,
|
||||
sendMemberName: t.sendMemberName,
|
||||
peerName: t.peerName
|
||||
};
|
||||
}));
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@@ -4,33 +4,33 @@ import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
times: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['user_id', 'times']
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
times: { type: ['number', 'string'] }
|
||||
},
|
||||
required: ['user_id', 'times']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
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();
|
||||
const uid: string = await NTQQUserApi.getUidByUin(qq) || '';
|
||||
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1);
|
||||
//logDebug('点赞结果', result);
|
||||
if (result.result !== 0) {
|
||||
throw Error(result.errMsg);
|
||||
}
|
||||
} catch (e) {
|
||||
throw `点赞失败 ${e}`;
|
||||
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();
|
||||
const uid: string = await NTQQUserApi.getUidByUin(qq) || '';
|
||||
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1);
|
||||
//logDebug('点赞结果', result);
|
||||
if (result.result !== 0) {
|
||||
throw Error(result.errMsg);
|
||||
}
|
||||
} catch (e) {
|
||||
throw `点赞失败 ${e}`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -4,24 +4,24 @@ import { ActionName } from '../types';
|
||||
import { NTQQFriendApi } from '@/core/apis/friend';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flag: { type: 'string' },
|
||||
approve: { type: ['string', 'boolean'] },
|
||||
remark: { type: 'string' }
|
||||
},
|
||||
required: ['flag']
|
||||
type: 'object',
|
||||
properties: {
|
||||
flag: { type: 'string' },
|
||||
approve: { type: ['string', 'boolean'] },
|
||||
remark: { type: 'string' }
|
||||
},
|
||||
required: ['flag']
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export enum EventType {
|
||||
|
||||
|
||||
export abstract class OB11BaseEvent {
|
||||
time = Math.floor(Date.now() / 1000);
|
||||
self_id = parseInt(selfInfo.uin);
|
||||
post_type: EventType = EventType.META;
|
||||
time = Math.floor(Date.now() / 1000);
|
||||
self_id = parseInt(selfInfo.uin);
|
||||
post_type: EventType = EventType.META;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { EventType, OB11BaseEvent } from '../OB11BaseEvent';
|
||||
|
||||
export abstract class OB11BaseMessageEvent extends OB11BaseEvent {
|
||||
post_type = EventType.MESSAGE;
|
||||
post_type = EventType.MESSAGE;
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
import { EventType, OB11BaseEvent } from '../OB11BaseEvent';
|
||||
|
||||
export abstract class OB11BaseMetaEvent extends OB11BaseEvent {
|
||||
post_type = EventType.META;
|
||||
meta_event_type: string;
|
||||
post_type = EventType.META;
|
||||
meta_event_type: string;
|
||||
}
|
@@ -6,16 +6,16 @@ interface HeartbeatStatus {
|
||||
}
|
||||
|
||||
export class OB11HeartbeatEvent extends OB11BaseMetaEvent {
|
||||
meta_event_type = 'heartbeat';
|
||||
status: HeartbeatStatus;
|
||||
interval: number;
|
||||
meta_event_type = 'heartbeat';
|
||||
status: HeartbeatStatus;
|
||||
interval: number;
|
||||
|
||||
public constructor(isOnline: boolean, isGood: boolean, interval: number) {
|
||||
super();
|
||||
this.interval = interval;
|
||||
this.status = {
|
||||
online: isOnline,
|
||||
good: isGood
|
||||
};
|
||||
}
|
||||
public constructor(isOnline: boolean, isGood: boolean, interval: number) {
|
||||
super();
|
||||
this.interval = interval;
|
||||
this.status = {
|
||||
online: isOnline,
|
||||
good: isGood
|
||||
};
|
||||
}
|
||||
}
|
@@ -7,11 +7,11 @@ export enum LifeCycleSubType {
|
||||
}
|
||||
|
||||
export class OB11LifeCycleEvent extends OB11BaseMetaEvent {
|
||||
meta_event_type = 'lifecycle';
|
||||
sub_type: LifeCycleSubType;
|
||||
meta_event_type = 'lifecycle';
|
||||
sub_type: LifeCycleSubType;
|
||||
|
||||
public constructor(subType: LifeCycleSubType) {
|
||||
super();
|
||||
this.sub_type = subType;
|
||||
}
|
||||
public constructor(subType: LifeCycleSubType) {
|
||||
super();
|
||||
this.sub_type = subType;
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
import { EventType, OB11BaseEvent } from '../OB11BaseEvent';
|
||||
|
||||
export abstract class OB11BaseNoticeEvent extends OB11BaseEvent {
|
||||
post_type = EventType.NOTICE;
|
||||
post_type = EventType.NOTICE;
|
||||
}
|
@@ -1,11 +1,11 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
|
||||
export class OB11FriendAddNoticeEvent extends OB11BaseNoticeEvent {
|
||||
notice_type = 'friend_add';
|
||||
user_id: number;
|
||||
notice_type = 'friend_add';
|
||||
user_id: number;
|
||||
|
||||
public constructor(user_Id: number) {
|
||||
super();
|
||||
this.user_id = user_Id;
|
||||
}
|
||||
public constructor(user_Id: number) {
|
||||
super();
|
||||
this.user_id = user_Id;
|
||||
}
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
|
||||
export class OB11FriendRecallNoticeEvent extends OB11BaseNoticeEvent {
|
||||
notice_type = 'friend_recall';
|
||||
user_id: number;
|
||||
message_id: number;
|
||||
notice_type = 'friend_recall';
|
||||
user_id: number;
|
||||
message_id: number;
|
||||
|
||||
public constructor(userId: number, messageId: number) {
|
||||
super();
|
||||
this.user_id = userId;
|
||||
this.message_id = messageId;
|
||||
}
|
||||
public constructor(userId: number, messageId: number) {
|
||||
super();
|
||||
this.user_id = userId;
|
||||
this.message_id = messageId;
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
export class OB11GroupAdminNoticeEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_admin';
|
||||
sub_type: 'set' | 'unset' = "set"; // "set" | "unset"
|
||||
notice_type = 'group_admin';
|
||||
sub_type: 'set' | 'unset' = "set"; // "set" | "unset"
|
||||
}
|
@@ -1,17 +1,17 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
export class OB11GroupBanEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_ban';
|
||||
operator_id: number;
|
||||
duration: number;
|
||||
sub_type: 'ban' | 'lift_ban';
|
||||
notice_type = 'group_ban';
|
||||
operator_id: number;
|
||||
duration: number;
|
||||
sub_type: 'ban' | 'lift_ban';
|
||||
|
||||
constructor(groupId: number, userId: number, operatorId: number, duration: number, sub_type: 'ban' | 'lift_ban') {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId;
|
||||
this.user_id = userId;
|
||||
this.duration = duration;
|
||||
this.sub_type = sub_type;
|
||||
}
|
||||
constructor(groupId: number, userId: number, operatorId: number, duration: number, sub_type: 'ban' | 'lift_ban') {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId;
|
||||
this.user_id = userId;
|
||||
this.duration = duration;
|
||||
this.sub_type = sub_type;
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
export class OB11GroupCardEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_card';
|
||||
card_new: string;
|
||||
card_old: string;
|
||||
notice_type = 'group_card';
|
||||
card_new: string;
|
||||
card_old: string;
|
||||
|
||||
|
||||
constructor(groupId: number, userId: number, cardNew: string, cardOld: string) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.card_new = cardNew;
|
||||
this.card_old = cardOld;
|
||||
}
|
||||
constructor(groupId: number, userId: number, cardNew: string, cardOld: string) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.card_new = cardNew;
|
||||
this.card_old = cardOld;
|
||||
}
|
||||
}
|
||||
|
@@ -3,15 +3,15 @@ import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
export type GroupDecreaseSubType = 'leave' | 'kick' | 'kick_me';
|
||||
|
||||
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_decrease';
|
||||
sub_type: GroupDecreaseSubType = 'leave'; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
|
||||
operator_id: number;
|
||||
notice_type = 'group_decrease';
|
||||
sub_type: GroupDecreaseSubType = 'leave'; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
|
||||
operator_id: number;
|
||||
|
||||
constructor(groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
|
||||
this.user_id = userId;
|
||||
this.sub_type = subType;
|
||||
}
|
||||
constructor(groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
|
||||
this.user_id = userId;
|
||||
this.sub_type = subType;
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
export class OB11GroupEssenceEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'essence';
|
||||
message_id: number;
|
||||
sender_id: number;
|
||||
sub_type: 'add' | 'delete' = 'add';
|
||||
notice_type = 'essence';
|
||||
message_id: number;
|
||||
sender_id: number;
|
||||
sub_type: 'add' | 'delete' = 'add';
|
||||
|
||||
constructor(groupId: number, message_id: number, sender_id: number) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.message_id = message_id;
|
||||
this.sender_id = sender_id;
|
||||
}
|
||||
constructor(groupId: number, message_id: number, sender_id: number) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.message_id = message_id;
|
||||
this.sender_id = sender_id;
|
||||
}
|
||||
}
|
||||
|
@@ -2,14 +2,14 @@ import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
type GroupIncreaseSubType = 'approve' | 'invite';
|
||||
export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_increase';
|
||||
operator_id: number;
|
||||
sub_type: GroupIncreaseSubType;
|
||||
constructor(groupId: number, userId: number, operatorId: number, subType: GroupIncreaseSubType = 'approve') {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId;
|
||||
this.user_id = userId;
|
||||
this.sub_type = subType;
|
||||
}
|
||||
notice_type = 'group_increase';
|
||||
operator_id: number;
|
||||
sub_type: GroupIncreaseSubType;
|
||||
constructor(groupId: number, userId: number, operatorId: number, subType: GroupIncreaseSubType = 'approve') {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operator_id = operatorId;
|
||||
this.user_id = userId;
|
||||
this.sub_type = subType;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
|
||||
export abstract class OB11GroupNoticeEvent extends OB11BaseNoticeEvent {
|
||||
group_id: number = 0;
|
||||
user_id: number = 0;
|
||||
group_id: number = 0;
|
||||
user_id: number = 0;
|
||||
}
|
@@ -1,15 +1,15 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
export class OB11GroupRecallNoticeEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_recall';
|
||||
operator_id: number;
|
||||
message_id: number;
|
||||
notice_type = 'group_recall';
|
||||
operator_id: number;
|
||||
message_id: number;
|
||||
|
||||
constructor(groupId: number, userId: number, operatorId: number, messageId: number) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.operator_id = operatorId;
|
||||
this.message_id = messageId;
|
||||
}
|
||||
constructor(groupId: number, userId: number, operatorId: number, messageId: number) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.operator_id = operatorId;
|
||||
this.message_id = messageId;
|
||||
}
|
||||
}
|
@@ -1,15 +1,15 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
export class OB11GroupTitleEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'notify';
|
||||
sub_type = 'title';
|
||||
title: string;
|
||||
notice_type = 'notify';
|
||||
sub_type = 'title';
|
||||
title: string;
|
||||
|
||||
|
||||
constructor(groupId: number, userId: number, title: string) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.title = title;
|
||||
}
|
||||
constructor(groupId: number, userId: number, title: string) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
|
@@ -8,13 +8,13 @@ export interface GroupUploadFile{
|
||||
}
|
||||
|
||||
export class OB11GroupUploadNoticeEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_upload';
|
||||
file: GroupUploadFile;
|
||||
notice_type = 'group_upload';
|
||||
file: GroupUploadFile;
|
||||
|
||||
constructor(groupId: number, userId: number, file: GroupUploadFile) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.file = file;
|
||||
}
|
||||
constructor(groupId: number, userId: number, file: GroupUploadFile) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId;
|
||||
this.file = file;
|
||||
}
|
||||
}
|
@@ -1,16 +1,16 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
//输入状态事件 初步完成 Mlikio wa Todo 需要做一些过滤
|
||||
export class OB11InputStatusEvent extends OB11BaseNoticeEvent {
|
||||
notice_type = 'notify';
|
||||
sub_type = 'input_status';
|
||||
status_text = "对方正在输入..."
|
||||
eventType = 1;
|
||||
user_id = 0;
|
||||
constructor(user_id: number, eventType: number, status_text: string) {
|
||||
super();
|
||||
this.user_id = user_id;
|
||||
this.eventType = eventType;
|
||||
this.status_text = status_text;
|
||||
}
|
||||
notice_type = 'notify';
|
||||
sub_type = 'input_status';
|
||||
status_text = "对方正在输入...";
|
||||
eventType = 1;
|
||||
user_id = 0;
|
||||
constructor(user_id: number, eventType: number, status_text: string) {
|
||||
super();
|
||||
this.user_id = user_id;
|
||||
this.eventType = eventType;
|
||||
this.status_text = status_text;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,15 +6,15 @@ export interface MsgEmojiLike {
|
||||
}
|
||||
|
||||
export class OB11GroupMsgEmojiLikeEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_msg_emoji_like';
|
||||
message_id: number;
|
||||
likes: MsgEmojiLike[];
|
||||
notice_type = 'group_msg_emoji_like';
|
||||
message_id: number;
|
||||
likes: MsgEmojiLike[];
|
||||
|
||||
constructor(groupId: number, userId: number, messageId: number, likes: MsgEmojiLike[]) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId; // 可为空,表示是对别人的消息操作,如果是对bot自己的消息则不为空
|
||||
this.message_id = messageId;
|
||||
this.likes = likes;
|
||||
}
|
||||
constructor(groupId: number, userId: number, messageId: number, likes: MsgEmojiLike[]) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId; // 可为空,表示是对别人的消息操作,如果是对bot自己的消息则不为空
|
||||
this.message_id = messageId;
|
||||
this.likes = likes;
|
||||
}
|
||||
}
|
||||
|
@@ -1,32 +1,32 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
|
||||
class OB11PokeEvent extends OB11BaseNoticeEvent {
|
||||
notice_type = 'notify';
|
||||
sub_type = 'poke';
|
||||
target_id = 0;
|
||||
user_id = 0;
|
||||
notice_type = 'notify';
|
||||
sub_type = 'poke';
|
||||
target_id = 0;
|
||||
user_id = 0;
|
||||
}
|
||||
|
||||
export class OB11FriendPokeEvent extends OB11PokeEvent {
|
||||
raw_info: any;
|
||||
//raw_message nb等框架标准为string
|
||||
constructor(user_id: number, target_id: number, raw_message: any) {
|
||||
super();
|
||||
this.target_id = target_id;
|
||||
this.user_id = user_id;
|
||||
this.raw_info = raw_message;
|
||||
}
|
||||
raw_info: any;
|
||||
//raw_message nb等框架标准为string
|
||||
constructor(user_id: number, target_id: number, raw_message: any) {
|
||||
super();
|
||||
this.target_id = target_id;
|
||||
this.user_id = user_id;
|
||||
this.raw_info = raw_message;
|
||||
}
|
||||
}
|
||||
|
||||
export class OB11GroupPokeEvent extends OB11PokeEvent {
|
||||
group_id: number;
|
||||
raw_info: any;
|
||||
//raw_message nb等框架标准为string
|
||||
constructor(group_id: number, user_id: number = 0, target_id: number = 0, raw_message: any) {
|
||||
super();
|
||||
this.group_id = group_id;
|
||||
this.target_id = target_id;
|
||||
this.user_id = user_id;
|
||||
this.raw_info = raw_message;
|
||||
}
|
||||
group_id: number;
|
||||
raw_info: any;
|
||||
//raw_message nb等框架标准为string
|
||||
constructor(group_id: number, user_id: number = 0, target_id: number = 0, raw_message: any) {
|
||||
super();
|
||||
this.group_id = group_id;
|
||||
this.target_id = target_id;
|
||||
this.user_id = user_id;
|
||||
this.raw_info = raw_message;
|
||||
}
|
||||
}
|
||||
|
@@ -3,9 +3,9 @@ import { EventType } from '../OB11BaseEvent';
|
||||
|
||||
|
||||
export class OB11FriendRequestEvent extends OB11BaseNoticeEvent {
|
||||
post_type = EventType.REQUEST;
|
||||
user_id: number = 0;
|
||||
request_type = 'friend' as const;
|
||||
comment: string = '';
|
||||
flag: string = '';
|
||||
post_type = EventType.REQUEST;
|
||||
user_id: number = 0;
|
||||
request_type = 'friend' as const;
|
||||
comment: string = '';
|
||||
flag: string = '';
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user