コード例 #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);
            }
        }
コード例 #2
0
        private async Task <string> FormatPromotionLogEntry(long promotionActionId, PromotionActionCreationData data)
        {
            var promotionAction = await PromotionsService.GetPromotionActionSummaryAsync(promotionActionId);

            var key = (promotionAction.Type, promotionAction.NewComment?.Sentiment, promotionAction.Campaign?.Outcome);

            if (!_logRenderTemplates.TryGetValue(key, out var renderTemplate))
            {
                return(null);
            }

            return(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.NewComment?.Campaign.Id,
                                 promotionAction.NewComment?.Campaign.Subject.DisplayName,
                                 promotionAction.NewComment?.Campaign.Subject.Id,
                                 promotionAction.NewComment?.Campaign.TargetRole.Name,
                                 promotionAction.NewComment?.Campaign.TargetRole.Id,
                                 promotionAction.NewComment?.Content));
        }
コード例 #3
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);
            }
        }
コード例 #4
0
 /// <summary>
 /// Constructs a new <see cref="PromotionActionCreatedNotification"/> from the given values.
 /// </summary>
 /// <param name="id">The value to use for <see cref="Id"/>.</param>
 /// <param name="data">The value to use for <see cref="Data"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="data"/>.</exception>
 public PromotionActionCreatedNotification(long id, PromotionActionCreationData data)
 {
     Id   = id;
     Data = data ?? throw new ArgumentNullException(nameof(data));
 }
コード例 #5
0
        private async Task <Embed> FormatPromotionNotification(long promotionActionId, PromotionActionCreationData data)
        {
            var promotionAction = await PromotionsService.GetPromotionActionSummaryAsync(promotionActionId);

            var targetCampaign = promotionAction.Campaign ?? promotionAction.NewComment.Campaign;

            var embed = new EmbedBuilder();

            if (promotionAction.Type != PromotionActionType.CampaignClosed)
            {
                return(null);
            }
            if (targetCampaign.Outcome != PromotionCampaignOutcome.Accepted)
            {
                return(null);
            }

            var boldName = $"**{targetCampaign.Subject.Username}#{targetCampaign.Subject.Discriminator}**";
            var boldRole = $"**{MentionUtils.MentionRole(targetCampaign.TargetRole.Id)}**";

            var subject = await UserService.GetUserInformationAsync(data.GuildId, targetCampaign.Subject.Id);

            embed = embed
                    .WithTitle("The campaign is over!")
                    .WithDescription($"Staff accepted the campaign, and {boldName} was promoted to {boldRole}! 🎉")
                    .WithAuthor(subject)
                    .WithFooter("See more at https://mod.gg/promotions");

            return(embed.Build());
        }
コード例 #6
0
        private async Task <Embed> FormatPromotionNotificationAsync(long promotionActionId, PromotionActionCreationData data)
        {
            var promotionAction = await PromotionsService.GetPromotionActionSummaryAsync(promotionActionId);

            var targetCampaign = promotionAction.Campaign ?? promotionAction.NewComment.Campaign;

            var embed = new EmbedBuilder();

            if (promotionAction.Type != PromotionActionType.CampaignClosed)
            {
                return(null);
            }
            if (targetCampaign.Outcome != PromotionCampaignOutcome.Accepted)
            {
                return(null);
            }

            var boldName = $"**{targetCampaign.Subject.GetFullUsername()}**";
            var boldRole = $"**{MentionUtils.MentionRole(targetCampaign.TargetRole.Id)}**";

            var subject = await UserService.GetUserInformationAsync(data.GuildId, targetCampaign.Subject.Id);

            // https://modix.gg/promotions
            var url = new UriBuilder(ModixConfig.WebsiteBaseUrl)
            {
                Path = "/promotions"
            }.RemoveDefaultPort().ToString();

            embed = embed
                    .WithTitle("The campaign is over!")
                    .WithDescription($"Staff accepted the campaign, and {boldName} was promoted to {boldRole}! 🎉")
                    .WithUserAsAuthor(subject)
                    .WithFooter($"See more at {url}");

            return(embed.Build());
        }
コード例 #7
0
        private async Task <Embed> FormatPromotionNotification(long promotionActionId, PromotionActionCreationData data)
        {
            var promotionAction = await PromotionsService.GetPromotionActionSummaryAsync(promotionActionId);

            var targetCampaign = promotionAction.Campaign ?? promotionAction.NewComment.Campaign;

            var embed = new EmbedBuilder();

            //Because we have comment creation as a separate operation from starting the campaign,
            //we don't have access to the "initial" comment when a campaign is created. So, we have to
            //note that a campaign was created, and actually send the log message when the first comment
            //is created (containing the comment body)
            switch (promotionAction.Type)
            {
            case PromotionActionType.CampaignCreated:

                _initialCommentQueue.TryAdd(targetCampaign.Id, embed
                                            .WithTitle("A new campaign has been started!")
                                            .AddField("If accepted, their new role will be", MentionUtils.MentionRole(targetCampaign.TargetRole.Id)));

                return(null);

            case PromotionActionType.CampaignClosed:

                var fullCampaign = (await PromotionsService.SearchCampaignsAsync(new PromotionCampaignSearchCriteria
                {
                    Id = targetCampaign.Id
                }))
                                   .First();

                embed = embed
                        .WithTitle("The campaign is over!")
                        .AddField("Approval Rate", fullCampaign.GetApprovalPercentage().ToString("p"), true);

                var boldName = $"**{targetCampaign.Subject.Username}#{targetCampaign.Subject.Discriminator}**";
                var boldRole = $"**{MentionUtils.MentionRole(targetCampaign.TargetRole.Id)}**";

                switch (targetCampaign.Outcome)
                {
                case PromotionCampaignOutcome.Accepted:
                    embed = embed
                            .WithDescription($"Staff accepted the campaign, and {boldName} was promoted to {boldRole}! 🎉");
                    break;

                case PromotionCampaignOutcome.Rejected:
                    embed = embed
                            .WithDescription($"Staff rejected the campaign to promote {boldName} to {boldRole}");
                    break;

                case PromotionCampaignOutcome.Failed:
                default:
                    embed = embed
                            .WithDescription("There was an issue while accepting or denying the campaign. Ask staff for details.")
                            .AddField("Target Role", MentionUtils.MentionRole(targetCampaign.TargetRole.Id), true);
                    break;
                }

                break;

            case PromotionActionType.CommentCreated:

                if (_initialCommentQueue.TryRemove(targetCampaign.Id, out embed))
                {
                    embed.Description = $"👍 {promotionAction.NewComment.Content}";
                }
                else
                {
                    return(null);
                }

                break;

            case PromotionActionType.CommentModified:
            default:
                return(null);
            }

            var subject = await UserService.GetUserInformationAsync(data.GuildId, targetCampaign.Subject.Id);

            return(embed
                   .WithAuthor(subject)
                   .WithFooter("See more at https://mod.gg/promotions")
                   .Build());
        }