/// <summary> /// Creates a new help formatter instance. /// </summary> /// <param name="ctx">Context in which the formatter is invoked.</param> /// <param name="bot">Turret bot instance.</param> public TurretHelpFormatter(CommandContext ctx, TurretBot bot) : base(ctx) { this.Bot = bot; this.Message = new StringBuilder(); this.Message.AppendLine("```less") .AppendLine($"Music Turret v{bot.BotVersion} by Emzi0767") .AppendLine(); }
/// <summary> /// Asynchronous entry point of the bot's binary. /// </summary> /// <param name="args">Command-line arguments for the binary.</param> /// <returns></returns> private static async Task MainAsync(string[] args) { // locate the config file var dockerSecret = Environment.GetEnvironmentVariable("DOCKER_SECRET"); var cfgFile = new FileInfo(dockerSecret != null ? Path.Combine("/run/secrets", dockerSecret) : "config.json"); // load the config file and validate it var cfgLoader = new TurretConfigLoader(); var cfg = await cfgLoader.LoadConfigurationAsync(cfgFile); cfgLoader.ValidateConfiguration(cfg); // create database type mapping NpgsqlConnection.GlobalTypeMapper.MapEnum <DatabaseEntityKind>("entity_kind"); // validate database var dbcsp = new ConnectionStringProvider(cfg.PostgreSQL); using (var db = new DatabaseContext(dbcsp)) { var dbv = db.Metadata.SingleOrDefault(x => x.MetaKey == "schema_version"); if (dbv == null || dbv.MetaValue != "2") { throw new InvalidDataException("Database schema version mismatch."); } dbv = db.Metadata.SingleOrDefault(x => x.MetaKey == "project"); if (dbv == null || dbv.MetaValue != "Music Turret") { throw new InvalidDataException("Database schema type mismatch."); } } // create shards Shards = new Dictionary <int, TurretBot>(); var async = new AsyncExecutor(); for (int i = 0; i < cfg.Discord.ShardCount; i++) { var shard = new TurretBot(cfg, i, async); await shard.StartAsync(); Shards[i] = shard; } // wait forever await Task.Delay(-1); }