mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
Added .log userwarned
This commit is contained in:
@@ -27,5 +27,6 @@ public enum LogType
|
||||
UserPresence,
|
||||
VoicePresence,
|
||||
VoicePresenceTts,
|
||||
UserMuted
|
||||
UserMuted,
|
||||
UserWarned,
|
||||
}
|
@@ -4,7 +4,7 @@ namespace NadekoBot.Services.Database.Models;
|
||||
public class LogSetting : DbEntity
|
||||
{
|
||||
public List<IgnoredLogItem> LogIgnores { get; set; } = new();
|
||||
|
||||
|
||||
public ulong GuildId { get; set; }
|
||||
public ulong? LogOtherId { get; set; }
|
||||
public ulong? MessageUpdatedId { get; set; }
|
||||
@@ -29,4 +29,5 @@ public class LogSetting : DbEntity
|
||||
|
||||
public ulong? LogVoicePresenceId { get; set; }
|
||||
public ulong? LogVoicePresenceTTSId { get; set; }
|
||||
public ulong? LogWarnsId { get; set; }
|
||||
}
|
3518
src/NadekoBot/Migrations/MySql/20220703194400_logwarns.Designer.cs
generated
Normal file
3518
src/NadekoBot/Migrations/MySql/20220703194400_logwarns.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
src/NadekoBot/Migrations/MySql/20220703194400_logwarns.cs
Normal file
25
src/NadekoBot/Migrations/MySql/20220703194400_logwarns.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace NadekoBot.Migrations.Mysql
|
||||
{
|
||||
public partial class logwarns : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<ulong>(
|
||||
name: "logwarnsid",
|
||||
table: "logsettings",
|
||||
type: "bigint unsigned",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "logwarnsid",
|
||||
table: "logsettings");
|
||||
}
|
||||
}
|
||||
}
|
@@ -1406,6 +1406,10 @@ namespace NadekoBot.Migrations.Mysql
|
||||
.HasColumnType("bigint unsigned")
|
||||
.HasColumnName("logvoicepresencettsid");
|
||||
|
||||
b.Property<ulong?>("LogWarnsId")
|
||||
.HasColumnType("bigint unsigned")
|
||||
.HasColumnName("logwarnsid");
|
||||
|
||||
b.Property<ulong?>("MessageDeletedId")
|
||||
.HasColumnType("bigint unsigned")
|
||||
.HasColumnName("messagedeletedid");
|
||||
|
3660
src/NadekoBot/Migrations/Postgresql/20220703194412_logwarns.Designer.cs
generated
Normal file
3660
src/NadekoBot/Migrations/Postgresql/20220703194412_logwarns.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace NadekoBot.Migrations.PostgreSql
|
||||
{
|
||||
public partial class logwarns : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<decimal>(
|
||||
name: "logwarnsid",
|
||||
table: "logsettings",
|
||||
type: "numeric(20,0)",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "logwarnsid",
|
||||
table: "logsettings");
|
||||
}
|
||||
}
|
||||
}
|
@@ -1472,6 +1472,10 @@ namespace NadekoBot.Migrations.PostgreSql
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("logvoicepresencettsid");
|
||||
|
||||
b.Property<decimal?>("LogWarnsId")
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("logwarnsid");
|
||||
|
||||
b.Property<decimal?>("MessageDeletedId")
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("messagedeletedid");
|
||||
|
2825
src/NadekoBot/Migrations/Sqlite/20220703194348_logwarns.Designer.cs
generated
Normal file
2825
src/NadekoBot/Migrations/Sqlite/20220703194348_logwarns.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
43
src/NadekoBot/Migrations/Sqlite/20220703194348_logwarns.cs
Normal file
43
src/NadekoBot/Migrations/Sqlite/20220703194348_logwarns.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
{
|
||||
public partial class logwarns : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Name",
|
||||
table: "StreamOnlineMessages",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "TEXT");
|
||||
|
||||
migrationBuilder.AddColumn<ulong>(
|
||||
name: "LogWarnsId",
|
||||
table: "LogSettings",
|
||||
type: "INTEGER",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LogWarnsId",
|
||||
table: "LogSettings");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Name",
|
||||
table: "StreamOnlineMessages",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: "",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
@@ -278,7 +278,6 @@ namespace NadekoBot.Migrations
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Type")
|
||||
@@ -1100,6 +1099,9 @@ namespace NadekoBot.Migrations
|
||||
b.Property<ulong?>("LogVoicePresenceTTSId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<ulong?>("LogWarnsId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<ulong?>("MessageDeletedId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
|
@@ -26,6 +26,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
private readonly ConcurrentHashSet<ulong> _ignoreMessageIds = new();
|
||||
private readonly UserPunishService _punishService;
|
||||
|
||||
public LogCommandService(
|
||||
DiscordSocketClient client,
|
||||
@@ -35,7 +36,8 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
ProtectionService prot,
|
||||
GuildTimezoneService tz,
|
||||
IMemoryCache memoryCache,
|
||||
IEmbedBuilderService eb)
|
||||
IEmbedBuilderService eb,
|
||||
UserPunishService punishService)
|
||||
{
|
||||
_client = client;
|
||||
_memoryCache = memoryCache;
|
||||
@@ -45,6 +47,8 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
_mute = mute;
|
||||
_prot = prot;
|
||||
_tz = tz;
|
||||
_punishService = punishService;
|
||||
|
||||
using (var uow = db.GetDbContext())
|
||||
{
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
@@ -78,6 +82,8 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
_mute.UserUnmuted += MuteCommands_UserUnmuted;
|
||||
|
||||
_prot.OnAntiProtectionTriggered += TriggeredAntiProtection;
|
||||
|
||||
_punishService.OnUserWarned += PunishServiceOnOnUserWarned;
|
||||
}
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
@@ -183,6 +189,30 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
GuildLogSettings.AddOrUpdate(guildId, _ => logSetting, (_, _) => logSetting);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async Task PunishServiceOnOnUserWarned(Warning arg)
|
||||
{
|
||||
if (!GuildLogSettings.TryGetValue(arg.GuildId, out var logSetting) || logSetting.LogWarnsId is null)
|
||||
return;
|
||||
|
||||
var g = _client.GetGuild(arg.GuildId);
|
||||
|
||||
ITextChannel? logChannel;
|
||||
if ((logChannel = await TryGetLogChannel(g, logSetting, LogType.UserWarned)) is null)
|
||||
return;
|
||||
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
.WithTitle($"⚠️ User Warned")
|
||||
.WithDescription($"<@{arg.UserId}> | {arg.UserId}")
|
||||
.AddField("Mod", arg.Moderator)
|
||||
.AddField("Reason", string.IsNullOrWhiteSpace(arg.Reason) ? "-" : arg.Reason, true)
|
||||
.WithFooter(CurrentTime(g));
|
||||
|
||||
await logChannel.EmbedAsync(embed);
|
||||
}
|
||||
|
||||
private Task _client_UserUpdated(SocketUser before, SocketUser uAfter)
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
@@ -296,6 +326,9 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
channelId = logSetting.LogVoicePresenceTTSId =
|
||||
logSetting.LogVoicePresenceTTSId is null ? cid : default;
|
||||
break;
|
||||
case LogType.UserWarned:
|
||||
channelId = logSetting.LogWarnsId = logSetting.LogWarnsId is null ? cid : default;
|
||||
break;
|
||||
}
|
||||
|
||||
uow.SaveChanges();
|
||||
@@ -1144,6 +1177,9 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
case LogType.UserMuted:
|
||||
id = logSetting.UserMutedId;
|
||||
break;
|
||||
case LogType.UserWarned:
|
||||
id = logSetting.LogWarnsId;
|
||||
break;
|
||||
}
|
||||
|
||||
if (id is null or 0)
|
||||
@@ -1214,6 +1250,9 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
|
||||
case LogType.VoicePresenceTts:
|
||||
newLogSetting.LogVoicePresenceTTSId = null;
|
||||
break;
|
||||
case LogType.UserWarned:
|
||||
newLogSetting.LogWarnsId = null;
|
||||
break;
|
||||
}
|
||||
|
||||
GuildLogSettings.AddOrUpdate(guildId, newLogSetting, (_, _) => newLogSetting);
|
||||
|
@@ -18,6 +18,8 @@ public class UserPunishService : INService, IReadyExecutor
|
||||
private readonly BotConfigService _bcs;
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public event Func<Warning, Task> OnUserWarned = static delegate { return Task.CompletedTask; };
|
||||
|
||||
public UserPunishService(
|
||||
MuteService mute,
|
||||
DbService db,
|
||||
@@ -93,6 +95,8 @@ public class UserPunishService : INService, IReadyExecutor
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
_ = OnUserWarned(warn);
|
||||
|
||||
var totalCount = previousCount + weight;
|
||||
|
||||
var p = ps.Where(x => x.Count > previousCount && x.Count <= totalCount)
|
||||
|
Reference in New Issue
Block a user