public async Task <(bool, DiscordEmbed)> TryGenWorkshopEmbed(DiscordEmbedBuilder baseEmbed, ulong id) { PublishedFileDetailsModel response = await _steamWebApiHelper.GetPublishedFileDetails(id); if (response == null || response.Result == 9) // Friends Only / Private { return(false, null); } PlayerSummaryModel userResponse = await _steamWebApiHelper.GetPlayerSummary(response.Creator); string description = string.Join(" ", Regex.Replace(response.Description, @"\[[^]]+\]", "").Split(Environment.NewLine)); if (response.PreviewUrl != null) { baseEmbed.WithThumbnail(response.PreviewUrl); } if (!string.IsNullOrWhiteSpace(description)) { baseEmbed.WithDescription(description.Length > 200 ? description.Substring(0, 200).Trim() + "..." : description); } baseEmbed .WithTitle($"{response.Title} by {userResponse.Nickname}") .WithUrl(WebLinkPrefix_FileDetails + response.PublishedFileId.ToString()) .AddField("Last Updated", response.TimeUpdated.ToString(), true) .AddField("Views", string.Format("{0:n0}", response.Views), true); if (response.Tags.Any()) { baseEmbed.AddField("Tags", string.Join(", ", response.Tags), true); } baseEmbed .AddField("Steam Client Link", ClientLinkPrefix_CommunityFilePage + response.PublishedFileId.ToString(), true); return(true, baseEmbed.Build()); }
static async Task Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; Console.CursorVisible = false; Console.Title = "WorkshopGen"; string workingPath = Directory.GetCurrentDirectory(); string configLocation = Path.Combine(workingPath, "workshopgen.json"); if (File.Exists(configLocation)) { Console.WriteLine(string.Format("Found config file at: {0}", configLocation)); string configContents = File.ReadAllText(configLocation); config = JsonConvert.DeserializeObject <Config>(configContents); } else { Console.WriteLine(string.Format("Creating config file at: {0}", configLocation)); File.WriteAllText(configLocation, JsonConvert.SerializeObject(config)); } if (string.IsNullOrEmpty(config.api_key)) { Console.WriteLine("No API key found."); return; } if (string.IsNullOrEmpty(config.workshop_id)) { Console.WriteLine("No Workshop ID found."); return; } if (string.IsNullOrEmpty(config.verbose) || (config.verbose != "true")) { Verbose = false; } if (string.IsNullOrEmpty(config.filename)) { config.filename = "workshop.lua"; } if (string.IsNullOrEmpty(config.fullpath)) { config.fullpath = workingPath; } if (args?.Length > 0) { Console.WriteLine(string.Format("Using provided Workshop ID: {0}", args[0])); config.workshop_id = args[0]; } else { Console.WriteLine(string.Format("Using default Workshop ID: {0}", config.workshop_id)); } SetupInterfaces(); // Setup the SteamRemoteStorage interface var response = await SendRequestAsync(); // Get the response from Steam WebAPI as string Root Deserialised = JsonConvert.DeserializeObject <Root>(response); // Deserialises into a Root object. List <Child> CollectionContents = Deserialised.response.collectiondetails[0].children; // We are looking for only the children of the collection. // Setting up a visual progress bar. (The generation process can take a while.) Console.Clear(); int count = CollectionContents.Count; int progress = 0; Console.Write("["); for (int i = 0; i < 50; i++) { Console.Write(" "); } Console.WriteLine("]"); // List <PublishedFileDetailsModel> Files = new List <PublishedFileDetailsModel>(); foreach (var file in Deserialised.response.collectiondetails[0].children) { var webResponse = await SteamInterface.GetPublishedFileDetailsAsync(ulong.Parse(file.publishedfileid)); try { PublishedFileDetailsModel fileDetails = webResponse.Data; // Progress bar progress++; decimal percentage = ((decimal)progress / (decimal)count) * 100; Console.SetCursorPosition(1 + (int)(percentage / 2), 0); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("\u25A0"); // block character Console.ResetColor(); Console.SetCursorPosition(0, 1); Console.WriteLine(string.Format(" {0}/{1} {2}%", progress, count, (int)percentage)); Console.WriteLine(""); // Console.WriteLine(string.Concat(fileDetails.Title, " ", fileDetails.PublishedFileId , " ")); // Output file information Files.Add(fileDetails); } catch (Exception e) { if (Verbose) { Console.WriteLine(e.Message); } } } List <string> Lua = new List <string>(); // Create a list of strings to write to our workshop.lua foreach (var file in Files) { string line = string.Format("resource.AddWorkshop(\"{0}\") ", file.PublishedFileId); line += string.Format("-- {0}", file.Title); Lua.Add(line); } if (Verbose) { Console.Clear(); foreach (var line in Lua) { Console.WriteLine(line); } } string filepath = Path.Combine(config.fullpath, config.filename); using (StreamWriter writer = new StreamWriter(File.Open(filepath, FileMode.OpenOrCreate))) { foreach (var str in Lua) { writer.WriteLine(str); } Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(string.Format("Saved to: {0}", filepath)); Console.ResetColor(); } Console.CursorVisible = true; }