using JetBrains.Annotations; using Microsoft.Extensions.Logging; using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.Gateway.Responders; using Remora.Results; using TeamOctolings.Octobot.Data; using TeamOctolings.Octobot.Services; namespace TeamOctolings.Octobot.Responders; /// /// Handles removing guild ID from if the guild becomes unavailable. /// [UsedImplicitly] public sealed class GuildUnloadedResponder : IResponder { private readonly GuildDataService _guildData; private readonly ILogger _logger; public GuildUnloadedResponder( GuildDataService guildData, ILogger logger) { _guildData = guildData; _logger = logger; } public Task RespondAsync(IGuildDelete gatewayEvent, CancellationToken ct = default) { var guildId = gatewayEvent.ID; var isDataRemoved = _guildData.UnloadGuildData(guildId); if (isDataRemoved) { _logger.LogInformation("Unloaded guild {GuildId}", guildId); } return Task.FromResult(Result.Success); } }