using System; using System.Net.Http; using Autofac; using Myriad.Cache; using Myriad.Gateway; using NodaTime; using PluralKit.Core; using Sentry; using Serilog; namespace PluralKit.Bot { public class BotModule: Module { protected override void Load(ContainerBuilder builder) { // Clients builder.Register(c => { var botConfig = c.Resolve(); return new GatewaySettings { Token = botConfig.Token, MaxShardConcurrency = botConfig.MaxShardConcurrency, Intents = GatewayIntent.Guilds | GatewayIntent.DirectMessages | GatewayIntent.DirectMessageReactions | GatewayIntent.GuildEmojis | GatewayIntent.GuildMessages | GatewayIntent.GuildWebhooks | GatewayIntent.GuildMessageReactions }; }).AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.Register(c => new Myriad.Rest.DiscordApiClient(c.Resolve().Token, c.Resolve())) .AsSelf().SingleInstance(); builder.RegisterType().AsSelf().As().SingleInstance(); // Commands builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); builder.RegisterType().AsSelf(); // Bot core builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().As>(); builder.RegisterType().As>().As>(); builder.RegisterType().As>(); builder.RegisterType().As>(); // Event handler queue builder.RegisterType>().AsSelf().SingleInstance(); builder.RegisterType>().AsSelf().SingleInstance(); // Bot services builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); // Sentry stuff builder.Register(_ => new Scope(null)).AsSelf().InstancePerLifetimeScope(); builder.RegisterType() .As>() .As>() .As>() .As>() .As>() .SingleInstance(); // Proxy stuff builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); // Utils builder.Register(c => new HttpClient { Timeout = TimeSpan.FromSeconds(5) }).AsSelf().SingleInstance(); builder.RegisterInstance(SystemClock.Instance).As(); builder.RegisterType().AsSelf().SingleInstance(); } } }