Ejemplo n.º 1
0
        public async Task OnPromotionActionCreatedAsync(long promotionActionId, PromotionActionCreationData data)
        {
            if (await DesignatedChannelService.AnyDesignatedChannelAsync(data.GuildId, DesignatedChannelType.PromotionLog))
            {
                var message = await FormatPromotionLogEntry(promotionActionId, data);

                if (message == null)
                {
                    return;
                }

                await DesignatedChannelService.SendToDesignatedChannelsAsync(
                    await DiscordClient.GetGuildAsync(data.GuildId), DesignatedChannelType.PromotionLog, message);
            }

            if (await DesignatedChannelService.AnyDesignatedChannelAsync(data.GuildId, DesignatedChannelType.PromotionNotifications))
            {
                var embed = await FormatPromotionNotification(promotionActionId, data);

                if (embed == null)
                {
                    return;
                }

                await DesignatedChannelService.SendToDesignatedChannelsAsync(
                    await DiscordClient.GetGuildAsync(data.GuildId), DesignatedChannelType.PromotionNotifications, "", embed);
            }
        }
Ejemplo n.º 2
0
        public async Task HandleNotificationAsync(PromotionActionCreatedNotification notification, CancellationToken cancellationToken)
        {
            // TODO: Temporary workaround, remove as part of auth rework.
            if (AuthorizationService.CurrentUserId is null)
            {
                await AuthorizationService.OnAuthenticatedAsync(await SelfUserProvider.GetSelfUserAsync());
            }

            if (await DesignatedChannelService.AnyDesignatedChannelAsync(notification.Data.GuildId, DesignatedChannelType.PromotionLog))
            {
                var message = await FormatPromotionLogEntryAsync(notification.Id);

                if (message == null)
                {
                    return;
                }

                await DesignatedChannelService.SendToDesignatedChannelsAsync(
                    await DiscordClient.GetGuildAsync(notification.Data.GuildId), DesignatedChannelType.PromotionLog, message);
            }

            if (await DesignatedChannelService.AnyDesignatedChannelAsync(notification.Data.GuildId, DesignatedChannelType.PromotionNotifications))
            {
                var embed = await FormatPromotionNotificationAsync(notification.Id, notification.Data);

                if (embed == null)
                {
                    return;
                }

                await DesignatedChannelService.SendToDesignatedChannelsAsync(
                    await DiscordClient.GetGuildAsync(notification.Data.GuildId), DesignatedChannelType.PromotionNotifications, "", embed);
            }
        }
Ejemplo n.º 3
0
        /// <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);
            }
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        public async Task OnPromotionActionCreatedAsync(long moderationActionId, PromotionActionCreationData data)
        {
            if (!await DesignatedChannelService.AnyDesignatedChannelAsync(data.GuildId, DesignatedChannelType.PromotionLog))
            {
                return;
            }

            try
            {
                var promotionAction = await PromotionsService.GetPromotionActionSummaryAsync(moderationActionId);

                if (!_renderTemplates.TryGetValue((promotionAction.Type, promotionAction.Comment?.Sentiment, promotionAction.Campaign?.Outcome), out var renderTemplate))
                {
                    return;
                }

                var message = string.Format(renderTemplate,
                                            promotionAction.Created.UtcDateTime.ToString("HH:mm:ss"),
                                            promotionAction.Campaign?.Id,
                                            promotionAction.Campaign?.Subject.DisplayName,
                                            promotionAction.Campaign?.Subject.Id,
                                            promotionAction.Campaign?.TargetRole.Name,
                                            promotionAction.Campaign?.TargetRole.Id,
                                            promotionAction.Comment?.Campaign.Id,
                                            promotionAction.Comment?.Campaign.Subject.DisplayName,
                                            promotionAction.Comment?.Campaign.Subject.Id,
                                            promotionAction.Comment?.Campaign.TargetRole.Name,
                                            promotionAction.Comment?.Campaign.TargetRole.Id,
                                            promotionAction.Comment?.Content);

                await DesignatedChannelService.SendToDesignatedChannelsAsync(
                    await DiscordClient.GetGuildAsync(data.GuildId), DesignatedChannelType.PromotionLog, message);
            }
            catch (Exception ex)
            {
                var text = Newtonsoft.Json.JsonConvert.SerializeObject(ex);
            }
        }