public CommandRefreshWorker(ILogger <CommandRefreshWorker> logger, DiscordSocketClient client, CommandHandlingService commandHandlingService, IOptions <CommandsSettings> commandsSettings) { _logger = logger; _client = client; _commandHandlingService = commandHandlingService; _commandsSettings = commandsSettings.Value; }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureHostConfiguration(config => { var development = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"); var isDev = string.IsNullOrWhiteSpace(development) || development.ToLower() == "development"; if (isDev) { config.AddUserSecrets(Assembly.GetExecutingAssembly()); } }) .ConfigureServices((hostContext, services) => { var commandsSettings = new CommandsSettings(); hostContext.Configuration.GetSection(nameof(CommandsSettings)).Bind(commandsSettings); services.Configure <CommandsSettings>(hostContext.Configuration.GetSection(nameof(CommandsSettings))); services.AddHttpClient <IBrobotService, BrobotService>(configure => { configure.BaseAddress = new Uri(commandsSettings.BaseUrl); configure.DefaultRequestHeaders.Add("x-api-key", commandsSettings.ApiKey); }); services.AddHttpClient <IRandomFactService, RandomFactService>(configure => { configure.BaseAddress = new Uri(commandsSettings.RandomFactBaseUrl); }); services.AddHttpClient <IGiphyService, GiphyService>(configure => { configure.BaseAddress = new Uri(commandsSettings.GiphyBaseUrl); }); var config = new DiscordSocketConfig { AlwaysDownloadUsers = true }; var client = new DiscordSocketClient(config); services.AddSingleton <DiscordSocketClient>(client); services.AddSingleton <CommandService>(); services.AddSingleton <CommandHandlingService>(); services.AddSingleton <Random>(); services.AddHostedService <CommandRefreshWorker>(); });