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:
parent
422becf6c6
commit
1e9e1b4bb2
6 changed files with 61 additions and 3 deletions
|
@ -798,4 +798,7 @@
|
||||||
<data name="WarnThresholdExceededDescription" xml:space="preserve">
|
<data name="WarnThresholdExceededDescription" xml:space="preserve">
|
||||||
<value>Increase the Warn Threshold or set a Warn Punishment.</value>
|
<value>Increase the Warn Threshold or set a Warn Punishment.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="InvalidWarnPunishment" xml:space="preserve">
|
||||||
|
<value>Invalid Warn Punishment is set.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
|
@ -798,4 +798,7 @@
|
||||||
<data name="WarnThresholdExceededDescription" xml:space="preserve">
|
<data name="WarnThresholdExceededDescription" xml:space="preserve">
|
||||||
<value>Увеличьте порог предупреждения или установите наказание за предупреждение.</value>
|
<value>Увеличьте порог предупреждения или установите наказание за предупреждение.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="InvalidWarnPunishment" xml:space="preserve">
|
||||||
|
<value>Установлено неверное наказание за предупреждение.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
|
@ -141,6 +141,28 @@ public class WarnCommandGroup : CommandGroup
|
||||||
return await _feedback.SendContextualEmbedResultAsync(errorEmbed, ct: CancellationToken);
|
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,
|
return await WarnUserAsync(executor, target, reason, guild, data, channelId, bot, settings,
|
||||||
warns, warnThreshold, warnPunishment, warnDuration, ct);
|
warns, warnThreshold, warnPunishment, warnDuration, ct);
|
||||||
}
|
}
|
||||||
|
@ -181,8 +203,7 @@ public class WarnCommandGroup : CommandGroup
|
||||||
_utility.LogAction(settings, channelId, executor, title, description,
|
_utility.LogAction(settings, channelId, executor, title, description,
|
||||||
target, ColorsList.Yellow, false, ct);
|
target, ColorsList.Yellow, false, ct);
|
||||||
|
|
||||||
var embed = new EmbedBuilder().WithSmallTitle(
|
var embed = new EmbedBuilder().WithSmallTitle(title, target)
|
||||||
title, target)
|
|
||||||
.WithColour(ColorsList.Green).Build();
|
.WithColour(ColorsList.Green).Build();
|
||||||
|
|
||||||
if (warns.Count >= warnThreshold && warnThreshold is not 0)
|
if (warns.Count >= warnThreshold && warnThreshold is not 0)
|
||||||
|
|
|
@ -12,7 +12,7 @@ public static class GuildSettings
|
||||||
{
|
{
|
||||||
public static readonly LanguageOption Language = new("Language", "en");
|
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>
|
/// <summary>
|
||||||
/// Controls what message should be sent in <see cref="PublicFeedbackChannel" /> when a new member joins the guild.
|
/// Controls what message should be sent in <see cref="PublicFeedbackChannel" /> when a new member joins the guild.
|
||||||
|
|
23
src/Data/Options/PunishmentOption.cs
Normal file
23
src/Data/Options/PunishmentOption.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
8
src/Messages.Designer.cs
generated
8
src/Messages.Designer.cs
generated
|
@ -1344,5 +1344,13 @@ namespace Octobot {
|
||||||
return ResourceManager.GetString("WarnThresholdExceededDescription", resourceCulture);
|
return ResourceManager.GetString("WarnThresholdExceededDescription", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string InvalidWarnPunishment
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ResourceManager.GetString("InvalidWarnPunishment", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue