예제 #1
0
        public async Task CampaignsAsync()
        {
            var campaigns = await PromotionsService.SearchCampaignsAsync(new PromotionCampaignSearchCriteria()
            {
                GuildId  = Context.Guild.Id,
                IsClosed = false
            });

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

            var embed = new EmbedBuilder()
            {
                Title       = Format.Bold("Active Promotion Campaigns"),
                Url         = url,
                Color       = Color.Gold,
                Timestamp   = DateTimeOffset.Now,
                Description = campaigns.Any() ? null : "There are no active promotion campaigns."
            };

            foreach (var campaign in campaigns)
            {
                var idLabel    = $"#{campaign.Id}";
                var votesLabel = (campaign.GetTotalVotes() == 1) ? "Vote" : "Votes";

                var approvalLabel      = $"👍 {campaign.GetNumberOfApprovals()} / 👎 {campaign.GetNumberOfOppositions()}";
                var timeRemaining      = campaign.GetTimeUntilCampaignCanBeClosed();
                var timeRemainingLabel = timeRemaining < TimeSpan.FromSeconds(1) ? "Can be closed now" : $"{timeRemaining.Humanize(precision: 2, minUnit: TimeUnit.Minute)} until close";

                embed.AddField(new EmbedFieldBuilder()
                {
                    Name     = $"{Format.Bold(idLabel)}: {Format.Bold(campaign.Subject.GetFullUsername())} to {campaign.TargetRole.Name}",
                    Value    = $"{approvalLabel} ({timeRemainingLabel})",
                    IsInline = false
                });
            }

            await ReplyAsync("", embed : embed.Build());
        }
예제 #2
0
        public async Task Campaigns()
        {
            var campaigns = await PromotionsService.SearchCampaignsAsync(new PromotionCampaignSearchCriteria()
            {
                GuildId  = Context.Guild.Id,
                IsClosed = false
            });

            var embed = new EmbedBuilder()
            {
                Title       = Format.Bold("Active Promotion Campaigns"),
                Url         = "https://mod.gg/promotions",
                Color       = Color.Gold,
                Timestamp   = DateTimeOffset.Now,
                Description = campaigns.Any() ? null : "There are no active promotion campaigns."
            };

            foreach (var campaign in campaigns)
            {
                var totalVotes = campaign.CommentCounts
                                 .Select(x => x.Value)
                                 .Sum();
                var totalApprovals = campaign.CommentCounts
                                     .Where(x => x.Key == PromotionSentiment.Approve)
                                     .Select(x => x.Value)
                                     .Sum();
                var approvalPercentage = Math.Round((float)totalApprovals / totalVotes * 100);

                var idLabel       = $"#{campaign.Id}";
                var votesLabel    = (totalVotes == 1) ? "Vote" : "Votes";
                var approvalLabel = Format.Italics($"{approvalPercentage}% approval");

                embed.AddField(new EmbedFieldBuilder()
                {
                    Name     = $"{Format.Bold(idLabel)}: For {Format.Bold(campaign.Subject.DisplayName)} to {Format.Bold(campaign.TargetRole.Name)}",
                    Value    = $"{totalVotes} {votesLabel} ({approvalLabel})",
                    IsInline = false
                });
            }

            await ReplyAsync("", embed : embed.Build());
        }
예제 #3
0
        public async Task CampaignsAsync()
        {
            var campaigns = await PromotionsService.SearchCampaignsAsync(new PromotionCampaignSearchCriteria()
            {
                GuildId  = Context.Guild.Id,
                IsClosed = false
            });

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

            var embed = new EmbedBuilder()
            {
                Title       = Format.Bold("Active Promotion Campaigns"),
                Url         = url,
                Color       = Color.Gold,
                Timestamp   = DateTimeOffset.Now,
                Description = campaigns.Any() ? null : "There are no active promotion campaigns."
            };

            foreach (var campaign in campaigns)
            {
                var idLabel    = $"#{campaign.Id}";
                var votesLabel = (campaign.GetTotalVotes() == 1) ? "Vote" : "Votes";

                var percentage    = Math.Round(campaign.GetApprovalPercentage() * 100);
                var approvalLabel = Format.Italics($"{percentage}% approval");

                embed.AddField(new EmbedFieldBuilder()
                {
                    Name     = $"{Format.Bold(idLabel)}: For {Format.Bold(campaign.Subject.GetFullUsername())} to {Format.Bold(campaign.TargetRole.Name)}",
                    Value    = $"{campaign.GetTotalVotes()} {votesLabel} ({approvalLabel})",
                    IsInline = false
                });
            }

            await ReplyAsync("", embed : embed.Build());
        }
예제 #4
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());
        }