mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-13 17:26:08 +03:00
Merge branch 'master' into onemethodformute
This commit is contained in:
commit
e02b934221
3 changed files with 44 additions and 1 deletions
|
@ -41,7 +41,7 @@ public class GuildLoadedResponder : IResponder<IGuildCreate>
|
|||
}
|
||||
|
||||
var guild = gatewayEvent.Guild.AsT0;
|
||||
_logger.LogInformation("Joined guild \"{Name}\"", guild.Name);
|
||||
_logger.LogInformation("Joined guild {ID} (\"{Name}\")", guild.ID, guild.Name);
|
||||
|
||||
var data = await _guildData.GetData(guild.ID, ct);
|
||||
var cfg = data.Settings;
|
||||
|
|
38
src/Responders/GuildUnloadedResponder.cs
Normal file
38
src/Responders/GuildUnloadedResponder.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Handles removing guild ID from <see cref="GuildData" /> if the guild becomes unavailable.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public class GuildUnloadedResponder : IResponder<IGuildDelete>
|
||||
{
|
||||
private readonly GuildDataService _guildData;
|
||||
private readonly ILogger<GuildUnloadedResponder> _logger;
|
||||
|
||||
public GuildUnloadedResponder(
|
||||
GuildDataService guildData, ILogger<GuildUnloadedResponder> logger)
|
||||
{
|
||||
_guildData = guildData;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task<Result> RespondAsync(IGuildDelete gatewayEvent, CancellationToken ct = default)
|
||||
{
|
||||
var guildId = gatewayEvent.ID;
|
||||
var isDataRemoved = _guildData.UnloadGuildData(guildId);
|
||||
if (isDataRemoved)
|
||||
{
|
||||
_logger.LogInformation("Left guild {GuildId}", guildId);
|
||||
}
|
||||
|
||||
return Task.FromResult(Result.FromSuccess());
|
||||
}
|
||||
}
|
|
@ -142,4 +142,9 @@ public sealed class GuildDataService : IHostedService
|
|||
{
|
||||
return _datas.Keys;
|
||||
}
|
||||
|
||||
public bool UnloadGuildData(Snowflake id)
|
||||
{
|
||||
return _datas.TryRemove(id, out _);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue