mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
Fix mute role returning when rejoining server (#121)
Closes #117 --------- Signed-off-by: Macintosh II <mctaylxrs@outlook.com> Co-authored-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
e907930623
commit
4e4e60f845
1 changed files with 29 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
using Boyfriend.Data;
|
using Boyfriend.Data;
|
||||||
using Boyfriend.Services;
|
using Boyfriend.Services;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
@ -5,6 +6,7 @@ using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||||
using Remora.Discord.API.Abstractions.Rest;
|
using Remora.Discord.API.Abstractions.Rest;
|
||||||
using Remora.Discord.Extensions.Embeds;
|
using Remora.Discord.Extensions.Embeds;
|
||||||
using Remora.Discord.Gateway.Responders;
|
using Remora.Discord.Gateway.Responders;
|
||||||
|
using Remora.Rest.Core;
|
||||||
using Remora.Results;
|
using Remora.Results;
|
||||||
|
|
||||||
namespace Boyfriend.Responders;
|
namespace Boyfriend.Responders;
|
||||||
|
@ -40,15 +42,10 @@ public class GuildMemberJoinedResponder : IResponder<IGuildMemberAdd>
|
||||||
var cfg = data.Settings;
|
var cfg = data.Settings;
|
||||||
var memberData = data.GetOrCreateMemberData(user.ID);
|
var memberData = data.GetOrCreateMemberData(user.ID);
|
||||||
|
|
||||||
if (GuildSettings.ReturnRolesOnRejoin.Get(cfg))
|
var returnRolesResult = await TryReturnRolesAsync(cfg, memberData, gatewayEvent.GuildID, user.ID, ct);
|
||||||
|
if (!returnRolesResult.IsSuccess)
|
||||||
{
|
{
|
||||||
var result = await _guildApi.ModifyGuildMemberAsync(
|
return Result.FromError(returnRolesResult.Error);
|
||||||
gatewayEvent.GuildID, user.ID,
|
|
||||||
roles: memberData.Roles.ConvertAll(r => r.ToSnowflake()), ct: ct);
|
|
||||||
if (!result.IsSuccess)
|
|
||||||
{
|
|
||||||
return Result.FromError(result.Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GuildSettings.PublicFeedbackChannel.Get(cfg).Empty()
|
if (GuildSettings.PublicFeedbackChannel.Get(cfg).Empty()
|
||||||
|
@ -83,4 +80,28 @@ public class GuildMemberJoinedResponder : IResponder<IGuildMemberAdd>
|
||||||
GuildSettings.PublicFeedbackChannel.Get(cfg), embeds: new[] { built },
|
GuildSettings.PublicFeedbackChannel.Get(cfg), embeds: new[] { built },
|
||||||
allowedMentions: Boyfriend.NoMentions, ct: ct);
|
allowedMentions: Boyfriend.NoMentions, ct: ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<Result> TryReturnRolesAsync(
|
||||||
|
JsonNode cfg, MemberData memberData, Snowflake guildId, Snowflake userId, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (!GuildSettings.ReturnRolesOnRejoin.Get(cfg))
|
||||||
|
{
|
||||||
|
return Result.FromSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
var assignRoles = new List<Snowflake>();
|
||||||
|
|
||||||
|
if (memberData.MutedUntil is null || !GuildSettings.RemoveRolesOnMute.Get(cfg))
|
||||||
|
{
|
||||||
|
assignRoles.AddRange(memberData.Roles.ConvertAll(r => r.ToSnowflake()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memberData.MutedUntil is not null)
|
||||||
|
{
|
||||||
|
assignRoles.Add(GuildSettings.MuteRole.Get(cfg));
|
||||||
|
}
|
||||||
|
|
||||||
|
return await _guildApi.ModifyGuildMemberAsync(
|
||||||
|
guildId, userId, roles: assignRoles, ct: ct);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue