using System; using System.Net.Http; using Autofac; using DSharpPlus; using DSharpPlus.EventArgs; 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 => new DiscordConfiguration { Token = c.Resolve().Token, TokenType = TokenType.Bot, MessageCacheSize = 0, LargeThreshold = 50, LoggerFactory = c.Resolve() }).AsSelf(); builder.Register(c => new DiscordShardedClient(c.Resolve())).AsSelf().SingleInstance(); builder.Register(c => new DiscordRestClient(c.Resolve())).AsSelf().SingleInstance(); builder.Register(c => new GatewaySettings { Token = c.Resolve().Token, 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(); // 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(); 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(); // TODO: // 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(); } } }