1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-11 08:23:15 +03:00

Synchronize roles only on member data updates (#130)

This PR makes it so that roles in MemberData are updated only in
MemberUpdateService. This reduces possible points of failures,
maintenance burden and reliance on gateway events
This commit is contained in:
Octol1ttle 2023-09-30 20:36:55 +05:00 committed by GitHub
parent 5d278883d5
commit d713b977f0
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 51 deletions

View file

@ -1,33 +0,0 @@
using JetBrains.Annotations;
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 updating <see cref="MemberData.Roles" /> when a guild member is updated.
/// </summary>
[UsedImplicitly]
public class GuildMemberUpdateResponder : IResponder<IGuildMemberUpdate>
{
private readonly GuildDataService _guildData;
public GuildMemberUpdateResponder(GuildDataService guildData)
{
_guildData = guildData;
}
public async Task<Result> RespondAsync(IGuildMemberUpdate gatewayEvent, CancellationToken ct = default)
{
var memberData = await _guildData.GetMemberData(gatewayEvent.GuildID, gatewayEvent.User.ID, ct);
if (memberData.MutedUntil is null)
{
memberData.Roles = gatewayEvent.Roles.ToList().ConvertAll(r => r.Value);
}
return Result.FromSuccess();
}
}