From 9edbd8535a827420f717133963ffdbdf52b153de Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 14 Feb 2017 20:26:48 +0100 Subject: [PATCH] protection commands localized --- .../Commands/ProtectionCommands.cs | 76 ++++++------- .../Resources/ResponseStrings.Designer.cs | 100 ++++++++++++++++++ src/NadekoBot/Resources/ResponseStrings.resx | 34 ++++++ 3 files changed, 172 insertions(+), 38 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs b/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs index ed85c42d..0cc02896 100644 --- a/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/ProtectionCommands.cs @@ -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 RaidUsers { get; set; } = new ConcurrentHashSet(); - - 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 UserStats { get; set; } = new ConcurrentDictionary(); - - 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 _antiSpamGuilds = new ConcurrentDictionary(); - 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") diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index 042557ed..ee7d0001 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -447,6 +447,78 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Active Protections. + /// + public static string administration_prot_active { + get { + return ResourceManager.GetString("administration_prot_active", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} has been **disabled** on this server.. + /// + public static string administration_prot_disable { + get { + return ResourceManager.GetString("administration_prot_disable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} Enabled. + /// + public static string administration_prot_enable { + get { + return ResourceManager.GetString("administration_prot_enable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Error. I need ManageRoles permission. + /// + public static string administration_prot_error { + get { + return ResourceManager.GetString("administration_prot_error", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No protections enabled.. + /// + public static string administration_prot_none { + get { + return ResourceManager.GetString("administration_prot_none", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User threshold must be between {0} and {1}.. + /// + public static string administration_raid_cnt { + get { + return ResourceManager.GetString("administration_raid_cnt", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If {0} or more users join within {1} seconds, I will {2} them.. + /// + public static string administration_raid_stats { + get { + return ResourceManager.GetString("administration_raid_stats", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Time must be between {0} and {1} seconds.. + /// + public static string administration_raid_time { + get { + return ResourceManager.GetString("administration_raid_time", resourceCulture); + } + } + /// /// Looks up a localized string similar to Removed the playing message: {0}. /// @@ -511,6 +583,34 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to {0} will ignore this channel.. + /// + public static string administration_spam_ignore { + get { + return ResourceManager.GetString("administration_spam_ignore", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} will no longer ignore this channel.. + /// + public static string administration_spam_not_ignore { + get { + return ResourceManager.GetString("administration_spam_not_ignore", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If a user posts {0} same messages in a row, I will {1} them. + /// __IgnoredChannels__: {2}. + /// + public static string administration_spam_stats { + get { + return ResourceManager.GetString("administration_spam_stats", resourceCulture); + } + } + /// /// Looks up a localized string similar to Text Channel Destroyed . /// diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index 0f7e0cae..45a93e60 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -431,6 +431,30 @@ Old Topic + + Active Protections + + + {0} has been **disabled** on this server. + + + {0} Enabled + + + Error. I need ManageRoles permission + + + No protections enabled. + + + User threshold must be between {0} and {1}. + + + If {0} or more users join within {1} seconds, I will {2} them. + + + Time must be between {0} and {1} seconds. + Removed the playing message: {0} @@ -454,6 +478,16 @@ soft-banned (kicked) PLURAL + + {0} will ignore this channel. + + + {0} will no longer ignore this channel. + + + If a user posts {0} same messages in a row, I will {1} them. + __IgnoredChannels__: {2} + Text Channel Destroyed