public static LocalisedString ToLocalisable(this TT2Submission.SubmissionType type) { switch (type) { case TT2Submission.SubmissionType.Bug: return((LocalisedString)BUG); case TT2Submission.SubmissionType.Question: return((LocalisedString)QUESTION); case TT2Submission.SubmissionType.Suggestion: return((LocalisedString)SUGGESTION); } return((RawString)type.ToString()); }
async Task ListAsync(TT2Submission.SubmissionType[] type = null) { if (type == null) { type = new TT2Submission.SubmissionType[] { TT2Submission.SubmissionType.Bug, TT2Submission.SubmissionType.Question, TT2Submission.SubmissionType.Suggestion } } ; var unanswered = await Database.Find <TT2Submission>(s => s.Response == null); unanswered = unanswered.Where(s => type.Contains(s.Type)); if (unanswered.Count() == 0) { await ReplyAsync("There are no unanswered submissions!", ReplyType.Info); return; } var table = new List <string[]>(); table.Add(new string[] { "id", "Title", "Type", "Submitter" }); foreach (var submission in unanswered) { var user = Client.GetUser(submission.Submitter); table.Add(new string[] { submission.Id.ToString(), submission.Title.Substring(0, 50), $"[{submission.Type}]", user != null ? $"{user} ({user.Id})" : $"UNKNOWN USER ({submission.Id})" }); } await ReplyAsync($"```css\n{table.ToArray().Tableify()}```"); }
async Task ListAsync(TT2Submission.SubmissionType[] type = null) { if (type == null) { type = new TT2Submission.SubmissionType[] { TT2Submission.SubmissionType.Bug, TT2Submission.SubmissionType.Question, TT2Submission.SubmissionType.Suggestion } } ; var unanswered = await Database.Find <TT2Submission>(s => s.Response == null); unanswered = unanswered.Where(s => type.Contains(s.Type)); if (unanswered.Count() == 0) { await ReplyAsync(SubmitText.LIST_NONE, ReplyType.Info); return; } var table = new List <string[]> { TextResource.GetResource(SubmitText.LIST_HEADERS).Split(',') }; foreach (var submission in unanswered) { var user = Client.GetUser(submission.Submitter); table.Add(TextResource.Format(SubmitText.LIST_ROW, submission.Id.ToString(), submission.Title.Substring(0, 50), $"[{submission.Type}]", user?.Username ?? TextResource.GetResource(TBLocalisation.UNKNOWNUSER), user?.Id ?? submission.Id).Split(',') ); } await ReplyAsync(SubmitText.LIST_TABLEFORMAT, table.ToArray().Tableify()); }
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); }