Antispam can now take an extra parameter at the end which is the time of the mute. It will be ignored if punishment type isn't mute

This commit is contained in:
Master Kwoth 2017-08-16 01:12:18 +02:00
parent fe3770270e
commit 03a86b0be9
6 changed files with 1759 additions and 5 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class mutetimeantispam : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "MuteTime",
table: "AntiSpamSetting",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "MuteTime",
table: "AntiSpamSetting");
}
}
}

View File

@ -70,6 +70,8 @@ namespace NadekoBot.Migrations
b.Property<int>("MessageThreshold");
b.Property<int>("MuteTime");
b.HasKey("Id");
b.HasIndex("GuildConfigId")

View File

@ -33,9 +33,17 @@ namespace NadekoBot.Modules.Administration
if (string.IsNullOrWhiteSpace(ignoredString))
ignoredString = "none";
string add = "";
if (stats.AntiSpamSettings.Action == PunishmentAction.Mute
&& stats.AntiSpamSettings.MuteTime > 0)
{
add = " (" + stats.AntiSpamSettings.MuteTime + "s)";
}
return GetText("spam_stats",
Format.Bold(stats.AntiSpamSettings.MessageThreshold.ToString()),
Format.Bold(stats.AntiSpamSettings.Action.ToString()),
Format.Bold(stats.AntiSpamSettings.Action.ToString() + add),
ignoredString);
}
@ -162,6 +170,7 @@ namespace NadekoBot.Modules.Administration
{
Action = action,
MessageThreshold = messageCount,
MuteTime = time,
}
};
@ -169,6 +178,7 @@ namespace NadekoBot.Modules.Administration
{
stats.AntiSpamSettings.MessageThreshold = messageCount;
stats.AntiSpamSettings.Action = action;
stats.AntiSpamSettings.MuteTime = time;
return stats;
});

View File

@ -78,7 +78,7 @@ namespace NadekoBot.Modules.Administration.Services
if (spamSettings.UserStats.TryRemove(msg.Author.Id, out stats))
{
stats.Dispose();
await PunishUsers(spamSettings.AntiSpamSettings.Action, ProtectionType.Spamming, (IGuildUser)msg.Author)
await PunishUsers(spamSettings.AntiSpamSettings.Action, ProtectionType.Spamming, spamSettings.AntiSpamSettings.MuteTime, (IGuildUser)msg.Author)
.ConfigureAwait(false);
}
}
@ -111,7 +111,7 @@ namespace NadekoBot.Modules.Administration.Services
var users = settings.RaidUsers.ToArray();
settings.RaidUsers.Clear();
await PunishUsers(settings.AntiRaidSettings.Action, ProtectionType.Raiding, users).ConfigureAwait(false);
await PunishUsers(settings.AntiRaidSettings.Action, ProtectionType.Raiding, 0, users).ConfigureAwait(false);
}
await Task.Delay(1000 * settings.AntiRaidSettings.Seconds).ConfigureAwait(false);
@ -129,7 +129,7 @@ namespace NadekoBot.Modules.Administration.Services
}
private async Task PunishUsers(PunishmentAction action, ProtectionType pt, params IGuildUser[] gus)
private async Task PunishUsers(PunishmentAction action, ProtectionType pt, int muteTime, params IGuildUser[] gus)
{
_log.Info($"[{pt}] - Punishing [{gus.Length}] users with [{action}] in {gus[0].Guild.Name} guild");
foreach (var gu in gus)
@ -139,7 +139,10 @@ namespace NadekoBot.Modules.Administration.Services
case PunishmentAction.Mute:
try
{
if (muteTime <= 0)
await _mute.MuteUser(gu).ConfigureAwait(false);
else
await _mute.TimedMute(gu, TimeSpan.FromSeconds(muteTime)).ConfigureAwait(false);
}
catch (Exception ex) { _log.Warn(ex, "I can't apply punishement"); }
break;

View File

@ -18,6 +18,7 @@ namespace NadekoBot.Services.Database.Models
public PunishmentAction Action { get; set; }
public int MessageThreshold { get; set; } = 3;
public int MuteTime { get; set; } = 0;
public HashSet<AntiSpamIgnore> IgnoredChannels { get; set; } = new HashSet<AntiSpamIgnore>();
}