Beispiel #1
0
        public async Task <PromotionCampaignEntity> CreateCampaign(SocketGuildUser user, string commentBody)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (string.IsNullOrWhiteSpace(commentBody))
            {
                throw new ArgumentException("Comment cannot be empty!");
            }
            if ((await GetCampaigns()).Any(d => (ulong)d.PromotionFor.Id == user.Id))
            {
                throw new ArgumentException("A campaign already exists for that user.");
            }

            if (user.Roles.Count > 1)
            {
                throw new ArgumentException("Recommended user must be unranked.");
            }

            var timeOnServer = DateTimeOffset.UtcNow - user.JoinedAt.Value.ToUniversalTime();

            if (timeOnServer < TimeSpan.FromDays(30))
            {
                throw new ArgumentException(
                          $"Recommended user must have been a member of the server for more than 30 days. Currently: {timeOnServer.TotalDays}");
            }

            var ret = new PromotionCampaignEntity
            {
                StartDate = DateTimeOffset.UtcNow,
                Status    = CampaignStatus.Active
            };

            await _repository.AddCampaign(ret, user);

            await AddComment(ret, commentBody, PromotionSentiment.For);

            if (PromotionChannel == null)
            {
                throw new NullReferenceException(nameof(promotionChannelID));
            }

            await PromotionChannel.SendMessageAsync("", false,
                                                    new EmbedBuilder()
                                                    .WithTitle("Campaign Started")
                                                    .WithAuthor(user)
                                                    .WithDescription(commentBody)
                                                    .WithFooter("Vote now at https://mod.gg/promotions"));

            return(ret);
        }