public static async Task <Robot> StartBot(Options options) { if (options.Test && (options.ScriptFiles == null || !options.ScriptFiles.Any())) { Console.WriteLine("You need to specify at least one script file to test."); return(null); } var logConfig = CreateLogConfig(options); ConfigurePath(options, logConfig.GetLogger()); var builder = new RobotBuilder(logConfig).WithConfiguration(GetConfiguration(options)); if (!string.IsNullOrWhiteSpace(options.Name)) { builder.WithName(options.Name); } if (options.Test) { builder.DisableScriptDiscovery(); } if (!string.IsNullOrEmpty(options.WorkingDirectory)) { builder.UseWorkingDirectory(options.WorkingDirectory); } if (options.Watch) { builder.EnableScriptWatcher(); } Robot robot = null; try { robot = builder.Build(); if (robot == null) { return(null); } } catch (Exception e) { logConfig.GetLogger().Fatal("Could not build robot. Try installing the latest version of any mmbot packages (mmbot.jabbr, mmbot.slack etc) if there was a breaking change.", e); } await robot.Run().ContinueWith(t => { if (!t.IsFaulted) { Console.WriteLine(IntroText); Console.WriteLine((options.Test ? "The test console is ready. " : "mmbot is running. ") + "Press CTRL+C at any time to exit"); } }); return(robot); }
public static async Task<Robot> StartBot(Options options) { if (options.Test && (options.ScriptFiles == null || !options.ScriptFiles.Any())) { Console.WriteLine("You need to specify at least one script file to test."); return null; } var logConfig = CreateLogConfig(options); ConfigurePath(options, logConfig.GetLogger()); var builder = new RobotBuilder(logConfig).WithConfiguration(GetConfiguration(options)); if (!string.IsNullOrWhiteSpace(options.Name)) { builder.WithName(options.Name); } if (options.Test) { builder.DisableScriptDiscovery(); } if (!string.IsNullOrEmpty(options.WorkingDirectory)) { builder.UseWorkingDirectory(options.WorkingDirectory); } if (options.Watch) { builder.EnableScriptWatcher(); } Robot robot = null; try { robot = builder.Build(); } catch (Exception e) { logConfig.GetLogger().Fatal("Could not build robot. Try installing the latest version of any mmbot packages (mmbot.jabbr, mmbot.slack etc) if there was a breaking change.", e); } if (robot == null) { return null; } await robot.Run().ContinueWith(t => { if (!t.IsFaulted) { Console.WriteLine(IntroText); Console.WriteLine((options.Test ? "The test console is ready. " : "mmbot is running. ") + "Press CTRL+C at any time to exit"); } }); return robot; }