private static async Task InitBots() { if (Bot.Bots != null) { return; } StringComparer botsComparer = await Core.GetBotsComparer().ConfigureAwait(false); Bot.Init(botsComparer); // 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(() => 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(botsComparer); } 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); }
private static void InitBotsComparer(StringComparer botsComparer) { if (botsComparer == null) { ArchiLogger.LogNullError(nameof(botsComparer)); return; } if (Bot.Bots != null) { return; } Bot.Init(botsComparer); }