mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-20 00:43:36 +03:00
Resolve conversations pt.2
Signed-off-by: Macintosh II <mctaylxrs@outlook.com>
This commit is contained in:
parent
3c63e19ee0
commit
4f2b793c76
1 changed files with 44 additions and 9 deletions
|
@ -327,19 +327,18 @@ public class MuteCommandGroup : CommandGroup
|
||||||
return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct);
|
return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memberData.MutedUntil is not null)
|
var removeMuteRoleAsync =
|
||||||
|
await RemoveMuteRoleAsync(target, reason, guildId, memberData, user, CancellationToken);
|
||||||
|
if (!removeMuteRoleAsync.IsSuccess)
|
||||||
{
|
{
|
||||||
await _guildApi.ModifyGuildMemberAsync(
|
return Result.FromError(removeMuteRoleAsync.Error);
|
||||||
guildId, target.ID, roles: memberData.Roles.ConvertAll(r => r.ToSnowflake()),
|
|
||||||
reason: $"({user.GetTag()}) {reason}".EncodeHeader(), ct: ct);
|
|
||||||
memberData.MutedUntil = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (communicationDisabledUntil is not null)
|
var removeTimeoutResult =
|
||||||
|
await RemoveTimeoutAsync(target, reason, guildId, communicationDisabledUntil, user, CancellationToken);
|
||||||
|
if (!removeTimeoutResult.IsSuccess)
|
||||||
{
|
{
|
||||||
await _guildApi.ModifyGuildMemberAsync(
|
return Result.FromError(removeTimeoutResult.Error);
|
||||||
guildId, target.ID, reason: $"({user.GetTag()}) {reason}".EncodeHeader(),
|
|
||||||
communicationDisabledUntil: null, ct: ct);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var title = string.Format(Messages.UserUnmuted, target.GetTag());
|
var title = string.Format(Messages.UserUnmuted, target.GetTag());
|
||||||
|
@ -357,4 +356,40 @@ public class MuteCommandGroup : CommandGroup
|
||||||
|
|
||||||
return await _feedback.SendContextualEmbedResultAsync(embed, ct);
|
return await _feedback.SendContextualEmbedResultAsync(embed, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<Result> RemoveMuteRoleAsync(
|
||||||
|
IUser target, string reason, Snowflake guildId, MemberData memberData, IUser user, CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
if (memberData.MutedUntil is null)
|
||||||
|
{
|
||||||
|
return Result.FromSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
var muteResult = await _guildApi.ModifyGuildMemberAsync(
|
||||||
|
guildId, target.ID, roles: memberData.Roles.ConvertAll(r => r.ToSnowflake()),
|
||||||
|
reason: $"({user.GetTag()}) {reason}".EncodeHeader(), ct: ct);
|
||||||
|
if (!muteResult.IsSuccess)
|
||||||
|
{
|
||||||
|
return Result.FromError(muteResult.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
memberData.MutedUntil = null;
|
||||||
|
|
||||||
|
return Result.FromSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<Result> RemoveTimeoutAsync(
|
||||||
|
IUser target, string reason, Snowflake guildId, DateTimeOffset? communicationDisabledUntil,
|
||||||
|
IUser user, CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
if (communicationDisabledUntil is null)
|
||||||
|
{
|
||||||
|
return Result.FromSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
var muteResult = await _guildApi.ModifyGuildMemberAsync(
|
||||||
|
guildId, target.ID, reason: $"({user.GetTag()}) {reason}".EncodeHeader(),
|
||||||
|
communicationDisabledUntil: null, ct: ct);
|
||||||
|
return !muteResult.IsSuccess ? Result.FromError(muteResult.Error) : Result.FromSuccess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue