Added .warn weights, improved .warnlog

This commit is contained in:
Kwoth
2021-11-21 02:01:21 +01:00
parent 0a029a7847
commit 22b452e449
10 changed files with 2733 additions and 12 deletions

View File

@@ -4,6 +4,10 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
## Unreleased ## Unreleased
### Changed
- `.warn` now supports weighted warnings
- `.warnlog` will now show current amount and total amount of warnings
## [3.0.9] - 21.11.2021 ## [3.0.9] - 21.11.2021
### Changed ### Changed

View File

@@ -8,5 +8,6 @@
public bool Forgiven { get; set; } public bool Forgiven { get; set; }
public string ForgivenBy { get; set; } public string ForgivenBy { get; set; }
public string Moderator { get; set; } public string Moderator { get; set; }
public int Weight { get; set; }
} }
} }

View File

@@ -196,10 +196,16 @@ namespace NadekoBot.Services.Database
#endregion #endregion
#region Warnings #region Warnings
var warn = modelBuilder.Entity<Warning>();
modelBuilder.Entity<Warning>(warn =>
{
warn.HasIndex(x => x.GuildId); warn.HasIndex(x => x.GuildId);
warn.HasIndex(x => x.UserId); warn.HasIndex(x => x.UserId);
warn.HasIndex(x => x.DateAdded); warn.HasIndex(x => x.DateAdded);
warn.Property(x => x.Weight)
.HasDefaultValue(1);
});
#endregion #endregion
#region PatreonRewards #region PatreonRewards

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class weightedwarnings : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "Weight",
table: "Warnings",
type: "INTEGER",
nullable: false,
defaultValue: 1);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Weight",
table: "Warnings");
}
}
}

View File

@@ -1967,6 +1967,11 @@ namespace NadekoBot.Migrations
b.Property<ulong>("UserId") b.Property<ulong>("UserId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("Weight")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(1);
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("DateAdded"); b.HasIndex("DateAdded");

View File

@@ -41,8 +41,11 @@ namespace NadekoBot.Modules.Administration.Services
}, null, TimeSpan.FromSeconds(0), TimeSpan.FromHours(12)); }, null, TimeSpan.FromSeconds(0), TimeSpan.FromHours(12));
} }
public async Task<WarningPunishment> Warn(IGuild guild, ulong userId, IUser mod, string reason) public async Task<WarningPunishment> Warn(IGuild guild, ulong userId, IUser mod, int weight, string reason)
{ {
if (weight <= 0)
throw new ArgumentOutOfRangeException(nameof(weight));
var modName = mod.ToString(); var modName = mod.ToString();
if (string.IsNullOrWhiteSpace(reason)) if (string.IsNullOrWhiteSpace(reason))
@@ -57,6 +60,7 @@ namespace NadekoBot.Modules.Administration.Services
Forgiven = false, Forgiven = false,
Reason = reason, Reason = reason,
Moderator = modName, Moderator = modName,
Weight = weight,
}; };
int warnings = 1; int warnings = 1;
@@ -70,7 +74,7 @@ namespace NadekoBot.Modules.Administration.Services
.Warnings .Warnings
.ForId(guildId, userId) .ForId(guildId, userId)
.Where(w => !w.Forgiven && w.UserId == userId) .Where(w => !w.Forgiven && w.UserId == userId)
.Count(); .Sum(x => x.Weight);
uow.Warnings.Add(warn); uow.Warnings.Add(warn);

View File

@@ -54,8 +54,17 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Aliases] [NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.BanMembers)] [UserPerm(GuildPerm.BanMembers)]
public async Task Warn(IGuildUser user, [Leftover] string reason = null) public Task Warn(IGuildUser user, [Leftover] string reason = null)
=> Warn(1, user, reason);
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.BanMembers)]
public async Task Warn(int weight, IGuildUser user, [Leftover] string reason = null)
{ {
if (weight <= 0)
return;
if (!await CheckRoleHierarchy(user)) if (!await CheckRoleHierarchy(user))
return; return;
@@ -76,7 +85,7 @@ namespace NadekoBot.Modules.Administration
WarningPunishment punishment; WarningPunishment punishment;
try try
{ {
punishment = await _service.Warn(ctx.Guild, user.Id, ctx.User, reason).ConfigureAwait(false); punishment = await _service.Warn(ctx.Guild, user.Id, ctx.User, weight, reason).ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -230,19 +239,29 @@ namespace NadekoBot.Modules.Administration
} }
else else
{ {
var descText = GetText(strs.warn_count(
Format.Bold(warnings.Where(x => !x.Forgiven).Sum(x => x.Weight).ToString()),
Format.Bold(warnings.Sum(x => x.Weight).ToString())));
embed.WithDescription(descText);
var i = page * 9; var i = page * 9;
foreach (var w in warnings) foreach (var w in warnings)
{ {
i++; i++;
var name = GetText(strs.warned_on_by( var name = GetText(strs.warned_on_by(
w.DateAdded.Value.ToString("dd.MM.yyy"), w.DateAdded?.ToString("dd.MM.yyy"),
w.DateAdded.Value.ToString("HH:mm"), w.DateAdded?.ToString("HH:mm"),
w.Moderator)); w.Moderator));
if (w.Forgiven) if (w.Forgiven)
name = $"{Format.Strikethrough(name)} {GetText(strs.warn_cleared_by(w.ForgivenBy))}"; name = $"{Format.Strikethrough(name)} {GetText(strs.warn_cleared_by(w.ForgivenBy))}";
embed.AddField($"#`{i}` " + name, w.Reason.TrimTo(1020));
embed.AddField($"#`{i}` " + name,
Format.Code(GetText(strs.warn_weight(w.Weight))) +
'\n' +
w.Reason.TrimTo(1000));
} }
} }

View File

@@ -1596,9 +1596,12 @@ warnlogall:
- "" - ""
- "2" - "2"
warn: warn:
desc: "Warns a user." desc: |-
Warns a user with an optional reason.
You can specify a warning weight integer before the user. For example, 3 would mean that this warning counts as 3 warnings.
args: args:
- "@Someone Very rude person" - "@Someone Very rude person"
- "3 @Someone Very rude person"
scadd: scadd:
desc: "Adds a command to the list of commands which will be executed automatically in the current channel, in the order they were added in, by the bot when it startups up." desc: "Adds a command to the list of commands which will be executed automatically in the current channel, in the order they were added in, by the bot when it startups up."
args: args:

View File

@@ -665,6 +665,8 @@
"warning_clear_fail": "Warning not cleared. Either the warning at that index doesn't exist, or it has already been cleared.", "warning_clear_fail": "Warning not cleared. Either the warning at that index doesn't exist, or it has already been cleared.",
"warning_cleared": "Warning {0} has been cleared for {1}.", "warning_cleared": "Warning {0} has been cleared for {1}.",
"warnings_none": "No warning on this page.", "warnings_none": "No warning on this page.",
"warn_weight": "Weight: {0}",
"warn_count": "{0} current, {1} total",
"warnlog_for": "Warnlog for {0}", "warnlog_for": "Warnlog for {0}",
"warnpl_none": "No punishments set.", "warnpl_none": "No punishments set.",
"warn_expire_set_delete": "Warnings will be deleted after {0} days.", "warn_expire_set_delete": "Warnings will be deleted after {0} days.",