mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Added .log userwarned
This commit is contained in:
@@ -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