using JetBrains.Annotations; using Microsoft.Extensions.Logging; using Octobot.Data; using Octobot.Services; using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.Gateway.Responders; using Remora.Results; namespace Octobot.Responders; /// /// Handles removing guild ID from if the guild becomes unavailable. /// [UsedImplicitly] public 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); } }