Add WebUI token update and callback handling

Introduces callback mechanisms for WebUI token changes and QQ login status updates. The WebUI token is now updated and communicated via a callback after login, and related runtime and type definitions are extended to support these features. Also sets a static default token value in the config schema.
This commit is contained in:
手瓜一十雪
2025-09-06 18:15:35 +08:00
parent 78cd5eab19
commit ff33fb9efb
5 changed files with 60 additions and 4 deletions

View File

@@ -13,6 +13,8 @@ import {
SendStatusType,
NTMsgType,
MessageElement,
ElementType,
NTMsgAtType,
} from '@/core';
import { OB11ConfigLoader } from '@/onebot/config';
import {
@@ -178,6 +180,25 @@ export class NapCatOneBot11Adapter {
WebUiDataRuntime.setQQVersion(this.core.context.basicInfoWrapper.getFullQQVersion());
WebUiDataRuntime.setQQLoginInfo(selfInfo);
WebUiDataRuntime.setQQLoginStatus(true);
WebUiDataRuntime.getQQLoginCallback()(true);
let sendWebUiToken = async (token: string) => {
await this.core.apis.MsgApi.sendMsg(
{ chatType: ChatType.KCHATTYPEC2C, peerUid: selfInfo.uid, guildId: '' },
[{
elementType: ElementType.TEXT,
elementId: '',
textElement: {
content: 'Update WebUi Token: ' + token,
atType: NTMsgAtType.ATTYPEUNKNOWN,
atUid: '',
atTinyId: '',
atNtUid: '',
}
}],
5000
)
};
WebUiDataRuntime.setWebUiTokenChangeCallback(sendWebUiToken);
WebUiDataRuntime.setOnOB11ConfigChanged(async (newConfig) => {
const prev = this.configLoader.configData;
this.configLoader.save(newConfig);