public Bot(IOptionsMonitor <BotConfiguration> options, IHubContext <MonitorHub> hubContext) { this.gameStateManager = new GameStateManager(); this.options = options ?? throw new ArgumentNullException(nameof(options)); this.dbActionFactory = new SqliteDatabaseActionFactory(this.options.CurrentValue.DatabaseDataSource); this.readerRejoinedMap = new Dictionary <IGuildUser, bool>(); DiscordSocketConfig clientConfig = new DiscordSocketConfig() { // May not be needed MessageCacheSize = 1024 * 16 }; this.client = new DiscordSocketClient(clientConfig); IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(this.client); serviceCollection.AddSingleton(this.gameStateManager); serviceCollection.AddSingleton(this.options); serviceCollection.AddSingleton(this.dbActionFactory); serviceCollection.AddSingleton <IFileScoresheetGenerator>(new ExcelFileScoresheetGenerator()); IGoogleSheetsApi googleSheetsApi = new GoogleSheetsApi(this.options); serviceCollection.AddSingleton <IGoogleSheetsGeneratorFactory>( new GoogleSheetsGeneratorFactory(googleSheetsApi)); this.serviceProvider = serviceCollection.BuildServiceProvider(); this.commandService = new CommandService(new CommandServiceConfig() { CaseSensitiveCommands = false, LogLevel = LogSeverity.Info, DefaultRunMode = RunMode.Async, }); this.commandService.Log += this.OnLogAsync; this.logger = Log.ForContext(this.GetType()); this.discordNetEventLogger = new DiscordNetEventLogger(this.client, this.commandService); Task.WaitAll(this.commandService.AddModulesAsync(Assembly.GetExecutingAssembly(), this.serviceProvider)); this.messageHandler = new MessageHandler( this.options, this.dbActionFactory, hubContext, this.logger); this.client.MessageReceived += this.OnMessageCreated; this.client.GuildMemberUpdated += this.OnPresenceUpdated; this.client.JoinedGuild += this.OnGuildJoined; this.configurationChangeCallback = this.options.OnChange((configuration, value) => { this.logger.Information("Configuration has been reloaded"); }); }
public Bot(IOptionsMonitor <BotConfiguration> options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } this.gameStateManager = new GameStateManager(); this.options = options; // TODO: Rewrite this so that // #1: buzz emojis are server-dependent, since emojis are // #2: This can be updated if the config file is refreshed. this.buzzEmojisRegex = BuildBuzzEmojiRegexes(this.options.CurrentValue); this.readerRejoinedMap = new Dictionary <IGuildUser, bool>(); DiscordSocketConfig clientConfig = new DiscordSocketConfig() { // May not be needed MessageCacheSize = 1024 * 16 }; this.client = new DiscordSocketClient(clientConfig); IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(this.client); serviceCollection.AddSingleton(this.gameStateManager); serviceCollection.AddSingleton(this.options); this.serviceProvider = serviceCollection.BuildServiceProvider(); this.commandService = new CommandService(new CommandServiceConfig() { CaseSensitiveCommands = false, LogLevel = LogSeverity.Info, }); this.logger = Log.ForContext(this.GetType()); this.discordNetEventLogger = new DiscordNetEventLogger(this.client, this.commandService); Task.WaitAll(this.commandService.AddModulesAsync(Assembly.GetExecutingAssembly(), this.serviceProvider)); this.client.MessageReceived += this.OnMessageCreated; this.client.GuildMemberUpdated += this.OnPresenceUpdated; this.configurationChangeCallback = this.options.OnChange((configuration, value) => { this.logger.Information("Configuration has been reloaded"); }); }