public async Task Mod([Remainder] string mod) { mod = mod.RemoveWhitespace(); if (mod.EqualsIgnoreCase(">count")) { await ReplyAsync($"Found `{ModsManager.Mods.Count()}` cached mods"); return; } var(result, str) = await ShowSimilarMods(mod); if (result) { if (string.IsNullOrEmpty(str)) { // Fixes not finding files mod = ModsManager.Mods.FirstOrDefault(m => string.Equals(m, mod, StringComparison.CurrentCultureIgnoreCase)); if (mod == null) { return; } } else { mod = str; } // Some mod is found continue. var modjson = JObject.Parse(await BotUtils.FileReadToEndAsync(new SemaphoreSlim(1, 1), ModsManager.ModPath(mod))); var eb = new EmbedBuilder() .WithTitle("Mod: ") .WithCurrentTimestamp() .WithAuthor(new EmbedAuthorBuilder { IconUrl = Context.Message.Author.GetAvatarUrl(), Name = $"Requested by {Context.Message.Author.FullName()}" }); foreach (var property in modjson.Properties().Where(x => !string.IsNullOrEmpty(x.Value.ToString()))) { var name = property.Name; var value = property.Value; if (name.EqualsIgnoreCase("displayname")) { eb.Title += value.ToString(); } else if (name.EqualsIgnoreCase("downloads")) { eb.AddField("# of Downloads", $"{property.Value:n0}", true); } else if (name.EqualsIgnoreCase("updatetimestamp")) { eb.AddField("Last updated", DateTime.Parse($"{property.Value}").ToString("dddd, MMMMM d, yyyy h:mm:ss tt", new CultureInfo("en-US")), true); } else if (name.EqualsIgnoreCase("iconurl")) { eb.ThumbnailUrl = value.ToString(); } else { eb.AddField(name.FirstCharToUpper(), value, true); } } eb.AddField("Widget", $"<{ModsManager.WidgetUrl}{mod}.png>", true); using (var client = new System.Net.Http.HttpClient()) { var response = await client.GetAsync(ModsManager.QueryHomepageUrl + mod); var postResponse = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(postResponse) && !postResponse.StartsWith("Failed:")) { eb.Url = postResponse; eb.AddField("Homepage", $"<{postResponse}>", true); } } await ReplyAsync("", embed : eb.Build()); } }