protection commands localized
This commit is contained in:
parent
b890506de6
commit
9edbd8535a
@ -4,12 +4,10 @@ using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -26,12 +24,8 @@ namespace NadekoBot.Modules.Administration
|
||||
public class AntiRaidStats
|
||||
{
|
||||
public AntiRaidSetting AntiRaidSettings { get; set; }
|
||||
public int UsersCount { get; set; } = 0;
|
||||
public int UsersCount { get; set; }
|
||||
public ConcurrentHashSet<IGuildUser> RaidUsers { get; set; } = new ConcurrentHashSet<IGuildUser>();
|
||||
|
||||
public override string ToString() =>
|
||||
$"If **{AntiRaidSettings.UserThreshold}** or more users join within **{AntiRaidSettings.Seconds}** seconds," +
|
||||
$" I will **{AntiRaidSettings.Action}** them.";
|
||||
}
|
||||
|
||||
public class AntiSpamStats
|
||||
@ -39,16 +33,6 @@ namespace NadekoBot.Modules.Administration
|
||||
public AntiSpamSetting AntiSpamSettings { get; set; }
|
||||
public ConcurrentDictionary<ulong, UserSpamStats> UserStats { get; set; }
|
||||
= new ConcurrentDictionary<ulong, UserSpamStats>();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var ignoredString = string.Join(", ", AntiSpamSettings.IgnoredChannels.Select(c => $"<#{c.ChannelId}>"));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ignoredString))
|
||||
ignoredString = "none";
|
||||
return $"If a user posts **{AntiSpamSettings.MessageThreshold}** same messages in a row, I will **{AntiSpamSettings.Action}** them."
|
||||
+ $"\n\t__IgnoredChannels__: {ignoredString}";
|
||||
}
|
||||
}
|
||||
|
||||
public class UserSpamStats
|
||||
@ -84,7 +68,7 @@ namespace NadekoBot.Modules.Administration
|
||||
private static readonly ConcurrentDictionary<ulong, AntiSpamStats> _antiSpamGuilds =
|
||||
new ConcurrentDictionary<ulong, AntiSpamStats>();
|
||||
|
||||
private static Logger _log { get; }
|
||||
private new static readonly Logger _log;
|
||||
|
||||
static ProtectionCommands()
|
||||
{
|
||||
@ -141,7 +125,10 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
@ -175,7 +162,10 @@ namespace NadekoBot.Modules.Administration
|
||||
--settings.UsersCount;
|
||||
|
||||
}
|
||||
catch { }
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
@ -219,13 +209,27 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex, "I can't apply punishment"); }
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
await LogCommands.TriggeredAntiProtection(gus, action, pt).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private string GetAntiSpamString(AntiSpamStats stats)
|
||||
{
|
||||
var ignoredString = string.Join(", ", stats.AntiSpamSettings.IgnoredChannels.Select(c => $"<#{c.ChannelId}>"));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ignoredString))
|
||||
ignoredString = "none";
|
||||
return GetText("spam_stats",
|
||||
Format.Bold(stats.AntiSpamSettings.MessageThreshold.ToString()),
|
||||
Format.Bold(stats.AntiSpamSettings.Action.ToString()),
|
||||
ignoredString);
|
||||
}
|
||||
|
||||
private string GetAntiRaidString(AntiRaidStats stats) => GetText("raid_stats",
|
||||
Format.Bold(stats.AntiRaidSettings.UserThreshold.ToString()),
|
||||
Format.Bold(stats.AntiRaidSettings.Seconds.ToString()),
|
||||
Format.Bold(stats.AntiRaidSettings.Action.ToString()));
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@ -234,13 +238,13 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
if (userThreshold < 2 || userThreshold > 30)
|
||||
{
|
||||
await Context.Channel.SendErrorAsync("❗️User threshold must be between **2** and **30**.").ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("raid_cnt", 2, 30).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (seconds < 2 || seconds > 300)
|
||||
{
|
||||
await Context.Channel.SendErrorAsync("❗️Time must be between **2** and **300** seconds.").ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("raid_time", 2, 300).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -254,7 +258,7 @@ namespace NadekoBot.Modules.Administration
|
||||
gc.AntiRaidSetting = null;
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
await Context.Channel.SendConfirmAsync("**Anti-Raid** feature has been **disabled** on this server.").ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("prot_disable", "Anti-Raid").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -264,10 +268,8 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Context.Channel.SendConfirmAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" +
|
||||
"or create 'nadeko-mute' role with disabled SendMessages and try again.")
|
||||
.ConfigureAwait(false);
|
||||
_log.Warn(ex);
|
||||
await ReplyErrorLocalized("prot_error").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -291,7 +293,7 @@ namespace NadekoBot.Modules.Administration
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await Context.Channel.SendConfirmAsync("Anti-Raid Enabled", $"{Context.User.Mention} {stats.ToString()}")
|
||||
await Context.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Raid"), $"{Context.User.Mention} {GetAntiRaidString(stats)}")
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@ -314,7 +316,7 @@ namespace NadekoBot.Modules.Administration
|
||||
gc.AntiSpamSetting = null;
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
await Context.Channel.SendConfirmAsync("**Anti-Spam** has been **disabled** on this server.").ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("prot_disable", "Anti-Spam").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -324,10 +326,8 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Context.Channel.SendErrorAsync("⚠️ Failed creating a mute role. Give me ManageRoles permission" +
|
||||
"or create 'nadeko-mute' role with disabled SendMessages and try again.")
|
||||
.ConfigureAwait(false);
|
||||
_log.Warn(ex);
|
||||
await ReplyErrorLocalized("prot_error").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -350,7 +350,7 @@ namespace NadekoBot.Modules.Administration
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await Context.Channel.SendConfirmAsync("Anti-Spam Enabled", $"{Context.User.Mention} {stats.ToString()}").ConfigureAwait(false);
|
||||
await Context.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Spam"), $"{Context.User.Mention} {GetAntiSpamString(stats)}").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@ -392,9 +392,9 @@ namespace NadekoBot.Modules.Administration
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
if (added)
|
||||
await Context.Channel.SendConfirmAsync("Anti-Spam will ignore this channel.").ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("spam_ignore", "Anti-Spam").ConfigureAwait(false);
|
||||
else
|
||||
await Context.Channel.SendConfirmAsync("Anti-Spam will no longer ignore this channel.").ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("spam_not_ignore", "Anti-Spam").ConfigureAwait(false);
|
||||
|
||||
}
|
||||
|
||||
@ -410,12 +410,12 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
if (spam == null && raid == null)
|
||||
{
|
||||
await Context.Channel.SendConfirmAsync("No protections enabled.");
|
||||
await ReplyConfirmLocalized("prot_none").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = new EmbedBuilder().WithOkColor()
|
||||
.WithTitle("Protections Enabled");
|
||||
.WithTitle(GetText("prot_active"));
|
||||
|
||||
if (spam != null)
|
||||
embed.AddField(efb => efb.WithName("Anti-Spam")
|
||||
|
100
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
100
src/NadekoBot/Resources/ResponseStrings.Designer.cs
generated
@ -447,6 +447,78 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Active Protections.
|
||||
/// </summary>
|
||||
public static string administration_prot_active {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_prot_active", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0} has been **disabled** on this server..
|
||||
/// </summary>
|
||||
public static string administration_prot_disable {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_prot_disable", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0} Enabled.
|
||||
/// </summary>
|
||||
public static string administration_prot_enable {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_prot_enable", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error. I need ManageRoles permission.
|
||||
/// </summary>
|
||||
public static string administration_prot_error {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_prot_error", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No protections enabled..
|
||||
/// </summary>
|
||||
public static string administration_prot_none {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_prot_none", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to User threshold must be between {0} and {1}..
|
||||
/// </summary>
|
||||
public static string administration_raid_cnt {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_raid_cnt", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to If {0} or more users join within {1} seconds, I will {2} them..
|
||||
/// </summary>
|
||||
public static string administration_raid_stats {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_raid_stats", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Time must be between {0} and {1} seconds..
|
||||
/// </summary>
|
||||
public static string administration_raid_time {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_raid_time", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Removed the playing message: {0}.
|
||||
/// </summary>
|
||||
@ -511,6 +583,34 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0} will ignore this channel..
|
||||
/// </summary>
|
||||
public static string administration_spam_ignore {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_spam_ignore", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {0} will no longer ignore this channel..
|
||||
/// </summary>
|
||||
public static string administration_spam_not_ignore {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_spam_not_ignore", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to If a user posts {0} same messages in a row, I will {1} them.
|
||||
/// __IgnoredChannels__: {2}.
|
||||
/// </summary>
|
||||
public static string administration_spam_stats {
|
||||
get {
|
||||
return ResourceManager.GetString("administration_spam_stats", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Text Channel Destroyed .
|
||||
/// </summary>
|
||||
|
@ -431,6 +431,30 @@
|
||||
<data name="administration_old_topic" xml:space="preserve">
|
||||
<value>Old Topic</value>
|
||||
</data>
|
||||
<data name="administration_prot_active" xml:space="preserve">
|
||||
<value>Active Protections</value>
|
||||
</data>
|
||||
<data name="administration_prot_disable" xml:space="preserve">
|
||||
<value>{0} has been **disabled** on this server.</value>
|
||||
</data>
|
||||
<data name="administration_prot_enable" xml:space="preserve">
|
||||
<value>{0} Enabled</value>
|
||||
</data>
|
||||
<data name="administration_prot_error" xml:space="preserve">
|
||||
<value>Error. I need ManageRoles permission</value>
|
||||
</data>
|
||||
<data name="administration_prot_none" xml:space="preserve">
|
||||
<value>No protections enabled.</value>
|
||||
</data>
|
||||
<data name="administration_raid_cnt" xml:space="preserve">
|
||||
<value>User threshold must be between {0} and {1}.</value>
|
||||
</data>
|
||||
<data name="administration_raid_stats" xml:space="preserve">
|
||||
<value>If {0} or more users join within {1} seconds, I will {2} them.</value>
|
||||
</data>
|
||||
<data name="administration_raid_time" xml:space="preserve">
|
||||
<value>Time must be between {0} and {1} seconds.</value>
|
||||
</data>
|
||||
<data name="administration_reprm" xml:space="preserve">
|
||||
<value>Removed the playing message: {0}</value>
|
||||
</data>
|
||||
@ -454,6 +478,16 @@
|
||||
<value>soft-banned (kicked)</value>
|
||||
<comment>PLURAL</comment>
|
||||
</data>
|
||||
<data name="administration_spam_ignore" xml:space="preserve">
|
||||
<value>{0} will ignore this channel.</value>
|
||||
</data>
|
||||
<data name="administration_spam_not_ignore" xml:space="preserve">
|
||||
<value>{0} will no longer ignore this channel.</value>
|
||||
</data>
|
||||
<data name="administration_spam_stats" xml:space="preserve">
|
||||
<value>If a user posts {0} same messages in a row, I will {1} them.
|
||||
__IgnoredChannels__: {2}</value>
|
||||
</data>
|
||||
<data name="administration_text_chan_created" xml:space="preserve">
|
||||
<value>Text Channel Destroyed </value>
|
||||
</data>
|
||||
|
Loading…
Reference in New Issue
Block a user