1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-01 03:29:54 +03:00

Add mute role support & fix /unmute (#109)

- Added support for `MuteRole`, now if you add any role to this setting,
then try to mute a member, all his roles will be removed except for the
one you set in this setting.
- Fixed `/unmute`, that tried to set target's display name to unmute
reason.

---------

Signed-off-by: Macintosh II <mctaylxrs@outlook.com>
This commit is contained in:
Macintxsh 2023-09-21 20:16:09 +03:00 committed by GitHub
parent b796b885a1
commit 1e8b7e5373
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 172 additions and 16 deletions

View file

@ -79,17 +79,9 @@ public sealed partial class MemberUpdateService : BackgroundService
{
var failedResults = new List<Result>();
var id = data.Id.ToSnowflake();
if (DateTimeOffset.UtcNow > data.BannedUntil)
{
var unbanResult = await _guildApi.RemoveGuildBanAsync(
guildId, id, Messages.PunishmentExpired.EncodeHeader(), ct);
if (unbanResult.IsSuccess)
{
data.BannedUntil = null;
}
return unbanResult;
}
var punishmentsResult = await CheckMemberPunishmentsAsync(guildId, id, data, ct);
failedResults.AddIfFailed(punishmentsResult);
if (defaultRole.Value is not 0 && !data.Roles.Contains(defaultRole.Value))
{
@ -125,6 +117,37 @@ public sealed partial class MemberUpdateService : BackgroundService
return failedResults.AggregateErrors();
}
private async Task<Result> CheckMemberPunishmentsAsync(
Snowflake guildId, Snowflake id, MemberData data, CancellationToken ct)
{
if (DateTimeOffset.UtcNow > data.BannedUntil)
{
var unbanResult = await _guildApi.RemoveGuildBanAsync(
guildId, id, Messages.PunishmentExpired.EncodeHeader(), ct);
if (unbanResult.IsSuccess)
{
data.BannedUntil = null;
}
return unbanResult;
}
if (DateTimeOffset.UtcNow > data.MutedUntil)
{
var unmuteResult = await _guildApi.ModifyGuildMemberAsync(
guildId, id, roles: data.Roles.ConvertAll(r => r.ToSnowflake()),
reason: Messages.PunishmentExpired.EncodeHeader(), ct: ct);
if (unmuteResult.IsSuccess)
{
data.MutedUntil = null;
}
return unmuteResult;
}
return Result.FromSuccess();
}
private async Task<Result> FilterNicknameAsync(Snowflake guildId, IUser user, IGuildMember member,
CancellationToken ct)
{