using Boyfriend.Data.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Remora.Discord.API.Abstractions.Gateway.Commands; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Gateway.Commands; using Remora.Discord.API.Objects; using Remora.Discord.Caching.Extensions; using Remora.Discord.Caching.Services; using Remora.Discord.Commands.Extensions; using Remora.Discord.Gateway; using Remora.Discord.Gateway.Extensions; using Remora.Discord.Hosting.Extensions; using Remora.Discord.Interactivity.Extensions; using Remora.Rest.Core; namespace Boyfriend; public class Boyfriend { public static readonly AllowedMentions NoMentions = new( Array.Empty(), Array.Empty(), Array.Empty()); public static async Task Main(string[] args) { var host = CreateHostBuilder(args).UseConsoleLifetime().Build(); await host.RunAsync(); } private static IHostBuilder CreateHostBuilder(string[] args) { return Host.CreateDefaultBuilder(args) .AddDiscordService( services => { var configuration = services.GetRequiredService(); return configuration.GetValue("BOT_TOKEN") ?? throw new InvalidOperationException( "No bot token has been provided. Set the " + "BOT_TOKEN environment variable to a valid token."); } ).ConfigureServices( (_, services) => { services.Configure( options => { options.Intents |= GatewayIntents.MessageContents | GatewayIntents.GuildMembers | GatewayIntents.GuildScheduledEvents; options.Presence = new UpdatePresence( UserStatus.Online, false, DateTimeOffset.UtcNow, new[] { new Activity("with Remora.Discord", ActivityType.Game) }); }); services.Configure( settings => { settings.SetDefaultAbsoluteExpiration(TimeSpan.FromHours(1)); settings.SetDefaultSlidingExpiration(TimeSpan.FromMinutes(30)); settings.SetAbsoluteExpiration(TimeSpan.FromDays(7)); settings.SetSlidingExpiration(TimeSpan.FromDays(7)); }); services.AddTransient() .AddDiscordCaching() .AddDiscordCommands() .AddInteractivity() .AddInteractionGroup() .AddSingleton(); var responderTypes = typeof(Boyfriend).Assembly .GetExportedTypes() .Where(t => t.IsResponder()); foreach (var responderType in responderTypes) services.AddResponder(responderType); } ).ConfigureLogging( c => c.AddConsole() .AddFilter("System.Net.Http.HttpClient.*.LogicalHandler", LogLevel.Warning) .AddFilter("System.Net.Http.HttpClient.*.ClientHandler", LogLevel.Warning) ); } public static string GetLocalized(string key) { return Messages.ResourceManager.GetString(key, Messages.Culture) ?? key; } }