internal static async Task InitBots()
{
if (Bot.Bots.Count != 0)
{
return;
}
// Ensure that we ask for a list of servers if we don't have any saved servers available
IEnumerable <ServerRecord> servers = await Program.GlobalDatabase.ServerListProvider.FetchServerListAsync().ConfigureAwait(false);
if (servers?.Any() != true)
{
ArchiLogger.LogGenericInfo(string.Format(Strings.Initializing, nameof(SteamDirectory)));
SteamConfiguration steamConfiguration = SteamConfiguration.Create(builder => builder.WithProtocolTypes(Program.GlobalConfig.SteamProtocols).WithCellID(Program.GlobalDatabase.CellID).WithServerListProvider(Program.GlobalDatabase.ServerListProvider).WithHttpClientFactory(() => Program.WebBrowser.GenerateDisposableHttpClient()));
try {
await SteamDirectory.LoadAsync(steamConfiguration).ConfigureAwait(false);
ArchiLogger.LogGenericInfo(Strings.Success);
} catch {
ArchiLogger.LogGenericWarning(Strings.BotSteamDirectoryInitializationFailed);
await Task.Delay(5000).ConfigureAwait(false);
}
}
HashSet <string> botNames;
try {
botNames = Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*" + SharedInfo.ConfigExtension).Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName) && IsValidBotName(botName)).ToHashSet();
} catch (Exception e) {
ArchiLogger.LogGenericException(e);
return;
}
if (botNames.Count == 0)
{
ArchiLogger.LogGenericWarning(Strings.ErrorNoBotsDefined);
return;
}
if (botNames.Count > MaximumRecommendedBotsCount)
{
ArchiLogger.LogGenericWarning(string.Format(Strings.WarningExcessiveBotsCount, MaximumRecommendedBotsCount));
await Task.Delay(10000).ConfigureAwait(false);
}
await Utilities.InParallel(botNames.OrderBy(botName => botName).Select(Bot.RegisterBot)).ConfigureAwait(false);
}