mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: migrateOneBotConfigsV1
This commit is contained in:
parent
4271acc6ab
commit
623799c049
@ -124,7 +124,6 @@ export const mergeNetworkDefaultConfig = {
|
|||||||
|
|
||||||
type NetworkConfigKeys = keyof typeof mergeNetworkDefaultConfig;
|
type NetworkConfigKeys = keyof typeof mergeNetworkDefaultConfig;
|
||||||
|
|
||||||
// TODO: wrong type hint in userConfig (aka old userConfig)
|
|
||||||
export function mergeOneBotConfigs(
|
export function mergeOneBotConfigs(
|
||||||
userConfig: Partial<OneBotConfig>,
|
userConfig: Partial<OneBotConfig>,
|
||||||
defaultConfig: OneBotConfig = defaultOneBotConfigs
|
defaultConfig: OneBotConfig = defaultOneBotConfigs
|
||||||
@ -149,57 +148,61 @@ export function mergeOneBotConfigs(
|
|||||||
return mergedConfig;
|
return mergedConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function migrateOneBotConfigsV1(
|
function checkIsOneBotConfigV1(v1Config: Partial<v1Config>): boolean {
|
||||||
v1Config: Partial<v1Config>,
|
return v1Config.http !== undefined || v1Config.ws !== undefined || v1Config.reverseWs !== undefined;
|
||||||
defaultConfig: OneBotConfig = defaultOneBotConfigs
|
}
|
||||||
): OneBotConfig {
|
|
||||||
const mergedConfig = { ...defaultConfig };
|
export function migrateOneBotConfigsV1(config: Partial<v1Config>): OneBotConfig {
|
||||||
if (v1Config.http) {
|
if (!checkIsOneBotConfigV1(config)) {
|
||||||
|
return config as OneBotConfig;
|
||||||
|
}
|
||||||
|
const mergedConfig = { ...defaultOneBotConfigs };
|
||||||
|
if (config.http) {
|
||||||
mergedConfig.network.httpServers = [
|
mergedConfig.network.httpServers = [
|
||||||
mergeConfigs(httpServerDefaultConfigs, {
|
mergeConfigs(httpServerDefaultConfigs, {
|
||||||
enable: v1Config.http.enable,
|
enable: config.http.enable,
|
||||||
port: v1Config.http.port,
|
port: config.http.port,
|
||||||
host: v1Config.http.host,
|
host: config.http.host,
|
||||||
token: v1Config.http.secret,
|
token: config.http.secret,
|
||||||
debug: v1Config.debug,
|
debug: config.debug,
|
||||||
messagePostFormat: v1Config.messagePostFormat,
|
messagePostFormat: config.messagePostFormat,
|
||||||
reportSelfMessage: v1Config.reportSelfMessage,
|
reportSelfMessage: config.reportSelfMessage,
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if (v1Config.ws) {
|
if (config.ws) {
|
||||||
mergedConfig.network.websocketServers = [
|
mergedConfig.network.websocketServers = [
|
||||||
mergeConfigs(websocketServerDefaultConfigs, {
|
mergeConfigs(websocketServerDefaultConfigs, {
|
||||||
enable: v1Config.ws.enable,
|
enable: config.ws.enable,
|
||||||
port: v1Config.ws.port,
|
port: config.ws.port,
|
||||||
host: v1Config.ws.host,
|
host: config.ws.host,
|
||||||
token: v1Config.token,
|
token: config.token,
|
||||||
debug: v1Config.debug,
|
debug: config.debug,
|
||||||
messagePostFormat: v1Config.messagePostFormat,
|
messagePostFormat: config.messagePostFormat,
|
||||||
reportSelfMessage: v1Config.reportSelfMessage,
|
reportSelfMessage: config.reportSelfMessage,
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if (v1Config.reverseWs) {
|
if (config.reverseWs) {
|
||||||
mergedConfig.network.websocketClients = v1Config.reverseWs.urls.map((url) =>
|
mergedConfig.network.websocketClients = config.reverseWs.urls.map((url) =>
|
||||||
mergeConfigs(websocketClientDefaultConfigs, {
|
mergeConfigs(websocketClientDefaultConfigs, {
|
||||||
enable: v1Config.reverseWs?.enable,
|
enable: config.reverseWs?.enable,
|
||||||
url: url,
|
url: url,
|
||||||
token: v1Config.token,
|
token: config.token,
|
||||||
debug: v1Config.debug,
|
debug: config.debug,
|
||||||
messagePostFormat: v1Config.messagePostFormat,
|
messagePostFormat: config.messagePostFormat,
|
||||||
reportSelfMessage: v1Config.reportSelfMessage,
|
reportSelfMessage: config.reportSelfMessage,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (v1Config.heartInterval) {
|
if (config.heartInterval) {
|
||||||
mergedConfig.network.websocketServers[0].heartInterval = v1Config.heartInterval;
|
mergedConfig.network.websocketServers[0].heartInterval = config.heartInterval;
|
||||||
}
|
}
|
||||||
if (v1Config.musicSignUrl) {
|
if (config.musicSignUrl) {
|
||||||
mergedConfig.musicSignUrl = v1Config.musicSignUrl;
|
mergedConfig.musicSignUrl = config.musicSignUrl;
|
||||||
}
|
}
|
||||||
if (v1Config.enableLocalFile2Url) {
|
if (config.enableLocalFile2Url) {
|
||||||
mergedConfig.enableLocalFile2Url = v1Config.enableLocalFile2Url;
|
mergedConfig.enableLocalFile2Url = config.enableLocalFile2Url;
|
||||||
}
|
}
|
||||||
return mergedConfig;
|
return mergedConfig;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,8 @@ export class NapCatOneBot11Adapter {
|
|||||||
this.core = core;
|
this.core = core;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.configLoader = new OB11ConfigLoader(core, pathWrapper.configPath);
|
this.configLoader = new OB11ConfigLoader(core, pathWrapper.configPath);
|
||||||
this.configLoader.save(mergeOneBotConfigs(migrateOneBotConfigsV1(this.configLoader.configData)));
|
this.configLoader.save(migrateOneBotConfigsV1(this.configLoader.configData));
|
||||||
|
this.configLoader.save(mergeOneBotConfigs(this.configLoader.configData));
|
||||||
this.apis = {
|
this.apis = {
|
||||||
GroupApi: new OneBotGroupApi(this, core),
|
GroupApi: new OneBotGroupApi(this, core),
|
||||||
UserApi: new OneBotUserApi(this, core),
|
UserApi: new OneBotUserApi(this, core),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user