Exemple #1
0
 public ChannelRuleService(DiscordSocketClient discord, IJobScheduler scheduler,
                           ChannelRuleSettings config)
     : base(discord)
 {
     _discord        = discord;
     _jobScheduler   = scheduler;
     _discord.Ready -= InitializeServiceAsync;
     _discord.Ready += InitializeServiceAsync;
 }
Exemple #2
0
        public async Task StartupAsync()
        {
            //Set up configuration
            var builder = new ConfigurationBuilder()
                          .SetBasePath(AppContext.BaseDirectory)
                          .AddJsonFile("config.json", optional: false, reloadOnChange: true)
                          .AddJsonFile("config.Local.json", optional: true, reloadOnChange: true);

            _config = builder.Build();

            var discordSettings             = new DiscordSettings();
            var channelRuleSettings         = new ChannelRuleSettings();
            var battleNetApiSettings        = new BattleNetApiSettings();
            var gameStateEmissionSettings   = new GameStateEmissionSettings();
            var gamblingSettings            = new GamblingSettings();
            var voiceChannelTrackerSettings = new VoiceChannelTrackerSettings();
            var guildApplicationSettings    = new GuildApplicationSettings();
            var signupsSettings             = new SignupsSettings();
            var twitterClientSettings       = new TwitterClientSettings();
            var twitterServiceSettings      = new TwitterServiceSettings();
            var storageSettings             = new AzureStorageSettings();
            var announcementServiceSettings = new AnnouncementServiceSettings();
            var warcraftLogsApiSettings     = new WarcraftLogsApiSettings();

            _config.GetSection(nameof(DiscordSettings)).Bind(discordSettings);
            _config.GetSection(nameof(ChannelRuleSettings)).Bind(channelRuleSettings);
            _config.GetSection(nameof(BattleNetApiSettings)).Bind(battleNetApiSettings);
            _config.GetSection(nameof(GameStateEmissionSettings)).Bind(gameStateEmissionSettings);
            _config.GetSection(nameof(GamblingSettings)).Bind(gamblingSettings);
            _config.GetSection(nameof(VoiceChannelTrackerSettings)).Bind(voiceChannelTrackerSettings);
            _config.GetSection(nameof(GuildApplicationSettings)).Bind(guildApplicationSettings);
            _config.GetSection(nameof(SignupsSettings)).Bind(signupsSettings);
            _config.GetSection(nameof(TwitterClientSettings)).Bind(twitterClientSettings);
            _config.GetSection(nameof(TwitterServiceSettings)).Bind(twitterServiceSettings);
            _config.GetSection(nameof(AzureStorageSettings)).Bind(storageSettings);
            _config.GetSection(nameof(AnnouncementServiceSettings)).Bind(announcementServiceSettings);
            _config.GetSection(nameof(WarcraftLogsApiSettings)).Bind(warcraftLogsApiSettings);

            //Set up discord client
            _discord = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel            = LogSeverity.Verbose,
                MessageCacheSize    = 1000,
                AlwaysDownloadUsers = true
            });

            //Set up a service provider with all relevant resources for DI
            IServiceCollection services = new ServiceCollection()
                                          .AddSingleton <DiscordSocketClient>(_discord)
                                          .AddSingleton(discordSettings)
                                          .AddSingleton(channelRuleSettings)
                                          .AddSingleton(battleNetApiSettings)
                                          .AddSingleton(gameStateEmissionSettings)
                                          .AddSingleton(gamblingSettings)
                                          .AddSingleton(voiceChannelTrackerSettings)
                                          .AddSingleton(guildApplicationSettings)
                                          .AddSingleton(signupsSettings)
                                          .AddSingleton(twitterClientSettings)
                                          .AddSingleton(twitterServiceSettings)
                                          .AddSingleton(announcementServiceSettings)
                                          .AddSingleton(storageSettings)
                                          .AddSingleton(warcraftLogsApiSettings)
                                          .AddSingleton <Random>()
                                          .AddSingleton <IJobScheduler, JobScheduler>()
                                          .AddBotServices()
                                          .AddScoped <IWarcraftLogsApi, WarcraftLogsApi>()
                                          .AddScoped <ISpreadsheetClient, GoogleSheetsClient>()
                                          .AddScoped <IRepository <GameTrackMember>, AzureStorageRepository <GameTrackMember> >()
                                          .AddScoped <IRepository <Giveaway>, AzureStorageRepository <Giveaway> >()
                                          .AddScoped <IRepository <GamblingStandings>, AzureStorageRepository <GamblingStandings> >()
                                          .AddScoped <IRepository <Reminder>, AzureStorageRepository <Reminder> >()
                                          .AddScoped <IRepository <Command>, AzureStorageRepository <Command> >()
                                          .AddScoped <IRepository <Statistics>, AzureStorageRepository <Statistics> >()
                                          .AddScoped <IRepository <RaidAttendance>, AzureStorageRepository <RaidAttendance> >()
                                          .AddScoped <IRepository <RaidAttendanceSummary>, AzureStorageRepository <RaidAttendanceSummary> >()
                                          .AddScoped <IRepository <UsersCharacters>, AzureStorageRepository <UsersCharacters> >()
                                          .AddScoped <IRepository <Personality>, AzureStorageRepository <Personality> >()
                                          .AddScoped <IWowheadClient, WowheadClient>()
                                          .AddTransient <TwitterClient>()
                                          .AddLogging(config =>
            {
                config.AddConsole();
                config.AddProvider(new DiscordChannelLoggerProvider(_discord, 124446036637908995, LogLevel.Warning));                         // todo: config the channel id?
            });

            //Build the service provider
            _serviceProvider = services.BuildServiceProvider();


            //Start the desired services
            try
            {
                foreach (var s in services.Where(s => s.ServiceType.BaseType == typeof(BotServiceBase)))
                {
                    _serviceProvider.GetRequiredService(s.ServiceType);
                }

                _serviceProvider.GetRequiredService <AnnouncementService>();                // todo: make this a BotService
            }
            catch (Exception)
            {
            }

            await _serviceProvider.GetRequiredService <StartupService>().StartAsync();

            //          _serviceProvider.GetRequiredService<ILogger<VereesaClient>>().LogWarning(@"`
            //                          Neon's own Discord Bot!
            // ██╗   ██╗███████╗██████╗ ███████╗███████╗███████╗ █████╗
            // ██║   ██║██╔════╝██╔══██╗██╔════╝██╔════╝██╔════╝██╔══██╗
            // ██║   ██║█████╗  ██████╔╝█████╗  █████╗  ███████╗███████║
            // ╚██╗ ██╔╝██╔══╝  ██╔══██╗██╔══╝  ██╔══╝  ╚════██║██╔══██║
            //  ╚████╔╝ ███████╗██║  ██║███████╗███████╗███████║██║  ██║
            //   ╚═══╝  ╚══════╝╚═╝  ╚═╝╚══════╝╚══════╝╚══════╝╚═╝  ╚═╝
            //  I am now accepting your requests!
            // `");
        }