public void CreateConfigIfNotExists(bool interactive = false) { if (File.Exists(config.Path)) { return; } Log.Warn("No permission file found."); var settings = new CreateFileSettings { OverwriteIfExists = false, }; if (interactive) { Console.WriteLine("Do you want to set up an admin in the default permission file template? [Y/n]"); if (Interactive.UserAgree(defaultTo: true)) { var adminUid = Interactive.LoopAction("Please enter an admin uid", uid => { if (!Uid.IsValid(uid)) { Console.WriteLine("The uid seems to be invalid, continue anyway? [y/N]"); return(Interactive.UserAgree(defaultTo: false)); } return(true); }); if (adminUid is null) { return; } settings.AdminUids = new[] { adminUid }; } } CreateConfig(settings); }
public void RunBots(bool interactive) { var botConfigList = confRoot.GetAllBots(); if (botConfigList is null) { return; } if (botConfigList.Length == 0) { if (!interactive) { Log.Warn("No bots are configured in the load list."); return; } Console.WriteLine("It seems like there are no bots configured."); Console.WriteLine("Fill out this quick setup to get started."); var newBot = CreateNewBot(); newBot.Run.Value = true; string address = Interactive.LoopAction("Please enter the ip, domain or nickname (with port; default: 9987) where to connect to:", addr => { if (TS3Client.TsDnsResolver.TryResolve(addr, out _)) { return(true); } Console.WriteLine("The address seems invalid or could not be resolved, continue anyway? [y/N]"); return(Interactive.UserAgree(defaultTo: false)); }); if (address is null) { return; } newBot.Connect.Address.Value = address; Console.WriteLine("Please enter the server password (or leave empty for none):"); newBot.Connect.ServerPassword.Password.Value = Console.ReadLine(); if (!newBot.SaveNew(ConfigHelper.DefaultBotName)) { Log.Error("Could not save new bot. Ensure that the bot has access to the directory."); return; } if (!confRoot.Save()) { Log.Error("Could not save root config. The bot won't start by default."); } var runResult = RunBot(newBot); if (!runResult.Ok) { Log.Error("Could not run bot ({0})", runResult.Error); } return; } foreach (var instance in botConfigList) { if (!instance.Run) { continue; } var result = RunBot(instance); if (!result.Ok) { Log.Error("Could not instantiate bot: {0}", result.Error); } } }