mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-18 20:30:08 +08:00
Refactor FileApi usage to obContext in OneBot
Replaced references to `core.apis.FileApi` with `obContext.apis.FileApi` across actions and message API to ensure consistent context usage. Added FileApi to the ApiListType and initialized it in NapCatOneBot11Adapter. This improves maintainability and context handling for file-related operations.
This commit is contained in:
parent
8df54d5cd3
commit
4dc8b3ed3b
@ -41,7 +41,7 @@ export default class GoCQHTTPUploadGroupFile extends OneBotAction<Payload, Uploa
|
||||
peer,
|
||||
deleteAfterSentFiles: [],
|
||||
};
|
||||
const sendFileEle = await this.core.apis.FileApi.createValidSendFileElement(msgContext, downloadResult.path, payload.name, payload.folder ?? payload.folder_id);
|
||||
const sendFileEle = await this.obContext.apis.FileApi.createValidSendFileElement(msgContext, downloadResult.path, payload.name, payload.folder ?? payload.folder_id);
|
||||
msgContext.deleteAfterSentFiles.push(downloadResult.path);
|
||||
const returnMsg = await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, [sendFileEle], msgContext.deleteAfterSentFiles);
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ export default class GoCQHTTPUploadPrivateFile extends OneBotAction<Payload, Upl
|
||||
}, ContextMode.Private),
|
||||
deleteAfterSentFiles: [],
|
||||
};
|
||||
const sendFileEle: SendFileElement = await this.core.apis.FileApi.createValidSendFileElement(msgContext, downloadResult.path, payload.name);
|
||||
const sendFileEle: SendFileElement = await this.obContext.apis.FileApi.createValidSendFileElement(msgContext, downloadResult.path, payload.name);
|
||||
msgContext.deleteAfterSentFiles.push(downloadResult.path);
|
||||
const returnMsg = await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(await this.getPeer(payload), [sendFileEle], msgContext.deleteAfterSentFiles);
|
||||
|
||||
|
||||
@ -666,7 +666,7 @@ export class OneBotMsgApi {
|
||||
|
||||
// File service
|
||||
[OB11MessageDataType.image]: async (sendMsg, context) => {
|
||||
return await this.core.apis.FileApi.createValidSendPicElement(
|
||||
return await this.obContext.apis.FileApi.createValidSendPicElement(
|
||||
context,
|
||||
(await this.handleOb11FileLikeMessage(sendMsg, context)).path,
|
||||
sendMsg.data.summary,
|
||||
@ -676,7 +676,7 @@ export class OneBotMsgApi {
|
||||
|
||||
[OB11MessageDataType.file]: async (sendMsg, context) => {
|
||||
const { path, fileName } = await this.handleOb11FileLikeMessage(sendMsg, context);
|
||||
return await this.core.apis.FileApi.createValidSendFileElement(context, path, fileName);
|
||||
return await this.obContext.apis.FileApi.createValidSendFileElement(context, path, fileName);
|
||||
},
|
||||
|
||||
[OB11MessageDataType.video]: async (sendMsg, context) => {
|
||||
@ -691,11 +691,11 @@ export class OneBotMsgApi {
|
||||
}
|
||||
}
|
||||
|
||||
return await this.core.apis.FileApi.createValidSendVideoElement(context, path, fileName, thumb);
|
||||
return await this.obContext.apis.FileApi.createValidSendVideoElement(context, path, fileName, thumb);
|
||||
},
|
||||
|
||||
[OB11MessageDataType.voice]: async (sendMsg, context) =>
|
||||
this.core.apis.FileApi.createValidSendPttElement(context,
|
||||
this.obContext.apis.FileApi.createValidSendPttElement(context,
|
||||
(await this.handleOb11FileLikeMessage(sendMsg, context)).path),
|
||||
|
||||
[OB11MessageDataType.json]: async ({ data: { data } }) => ({
|
||||
|
||||
@ -54,6 +54,7 @@ import { IOB11NetworkAdapter } from '@/napcat-onebot/network/adapter';
|
||||
import { OB11HttpSSEServerAdapter } from './network/http-server-sse';
|
||||
import { OB11PluginMangerAdapter } from './network/plugin-manger';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { OneBotFileApi } from './api/file';
|
||||
|
||||
interface ApiListType {
|
||||
GroupApi: OneBotGroupApi;
|
||||
@ -61,6 +62,7 @@ interface ApiListType {
|
||||
FriendApi: OneBotFriendApi;
|
||||
MsgApi: OneBotMsgApi;
|
||||
QuickActionApi: OneBotQuickActionApi;
|
||||
FileApi: OneBotFileApi;
|
||||
}
|
||||
// OneBot实现类
|
||||
export class NapCatOneBot11Adapter {
|
||||
@ -83,6 +85,7 @@ export class NapCatOneBot11Adapter {
|
||||
FriendApi: new OneBotFriendApi(this, core),
|
||||
MsgApi: new OneBotMsgApi(this, core),
|
||||
QuickActionApi: new OneBotQuickActionApi(this, core),
|
||||
FileApi: new OneBotFileApi(this, core),
|
||||
} as const;
|
||||
this.actions = createActionMap(this, core);
|
||||
this.networkManager = new OB11NetworkManager();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user