public async Task AddComment(PromotionCampaignEntity campaign, string comment, PromotionSentiment sentiment) { comment = _badCharacterRegex.Replace(comment, ""); if (comment.Trim().Length < 10) { throw new ArgumentException("Comment is too short, must be more than 10 characters."); } if (comment.Length > 1000) { throw new ArgumentException("Comment is too long, must be under 1000 characters."); } if (campaign.Status != CampaignStatus.Active) { throw new ArgumentException("Campaign must be active to comment."); } var promotionComment = new PromotionCommentEntity { PostedDate = DateTimeOffset.UtcNow, Body = comment, Sentiment = sentiment }; await _repository.AddCommentToCampaign(campaign, promotionComment); }
public async Task ApproveCampaign(SocketGuildUser promoter, PromotionCampaignEntity campaign) { ThrowIfNotStaff(promoter); var foundUser = CurrentGuild.GetUser((ulong)campaign.PromotionFor.Id); var foundRole = CurrentGuild.Roles.FirstOrDefault(d => d.Id == allowedToCommentRoleID); if (foundRole == null) { throw new InvalidOperationException("The server does not have a 'Regular' role to grant."); } await foundUser.AddRoleAsync(foundRole); campaign.Status = CampaignStatus.Approved; await _repository.UpdateCampaign(campaign); if (PromotionChannel == null) { throw new NullReferenceException(nameof(PromotionChannel)); } await PromotionChannel.SendMessageAsync( $"{MentionUtils.MentionUser((ulong)campaign.PromotionFor.Id)} has been promoted to Regular! 🎉"); }
public async Task ActivateCampaign(SocketGuildUser promoter, PromotionCampaignEntity campaign) { ThrowIfNotStaff(promoter); if (campaign.Status != CampaignStatus.Denied) { throw new InvalidOperationException("Cannot reactivate a campaign that has not been denied."); } campaign.Status = CampaignStatus.Active; await _repository.UpdateCampaign(campaign); }
public async Task DenyCampaign(SocketGuildUser promoter, PromotionCampaignEntity campaign) { ThrowIfNotStaff(promoter); if (campaign.Status == CampaignStatus.Denied) { throw new InvalidOperationException("The campaign has already been denied."); } campaign.Status = CampaignStatus.Denied; await _repository.UpdateCampaign(campaign); }
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); }
public async Task AddCampaign(PromotionCampaignEntity campaign, SocketGuildUser user) { var promoUser = await _context.Users.FirstOrDefaultAsync(u => (ulong)u.Id == user.Id); if (promoUser == null) { // TODO: This needs to be done through IUserService. There are concurrency issues if anyone else manages users in the DB directly. await _context.Users.AddAsync(new UserEntity { Username = $"{user.Username}#{user.Discriminator}", Id = (long)user.Id, Nickname = user.Nickname, }); } campaign.PromotionFor = promoUser; await _context.PromotionCampaigns.AddAsync(campaign); await _context.SaveChangesAsync(); }
public async Task UpdateCampaign(PromotionCampaignEntity campaign) { _context.Update(campaign); await _context.SaveChangesAsync(); }
public async Task AddCommentToCampaign(PromotionCampaignEntity campaign, PromotionCommentEntity comment) { await campaign.Comments.AddAsync(comment); await _context.SaveChangesAsync(); }