mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 13:05:09 +00:00
chore: run a full eslint
This commit is contained in:
@@ -11,10 +11,12 @@ class BaseAction<PayloadType, ReturnDataType> {
|
||||
private validate: undefined | ValidateFunction<any> = undefined;
|
||||
PayloadSchema: any = undefined;
|
||||
OneBotContext: NapCatOneBot11Adapter;
|
||||
constructor(onebotContext:NapCatOneBot11Adapter,coreContext: NapCatCore) {
|
||||
|
||||
constructor(onebotContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
|
||||
this.OneBotContext = onebotContext;
|
||||
this.CoreContext = coreContext;
|
||||
}
|
||||
|
||||
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
||||
if (this.PayloadSchema) {
|
||||
this.validate = new Ajv({ allowUnionTypes: true }).compile(this.PayloadSchema);
|
||||
@@ -26,11 +28,11 @@ class BaseAction<PayloadType, ReturnDataType> {
|
||||
});
|
||||
return {
|
||||
valid: false,
|
||||
message: errorMessages.join('\n') as string || '未知错误'
|
||||
message: errorMessages.join('\n') as string || '未知错误',
|
||||
};
|
||||
}
|
||||
return {
|
||||
valid: true
|
||||
valid: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export class OB11Response {
|
||||
data: data,
|
||||
message: message,
|
||||
wording: message,
|
||||
echo: null
|
||||
echo: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
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' }
|
||||
brief: { type: 'string' },
|
||||
},
|
||||
required: ['brief', 'rawData'],
|
||||
} as const satisfies JSONSchema;
|
||||
@@ -15,12 +16,13 @@ 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
|
||||
payload.brief, payload.rawData,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
count: { type: 'number' },
|
||||
}
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -13,8 +14,9 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export class FetchCustomFace extends BaseAction<Payload, string[]> {
|
||||
actionName = ActionName.FetchCustomFace;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload) {
|
||||
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
|
||||
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
|
||||
const ret = await this.CoreContext.getApiContext().MsgApi.fetchFavEmojiList(payload.count || 48);
|
||||
return ret.emojiInfoList.map(e => e.url);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ const SchemaData = {
|
||||
emojiId: { type: 'string' },
|
||||
emojiType: { type: 'string' },
|
||||
message_id: { type: ['string', 'number'] },
|
||||
count: { type: 'number' }
|
||||
count: { type: 'number' },
|
||||
},
|
||||
required: ['emojiId', 'emojiType', 'message_id']
|
||||
required: ['emojiId', 'emojiType', 'message_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -22,10 +22,11 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export class FetchEmojiLike extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.FetchEmojiLike;
|
||||
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('消息不存在');
|
||||
if (!msgIdPeer) throw new Error('消息不存在');
|
||||
const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
||||
return await NTQQMsgApi.getMsgEmojiLikesList(msgIdPeer.Peer, msg.msgSeq, payload.emojiId, payload.emojiType, payload.count);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
@@ -7,7 +6,7 @@ const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
category: { type: 'number' },
|
||||
count: { type: 'number' }
|
||||
count: { type: 'number' },
|
||||
},
|
||||
required: ['category', 'count'],
|
||||
} as const satisfies JSONSchema;
|
||||
@@ -17,6 +16,7 @@ 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);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { OB11Constructor } from '@/onebot/helper/constructor';
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/apis/group';
|
||||
|
||||
interface OB11GroupRequestNotify {
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
flag: string
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
flag: string
|
||||
}
|
||||
|
||||
export default class GetGroupAddRequest extends BaseAction<null, OB11GroupRequestNotify[] | null> {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
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);
|
||||
|
||||
@@ -1,11 +1,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;
|
||||
|
||||
protected async _handle(payload: void) {
|
||||
// console.log(await NTQQUserApi.getRobotUinRange());
|
||||
// console.log(await NTQQUserApi.getRobotUinRange());
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
return await NTQQUserApi.getRobotUinRange();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ const SchemaData = {
|
||||
properties: {
|
||||
image: { type: 'string' },
|
||||
},
|
||||
required: ['image']
|
||||
required: ['image'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,9 +17,10 @@ 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));
|
||||
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.image));
|
||||
if (!success) {
|
||||
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
|
||||
}
|
||||
@@ -27,7 +28,8 @@ export class OCRImage extends BaseAction<Payload, any> {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQSystemApi.ORCImage(path);
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
fs.unlink(path, () => {
|
||||
});
|
||||
}
|
||||
if (!ret) {
|
||||
throw `OCR ${payload.file}失败`;
|
||||
@@ -35,11 +37,13 @@ export class OCRImage extends BaseAction<Payload, any> {
|
||||
return ret.result;
|
||||
}
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
fs.unlink(path, () => {
|
||||
});
|
||||
}
|
||||
throw `OCR ${payload.file}失败,文件可能不存在`;
|
||||
}
|
||||
}
|
||||
|
||||
export class IOCRImage extends OCRImage {
|
||||
actionName = ActionName.IOCRImage;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import * as fs from 'node:fs';
|
||||
import { NTQQUserApi } from '@/core/apis/user';
|
||||
import { checkFileReceived, uri2local } from '@/common/utils/file';
|
||||
|
||||
// import { log } from "../../../common/utils";
|
||||
|
||||
interface Payload {
|
||||
file: string,
|
||||
groupCode: string
|
||||
file: string,
|
||||
groupCode: string
|
||||
}
|
||||
|
||||
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') {
|
||||
@@ -24,6 +25,7 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
|
||||
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));
|
||||
@@ -34,7 +36,8 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQGroupApi.setGroupAvatar(payload.groupCode, path);
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
fs.unlink(path, () => {
|
||||
});
|
||||
}
|
||||
if (!ret) {
|
||||
throw `头像${payload.file}设置失败,api无返回`;
|
||||
@@ -48,7 +51,8 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
|
||||
return ret;
|
||||
} else {
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
fs.unlink(path, () => {
|
||||
});
|
||||
}
|
||||
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi } from '@/core/apis';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
@@ -9,7 +7,7 @@ const SchemaData = {
|
||||
properties: {
|
||||
longNick: { type: 'string' },
|
||||
},
|
||||
required: [ 'longNick'],
|
||||
required: ['longNick'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,6 +15,7 @@ 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);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import { NTQQUserApi } from '@/core/apis';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
// 设置在线状态
|
||||
|
||||
@@ -9,7 +8,7 @@ const SchemaData = {
|
||||
properties: {
|
||||
status: { type: 'number' },
|
||||
extStatus: { type: 'number' },
|
||||
batteryStatus: { type: 'number' }
|
||||
batteryStatus: { type: 'number' },
|
||||
},
|
||||
required: ['status', 'extStatus', 'batteryStatus'],
|
||||
} as const satisfies JSONSchema;
|
||||
@@ -19,13 +18,14 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export class SetOnlineStatus extends BaseAction<Payload, null> {
|
||||
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 }
|
||||
// 可设置状态
|
||||
// { 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) {
|
||||
|
||||
@@ -2,12 +2,14 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import * as fs from 'node:fs';
|
||||
import { checkFileReceived, uri2local } from '@/common/utils/file';
|
||||
|
||||
interface Payload {
|
||||
file: string
|
||||
file: string;
|
||||
}
|
||||
|
||||
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') {
|
||||
@@ -20,6 +22,7 @@ export default class SetAvatar extends BaseAction<Payload, null> {
|
||||
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));
|
||||
@@ -30,7 +33,8 @@ export default class SetAvatar extends BaseAction<Payload, null> {
|
||||
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||
const ret = await NTQQUserApi.setQQAvatar(path);
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
fs.unlink(path, () => {
|
||||
});
|
||||
}
|
||||
if (!ret) {
|
||||
throw `头像${payload.file}设置失败,api无返回`;
|
||||
@@ -43,7 +47,8 @@ export default class SetAvatar extends BaseAction<Payload, null> {
|
||||
}
|
||||
} else {
|
||||
if (!isLocal) {
|
||||
fs.unlink(path, () => { });
|
||||
fs.unlink(path, () => {
|
||||
});
|
||||
}
|
||||
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
@@ -8,7 +7,7 @@ const SchemaData = {
|
||||
properties: {
|
||||
nick: { type: 'string' },
|
||||
longNick: { type: 'string' },
|
||||
sex: { type: 'number' }//传Sex值?建议传0
|
||||
sex: { type: 'number' },//传Sex值?建议传0
|
||||
},
|
||||
required: ['nick', 'longNick', 'sex'],
|
||||
} as const satisfies JSONSchema;
|
||||
@@ -18,6 +17,7 @@ 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({
|
||||
@@ -25,7 +25,7 @@ export class SetSelfProfile extends BaseAction<Payload, any | null> {
|
||||
longNick: payload.longNick,
|
||||
sex: payload.sex,
|
||||
birthday: { birthday_year: '', birthday_month: '', birthday_day: '' },
|
||||
location: undefined
|
||||
location: undefined,
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQSystemApi } from '@/core/apis';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
@@ -8,8 +7,8 @@ const SchemaData = {
|
||||
properties: {
|
||||
words: {
|
||||
type: 'array',
|
||||
items: { type: 'string' }
|
||||
}
|
||||
items: { type: 'string' },
|
||||
},
|
||||
},
|
||||
required: ['words'],
|
||||
} as const satisfies JSONSchema;
|
||||
@@ -19,6 +18,7 @@ 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);
|
||||
|
||||
@@ -17,6 +17,7 @@ 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;
|
||||
@@ -27,20 +28,23 @@ export class sharePeer extends BaseAction<Payload, any> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const SchemaDataGroupEx = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: 'string' },
|
||||
},
|
||||
required: ['group_id']
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
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']
|
||||
required: ['group_id', 'file_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -15,6 +16,7 @@ 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]);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
@@ -9,7 +8,7 @@ const SchemaData = {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
folder_id: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'folder_id']
|
||||
required: ['group_id', 'folder_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,6 +16,7 @@ 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;
|
||||
|
||||
@@ -6,26 +6,28 @@ import { ChatType, ElementType, FileElement, Peer, RawMessage, VideoElement } fr
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
export interface GetFilePayload {
|
||||
file: string; // 文件名或者fileUuid
|
||||
file: string; // 文件名或者fileUuid
|
||||
}
|
||||
|
||||
export interface GetFileResponse {
|
||||
file?: string; // path
|
||||
url?: string;
|
||||
file_size?: string;
|
||||
file_name?: string;
|
||||
base64?: string;
|
||||
file?: string; // path
|
||||
url?: string;
|
||||
file_size?: string;
|
||||
file_name?: string;
|
||||
base64?: string;
|
||||
}
|
||||
|
||||
const GetFileBase_PayloadSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
file: { type: 'string' }
|
||||
file: { type: 'string' },
|
||||
},
|
||||
required: ['file']
|
||||
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) {
|
||||
@@ -38,6 +40,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
}
|
||||
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;
|
||||
@@ -45,9 +48,9 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQFileApi = this.CoreContext.getApiContext().FileApi;
|
||||
let UuidData: {
|
||||
high: string;
|
||||
low: string;
|
||||
} | undefined;
|
||||
high: string;
|
||||
low: string;
|
||||
} | undefined;
|
||||
try {
|
||||
UuidData = UUIDConverter.decode(payload.file);
|
||||
if (UuidData) {
|
||||
@@ -87,7 +90,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
file: downloadPath,
|
||||
url: downloadPath,
|
||||
file_size: fileSize,
|
||||
file_name: fileName
|
||||
file_name: fileName,
|
||||
};
|
||||
if (true/*enableLocalFile2Url*/) {
|
||||
try {
|
||||
@@ -127,7 +130,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
file: downloadPath,
|
||||
url: downloadPath,
|
||||
file_size: NTSearchNameResult[0].fileSize.toString(),
|
||||
file_name: NTSearchNameResult[0].fileName
|
||||
file_name: NTSearchNameResult[0].fileName,
|
||||
};
|
||||
if (true/*enableLocalFile2Url*/) {
|
||||
try {
|
||||
@@ -182,24 +185,24 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
// // }
|
||||
// }
|
||||
|
||||
// }
|
||||
// // log('file found', cache);
|
||||
// const res: GetFileResponse = {
|
||||
// file: cache.path,
|
||||
// url: cache.url,
|
||||
// file_size: cache.size.toString(),
|
||||
// file_name: cache.name
|
||||
// };
|
||||
// if (enableLocalFile2Url) {
|
||||
// if (!cache.url) {
|
||||
// try {
|
||||
// res.base64 = await fs.readFile(cache.path, 'base64');
|
||||
// } catch (e) {
|
||||
// throw new Error('文件下载失败. ' + e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//return res;
|
||||
// }
|
||||
// // log('file found', cache);
|
||||
// const res: GetFileResponse = {
|
||||
// file: cache.path,
|
||||
// url: cache.url,
|
||||
// file_size: cache.size.toString(),
|
||||
// file_name: cache.name
|
||||
// };
|
||||
// if (enableLocalFile2Url) {
|
||||
// if (!cache.url) {
|
||||
// try {
|
||||
// res.base64 = await fs.readFile(cache.path, 'base64');
|
||||
// } catch (e) {
|
||||
// throw new Error('文件下载失败. ' + e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,20 +210,21 @@ const GetFile_PayloadSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
file_id: { type: 'string' },
|
||||
file: { type: 'string' }
|
||||
file: { type: 'string' },
|
||||
},
|
||||
required: ['file_id']
|
||||
required: ['file_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type GetFile_Payload_Internal = FromSchema<typeof GetFile_PayloadSchema>;
|
||||
|
||||
interface GetFile_Payload extends GetFile_Payload_Internal {
|
||||
file: string
|
||||
file: string;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi, NTQQUserApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['string', 'number'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
required: ['group_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -16,6 +15,7 @@ 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()]);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -8,7 +9,7 @@ const SchemaData = {
|
||||
start_index: { type: 'number' },
|
||||
file_count: { type: 'number' },
|
||||
},
|
||||
required: ['group_id', 'start_index', 'file_count']
|
||||
required: ['group_id', 'start_index', 'file_count'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -16,6 +17,7 @@ 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(), {
|
||||
@@ -23,8 +25,10 @@ export class GetGroupFileList extends BaseAction<Payload, { FileList: Array<any>
|
||||
fileCount: payload.file_count,
|
||||
startIndex: payload.start_index,
|
||||
sortOrder: 2,
|
||||
showOnlinedocFolder: 0
|
||||
}).catch((e) => { return []; });
|
||||
showOnlinedocFolder: 0,
|
||||
}).catch((e) => {
|
||||
return [];
|
||||
});
|
||||
return { FileList: ret };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { GetFileBase, GetFilePayload, GetFileResponse } from './GetFile';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
interface Payload extends GetFilePayload {
|
||||
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
|
||||
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac';
|
||||
}
|
||||
|
||||
export default class GetRecord extends GetFileBase {
|
||||
@@ -12,4 +12,4 @@ export default class GetRecord extends GetFileBase {
|
||||
const res = super._handle(payload);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
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']
|
||||
required: ['group_id', 'folder_name'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -15,6 +16,7 @@ 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;
|
||||
|
||||
@@ -5,9 +5,11 @@ import { join as joinPath } from 'node:path';
|
||||
import { calculateFileMD5, httpDownload } from '@/common/utils/file';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
interface FileResponse {
|
||||
file: string;
|
||||
file: string;
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -18,9 +20,9 @@ const SchemaData = {
|
||||
headers: {
|
||||
type: ['string', 'array'],
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
@@ -29,6 +31,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GoCQHTTPDownloadFile extends BaseAction<Payload, FileResponse> {
|
||||
actionName = ActionName.GoCQHTTP_DownloadFile;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<FileResponse> {
|
||||
const isRandomName = !payload.name;
|
||||
const name = payload.name || randomUUID();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11ForwardMessage, OB11Message, OB11MessageData } from '../../types';
|
||||
import { NTQQMsgApi } from '@/core/apis';
|
||||
import { OB11Constructor } from '../../helper/data';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
@@ -10,19 +9,20 @@ const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: 'string' },
|
||||
id: { type: 'string' }
|
||||
id: { type: 'string' },
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
interface Response {
|
||||
messages: (OB11Message & { content: OB11MessageData })[];
|
||||
messages: (OB11Message & { content: OB11MessageData })[];
|
||||
}
|
||||
|
||||
export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_GetForwardMsg;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
const msgId = payload.message_id || payload.id;
|
||||
@@ -40,8 +40,12 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
|
||||
}
|
||||
const msgList = data.msgList;
|
||||
const messages = await Promise.all(msgList.map(async msg => {
|
||||
const resMsg = await OB11Constructor.message(this.CoreContext, msg, "array");
|
||||
resMsg.message_id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)!;
|
||||
const resMsg = await OB11Constructor.message(this.CoreContext, msg, 'array');
|
||||
resMsg.message_id = MessageUnique.createMsg({
|
||||
guildId: '',
|
||||
chatType: msg.chatType,
|
||||
peerUid: msg.peerUid,
|
||||
}, msg.msgId)!;
|
||||
return resMsg;
|
||||
}));
|
||||
messages.map(msg => {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11Message, OB11User } from '../../types';
|
||||
import { OB11Message } from '../../types';
|
||||
import { ActionName } from '../types';
|
||||
import { ChatType, RawMessage } from '@/core/entities';
|
||||
import { NTQQMsgApi } from '@/core/apis/msg';
|
||||
import { OB11Constructor } from '../../helper/data';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
interface Response {
|
||||
messages: OB11Message[];
|
||||
messages: OB11Message[];
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
@@ -17,9 +16,9 @@ const SchemaData = {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
message_seq: { type: 'number' },
|
||||
count: { type: 'number' },
|
||||
reverseOrder: { type: 'boolean' }
|
||||
reverseOrder: { type: 'boolean' },
|
||||
},
|
||||
required: ['user_id']
|
||||
required: ['user_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -27,6 +26,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
||||
actionName = ActionName.GetFriendMsgHistory;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
@@ -53,7 +53,7 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
||||
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
||||
}));
|
||||
//转换消息
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, "array")));
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
|
||||
return { 'messages': ob11MsgList };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { WebHonorType } from '@/core/entities';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
type: { enum: [WebHonorType.ALL, WebHonorType.EMOTION, WebHonorType.LEGEND, WebHonorType.PERFORMER, WebHonorType.STRONG_NEWBIE, WebHonorType.TALKATIVE] }
|
||||
group_id: { type: ['number', 'string'] },
|
||||
type: { enum: [WebHonorType.ALL, WebHonorType.EMOTION, WebHonorType.LEGEND, WebHonorType.PERFORMER, WebHonorType.STRONG_NEWBIE, WebHonorType.TALKATIVE] },
|
||||
},
|
||||
required: ['group_id']
|
||||
required: ['group_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
// enum是不是有点抽象
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
|
||||
actionName = ActionName.GetGroupHonorInfo;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload) {
|
||||
if (!payload.type) {
|
||||
payload.type = WebHonorType.ALL;
|
||||
|
||||
@@ -5,8 +5,9 @@ import { ChatType, Peer, RawMessage } from '@/core/entities';
|
||||
import { OB11Constructor } from '../../helper/data';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
interface Response {
|
||||
messages: OB11Message[];
|
||||
messages: OB11Message[];
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
@@ -15,9 +16,9 @@ const SchemaData = {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
message_seq: { type: 'number' },
|
||||
count: { type: 'number' },
|
||||
reverseOrder: { type: 'boolean' }
|
||||
reverseOrder: { type: 'boolean' },
|
||||
},
|
||||
required: ['group_id']
|
||||
required: ['group_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -25,6 +26,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Response> {
|
||||
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<Response> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
//处理参数
|
||||
@@ -46,7 +48,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
||||
}));
|
||||
|
||||
//转换消息
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, "array")));
|
||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
|
||||
return { 'messages': ob11MsgList };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,18 +7,18 @@ const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
no_cache: { type: 'boolean' },
|
||||
}
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
export class GetOnlineClient extends BaseAction<void, Array<any>> {
|
||||
actionName = ActionName.GetOnlineClient;
|
||||
|
||||
protected async _handle(payload: void) {
|
||||
//注册监听
|
||||
//注册监听
|
||||
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
|
||||
NTQQSystemApi.getOnlineDev();
|
||||
await sleep(500);
|
||||
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@ import { OB11Constructor } from '../../helper/data';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { calcQQLevel } from '@/common/utils/helper';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['user_id']
|
||||
required: ['user_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -32,7 +33,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
||||
qid: extendData.info.qid,
|
||||
level: extendData.info.qqLevel && calcQQLevel(extendData.info.qqLevel) || 0,
|
||||
login_days: 0,
|
||||
uid: ''
|
||||
uid: '',
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -3,15 +3,16 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { QuickAction, QuickActionEvent } from '@/onebot/types';
|
||||
|
||||
interface Payload{
|
||||
context: QuickActionEvent,
|
||||
operation: QuickAction
|
||||
interface Payload {
|
||||
context: QuickActionEvent,
|
||||
operation: QuickAction
|
||||
}
|
||||
|
||||
export class GoCQHTTPHandleQuickAction extends BaseAction<Payload, null>{
|
||||
export class GoCQHTTPHandleQuickAction extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_HandleQuickAction;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
handleQuickOperation(this.CoreContext,payload.context, payload.operation).then().catch(this.CoreContext.context.logger.logError);
|
||||
handleQuickOperation(this.CoreContext, payload.context, payload.operation).then().catch(this.CoreContext.context.logger.logError);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import SendMsg, { normalize } from '../msg/SendMsg';
|
||||
import { OB11PostSendMsg } from '../../types';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
// 未验证
|
||||
export class GoCQHTTPSendForwardMsg extends SendMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendForwardMsg;
|
||||
|
||||
@@ -3,6 +3,7 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { unlink } from 'node:fs';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -10,21 +11,27 @@ const SchemaData = {
|
||||
content: { type: 'string' },
|
||||
image: { type: 'string' },
|
||||
pinned: { type: 'number' },
|
||||
confirmRequired: { type: 'number' }
|
||||
confirmRequired: { type: 'number' },
|
||||
},
|
||||
required: ['group_id', 'content']
|
||||
required: ['group_id', 'content'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
export class SendGroupNotice extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
||||
|
||||
protected async _handle(payload: Payload) {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
|
||||
if (payload.image) {
|
||||
//公告图逻辑
|
||||
const { errMsg, path, isLocal, success } = (await uri2local(this.CoreContext.NapCatTempPath,payload.image));
|
||||
const {
|
||||
errMsg,
|
||||
path,
|
||||
isLocal,
|
||||
success,
|
||||
} = (await uri2local(this.CoreContext.NapCatTempPath, payload.image));
|
||||
if (!success) {
|
||||
throw `群公告${payload.image}设置失败,image字段可能格式不正确`;
|
||||
}
|
||||
@@ -37,7 +44,8 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
|
||||
throw `群公告${payload.image}设置失败,图片上传失败`;
|
||||
}
|
||||
if (!isLocal) {
|
||||
unlink(path, () => { });
|
||||
unlink(path, () => {
|
||||
});
|
||||
}
|
||||
UploadImage = ImageUploadResult.picInfo;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { sendMsg } from '@/onebot/action/msg/SendMsg';
|
||||
import { uri2local } from '@/common/utils/file';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -13,9 +14,9 @@ const SchemaData = {
|
||||
file: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
folder: { type: 'string' },
|
||||
folder_id: { type: 'string' }//临时扩展
|
||||
folder_id: { type: 'string' },//临时扩展
|
||||
},
|
||||
required: ['group_id', 'file', 'name']
|
||||
required: ['group_id', 'file', 'name'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -23,6 +24,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
let file = payload.file;
|
||||
if (fs.existsSync(file)) {
|
||||
@@ -33,7 +35,10 @@ export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
||||
throw new Error(downloadResult.errMsg);
|
||||
}
|
||||
const sendFileEle: SendFileElement = await SendMsgElementConstructor.file(this.CoreContext, downloadResult.path, payload.name, payload.folder_id);
|
||||
await sendMsg(this.CoreContext, { chatType: ChatType.group, peerUid: payload.group_id.toString() }, [sendFileEle], [], true);
|
||||
await sendMsg(this.CoreContext, {
|
||||
chatType: ChatType.group,
|
||||
peerUid: payload.group_id.toString(),
|
||||
}, [sendFileEle], [], true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,15 @@ import { sendMsg } from '@/onebot/action/msg/SendMsg';
|
||||
import { uri2local } from '@/common/utils/file';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
file: { type: 'string' },
|
||||
name: { type: 'string' }
|
||||
name: { type: 'string' },
|
||||
},
|
||||
required: ['user_id', 'file', 'name']
|
||||
required: ['user_id', 'file', 'name'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -21,6 +22,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GOCQHTTP_UploadPrivateFile;
|
||||
PayloadSchema = SchemaData;
|
||||
|
||||
async getPeer(payload: Payload): Promise<Peer> {
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
@@ -34,6 +36,7 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
|
||||
}
|
||||
throw '缺少参数 user_id';
|
||||
}
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const peer = await this.getPeer(payload);
|
||||
let file = payload.file;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
@@ -7,9 +6,9 @@ import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['number', 'string'] }
|
||||
message_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['message_id']
|
||||
required: ['message_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,6 +16,7 @@ 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()));
|
||||
@@ -25,7 +25,7 @@ export default class DelEssenceMsg extends BaseAction<Payload, any> {
|
||||
}
|
||||
return await NTQQGroupApi.removeGroupEssence(
|
||||
msg.Peer.peerUid,
|
||||
msg.MsgId
|
||||
msg.MsgId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
group_id: { type: ['number', 'string'] },
|
||||
pages: { type: 'number' },
|
||||
},
|
||||
required: ['group_id', 'pages']
|
||||
required: ['group_id', 'pages'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,6 +17,7 @@ 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());
|
||||
|
||||
@@ -9,7 +9,7 @@ const SchemaData = {
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
required: ['group_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,6 +17,7 @@ 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());
|
||||
|
||||
@@ -9,7 +9,7 @@ const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
}
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,9 +17,10 @@ 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');
|
||||
const groupList: Group[] = await NTQQGroupApi.getGroups(payload?.no_cache === true || payload.no_cache === 'true');
|
||||
return OB11Constructor.groups(groupList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { OB11Constructor } from '../../helper/data';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -10,7 +11,7 @@ const SchemaData = {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
no_cache: { type: ['boolean', 'string'] },
|
||||
},
|
||||
required: ['group_id', 'user_id']
|
||||
required: ['group_id', 'user_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -18,6 +19,7 @@ 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;
|
||||
@@ -74,4 +76,5 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
||||
return retMember;
|
||||
}
|
||||
}
|
||||
export default GetGroupMemberInfo;
|
||||
|
||||
export default GetGroupMemberInfo;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
import { OB11GroupMember } from '../../types';
|
||||
import { OB11Constructor } from '../../helper/data';
|
||||
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']
|
||||
required: ['group_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -18,6 +18,7 @@ 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;
|
||||
@@ -31,7 +32,9 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
||||
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); });
|
||||
let _groupMembers = groupMembersArr.map(item => {
|
||||
return OB11Constructor.groupMember(group.groupCode, item);
|
||||
});
|
||||
|
||||
const MemberMap: Map<number, OB11GroupMember> = new Map<number, OB11GroupMember>();
|
||||
// 转为Map 方便索引
|
||||
|
||||
@@ -2,25 +2,26 @@ import { WebApiGroupNoticeFeed } from '@/core';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
interface GroupNotice {
|
||||
sender_id: number
|
||||
publish_time: number
|
||||
message: {
|
||||
text: string
|
||||
image: Array<{
|
||||
height: string
|
||||
width: string
|
||||
id: string
|
||||
}>
|
||||
}
|
||||
sender_id: number;
|
||||
publish_time: number;
|
||||
message: {
|
||||
text: string
|
||||
image: Array<{
|
||||
height: string
|
||||
width: string
|
||||
id: string
|
||||
}>
|
||||
};
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
group_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
required: ['group_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -30,6 +31,7 @@ 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;
|
||||
|
||||
@@ -49,8 +51,8 @@ export class GetGroupNotice extends BaseAction<Payload, GroupNotice[]> {
|
||||
text: retApiNotice.msg.text,
|
||||
image: retApiNotice.msg.pics?.map((pic) => {
|
||||
return { id: pic.id, height: pic.h, width: pic.w };
|
||||
}) || []
|
||||
}
|
||||
}) || [],
|
||||
},
|
||||
};
|
||||
retNotices.push(retNotice);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] }
|
||||
group_id: { type: ['number', 'string'] },
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
@@ -13,6 +13,7 @@ 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;
|
||||
|
||||
@@ -6,9 +6,9 @@ import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['number', 'string'] }
|
||||
message_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['message_id']
|
||||
required: ['message_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -16,6 +16,7 @@ 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()));
|
||||
@@ -24,7 +25,7 @@ export default class SetEssenceMsg extends BaseAction<Payload, any> {
|
||||
}
|
||||
return await NTQQGroupApi.addGroupEssence(
|
||||
msg.Peer.peerUid,
|
||||
msg.MsgId
|
||||
msg.MsgId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { GroupRequestOperateTypes } from '@/core/entities';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/apis/group';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
@@ -9,7 +8,7 @@ const SchemaData = {
|
||||
properties: {
|
||||
flag: { type: 'string' },
|
||||
approve: { type: ['string', 'boolean'] },
|
||||
reason: { type: 'string', nullable: true, }
|
||||
reason: { type: 'string', nullable: true },
|
||||
},
|
||||
required: ['flag'],
|
||||
} as const satisfies JSONSchema;
|
||||
@@ -19,13 +18,14 @@ 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 || " "
|
||||
payload.reason || ' ',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { GroupMemberRole } from '@/core/entities';
|
||||
import { ActionName } from '../types';
|
||||
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' }
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] },
|
||||
enable: { type: 'boolean' },
|
||||
},
|
||||
required: ['group_id', 'user_id']
|
||||
required: ['group_id', 'user_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -19,11 +18,12 @@ 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;
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if(!uid) throw new Error('get Uid Error');
|
||||
if (!uid) throw new Error('get Uid Error');
|
||||
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ const SchemaData = {
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] },
|
||||
duration: { type: ['number', 'string'] }
|
||||
duration: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['group_id', 'user_id', 'duration']
|
||||
required: ['group_id', 'user_id', 'duration'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,11 +17,12 @@ 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');
|
||||
if (!uid) throw new Error('uid error');
|
||||
await NTQQGroupApi.banMember(payload.group_id.toString(),
|
||||
[{ uid: uid, timeStamp: parseInt(payload.duration.toString()) }]);
|
||||
return null;
|
||||
|
||||
@@ -5,11 +5,11 @@ 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' }
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] },
|
||||
card: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'user_id', 'card']
|
||||
required: ['group_id', 'user_id', 'card'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,6 +17,7 @@ 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 || '');
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
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' ] },
|
||||
reject_add_request: { type: [ 'boolean' , 'string' ] }
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] },
|
||||
reject_add_request: { type: ['boolean', 'string'] },
|
||||
},
|
||||
required: ['group_id', 'user_id']
|
||||
required: ['group_id', 'user_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -19,12 +18,13 @@ 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');
|
||||
if (!uid) throw new Error('get Uid Error');
|
||||
await NTQQGroupApi.kickMember(payload.group_id.toString(), [uid], rejectReq);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
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' }
|
||||
group_id: { type: ['number', 'string'] },
|
||||
is_dismiss: { type: 'boolean' },
|
||||
},
|
||||
required: ['group_id']
|
||||
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;
|
||||
await NTQQGroupApi.quitGroup(payload.group_id.toString());
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/apis/group';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: [ 'number' , 'string' ] },
|
||||
group_name: { type: 'string' }
|
||||
group_id: { type: ['number', 'string'] },
|
||||
group_name: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'group_name']
|
||||
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);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
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'] }
|
||||
group_id: { type: ['number', 'string'] },
|
||||
enable: { type: ['boolean', 'string'] },
|
||||
},
|
||||
required: ['group_id']
|
||||
required: ['group_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -15,6 +16,7 @@ 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;
|
||||
|
||||
@@ -17,7 +17,7 @@ import GetStatus from './system/GetStatus';
|
||||
import {
|
||||
GoCQHTTPSendForwardMsg,
|
||||
GoCQHTTPSendGroupForwardMsg,
|
||||
GoCQHTTPSendPrivateForwardMsg
|
||||
GoCQHTTPSendPrivateForwardMsg,
|
||||
} from './go-cqhttp/SendForwardMsg';
|
||||
import GoCQHTTPGetStrangerInfo from './go-cqhttp/GetStrangerInfo';
|
||||
import SendLike from './user/SendLike';
|
||||
@@ -78,86 +78,86 @@ import { NapCatOneBot11Adapter } from '../main';
|
||||
|
||||
export function createActionMap(onebotContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
|
||||
const actionHandlers = [
|
||||
new FetchEmojiLike(onebotContext,coreContext),
|
||||
new GetFile(onebotContext,coreContext),
|
||||
new SetSelfProfile(onebotContext,coreContext),
|
||||
new shareGroupEx(onebotContext,coreContext),
|
||||
new sharePeer(onebotContext,coreContext),
|
||||
new CreateCollection(onebotContext,coreContext),
|
||||
new SetLongNick(onebotContext,coreContext),
|
||||
new ForwardFriendSingleMsg(onebotContext,coreContext),
|
||||
new ForwardGroupSingleMsg(onebotContext,coreContext),
|
||||
new MarkGroupMsgAsRead(onebotContext,coreContext),
|
||||
new MarkPrivateMsgAsRead(onebotContext,coreContext),
|
||||
new SetQQAvatar(onebotContext,coreContext),
|
||||
new TranslateEnWordToZn(onebotContext,coreContext),
|
||||
new GetGroupFileCount(onebotContext,coreContext),
|
||||
new GetGroupFileList(onebotContext,coreContext),
|
||||
new SetGroupFileFolder(onebotContext,coreContext),
|
||||
new DelGroupFile(onebotContext,coreContext),
|
||||
new DelGroupFileFolder(onebotContext,coreContext),
|
||||
new FetchEmojiLike(onebotContext, coreContext),
|
||||
new GetFile(onebotContext, coreContext),
|
||||
new SetSelfProfile(onebotContext, coreContext),
|
||||
new shareGroupEx(onebotContext, coreContext),
|
||||
new sharePeer(onebotContext, coreContext),
|
||||
new CreateCollection(onebotContext, coreContext),
|
||||
new SetLongNick(onebotContext, coreContext),
|
||||
new ForwardFriendSingleMsg(onebotContext, coreContext),
|
||||
new ForwardGroupSingleMsg(onebotContext, coreContext),
|
||||
new MarkGroupMsgAsRead(onebotContext, coreContext),
|
||||
new MarkPrivateMsgAsRead(onebotContext, coreContext),
|
||||
new SetQQAvatar(onebotContext, coreContext),
|
||||
new TranslateEnWordToZn(onebotContext, coreContext),
|
||||
new GetGroupFileCount(onebotContext, coreContext),
|
||||
new GetGroupFileList(onebotContext, coreContext),
|
||||
new SetGroupFileFolder(onebotContext, coreContext),
|
||||
new DelGroupFile(onebotContext, coreContext),
|
||||
new DelGroupFileFolder(onebotContext, coreContext),
|
||||
// onebot11
|
||||
new SendLike(onebotContext,coreContext),
|
||||
new GetMsg(onebotContext,coreContext),
|
||||
new GetLoginInfo(onebotContext,coreContext),
|
||||
new GetFriendList(onebotContext,coreContext),
|
||||
new GetGroupList(onebotContext,coreContext),
|
||||
new GetGroupInfo(onebotContext,coreContext),
|
||||
new GetGroupMemberList(onebotContext,coreContext),
|
||||
new GetGroupMemberInfo(onebotContext,coreContext),
|
||||
new SendGroupMsg(onebotContext,coreContext),
|
||||
new SendPrivateMsg(onebotContext,coreContext),
|
||||
new SendMsg(onebotContext,coreContext),
|
||||
new DeleteMsg(onebotContext,coreContext),
|
||||
new SetGroupAddRequest(onebotContext,coreContext),
|
||||
new SetFriendAddRequest(onebotContext,coreContext),
|
||||
new SetGroupLeave(onebotContext,coreContext),
|
||||
new GetVersionInfo(onebotContext,coreContext),
|
||||
new CanSendRecord(onebotContext,coreContext),
|
||||
new CanSendImage(onebotContext,coreContext),
|
||||
new GetStatus(onebotContext,coreContext),
|
||||
new SetGroupWholeBan(onebotContext,coreContext),
|
||||
new SetGroupBan(onebotContext,coreContext),
|
||||
new SetGroupKick(onebotContext,coreContext),
|
||||
new SetGroupAdmin(onebotContext,coreContext),
|
||||
new SetGroupName(onebotContext,coreContext),
|
||||
new SetGroupCard(onebotContext,coreContext),
|
||||
new GetImage(onebotContext,coreContext),
|
||||
new GetRecord(onebotContext,coreContext),
|
||||
new SetMsgEmojiLike(onebotContext,coreContext),
|
||||
new GetCookies(onebotContext,coreContext),
|
||||
new SetOnlineStatus(onebotContext,coreContext),
|
||||
new GetRobotUinRange(onebotContext,coreContext),
|
||||
new GetFriendWithCategory(onebotContext,coreContext),
|
||||
new SendLike(onebotContext, coreContext),
|
||||
new GetMsg(onebotContext, coreContext),
|
||||
new GetLoginInfo(onebotContext, coreContext),
|
||||
new GetFriendList(onebotContext, coreContext),
|
||||
new GetGroupList(onebotContext, coreContext),
|
||||
new GetGroupInfo(onebotContext, coreContext),
|
||||
new GetGroupMemberList(onebotContext, coreContext),
|
||||
new GetGroupMemberInfo(onebotContext, coreContext),
|
||||
new SendGroupMsg(onebotContext, coreContext),
|
||||
new SendPrivateMsg(onebotContext, coreContext),
|
||||
new SendMsg(onebotContext, coreContext),
|
||||
new DeleteMsg(onebotContext, coreContext),
|
||||
new SetGroupAddRequest(onebotContext, coreContext),
|
||||
new SetFriendAddRequest(onebotContext, coreContext),
|
||||
new SetGroupLeave(onebotContext, coreContext),
|
||||
new GetVersionInfo(onebotContext, coreContext),
|
||||
new CanSendRecord(onebotContext, coreContext),
|
||||
new CanSendImage(onebotContext, coreContext),
|
||||
new GetStatus(onebotContext, coreContext),
|
||||
new SetGroupWholeBan(onebotContext, coreContext),
|
||||
new SetGroupBan(onebotContext, coreContext),
|
||||
new SetGroupKick(onebotContext, coreContext),
|
||||
new SetGroupAdmin(onebotContext, coreContext),
|
||||
new SetGroupName(onebotContext, coreContext),
|
||||
new SetGroupCard(onebotContext, coreContext),
|
||||
new GetImage(onebotContext, coreContext),
|
||||
new GetRecord(onebotContext, coreContext),
|
||||
new SetMsgEmojiLike(onebotContext, coreContext),
|
||||
new GetCookies(onebotContext, coreContext),
|
||||
new SetOnlineStatus(onebotContext, coreContext),
|
||||
new GetRobotUinRange(onebotContext, coreContext),
|
||||
new GetFriendWithCategory(onebotContext, coreContext),
|
||||
//以下为go-cqhttp api
|
||||
new GetOnlineClient(onebotContext,coreContext),
|
||||
new OCRImage(onebotContext,coreContext),
|
||||
new IOCRImage(onebotContext,coreContext),
|
||||
new GetGroupHonorInfo(onebotContext,coreContext),
|
||||
new SendGroupNotice(onebotContext,coreContext),
|
||||
new GetGroupNotice(onebotContext,coreContext),
|
||||
new GetGroupEssence(onebotContext,coreContext),
|
||||
new GoCQHTTPSendForwardMsg(onebotContext,coreContext),
|
||||
new GoCQHTTPSendGroupForwardMsg(onebotContext,coreContext),
|
||||
new GoCQHTTPSendPrivateForwardMsg(onebotContext,coreContext),
|
||||
new GoCQHTTPGetStrangerInfo(onebotContext,coreContext),
|
||||
new GoCQHTTPDownloadFile(onebotContext,coreContext),
|
||||
new GetGuildList(onebotContext,coreContext),
|
||||
new GoCQHTTPMarkMsgAsRead(onebotContext,coreContext),
|
||||
new GoCQHTTPUploadGroupFile(onebotContext,coreContext),
|
||||
new GoCQHTTPGetGroupMsgHistory(onebotContext,coreContext),
|
||||
new GoCQHTTPGetForwardMsgAction(onebotContext,coreContext),
|
||||
new GetFriendMsgHistory(onebotContext,coreContext),
|
||||
new GoCQHTTPHandleQuickAction(onebotContext,coreContext),
|
||||
new GetGroupSystemMsg(onebotContext,coreContext),
|
||||
new DelEssenceMsg(onebotContext,coreContext),
|
||||
new SetEssenceMsg(onebotContext,coreContext),
|
||||
new GetRecentContact(onebotContext,coreContext),
|
||||
new MarkAllMsgAsRead(onebotContext,coreContext),
|
||||
new GetProfileLike(onebotContext,coreContext),
|
||||
new SetGroupHeader(onebotContext,coreContext),
|
||||
new FetchCustomFace(onebotContext,coreContext),
|
||||
new GoCQHTTPUploadPrivateFile(onebotContext,coreContext)
|
||||
new GetOnlineClient(onebotContext, coreContext),
|
||||
new OCRImage(onebotContext, coreContext),
|
||||
new IOCRImage(onebotContext, coreContext),
|
||||
new GetGroupHonorInfo(onebotContext, coreContext),
|
||||
new SendGroupNotice(onebotContext, coreContext),
|
||||
new GetGroupNotice(onebotContext, coreContext),
|
||||
new GetGroupEssence(onebotContext, coreContext),
|
||||
new GoCQHTTPSendForwardMsg(onebotContext, coreContext),
|
||||
new GoCQHTTPSendGroupForwardMsg(onebotContext, coreContext),
|
||||
new GoCQHTTPSendPrivateForwardMsg(onebotContext, coreContext),
|
||||
new GoCQHTTPGetStrangerInfo(onebotContext, coreContext),
|
||||
new GoCQHTTPDownloadFile(onebotContext, coreContext),
|
||||
new GetGuildList(onebotContext, coreContext),
|
||||
new GoCQHTTPMarkMsgAsRead(onebotContext, coreContext),
|
||||
new GoCQHTTPUploadGroupFile(onebotContext, coreContext),
|
||||
new GoCQHTTPGetGroupMsgHistory(onebotContext, coreContext),
|
||||
new GoCQHTTPGetForwardMsgAction(onebotContext, coreContext),
|
||||
new GetFriendMsgHistory(onebotContext, coreContext),
|
||||
new GoCQHTTPHandleQuickAction(onebotContext, coreContext),
|
||||
new GetGroupSystemMsg(onebotContext, coreContext),
|
||||
new DelEssenceMsg(onebotContext, coreContext),
|
||||
new SetEssenceMsg(onebotContext, coreContext),
|
||||
new GetRecentContact(onebotContext, coreContext),
|
||||
new MarkAllMsgAsRead(onebotContext, coreContext),
|
||||
new GetProfileLike(onebotContext, coreContext),
|
||||
new SetGroupHeader(onebotContext, coreContext),
|
||||
new FetchCustomFace(onebotContext, coreContext),
|
||||
new GoCQHTTPUploadPrivateFile(onebotContext, coreContext),
|
||||
];
|
||||
const actionMap = new Map<string, BaseAction<any, any>>();
|
||||
for (const action of actionHandlers) {
|
||||
|
||||
@@ -10,11 +10,11 @@ const SchemaData = {
|
||||
message_id: {
|
||||
oneOf: [
|
||||
{ type: 'number' },
|
||||
{ type: 'string' }
|
||||
]
|
||||
}
|
||||
{ type: 'string' },
|
||||
],
|
||||
},
|
||||
},
|
||||
required: ['message_id']
|
||||
required: ['message_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -22,6 +22,7 @@ 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));
|
||||
@@ -36,8 +37,10 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
).catch(e => new Promise<undefined>((resolve, reject) => { resolve(undefined); }));
|
||||
},
|
||||
).catch(e => new Promise<undefined>((resolve, reject) => {
|
||||
resolve(undefined);
|
||||
}));
|
||||
await NTQQMsgApi.recallMsg(msg.Peer, [msg.MsgId]);
|
||||
const data = await ret;
|
||||
if (!data) {
|
||||
|
||||
@@ -9,9 +9,9 @@ const SchemaData = {
|
||||
properties: {
|
||||
message_id: { type: 'number' },
|
||||
group_id: { type: ['number', 'string'] },
|
||||
user_id: { type: ['number', 'string'] }
|
||||
user_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['message_id']
|
||||
required: ['message_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
|
||||
@@ -13,7 +13,7 @@ const SchemaData = {
|
||||
properties: {
|
||||
message_id: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['message_id']
|
||||
required: ['message_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -21,6 +21,7 @@ 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));
|
||||
@@ -36,7 +37,7 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
|
||||
const msg = await NTQQMsgApi.getMsgsByMsgId(
|
||||
peer,
|
||||
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
||||
const retMsg = await OB11Constructor.message(this.CoreContext, msg.msgList[0], "array");
|
||||
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;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import { ChatType, Peer } from '@/core/entities';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
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'] }
|
||||
}
|
||||
group_id: { type: ['number', 'string'] },
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type PlayloadType = FromSchema<typeof SchemaData>;
|
||||
@@ -31,6 +30,7 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
||||
}
|
||||
return { chatType: ChatType.group, peerUid: payload.group_id.toString() };
|
||||
}
|
||||
|
||||
protected async _handle(payload: PlayloadType): Promise<null> {
|
||||
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||
// 调用API
|
||||
@@ -41,11 +41,13 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 以下为非标准实现
|
||||
export class MarkPrivateMsgAsRead extends MarkMsgAsRead {
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.MarkPrivateMsgAsRead;
|
||||
}
|
||||
|
||||
export class MarkGroupMsgAsRead extends MarkMsgAsRead {
|
||||
PayloadSchema = SchemaData;
|
||||
actionName = ActionName.MarkGroupMsgAsRead;
|
||||
@@ -53,7 +55,7 @@ export class MarkGroupMsgAsRead extends MarkMsgAsRead {
|
||||
|
||||
|
||||
interface Payload {
|
||||
message_id: number
|
||||
message_id: number;
|
||||
}
|
||||
|
||||
export class GoCQHTTPMarkMsgAsRead extends BaseAction<Payload, null> {
|
||||
|
||||
@@ -6,16 +6,23 @@ import { AtType, CustomMusicSignPostData, IdMusicSignPostData, NapCatCore, Peer,
|
||||
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
|
||||
|
||||
export type MessageContext = {
|
||||
deleteAfterSentFiles: string[],
|
||||
peer: Peer
|
||||
deleteAfterSentFiles: string[],
|
||||
peer: Peer
|
||||
}
|
||||
|
||||
async function handleOb11FileLikeMessage(
|
||||
coreContext: NapCatCore,
|
||||
{ data: inputdata }: OB11MessageFileBase,
|
||||
{ deleteAfterSentFiles }: MessageContext
|
||||
{ deleteAfterSentFiles }: MessageContext,
|
||||
) {
|
||||
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
|
||||
const { path, isLocal, fileName, errMsg, success } = (await uri2local(coreContext.NapCatTempPath, inputdata?.url || inputdata.file));
|
||||
const {
|
||||
path,
|
||||
isLocal,
|
||||
fileName,
|
||||
errMsg,
|
||||
success,
|
||||
} = (await uri2local(coreContext.NapCatTempPath, inputdata?.url || inputdata.file));
|
||||
|
||||
if (!success) {
|
||||
coreContext.context.logger.logError('文件下载失败', errMsg);
|
||||
@@ -30,13 +37,13 @@ async function handleOb11FileLikeMessage(
|
||||
}
|
||||
|
||||
const _handlers: {
|
||||
[Key in OB11MessageDataType]: (
|
||||
CoreContext: NapCatCore,
|
||||
sendMsg: Extract<OB11MessageData, { type: Key }>,
|
||||
// This picks the correct message type out
|
||||
// How great the type system of TypeScript is!
|
||||
context: MessageContext
|
||||
) => Promise<SendMessageElement | undefined>
|
||||
[Key in OB11MessageDataType]: (
|
||||
CoreContext: NapCatCore,
|
||||
sendMsg: Extract<OB11MessageData, { type: Key }>,
|
||||
// This picks the correct message type out
|
||||
// How great the type system of TypeScript is!
|
||||
context: MessageContext,
|
||||
) => Promise<SendMessageElement | undefined>
|
||||
} = {
|
||||
[OB11MessageDataType.text]: async (coreContext, { data: { text } }) => SendMsgElementConstructor.text(coreContext, text),
|
||||
|
||||
@@ -49,7 +56,7 @@ const _handlers: {
|
||||
// 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, "");
|
||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
|
||||
},
|
||||
[OB11MessageDataType.reply]: async (coreContext, { data: { id } }) => {
|
||||
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
|
||||
@@ -69,8 +76,8 @@ const _handlers: {
|
||||
|
||||
[OB11MessageDataType.mface]: async (coreContext, {
|
||||
data: {
|
||||
emoji_package_id, emoji_id, key, summary
|
||||
}
|
||||
emoji_package_id, emoji_id, key, summary,
|
||||
},
|
||||
}) => SendMsgElementConstructor.mface(coreContext, emoji_package_id, emoji_id, key, summary),
|
||||
|
||||
// File service
|
||||
@@ -79,7 +86,7 @@ const _handlers: {
|
||||
coreContext,
|
||||
(await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path,
|
||||
sendMsg.data.summary || '',
|
||||
sendMsg.data.subType || 0
|
||||
sendMsg.data.subType || 0,
|
||||
);
|
||||
context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath);
|
||||
return PicEle;
|
||||
@@ -119,7 +126,7 @@ const _handlers: {
|
||||
[OB11MessageDataType.markdown]: async (coreContext, { data: { content } }) => SendMsgElementConstructor.markdown(coreContext, content),
|
||||
|
||||
[OB11MessageDataType.music]: async (coreContext, { data }) => {
|
||||
// 保留, 直到...找到更好的解决方案
|
||||
// 保留, 直到...找到更好的解决方案
|
||||
if (data.type === 'custom') {
|
||||
if (!data.url) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数url');
|
||||
@@ -152,7 +159,7 @@ const _handlers: {
|
||||
postData = data;
|
||||
}
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
const signUrl = "";
|
||||
const signUrl = '';
|
||||
if (!signUrl) {
|
||||
if (data.type === 'qq') {
|
||||
//const musicJson = (await SignMusicWrapper(data.id.toString())).data.arkResult.slice(0, -1);
|
||||
@@ -179,24 +186,24 @@ const _handlers: {
|
||||
[OB11MessageDataType.Location]: async (coreContext) => {
|
||||
return SendMsgElementConstructor.location(coreContext);
|
||||
},
|
||||
[OB11MessageDataType.miniapp]: function (CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
|
||||
[OB11MessageDataType.miniapp]: function(CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
|
||||
throw new Error('Function not implemented.');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const handlers = <{
|
||||
[Key in OB11MessageDataType]: (
|
||||
coreContext: NapCatCore,
|
||||
sendMsg: OB11MessageData,
|
||||
context: MessageContext
|
||||
) => Promise<SendMessageElement | undefined>
|
||||
[Key in OB11MessageDataType]: (
|
||||
coreContext: NapCatCore,
|
||||
sendMsg: OB11MessageData,
|
||||
context: MessageContext,
|
||||
) => Promise<SendMessageElement | undefined>
|
||||
}>_handlers;
|
||||
|
||||
export default async function createSendElements(
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
ignoreTypes: OB11MessageDataType[] = [],
|
||||
) {
|
||||
const deleteAfterSentFiles: string[] = [];
|
||||
const callResultList: Array<Promise<SendMessageElement | undefined>> = [];
|
||||
@@ -207,7 +214,7 @@ export default async function createSendElements(
|
||||
const callResult = handlers[sendMsg.type](
|
||||
CoreContext,
|
||||
sendMsg,
|
||||
{ peer, deleteAfterSentFiles }
|
||||
{ peer, deleteAfterSentFiles },
|
||||
)?.catch(undefined);
|
||||
callResultList.push(callResult);
|
||||
}
|
||||
@@ -220,19 +227,19 @@ export async function createSendElementsParallel(
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
ignoreTypes: OB11MessageDataType[] = [],
|
||||
) {
|
||||
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 }))
|
||||
).then(
|
||||
results => results.filter(
|
||||
element => element !== undefined
|
||||
await Promise.all(
|
||||
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
||||
undefined :
|
||||
handlers[sendMsg.type](CoreContext, sendMsg, { peer, deleteAfterSentFiles })),
|
||||
).then(
|
||||
results => results.filter(
|
||||
element => element !== undefined,
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
);
|
||||
return { sendElements, deleteAfterSentFiles };
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@ 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
|
||||
peerUid: coreContext.selfInfo.uid,
|
||||
};
|
||||
const logger = coreContext.context.logger;
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
@@ -33,7 +34,7 @@ export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer,
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const selfPeer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: coreContext.selfInfo.uid
|
||||
peerUid: coreContext.selfInfo.uid,
|
||||
};
|
||||
let nodeMsgIds: string[] = [];
|
||||
const logger = coreContext.context.logger;
|
||||
@@ -54,20 +55,28 @@ export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer,
|
||||
//筛选node消息
|
||||
const isNodeMsg = OB11Data.filter(e => e.type === OB11MessageDataType.node).length;//找到子转发消息
|
||||
if (isNodeMsg !== 0) {
|
||||
if (isNodeMsg !== OB11Data.length) { logger.logError('子消息中包含非node消息 跳过不合法部分'); continue; }
|
||||
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); }
|
||||
if (nodeMsg) {
|
||||
nodeMsgIds.push(nodeMsg.msgId);
|
||||
MessageUnique.createMsg(selfPeer, nodeMsg.msgId);
|
||||
}
|
||||
//完成子卡片生成跳过后续
|
||||
continue;
|
||||
}
|
||||
const { sendElements } = await createSendElements(coreContext,OB11Data, destPeer);
|
||||
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); })));
|
||||
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) {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
|
||||
import {
|
||||
OB11MessageData,
|
||||
OB11MessageDataType,
|
||||
OB11MessageMixType,
|
||||
OB11MessageNode,
|
||||
OB11PostSendMsg
|
||||
OB11PostSendMsg,
|
||||
} from '@/onebot/types';
|
||||
import { ActionName, BaseCheckResult } from '@/onebot/action/types';
|
||||
import fs from 'node:fs';
|
||||
@@ -17,13 +16,15 @@ import BaseAction from '../../BaseAction';
|
||||
import { handleForwardNode } from './handle-forward-node';
|
||||
|
||||
export interface ReturnDataType {
|
||||
message_id: number;
|
||||
message_id: number;
|
||||
}
|
||||
|
||||
export enum ContextMode {
|
||||
Normal = 0,
|
||||
Private = 1,
|
||||
Group = 2
|
||||
Normal = 0,
|
||||
Private = 1,
|
||||
Group = 2
|
||||
}
|
||||
|
||||
// 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' ? (
|
||||
@@ -68,12 +69,18 @@ export async function sendMsg(coreContext: NapCatCore, peer: Peer, sendElements:
|
||||
}
|
||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout);
|
||||
try {
|
||||
returnMsg!.id = MessageUnique.createMsg({ chatType: peer.chatType, guildId: '', peerUid: peer.peerUid }, returnMsg!.msgId);
|
||||
returnMsg!.id = MessageUnique.createMsg({
|
||||
chatType: peer.chatType,
|
||||
guildId: '',
|
||||
peerUid: peer.peerUid,
|
||||
}, returnMsg!.msgId);
|
||||
} catch (e: any) {
|
||||
logger.logDebug('发送消息id获取失败', e);
|
||||
returnMsg!.id = 0;
|
||||
returnMsg!.id = 0;
|
||||
}
|
||||
deleteAfterSentFiles.map((f) => { fsPromise.unlink(f).then().catch(e => logger.logError('发送消息删除文件失败', e)); });
|
||||
deleteAfterSentFiles.map((f) => {
|
||||
fsPromise.unlink(f).then().catch(e => logger.logError('发送消息删除文件失败', e));
|
||||
});
|
||||
return returnMsg;
|
||||
}
|
||||
|
||||
@@ -88,7 +95,7 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
|
||||
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id?.toString());
|
||||
return {
|
||||
chatType: ChatType.group,
|
||||
peerUid: payload.group_id.toString()
|
||||
peerUid: payload.group_id.toString(),
|
||||
};
|
||||
}
|
||||
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
||||
@@ -97,7 +104,7 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
|
||||
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
|
||||
return {
|
||||
chatType: isBuddy ? ChatType.friend : ChatType.temp,
|
||||
peerUid: Uid!
|
||||
peerUid: Uid!,
|
||||
};
|
||||
}
|
||||
throw '请指定 group_id 或 user_id';
|
||||
@@ -121,7 +128,10 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
const messages = normalize(payload.message);
|
||||
const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node);
|
||||
if (nodeElementLength > 0 && nodeElementLength != messages.length) {
|
||||
return { valid: false, message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素' };
|
||||
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}不存在` };
|
||||
@@ -142,13 +152,17 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
|
||||
const messages = normalize(
|
||||
payload.message,
|
||||
payload.auto_escape === true || payload.auto_escape === 'true'
|
||||
payload.auto_escape === true || payload.auto_escape === 'true',
|
||||
);
|
||||
|
||||
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||
const returnMsg = await handleForwardNode(this.CoreContext,peer, messages as OB11MessageNode[]);
|
||||
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);
|
||||
const msgShortId = MessageUnique.createMsg({
|
||||
guildId: '',
|
||||
peerUid: peer.peerUid,
|
||||
chatType: peer.chatType,
|
||||
}, returnMsg!.msgId);
|
||||
return { message_id: msgShortId! };
|
||||
} else {
|
||||
throw Error('发送转发消息失败');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import SendMsg, { ContextMode } from './SendMsg';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import { OB11PostSendMsg } from '../../types';
|
||||
|
||||
// 未检测参数
|
||||
class SendPrivateMsg extends SendMsg {
|
||||
actionName = ActionName.SendPrivateMsg;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ActionName } from '../types';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { NTQQMsgApi } from '@/core/apis';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
|
||||
@@ -8,9 +7,9 @@ const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
message_id: { type: ['string', 'number'] },
|
||||
emoji_id: { type: ['string', 'number'] }
|
||||
emoji_id: { type: ['string', 'number'] },
|
||||
},
|
||||
required: ['message_id', 'emoji_id']
|
||||
required: ['message_id', 'emoji_id'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -18,6 +17,7 @@ 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()));
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ActionName } from '../types';
|
||||
import CanSendRecord from './CanSendRecord';
|
||||
|
||||
interface ReturnType {
|
||||
yes: boolean
|
||||
yes: boolean;
|
||||
}
|
||||
|
||||
export default class CanSendImage extends CanSendRecord {
|
||||
|
||||
@@ -2,7 +2,7 @@ import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
interface ReturnType {
|
||||
yes: boolean
|
||||
yes: boolean;
|
||||
}
|
||||
|
||||
export default class CanSendRecord extends BaseAction<any, ReturnType> {
|
||||
@@ -10,7 +10,7 @@ export default class CanSendRecord extends BaseAction<any, ReturnType> {
|
||||
|
||||
protected async _handle(_payload: void): Promise<ReturnType> {
|
||||
return {
|
||||
yes: true
|
||||
yes: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import { OB11User } from '../../types';
|
||||
import { OB11Constructor } from '../../helper/data';
|
||||
import BaseAction from '../BaseAction';
|
||||
|
||||
@@ -8,7 +8,7 @@ export default class GetStatus extends BaseAction<any, any> {
|
||||
return {
|
||||
online: !!this.CoreContext.selfInfo.online,
|
||||
good: true,
|
||||
stat:{}
|
||||
stat: {},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export default class GetVersionInfo extends BaseAction<any, any> {
|
||||
return {
|
||||
app_name: 'NapCat.Onebot',
|
||||
protocol_version: 'v11',
|
||||
app_version: napcat_version
|
||||
app_version: napcat_version,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
export type BaseCheckResult = ValidCheckResult | InvalidCheckResult
|
||||
|
||||
export interface ValidCheckResult {
|
||||
valid: true
|
||||
valid: true;
|
||||
|
||||
[k: string | number]: any
|
||||
[k: string | number]: any;
|
||||
}
|
||||
|
||||
export interface InvalidCheckResult {
|
||||
valid: false
|
||||
message: string
|
||||
valid: false;
|
||||
message: string;
|
||||
|
||||
[k: string | number]: any
|
||||
[k: string | number]: any;
|
||||
}
|
||||
|
||||
export enum ActionName {
|
||||
// 以下为扩展napcat扩展
|
||||
Unknown = "unknown",
|
||||
Unknown = 'unknown',
|
||||
SharePeer = 'ArkShareGroup',
|
||||
ShareGroupEx = 'ArkSharePeer',
|
||||
RebootNormal = 'reboot_normal',//无快速登录重新启动
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
interface Response {
|
||||
cookies: string,
|
||||
bkn: string
|
||||
cookies: string,
|
||||
bkn: string
|
||||
}
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
domain: { type: 'string' }
|
||||
domain: { type: 'string' },
|
||||
},
|
||||
required: ['domain']
|
||||
required: ['domain'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -19,6 +20,7 @@ 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;
|
||||
|
||||
@@ -9,13 +9,14 @@ const SchemaData = {
|
||||
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;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
@@ -7,8 +6,8 @@ import { OB11Constructor } from '@/onebot/helper/data';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
count: { type: ['number', 'string'] }
|
||||
}
|
||||
count: { type: ['number', 'string'] },
|
||||
},
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -16,6 +15,7 @@ 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;
|
||||
@@ -24,7 +24,7 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
|
||||
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");
|
||||
const lastestMsg = await OB11Constructor.message(this.CoreContext, FastMsg.msgList[0], 'array');
|
||||
return {
|
||||
lastestMsg: lastestMsg,
|
||||
peerUin: t.peerUin,
|
||||
@@ -34,7 +34,7 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
|
||||
msgId: t.msgId,
|
||||
sendNickName: t.sendNickName,
|
||||
sendMemberName: t.sendMemberName,
|
||||
peerName: t.peerName
|
||||
peerName: t.peerName,
|
||||
};
|
||||
}
|
||||
return {
|
||||
@@ -45,7 +45,7 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
|
||||
msgId: t.msgId,
|
||||
sendNickName: t.sendNickName,
|
||||
sendMemberName: t.sendMemberName,
|
||||
peerName: t.peerName
|
||||
peerName: t.peerName,
|
||||
};
|
||||
}));
|
||||
return data;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
@@ -7,9 +6,9 @@ const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: ['number', 'string'] },
|
||||
times: { type: ['number', 'string'] }
|
||||
times: { type: ['number', 'string'] },
|
||||
},
|
||||
required: ['user_id', 'times']
|
||||
required: ['user_id', 'times'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -17,6 +16,7 @@ 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);
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
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' }
|
||||
remark: { type: 'string' },
|
||||
},
|
||||
required: ['flag']
|
||||
required: ['flag'],
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
@@ -18,6 +17,7 @@ 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';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NapCatCore } from "@/core";
|
||||
import { NapCatOneBot11Adapter } from "../main";
|
||||
import { NapCatCore } from '@/core';
|
||||
import { NapCatOneBot11Adapter } from '../main';
|
||||
|
||||
export class OneBotFriendApi {
|
||||
obContext: NapCatOneBot11Adapter;
|
||||
@@ -9,4 +9,4 @@ export class OneBotFriendApi {
|
||||
this.obContext = obContext;
|
||||
this.coreContext = coreContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { NapCatCore } from "@/core";
|
||||
import { NapCatOneBot11Adapter } from "../main";
|
||||
import { NapCatCore } from '@/core';
|
||||
import { NapCatOneBot11Adapter } from '../main';
|
||||
|
||||
export class OneBotGroupApi {
|
||||
obContext: NapCatOneBot11Adapter;
|
||||
coreContext: NapCatCore;
|
||||
@@ -8,4 +9,4 @@ export class OneBotGroupApi {
|
||||
this.obContext = obContext;
|
||||
this.coreContext = coreContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { NapCatCore } from "@/core";
|
||||
import { NapCatOneBot11Adapter } from "../main";
|
||||
export class OneBotUserApi{
|
||||
import { NapCatCore } from '@/core';
|
||||
import { NapCatOneBot11Adapter } from '../main';
|
||||
|
||||
export class OneBotUserApi {
|
||||
obContext: NapCatOneBot11Adapter;
|
||||
coreContext: NapCatCore;
|
||||
|
||||
constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
|
||||
this.obContext = obContext;
|
||||
this.coreContext = coreContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export class OB11HeartbeatEvent extends OB11BaseMetaEvent {
|
||||
this.interval = interval;
|
||||
this.status = {
|
||||
online: isOnline,
|
||||
good: isGood
|
||||
good: isGood,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
export class OB11GroupAdminNoticeEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_admin';
|
||||
sub_type: 'set' | 'unset' = "set"; // "set" | "unset"
|
||||
}
|
||||
sub_type: 'set' | 'unset' = 'set'; // "set" | "unset"
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export class OB11GroupBanEvent extends OB11GroupNoticeEvent {
|
||||
duration: number;
|
||||
sub_type: 'ban' | 'lift_ban';
|
||||
|
||||
constructor(groupId: number, userId: number, operatorId: 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;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
export class OB11GroupEssenceEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'essence';
|
||||
message_id: number;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
export interface GroupUploadFile{
|
||||
export interface GroupUploadFile {
|
||||
id: string,
|
||||
name: string,
|
||||
size: number,
|
||||
@@ -17,4 +17,4 @@ export class OB11GroupUploadNoticeEvent extends OB11GroupNoticeEvent {
|
||||
this.user_id = userId;
|
||||
this.file = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
||||
|
||||
//输入状态事件 初步完成 Mlikio wa Todo 需要做一些过滤
|
||||
export class OB11InputStatusEvent extends OB11BaseNoticeEvent {
|
||||
notice_type = 'notify';
|
||||
sub_type = 'input_status';
|
||||
status_text = "对方正在输入...";
|
||||
status_text = '对方正在输入...';
|
||||
eventType = 1;
|
||||
user_id = 0;
|
||||
group_id = 0;
|
||||
|
||||
constructor(user_id: number, eventType: number, status_text: string) {
|
||||
super();
|
||||
this.user_id = user_id;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||
|
||||
export interface MsgEmojiLike {
|
||||
emoji_id: string,
|
||||
count: number
|
||||
emoji_id: string,
|
||||
count: number
|
||||
}
|
||||
|
||||
export class OB11GroupMsgEmojiLikeEvent extends OB11GroupNoticeEvent {
|
||||
|
||||
@@ -9,6 +9,7 @@ class OB11PokeEvent extends OB11BaseNoticeEvent {
|
||||
|
||||
export class OB11FriendPokeEvent extends OB11PokeEvent {
|
||||
raw_info: any;
|
||||
|
||||
//raw_message nb等框架标准为string
|
||||
constructor(user_id: number, target_id: number, raw_message: any) {
|
||||
super();
|
||||
@@ -21,6 +22,7 @@ export class OB11FriendPokeEvent extends OB11PokeEvent {
|
||||
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();
|
||||
|
||||
@@ -1,40 +1,41 @@
|
||||
import { ConfigBase } from '@/common/utils/ConfigBase';
|
||||
|
||||
export interface OB11Config {
|
||||
http: {
|
||||
enable: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
secret: string;
|
||||
enableHeart: boolean;
|
||||
enablePost: boolean;
|
||||
postUrls: string[];
|
||||
};
|
||||
ws: {
|
||||
enable: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
};
|
||||
reverseWs: {
|
||||
enable: boolean;
|
||||
urls: string[];
|
||||
};
|
||||
http: {
|
||||
enable: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
secret: string;
|
||||
enableHeart: boolean;
|
||||
enablePost: boolean;
|
||||
postUrls: string[];
|
||||
};
|
||||
ws: {
|
||||
enable: boolean;
|
||||
host: string;
|
||||
port: number;
|
||||
};
|
||||
reverseWs: {
|
||||
enable: boolean;
|
||||
urls: string[];
|
||||
};
|
||||
|
||||
debug: boolean;
|
||||
heartInterval: number;
|
||||
messagePostFormat: 'array' | 'string';
|
||||
enableLocalFile2Url: boolean;
|
||||
musicSignUrl: string;
|
||||
reportSelfMessage: boolean;
|
||||
token: string;
|
||||
GroupLocalTime: {
|
||||
Record: boolean,
|
||||
RecordList: Array<string>
|
||||
}
|
||||
debug: boolean;
|
||||
heartInterval: number;
|
||||
messagePostFormat: 'array' | 'string';
|
||||
enableLocalFile2Url: boolean;
|
||||
musicSignUrl: string;
|
||||
reportSelfMessage: boolean;
|
||||
token: string;
|
||||
GroupLocalTime: {
|
||||
Record: boolean,
|
||||
RecordList: Array<string>
|
||||
};
|
||||
}
|
||||
|
||||
export class OB11Config extends ConfigBase<OB11Config> {
|
||||
export class OB11Config extends ConfigBase<OB11Config> {
|
||||
name = 'onebot11';
|
||||
|
||||
protected getKeys(): string[] | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import fastXmlParser, { XMLParser } from 'fast-xml-parser';
|
||||
import fastXmlParser from 'fast-xml-parser';
|
||||
import {
|
||||
OB11Group,
|
||||
OB11GroupMember,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
OB11MessageData,
|
||||
OB11MessageDataType,
|
||||
OB11User,
|
||||
OB11UserSex
|
||||
OB11UserSex,
|
||||
} from '../types';
|
||||
import {
|
||||
AtType,
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
Sex,
|
||||
TipGroupElementType,
|
||||
User,
|
||||
VideoElement
|
||||
VideoElement,
|
||||
} from '@/core/entities';
|
||||
import { EventType } from '../event/OB11BaseEvent';
|
||||
import { encodeCQCode } from './cqcode';
|
||||
@@ -32,12 +32,9 @@ import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
||||
import { OB11GroupBanEvent } from '../event/notice/OB11GroupBanEvent';
|
||||
import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent';
|
||||
import { OB11GroupNoticeEvent } from '../event/notice/OB11GroupNoticeEvent';
|
||||
import { calcQQLevel } from '@/common/utils/helper';
|
||||
import { sleep, UUIDConverter } from '@/common/utils/helper';
|
||||
import { calcQQLevel, sleep, UUIDConverter } from '@/common/utils/helper';
|
||||
import { OB11GroupTitleEvent } from '../event/notice/OB11GroupTitleEvent';
|
||||
import { OB11GroupCardEvent } from '../event/notice/OB11GroupCardEvent';
|
||||
import { OB11GroupDecreaseEvent } from '../event/notice/OB11GroupDecreaseEvent';
|
||||
import { NTQQFileApi, NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from '@/core/apis';
|
||||
import { OB11GroupMsgEmojiLikeEvent } from '@/onebot/event/notice/OB11MsgEmojiLikeEvent';
|
||||
import { OB11FriendPokeEvent, OB11GroupPokeEvent } from '../event/notice/OB11PokeEvent';
|
||||
import { OB11FriendAddNoticeEvent } from '../event/notice/OB11FriendAddNoticeEvent';
|
||||
@@ -86,28 +83,25 @@ export class OB11Constructor {
|
||||
resMsg.sender.role = OB11Constructor.groupMemberRole(member.role);
|
||||
resMsg.sender.nickname = member.nick;
|
||||
}
|
||||
}
|
||||
else if (msg.chatType == ChatType.friend) {
|
||||
} else if (msg.chatType == ChatType.friend) {
|
||||
resMsg.sub_type = 'friend';
|
||||
resMsg.sender.nickname = (await NTQQUserApi.getUserDetailInfo(msg.senderUid)).nick;
|
||||
//const user = await NTQQUserApi.getUserDetailInfoByUin(msg.senderUin!);
|
||||
//resMsg.sender.nickname = user.info.nick;
|
||||
}
|
||||
else if (msg.chatType == ChatType.temp) {
|
||||
} else if (msg.chatType == ChatType.temp) {
|
||||
resMsg.sub_type = 'group';
|
||||
}
|
||||
for (const element of msg.elements) {
|
||||
let message_data: OB11MessageData = {
|
||||
data: {} as any,
|
||||
type: 'unknown' as any
|
||||
type: 'unknown' as any,
|
||||
};
|
||||
if (element.textElement && element.textElement?.atType !== AtType.notAt) {
|
||||
let qq: `${number}` | 'all';
|
||||
let name: string | undefined;
|
||||
if (element.textElement.atType == AtType.atAll) {
|
||||
qq = 'all';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
const { atNtUid, content } = element.textElement;
|
||||
let atQQ = element.textElement.atUid;
|
||||
if (!atQQ || atQQ === '0') {
|
||||
@@ -122,11 +116,10 @@ export class OB11Constructor {
|
||||
type: OB11MessageDataType.at,
|
||||
data: {
|
||||
qq: qq!,
|
||||
name
|
||||
}
|
||||
name,
|
||||
},
|
||||
};
|
||||
}
|
||||
else if (element.textElement) {
|
||||
} else if (element.textElement) {
|
||||
message_data['type'] = OB11MessageDataType.text;
|
||||
|
||||
let text = element.textElement.content;
|
||||
@@ -138,8 +131,7 @@ export class OB11Constructor {
|
||||
text = text.replace(/\r/g, '\n');
|
||||
}
|
||||
message_data['data']['text'] = text;
|
||||
}
|
||||
else if (element.replyElement) {
|
||||
} else if (element.replyElement) {
|
||||
message_data['type'] = OB11MessageDataType.reply;
|
||||
//log("收到回复消息", element.replyElement);
|
||||
try {
|
||||
@@ -151,7 +143,11 @@ export class OB11Constructor {
|
||||
};
|
||||
let replyMsg: RawMessage | undefined;
|
||||
if (!records) throw new Error('找不到回复消息');
|
||||
replyMsg = (await NTQQMsgApi.getMsgsBySeqAndCount({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, element.replyElement.replayMsgSeq, 1, true, true)).msgList[0];
|
||||
replyMsg = (await NTQQMsgApi.getMsgsBySeqAndCount({
|
||||
peerUid: msg.peerUid,
|
||||
guildId: '',
|
||||
chatType: msg.chatType,
|
||||
}, element.replyElement.replayMsgSeq, 1, true, true)).msgList[0];
|
||||
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
||||
replyMsg = (await NTQQMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq)).msgList[0];
|
||||
}
|
||||
@@ -161,7 +157,11 @@ export class OB11Constructor {
|
||||
if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') {
|
||||
throw new Error('回复消息消息验证失败');
|
||||
}
|
||||
message_data['data']['id'] = MessageUnique.createMsg({ peerUid: msg.peerUid, guildId: '', chatType: msg.chatType }, replyMsg.msgId)?.toString();
|
||||
message_data['data']['id'] = MessageUnique.createMsg({
|
||||
peerUid: msg.peerUid,
|
||||
guildId: '',
|
||||
chatType: msg.chatType,
|
||||
}, replyMsg.msgId)?.toString();
|
||||
//log("找到回复消息", message_data['data']['id'], replyMsg.msgList[0].msgId)
|
||||
} catch (e: any) {
|
||||
message_data['type'] = 'unknown' as any;
|
||||
@@ -169,8 +169,7 @@ export class OB11Constructor {
|
||||
logger.logError('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq);
|
||||
}
|
||||
|
||||
}
|
||||
else if (element.picElement) {
|
||||
} else if (element.picElement) {
|
||||
message_data['type'] = OB11MessageDataType.image;
|
||||
// message_data["data"]["file"] = element.picElement.sourcePath
|
||||
message_data['data']['file'] = element.picElement.fileName;
|
||||
@@ -186,8 +185,7 @@ export class OB11Constructor {
|
||||
//console.log(message_data['data']['url'])
|
||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||
message_data['data']['file_size'] = element.picElement.fileSize;
|
||||
}
|
||||
else if (element.fileElement) {
|
||||
} else if (element.fileElement) {
|
||||
const FileElement = element.fileElement;
|
||||
message_data['type'] = OB11MessageDataType.file;
|
||||
message_data['data']['file'] = FileElement.fileName;
|
||||
@@ -195,21 +193,21 @@ export class OB11Constructor {
|
||||
message_data['data']['url'] = FileElement.filePath;
|
||||
message_data['data']['file_id'] = UUIDConverter.encode(msg.peerUin, msg.msgId);
|
||||
message_data['data']['file_size'] = FileElement.fileSize;
|
||||
await NTQQFileApi.addFileCache({
|
||||
peerUid: msg.peerUid,
|
||||
chatType: msg.chatType,
|
||||
guildId: '',
|
||||
},
|
||||
msg.msgId,
|
||||
msg.msgSeq,
|
||||
msg.senderUid,
|
||||
element.elementId,
|
||||
element.elementType.toString(),
|
||||
FileElement.fileSize,
|
||||
FileElement.fileName
|
||||
await NTQQFileApi.addFileCache(
|
||||
{
|
||||
peerUid: msg.peerUid,
|
||||
chatType: msg.chatType,
|
||||
guildId: '',
|
||||
},
|
||||
msg.msgId,
|
||||
msg.msgSeq,
|
||||
msg.senderUid,
|
||||
element.elementId,
|
||||
element.elementType.toString(),
|
||||
FileElement.fileSize,
|
||||
FileElement.fileName,
|
||||
);
|
||||
}
|
||||
else if (element.videoElement) {
|
||||
} else if (element.videoElement) {
|
||||
const videoElement: VideoElement = element.videoElement;
|
||||
//读取视频链接并兜底
|
||||
let videoUrl;//Array
|
||||
@@ -221,7 +219,7 @@ export class OB11Constructor {
|
||||
videoUrl = await NTQQFileApi.getVideoUrl({
|
||||
chatType: msg.chatType,
|
||||
peerUid: msg.peerUid,
|
||||
guildId: '0'
|
||||
guildId: '0',
|
||||
}, msg.msgId, element.elementId);
|
||||
} catch (error) {
|
||||
videoUrl = undefined;
|
||||
@@ -230,7 +228,12 @@ export class OB11Constructor {
|
||||
let videoDownUrl = undefined;
|
||||
|
||||
if (videoUrl) {
|
||||
const videoDownUrlTemp = videoUrl.find((url) => { if (url.url) { return true; } return false; });
|
||||
const videoDownUrlTemp = videoUrl.find((url) => {
|
||||
if (url.url) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (videoDownUrlTemp) {
|
||||
videoDownUrl = videoDownUrlTemp.url;
|
||||
}
|
||||
@@ -246,21 +249,21 @@ export class OB11Constructor {
|
||||
message_data['data']['file_id'] = UUIDConverter.encode(msg.peerUin, msg.msgId);
|
||||
message_data['data']['file_size'] = videoElement.fileSize;
|
||||
|
||||
await NTQQFileApi.addFileCache({
|
||||
peerUid: msg.peerUid,
|
||||
chatType: msg.chatType,
|
||||
guildId: '',
|
||||
},
|
||||
msg.msgId,
|
||||
msg.msgSeq,
|
||||
msg.senderUid,
|
||||
element.elementId,
|
||||
element.elementType.toString(),
|
||||
videoElement.fileSize || '0',
|
||||
videoElement.fileName
|
||||
await NTQQFileApi.addFileCache(
|
||||
{
|
||||
peerUid: msg.peerUid,
|
||||
chatType: msg.chatType,
|
||||
guildId: '',
|
||||
},
|
||||
msg.msgId,
|
||||
msg.msgSeq,
|
||||
msg.senderUid,
|
||||
element.elementId,
|
||||
element.elementType.toString(),
|
||||
videoElement.fileSize || '0',
|
||||
videoElement.fileName,
|
||||
);
|
||||
}
|
||||
else if (element.pttElement) {
|
||||
} else if (element.pttElement) {
|
||||
message_data['type'] = OB11MessageDataType.voice;
|
||||
message_data['data']['file'] = element.pttElement.fileName;
|
||||
message_data['data']['path'] = element.pttElement.filePath;
|
||||
@@ -278,30 +281,25 @@ export class OB11Constructor {
|
||||
element.elementId,
|
||||
element.elementType.toString(),
|
||||
element.pttElement.fileSize || '0',
|
||||
element.pttElement.fileUuid || ''
|
||||
element.pttElement.fileUuid || '',
|
||||
);
|
||||
//以uuid作为文件名
|
||||
}
|
||||
else if (element.arkElement) {
|
||||
} else if (element.arkElement) {
|
||||
message_data['type'] = OB11MessageDataType.json;
|
||||
message_data['data']['data'] = element.arkElement.bytesData;
|
||||
}
|
||||
else if (element.faceElement) {
|
||||
} else if (element.faceElement) {
|
||||
const faceId = element.faceElement.faceIndex;
|
||||
if (faceId === FaceIndex.dice) {
|
||||
message_data['type'] = OB11MessageDataType.dice;
|
||||
message_data['data']['result'] = element.faceElement.resultId;
|
||||
}
|
||||
else if (faceId === FaceIndex.RPS) {
|
||||
} else if (faceId === FaceIndex.RPS) {
|
||||
message_data['type'] = OB11MessageDataType.RPS;
|
||||
message_data['data']['result'] = element.faceElement.resultId;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
message_data['type'] = OB11MessageDataType.face;
|
||||
message_data['data']['id'] = element.faceElement.faceIndex.toString();
|
||||
}
|
||||
}
|
||||
else if (element.marketFaceElement) {
|
||||
} else if (element.marketFaceElement) {
|
||||
message_data['type'] = OB11MessageDataType.mface;
|
||||
message_data['data']['summary'] = element.marketFaceElement.faceName;
|
||||
const md5 = element.marketFaceElement.emojiId;
|
||||
@@ -315,15 +313,17 @@ export class OB11Constructor {
|
||||
message_data['data']['emoji_package_id'] = String(element.marketFaceElement.emojiPackageId);
|
||||
message_data['data']['key'] = element.marketFaceElement.key;
|
||||
//mFaceCache.set(md5, element.marketFaceElement.faceName);
|
||||
}
|
||||
else if (element.markdownElement) {
|
||||
} else if (element.markdownElement) {
|
||||
message_data['type'] = OB11MessageDataType.markdown;
|
||||
message_data['data']['data'] = element.markdownElement.content;
|
||||
}
|
||||
else if (element.multiForwardMsgElement) {
|
||||
} else if (element.multiForwardMsgElement) {
|
||||
message_data['type'] = OB11MessageDataType.forward;
|
||||
message_data['data']['id'] = msg.msgId;
|
||||
const ParentMsgPeer = msg.parentMsgPeer ?? { chatType: msg.chatType, guildId: '', peerUid: msg.peerUid };
|
||||
const ParentMsgPeer = msg.parentMsgPeer ?? {
|
||||
chatType: msg.chatType,
|
||||
guildId: '',
|
||||
peerUid: msg.peerUid,
|
||||
};
|
||||
//判断是否在合并消息内
|
||||
msg.parentMsgIdList = msg.parentMsgIdList ?? [];
|
||||
//首次列表不存在则开始创建
|
||||
@@ -340,7 +340,7 @@ export class OB11Constructor {
|
||||
MultiMsg.parentMsgPeer = ParentMsgPeer;
|
||||
MultiMsg.parentMsgIdList = msg.parentMsgIdList;
|
||||
MultiMsg.id = MessageUnique.createMsg(ParentMsgPeer, MultiMsg.msgId);//该ID仅用查看 无法调用
|
||||
const msgList = await OB11Constructor.message(coreContext, MultiMsg, "array");
|
||||
const msgList = await OB11Constructor.message(coreContext, MultiMsg, 'array');
|
||||
message_data['data']['content'].push(msgList);
|
||||
//console.log("合并消息", msgList);
|
||||
}
|
||||
@@ -350,8 +350,7 @@ export class OB11Constructor {
|
||||
|
||||
if (messagePostFormat === 'string') {
|
||||
(resMsg.message as string) += cqCode;
|
||||
}
|
||||
else (resMsg.message as OB11MessageData[]).push(message_data);
|
||||
} else (resMsg.message as OB11MessageData[]).push(message_data);
|
||||
resMsg.raw_message += cqCode;
|
||||
}
|
||||
|
||||
@@ -359,6 +358,7 @@ export class OB11Constructor {
|
||||
resMsg.raw_message = resMsg.raw_message.trim();
|
||||
return resMsg;
|
||||
}
|
||||
|
||||
static async PrivateEvent(coreContext: NapCatCore, msg: RawMessage): Promise<OB11BaseNoticeEvent | undefined> {
|
||||
const NTQQGroupApi = coreContext.getApiContext().GroupApi;
|
||||
const NTQQUserApi = coreContext.getApiContext().UserApi;
|
||||
@@ -396,7 +396,8 @@ export class OB11Constructor {
|
||||
}
|
||||
}
|
||||
}
|
||||
static async GroupEvent(coreContext:NapCatCore,msg: RawMessage): Promise<OB11GroupNoticeEvent | undefined> {
|
||||
|
||||
static async GroupEvent(coreContext: NapCatCore, msg: RawMessage): Promise<OB11GroupNoticeEvent | undefined> {
|
||||
const NTQQGroupApi = coreContext.getApiContext().GroupApi;
|
||||
const NTQQUserApi = coreContext.getApiContext().UserApi;
|
||||
const NTQQFileApi = coreContext.getApiContext().FileApi;
|
||||
@@ -440,8 +441,7 @@ export class OB11Constructor {
|
||||
// log("构造群增加事件", event)
|
||||
return event;
|
||||
}
|
||||
}
|
||||
else if (groupElement.type === TipGroupElementType.ban) {
|
||||
} else if (groupElement.type === TipGroupElementType.ban) {
|
||||
logger.logDebug('收到群群员禁言提示', groupElement);
|
||||
const memberUid = groupElement.shutUp!.member.uid;
|
||||
const adminUid = groupElement.shutUp!.admin.uid;
|
||||
@@ -451,8 +451,7 @@ export class OB11Constructor {
|
||||
// log('OB11被禁言事件', adminUid);
|
||||
if (memberUid) {
|
||||
memberUin = (await getGroupMember(msg.peerUid, memberUid))?.uin || ''; // || (await NTQQUserApi.getUserDetailInfo(memberUid))?.uin
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
memberUin = '0'; // 0表示全员禁言
|
||||
if (duration > 0) {
|
||||
duration = -1;
|
||||
@@ -464,8 +463,7 @@ export class OB11Constructor {
|
||||
const event = new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
||||
return event;
|
||||
}
|
||||
}
|
||||
else if (groupElement.type == TipGroupElementType.kicked) {
|
||||
} else if (groupElement.type == TipGroupElementType.kicked) {
|
||||
logger.logDebug(`收到我被踢出或退群提示, 群${msg.peerUid}`, groupElement);
|
||||
NTQQGroupApi.quitGroup(msg.peerUid).then();
|
||||
try {
|
||||
@@ -477,13 +475,12 @@ export class OB11Constructor {
|
||||
return new OB11GroupDecreaseEvent(parseInt(msg.peerUid), parseInt(coreContext.selfInfo.uin), 0, 'leave');
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element.fileElement) {
|
||||
} else if (element.fileElement) {
|
||||
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin || ''), {
|
||||
id: element.fileElement.fileUuid!,
|
||||
name: element.fileElement.fileName,
|
||||
size: parseInt(element.fileElement.fileSize),
|
||||
busid: element.fileElement.fileBizId || 0
|
||||
busid: element.fileElement.fileBizId || 0,
|
||||
});
|
||||
}
|
||||
if (grayTipElement) {
|
||||
@@ -491,7 +488,7 @@ export class OB11Constructor {
|
||||
if (grayTipElement.xmlElement?.templId === '10382') {
|
||||
const emojiLikeData = new fastXmlParser.XMLParser({
|
||||
ignoreAttributes: false,
|
||||
attributeNamePrefix: ''
|
||||
attributeNamePrefix: '',
|
||||
}).parse(grayTipElement.xmlElement.content);
|
||||
logger.logDebug('收到表情回应我的消息', emojiLikeData);
|
||||
try {
|
||||
@@ -499,21 +496,25 @@ export class OB11Constructor {
|
||||
const msgSeq = emojiLikeData.gtip.url.msgseq;
|
||||
const emojiId = emojiLikeData.gtip.face.id;
|
||||
|
||||
const replyMsgList = (await NTQQMsgApi.getMsgsBySeqAndCount({ chatType: ChatType.group, guildId: '', peerUid: msg.peerUid }, msgSeq, 1, true, true)).msgList;
|
||||
const replyMsgList = (await NTQQMsgApi.getMsgsBySeqAndCount({
|
||||
chatType: ChatType.group,
|
||||
guildId: '',
|
||||
peerUid: msg.peerUid,
|
||||
}, msgSeq, 1, true, true)).msgList;
|
||||
if (replyMsgList.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const replyMsg = replyMsgList[0];
|
||||
console.log('表情回应消息', msgSeq, " 结算ID", replyMsg.msgId);
|
||||
console.log('表情回应消息', msgSeq, ' 结算ID', replyMsg.msgId);
|
||||
return new OB11GroupMsgEmojiLikeEvent(
|
||||
parseInt(msg.peerUid),
|
||||
parseInt(senderUin),
|
||||
MessageUnique.getShortIdByMsgId(replyMsg.msgId)!,
|
||||
[{
|
||||
emoji_id: emojiId,
|
||||
count: 1
|
||||
}]
|
||||
count: 1,
|
||||
}],
|
||||
);
|
||||
} catch (e: any) {
|
||||
logger.logError('解析表情回应消息失败', e.stack);
|
||||
@@ -559,7 +560,7 @@ export class OB11Constructor {
|
||||
const Peer: Peer = {
|
||||
guildId: '',
|
||||
chatType: ChatType.group,
|
||||
peerUid: Group!
|
||||
peerUid: Group!,
|
||||
};
|
||||
const msgData = await NTQQMsgApi.getMsgsBySeqAndCount(Peer, msgSeq.toString(), 1, true, true);
|
||||
return new OB11GroupEssenceEvent(parseInt(msg.peerUid), MessageUnique.getShortIdByMsgId(msgData.msgList[0].msgId)!, parseInt(msgData.msgList[0].senderUin));
|
||||
@@ -576,13 +577,14 @@ export class OB11Constructor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static friend(friend: User): OB11User {
|
||||
return {
|
||||
user_id: parseInt(friend.uin),
|
||||
nickname: friend.nick,
|
||||
remark: friend.remark,
|
||||
sex: OB11Constructor.sex(friend.sex!),
|
||||
level: friend.qqLevel && calcQQLevel(friend.qqLevel) || 0
|
||||
level: friend.qqLevel && calcQQLevel(friend.qqLevel) || 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -592,6 +594,7 @@ export class OB11Constructor {
|
||||
nickname: selfInfo.nick,
|
||||
};
|
||||
}
|
||||
|
||||
static friendsV2(friends: FriendV2[]): OB11User[] {
|
||||
const data: OB11User[] = [];
|
||||
friends.forEach(friend => {
|
||||
@@ -605,16 +608,23 @@ export class OB11Constructor {
|
||||
sex: sexValue,
|
||||
level: 0,
|
||||
categroyName: friend.categroyName,
|
||||
categoryId: friend.categoryId
|
||||
categoryId: friend.categoryId,
|
||||
});
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
static friends(friends: Friend[]): OB11User[] {
|
||||
const data: OB11User[] = [];
|
||||
friends.forEach(friend => {
|
||||
const sexValue = this.sex(friend.sex!);
|
||||
data.push({ user_id: parseInt(friend.uin), nickname: friend.nick, remark: friend.remark, sex: sexValue, level: 0 });
|
||||
data.push({
|
||||
user_id: parseInt(friend.uin),
|
||||
nickname: friend.nick,
|
||||
remark: friend.remark,
|
||||
sex: sexValue,
|
||||
level: 0,
|
||||
});
|
||||
});
|
||||
return data;
|
||||
}
|
||||
@@ -623,7 +633,7 @@ export class OB11Constructor {
|
||||
return {
|
||||
4: OB11GroupMemberRole.owner,
|
||||
3: OB11GroupMemberRole.admin,
|
||||
2: OB11GroupMemberRole.member
|
||||
2: OB11GroupMemberRole.member,
|
||||
}[role];
|
||||
}
|
||||
|
||||
@@ -631,7 +641,7 @@ export class OB11Constructor {
|
||||
const sexMap = {
|
||||
[Sex.male]: OB11UserSex.male,
|
||||
[Sex.female]: OB11UserSex.female,
|
||||
[Sex.unknown]: OB11UserSex.unknown
|
||||
[Sex.unknown]: OB11UserSex.unknown,
|
||||
};
|
||||
return sexMap[sex] || OB11UserSex.unknown;
|
||||
}
|
||||
@@ -660,7 +670,7 @@ export class OB11Constructor {
|
||||
}
|
||||
|
||||
static stranger(user: User): OB11User {
|
||||
//logDebug('construct ob11 stranger', user);
|
||||
//logDebug('construct ob11 stranger', user);
|
||||
return {
|
||||
...user,
|
||||
user_id: parseInt(user.uin),
|
||||
@@ -679,7 +689,7 @@ export class OB11Constructor {
|
||||
group_id: parseInt(group.groupCode),
|
||||
group_name: group.groupName,
|
||||
member_count: group.memberCount,
|
||||
max_member_count: group.maxMember
|
||||
max_member_count: group.maxMember,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,94 +7,80 @@ const spColor = chalk.cyan;// for special
|
||||
|
||||
// todo: 应该放到core去用RawMessage解析打印
|
||||
export async function logMessage(coreContext: NapCatCore, ob11Message: OB11Message) {
|
||||
const isSelfSent = ob11Message.sender.user_id.toString() === coreContext.selfInfo.uin;
|
||||
let prefix = '';
|
||||
let group: Group | undefined;
|
||||
if (isSelfSent) {
|
||||
prefix = '发送消息 ';
|
||||
if (ob11Message.message_type === 'private') {
|
||||
prefix += '给私聊 ';
|
||||
prefix += `${ob11Message.target_id}`;
|
||||
const isSelfSent = ob11Message.sender.user_id.toString() === coreContext.selfInfo.uin;
|
||||
let prefix = '';
|
||||
let group: Group | undefined;
|
||||
if (isSelfSent) {
|
||||
prefix = '发送消息 ';
|
||||
if (ob11Message.message_type === 'private') {
|
||||
prefix += '给私聊 ';
|
||||
prefix += `${ob11Message.target_id}`;
|
||||
} else {
|
||||
prefix += '给群聊 ';
|
||||
}
|
||||
}
|
||||
else {
|
||||
prefix += '给群聊 ';
|
||||
if (ob11Message.message_type === 'group') {
|
||||
if (ob11Message.group_id == 284840486) {
|
||||
group = await getGroup(ob11Message.group_id!);
|
||||
prefix += '转发消息[外部来源] ';
|
||||
} else {
|
||||
group = await getGroup(ob11Message.group_id!);
|
||||
prefix += `群[${group?.groupName}(${ob11Message.group_id})] `;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ob11Message.message_type === 'group') {
|
||||
if (ob11Message.group_id == 284840486) {
|
||||
group = await getGroup(ob11Message.group_id!);
|
||||
prefix += '转发消息[外部来源] ';
|
||||
let msgChain = '';
|
||||
if (Array.isArray(ob11Message.message)) {
|
||||
const msgParts = [];
|
||||
for (const segment of ob11Message.message) {
|
||||
if (segment.type === 'text') {
|
||||
msgParts.push(segment.data.text);
|
||||
} else if (segment.type === 'at') {
|
||||
const groupMember = await getGroupMember(ob11Message.group_id!, segment.data.qq!);
|
||||
msgParts.push(spSegColor(`[@${groupMember?.cardName || groupMember?.nick}(${segment.data.qq})]`));
|
||||
} else if (segment.type === 'reply') {
|
||||
msgParts.push(spSegColor(`[回复消息|id:${segment.data.id}]`));
|
||||
} else if (segment.type === 'image') {
|
||||
msgParts.push(spSegColor(`[图片|${segment.data.url}]`));
|
||||
} else if (segment.type === 'face') {
|
||||
msgParts.push(spSegColor(`[表情|id:${segment.data.id}]`));
|
||||
} else if (segment.type === 'mface') {
|
||||
// @ts-expect-error 商城表情 url
|
||||
msgParts.push(spSegColor(`[商城表情|${segment.data.url}]`));
|
||||
} else if (segment.type === 'record') {
|
||||
msgParts.push(spSegColor(`[语音|${segment.data.file}]`));
|
||||
} else if (segment.type === 'file') {
|
||||
msgParts.push(spSegColor(`[文件|${segment.data.file}]`));
|
||||
} else if (segment.type === 'json') {
|
||||
msgParts.push(spSegColor(`[json|${JSON.stringify(segment.data)}]`));
|
||||
} else if (segment.type === 'markdown') {
|
||||
msgParts.push(spSegColor(`[markdown|${segment.data.content}]`));
|
||||
} else if (segment.type === 'video') {
|
||||
msgParts.push(spSegColor(`[视频|${segment.data.url}]`));
|
||||
} else if (segment.type === 'forward') {
|
||||
msgParts.push(spSegColor(`[转发|${segment.data.id}|消息开始]`));
|
||||
segment.data.content.forEach((msg) => {
|
||||
logMessage(coreContext, msg);
|
||||
});
|
||||
msgParts.push(spSegColor(`[转发|${segment.data.id}|消息结束]`));
|
||||
} else {
|
||||
msgParts.push(spSegColor(`[未实现|${JSON.stringify(segment)}]`));
|
||||
}
|
||||
}
|
||||
msgChain = msgParts.join(' ');
|
||||
} else {
|
||||
group = await getGroup(ob11Message.group_id!);
|
||||
prefix += `群[${group?.groupName}(${ob11Message.group_id})] `;
|
||||
msgChain = ob11Message.message;
|
||||
}
|
||||
}
|
||||
let msgChain = '';
|
||||
if (Array.isArray(ob11Message.message)) {
|
||||
const msgParts = [];
|
||||
for (const segment of ob11Message.message) {
|
||||
if (segment.type === 'text') {
|
||||
msgParts.push(segment.data.text);
|
||||
}
|
||||
else if (segment.type === 'at') {
|
||||
const groupMember = await getGroupMember(ob11Message.group_id!, segment.data.qq!);
|
||||
msgParts.push(spSegColor(`[@${groupMember?.cardName || groupMember?.nick}(${segment.data.qq})]`));
|
||||
}
|
||||
else if (segment.type === 'reply') {
|
||||
msgParts.push(spSegColor(`[回复消息|id:${segment.data.id}]`));
|
||||
}
|
||||
else if (segment.type === 'image') {
|
||||
msgParts.push(spSegColor(`[图片|${segment.data.url}]`));
|
||||
}
|
||||
else if (segment.type === 'face') {
|
||||
msgParts.push(spSegColor(`[表情|id:${segment.data.id}]`));
|
||||
}
|
||||
else if (segment.type === 'mface') {
|
||||
// @ts-expect-error 商城表情 url
|
||||
msgParts.push(spSegColor(`[商城表情|${segment.data.url}]`));
|
||||
}
|
||||
else if (segment.type === 'record') {
|
||||
msgParts.push(spSegColor(`[语音|${segment.data.file}]`));
|
||||
}
|
||||
else if (segment.type === 'file') {
|
||||
msgParts.push(spSegColor(`[文件|${segment.data.file}]`));
|
||||
}
|
||||
else if (segment.type === 'json') {
|
||||
msgParts.push(spSegColor(`[json|${JSON.stringify(segment.data)}]`));
|
||||
}
|
||||
else if (segment.type === 'markdown') {
|
||||
msgParts.push(spSegColor(`[markdown|${segment.data.content}]`));
|
||||
}
|
||||
else if (segment.type === 'video') {
|
||||
msgParts.push(spSegColor(`[视频|${segment.data.url}]`));
|
||||
}
|
||||
else if (segment.type === 'forward') {
|
||||
msgParts.push(spSegColor(`[转发|${segment.data.id}|消息开始]`));
|
||||
segment.data.content.forEach((msg) => {
|
||||
logMessage(coreContext, msg);
|
||||
});
|
||||
msgParts.push(spSegColor(`[转发|${segment.data.id}|消息结束]`));
|
||||
}
|
||||
else {
|
||||
msgParts.push(spSegColor(`[未实现|${JSON.stringify(segment)}]`));
|
||||
}
|
||||
let msgString = `${prefix}${ob11Message.sender.nickname}(${ob11Message.sender.user_id}): ${msgChain}`;
|
||||
if (isSelfSent) {
|
||||
msgString = `${prefix}: ${msgChain}`;
|
||||
}
|
||||
msgChain = msgParts.join(' ');
|
||||
}
|
||||
else {
|
||||
msgChain = ob11Message.message;
|
||||
}
|
||||
let msgString = `${prefix}${ob11Message.sender.nickname}(${ob11Message.sender.user_id}): ${msgChain}`;
|
||||
if (isSelfSent) {
|
||||
msgString = `${prefix}: ${msgChain}`;
|
||||
}
|
||||
coreContext.context.logger.log(msgString);
|
||||
coreContext.context.logger.log(msgString);
|
||||
}
|
||||
|
||||
export async function logNotice(coreContext: NapCatCore, ob11Notice: any) {
|
||||
coreContext.context.logger.log(spColor('[Notice]'), ob11Notice);
|
||||
coreContext.context.logger.log(spColor('[Notice]'), ob11Notice);
|
||||
}
|
||||
|
||||
export async function logRequest(coreContext: NapCatCore, ob11Request: any) {
|
||||
coreContext.context.logger.log(spColor('[Request]'), ob11Request);
|
||||
coreContext.context.logger.log(spColor('[Request]'), ob11Request);
|
||||
}
|
||||
|
||||
@@ -1,38 +1,43 @@
|
||||
import {
|
||||
AtType,
|
||||
ElementType, FaceIndex, FaceType, NapCatCore, PicElement,
|
||||
ElementType,
|
||||
FaceIndex,
|
||||
FaceType,
|
||||
NapCatCore,
|
||||
PicType,
|
||||
SendArkElement,
|
||||
SendFaceElement,
|
||||
SendFileElement, SendMarkdownElement, SendMarketFaceElement,
|
||||
SendFileElement,
|
||||
SendMarkdownElement,
|
||||
SendMarketFaceElement,
|
||||
SendPicElement,
|
||||
SendPttElement,
|
||||
SendReplyElement,
|
||||
sendShareLocationElement,
|
||||
SendTextElement,
|
||||
SendVideoElement,
|
||||
viedo_type
|
||||
viedo_type,
|
||||
} from '@/core';
|
||||
import { promises as fs } from 'node:fs';
|
||||
import ffmpeg from 'fluent-ffmpeg';
|
||||
import { NTQQFileApi } from '@/core/apis/file';
|
||||
import { calculateFileMD5, isGIF } from '@/common/utils/file';
|
||||
import { defaultVideoThumb, getVideoInfo } from '@/common/utils/video';
|
||||
import { encodeSilk } from '@/common/utils/audio';
|
||||
import { isNull } from '@/common/utils/helper';
|
||||
import faceConfig from '@/core/external/face_config.json';
|
||||
import * as pathLib from 'node:path';
|
||||
|
||||
export class SendMsgElementConstructor {
|
||||
static location(CoreContext: NapCatCore): sendShareLocationElement {
|
||||
return {
|
||||
elementType: ElementType.SHARELOCATION,
|
||||
elementId: '',
|
||||
shareLocationElement: {
|
||||
text: "测试",
|
||||
ext: ""
|
||||
}
|
||||
text: '测试',
|
||||
ext: '',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static text(CoreContext: NapCatCore, content: string): SendTextElement {
|
||||
return {
|
||||
elementType: ElementType.TEXT,
|
||||
@@ -70,7 +75,7 @@ export class SendMsgElementConstructor {
|
||||
replayMsgId: msgId, // raw.msgId
|
||||
senderUin: senderUin,
|
||||
senderUinStr: senderUinStr,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -99,7 +104,7 @@ export class SendMsgElementConstructor {
|
||||
fileUuid: '',
|
||||
fileSubId: '',
|
||||
thumbFileSize: 0,
|
||||
summary
|
||||
summary,
|
||||
};
|
||||
//logDebug('图片信息', picElement);
|
||||
return {
|
||||
@@ -128,7 +133,7 @@ export class SendMsgElementConstructor {
|
||||
folderId: folderId,
|
||||
'filePath': path!,
|
||||
'fileSize': (fileSize).toString(),
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return element;
|
||||
@@ -153,7 +158,7 @@ export class SendMsgElementConstructor {
|
||||
time: 15,
|
||||
format: 'mp4',
|
||||
size: fileSize,
|
||||
filePath
|
||||
filePath,
|
||||
};
|
||||
try {
|
||||
videoInfo = await getVideoInfo(path, logger);
|
||||
@@ -183,7 +188,7 @@ export class SendMsgElementConstructor {
|
||||
timestamps: [0],
|
||||
filename: thumbFileName,
|
||||
folder: thumb,
|
||||
size: videoInfo.width + 'x' + videoInfo.height
|
||||
size: videoInfo.width + 'x' + videoInfo.height,
|
||||
}).on('end', () => {
|
||||
resolve(thumbPath);
|
||||
});
|
||||
@@ -219,7 +224,7 @@ export class SendMsgElementConstructor {
|
||||
// fileFormat: 2,
|
||||
// import_rich_media_context: null,
|
||||
// sourceVideoCodecFormat: 2
|
||||
}
|
||||
},
|
||||
};
|
||||
return element;
|
||||
}
|
||||
@@ -231,7 +236,11 @@ export class SendMsgElementConstructor {
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const NTQQFriendApi = coreContext.getApiContext().FriendApi;
|
||||
const logger = coreContext.context.logger;
|
||||
const { converted, path: silkPath, duration } = await encodeSilk(pttPath, coreContext.NapCatTempPath, coreContext.context.logger);
|
||||
const {
|
||||
converted,
|
||||
path: silkPath,
|
||||
duration,
|
||||
} = await encodeSilk(pttPath, coreContext.NapCatTempPath, coreContext.context.logger);
|
||||
// log("生成语音", silkPath, duration);
|
||||
if (!silkPath) {
|
||||
throw '语音转换失败, 请检查语音文件是否正常';
|
||||
@@ -263,9 +272,10 @@ export class SendMsgElementConstructor {
|
||||
fileSubId: '',
|
||||
playState: 1,
|
||||
autoConvertText: 0,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// NodeIQQNTWrapperSession sendMsg [
|
||||
// "0",
|
||||
// {
|
||||
@@ -289,7 +299,7 @@ export class SendMsgElementConstructor {
|
||||
// {}
|
||||
// ]
|
||||
static face(CoreContext: NapCatCore, faceId: number): SendFaceElement {
|
||||
// 从face_config.json中获取表情名称
|
||||
// 从face_config.json中获取表情名称
|
||||
const sysFaces = faceConfig.sysface;
|
||||
const emojiFaces = faceConfig.emoji;
|
||||
const face: any = sysFaces.find((face) => face.QSid === faceId.toString());
|
||||
@@ -330,7 +340,7 @@ export class SendMsgElementConstructor {
|
||||
}
|
||||
|
||||
static dice(CoreContext: NapCatCore, resultId: number | null): SendFaceElement {
|
||||
// 实际测试并不能控制结果
|
||||
// 实际测试并不能控制结果
|
||||
|
||||
// 随机1到6
|
||||
// if (isNull(resultId)) resultId = Math.floor(Math.random() * 6) + 1;
|
||||
@@ -348,14 +358,14 @@ export class SendMsgElementConstructor {
|
||||
// resultId: resultId.toString(),
|
||||
'surpriseId': '',
|
||||
// "randomType": 1,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// 猜拳(石头剪刀布)表情
|
||||
static rps(CoreContext: NapCatCore, resultId: number | null): SendFaceElement {
|
||||
// 实际测试并不能控制结果
|
||||
// if (isNull(resultId)) resultId = Math.floor(Math.random() * 3) + 1;
|
||||
// 实际测试并不能控制结果
|
||||
// if (isNull(resultId)) resultId = Math.floor(Math.random() * 3) + 1;
|
||||
return {
|
||||
elementType: ElementType.FACE,
|
||||
elementId: '',
|
||||
@@ -370,7 +380,7 @@ export class SendMsgElementConstructor {
|
||||
// 'resultId': resultId.toString(),
|
||||
'surpriseId': '',
|
||||
// "randomType": 1,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -384,8 +394,8 @@ export class SendMsgElementConstructor {
|
||||
arkElement: {
|
||||
bytesData: data,
|
||||
linkInfo: null,
|
||||
subElementType: null
|
||||
}
|
||||
subElementType: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -394,8 +404,8 @@ export class SendMsgElementConstructor {
|
||||
elementType: ElementType.MARKDOWN,
|
||||
elementId: '',
|
||||
markdownElement: {
|
||||
content
|
||||
}
|
||||
content,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
import { ChatType, Group, GroupRequestOperateTypes, NapCatCore, Peer } from "@/core";
|
||||
import { OB11FriendRequestEvent } from "../event/request/OB11FriendRequest";
|
||||
import { OB11GroupRequestEvent } from "../event/request/OB11GroupRequest";
|
||||
import { OB11Message, OB11MessageAt, OB11MessageData, OB11MessageReply, QuickAction, QuickActionEvent, QuickActionFriendRequest, QuickActionGroupMessage, QuickActionGroupRequest } from "../types";
|
||||
import { isNull } from "@/common/utils/helper";
|
||||
import { createSendElements, normalize, sendMsg } from "../action/msg/SendMsg";
|
||||
import { ChatType, Group, GroupRequestOperateTypes, NapCatCore, Peer } from '@/core';
|
||||
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest';
|
||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
||||
import {
|
||||
OB11Message,
|
||||
OB11MessageAt,
|
||||
OB11MessageData,
|
||||
OB11MessageReply,
|
||||
QuickAction,
|
||||
QuickActionEvent,
|
||||
QuickActionFriendRequest,
|
||||
QuickActionGroupMessage,
|
||||
QuickActionGroupRequest,
|
||||
} from '../types';
|
||||
import { isNull } from '@/common/utils/helper';
|
||||
import { createSendElements, normalize, sendMsg } from '../action/msg/SendMsg';
|
||||
|
||||
async function handleMsg(coreContext: NapCatCore, msg: OB11Message, quickAction: QuickAction) {
|
||||
msg = msg as OB11Message;
|
||||
const reply = quickAction.reply;
|
||||
const peer: Peer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: await coreContext.getApiContext().UserApi.getUidByUin(msg.user_id.toString()) as string
|
||||
peerUid: await coreContext.getApiContext().UserApi.getUidByUin(msg.user_id.toString()) as string,
|
||||
};
|
||||
if (msg.message_type == 'private') {
|
||||
if (msg.sub_type === 'group') {
|
||||
@@ -29,15 +39,15 @@ async function handleMsg(coreContext: NapCatCore, msg: OB11Message, quickAction:
|
||||
replyMessage.push({
|
||||
type: 'reply',
|
||||
data: {
|
||||
id: msg.message_id.toString()
|
||||
}
|
||||
id: msg.message_id.toString(),
|
||||
},
|
||||
} as OB11MessageReply);
|
||||
if ((quickAction as QuickActionGroupMessage).at_sender) {
|
||||
replyMessage.push({
|
||||
type: 'at',
|
||||
data: {
|
||||
qq: msg.user_id.toString()
|
||||
}
|
||||
qq: msg.user_id.toString(),
|
||||
},
|
||||
} as OB11MessageAt);
|
||||
}
|
||||
}
|
||||
@@ -46,6 +56,7 @@ async function handleMsg(coreContext: NapCatCore, msg: OB11Message, quickAction:
|
||||
sendMsg(coreContext, peer, sendElements, deleteAfterSentFiles, false).then().catch(coreContext.context.logger.logError);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleGroupRequest(coreContext: NapCatCore, request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) {
|
||||
if (!isNull(quickAction.approve)) {
|
||||
coreContext.getApiContext().GroupApi.handleGroupRequest(
|
||||
@@ -55,11 +66,13 @@ async function handleGroupRequest(coreContext: NapCatCore, request: OB11GroupReq
|
||||
).then().catch(coreContext.context.logger.logError);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleFriendRequest(coreContext: NapCatCore, request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) {
|
||||
if (!isNull(quickAction.approve)) {
|
||||
coreContext.getApiContext().FriendApi.handleFriendRequest(request.flag, !!quickAction.approve).then().catch(coreContext.context.logger.logError);
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleQuickOperation(coreContext: NapCatCore, context: QuickActionEvent, quickAction: QuickAction) {
|
||||
if (context.post_type === 'message') {
|
||||
handleMsg(coreContext, context as OB11Message, quickAction).then().catch(coreContext.context.logger.logError);
|
||||
@@ -69,9 +82,8 @@ export async function handleQuickOperation(coreContext: NapCatCore, context: Qui
|
||||
const groupRequest = context as OB11GroupRequestEvent;
|
||||
if ((friendRequest).request_type === 'friend') {
|
||||
handleFriendRequest(coreContext, friendRequest, quickAction).then().catch(coreContext.context.logger.logError);
|
||||
}
|
||||
else if (groupRequest.request_type === 'group') {
|
||||
} else if (groupRequest.request_type === 'group') {
|
||||
handleGroupRequest(coreContext, groupRequest, quickAction).then().catch(coreContext.context.logger.logError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { NapCatCore, InstanceContext } from "@/core";
|
||||
import { OB11Config } from "./helper/config";
|
||||
import { NapCatPathWrapper } from "@/common/framework/napcat";
|
||||
import { OneBotApiContextType } from "./types/adapter";
|
||||
import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from "./api";
|
||||
import { InstanceContext, NapCatCore } from '@/core';
|
||||
import { OB11Config } from './helper/config';
|
||||
import { NapCatPathWrapper } from '@/common/framework/napcat';
|
||||
import { OneBotApiContextType } from './types/adapter';
|
||||
import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from './api';
|
||||
|
||||
//OneBot实现类
|
||||
export class NapCatOneBot11Adapter {
|
||||
@@ -10,6 +10,7 @@ export class NapCatOneBot11Adapter {
|
||||
readonly context: InstanceContext;
|
||||
config: OB11Config;
|
||||
apiContext: OneBotApiContextType;
|
||||
|
||||
constructor(core: NapCatCore, context: InstanceContext, pathWrapper: NapCatPathWrapper) {
|
||||
this.core = core;
|
||||
this.context = context;
|
||||
@@ -17,7 +18,7 @@ export class NapCatOneBot11Adapter {
|
||||
this.apiContext = {
|
||||
GroupApi: new OneBotGroupApi(this, core),
|
||||
UserApi: new OneBotUserApi(this, core),
|
||||
FriendApi: new OneBotFriendApi(this, core)
|
||||
FriendApi: new OneBotFriendApi(this, core),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
'x-self-id': this.coreContext.selfInfo.uin
|
||||
'x-self-id': this.coreContext.selfInfo.uin,
|
||||
};
|
||||
const msgStr = JSON.stringify(event);
|
||||
if (this.secret && this.secret.length > 0) {
|
||||
@@ -48,7 +48,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
fetch(this.url, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: msgStr
|
||||
body: msgStr,
|
||||
}).then(async (res) => {
|
||||
let resJson: QuickAction;
|
||||
try {
|
||||
|
||||
@@ -3,33 +3,42 @@ import { OB11BaseEvent } from '@/onebot/event/OB11BaseEvent';
|
||||
|
||||
export interface IOB11NetworkAdapter {
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T): void;
|
||||
|
||||
onEvent<T extends OB11BaseEvent>(event: T): void;
|
||||
|
||||
open(): void | Promise<void>;
|
||||
|
||||
close(): void | Promise<void>;
|
||||
}
|
||||
|
||||
export class OB11NetworkManager {
|
||||
adapters: IOB11NetworkAdapter[] = [];
|
||||
|
||||
async getAllAdapters() {
|
||||
return this.adapters;
|
||||
}
|
||||
|
||||
async PostEvent(event: OB11BaseEvent) {
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
return Promise.all(this.adapters.map(adapter => adapter.onEvent(event)));
|
||||
}
|
||||
|
||||
async registerAdapter(adapter: IOB11NetworkAdapter) {
|
||||
return this.adapters.push(adapter);
|
||||
}
|
||||
|
||||
async closeSomeAdapters(adapters: IOB11NetworkAdapter[]) {
|
||||
this.adapters = this.adapters.filter(adapter => !adapters.includes(adapter));
|
||||
await Promise.all(adapters.map(adapter => adapter.close()));
|
||||
}
|
||||
|
||||
async closeAllAdapters() {
|
||||
this.adapters = [];
|
||||
await Promise.all(this.adapters.map(adapter => adapter.close()));
|
||||
}
|
||||
}
|
||||
|
||||
export * from './active-http';
|
||||
export * from './active-websocket';
|
||||
export * from './passive-http';
|
||||
export * from './passive-websocket';
|
||||
export * from './passive-websocket';
|
||||
|
||||
@@ -13,7 +13,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
private port: number;
|
||||
token: string;
|
||||
|
||||
constructor(port: number,token: string) {
|
||||
constructor(port: number, token: string) {
|
||||
this.port = port;
|
||||
this.token = token;
|
||||
}
|
||||
@@ -21,9 +21,11 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||
this.actionMap.set(action.actionName, action);
|
||||
}
|
||||
|
||||
registerHeartBeat() {
|
||||
//空心跳
|
||||
}
|
||||
|
||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||
// 事件处理逻辑可以在这里实现
|
||||
}
|
||||
@@ -76,4 +78,4 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter {
|
||||
this.hasBeenClosed = true;
|
||||
this.server?.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
wsClientsMutex = new Mutex();
|
||||
isOpen: boolean = false;
|
||||
hasBeenClosed: boolean = false;
|
||||
heartbeatInterval:number = 0;
|
||||
heartbeatInterval: number = 0;
|
||||
private actionMap: Map<string, BaseAction<any, any>> = new Map();
|
||||
|
||||
constructor(ip: string, port: number, heartbeatInterval: number, token: string) {
|
||||
@@ -49,9 +49,11 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
registerAction<T extends BaseAction<P, R>, P, R>(action: T) {
|
||||
this.actionMap.set(action.actionName, action);
|
||||
}
|
||||
|
||||
registerHeartBeat() {
|
||||
//WS正向心跳
|
||||
}
|
||||
|
||||
onEvent<T extends OB11BaseEvent>(event: T) {
|
||||
this.wsClientsMutex.runExclusive(async () => {
|
||||
this.wsClients.forEach((wsClient) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from "../api";
|
||||
import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from '../api';
|
||||
|
||||
export interface OneBotApiContextType {
|
||||
FriendApi: OneBotFriendApi;
|
||||
UserApi: OneBotUserApi;
|
||||
GroupApi: OneBotGroupApi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
export interface OB11User {
|
||||
user_id: number;
|
||||
nickname: string;
|
||||
remark?: string;
|
||||
sex?: OB11UserSex;
|
||||
level?: number;
|
||||
age?: number;
|
||||
qid?: string;
|
||||
login_days?: number;
|
||||
categroyName?:string;
|
||||
categoryId?:number;
|
||||
user_id: number;
|
||||
nickname: string;
|
||||
remark?: string;
|
||||
sex?: OB11UserSex;
|
||||
level?: number;
|
||||
age?: number;
|
||||
qid?: string;
|
||||
login_days?: number;
|
||||
categroyName?: string;
|
||||
categoryId?: number;
|
||||
}
|
||||
|
||||
export enum OB11UserSex {
|
||||
male = 'male',
|
||||
female = 'female',
|
||||
unknown = 'unknown'
|
||||
male = 'male',
|
||||
female = 'female',
|
||||
unknown = 'unknown'
|
||||
}
|
||||
|
||||
export enum OB11GroupMemberRole {
|
||||
owner = 'owner',
|
||||
admin = 'admin',
|
||||
member = 'member',
|
||||
owner = 'owner',
|
||||
admin = 'admin',
|
||||
member = 'member',
|
||||
}
|
||||
|
||||
export interface OB11GroupMember {
|
||||
group_id: number
|
||||
user_id: number
|
||||
nickname: string
|
||||
card?: string
|
||||
sex?: OB11UserSex
|
||||
age?: number
|
||||
join_time?: number
|
||||
last_sent_time?: number
|
||||
level?: string
|
||||
qq_level?: number
|
||||
role?: OB11GroupMemberRole
|
||||
title?: string
|
||||
area?: string
|
||||
unfriendly?: boolean
|
||||
title_expire_time?: number
|
||||
card_changeable?: boolean
|
||||
// 以下为gocq字段
|
||||
shut_up_timestamp?: number
|
||||
// 以下为扩展字段
|
||||
is_robot?: boolean
|
||||
qage?: number
|
||||
group_id: number;
|
||||
user_id: number;
|
||||
nickname: string;
|
||||
card?: string;
|
||||
sex?: OB11UserSex;
|
||||
age?: number;
|
||||
join_time?: number;
|
||||
last_sent_time?: number;
|
||||
level?: string;
|
||||
qq_level?: number;
|
||||
role?: OB11GroupMemberRole;
|
||||
title?: string;
|
||||
area?: string;
|
||||
unfriendly?: boolean;
|
||||
title_expire_time?: number;
|
||||
card_changeable?: boolean;
|
||||
// 以下为gocq字段
|
||||
shut_up_timestamp?: number;
|
||||
// 以下为扩展字段
|
||||
is_robot?: boolean;
|
||||
qage?: number;
|
||||
}
|
||||
|
||||
export interface OB11Group {
|
||||
group_id: number
|
||||
group_name: string
|
||||
member_count?: number
|
||||
max_member_count?: number
|
||||
group_id: number;
|
||||
group_name: string;
|
||||
member_count?: number;
|
||||
max_member_count?: number;
|
||||
}
|
||||
|
||||
export interface OB11Sender {
|
||||
user_id: number,
|
||||
nickname: string,
|
||||
sex?: OB11UserSex,
|
||||
age?: number,
|
||||
card?: string, // 群名片
|
||||
level?: string, // 群等级
|
||||
role?: OB11GroupMemberRole
|
||||
user_id: number,
|
||||
nickname: string,
|
||||
sex?: OB11UserSex,
|
||||
age?: number,
|
||||
card?: string, // 群名片
|
||||
level?: string, // 群等级
|
||||
role?: OB11GroupMemberRole
|
||||
}
|
||||
|
||||
@@ -3,202 +3,204 @@ import { EventType } from '@/onebot/event/OB11BaseEvent';
|
||||
import { CustomMusicSignPostData, IdMusicSignPostData, PicSubType, RawMessage } from '@/core';
|
||||
|
||||
export enum OB11MessageType {
|
||||
private = 'private',
|
||||
group = 'group'
|
||||
private = 'private',
|
||||
group = 'group'
|
||||
}
|
||||
|
||||
export interface OB11Message {
|
||||
target_id?: number; // 自己发送的消息才有此字段
|
||||
self_id?: number,
|
||||
time: number,
|
||||
message_id: number,
|
||||
message_seq: number, // 和message_id一样
|
||||
real_id: number,
|
||||
user_id: number,
|
||||
group_id?: number,
|
||||
message_type: 'private' | 'group',
|
||||
sub_type?: 'friend' | 'group' | 'normal',
|
||||
sender: OB11Sender,
|
||||
message: OB11MessageData[] | string,
|
||||
message_format: 'array' | 'string',
|
||||
raw_message: string,
|
||||
font: number,
|
||||
post_type?: EventType,
|
||||
raw?: RawMessage
|
||||
target_id?: number; // 自己发送的消息才有此字段
|
||||
self_id?: number,
|
||||
time: number,
|
||||
message_id: number,
|
||||
message_seq: number, // 和message_id一样
|
||||
real_id: number,
|
||||
user_id: number,
|
||||
group_id?: number,
|
||||
message_type: 'private' | 'group',
|
||||
sub_type?: 'friend' | 'group' | 'normal',
|
||||
sender: OB11Sender,
|
||||
message: OB11MessageData[] | string,
|
||||
message_format: 'array' | 'string',
|
||||
raw_message: string,
|
||||
font: number,
|
||||
post_type?: EventType,
|
||||
raw?: RawMessage
|
||||
}
|
||||
|
||||
export interface OB11ForwardMessage extends OB11Message {
|
||||
content: OB11MessageData[] | string;
|
||||
content: OB11MessageData[] | string;
|
||||
}
|
||||
|
||||
export interface OB11Return<DataType> {
|
||||
status: string
|
||||
retcode: number
|
||||
data: DataType
|
||||
message: string,
|
||||
echo?: any, // ws调用api才有此字段
|
||||
wording?: string, // go-cqhttp字段,错误信息
|
||||
status: string
|
||||
retcode: number
|
||||
data: DataType
|
||||
message: string,
|
||||
echo?: any, // ws调用api才有此字段
|
||||
wording?: string, // go-cqhttp字段,错误信息
|
||||
}
|
||||
|
||||
export enum OB11MessageDataType {
|
||||
text = 'text',
|
||||
image = 'image',
|
||||
music = 'music',
|
||||
video = 'video',
|
||||
voice = 'record',
|
||||
file = 'file',
|
||||
at = 'at',
|
||||
reply = 'reply',
|
||||
json = 'json',
|
||||
face = 'face',
|
||||
mface = 'mface', // 商城表情
|
||||
markdown = 'markdown',
|
||||
node = 'node', // 合并转发消息节点
|
||||
forward = 'forward', // 合并转发消息,用于上报
|
||||
xml = 'xml',
|
||||
poke = 'poke',
|
||||
dice = 'dice',
|
||||
RPS = 'rps',
|
||||
miniapp = 'miniapp',//json类
|
||||
Location = 'location'
|
||||
text = 'text',
|
||||
image = 'image',
|
||||
music = 'music',
|
||||
video = 'video',
|
||||
voice = 'record',
|
||||
file = 'file',
|
||||
at = 'at',
|
||||
reply = 'reply',
|
||||
json = 'json',
|
||||
face = 'face',
|
||||
mface = 'mface', // 商城表情
|
||||
markdown = 'markdown',
|
||||
node = 'node', // 合并转发消息节点
|
||||
forward = 'forward', // 合并转发消息,用于上报
|
||||
xml = 'xml',
|
||||
poke = 'poke',
|
||||
dice = 'dice',
|
||||
RPS = 'rps',
|
||||
miniapp = 'miniapp',//json类
|
||||
Location = 'location'
|
||||
}
|
||||
|
||||
export interface OB11MessageMFace {
|
||||
type: OB11MessageDataType.mface
|
||||
data: {
|
||||
emoji_package_id: number
|
||||
emoji_id: string
|
||||
key: string
|
||||
summary: string
|
||||
}
|
||||
type: OB11MessageDataType.mface;
|
||||
data: {
|
||||
emoji_package_id: number
|
||||
emoji_id: string
|
||||
key: string
|
||||
summary: string
|
||||
};
|
||||
}
|
||||
|
||||
export interface OB11MessageText {
|
||||
type: OB11MessageDataType.text,
|
||||
data: {
|
||||
text: string, // 纯文本
|
||||
}
|
||||
type: OB11MessageDataType.text,
|
||||
data: {
|
||||
text: string, // 纯文本
|
||||
}
|
||||
}
|
||||
|
||||
export interface OB11MessageFileBase {
|
||||
data: {
|
||||
thumb?: string;
|
||||
name?: string;
|
||||
file: string,
|
||||
url?: string;
|
||||
}
|
||||
data: {
|
||||
thumb?: string;
|
||||
name?: string;
|
||||
file: string,
|
||||
url?: string;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export interface OB11MessageImage extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.image
|
||||
data: OB11MessageFileBase['data'] & {
|
||||
summary?: string; // 图片摘要
|
||||
subType?: PicSubType
|
||||
},
|
||||
type: OB11MessageDataType.image
|
||||
data: OB11MessageFileBase['data'] & {
|
||||
summary?: string; // 图片摘要
|
||||
subType?: PicSubType
|
||||
},
|
||||
}
|
||||
|
||||
export interface OB11MessageRecord extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.voice
|
||||
type: OB11MessageDataType.voice;
|
||||
}
|
||||
|
||||
export interface OB11MessageFile extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.file
|
||||
type: OB11MessageDataType.file;
|
||||
}
|
||||
|
||||
export interface OB11MessageVideo extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.video
|
||||
type: OB11MessageDataType.video;
|
||||
}
|
||||
|
||||
export interface OB11MessageAt {
|
||||
type: OB11MessageDataType.at
|
||||
data: {
|
||||
qq: `${number}` | 'all'
|
||||
name?: string
|
||||
}
|
||||
type: OB11MessageDataType.at;
|
||||
data: {
|
||||
qq: `${number}` | 'all'
|
||||
name?: string
|
||||
};
|
||||
}
|
||||
|
||||
export interface OB11MessageReply {
|
||||
type: OB11MessageDataType.reply
|
||||
data: {
|
||||
id: string
|
||||
}
|
||||
type: OB11MessageDataType.reply;
|
||||
data: {
|
||||
id: string
|
||||
};
|
||||
}
|
||||
|
||||
export interface OB11MessageFace {
|
||||
type: OB11MessageDataType.face
|
||||
data: {
|
||||
id: string
|
||||
}
|
||||
type: OB11MessageDataType.face;
|
||||
data: {
|
||||
id: string
|
||||
};
|
||||
}
|
||||
|
||||
export type OB11MessageMixType = OB11MessageData[] | string | OB11MessageData;
|
||||
|
||||
export interface OB11MessageNode {
|
||||
type: OB11MessageDataType.node
|
||||
data: {
|
||||
id?: string
|
||||
user_id?: number
|
||||
nickname: string
|
||||
content: OB11MessageMixType
|
||||
}
|
||||
type: OB11MessageDataType.node;
|
||||
data: {
|
||||
id?: string
|
||||
user_id?: number
|
||||
nickname: string
|
||||
content: OB11MessageMixType
|
||||
};
|
||||
}
|
||||
|
||||
export interface OB11MessageIdMusic {
|
||||
type: OB11MessageDataType.music
|
||||
data: IdMusicSignPostData
|
||||
type: OB11MessageDataType.music;
|
||||
data: IdMusicSignPostData;
|
||||
}
|
||||
|
||||
export interface OB11MessageCustomMusic {
|
||||
type: OB11MessageDataType.music
|
||||
data: Omit<CustomMusicSignPostData, 'singer'> & { content?: string }
|
||||
type: OB11MessageDataType.music;
|
||||
data: Omit<CustomMusicSignPostData, 'singer'> & { content?: string };
|
||||
}
|
||||
|
||||
export interface OB11MessageJson {
|
||||
type: OB11MessageDataType.json
|
||||
data: { config: { token: string } } & any
|
||||
type: OB11MessageDataType.json;
|
||||
data: { config: { token: string } } & any;
|
||||
}
|
||||
|
||||
export interface OB11MessageDice {
|
||||
type: OB11MessageDataType.dice,
|
||||
data: {
|
||||
result: number
|
||||
}
|
||||
type: OB11MessageDataType.dice,
|
||||
data: {
|
||||
result: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface OB11MessageRPS {
|
||||
type: OB11MessageDataType.RPS,
|
||||
data: {
|
||||
result: number
|
||||
}
|
||||
type: OB11MessageDataType.RPS,
|
||||
data: {
|
||||
result: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface OB11MessageMarkdown {
|
||||
type: OB11MessageDataType.markdown
|
||||
data: {
|
||||
content: string
|
||||
}
|
||||
type: OB11MessageDataType.markdown;
|
||||
data: {
|
||||
content: string
|
||||
};
|
||||
}
|
||||
|
||||
export interface OB11MessageForward {
|
||||
type: OB11MessageDataType.forward
|
||||
data: {
|
||||
id: string,
|
||||
content: OB11Message[]
|
||||
}
|
||||
type: OB11MessageDataType.forward;
|
||||
data: {
|
||||
id: string,
|
||||
content: OB11Message[]
|
||||
};
|
||||
}
|
||||
|
||||
export type OB11MessageData =
|
||||
OB11MessageText |
|
||||
OB11MessageFace | OB11MessageMFace |
|
||||
OB11MessageAt | OB11MessageReply |
|
||||
OB11MessageImage | OB11MessageRecord | OB11MessageFile | OB11MessageVideo |
|
||||
OB11MessageNode | OB11MessageIdMusic | OB11MessageCustomMusic | OB11MessageJson |
|
||||
OB11MessageDice | OB11MessageRPS | OB11MessageMarkdown | OB11MessageForward
|
||||
OB11MessageText |
|
||||
OB11MessageFace | OB11MessageMFace |
|
||||
OB11MessageAt | OB11MessageReply |
|
||||
OB11MessageImage | OB11MessageRecord | OB11MessageFile | OB11MessageVideo |
|
||||
OB11MessageNode | OB11MessageIdMusic | OB11MessageCustomMusic | OB11MessageJson |
|
||||
OB11MessageDice | OB11MessageRPS | OB11MessageMarkdown | OB11MessageForward
|
||||
|
||||
export interface OB11PostSendMsg {
|
||||
message_type?: 'private' | 'group'
|
||||
user_id?: string,
|
||||
group_id?: string,
|
||||
message: OB11MessageMixType;
|
||||
messages?: OB11MessageMixType; // 兼容 go-cqhttp
|
||||
auto_escape?: boolean | string
|
||||
message_type?: 'private' | 'group'
|
||||
user_id?: string,
|
||||
group_id?: string,
|
||||
message: OB11MessageMixType;
|
||||
messages?: OB11MessageMixType; // 兼容 go-cqhttp
|
||||
auto_escape?: boolean | string
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user