1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-02-26 00:42:39 +03:00

Permission validation, PunishmentOption and that's it...?

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
Macintxsh 2024-04-08 16:38:03 +03:00
parent 422becf6c6
commit 1e9e1b4bb2
Signed by: mctaylors
GPG key ID: 7181BEBE676903C1
6 changed files with 61 additions and 3 deletions

View file

@ -798,4 +798,7 @@
<data name="WarnThresholdExceededDescription" xml:space="preserve">
<value>Increase the Warn Threshold or set a Warn Punishment.</value>
</data>
<data name="InvalidWarnPunishment" xml:space="preserve">
<value>Invalid Warn Punishment is set.</value>
</data>
</root>

View file

@ -798,4 +798,7 @@
<data name="WarnThresholdExceededDescription" xml:space="preserve">
<value>Увеличьте порог предупреждения или установите наказание за предупреждение.</value>
</data>
<data name="InvalidWarnPunishment" xml:space="preserve">
<value>Установлено неверное наказание за предупреждение.</value>
</data>
</root>

View file

@ -141,6 +141,28 @@ public class WarnCommandGroup : CommandGroup
return await _feedback.SendContextualEmbedResultAsync(errorEmbed, ct: CancellationToken);
}
if (warns.Count + 1 < warnThreshold)
{
return await WarnUserAsync(executor, target, reason, guild, data, channelId, bot, settings,
warns, warnThreshold, warnPunishment, warnDuration, ct);
}
var interactionResult
= await _access.CheckInteractionsAsync(guild.ID, bot.ID, target.ID,
$"{char.ToUpperInvariant(warnPunishment[0])}{warnPunishment[1..]}", ct);
if (!interactionResult.IsSuccess)
{
return ResultExtensions.FromError(interactionResult);
}
if (interactionResult.Entity is not null)
{
var errorEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, bot)
.WithColour(ColorsList.Red).Build();
return await _feedback.SendContextualEmbedResultAsync(errorEmbed, ct: ct);
}
return await WarnUserAsync(executor, target, reason, guild, data, channelId, bot, settings,
warns, warnThreshold, warnPunishment, warnDuration, ct);
}
@ -181,8 +203,7 @@ public class WarnCommandGroup : CommandGroup
_utility.LogAction(settings, channelId, executor, title, description,
target, ColorsList.Yellow, false, ct);
var embed = new EmbedBuilder().WithSmallTitle(
title, target)
var embed = new EmbedBuilder().WithSmallTitle(title, target)
.WithColour(ColorsList.Green).Build();
if (warns.Count >= warnThreshold && warnThreshold is not 0)

View file

@ -12,7 +12,7 @@ public static class GuildSettings
{
public static readonly LanguageOption Language = new("Language", "en");
public static readonly Option<string> WarnPunishment = new("WarnPunishment", "disabled");
public static readonly PunishmentOption WarnPunishment = new("WarnPunishment", "disabled");
/// <summary>
/// Controls what message should be sent in <see cref="PublicFeedbackChannel" /> when a new member joins the guild.

View file

@ -0,0 +1,23 @@
using System.Text.Json.Nodes;
using Remora.Results;
namespace Octobot.Data.Options;
/// <inheritdoc />
public sealed class PunishmentOption : Option<string>
{
private static readonly List<string> AllowedValues =
[
"ban", "kick", "mute", "off", "disable", "disabled"
];
public PunishmentOption(string name, string defaultValue) : base(name, defaultValue) { }
/// <inheritdoc />
public override Result Set(JsonNode settings, string from)
{
return AllowedValues.Contains(from.ToLowerInvariant())
? base.Set(settings, from.ToLowerInvariant())
: new ArgumentInvalidError(nameof(from), Messages.InvalidWarnPunishment);
}
}

View file

@ -1344,5 +1344,13 @@ namespace Octobot {
return ResourceManager.GetString("WarnThresholdExceededDescription", resourceCulture);
}
}
internal static string InvalidWarnPunishment
{
get
{
return ResourceManager.GetString("InvalidWarnPunishment", resourceCulture);
}
}
}
}