public Launcher( ILogger logger, IIrcClient client, ICommandParser commandParser, ICommandHandler commandHandler, CommandOverrideConfiguration commandOverrideConfiguration, ISession globalSession, BotConfiguration botConfiguration) { this.logger = logger; this.client = client; this.commandParser = commandParser; this.commandOverrideConfiguration = commandOverrideConfiguration; this.globalSession = globalSession; StartupTimeMetric.Set((StartupTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds); this.exitLock = new ManualResetEvent(false); this.client.DisconnectedEvent += (sender, args) => this.Stop(); this.client.ReceivedMessage += commandHandler.OnMessageReceived; if (botConfiguration.PrometheusMetricsPort.HasValue) { var metricsServer = new MetricServer(botConfiguration.PrometheusMetricsPort.Value); metricsServer.Start(); var mainAssembly = Assembly.GetAssembly(Type.GetType("Helpmebot.Launch, Helpmebot")); VersionInfo.WithLabels( FileVersionInfo.GetVersionInfo(mainAssembly.Location).FileVersion, FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(IrcClient)).Location) .FileVersion, FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(CommandBase)).Location) .FileVersion, FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(MediaWikiApi)).Location) .FileVersion, RuntimeInformation.FrameworkDescription, Environment.OSVersion.ToString(), ((TargetFrameworkAttribute)mainAssembly .GetCustomAttributes(typeof(TargetFrameworkAttribute), false) .FirstOrDefault())?.FrameworkDisplayName ?? "Unknown" ) .Set(1); } }
public void Inflate(CommandOverrideConfiguration config) { var commandInterface = typeof(ICommand); foreach (var entry in config.OverrideMap) { entry.CommandType = TypeResolver.GetType(entry.Type); if (entry.CommandType == null) { throw new Exception($"Unable to locate type {entry.Type} in override map"); } if (!commandInterface.IsAssignableFrom(entry.CommandType)) { throw new Exception($"Unable to type {entry.CommandType} is not a bot command."); } } }