diff --git a/src/common/utils/ConfigBase.ts b/src/common/utils/ConfigBase.ts index d1d34ded..ce4070d1 100644 --- a/src/common/utils/ConfigBase.ts +++ b/src/common/utils/ConfigBase.ts @@ -4,13 +4,13 @@ import type { NapCatCore } from '@/core'; export abstract class ConfigBase { name: string; - coreContext: NapCatCore; + core: NapCatCore; configPath: string; configData: T = {} as T; - protected constructor(name: string, coreContext: NapCatCore, configPath: string) { + protected constructor(name: string, core: NapCatCore, configPath: string) { this.name = name; - this.coreContext = coreContext; + this.core = core; this.configPath = configPath; fs.mkdirSync(this.configPath, { recursive: true }); this.read(); @@ -28,8 +28,8 @@ export abstract class ConfigBase { } read(): T { - const logger = this.coreContext.context.logger; - const configPath = this.getConfigPath(this.coreContext.selfInfo.uin); + const logger = this.core.context.logger; + const configPath = this.getConfigPath(this.core.selfInfo.uin); if (!fs.existsSync(configPath)) { try { fs.writeFileSync(configPath, fs.readFileSync(this.getConfigPath(undefined), 'utf-8')); @@ -54,8 +54,8 @@ export abstract class ConfigBase { save(newConfigData: T = this.configData) { - const logger = this.coreContext.context.logger; - const selfInfo = this.coreContext.selfInfo; + const logger = this.core.context.logger; + const selfInfo = this.core.selfInfo; this.configData = newConfigData; const configPath = this.getConfigPath(selfInfo.uin); try { diff --git a/src/core/helper/config.ts b/src/core/helper/config.ts index 5860b27d..a1b8fcc2 100644 --- a/src/core/helper/config.ts +++ b/src/core/helper/config.ts @@ -7,7 +7,7 @@ export type NapCatConfig = typeof napCatDefaultConfig; // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging export class NapCatConfigLoader extends ConfigBase { - constructor(coreContext: NapCatCore, configPath: string) { - super('napcat', coreContext, configPath); + constructor(core: NapCatCore, configPath: string) { + super('napcat', core, configPath); } } diff --git a/src/onebot/action/BaseAction.ts b/src/onebot/action/BaseAction.ts index 9c4ec34a..c6d696d8 100644 --- a/src/onebot/action/BaseAction.ts +++ b/src/onebot/action/BaseAction.ts @@ -8,19 +8,19 @@ import { NapCatOneBot11Adapter } from '@/onebot'; abstract class BaseAction { actionName: ActionName = ActionName.Unknown; - CoreContext: NapCatCore; + core: NapCatCore; private validate: undefined | ValidateFunction = undefined; - PayloadSchema: any = undefined; - OneBotContext: NapCatOneBot11Adapter; + payloadSchema: any = undefined; + obContext: NapCatOneBot11Adapter; - constructor(onebotContext: NapCatOneBot11Adapter, coreContext: NapCatCore) { - this.OneBotContext = onebotContext; - this.CoreContext = coreContext; + constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) { + this.obContext = obContext; + this.core = core; } protected async check(payload: PayloadType): Promise { - if (this.PayloadSchema) { - this.validate = new Ajv({ allowUnionTypes: true }).compile(this.PayloadSchema); + if (this.payloadSchema) { + this.validate = new Ajv({ allowUnionTypes: true }).compile(this.payloadSchema); } if (this.validate && !this.validate(payload)) { const errors = this.validate.errors as ErrorObject[]; @@ -46,7 +46,7 @@ abstract class BaseAction { const resData = await this._handle(payload); return OB11Response.ok(resData); } catch (e: any) { - this.CoreContext.context.logger.logError('发生错误', e); + this.core.context.logger.logError('发生错误', e); return OB11Response.error(e?.toString() || e?.stack?.toString() || '未知错误,可能操作超时', 200); } } @@ -60,7 +60,7 @@ abstract class BaseAction { const resData = await this._handle(payload); return OB11Response.ok(resData, echo); } catch (e: any) { - this.CoreContext.context.logger.logError('发生错误', e); + this.core.context.logger.logError('发生错误', e); return OB11Response.error(e.stack?.toString() || e.toString(), 1200, echo); } } diff --git a/src/onebot/action/extends/CreateCollection.ts b/src/onebot/action/extends/CreateCollection.ts index d46c01e3..d7a5e58c 100644 --- a/src/onebot/action/extends/CreateCollection.ts +++ b/src/onebot/action/extends/CreateCollection.ts @@ -15,13 +15,13 @@ type Payload = FromSchema; export class CreateCollection extends BaseAction { actionName = ActionName.CreateCollection; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - return await this.CoreContext.apis.CollectionApi.createCollection( - this.CoreContext.selfInfo.uin, - this.CoreContext.selfInfo.uid, - this.CoreContext.selfInfo.nick, + return await this.core.apis.CollectionApi.createCollection( + this.core.selfInfo.uin, + this.core.selfInfo.uid, + this.core.selfInfo.nick, payload.brief, payload.rawData, ); } diff --git a/src/onebot/action/extends/FetchCustomFace.ts b/src/onebot/action/extends/FetchCustomFace.ts index d9ed5fef..041e38f6 100644 --- a/src/onebot/action/extends/FetchCustomFace.ts +++ b/src/onebot/action/extends/FetchCustomFace.ts @@ -13,11 +13,11 @@ type Payload = FromSchema; export class FetchCustomFace extends BaseAction { actionName = ActionName.FetchCustomFace; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { //48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa - const ret = await this.CoreContext.apis.MsgApi.fetchFavEmojiList(+(payload.count ?? 48)); + const ret = await this.core.apis.MsgApi.fetchFavEmojiList(+(payload.count ?? 48)); return ret.emojiInfoList.map(e => e.url); } } diff --git a/src/onebot/action/extends/FetchEmojiLike.ts b/src/onebot/action/extends/FetchEmojiLike.ts index af89b111..d21c9dac 100644 --- a/src/onebot/action/extends/FetchEmojiLike.ts +++ b/src/onebot/action/extends/FetchEmojiLike.ts @@ -21,9 +21,9 @@ type Payload = FromSchema; export class FetchEmojiLike extends BaseAction { actionName = ActionName.FetchEmojiLike; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString())); if (!msgIdPeer) throw new Error('消息不存在'); const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0]; diff --git a/src/onebot/action/extends/GetCollectionList.ts b/src/onebot/action/extends/GetCollectionList.ts index c7d3e1b6..bf15c5ea 100644 --- a/src/onebot/action/extends/GetCollectionList.ts +++ b/src/onebot/action/extends/GetCollectionList.ts @@ -15,9 +15,9 @@ type Payload = FromSchema; export class GetCollectionList extends BaseAction { actionName = ActionName.GetCollectionList; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQCollectionApi = this.CoreContext.apis.CollectionApi; + const NTQQCollectionApi = this.core.apis.CollectionApi; return await NTQQCollectionApi.getAllCollection(parseInt(payload.category.toString()), +(payload.count ?? 1)); } } diff --git a/src/onebot/action/extends/GetFriendWithCategory.ts b/src/onebot/action/extends/GetFriendWithCategory.ts index 08ac9627..12cd92b0 100644 --- a/src/onebot/action/extends/GetFriendWithCategory.ts +++ b/src/onebot/action/extends/GetFriendWithCategory.ts @@ -5,7 +5,7 @@ import { ActionName } from '../types'; export class GetFriendWithCategory extends BaseAction { actionName = ActionName.GetFriendsWithCategory; async _handle(payload: void) { - return (await this.CoreContext.apis.FriendApi.getBuddyV2ExWithCate(true)).map(category => ({ + return (await this.core.apis.FriendApi.getBuddyV2ExWithCate(true)).map(category => ({ ...category, buddyList: OB11Constructor.friendsV2(category.buddyList), })); diff --git a/src/onebot/action/extends/GetGroupAddRequest.ts b/src/onebot/action/extends/GetGroupAddRequest.ts index e7b2020a..2b37bd75 100644 --- a/src/onebot/action/extends/GetGroupAddRequest.ts +++ b/src/onebot/action/extends/GetGroupAddRequest.ts @@ -11,7 +11,7 @@ export default class GetGroupAddRequest extends BaseAction { - const data = await this.CoreContext.apis.GroupApi.getGroupIgnoreNotifies(); + const data = await this.core.apis.GroupApi.getGroupIgnoreNotifies(); // log(data); // const notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE); // const returnData: OB11GroupRequestNotify[] = []; diff --git a/src/onebot/action/extends/GetProfileLike.ts b/src/onebot/action/extends/GetProfileLike.ts index d9312bb6..1a726a4a 100644 --- a/src/onebot/action/extends/GetProfileLike.ts +++ b/src/onebot/action/extends/GetProfileLike.ts @@ -5,8 +5,8 @@ export class GetProfileLike extends BaseAction { actionName = ActionName.GetProfileLike; async _handle(payload: void) { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const ret = await NTQQUserApi.getProfileLike(this.CoreContext.selfInfo.uid); + const NTQQUserApi = this.core.apis.UserApi; + const ret = await NTQQUserApi.getProfileLike(this.core.selfInfo.uid); const listdata: any[] = ret.info.userLikeInfos[0].favoriteInfo.userInfos; for (let i = 0; i < listdata.length; i++) { listdata[i].uin = parseInt((await NTQQUserApi.getUinByUidV2(listdata[i].uid)) || ''); diff --git a/src/onebot/action/extends/GetRobotUinRange.ts b/src/onebot/action/extends/GetRobotUinRange.ts index 0466f3cf..707f8f75 100644 --- a/src/onebot/action/extends/GetRobotUinRange.ts +++ b/src/onebot/action/extends/GetRobotUinRange.ts @@ -5,7 +5,7 @@ export class GetRobotUinRange extends BaseAction> { actionName = ActionName.GetRobotUinRange; async _handle(payload: void) { - const NTQQUserApi = this.CoreContext.apis.UserApi; + const NTQQUserApi = this.core.apis.UserApi; return await NTQQUserApi.getRobotUinRange(); } } diff --git a/src/onebot/action/extends/OCRImage.ts b/src/onebot/action/extends/OCRImage.ts index 8def1814..e9e8f030 100644 --- a/src/onebot/action/extends/OCRImage.ts +++ b/src/onebot/action/extends/OCRImage.ts @@ -15,11 +15,11 @@ type Payload = FromSchema; export class OCRImage extends BaseAction { actionName = ActionName.OCRImage; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQSystemApi = this.CoreContext.apis.SystemApi; - const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.image)); + const NTQQSystemApi = this.core.apis.SystemApi; + const { path, isLocal, errMsg, success } = (await uri2local(this.core.NapCatTempPath, payload.image)); if (!success) { throw `OCR ${payload.image}失败,image字段可能格式不正确`; } diff --git a/src/onebot/action/extends/SetInputStatus.ts b/src/onebot/action/extends/SetInputStatus.ts index fccea293..d1af6fca 100644 --- a/src/onebot/action/extends/SetInputStatus.ts +++ b/src/onebot/action/extends/SetInputStatus.ts @@ -19,8 +19,8 @@ export class SetInputStatus extends BaseAction { actionName = ActionName.SetInputStatus; async _handle(payload: Payload) { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQMsgApi = this.core.apis.MsgApi; let peer: Peer; if (payload.group_id) { peer = { diff --git a/src/onebot/action/extends/SetLongNick.ts b/src/onebot/action/extends/SetLongNick.ts index a9a07af0..c1e97d7b 100644 --- a/src/onebot/action/extends/SetLongNick.ts +++ b/src/onebot/action/extends/SetLongNick.ts @@ -14,10 +14,10 @@ type Payload = FromSchema; export class SetLongNick extends BaseAction { actionName = ActionName.SetLongNick; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQUserApi = this.CoreContext.apis.UserApi; + const NTQQUserApi = this.core.apis.UserApi; const ret = await NTQQUserApi.setLongNick(payload.longNick); return ret; } diff --git a/src/onebot/action/extends/SetOnlineStatus.ts b/src/onebot/action/extends/SetOnlineStatus.ts index efbcc818..0c6a5274 100644 --- a/src/onebot/action/extends/SetOnlineStatus.ts +++ b/src/onebot/action/extends/SetOnlineStatus.ts @@ -17,10 +17,10 @@ type Payload = FromSchema; export class SetOnlineStatus extends BaseAction { actionName = ActionName.SetOnlineStatus; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQUserApi = this.CoreContext.apis.UserApi; + const NTQQUserApi = this.core.apis.UserApi; const ret = await NTQQUserApi.setSelfOnlineStatus( parseInt(payload.status.toString()), parseInt(payload.extStatus.toString()), diff --git a/src/onebot/action/extends/SetQQAvatar.ts b/src/onebot/action/extends/SetQQAvatar.ts index ee83444c..4939f7bc 100644 --- a/src/onebot/action/extends/SetQQAvatar.ts +++ b/src/onebot/action/extends/SetQQAvatar.ts @@ -24,8 +24,8 @@ export default class SetAvatar extends BaseAction { } async _handle(payload: Payload): Promise { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file)); + const NTQQUserApi = this.core.apis.UserApi; + const { path, isLocal, errMsg, success } = (await uri2local(this.core.NapCatTempPath, payload.file)); if (!success) { throw `头像${payload.file}设置失败,file字段可能格式不正确`; } diff --git a/src/onebot/action/extends/ShareContact.ts b/src/onebot/action/extends/ShareContact.ts index 1a039182..ca452b3a 100644 --- a/src/onebot/action/extends/ShareContact.ts +++ b/src/onebot/action/extends/ShareContact.ts @@ -16,11 +16,11 @@ type Payload = FromSchema; export class SharePeer extends BaseAction { actionName = ActionName.SharePeer; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQGroupApi = this.core.apis.GroupApi; if (payload.group_id) { return await NTQQGroupApi.getGroupRecommendContactArkJson(payload.group_id); } else if (payload.user_id) { @@ -41,10 +41,10 @@ type PayloadGroupEx = FromSchema; export class ShareGroupEx extends BaseAction { actionName = ActionName.ShareGroupEx; - PayloadSchema = SchemaDataGroupEx; + payloadSchema = SchemaDataGroupEx; async _handle(payload: PayloadGroupEx) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; return await NTQQGroupApi.getArkJsonGroupShare(payload.group_id); } } diff --git a/src/onebot/action/extends/TranslateEnWordToZn.ts b/src/onebot/action/extends/TranslateEnWordToZn.ts index d4c1cbb6..0ce0a3a8 100644 --- a/src/onebot/action/extends/TranslateEnWordToZn.ts +++ b/src/onebot/action/extends/TranslateEnWordToZn.ts @@ -17,10 +17,10 @@ type Payload = FromSchema; export class TranslateEnWordToZn extends BaseAction | null> { actionName = ActionName.TranslateEnWordToZn; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQSystemApi = this.CoreContext.apis.SystemApi; + const NTQQSystemApi = this.core.apis.SystemApi; const ret = await NTQQSystemApi.translateEnWordToZn(payload.words); if (ret.result !== 0) { throw new Error('翻译失败'); diff --git a/src/onebot/action/file/DelGroupFile.ts b/src/onebot/action/file/DelGroupFile.ts index 0e926631..b27b4e2e 100644 --- a/src/onebot/action/file/DelGroupFile.ts +++ b/src/onebot/action/file/DelGroupFile.ts @@ -15,10 +15,10 @@ type Payload = FromSchema; export class DelGroupFile extends BaseAction { actionName = ActionName.DelGroupFile; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; return await NTQQGroupApi.DelGroupFile(payload.group_id.toString(), [payload.file_id]); } } diff --git a/src/onebot/action/file/DelGroupFileFolder.ts b/src/onebot/action/file/DelGroupFileFolder.ts index f80fa260..536891e6 100644 --- a/src/onebot/action/file/DelGroupFileFolder.ts +++ b/src/onebot/action/file/DelGroupFileFolder.ts @@ -15,10 +15,10 @@ type Payload = FromSchema; export class DelGroupFileFolder extends BaseAction { actionName = ActionName.DelGroupFileFolder; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; return (await NTQQGroupApi.DelGroupFileFolder(payload.group_id.toString(), payload.folder_id)).groupFileCommonResult; } } diff --git a/src/onebot/action/file/GetFile.ts b/src/onebot/action/file/GetFile.ts index 52b8fe53..afae43fd 100644 --- a/src/onebot/action/file/GetFile.ts +++ b/src/onebot/action/file/GetFile.ts @@ -26,14 +26,14 @@ const GetFileBase_PayloadSchema = { } as const satisfies JSONSchema; export class GetFileBase extends BaseAction { - PayloadSchema: any = GetFileBase_PayloadSchema; + payloadSchema: any = GetFileBase_PayloadSchema; async _handle(payload: GetFilePayload): Promise { - const NTQQFriendApi = this.CoreContext.apis.FriendApi; - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQMsgApi = this.CoreContext.apis.MsgApi; - const NTQQGroupApi = this.CoreContext.apis.GroupApi; - const NTQQFileApi = this.CoreContext.apis.FileApi; + const NTQQFriendApi = this.core.apis.FriendApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQMsgApi = this.core.apis.MsgApi; + const NTQQGroupApi = this.core.apis.GroupApi; + const NTQQFileApi = this.core.apis.FileApi; let UuidData: { high: string; low: string; @@ -90,7 +90,7 @@ export class GetFileBase extends BaseAction { return res; } } catch { - this.CoreContext.context.logger.logDebug('GetFileBase Mode - 1 Error'); + this.core.context.logger.logDebug('GetFileBase Mode - 1 Error'); } const NTSearchNameResult = (await NTQQFileApi.searchfile([payload.file])).resultItems; @@ -210,7 +210,7 @@ interface GetFile_Payload extends GetFile_Payload_Internal { export default class GetFile extends GetFileBase { actionName = ActionName.GetFile; - PayloadSchema = GetFile_PayloadSchema; + payloadSchema = GetFile_PayloadSchema; async _handle(payload: GetFile_Payload): Promise { payload.file = payload.file_id; diff --git a/src/onebot/action/file/GetGroupFileCount.ts b/src/onebot/action/file/GetGroupFileCount.ts index 250b8053..a42f5ce9 100644 --- a/src/onebot/action/file/GetGroupFileCount.ts +++ b/src/onebot/action/file/GetGroupFileCount.ts @@ -14,10 +14,10 @@ type Payload = FromSchema; export class GetGroupFileCount extends BaseAction { actionName = ActionName.GetGroupFileCount; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; const ret = await NTQQGroupApi.GetGroupFileCount([payload.group_id?.toString()]); return { count: ret.groupFileCounts[0] }; } diff --git a/src/onebot/action/file/GetGroupFileList.ts b/src/onebot/action/file/GetGroupFileList.ts index e1fc23c7..dbb7ff4f 100644 --- a/src/onebot/action/file/GetGroupFileList.ts +++ b/src/onebot/action/file/GetGroupFileList.ts @@ -16,10 +16,10 @@ type Payload = FromSchema; export class GetGroupFileList extends BaseAction }> { actionName = ActionName.GetGroupFileList; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const ret = await NTQQMsgApi.getGroupFileList(payload.group_id.toString(), { sortType: 1, fileCount: payload.file_count, diff --git a/src/onebot/action/file/SetGroupFileFolder.ts b/src/onebot/action/file/SetGroupFileFolder.ts index 07c67854..f5744c28 100644 --- a/src/onebot/action/file/SetGroupFileFolder.ts +++ b/src/onebot/action/file/SetGroupFileFolder.ts @@ -15,10 +15,10 @@ type Payload = FromSchema; export class SetGroupFileFolder extends BaseAction { actionName = ActionName.SetGroupFileFolder; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; return (await NTQQGroupApi.CreatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem; } } diff --git a/src/onebot/action/go-cqhttp/DownloadFile.ts b/src/onebot/action/go-cqhttp/DownloadFile.ts index 74209209..1dae2cbc 100644 --- a/src/onebot/action/go-cqhttp/DownloadFile.ts +++ b/src/onebot/action/go-cqhttp/DownloadFile.ts @@ -30,12 +30,12 @@ type Payload = FromSchema; export default class GoCQHTTPDownloadFile extends BaseAction { actionName = ActionName.GoCQHTTP_DownloadFile; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const isRandomName = !payload.name; const name = payload.name || randomUUID(); - const filePath = joinPath(this.CoreContext.NapCatTempPath, name); + const filePath = joinPath(this.core.NapCatTempPath, name); if (payload.base64) { fs.writeFileSync(filePath, payload.base64, 'base64'); @@ -51,7 +51,7 @@ export default class GoCQHTTPDownloadFile extends BaseAction { actionName = ActionName.GoCQHTTP_GetForwardMsg; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const msgId = payload.message_id || payload.id; if (!msgId) { throw Error('message_id is required'); @@ -39,7 +39,7 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction { } const msgList = data.msgList; const messages = (await Promise.all(msgList.map(async msg => { - const resMsg = await this.OneBotContext.apiContext.MsgApi + const resMsg = await this.obContext.apiContext.MsgApi .parseMessage(msg); if (!resMsg) return; resMsg.message_id = MessageUnique.createMsg({ diff --git a/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts index 7be0bb10..11773072 100644 --- a/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts @@ -24,12 +24,12 @@ type Payload = FromSchema; export default class GetFriendMsgHistory extends BaseAction { actionName = ActionName.GetFriendMsgHistory; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQMsgApi = this.CoreContext.apis.MsgApi; - const NTQQFriendApi = this.CoreContext.apis.FriendApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQMsgApi = this.core.apis.MsgApi; + const NTQQFriendApi = this.core.apis.FriendApi; //处理参数 const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); const MsgCount = +(payload.count ?? 20); @@ -53,7 +53,7 @@ export default class GetFriendMsgHistory extends BaseAction { })); //转换消息 const ob11MsgList = (await Promise.all( - msgList.map(msg => this.OneBotContext.apiContext.MsgApi.parseMessage(msg))) + msgList.map(msg => this.obContext.apiContext.MsgApi.parseMessage(msg))) ).filter(msg => msg !== undefined); return { 'messages': ob11MsgList }; } diff --git a/src/onebot/action/go-cqhttp/GetGroupHonorInfo.ts b/src/onebot/action/go-cqhttp/GetGroupHonorInfo.ts index 25ffa30c..e8e66678 100644 --- a/src/onebot/action/go-cqhttp/GetGroupHonorInfo.ts +++ b/src/onebot/action/go-cqhttp/GetGroupHonorInfo.ts @@ -16,13 +16,13 @@ type Payload = FromSchema; export class GetGroupHonorInfo extends BaseAction> { actionName = ActionName.GetGroupHonorInfo; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { if (!payload.type) { payload.type = WebHonorType.ALL; } - const NTQQWebApi = this.CoreContext.apis.WebApi; + const NTQQWebApi = this.core.apis.WebApi; return await NTQQWebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type); } } diff --git a/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts b/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts index fd83bb5e..f26b66d8 100644 --- a/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts +++ b/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts @@ -24,10 +24,10 @@ type Payload = FromSchema; export default class GoCQHTTPGetGroupMsgHistory extends BaseAction { actionName = ActionName.GoCQHTTP_GetGroupMsgHistory; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; //处理参数 const isReverseOrder = payload.reverseOrder || true; const MsgCount = +(payload.count ?? 20); @@ -48,7 +48,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction this.OneBotContext.apiContext.MsgApi.parseMessage(msg))) + msgList.map(msg => this.obContext.apiContext.MsgApi.parseMessage(msg))) ).filter(msg => msg !== undefined); return { 'messages': ob11MsgList }; } diff --git a/src/onebot/action/go-cqhttp/GetOnlineClient.ts b/src/onebot/action/go-cqhttp/GetOnlineClient.ts index be9485f9..ec45747b 100644 --- a/src/onebot/action/go-cqhttp/GetOnlineClient.ts +++ b/src/onebot/action/go-cqhttp/GetOnlineClient.ts @@ -15,7 +15,7 @@ export class GetOnlineClient extends BaseAction> { async _handle(payload: void) { //注册监听 - const NTQQSystemApi = this.CoreContext.apis.SystemApi; + const NTQQSystemApi = this.core.apis.SystemApi; NTQQSystemApi.getOnlineDev(); await sleep(500); diff --git a/src/onebot/action/go-cqhttp/GetStrangerInfo.ts b/src/onebot/action/go-cqhttp/GetStrangerInfo.ts index 47ca29ec..4f6a01a1 100644 --- a/src/onebot/action/go-cqhttp/GetStrangerInfo.ts +++ b/src/onebot/action/go-cqhttp/GetStrangerInfo.ts @@ -19,7 +19,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction { - const NTQQUserApi = this.CoreContext.apis.UserApi; + const NTQQUserApi = this.core.apis.UserApi; const user_id = payload.user_id.toString(); const extendData = await NTQQUserApi.getUserDetailInfoByUinV2(user_id); const uid = (await NTQQUserApi.getUidByUinV2(user_id))!; diff --git a/src/onebot/action/go-cqhttp/QuickAction.ts b/src/onebot/action/go-cqhttp/QuickAction.ts index 07aa982a..3846f9e3 100644 --- a/src/onebot/action/go-cqhttp/QuickAction.ts +++ b/src/onebot/action/go-cqhttp/QuickAction.ts @@ -12,7 +12,7 @@ export class GoCQHTTPHandleQuickAction extends BaseAction { actionName = ActionName.GoCQHTTP_HandleQuickAction; async _handle(payload: Payload): Promise { - handleQuickOperation(this.CoreContext, this.OneBotContext, payload.context, payload.operation).then().catch(this.CoreContext.context.logger.logError); + handleQuickOperation(this.core, this.obContext, payload.context, payload.operation).then().catch(this.core.context.logger.logError); return null; } } diff --git a/src/onebot/action/go-cqhttp/SendGroupNotice.ts b/src/onebot/action/go-cqhttp/SendGroupNotice.ts index 8d411a38..6a5a52bc 100644 --- a/src/onebot/action/go-cqhttp/SendGroupNotice.ts +++ b/src/onebot/action/go-cqhttp/SendGroupNotice.ts @@ -22,7 +22,7 @@ export class SendGroupNotice extends BaseAction { actionName = ActionName.GoCQHTTP_SendGroupNotice; async _handle(payload: Payload) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; let UploadImage: { id: string, width: number, height: number } | undefined = undefined; if (payload.image) { //公告图逻辑 @@ -31,7 +31,7 @@ export class SendGroupNotice extends BaseAction { path, isLocal, success, - } = (await uri2local(this.CoreContext.NapCatTempPath, payload.image)); + } = (await uri2local(this.core.NapCatTempPath, payload.image)); if (!success) { throw `群公告${payload.image}设置失败,image字段可能格式不正确`; } diff --git a/src/onebot/action/go-cqhttp/SetGroupPortrait.ts b/src/onebot/action/go-cqhttp/SetGroupPortrait.ts index 4da22822..7828a28c 100644 --- a/src/onebot/action/go-cqhttp/SetGroupPortrait.ts +++ b/src/onebot/action/go-cqhttp/SetGroupPortrait.ts @@ -27,8 +27,8 @@ export default class SetGroupPortrait extends BaseAction { } async _handle(payload: Payload): Promise { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; - const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file)); + const NTQQGroupApi = this.core.apis.GroupApi; + const { path, isLocal, errMsg, success } = (await uri2local(this.core.NapCatTempPath, payload.file)); if (!success) { throw `头像${payload.file}设置失败,file字段可能格式不正确`; } diff --git a/src/onebot/action/go-cqhttp/SetQQProfile.ts b/src/onebot/action/go-cqhttp/SetQQProfile.ts index 27c0089c..3f0580a6 100644 --- a/src/onebot/action/go-cqhttp/SetQQProfile.ts +++ b/src/onebot/action/go-cqhttp/SetQQProfile.ts @@ -16,11 +16,11 @@ type Payload = FromSchema; export class SetQQProfile extends BaseAction { actionName = ActionName.SetQQProfile; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const self = this.CoreContext.selfInfo; + const NTQQUserApi = this.core.apis.UserApi; + const self = this.core.selfInfo; const OldProfile = await NTQQUserApi.getUserDetailInfo(self.uid); const ret = await NTQQUserApi.modifySelfProfile({ nick: payload.nickname, diff --git a/src/onebot/action/go-cqhttp/UploadGroupFile.ts b/src/onebot/action/go-cqhttp/UploadGroupFile.ts index e7e8cc5b..41cde7d7 100644 --- a/src/onebot/action/go-cqhttp/UploadGroupFile.ts +++ b/src/onebot/action/go-cqhttp/UploadGroupFile.ts @@ -22,19 +22,19 @@ type Payload = FromSchema; export default class GoCQHTTPUploadGroupFile extends BaseAction { actionName = ActionName.GoCQHTTP_UploadGroupFile; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { let file = payload.file; if (fs.existsSync(file)) { file = `file://${file}`; } - const downloadResult = await uri2local(this.CoreContext.NapCatTempPath, file); + const downloadResult = await uri2local(this.core.NapCatTempPath, file); if (!downloadResult.success) { throw new Error(downloadResult.errMsg); } - const sendFileEle = await this.CoreContext.apis.FileApi.createValidSendFileElement(downloadResult.path, payload.name, payload.folder_id); - await sendMsg(this.CoreContext, { + const sendFileEle = await this.core.apis.FileApi.createValidSendFileElement(downloadResult.path, payload.name, payload.folder_id); + await sendMsg(this.core, { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString(), }, [sendFileEle], [], true); diff --git a/src/onebot/action/go-cqhttp/UploadPrivateFile.ts b/src/onebot/action/go-cqhttp/UploadPrivateFile.ts index c777e197..f2e7b34f 100644 --- a/src/onebot/action/go-cqhttp/UploadPrivateFile.ts +++ b/src/onebot/action/go-cqhttp/UploadPrivateFile.ts @@ -20,11 +20,11 @@ type Payload = FromSchema; export default class GoCQHTTPUploadPrivateFile extends BaseAction { actionName = ActionName.GOCQHTTP_UploadPrivateFile; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async getPeer(payload: Payload): Promise { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQFriendApi = this.CoreContext.apis.FriendApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQFriendApi = this.core.apis.FriendApi; if (payload.user_id) { const peerUid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); if (!peerUid) { @@ -42,12 +42,12 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction if (fs.existsSync(file)) { file = `file://${file}`; } - const downloadResult = await uri2local(this.CoreContext.NapCatTempPath, file); + const downloadResult = await uri2local(this.core.NapCatTempPath, file); if (!downloadResult.success) { throw new Error(downloadResult.errMsg); } - const sendFileEle: SendFileElement = await this.CoreContext.apis.FileApi.createValidSendFileElement(downloadResult.path, payload.name); - await sendMsg(this.CoreContext, peer, [sendFileEle], [], true); + const sendFileEle: SendFileElement = await this.core.apis.FileApi.createValidSendFileElement(downloadResult.path, payload.name); + await sendMsg(this.core, peer, [sendFileEle], [], true); return null; } } diff --git a/src/onebot/action/group/DelEssenceMsg.ts b/src/onebot/action/group/DelEssenceMsg.ts index 001f178a..dde3781e 100644 --- a/src/onebot/action/group/DelEssenceMsg.ts +++ b/src/onebot/action/group/DelEssenceMsg.ts @@ -15,10 +15,10 @@ type Payload = FromSchema; export default class DelEssenceMsg extends BaseAction { actionName = ActionName.DelEssenceMsg; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString())); if (!msg) throw new Error('msg not found'); return await NTQQGroupApi.removeGroupEssence( diff --git a/src/onebot/action/group/DelGroupNotice.ts b/src/onebot/action/group/DelGroupNotice.ts index 4008244e..c91ac833 100644 --- a/src/onebot/action/group/DelGroupNotice.ts +++ b/src/onebot/action/group/DelGroupNotice.ts @@ -17,10 +17,10 @@ type Payload = FromSchema; export class DelGroupNotice extends BaseAction { actionName = ActionName.DelGroupNotice; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; const group = payload.group_id.toString(); const feedId = payload.feed_id; return await NTQQGroupApi.deleteGroupBulletin(group, feedId); diff --git a/src/onebot/action/group/GetGroupEssence.ts b/src/onebot/action/group/GetGroupEssence.ts index c17db16a..a54575f6 100644 --- a/src/onebot/action/group/GetGroupEssence.ts +++ b/src/onebot/action/group/GetGroupEssence.ts @@ -16,10 +16,10 @@ type Payload = FromSchema; export class GetGroupEssence extends BaseAction { actionName = ActionName.GoCQHTTP_GetEssenceMsg; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQWebApi = this.CoreContext.apis.WebApi; + const NTQQWebApi = this.core.apis.WebApi; const ret = await NTQQWebApi.getGroupEssenceMsg(payload.group_id.toString(), (payload.pages || "0").toString()); if (!ret) { throw new Error('获取失败'); diff --git a/src/onebot/action/group/GetGroupInfo.ts b/src/onebot/action/group/GetGroupInfo.ts index fc069652..5b2f14cf 100644 --- a/src/onebot/action/group/GetGroupInfo.ts +++ b/src/onebot/action/group/GetGroupInfo.ts @@ -16,10 +16,10 @@ type Payload = FromSchema; class GetGroupInfo extends BaseAction { actionName = ActionName.GetGroupInfo; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString()); if (!group) throw `群${payload.group_id}不存在`; return OB11Constructor.group(group); diff --git a/src/onebot/action/group/GetGroupList.ts b/src/onebot/action/group/GetGroupList.ts index 04b93413..72e63313 100644 --- a/src/onebot/action/group/GetGroupList.ts +++ b/src/onebot/action/group/GetGroupList.ts @@ -16,10 +16,10 @@ type Payload = FromSchema; class GetGroupList extends BaseAction { actionName = ActionName.GetGroupList; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; const groupList: Group[] = await NTQQGroupApi.getGroups(typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache); return OB11Constructor.groups(groupList); } diff --git a/src/onebot/action/group/GetGroupMemberInfo.ts b/src/onebot/action/group/GetGroupMemberInfo.ts index 5764e1d4..5f02c28f 100644 --- a/src/onebot/action/group/GetGroupMemberInfo.ts +++ b/src/onebot/action/group/GetGroupMemberInfo.ts @@ -19,11 +19,11 @@ type Payload = FromSchema; class GetGroupMemberInfo extends BaseAction { actionName = ActionName.GetGroupMemberInfo; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQGroupApi = this.core.apis.GroupApi; const isNocache = typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache; const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); if (!uid) throw new Error (`Uin2Uid Error ${payload.user_id}不存在`); @@ -33,14 +33,14 @@ class GetGroupMemberInfo extends BaseAction { ]); if (member.status !== 'fulfilled') throw new Error (`群(${payload.group_id})成员${payload.user_id}不存在 ${member.reason}`); if (info.status === 'fulfilled') { - this.CoreContext.context.logger.logDebug("群成员详细信息结果", info.value); + this.core.context.logger.logDebug("群成员详细信息结果", info.value); Object.assign(member, info.value); } else { - this.CoreContext.context.logger.logDebug(`获取群成员详细信息失败, 只能返回基础信息 ${info.reason}`); + this.core.context.logger.logDebug(`获取群成员详细信息失败, 只能返回基础信息 ${info.reason}`); } const date = Math.round(Date.now() / 1000); const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member.value as GroupMember); - const Member = await this.CoreContext.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id); + const Member = await this.core.apis.GroupApi.getGroupMember(payload.group_id.toString(), retMember.user_id); retMember.last_sent_time = parseInt(Member?.lastSpeakTime || date.toString()); retMember.join_time = parseInt(Member?.joinTime || date.toString()); return retMember; diff --git a/src/onebot/action/group/GetGroupMemberList.ts b/src/onebot/action/group/GetGroupMemberList.ts index ab0015c0..856e3ff8 100644 --- a/src/onebot/action/group/GetGroupMemberList.ts +++ b/src/onebot/action/group/GetGroupMemberList.ts @@ -17,11 +17,11 @@ type Payload = FromSchema; class GetGroupMemberList extends BaseAction { actionName = ActionName.GetGroupMemberList; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; - const NTQQWebApi = this.CoreContext.apis.WebApi; + const NTQQGroupApi = this.core.apis.GroupApi; + const NTQQWebApi = this.core.apis.WebApi; const groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString()); const groupMembersArr = Array.from(groupMembers.values()); @@ -39,7 +39,7 @@ class GetGroupMemberList extends BaseAction { MemberMap.set(_groupMembers[i].user_id, _groupMembers[i]); } - const selfRole = groupMembers.get(this.CoreContext.selfInfo.uid)?.role; + const selfRole = groupMembers.get(this.core.selfInfo.uid)?.role; const isPrivilege = selfRole === 3 || selfRole === 4; _groupMembers.forEach(item => { diff --git a/src/onebot/action/group/GetGroupNotice.ts b/src/onebot/action/group/GetGroupNotice.ts index 1cbab158..22b18145 100644 --- a/src/onebot/action/group/GetGroupNotice.ts +++ b/src/onebot/action/group/GetGroupNotice.ts @@ -31,10 +31,10 @@ type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed; export class GetGroupNotice extends BaseAction { actionName = ActionName.GoCQHTTP_GetGroupNotice; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQWebApi = this.CoreContext.apis.WebApi; + const NTQQWebApi = this.core.apis.WebApi; const group = payload.group_id.toString(); const ret = await NTQQWebApi.getGroupNotice(group); diff --git a/src/onebot/action/group/GetGroupSystemMsg.ts b/src/onebot/action/group/GetGroupSystemMsg.ts index bb465e82..222eb410 100644 --- a/src/onebot/action/group/GetGroupSystemMsg.ts +++ b/src/onebot/action/group/GetGroupSystemMsg.ts @@ -16,8 +16,8 @@ export class GetGroupSystemMsg extends BaseAction { actionName = ActionName.GetGroupSystemMsg; async _handle(payload: void) { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQGroupApi = this.core.apis.GroupApi; // 默认10条 该api未完整实现 包括响应数据规范化 类型规范化 const SingleScreenNotifies = await NTQQGroupApi.getSingleScreenNotifies(10); const retData: any = { InvitedRequest: [], join_requests: [] }; diff --git a/src/onebot/action/group/SetEssenceMsg.ts b/src/onebot/action/group/SetEssenceMsg.ts index 1253f722..9a49db81 100644 --- a/src/onebot/action/group/SetEssenceMsg.ts +++ b/src/onebot/action/group/SetEssenceMsg.ts @@ -15,10 +15,10 @@ type Payload = FromSchema; export default class SetEssenceMsg extends BaseAction { actionName = ActionName.SetEssenceMsg; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString())); if (!msg) { throw new Error('msg not found'); diff --git a/src/onebot/action/group/SetGroupAddRequest.ts b/src/onebot/action/group/SetGroupAddRequest.ts index 3c2e05d2..c043518d 100644 --- a/src/onebot/action/group/SetGroupAddRequest.ts +++ b/src/onebot/action/group/SetGroupAddRequest.ts @@ -17,10 +17,10 @@ type Payload = FromSchema; export default class SetGroupAddRequest extends BaseAction { actionName = ActionName.SetGroupAddRequest; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; const flag = payload.flag.toString(); const approve = payload.approve?.toString() !== 'false'; await NTQQGroupApi.handleGroupRequest(flag, diff --git a/src/onebot/action/group/SetGroupAdmin.ts b/src/onebot/action/group/SetGroupAdmin.ts index db0d2c3b..5b5f8b9d 100644 --- a/src/onebot/action/group/SetGroupAdmin.ts +++ b/src/onebot/action/group/SetGroupAdmin.ts @@ -17,12 +17,12 @@ type Payload = FromSchema; export default class SetGroupAdmin extends BaseAction { actionName = ActionName.SetGroupAdmin; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const enable = typeof payload.enable === 'string' ? payload.enable === 'true' : !!payload.enable; - const NTQQGroupApi = this.CoreContext.apis.GroupApi; - const NTQQUserApi = this.CoreContext.apis.UserApi; + const NTQQGroupApi = this.core.apis.GroupApi; + const NTQQUserApi = this.core.apis.UserApi; const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); if (!uid) throw new Error('get Uid Error'); await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, enable ? GroupMemberRole.admin : GroupMemberRole.normal); diff --git a/src/onebot/action/group/SetGroupBan.ts b/src/onebot/action/group/SetGroupBan.ts index 9ba52f46..5d2a4178 100644 --- a/src/onebot/action/group/SetGroupBan.ts +++ b/src/onebot/action/group/SetGroupBan.ts @@ -16,11 +16,11 @@ type Payload = FromSchema; export default class SetGroupBan extends BaseAction { actionName = ActionName.SetGroupBan; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; - const NTQQUserApi = this.CoreContext.apis.UserApi; + const NTQQGroupApi = this.core.apis.GroupApi; + const NTQQUserApi = this.core.apis.UserApi; const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); if (!uid) throw new Error('uid error'); await NTQQGroupApi.banMember(payload.group_id.toString(), diff --git a/src/onebot/action/group/SetGroupCard.ts b/src/onebot/action/group/SetGroupCard.ts index b1d518e3..fb7e558e 100644 --- a/src/onebot/action/group/SetGroupCard.ts +++ b/src/onebot/action/group/SetGroupCard.ts @@ -16,10 +16,10 @@ type Payload = FromSchema; export default class SetGroupCard extends BaseAction { actionName = ActionName.SetGroupCard; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; const member = await NTQQGroupApi.getGroupMember(payload.group_id.toString(), payload.user_id.toString()); member && await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || ''); return null; diff --git a/src/onebot/action/group/SetGroupKick.ts b/src/onebot/action/group/SetGroupKick.ts index 5546985d..f5977bcd 100644 --- a/src/onebot/action/group/SetGroupKick.ts +++ b/src/onebot/action/group/SetGroupKick.ts @@ -17,11 +17,11 @@ type Payload = FromSchema; export default class SetGroupKick extends BaseAction { actionName = ActionName.SetGroupKick; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; - const NTQQUserApi = this.CoreContext.apis.UserApi; + const NTQQGroupApi = this.core.apis.GroupApi; + const NTQQUserApi = this.core.apis.UserApi; const rejectReq = payload.reject_add_request?.toString() == 'true'; const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); if (!uid) throw new Error('get Uid Error'); diff --git a/src/onebot/action/group/SetGroupLeave.ts b/src/onebot/action/group/SetGroupLeave.ts index 4d3b1153..64841cea 100644 --- a/src/onebot/action/group/SetGroupLeave.ts +++ b/src/onebot/action/group/SetGroupLeave.ts @@ -14,10 +14,10 @@ const SchemaData = { type Payload = FromSchema; export default class SetGroupLeave extends BaseAction { actionName = ActionName.SetGroupLeave; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; await NTQQGroupApi.quitGroup(payload.group_id.toString()); } } diff --git a/src/onebot/action/group/SetGroupName.ts b/src/onebot/action/group/SetGroupName.ts index 9009c587..12297d7d 100644 --- a/src/onebot/action/group/SetGroupName.ts +++ b/src/onebot/action/group/SetGroupName.ts @@ -14,10 +14,10 @@ const SchemaData = { type Payload = FromSchema; export default class SetGroupName extends BaseAction { actionName = ActionName.SetGroupName; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name); return null; } diff --git a/src/onebot/action/group/SetGroupWholeBan.ts b/src/onebot/action/group/SetGroupWholeBan.ts index e0d3293b..0b286e00 100644 --- a/src/onebot/action/group/SetGroupWholeBan.ts +++ b/src/onebot/action/group/SetGroupWholeBan.ts @@ -15,11 +15,11 @@ type Payload = FromSchema; export default class SetGroupWholeBan extends BaseAction { actionName = ActionName.SetGroupWholeBan; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const enable = payload.enable?.toString() !== 'false'; - const NTQQGroupApi = this.CoreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; await NTQQGroupApi.banGroup(payload.group_id.toString(), enable); return null; } diff --git a/src/onebot/action/index.ts b/src/onebot/action/index.ts index f2d4ced2..2923dd4c 100644 --- a/src/onebot/action/index.ts +++ b/src/onebot/action/index.ts @@ -84,93 +84,93 @@ import { DelGroupNotice } from './group/DelGroupNotice'; export type ActionMap = Map>; -export function createActionMap(onebotContext: NapCatOneBot11Adapter, coreContext: NapCatCore): ActionMap { +export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore): ActionMap { const actionHandlers = [ - new FetchEmojiLike(onebotContext, coreContext), - new GetFile(onebotContext, coreContext), - new SetQQProfile(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(obContext, core), + new GetFile(obContext, core), + new SetQQProfile(obContext, core), + new ShareGroupEx(obContext, core), + new SharePeer(obContext, core), + new CreateCollection(obContext, core), + new SetLongNick(obContext, core), + new ForwardFriendSingleMsg(obContext, core), + new ForwardGroupSingleMsg(obContext, core), + new MarkGroupMsgAsRead(obContext, core), + new MarkPrivateMsgAsRead(obContext, core), + new SetQQAvatar(obContext, core), + new TranslateEnWordToZn(obContext, core), + new GetGroupFileCount(obContext, core), + new GetGroupFileList(obContext, core), + new SetGroupFileFolder(obContext, core), + new DelGroupFile(obContext, core), + new DelGroupFileFolder(obContext, core), // 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(obContext, core), + new GetMsg(obContext, core), + new GetLoginInfo(obContext, core), + new GetFriendList(obContext, core), + new GetGroupList(obContext, core), + new GetGroupInfo(obContext, core), + new GetGroupMemberList(obContext, core), + new GetGroupMemberInfo(obContext, core), + new SendGroupMsg(obContext, core), + new SendPrivateMsg(obContext, core), + new SendMsg(obContext, core), + new DeleteMsg(obContext, core), + new SetGroupAddRequest(obContext, core), + new SetFriendAddRequest(obContext, core), + new SetGroupLeave(obContext, core), + new GetVersionInfo(obContext, core), + new CanSendRecord(obContext, core), + new CanSendImage(obContext, core), + new GetStatus(obContext, core), + new SetGroupWholeBan(obContext, core), + new SetGroupBan(obContext, core), + new SetGroupKick(obContext, core), + new SetGroupAdmin(obContext, core), + new SetGroupName(obContext, core), + new SetGroupCard(obContext, core), + new GetImage(obContext, core), + new GetRecord(obContext, core), + new SetMsgEmojiLike(obContext, core), + new GetCookies(obContext, core), + new SetOnlineStatus(obContext, core), + new GetRobotUinRange(obContext, core), + new GetFriendWithCategory(obContext, core), //以下为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 SetGroupPortrait(onebotContext, coreContext), - new FetchCustomFace(onebotContext, coreContext), - new GoCQHTTPUploadPrivateFile(onebotContext, coreContext), - new GetGuildProfile(onebotContext, coreContext), - new SetModelShow(onebotContext, coreContext), - new SetInputStatus(onebotContext, coreContext), - new GetCSRF(onebotContext, coreContext), - new DelGroupNotice(onebotContext, coreContext), + new GetOnlineClient(obContext, core), + new OCRImage(obContext, core), + new IOCRImage(obContext, core), + new GetGroupHonorInfo(obContext, core), + new SendGroupNotice(obContext, core), + new GetGroupNotice(obContext, core), + new GetGroupEssence(obContext, core), + new GoCQHTTPSendForwardMsg(obContext, core), + new GoCQHTTPSendGroupForwardMsg(obContext, core), + new GoCQHTTPSendPrivateForwardMsg(obContext, core), + new GoCQHTTPGetStrangerInfo(obContext, core), + new GoCQHTTPDownloadFile(obContext, core), + new GetGuildList(obContext, core), + new GoCQHTTPMarkMsgAsRead(obContext, core), + new GoCQHTTPUploadGroupFile(obContext, core), + new GoCQHTTPGetGroupMsgHistory(obContext, core), + new GoCQHTTPGetForwardMsgAction(obContext, core), + new GetFriendMsgHistory(obContext, core), + new GoCQHTTPHandleQuickAction(obContext, core), + new GetGroupSystemMsg(obContext, core), + new DelEssenceMsg(obContext, core), + new SetEssenceMsg(obContext, core), + new GetRecentContact(obContext, core), + new MarkAllMsgAsRead(obContext, core), + new GetProfileLike(obContext, core), + new SetGroupPortrait(obContext, core), + new FetchCustomFace(obContext, core), + new GoCQHTTPUploadPrivateFile(obContext, core), + new GetGuildProfile(obContext, core), + new SetModelShow(obContext, core), + new SetInputStatus(obContext, core), + new GetCSRF(obContext, core), + new DelGroupNotice(obContext, core), ]; const actionMap = new Map(); for (const action of actionHandlers) { diff --git a/src/onebot/action/msg/DeleteMsg.ts b/src/onebot/action/msg/DeleteMsg.ts index a7c6fece..e8c31a6c 100644 --- a/src/onebot/action/msg/DeleteMsg.ts +++ b/src/onebot/action/msg/DeleteMsg.ts @@ -21,13 +21,13 @@ type Payload = FromSchema; class DeleteMsg extends BaseAction { actionName = ActionName.DeleteMsg; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id)); if (msg) { - const ret = this.CoreContext.eventWrapper.RegisterListen + const ret = this.core.eventWrapper.RegisterListen ( 'NodeIKernelMsgListener/onMsgInfoListUpdate', 1, diff --git a/src/onebot/action/msg/ForwardSingleMsg.ts b/src/onebot/action/msg/ForwardSingleMsg.ts index 048470bb..7de1c875 100644 --- a/src/onebot/action/msg/ForwardSingleMsg.ts +++ b/src/onebot/action/msg/ForwardSingleMsg.ts @@ -18,7 +18,7 @@ type Payload = FromSchema; class ForwardSingleMsg extends BaseAction { protected async getTargetPeer(payload: Payload): Promise { - const NTQQUserApi = this.CoreContext.apis.UserApi; + const NTQQUserApi = this.core.apis.UserApi; if (payload.user_id) { const peerUid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); if (!peerUid) { @@ -30,7 +30,7 @@ class ForwardSingleMsg extends BaseAction { } async _handle(payload: Payload): Promise { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString())); if (!msg) { throw new Error(`无法找到消息${payload.message_id}`); @@ -48,11 +48,11 @@ class ForwardSingleMsg extends BaseAction { } export class ForwardFriendSingleMsg extends ForwardSingleMsg { - PayloadSchema = SchemaData; + payloadSchema = SchemaData; actionName = ActionName.ForwardFriendSingleMsg; } export class ForwardGroupSingleMsg extends ForwardSingleMsg { - PayloadSchema = SchemaData; + payloadSchema = SchemaData; actionName = ActionName.ForwardGroupSingleMsg; } diff --git a/src/onebot/action/msg/GetMsg.ts b/src/onebot/action/msg/GetMsg.ts index 02f2a9a9..b36443c5 100644 --- a/src/onebot/action/msg/GetMsg.ts +++ b/src/onebot/action/msg/GetMsg.ts @@ -19,10 +19,10 @@ type Payload = FromSchema; class GetMsg extends BaseAction { actionName = ActionName.GetMsg; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; // log("history msg ids", Object.keys(msgHistory)); if (!payload.message_id) { throw Error('参数message_id不能为空'); @@ -36,7 +36,7 @@ class GetMsg extends BaseAction { const msg = await NTQQMsgApi.getMsgsByMsgId( peer, [msgIdWithPeer?.MsgId || payload.message_id.toString()]); - const retMsg = await this.OneBotContext.apiContext.MsgApi.parseMessage(msg.msgList[0], 'array'); + const retMsg = await this.obContext.apiContext.MsgApi.parseMessage(msg.msgList[0], 'array'); if (!retMsg) throw Error('消息为空'); try { retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!; diff --git a/src/onebot/action/msg/MarkMsgAsRead.ts b/src/onebot/action/msg/MarkMsgAsRead.ts index adc21da9..16f733b9 100644 --- a/src/onebot/action/msg/MarkMsgAsRead.ts +++ b/src/onebot/action/msg/MarkMsgAsRead.ts @@ -15,8 +15,8 @@ type PlayloadType = FromSchema; class MarkMsgAsRead extends BaseAction { async getPeer(payload: PlayloadType): Promise { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQFriendApi = this.CoreContext.apis.FriendApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQFriendApi = this.core.apis.FriendApi; if (payload.user_id) { const peerUid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString()); if (!peerUid) { @@ -32,7 +32,7 @@ class MarkMsgAsRead extends BaseAction { } async _handle(payload: PlayloadType): Promise { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; // 调用API const ret = await NTQQMsgApi.setMsgRead(await this.getPeer(payload)); if (ret.result != 0) { @@ -44,12 +44,12 @@ class MarkMsgAsRead extends BaseAction { // 以下为非标准实现 export class MarkPrivateMsgAsRead extends MarkMsgAsRead { - PayloadSchema = SchemaData; + payloadSchema = SchemaData; actionName = ActionName.MarkPrivateMsgAsRead; } export class MarkGroupMsgAsRead extends MarkMsgAsRead { - PayloadSchema = SchemaData; + payloadSchema = SchemaData; actionName = ActionName.MarkGroupMsgAsRead; } @@ -70,7 +70,7 @@ export class MarkAllMsgAsRead extends BaseAction { actionName = ActionName._MarkAllMsgAsRead; async _handle(payload: Payload): Promise { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; await NTQQMsgApi.markallMsgAsRead(); return null; } diff --git a/src/onebot/action/msg/SendMsg.ts b/src/onebot/action/msg/SendMsg.ts index 51e41a75..701376bc 100644 --- a/src/onebot/action/msg/SendMsg.ts +++ b/src/onebot/action/msg/SendMsg.ts @@ -32,9 +32,9 @@ export function normalize(message: OB11MessageMixType, autoEscape = false): OB11 ) : Array.isArray(message) ? message : [message]; } -export async function sendMsg(coreContext: NapCatCore, peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) { - const NTQQMsgApi = coreContext.apis.MsgApi; - const logger = coreContext.context.logger; +export async function sendMsg(core: NapCatCore, peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) { + const NTQQMsgApi = core.apis.MsgApi; + const logger = core.context.logger; if (!sendElements.length) { throw new Error('消息体无法解析, 请检查是否发送了不支持的消息类型'); } @@ -80,13 +80,13 @@ export async function sendMsg(coreContext: NapCatCore, peer: Peer, sendElements: return returnMsg; } -async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg, contextMode: ContextMode): Promise { +async function createContext(core: NapCatCore, payload: OB11PostSendMsg, contextMode: ContextMode): Promise { // This function determines the type of message by the existence of user_id / group_id, // not message_type. // This redundant design of Ob11 here should be blamed. - const NTQQFriendApi = coreContext.apis.FriendApi; - const NTQQUserApi = coreContext.apis.UserApi; - const NTQQMsgApi = coreContext.apis.MsgApi; + const NTQQFriendApi = core.apis.FriendApi; + const NTQQUserApi = core.apis.UserApi; + const NTQQMsgApi = core.apis.MsgApi; if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) { return { chatType: ChatType.KCHATTYPEGROUP, @@ -149,7 +149,7 @@ export class SendMsg extends BaseAction { }; } if (payload.user_id && payload.message_type !== 'group') { - // const uid = await this.CoreContext.apis.UserApi.getUidByUinV2(payload.user_id.toString()); + // const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString()); // const isBuddy = await NTQQFriendApi.isBuddy(uid!); // if (!isBuddy) { } } @@ -159,7 +159,7 @@ export class SendMsg extends BaseAction { async _handle(payload: OB11PostSendMsg): Promise<{ message_id: number }> { if (payload.message_type === 'group') this.contextMode = ContextMode.Group; if (payload.message_type === 'private') this.contextMode = ContextMode.Private; - const peer = await createContext(this.CoreContext, payload, this.contextMode); + const peer = await createContext(this.core, payload, this.contextMode); const messages = normalize( payload.message, @@ -187,20 +187,20 @@ export class SendMsg extends BaseAction { } // log("send msg:", peer, sendElements) - const { sendElements, deleteAfterSentFiles } = await this.OneBotContext.apiContext.MsgApi + const { sendElements, deleteAfterSentFiles } = await this.obContext.apiContext.MsgApi .createSendElements(messages, peer); - const returnMsg = await sendMsg(this.CoreContext, peer, sendElements, deleteAfterSentFiles); + const returnMsg = await sendMsg(this.core, peer, sendElements, deleteAfterSentFiles); return { message_id: returnMsg!.id! }; } private async handleForwardedNodes(destPeer: Peer, messageNodes: OB11MessageNode[]): Promise { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const selfPeer = { chatType: ChatType.KCHATTYPEC2C, - peerUid: this.CoreContext.selfInfo.uid, + peerUid: this.core.selfInfo.uid, }; let nodeMsgIds: string[] = []; - const logger = this.CoreContext.context.logger; + const logger = this.core.context.logger; for (const messageNode of messageNodes) { const nodeId = messageNode.data.id; if (nodeId) { @@ -230,7 +230,7 @@ export class SendMsg extends BaseAction { //完成子卡片生成跳过后续 continue; } - const { sendElements } = await this.OneBotContext.apiContext.MsgApi + const { sendElements } = await this.obContext.apiContext.MsgApi .createSendElements(OB11Data, destPeer); //拆分消息 const MixElement = sendElements.filter(element => element.elementType !== ElementType.FILE && element.elementType !== ElementType.VIDEO); @@ -238,7 +238,7 @@ export class SendMsg extends BaseAction { const AllElement: SendMessageElement[][] = [MixElement, ...SingleElement].filter(e => e !== undefined && e.length !== 0); const MsgNodeList: Promise[] = []; for (const sendElementsSplitElement of AllElement) { - MsgNodeList.push(sendMsg(this.CoreContext, selfPeer, sendElementsSplitElement, [], true).catch(_ => undefined)); + MsgNodeList.push(sendMsg(this.core, selfPeer, sendElementsSplitElement, [], true).catch(_ => undefined)); } (await Promise.allSettled(MsgNodeList)).map((result) => { if (result.status === 'fulfilled' && result.value) { @@ -272,7 +272,7 @@ export class SendMsg extends BaseAction { let retMsgIds: string[] = []; if (needSendSelf) { for (const [, msg] of nodeMsgArray.entries()) { - if (msg.peerUid === this.CoreContext.selfInfo.uid) { + if (msg.peerUid === this.core.selfInfo.uid) { retMsgIds.push(msg.msgId); continue; } @@ -295,10 +295,10 @@ export class SendMsg extends BaseAction { async cloneMsg(msg: RawMessage): Promise { const selfPeer = { chatType: ChatType.KCHATTYPEC2C, - peerUid: this.CoreContext.selfInfo.uid, + peerUid: this.core.selfInfo.uid, }; - const logger = this.CoreContext.context.logger; - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const logger = this.core.context.logger; + const NTQQMsgApi = this.core.apis.MsgApi; //msg 为待克隆消息 const sendElements: SendMessageElement[] = []; diff --git a/src/onebot/action/msg/SetMsgEmojiLike.ts b/src/onebot/action/msg/SetMsgEmojiLike.ts index a7b49c37..79b50e71 100644 --- a/src/onebot/action/msg/SetMsgEmojiLike.ts +++ b/src/onebot/action/msg/SetMsgEmojiLike.ts @@ -16,10 +16,10 @@ type Payload = FromSchema; export class SetMsgEmojiLike extends BaseAction { actionName = ActionName.SetMsgEmojiLike; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString())); if (!msg) { throw new Error('msg not found'); diff --git a/src/onebot/action/system/GetLoginInfo.ts b/src/onebot/action/system/GetLoginInfo.ts index 9f9ce789..6d0e9aac 100644 --- a/src/onebot/action/system/GetLoginInfo.ts +++ b/src/onebot/action/system/GetLoginInfo.ts @@ -7,7 +7,7 @@ class GetLoginInfo extends BaseAction { actionName = ActionName.GetLoginInfo; async _handle(payload: null) { - return OB11Constructor.selfInfo(this.CoreContext.selfInfo); + return OB11Constructor.selfInfo(this.core.selfInfo); } } diff --git a/src/onebot/action/system/GetStatus.ts b/src/onebot/action/system/GetStatus.ts index 4be3c2ef..e543b8f6 100644 --- a/src/onebot/action/system/GetStatus.ts +++ b/src/onebot/action/system/GetStatus.ts @@ -6,7 +6,7 @@ export default class GetStatus extends BaseAction { async _handle(payload: any): Promise { return { - online: !!this.CoreContext.selfInfo.online, + online: !!this.core.selfInfo.online, good: true, stat: {}, }; diff --git a/src/onebot/action/user/GetCookies.ts b/src/onebot/action/user/GetCookies.ts index 147b49db..546d2ad6 100644 --- a/src/onebot/action/user/GetCookies.ts +++ b/src/onebot/action/user/GetCookies.ts @@ -19,11 +19,11 @@ type Payload = FromSchema; export class GetCookies extends BaseAction { actionName = ActionName.GetCookies; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQWebApi = this.CoreContext.apis.WebApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQWebApi = this.core.apis.WebApi; // if (!payload.domain) { // throw new Error('缺少参数 domain'); // } diff --git a/src/onebot/action/user/GetFriendList.ts b/src/onebot/action/user/GetFriendList.ts index 1de6fc86..bfa125b8 100644 --- a/src/onebot/action/user/GetFriendList.ts +++ b/src/onebot/action/user/GetFriendList.ts @@ -15,11 +15,11 @@ const SchemaData = { type Payload = FromSchema; export default class GetFriendList extends BaseAction { actionName = ActionName.GetFriendList; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { //全新逻辑 - const NTQQFriendApi = this.CoreContext.apis.FriendApi; + const NTQQFriendApi = this.core.apis.FriendApi; return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(typeof payload.no_cache === 'string' ? payload.no_cache === 'true' : !!payload.no_cache)); } } diff --git a/src/onebot/action/user/GetRecentContact.ts b/src/onebot/action/user/GetRecentContact.ts index c46cf50e..54a49b49 100644 --- a/src/onebot/action/user/GetRecentContact.ts +++ b/src/onebot/action/user/GetRecentContact.ts @@ -13,17 +13,17 @@ type Payload = FromSchema; export default class GetRecentContact extends BaseAction { actionName = ActionName.GetRecentContact; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload) { - const NTQQUserApi = this.CoreContext.apis.UserApi; - const NTQQMsgApi = this.CoreContext.apis.MsgApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQMsgApi = this.core.apis.MsgApi; const ret = await NTQQUserApi.getRecentContactListSnapShot(+(payload.count || 10)); return await Promise.all(ret.info.changedList.map(async (t) => { const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]); if (FastMsg.msgList.length > 0) { //扩展ret.info.changedList - const lastestMsg = await this.OneBotContext.apiContext.MsgApi.parseMessage(FastMsg.msgList[0], 'array'); + const lastestMsg = await this.obContext.apiContext.MsgApi.parseMessage(FastMsg.msgList[0], 'array'); return { lastestMsg: lastestMsg, peerUin: t.peerUin, diff --git a/src/onebot/action/user/SendLike.ts b/src/onebot/action/user/SendLike.ts index 87d11e31..41f8210f 100644 --- a/src/onebot/action/user/SendLike.ts +++ b/src/onebot/action/user/SendLike.ts @@ -15,10 +15,10 @@ type Payload = FromSchema; export default class SendLike extends BaseAction { actionName = ActionName.SendLike; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQUserApi = this.CoreContext.apis.UserApi; + const NTQQUserApi = this.core.apis.UserApi; //logDebug('点赞参数', payload); try { const qq = payload.user_id.toString(); diff --git a/src/onebot/action/user/SetFriendAddRequest.ts b/src/onebot/action/user/SetFriendAddRequest.ts index b213cea4..7e535f60 100644 --- a/src/onebot/action/user/SetFriendAddRequest.ts +++ b/src/onebot/action/user/SetFriendAddRequest.ts @@ -16,10 +16,10 @@ type Payload = FromSchema; export default class SetFriendAddRequest extends BaseAction { actionName = ActionName.SetFriendAddRequest; - PayloadSchema = SchemaData; + payloadSchema = SchemaData; async _handle(payload: Payload): Promise { - const NTQQFriendApi = this.CoreContext.apis.FriendApi; + const NTQQFriendApi = this.core.apis.FriendApi; const approve = payload.approve?.toString() !== 'false'; await NTQQFriendApi.handleFriendRequest(payload.flag, approve); return null; diff --git a/src/onebot/api/friend.ts b/src/onebot/api/friend.ts index 6e909376..5a8513fd 100644 --- a/src/onebot/api/friend.ts +++ b/src/onebot/api/friend.ts @@ -5,15 +5,15 @@ import { OB11FriendPokeEvent } from '../event/notice/OB11PokeEvent'; export class OneBotFriendApi { obContext: NapCatOneBot11Adapter; - coreContext: NapCatCore; + core: NapCatCore; friendList: Map = new Map();//此处作为缓存 uin->info - constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore) { + constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) { this.obContext = obContext; - this.coreContext = coreContext; + this.core = core; } //使用前预先判断 busiId 1061 async parsePrivatePokeEvent(grayTipElement: GrayTipElement) { - const NTQQUserApi = this.coreContext.apis.UserApi; + const NTQQUserApi = this.core.apis.UserApi; const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr); let pokedetail: any[] = json.items; //筛选item带有uid的元素 @@ -21,7 +21,7 @@ export class OneBotFriendApi { //console.log("[NapCat] 群拍一拍 群:", pokedetail, parseInt(msg.peerUid), " ", await NTQQUserApi.getUinByUid(pokedetail[0].uid), "拍了拍", await NTQQUserApi.getUinByUid(pokedetail[1].uid)); if (pokedetail.length == 2) { return new OB11FriendPokeEvent( - this.coreContext, + this.core, parseInt((await NTQQUserApi.getUinByUidV2(pokedetail[0].uid))!), parseInt((await NTQQUserApi.getUinByUidV2(pokedetail[1].uid))!), pokedetail diff --git a/src/onebot/api/group.ts b/src/onebot/api/group.ts index b16883ce..04eae235 100644 --- a/src/onebot/api/group.ts +++ b/src/onebot/api/group.ts @@ -9,15 +9,15 @@ import { MessageUnique } from '@/common/utils/MessageUnique'; export class OneBotGroupApi { obContext: NapCatOneBot11Adapter; - coreContext: NapCatCore; + core: NapCatCore; GroupMemberList: Map = new Map();//此处作为缓存 group_id->memberUin->info - constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore) { + constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) { this.obContext = obContext; - this.coreContext = coreContext; + this.core = core; } async parseGroupBanEvent(GroupCode: string, grayTipElement: GrayTipElement) { const groupElement = grayTipElement?.groupElement; - const NTQQGroupApi = this.coreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; if (!groupElement?.shutUp) return undefined; const memberUid = groupElement.shutUp!.member.uid; const adminUid = groupElement.shutUp!.admin.uid; @@ -35,7 +35,7 @@ export class OneBotGroupApi { const adminUin = (await NTQQGroupApi.getGroupMember(GroupCode, adminUid))?.uin; if (memberUin && adminUin) { return new OB11GroupBanEvent( - this.coreContext, + this.core, parseInt(GroupCode), parseInt(memberUin), parseInt(adminUin), @@ -46,7 +46,7 @@ export class OneBotGroupApi { return undefined; } async parseGroupIncreaseEvent(GroupCode: string, grayTipElement: GrayTipElement) { - this.coreContext.context.logger.logDebug('收到新人被邀请进群消息', grayTipElement); + this.core.context.logger.logDebug('收到新人被邀请进群消息', grayTipElement); const xmlElement = grayTipElement.xmlElement; if (xmlElement?.content) { const regex = /jp="(\d+)"/g; @@ -61,7 +61,7 @@ export class OneBotGroupApi { if (matches.length === 2) { const [inviter, invitee] = matches; return new OB11GroupIncreaseEvent( - this.coreContext, + this.core, parseInt(GroupCode), parseInt(invitee), parseInt(inviter), @@ -72,7 +72,7 @@ export class OneBotGroupApi { return undefined; } async parseGroupMemberIncreaseEvent(GroupCode: string, grayTipElement: GrayTipElement) { - const NTQQGroupApi = this.coreContext.apis.GroupApi; + const NTQQGroupApi = this.core.apis.GroupApi; const groupElement = grayTipElement?.groupElement; if (!groupElement) return undefined; const member = await NTQQGroupApi.getGroupMemberV2(GroupCode, groupElement.memberUid); @@ -81,7 +81,7 @@ export class OneBotGroupApi { if (memberUin) { const operatorUin = adminMember?.uin || memberUin; return new OB11GroupIncreaseEvent( - this.coreContext, + this.core, parseInt(GroupCode), parseInt(memberUin), parseInt(operatorUin) @@ -90,16 +90,16 @@ export class OneBotGroupApi { return undefined; } async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) { - const NTQQGroupApi = this.coreContext.apis.GroupApi; - const NTQQUserApi = this.coreContext.apis.UserApi; + const NTQQGroupApi = this.core.apis.GroupApi; + const NTQQUserApi = this.core.apis.UserApi; const groupElement = grayTipElement?.groupElement; if (!groupElement) return undefined; const adminUin = (await NTQQGroupApi.getGroupMember(GroupCode, groupElement.adminUid))?.uin || (await NTQQUserApi.getUidByUinV2(groupElement.adminUid)); if (adminUin) { return new OB11GroupDecreaseEvent( - this.coreContext, + this.core, parseInt(GroupCode), - parseInt(this.coreContext.selfInfo.uin), + parseInt(this.core.selfInfo.uin), parseInt(adminUin), 'kick_me' ); @@ -107,12 +107,12 @@ export class OneBotGroupApi { return undefined; } async parseGroupEmjioLikeEvent(GroupCode: string, grayTipElement: GrayTipElement) { - const NTQQMsgApi = this.coreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const emojiLikeData = new fastXmlParser.XMLParser({ ignoreAttributes: false, attributeNamePrefix: '', }).parse(grayTipElement.xmlElement.content); - this.coreContext.context.logger.logDebug('收到表情回应我的消息', emojiLikeData); + this.core.context.logger.logDebug('收到表情回应我的消息', emojiLikeData); try { const senderUin = emojiLikeData.gtip.qq.jp; const msgSeq = emojiLikeData.gtip.url.msgseq; @@ -130,7 +130,7 @@ export class OneBotGroupApi { //console.log("表情回应消息长度检测", msgSeq, replyMsg.elements); if (!replyMsg) throw new Error('找不到回应消息'); return new OB11GroupMsgEmojiLikeEvent( - this.coreContext, + this.core, parseInt(GroupCode), parseInt(senderUin), MessageUnique.getShortIdByMsgId(replyMsg.msgId)!, @@ -140,7 +140,7 @@ export class OneBotGroupApi { }], ); } catch (e: any) { - this.coreContext.context.logger.logError('解析表情回应消息失败', e.stack); + this.core.context.logger.logError('解析表情回应消息失败', e.stack); } return undefined; } diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index fdda01cc..cf96ce2b 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -55,7 +55,7 @@ function keyCanBeParsed(key: string, parser: RawToOb11Converters): key is keyof export class OneBotMsgApi { obContext: NapCatOneBot11Adapter; - coreContext: NapCatCore; + core: NapCatCore; rawToOb11Converters: RawToOb11Converters = { textElement: async element => { @@ -78,7 +78,7 @@ export class OneBotMsgApi { const { atNtUid, /* content */ } = element; let atQQ = element.atUid; if (!atQQ || atQQ === '0') { - atQQ = await this.coreContext.apis.UserApi.getUinByUidV2(atNtUid); + atQQ = await this.core.apis.UserApi.getUinByUidV2(atNtUid); } if (atQQ) { qq = atQQ as `${number}`; @@ -102,18 +102,18 @@ export class OneBotMsgApi { file: element.fileName, sub_type: element.picSubType, file_id: UUIDConverter.encode(msg.peerUin, msg.msgId), - url: await this.coreContext.apis.FileApi.getImageUrl(element), + url: await this.core.apis.FileApi.getImageUrl(element), file_size: element.fileSize, }, }; } catch (e: any) { - this.coreContext.context.logger.logError('获取图片url失败', e.stack); + this.core.context.logger.logError('获取图片url失败', e.stack); return null; } }, fileElement: async (element, msg, elementWrapper) => { - await this.coreContext.apis.FileApi.addFileCache( + await this.core.apis.FileApi.addFileCache( { peerUid: msg.peerUid, chatType: msg.chatType, @@ -166,7 +166,7 @@ export class OneBotMsgApi { }, marketFaceElement: async (_, msg, elementWrapper) => { - await this.coreContext.apis.FileApi.addFileCache( + await this.core.apis.FileApi.addFileCache( { peerUid: msg.peerUid, chatType: msg.chatType, @@ -192,7 +192,7 @@ export class OneBotMsgApi { }, replyElement: async (element, msg) => { - const NTQQMsgApi = this.coreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const records = msg.records.find(msgRecord => msgRecord.msgId === element?.sourceMsgIdInRecords); const peer = { chatType: msg.chatType, @@ -200,7 +200,7 @@ export class OneBotMsgApi { guildId: '', }; if (!records) { - this.coreContext.context.logger.logError('获取不到引用的消息', element.replayMsgSeq); + this.core.context.logger.logError('获取不到引用的消息', element.replayMsgSeq); return null; } let replyMsg: RawMessage | undefined; @@ -221,7 +221,7 @@ export class OneBotMsgApi { // Attempt 3 const replyMsgList = (await NTQQMsgApi.getMsgExBySeq(peer, records.msgSeq)).msgList; if (replyMsgList.length < 1) { - this.coreContext.context.logger.logError('回复消息消息验证失败', element.replayMsgSeq); + this.core.context.logger.logError('回复消息消息验证失败', element.replayMsgSeq); return null; } replyMsg = replyMsgList.filter(e => e.msgSeq == records.msgSeq) @@ -242,7 +242,7 @@ export class OneBotMsgApi { }, videoElement: async (element, msg, elementWrapper) => { - const NTQQFileApi = this.coreContext.apis.FileApi; + const NTQQFileApi = this.core.apis.FileApi; //读取视频链接并兜底 let videoUrlWrappers: Awaited> | undefined; @@ -257,7 +257,7 @@ export class OneBotMsgApi { guildId: '0', }, msg.msgId, elementWrapper.elementId); } catch (error) { - this.coreContext.context.logger.logWarn('获取视频 URL 失败'); + this.core.context.logger.logWarn('获取视频 URL 失败'); } //读取在线URL @@ -305,7 +305,7 @@ export class OneBotMsgApi { }, pttElement: async (element, msg, elementWrapper) => { - await this.coreContext.apis.FileApi.addFileCache( + await this.core.apis.FileApi.addFileCache( { peerUid: msg.peerUid, chatType: msg.chatType, @@ -331,7 +331,7 @@ export class OneBotMsgApi { }, multiForwardMsgElement: async (_, msg) => { - const NTQQMsgApi = this.coreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const message_data: OB11MessageForward = { data: {} as any, type: OB11MessageDataType.forward, @@ -418,8 +418,8 @@ export class OneBotMsgApi { if (!context.peer || context.peer.chatType == ChatType.KCHATTYPEC2C) return undefined; if (atQQ === 'all') return at(atQQ, atQQ, AtType.atAll, '全体成员'); - const NTQQGroupApi = this.coreContext.apis.GroupApi; - const NTQQUserApi = this.coreContext.apis.UserApi; + const NTQQGroupApi = this.core.apis.GroupApi; + const NTQQUserApi = this.core.apis.UserApi; const atMember = await NTQQGroupApi.getGroupMember(context.peer.peerUid, atQQ); if (atMember) { return at(atQQ, atMember.uid, AtType.atUser, atMember.nick || atMember.cardName); @@ -433,10 +433,10 @@ export class OneBotMsgApi { [OB11MessageDataType.reply]: async ({ data: { id } }) => { const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id)); if (!replyMsgM) { - this.coreContext.context.logger.logWarn('回复消息不存在', id); + this.core.context.logger.logWarn('回复消息不存在', id); return undefined; } - const NTQQMsgApi = this.coreContext.apis.MsgApi; + const NTQQMsgApi = this.core.apis.MsgApi; const replyMsg = (await NTQQMsgApi.getMsgsByMsgId( replyMsgM.Peer, [replyMsgM.MsgId])).msgList[0]; return replyMsg ? @@ -497,7 +497,7 @@ export class OneBotMsgApi { // File service [OB11MessageDataType.image]: async (sendMsg, context) => { - const sendPicElement = await this.coreContext.apis.FileApi.createValidSendPicElement( + const sendPicElement = await this.core.apis.FileApi.createValidSendPicElement( (await this.handleOb11FileLikeMessage(sendMsg, context)).path, sendMsg.data.summary, sendMsg.data.sub_type, @@ -508,7 +508,7 @@ export class OneBotMsgApi { [OB11MessageDataType.file]: async (sendMsg, context) => { const { path, fileName } = await this.handleOb11FileLikeMessage(sendMsg, context); - return await this.coreContext.apis.FileApi.createValidSendFileElement(path, fileName); + return await this.core.apis.FileApi.createValidSendFileElement(path, fileName); }, [OB11MessageDataType.video]: async (sendMsg, context) => { @@ -516,17 +516,17 @@ export class OneBotMsgApi { let thumb = sendMsg.data.thumb; if (thumb) { - const uri2LocalRes = await uri2local(this.coreContext.NapCatTempPath, thumb); + const uri2LocalRes = await uri2local(this.core.NapCatTempPath, thumb); if (uri2LocalRes.success) thumb = uri2LocalRes.path; } - const videoEle = await this.coreContext.apis.FileApi.createValidSendVideoElement(path, fileName, thumb); + const videoEle = await this.core.apis.FileApi.createValidSendVideoElement(path, fileName, thumb); context.deleteAfterSentFiles.push(videoEle.videoElement.filePath); return videoEle; }, [OB11MessageDataType.voice]: async (sendMsg, context) => - this.coreContext.apis.FileApi.createValidSendPttElement( + this.core.apis.FileApi.createValidSendPttElement( (await this.handleOb11FileLikeMessage(sendMsg, context)).path), [OB11MessageDataType.json]: async ({ data: { data } }) => ({ @@ -584,24 +584,24 @@ export class OneBotMsgApi { // 保留, 直到...找到更好的解决方案 if (data.type === 'custom') { if (!data.url) { - this.coreContext.context.logger.logError('自定义音卡缺少参数url'); + this.core.context.logger.logError('自定义音卡缺少参数url'); return undefined; } if (!data.audio) { - this.coreContext.context.logger.logError('自定义音卡缺少参数audio'); + this.core.context.logger.logError('自定义音卡缺少参数audio'); return undefined; } if (!data.title) { - this.coreContext.context.logger.logError('自定义音卡缺少参数title'); + this.core.context.logger.logError('自定义音卡缺少参数title'); return undefined; } } else { if (!['qq', '163'].includes(data.type)) { - this.coreContext.context.logger.logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type); + this.core.context.logger.logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type); return undefined; } if (!data.id) { - this.coreContext.context.logger.logError('音乐卡片缺少参数id'); + this.core.context.logger.logError('音乐卡片缺少参数id'); return undefined; } } @@ -621,7 +621,7 @@ export class OneBotMsgApi { const musicJson = await RequestUtil.HttpGetJson(signUrl, 'POST', postData); return this.ob11ToRawConverters.json(musicJson, context); } catch (e) { - this.coreContext.context.logger.logError('生成音乐消息失败', e); + this.core.context.logger.logError('生成音乐消息失败', e); } }, @@ -645,9 +645,9 @@ export class OneBotMsgApi { [OB11MessageDataType.miniapp]: async () => undefined, }; - constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore) { + constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) { this.obContext = obContext; - this.coreContext = coreContext; + this.core = core; } async parseMessage( @@ -657,11 +657,11 @@ export class OneBotMsgApi { if (msg.senderUin == '0' || msg.senderUin == '') return; if (msg.peerUin == '0' || msg.peerUin == '') return; //跳过空消息 - const NTQQGroupApi = this.coreContext.apis.GroupApi; - const NTQQUserApi = this.coreContext.apis.UserApi; - const NTQQMsgApi = this.coreContext.apis.MsgApi; + const NTQQGroupApi = this.core.apis.GroupApi; + const NTQQUserApi = this.core.apis.UserApi; + const NTQQMsgApi = this.core.apis.MsgApi; const resMsg: OB11Message = { - self_id: parseInt(this.coreContext.selfInfo.uin), + self_id: parseInt(this.core.selfInfo.uin), user_id: parseInt(msg.senderUin!), time: parseInt(msg.msgTime) || Date.now(), message_id: msg.id!, @@ -678,7 +678,7 @@ export class OneBotMsgApi { sub_type: 'friend', message: messagePostFormat === 'string' ? '' : [], message_format: messagePostFormat === 'string' ? 'string' : 'array', - post_type: this.coreContext.selfInfo.uin == msg.senderUin ? EventType.MESSAGE_SENT : EventType.MESSAGE, + post_type: this.core.selfInfo.uin == msg.senderUin ? EventType.MESSAGE_SENT : EventType.MESSAGE, }; if (msg.chatType == ChatType.KCHATTYPEGROUP) { resMsg.sub_type = 'normal'; // 这里go-cqhttp是group,而onebot11标准是normal, 蛋疼 @@ -763,7 +763,7 @@ export class OneBotMsgApi { const isBlankUrl = !inputdata.url || inputdata.url === ''; const isBlankFile = !inputdata.file || inputdata.file === ''; if (isBlankUrl && isBlankFile) { - this.coreContext.context.logger.logError('文件消息缺少参数', inputdata); + this.core.context.logger.logError('文件消息缺少参数', inputdata); throw Error('文件消息缺少参数'); } const fileOrUrl = (isBlankUrl ? inputdata.file : inputdata.url) ?? ""; @@ -773,10 +773,10 @@ export class OneBotMsgApi { fileName, errMsg, success, - } = (await uri2local(this.coreContext.NapCatTempPath, fileOrUrl)); + } = (await uri2local(this.core.NapCatTempPath, fileOrUrl)); if (!success) { - this.coreContext.context.logger.logError('文件下载失败', errMsg); + this.core.context.logger.logError('文件下载失败', errMsg); throw Error('文件下载失败' + errMsg); } diff --git a/src/onebot/api/user.ts b/src/onebot/api/user.ts index e0fb0ba9..8356ee2f 100644 --- a/src/onebot/api/user.ts +++ b/src/onebot/api/user.ts @@ -4,10 +4,10 @@ import { NapCatOneBot11Adapter } from '@/onebot'; export class OneBotUserApi { obContext: NapCatOneBot11Adapter; - coreContext: NapCatCore; + core: NapCatCore; - constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore) { + constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) { this.obContext = obContext; - this.coreContext = coreContext; + this.core = core; } } diff --git a/src/onebot/helper/config.ts b/src/onebot/helper/config.ts index d7929b7a..2ce04bf6 100644 --- a/src/onebot/helper/config.ts +++ b/src/onebot/helper/config.ts @@ -5,7 +5,7 @@ import { NapCatCore } from '@/core'; export type OB11Config = typeof ob11DefaultConfig; export class OB11ConfigLoader extends ConfigBase { - constructor(coreContext: NapCatCore, configPath: string) { - super('onebot11', coreContext, configPath); + constructor(core: NapCatCore, configPath: string) { + super('onebot11', core, configPath); } } diff --git a/src/onebot/helper/quick.ts b/src/onebot/helper/quick.ts index 650b3c98..6981f969 100644 --- a/src/onebot/helper/quick.ts +++ b/src/onebot/helper/quick.ts @@ -16,12 +16,12 @@ import { isNull } from '@/common/utils/helper'; import { normalize, sendMsg } from '../action/msg/SendMsg'; import { NapCatOneBot11Adapter } from '..'; -async function handleMsg(coreContext: NapCatCore, obContext: NapCatOneBot11Adapter, msg: OB11Message, quickAction: QuickAction) { +async function handleMsg(core: NapCatCore, obContext: NapCatOneBot11Adapter, msg: OB11Message, quickAction: QuickAction) { msg = msg as OB11Message; const reply = quickAction.reply; const peer: Peer = { chatType: ChatType.KCHATTYPEC2C, - peerUid: await coreContext.apis.UserApi.getUidByUinV2(msg.user_id.toString()) as string, + peerUid: await core.apis.UserApi.getUidByUinV2(msg.user_id.toString()) as string, }; if (msg.message_type == 'private') { if (msg.sub_type === 'group') { @@ -36,7 +36,7 @@ async function handleMsg(coreContext: NapCatCore, obContext: NapCatOneBot11Adapt let replyMessage: OB11MessageData[] = []; if (msg.message_type == 'group') { - group = await coreContext.apis.GroupApi.getGroup(msg.group_id!.toString()); + group = await core.apis.GroupApi.getGroup(msg.group_id!.toString()); replyMessage.push({ type: 'reply', data: { @@ -54,37 +54,37 @@ async function handleMsg(coreContext: NapCatCore, obContext: NapCatOneBot11Adapt } replyMessage = replyMessage.concat(normalize(reply, quickAction.auto_escape)); const { sendElements, deleteAfterSentFiles } = await obContext.apiContext.MsgApi.createSendElements(replyMessage, peer); - sendMsg(coreContext, peer, sendElements, deleteAfterSentFiles, false).then().catch(coreContext.context.logger.logError); + sendMsg(core, peer, sendElements, deleteAfterSentFiles, false).then().catch(core.context.logger.logError); } } -async function handleGroupRequest(coreContext: NapCatCore, request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) { +async function handleGroupRequest(core: NapCatCore, request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) { if (!isNull(quickAction.approve)) { - coreContext.apis.GroupApi.handleGroupRequest( + core.apis.GroupApi.handleGroupRequest( request.flag, quickAction.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject, quickAction.reason, - ).then().catch(coreContext.context.logger.logError); + ).then().catch(core.context.logger.logError); } } -async function handleFriendRequest(coreContext: NapCatCore, request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) { +async function handleFriendRequest(core: NapCatCore, request: OB11FriendRequestEvent, quickAction: QuickActionFriendRequest) { if (!isNull(quickAction.approve)) { - coreContext.apis.FriendApi.handleFriendRequest(request.flag, !!quickAction.approve).then().catch(coreContext.context.logger.logError); + core.apis.FriendApi.handleFriendRequest(request.flag, !!quickAction.approve).then().catch(core.context.logger.logError); } } -export async function handleQuickOperation(coreContext: NapCatCore, obContext: NapCatOneBot11Adapter, context: QuickActionEvent, quickAction: QuickAction) { +export async function handleQuickOperation(core: NapCatCore, obContext: NapCatOneBot11Adapter, context: QuickActionEvent, quickAction: QuickAction) { if (context.post_type === 'message') { - handleMsg(coreContext, obContext, context as OB11Message, quickAction).then().catch(coreContext.context.logger.logError); + handleMsg(core, obContext, context as OB11Message, quickAction).then().catch(core.context.logger.logError); } if (context.post_type === 'request') { const friendRequest = context as OB11FriendRequestEvent; const groupRequest = context as OB11GroupRequestEvent; if ((friendRequest).request_type === 'friend') { - handleFriendRequest(coreContext, friendRequest, quickAction).then().catch(coreContext.context.logger.logError); + handleFriendRequest(core, friendRequest, quickAction).then().catch(core.context.logger.logError); } else if (groupRequest.request_type === 'group') { - handleGroupRequest(coreContext, groupRequest, quickAction).then().catch(coreContext.context.logger.logError); + handleGroupRequest(core, groupRequest, quickAction).then().catch(core.context.logger.logError); } } } diff --git a/src/onebot/network/active-http.ts b/src/onebot/network/active-http.ts index f055fbde..7f631790 100644 --- a/src/onebot/network/active-http.ts +++ b/src/onebot/network/active-http.ts @@ -13,10 +13,10 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter { constructor( public url: string, public secret: string | undefined, - public coreContext: NapCatCore, + public core: NapCatCore, public obContext: NapCatOneBot11Adapter ) { - this.logger = coreContext.context.logger; + this.logger = core.context.logger; } onEvent(event: T) { @@ -25,7 +25,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter { } const headers: Record = { 'Content-Type': 'application/json', - 'x-self-id': this.coreContext.selfInfo.uin, + 'x-self-id': this.core.selfInfo.uin, }; const msgStr = JSON.stringify(event); if (this.secret && this.secret.length > 0) { @@ -48,7 +48,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter { return; } try { - handleQuickOperation(this.coreContext, this.obContext, event as QuickActionEvent, resJson).then().catch(this.logger.logError); + handleQuickOperation(this.core, this.obContext, event as QuickActionEvent, resJson).then().catch(this.logger.logError); } catch (e: any) { this.logger.logError('[OneBot] [Http Client] 新消息事件HTTP上报返回快速操作失败', e); } diff --git a/src/onebot/network/active-websocket.ts b/src/onebot/network/active-websocket.ts index 15b16970..680c2350 100644 --- a/src/onebot/network/active-websocket.ts +++ b/src/onebot/network/active-websocket.ts @@ -19,10 +19,10 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter { public reconnectIntervalInMillis: number, public heartbeatIntervalInMillis: number, private token: string, - public coreContext: NapCatCore, + public core: NapCatCore, public actions: ActionMap, ) { - this.logger = coreContext.context.logger; + this.logger = core.context.logger; } onEvent(event: T) { @@ -37,7 +37,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter { } this.heartbeatRef = setInterval(() => { if (this.connection && this.connection.readyState === WebSocket.OPEN) { - this.connection.send(JSON.stringify(new OB11HeartbeatEvent(this.coreContext, this.heartbeatIntervalInMillis, this.coreContext.selfInfo.online, true))); + this.connection.send(JSON.stringify(new OB11HeartbeatEvent(this.core, this.heartbeatIntervalInMillis, this.core.selfInfo.online, true))); } }, this.heartbeatIntervalInMillis); await this.tryConnect(); @@ -74,7 +74,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter { handshakeTimeout: 2000, perMessageDeflate: false, headers: { - 'X-Self-ID': this.coreContext.selfInfo.uin, + 'X-Self-ID': this.core.selfInfo.uin, 'Authorization': `Bearer ${this.token}`, 'x-client-role': 'Universal', // koishi-adapter-onebot 需要这个字段 'User-Agent': 'OneBot/11', @@ -89,7 +89,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter { }); this.connection.on('open', () => { try { - this.connectEvent(this.coreContext); + this.connectEvent(this.core); } catch (e) { this.logger.logError('[OneBot] [WebSocket Client] 发送连接生命周期失败', e); } diff --git a/src/onebot/network/passive-http.ts b/src/onebot/network/passive-http.ts index 689ea39b..b23b4600 100644 --- a/src/onebot/network/passive-http.ts +++ b/src/onebot/network/passive-http.ts @@ -14,7 +14,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter { constructor( public port: number, public token: string, - public coreContext: NapCatCore, + public core: NapCatCore, public actions: ActionMap, ) { } @@ -26,7 +26,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter { open() { try { if (this.isOpen) { - this.coreContext.context.logger.logError('Cannot open a closed HTTP server'); + this.core.context.logger.logError('Cannot open a closed HTTP server'); return; } if (!this.isOpen) { @@ -34,7 +34,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter { this.isOpen = true; } } catch (e) { - this.coreContext.context.logger.logError(`[OneBot] [HTTP Server Adapter] Boot Error: ${e}`); + this.core.context.logger.logError(`[OneBot] [HTTP Server Adapter] Boot Error: ${e}`); } } @@ -66,7 +66,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter { this.app.use((req, res) => this.handleRequest(req, res)); this.server.listen(this.port, () => { - this.coreContext.context.logger.log(`[OneBot] [HTTP Server Adapter] Start On Port ${this.port}`); + this.core.context.logger.log(`[OneBot] [HTTP Server Adapter] Start On Port ${this.port}`); }); } @@ -84,7 +84,7 @@ export class OB11PassiveHttpAdapter implements IOB11NetworkAdapter { private async handleRequest(req: Request, res: Response) { if (!this.isOpen) { - this.coreContext.context.logger.log(`[OneBot] [HTTP Server Adapter] Server is closed`); + this.core.context.logger.log(`[OneBot] [HTTP Server Adapter] Server is closed`); return res.json(OB11Response.error('Server is closed', 200)); } diff --git a/src/onebot/network/passive-websocket.ts b/src/onebot/network/passive-websocket.ts index d1d0307b..41d410ab 100644 --- a/src/onebot/network/passive-websocket.ts +++ b/src/onebot/network/passive-websocket.ts @@ -1,12 +1,10 @@ import { IOB11NetworkAdapter, OB11EmitEventContent } from './index'; import urlParse from 'url'; -import BaseAction from '@/onebot/action/BaseAction'; import { WebSocket, WebSocketServer } from 'ws'; import { Mutex } from 'async-mutex'; import { OB11Response } from '../action/OB11Response'; import { ActionName } from '../action/types'; import { NapCatCore } from '@/core'; -import { NapCatOneBot11Adapter } from '..'; import { LogWrapper } from '@/common/utils/log'; import { OB11HeartbeatEvent } from '../event/meta/OB11HeartbeatEvent'; import { IncomingMessage } from 'http'; @@ -20,7 +18,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { isOpen: boolean = false; hasBeenClosed: boolean = false; heartbeatInterval: number = 0; - coreContext: NapCatCore; + core: NapCatCore; logger: LogWrapper; private heartbeatIntervalId: NodeJS.Timeout | null = null; @@ -29,11 +27,11 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { port: number, heartbeatInterval: number, token: string, - coreContext: NapCatCore, + core: NapCatCore, public actions: ActionMap ) { - this.coreContext = coreContext; - this.logger = coreContext.context.logger; + this.core = core; + this.logger = core.context.logger; this.heartbeatInterval = heartbeatInterval; this.wsServer = new WebSocketServer({ @@ -41,7 +39,6 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { host: ip, maxPayload: 1024 * 1024 * 1024, }); - const core = coreContext; this.wsServer.on('connection', async (wsClient, wsReq) => { if (!this.isOpen) { wsClient.close(); @@ -120,7 +117,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter { this.wsClientsMutex.runExclusive(async () => { this.wsClients.forEach((wsClient) => { if (wsClient.readyState === WebSocket.OPEN) { - wsClient.send(JSON.stringify(new OB11HeartbeatEvent(this.coreContext, this.heartbeatInterval, this.coreContext.selfInfo.online, true))); + wsClient.send(JSON.stringify(new OB11HeartbeatEvent(this.core, this.heartbeatInterval, this.core.selfInfo.online, true))); } }); });