-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
86 lines (72 loc) · 3.29 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using Disqord.Bot;
using Disqord.Bot.Hosting;
using Disqord.Gateway;
using Humanizer.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Qmmands;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;
using System;
using System.Globalization;
using System.Threading.Tasks;
using TarkovItemBot.Options;
using TarkovItemBot.Services;
using TarkovItemBot.Services.TarkovDatabase;
using TarkovItemBot.Services.TarkovDatabaseSearch;
using TarkovItemBot.Services.TarkovTools;
namespace TarkovItemBot
{
class Program
{
static async Task Main()
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Console(theme: ConsoleTheme.None)
.CreateLogger();
var hostBuilder = Host.CreateDefaultBuilder()
.UseSerilog()
.ConfigureAppConfiguration((context, config) =>
{
config.AddEnvironmentVariables("TarkovItemBot_");
})
.ConfigureDiscordBot((context, bot) =>
{
bot.Token = context.Configuration["Bot:Token"];
bot.Prefixes = new[] { context.Configuration["Bot:Prefix"] };
bot.Intents &= ~GatewayIntents.Members;
bot.Intents &= ~GatewayIntents.MessageContent;
})
.ConfigureServices((context, services) =>
{
//Config
services.Configure<BotOptions>(context.Configuration.GetSection("Bot"));
services.Configure<TarkovDatabaseOptions>(context.Configuration.GetSection("TarkovDatabase"));
services.Configure<TarkovToolsOptions>(context.Configuration.GetSection("TarkovTools"));
// Cache
services.AddMemoryCache();
// Tarkov Database
services.AddHttpClient<TarkovDatabaseAuthClient>();
services.AddScoped<TarkovDatabaseTokenCache>();
services.AddTransient<TarkovDatabaseTokenHandler>();
// TODO: Ratelimit from config
services.AddHttpClient<TarkovDatabaseClient>().AddHttpMessageHandler(_ => new RateLimitHandler(500, TimeSpan.FromMinutes(1)))
.AddHttpMessageHandler<TarkovDatabaseTokenHandler>();
// Tarkov Database Search
services.AddHttpClient<TarkovSearchAuthClient>();
services.AddScoped<TarkovSearchTokenCache>();
services.AddTransient<TarkovSearchTokenHandler>();
// TODO: Ratelimit from config
services.AddHttpClient<TarkovSearchClient>().AddHttpMessageHandler(_ => new RateLimitHandler(100, TimeSpan.FromSeconds(10)))
.AddHttpMessageHandler<TarkovSearchTokenHandler>();
services.AddHttpClient<TarkovToolsClient>();
services.AddMemoryCache();
services.AddSingleton<PresenceService>();
services.AddSingleton<SlashMigrationService>();
});
await hostBuilder.RunConsoleAsync();
}
}
}