2020-01-26 00:27:45 +00:00
|
|
|
using System;
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
|
|
using Autofac;
|
|
|
|
|
2020-04-17 21:10:01 +00:00
|
|
|
using DSharpPlus;
|
2020-05-01 23:52:52 +00:00
|
|
|
using DSharpPlus.EventArgs;
|
2020-01-26 00:27:45 +00:00
|
|
|
|
2020-06-06 23:30:19 +00:00
|
|
|
using NodaTime;
|
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
using PluralKit.Core;
|
2020-01-26 00:27:45 +00:00
|
|
|
|
|
|
|
using Sentry;
|
|
|
|
|
|
|
|
namespace PluralKit.Bot
|
|
|
|
{
|
|
|
|
public class BotModule: Module
|
|
|
|
{
|
|
|
|
protected override void Load(ContainerBuilder builder)
|
|
|
|
{
|
2020-04-24 19:50:28 +00:00
|
|
|
// Clients
|
2020-04-28 22:05:26 +00:00
|
|
|
builder.Register(c => new DiscordConfiguration
|
2020-04-24 19:50:28 +00:00
|
|
|
{
|
|
|
|
Token = c.Resolve<BotConfig>().Token,
|
|
|
|
TokenType = TokenType.Bot,
|
|
|
|
MessageCacheSize = 0,
|
2020-04-28 22:05:26 +00:00
|
|
|
LargeThreshold = 50
|
|
|
|
}).AsSelf();
|
|
|
|
builder.Register(c => new DiscordShardedClient(c.Resolve<DiscordConfiguration>())).AsSelf().SingleInstance();
|
|
|
|
builder.Register(c => new DiscordRestClient(c.Resolve<DiscordConfiguration>())).AsSelf().SingleInstance();
|
2020-04-24 19:50:28 +00:00
|
|
|
|
2020-01-26 00:27:45 +00:00
|
|
|
// Commands
|
|
|
|
builder.RegisterType<CommandTree>().AsSelf();
|
2020-02-01 12:03:02 +00:00
|
|
|
builder.RegisterType<Autoproxy>().AsSelf();
|
|
|
|
builder.RegisterType<Fun>().AsSelf();
|
2020-06-29 21:51:12 +00:00
|
|
|
builder.RegisterType<Groups>().AsSelf();
|
2020-02-01 12:03:02 +00:00
|
|
|
builder.RegisterType<Help>().AsSelf();
|
|
|
|
builder.RegisterType<ImportExport>().AsSelf();
|
|
|
|
builder.RegisterType<Member>().AsSelf();
|
|
|
|
builder.RegisterType<MemberAvatar>().AsSelf();
|
|
|
|
builder.RegisterType<MemberEdit>().AsSelf();
|
|
|
|
builder.RegisterType<MemberProxy>().AsSelf();
|
|
|
|
builder.RegisterType<Misc>().AsSelf();
|
|
|
|
builder.RegisterType<ServerConfig>().AsSelf();
|
|
|
|
builder.RegisterType<Switch>().AsSelf();
|
2020-02-12 14:16:19 +00:00
|
|
|
builder.RegisterType<System>().AsSelf();
|
2020-02-01 12:03:02 +00:00
|
|
|
builder.RegisterType<SystemEdit>().AsSelf();
|
|
|
|
builder.RegisterType<SystemFront>().AsSelf();
|
|
|
|
builder.RegisterType<SystemLink>().AsSelf();
|
|
|
|
builder.RegisterType<SystemList>().AsSelf();
|
|
|
|
builder.RegisterType<Token>().AsSelf();
|
2020-01-26 00:27:45 +00:00
|
|
|
|
|
|
|
// Bot core
|
|
|
|
builder.RegisterType<Bot>().AsSelf().SingleInstance();
|
2020-05-01 23:52:52 +00:00
|
|
|
builder.RegisterType<MessageCreated>().As<IEventHandler<MessageCreateEventArgs>>();
|
|
|
|
builder.RegisterType<MessageDeleted>().As<IEventHandler<MessageDeleteEventArgs>>().As<IEventHandler<MessageBulkDeleteEventArgs>>();
|
|
|
|
builder.RegisterType<MessageEdited>().As<IEventHandler<MessageUpdateEventArgs>>();
|
|
|
|
builder.RegisterType<ReactionAdded>().As<IEventHandler<MessageReactionAddEventArgs>>();
|
2020-01-26 00:27:45 +00:00
|
|
|
|
2020-05-05 14:03:46 +00:00
|
|
|
// Event handler queue
|
|
|
|
builder.RegisterType<HandlerQueue<MessageCreateEventArgs>>().AsSelf().SingleInstance();
|
|
|
|
builder.RegisterType<HandlerQueue<MessageReactionAddEventArgs>>().AsSelf().SingleInstance();
|
|
|
|
|
2020-01-26 00:27:45 +00:00
|
|
|
// Bot services
|
|
|
|
builder.RegisterType<EmbedService>().AsSelf().SingleInstance();
|
|
|
|
builder.RegisterType<ProxyService>().AsSelf().SingleInstance();
|
|
|
|
builder.RegisterType<LogChannelService>().AsSelf().SingleInstance();
|
|
|
|
builder.RegisterType<DataFileService>().AsSelf().SingleInstance();
|
|
|
|
builder.RegisterType<WebhookExecutorService>().AsSelf().SingleInstance();
|
|
|
|
builder.RegisterType<WebhookCacheService>().AsSelf().SingleInstance();
|
|
|
|
builder.RegisterType<ShardInfoService>().AsSelf().SingleInstance();
|
|
|
|
builder.RegisterType<CpuStatService>().AsSelf().SingleInstance();
|
|
|
|
builder.RegisterType<PeriodicStatCollector>().AsSelf().SingleInstance();
|
2020-02-12 13:21:48 +00:00
|
|
|
builder.RegisterType<LastMessageCacheService>().AsSelf().SingleInstance();
|
2020-02-14 23:12:03 +00:00
|
|
|
builder.RegisterType<LoggerCleanService>().AsSelf().SingleInstance();
|
2020-01-26 00:27:45 +00:00
|
|
|
|
|
|
|
// Sentry stuff
|
|
|
|
builder.Register(_ => new Scope(null)).AsSelf().InstancePerLifetimeScope();
|
2020-05-02 14:00:43 +00:00
|
|
|
builder.RegisterType<SentryEnricher>()
|
|
|
|
.As<ISentryEnricher<MessageCreateEventArgs>>()
|
|
|
|
.As<ISentryEnricher<MessageDeleteEventArgs>>()
|
|
|
|
.As<ISentryEnricher<MessageUpdateEventArgs>>()
|
|
|
|
.As<ISentryEnricher<MessageBulkDeleteEventArgs>>()
|
|
|
|
.As<ISentryEnricher<MessageReactionAddEventArgs>>()
|
|
|
|
.SingleInstance();
|
2020-06-11 21:20:46 +00:00
|
|
|
|
|
|
|
// Proxy stuff
|
2020-06-12 18:29:50 +00:00
|
|
|
builder.RegisterType<ProxyMatcher>().AsSelf().SingleInstance();
|
2020-06-11 21:20:46 +00:00
|
|
|
builder.RegisterType<ProxyTagParser>().AsSelf().SingleInstance();
|
2020-04-28 22:05:26 +00:00
|
|
|
|
2020-01-26 00:27:45 +00:00
|
|
|
// Utils
|
|
|
|
builder.Register(c => new HttpClient
|
|
|
|
{
|
|
|
|
Timeout = TimeSpan.FromSeconds(5)
|
|
|
|
}).AsSelf().SingleInstance();
|
2020-06-06 23:30:19 +00:00
|
|
|
builder.RegisterInstance(SystemClock.Instance).As<IClock>();
|
2020-08-26 22:07:00 +00:00
|
|
|
|
|
|
|
builder.RegisterType<DiscordRequestObserver>().AsSelf().SingleInstance();
|
2020-01-26 00:27:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|