public async Task GetProblemCover(int id) { ProblemCover problem = ProblemCovers.GetProblemCover(id, Guilds.GetGuild(Context.Guild.Id).Categories); EmbedBuilder embed = new EmbedBuilder { Title = $"{problem.Id} - {problem.Title}", Description = problem.Description }; if (problem.ImageURL != null) { embed.ImageUrl = problem.ImageURL; } await Context.Channel.SendMessageAsync("", false, embed.Build()); }
/// <summary> /// Znajdź opracowanie problemu. /// </summary> /// <param name="id"> /// Id opracowania, które należy znaleźć. /// </param> /// <param name="categories"> /// Lista wszystkich dostępnych na serwerze kategorii /// </param> /// <returns> /// Znalezione opracowanie problemu /// </returns> /// <remarks> /// Może zwrócić null jeśli nie znajdzie opracowania. /// </remarks> public static ProblemCover GetProblemCover(int id, List <Category> categories) { // initialize with null "value" ProblemCover problem = null; // iterate over all categories foreach (Category category in categories) { // try to find problem with id in this category problem = category.ProblemCovers.SingleOrDefault(p => p.Id == id); // if successfully found if (problem != null) { // break the loop break; } } // return problem cover return(problem); }
public async Task CreateProblemCover() { try { Guild guild = Guilds.GetGuild(Context.Guild.Id); string msg = "Guild Category List:\n"; foreach (Category category in guild.Categories) { msg += $"{category.Id} - {category.Name} ({category.ProblemCovers.Count}/{category.Questions.Count})\n"; } msg += "\nPodaj indeks kategorii:"; await Context.Channel.SendMessageAsync(msg); SocketMessage massageWithCategoryId = await NextMessageAsync(true, true, TimeSpan.FromMinutes(2)); if (massageWithCategoryId == null) { await Context.Channel.SendMessageAsync("Nie otrzymano informacji zwrotnej. Wstrzymano dodawanie pytania."); return; } Category desiredCategory = guild.Categories.SingleOrDefault(x => x.Id == Int32.Parse(massageWithCategoryId.Content.Trim())); if (desiredCategory == null) { await Context.Channel.SendMessageAsync("Nie znaleziono kategorii. Wstrzymano dodawanie pytania."); return; } await ReplyAsync("Podaj tytuł problemu:"); SocketMessage messageWithProblemTitle = await NextMessageAsync(true, true, TimeSpan.FromMinutes(2)); if (messageWithProblemTitle == null) { await Context.Channel.SendMessageAsync("Nie otrzymano informacji zwrotnej. Wstrzymano dodawanie pytania."); return; } string title = messageWithProblemTitle.Content; await ReplyAsync("Podaj treść opracowania:"); SocketMessage messageWithProblemDescription = await NextMessageAsync(true, true, TimeSpan.FromMinutes(2)); if (messageWithProblemDescription == null) { await Context.Channel.SendMessageAsync("Nie otrzymano informacji zwrotnej. Wstrzymano dodawanie pytania."); return; } string description = messageWithProblemDescription.Content; await ReplyAsync("Podaj URL zdjęcia do opracowania (zignoruj tą wiadomość przez min, aby nic nie dodawać):"); string imageURL = null; SocketMessage messageWithImageUrl = await NextMessageAsync(true, true, TimeSpan.FromMinutes(2)); if (messageWithImageUrl != null) { imageURL = messageWithImageUrl.Content; } ProblemCover problem = ProblemCovers.CreateProblemCover(title, description, guild.Categories, imageURL); desiredCategory.ProblemCovers.Add(problem); Guilds.Save(); await Context.Channel.SendMessageAsync("Dodano opracowanie problemu."); } catch (Exception) { await ReplyAsync("Niewłaściwy format. Wstrzymano dodawanie pytania."); return; } }