/// <inheritdoc /> public async Task OnModerationActionCreatedAsync(long moderationActionId, ModerationActionCreationData data) { if (!await DesignatedChannelService.AnyDesignatedChannelAsync(data.GuildId, DesignatedChannelType.ModerationLog)) { return; } try { var moderationActionResult = await ModerationService.GetModerationActionSummaryAsync(moderationActionId); if (moderationActionResult.IsFailure) { return; } var moderationAction = moderationActionResult.Result; if (!_renderTemplates.TryGetValue((moderationAction.Type, moderationAction.Infraction?.Type), out var renderTemplate)) { return; } // De-linkify links in the message, otherwise Discord will make auto-embeds for them in the log channel var content = moderationAction.DeletedMessage?.Content.Replace("http://", "[redacted]").Replace("https://", "[redacted]"); var message = string.Format(renderTemplate, moderationAction.Created.UtcDateTime.ToString("HH:mm:ss"), moderationAction.CreatedBy.DisplayName, moderationAction.Infraction?.Id, moderationAction.Infraction?.Subject.DisplayName, moderationAction.Infraction?.Subject.Id, moderationAction.Infraction?.Reason, moderationAction.DeletedMessage?.Id, moderationAction.DeletedMessage?.Author.DisplayName, moderationAction.DeletedMessage?.Author.Id, moderationAction.DeletedMessage?.Channel.Name, moderationAction.DeletedMessage?.Channel.Id, moderationAction.DeletedMessage?.Reason, string.IsNullOrWhiteSpace(content) ? "Empty Message Content" : content); await DesignatedChannelService.SendToDesignatedChannelsAsync( await DiscordClient.GetGuildAsync(data.GuildId), DesignatedChannelType.ModerationLog, message); } catch (Exception ex) { var text = Newtonsoft.Json.JsonConvert.SerializeObject(ex); } }
/// <inheritdoc /> public async Task <long> CreateAsync(ModerationActionCreationData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } var entity = data.ToEntity(); entity.Created = DateTimeOffset.Now; await ModixContext.ModerationActions.AddAsync(entity); await ModixContext.SaveChangesAsync(); return(entity.Id); }
/// <inheritdoc /> public async Task OnModerationActionCreatedAsync(long moderationActionId, ModerationActionCreationData data) { if (!await DesignatedChannelService.AnyDesignatedChannelAsync(data.GuildId, DesignatedChannelType.ModerationLog)) { return; } var moderationAction = await ModerationService.GetModerationActionSummaryAsync(moderationActionId); if (!_renderTemplates.TryGetValue((moderationAction.Type, moderationAction.Infraction?.Type), out var renderTemplate)) { return; } // De-linkify links in the message, otherwise Discord will make auto-embeds for them in the log channel var content = moderationAction.DeletedMessage?.Content.Replace("http://", "[redacted]").Replace("https://", "[redacted]"); var message = string.Format(renderTemplate, moderationAction.Created.UtcDateTime.ToString("HH:mm:ss"), moderationAction.CreatedBy.GetFullUsername(), moderationAction.Infraction?.Id, moderationAction.Infraction?.Subject.GetFullUsername(), moderationAction.Infraction?.Subject.Id, moderationAction.Infraction?.Reason, moderationAction.DeletedMessage?.Id, moderationAction.DeletedMessage?.Author.GetFullUsername(), moderationAction.DeletedMessage?.Author.Id, moderationAction.DeletedMessage?.Channel.Name ?? moderationAction.DeletedMessages?.First().Channel.Name, moderationAction.DeletedMessage?.Channel.Id, moderationAction.DeletedMessage?.Reason, string.IsNullOrWhiteSpace(content) ? "Empty Message Content" : content, moderationAction.DeletedMessages?.Count, GetBatchUrl(moderationAction.DeletedMessages?.FirstOrDefault()?.BatchId), moderationAction.OriginalInfractionReason, string.IsNullOrEmpty(moderationAction.Infraction?.RescindReason) ? "" : $"for reason: ```\n{moderationAction.Infraction?.RescindReason}```"); await DesignatedChannelService.SendToDesignatedChannelsAsync( await DiscordClient.GetGuildAsync(data.GuildId), DesignatedChannelType.ModerationLog, message); }
public async Task OnModerationActionCreatedAsync(long moderationActionId, ModerationActionCreationData data) { var logChannelIds = await ModerationService.GetLogChannelIdsAsync(data.GuildId); if (!logChannelIds.Any()) { return; } try { var moderationAction = await ModerationService.GetModerationActionSummaryAsync(moderationActionId); if (!_renderTemplates.TryGetValue((moderationAction.Type, moderationAction.Infraction.Type), out var renderTemplate)) { return; } var message = string.Format(renderTemplate, moderationAction.Id, moderationAction.Created.UtcDateTime.ToString("HH:mm:ss"), moderationAction.CreatedBy.DisplayName, moderationAction.Infraction.Subject.DisplayName, moderationAction.Infraction.Subject.Id, moderationAction.Infraction.Reason); foreach (var logChannelId in logChannelIds) { await(await DiscordClient.GetChannelAsync(logChannelId) as IMessageChannel) .SendMessageAsync(message); } } catch (Exception ex) { var text = Newtonsoft.Json.JsonConvert.SerializeObject(ex); } }
private async Task RaiseModerationActionCreatedAsync(long moderationActionId, ModerationActionCreationData data) { foreach (var handler in ModerationActionEventHandlers) { await handler.OnModerationActionCreatedAsync(moderationActionId, data); } }