Skip to content

Commit

Permalink
Update thunderstore api json to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiao921 committed Oct 3, 2020
1 parent 9931ad0 commit abd5a3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHEF/Components/Commands/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public async Task ModInfo(
}

var embedBuilder = new EmbedBuilder();
embedBuilder.WithColor(modInfo.IsDeprecated ? Color.Red : Color.Green);

var pinkColor = new Color(255, 20, 147);
embedBuilder.WithColor(modInfo.IsDeprecated ? Color.Red : modInfo.IsNsfw() ? pinkColor : Color.Green);

embedBuilder.WithAuthor(modInfo.Owner);
embedBuilder.WithTitle($"{modInfo.Name} v{modInfo.LatestPackage().VersionNumber}");
Expand All @@ -199,6 +201,8 @@ public async Task ModInfo(
embedBuilder.AddField("DEPRECATED", "This mod is deprecated, it may not work correctly.");
}

embedBuilder.AddField("Categories", string.Join(", ", modInfo.Categories));

embedBuilder.AddField("Rating Score", modInfo.RatingScore, true);
embedBuilder.AddField("Total downloads", modInfo.TotalDownloads(), true);

Expand Down
10 changes: 9 additions & 1 deletion CHEF/Components/Commands/ThunderstoreAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ public class PackageV1
[JsonProperty("is_deprecated")]
public bool IsDeprecated { get; set; }

[JsonProperty("has_nsfw_content")]
public bool HasNsfwContent { get; set; }

[JsonProperty("categories")]
public string[] Categories { get; set; }

[JsonProperty("versions")]
public VersionV1[] Versions { get; set; }

public VersionV1 LatestPackage() => Versions[0];
public long TotalDownloads() => Versions.Sum(version => version.Downloads);
public bool IsNsfw() => HasNsfwContent ||
Categories.Any(category => category.ToLowerInvariant().Contains("nsfw"));
}

public class VersionV1
Expand All @@ -64,7 +72,7 @@ public class VersionV1
public string VersionNumber { get; set; }

[JsonProperty("dependencies")]
public string[] Dependencies { get; set; }
public object[] Dependencies { get; set; }

[JsonProperty("download_url")]
public Uri DownloadUrl { get; set; }
Expand Down

0 comments on commit abd5a3b

Please sign in to comment.