Embedable GetSubmissionMessage(TT2Submission submission) { var color = System.Drawing.Color.Pink.ToDiscord(); switch (submission.Type) { case TT2Submission.SubmissionType.Bug: color = System.Drawing.Color.Red.ToDiscord(); break; case TT2Submission.SubmissionType.Question: color = System.Drawing.Color.SkyBlue.ToDiscord(); break; case TT2Submission.SubmissionType.Suggestion: color = System.Drawing.Color.Green.ToDiscord(); break; } IUser submitter = Client.GetUser(submission.Submitter); IUser replier = null; if (submission.Answerer != null) { replier = Client.GetUser(submission.Answerer.Value); } var builder = new EmbedBuilder { Color = color, Title = $"{submission.Type} #{submission.Id}: {submission.Title}", Description = submission.Description, Timestamp = submission.SubmissionTime }; if (submitter != null) { builder.WithAuthor(submitter); } if (submission.Reddit != null) { builder.AddField("Reddit link", submission.Reddit); } if (submission.ImageUrl != null) { builder.AddField("Image", submission.ImageUrl); } if (string.IsNullOrWhiteSpace(submission.Response)) { builder.AddField("GH reply", "No reply yet!"); } else { builder.AddField("GH reply", submission.Response); } if (replier != null) { builder.WithFooter(new EmbedFooterBuilder { IconUrl = replier.GetAvatarUrl(), Text = $"{replier} | Replied {submission.ReplyTime}" }); } return(builder); }
async Task SubmitAsync(string title, TT2Submission.SubmissionType type, string description, Uri image, Uri reddit) { var canSubmit = (await Database.FindById <PlayerData>(Author.Id))?.CanGHSubmit ?? true; if (!canSubmit) { await ReplyAsync(SubmitText.BLOCKED, ReplyType.Error, type); } else if (SubmissionChannel == null) { await ReplyAsync(SubmitText.MISSING_CHANNEL, ReplyType.Error); } else if (string.IsNullOrWhiteSpace(description)) { await ReplyAsync(SubmitText.MISSING_DESCRIPTION); } else { var urlString = Message.Attachments.FirstOrDefault(a => Regex.IsMatch(a.Url, TT2Global.ImageRegex))?.Url; Uri imageUrl = null; if (urlString != null) { if (image != null) { await ReplyAsync(SubmitText.IMAGE_TOOMANY, ReplyType.Error); return; } else { imageUrl = new Uri(urlString); } } else if (image != null && !Regex.IsMatch(image.AbsoluteUri, TT2Global.ImageRegex)) { await ReplyAsync(SubmitText.IMAGE_INVALID, ReplyType.Error); return; } else if (image != null) { imageUrl = image; } Uri redditUrl = null; if (reddit != null && !Regex.IsMatch(reddit.AbsoluteUri, @"^https?:\/\/(www.)?redd(.it|it.com)\/.*$")) { await ReplyAsync(SubmitText.REDDIT_INVALID, ReplyType.Error); return; } var submission = new TT2Submission { Description = description, Title = title, ImageUrl = imageUrl, Reddit = redditUrl, Submitter = Author.Id, Type = type, SubmissionTime = DateTime.Now }; await Database.Insert(submission); var message = await Reply(SubmissionChannel).WithEmbedable(GetSubmissionMessage(submission)) .SendAsync(); submission.Message = message.Id; await Database.Upsert(submission); await ReplyAsync(SubmitText.SUCCESS, ReplyType.Success, type.ToLocalisable()); } }
async Task SubmitAsync(string title, TT2Submission.SubmissionType type, string description, Uri image, Uri reddit) { var canSubmit = (await Database.FindById <PlayerData>(Author.Id))?.CanGHSubmit ?? true; if (!canSubmit) { await ReplyAsync("You have been blocked from using this command. Please contact one of the admins on the /r/TapTitans2 discord if you think this is a mistake.", ReplyType.Error); return; } if (SubmissionChannel == null) { await ReplyAsync($"I could not locate where to send the {type}! Please try again later.", ReplyType.Error); return; } if (string.IsNullOrWhiteSpace(description)) { await ReplyAsync("Please make sure you provide a description using the `-d` flag!"); return; } var urlString = Message.Attachments.FirstOrDefault(a => Regex.IsMatch(a.Url, TT2Settings.ImageRegex))?.Url; Uri imageUrl = null; if (urlString != null) { if (image != null) { await ReplyAsync("You cannot specify an image flag if you attach an image!", ReplyType.Error); return; } else { imageUrl = new Uri(urlString); } } else if (image != null && !Regex.IsMatch(image.AbsoluteUri, TT2Settings.ImageRegex)) { await ReplyAsync("The image you supplied is not a valid image!", ReplyType.Error); return; } else if (image != null) { imageUrl = image; } Uri redditUrl = null; if (reddit != null && !Regex.IsMatch(reddit.AbsoluteUri, @"^https?:\/\/(www.)?redd(.it|it.com)\/.*$")) { await ReplyAsync("The URL you gave was not a valid reddit URL", ReplyType.Error); return; } var submission = new TT2Submission { Description = description, Title = title, ImageUrl = imageUrl, Reddit = redditUrl, Submitter = Author.Id, Type = type, SubmissionTime = DateTime.Now }; await Database.Insert(submission); var message = await ReplyAsync(SubmissionChannel, "", embed : GetSubmissionMessage(submission).Build()); submission.Message = message.Id; await Database.Upsert(submission); await ReplyAsync($"Your {type} has been successfully sent!", ReplyType.Success); }