Finalized some things. closes #183 and #1059

This commit is contained in:
Kwoth 2017-03-30 20:34:40 +02:00
parent 324360073b
commit 9cf03a1fb4
3 changed files with 54 additions and 11 deletions

View File

@ -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<PunishmentAction?> 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<WarningPunishment> 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]

View File

@ -1702,6 +1702,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to User {0} has been warned and {1} punishment has been applied..
/// </summary>
public static string administration_user_warned_and_punished {
get {
return ResourceManager.GetString("administration_user_warned_and_punished", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Username.
/// </summary>
@ -1900,6 +1909,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to No punishments set..
/// </summary>
public static string administration_warnpl_none {
get {
return ResourceManager.GetString("administration_warnpl_none", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User {0} from text chat.
/// </summary>

View File

@ -2296,6 +2296,9 @@ Owner ID: {2}</value>
<data name="administration_user_warned" xml:space="preserve">
<value>User {0} has been warned.</value>
</data>
<data name="administration_user_warned_and_punished" xml:space="preserve">
<value>User {0} has been warned and {1} punishment has been applied.</value>
</data>
<data name="administration_warned_on" xml:space="preserve">
<value>Warned on {0} server</value>
</data>
@ -2311,6 +2314,9 @@ Owner ID: {2}</value>
<data name="administration_warnlog_for" xml:space="preserve">
<value>Warnlog for {0}</value>
</data>
<data name="administration_warnpl_none" xml:space="preserve">
<value>No punishments set.</value>
</data>
<data name="administration_warn_cleared_by" xml:space="preserve">
<value>cleared by {0}</value>
</data>