From 9cf03a1fb407cff41fc18917bbf9d73b8d4d4f52 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 30 Mar 2017 20:34:40 +0200 Subject: [PATCH] Finalized some things. closes #183 and #1059 --- .../Commands/UserPunishCommands.cs | 41 ++++++++++++++----- .../Resources/ResponseStrings.Designer.cs | 18 ++++++++ src/NadekoBot/Resources/ResponseStrings.resx | 6 +++ 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs b/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs index 53479589..ded760c2 100644 --- a/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs @@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Administration [Group] public class UserPunishCommands : NadekoSubmodule { - private async Task InternalWarn(IGuild guild, ulong userId, string modName, string reason) + private async Task InternalWarn(IGuild guild, ulong userId, string modName, string reason) { if (string.IsNullOrWhiteSpace(reason)) reason = "-"; @@ -34,20 +34,20 @@ namespace NadekoBot.Modules.Administration Moderator = modName, }; - int warnings; + int warnings = 1; List ps; using (var uow = DbHandler.UnitOfWork()) { ps = uow.GuildConfigs.For(guildId, set => set.Include(x => x.WarnPunishments)) .WarnPunishments; - - uow.Warnings.Add(warn); - warnings = uow.Warnings + warnings += uow.Warnings .For(guildId, userId) .Where(w => !w.Forgiven && w.UserId == userId) .Count(); + uow.Warnings.Add(warn); + uow.Complete(); } @@ -57,7 +57,7 @@ namespace NadekoBot.Modules.Administration { var user = await guild.GetUserAsync(userId); if (user == null) - return; + return null; switch (p.Punishment) { case PunishmentAction.Mute: @@ -72,7 +72,10 @@ namespace NadekoBot.Modules.Administration default: break; } + return p.Punishment; } + + return null; } [NadekoCommand, Usage, Description, Aliases] @@ -89,9 +92,16 @@ namespace NadekoBot.Modules.Administration .ConfigureAwait(false); } catch { } - await InternalWarn(Context.Guild, user.Id, Context.User.ToString(), reason).ConfigureAwait(false); + var punishment = await InternalWarn(Context.Guild, user.Id, Context.User.ToString(), reason).ConfigureAwait(false); - await ReplyConfirmLocalized("user_warned", Format.Bold(user.ToString())).ConfigureAwait(false); + if (punishment == null) + { + await ReplyConfirmLocalized("user_warned", Format.Bold(user.ToString())).ConfigureAwait(false); + } + else + { + await ReplyConfirmLocalized("user_warned_and_punished", Format.Bold(user.ToString()), Format.Bold(punishment.ToString())).ConfigureAwait(false); + } } [NadekoCommand, Usage, Description, Aliases] @@ -146,7 +156,7 @@ namespace NadekoBot.Modules.Administration { var name = GetText("warned_on_by", w.DateAdded.Value.ToString("dd.MM.yyy"), w.DateAdded.Value.ToString("HH:mm"), w.Moderator); if (w.Forgiven) - name = Format.Strikethrough(name) + GetText("warn_cleared_by", w.ForgivenBy); + name = Format.Strikethrough(name) + " " + GetText("warn_cleared_by", w.ForgivenBy); embed.AddField(x => x .WithName(name) @@ -175,7 +185,7 @@ namespace NadekoBot.Modules.Administration } await ReplyConfirmLocalized("warnings_cleared", - (Context.Guild as SocketGuild)?.GetUser(userId)?.ToString() ?? userId.ToString()).ConfigureAwait(false); + Format.Bold((Context.Guild as SocketGuild)?.GetUser(userId)?.ToString() ?? userId.ToString())).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -254,9 +264,18 @@ namespace NadekoBot.Modules.Administration .ToArray(); } + string list; + if (ps.Any()) + { + list = string.Join("\n", ps.Select(x => $"{x.Count} -> {x.Punishment}")); + } + else + { + list = GetText("warnpl_none"); + } await Context.Channel.SendConfirmAsync( GetText("warn_punish_list"), - string.Join("\n", ps.Select(x => $"{x.Count} -> {x.Punishment}"))).ConfigureAwait(false); + list).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index a8e6ed17..34e12752 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -1702,6 +1702,15 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to User {0} has been warned and {1} punishment has been applied.. + /// + public static string administration_user_warned_and_punished { + get { + return ResourceManager.GetString("administration_user_warned_and_punished", resourceCulture); + } + } + /// /// Looks up a localized string similar to Username. /// @@ -1900,6 +1909,15 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to No punishments set.. + /// + public static string administration_warnpl_none { + get { + return ResourceManager.GetString("administration_warnpl_none", resourceCulture); + } + } + /// /// Looks up a localized string similar to User {0} from text chat. /// diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index 9ef50957..a94761da 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -2296,6 +2296,9 @@ Owner ID: {2} User {0} has been warned. + + User {0} has been warned and {1} punishment has been applied. + Warned on {0} server @@ -2311,6 +2314,9 @@ Owner ID: {2} Warnlog for {0} + + No punishments set. + cleared by {0}