This commit is contained in:
Łukasz Domeradzki
2023-09-20 13:53:15 +02:00
committed by GitHub
parent 9163b57c3e
commit af4a64b99e
2 changed files with 25 additions and 7 deletions

View File

@@ -580,6 +580,28 @@ public static class ASF {
await OnCreatedKeysFile(name, fullPath).ConfigureAwait(false);
}
private static async Task OnConfigChanged() {
string globalConfigFile = GetFilePath(EFileType.Config);
if (string.IsNullOrEmpty(globalConfigFile)) {
throw new InvalidOperationException(nameof(globalConfigFile));
}
(GlobalConfig? globalConfig, _) = await GlobalConfig.Load(globalConfigFile).ConfigureAwait(false);
if (globalConfig == null) {
// Invalid config file, we allow user to fix it without destroying the ASF instance right away
return;
}
if (globalConfig == GlobalConfig) {
return;
}
ArchiLogger.LogGenericInfo(Strings.GlobalConfigChanged);
await RestartOrExit().ConfigureAwait(false);
}
private static async void OnCreated(object sender, FileSystemEventArgs e) {
ArgumentNullException.ThrowIfNull(sender);
ArgumentNullException.ThrowIfNull(e);
@@ -666,8 +688,7 @@ public static class ASF {
}
if (botName.Equals(SharedInfo.ASF, StringComparison.OrdinalIgnoreCase)) {
ArchiLogger.LogGenericInfo(Strings.GlobalConfigChanged);
await RestartOrExit().ConfigureAwait(false);
await OnConfigChanged().ConfigureAwait(false);
return;
}

View File

@@ -1402,16 +1402,13 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
string configFile = GetFilePath(EFileType.Config);
if (string.IsNullOrEmpty(configFile)) {
ArchiLogger.LogNullError(configFile);
return;
throw new InvalidOperationException(nameof(configFile));
}
(BotConfig? botConfig, _) = await BotConfig.Load(configFile, BotName).ConfigureAwait(false);
if (botConfig == null) {
await Destroy().ConfigureAwait(false);
// Invalid config file, we allow user to fix it without destroying the bot right away
return;
}