diff --git a/src/Bot/Commands/Integrations/LolMmr/LolMmr.cs b/src/Bot/Commands/Integrations/LolMmr/LolMmr.cs index 3049617..511d7b8 100644 --- a/src/Bot/Commands/Integrations/LolMmr/LolMmr.cs +++ b/src/Bot/Commands/Integrations/LolMmr/LolMmr.cs @@ -46,9 +46,9 @@ namespace Geekbot.Bot.Commands.Integrations.LolMmr var sb = new StringBuilder(); sb.AppendLine($"**MMR for {summonerName}**"); - sb.AppendLine($"Normal: {data.Normal.Avg}"); - sb.AppendLine($"Ranked: {data.Ranked.Avg}"); - sb.AppendLine($"ARAM: {data.ARAM.Avg}"); + sb.AppendLine($"Normal: {data.Normal?.Avg ?? 0}"); + sb.AppendLine($"Ranked: {data.Ranked?.Avg ?? 0}"); + sb.AppendLine($"ARAM: {data.ARAM?.Avg ?? 0}"); await Context.Channel.SendMessageAsync(sb.ToString()); } diff --git a/src/Bot/Commands/Integrations/LolMmr/LolMmrDto.cs b/src/Bot/Commands/Integrations/LolMmr/LolMmrDto.cs index 51d4c85..233bcfc 100644 --- a/src/Bot/Commands/Integrations/LolMmr/LolMmrDto.cs +++ b/src/Bot/Commands/Integrations/LolMmr/LolMmrDto.cs @@ -1,9 +1,16 @@ +using System.Text.Json.Serialization; + namespace Geekbot.Bot.Commands.Integrations.LolMmr { public class LolMmrDto { + [JsonPropertyName("ranked")] public LolMrrInfoDto Ranked { get; set; } + + [JsonPropertyName("normal")] public LolMrrInfoDto Normal { get; set; } + + [JsonPropertyName("aram")] public LolMrrInfoDto ARAM { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Integrations/LolMmr/LolMrrInfoDto.cs b/src/Bot/Commands/Integrations/LolMmr/LolMrrInfoDto.cs index dfde27b..fbcc49a 100644 --- a/src/Bot/Commands/Integrations/LolMmr/LolMrrInfoDto.cs +++ b/src/Bot/Commands/Integrations/LolMmr/LolMrrInfoDto.cs @@ -5,7 +5,6 @@ namespace Geekbot.Bot.Commands.Integrations.LolMmr public class LolMrrInfoDto { [JsonPropertyName("avg")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public decimal Avg { get; set; } = 0; + public decimal? Avg { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictListItemDto.cs b/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictListItemDto.cs index 0aee35f..1daa9be 100644 --- a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictListItemDto.cs +++ b/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictListItemDto.cs @@ -1,12 +1,26 @@ -namespace Geekbot.Bot.Commands.Integrations.UbranDictionary +using System.Text.Json.Serialization; + +namespace Geekbot.Bot.Commands.Integrations.UbranDictionary { internal class UrbanListItemDto { + + [JsonPropertyName("definition")] public string Definition { get; set; } + + [JsonPropertyName("permalink")] public string Permalink { get; set; } - public string ThumbsUp { get; set; } + + [JsonPropertyName("thumbs_up")] + public int ThumbsUp { get; set; } + + [JsonPropertyName("word")] public string Word { get; set; } + + [JsonPropertyName("example")] public string Example { get; set; } - public string ThumbsDown { get; set; } + + [JsonPropertyName("thumbs_down")] + public int ThumbsDown { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictResponseDto.cs b/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictResponseDto.cs index 1846601..042b779 100644 --- a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictResponseDto.cs +++ b/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictResponseDto.cs @@ -1,10 +1,14 @@ using System.Collections.Generic; +using System.Text.Json.Serialization; namespace Geekbot.Bot.Commands.Integrations.UbranDictionary { internal class UrbanResponseDto { + [JsonPropertyName("tags")] public string[] Tags { get; set; } + + [JsonPropertyName("list")] public List List { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictionary.cs b/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictionary.cs index 9060b91..c009f69 100644 --- a/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictionary.cs +++ b/src/Bot/Commands/Integrations/UbranDictionary/UrbanDictionary.cs @@ -45,8 +45,8 @@ namespace Geekbot.Bot.Commands.Integrations.UbranDictionary if (!string.IsNullOrEmpty(definition.Definition)) eb.Description = ShortenIfToLong(definition.Definition, 1800); if (!string.IsNullOrEmpty(definition.Example)) eb.AddField("Example", ShortenIfToLong(definition.Example, 1024)); - if (!string.IsNullOrEmpty(definition.ThumbsUp)) eb.AddInlineField("Upvotes", definition.ThumbsUp); - if (!string.IsNullOrEmpty(definition.ThumbsDown)) eb.AddInlineField("Downvotes", definition.ThumbsDown); + if (definition.ThumbsUp != 0) eb.AddInlineField("Upvotes", definition.ThumbsUp); + if (definition.ThumbsDown != 0) eb.AddInlineField("Downvotes", definition.ThumbsDown); if (definitions.Tags?.Length > 0) eb.AddField("Tags", string.Join(", ", definitions.Tags)); await ReplyAsync("", false, eb.Build()); diff --git a/src/Bot/Commands/Randomness/Cat/CatResponseDto.cs b/src/Bot/Commands/Randomness/Cat/CatResponseDto.cs index febb66f..523613b 100644 --- a/src/Bot/Commands/Randomness/Cat/CatResponseDto.cs +++ b/src/Bot/Commands/Randomness/Cat/CatResponseDto.cs @@ -1,7 +1,10 @@ -namespace Geekbot.Bot.Commands.Randomness.Cat +using System.Text.Json.Serialization; + +namespace Geekbot.Bot.Commands.Randomness.Cat { internal class CatResponseDto { + [JsonPropertyName("file")] public string File { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Randomness/Chuck/ChuckNorrisJokeResponseDto.cs b/src/Bot/Commands/Randomness/Chuck/ChuckNorrisJokeResponseDto.cs index 99d9493..7c0aefa 100644 --- a/src/Bot/Commands/Randomness/Chuck/ChuckNorrisJokeResponseDto.cs +++ b/src/Bot/Commands/Randomness/Chuck/ChuckNorrisJokeResponseDto.cs @@ -1,7 +1,10 @@ -namespace Geekbot.Bot.Commands.Randomness.Chuck +using System.Text.Json.Serialization; + +namespace Geekbot.Bot.Commands.Randomness.Chuck { internal class ChuckNorrisJokeResponseDto { + [JsonPropertyName("value")] public string Value { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Randomness/Dad/DadJokeResponseDto.cs b/src/Bot/Commands/Randomness/Dad/DadJokeResponseDto.cs index 2d72bdd..012f9e9 100644 --- a/src/Bot/Commands/Randomness/Dad/DadJokeResponseDto.cs +++ b/src/Bot/Commands/Randomness/Dad/DadJokeResponseDto.cs @@ -1,7 +1,10 @@ -namespace Geekbot.Bot.Commands.Randomness.Dad +using System.Text.Json.Serialization; + +namespace Geekbot.Bot.Commands.Randomness.Dad { internal class DadJokeResponseDto { + [JsonPropertyName("joke")] public string Joke { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Randomness/Dog/DogResponseDto.cs b/src/Bot/Commands/Randomness/Dog/DogResponseDto.cs index 473c1ce..9f0dfce 100644 --- a/src/Bot/Commands/Randomness/Dog/DogResponseDto.cs +++ b/src/Bot/Commands/Randomness/Dog/DogResponseDto.cs @@ -1,7 +1,10 @@ -namespace Geekbot.Bot.Commands.Randomness.Dog +using System.Text.Json.Serialization; + +namespace Geekbot.Bot.Commands.Randomness.Dog { internal class DogResponseDto { + [JsonPropertyName("url")] public string Url { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Randomness/Greetings/GreetingBaseDto.cs b/src/Bot/Commands/Randomness/Greetings/GreetingBaseDto.cs index ae0274b..684ee5b 100644 --- a/src/Bot/Commands/Randomness/Greetings/GreetingBaseDto.cs +++ b/src/Bot/Commands/Randomness/Greetings/GreetingBaseDto.cs @@ -1,11 +1,22 @@ +using System.Text.Json.Serialization; + namespace Geekbot.Bot.Commands.Randomness.Greetings { public class GreetingBaseDto { + [JsonPropertyName("language")] public string Language { get; set; } + + [JsonPropertyName("languageNative")] public string LanguageNative { get; set; } + + [JsonPropertyName("languageCode")] public string LanguageCode { get; set; } + + [JsonPropertyName("script")] public string Script { get; set; } + + [JsonPropertyName("primary")] public GreetingDto Primary { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Randomness/Greetings/GreetingDto.cs b/src/Bot/Commands/Randomness/Greetings/GreetingDto.cs index 679e544..db7c8b6 100644 --- a/src/Bot/Commands/Randomness/Greetings/GreetingDto.cs +++ b/src/Bot/Commands/Randomness/Greetings/GreetingDto.cs @@ -1,10 +1,19 @@ +using System.Text.Json.Serialization; + namespace Geekbot.Bot.Commands.Randomness.Greetings { public class GreetingDto { + [JsonPropertyName("text")] public string Text { get; set; } + + [JsonPropertyName("dialect")] public string Dialect { get; set; } + + [JsonPropertyName("romanization")] public string Romanization { get; set; } + + [JsonPropertyName("use")] public string[] Use { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Randomness/Kanye/KanyeResponseDto.cs b/src/Bot/Commands/Randomness/Kanye/KanyeResponseDto.cs index 8ca248e..ab8c06f 100644 --- a/src/Bot/Commands/Randomness/Kanye/KanyeResponseDto.cs +++ b/src/Bot/Commands/Randomness/Kanye/KanyeResponseDto.cs @@ -1,8 +1,10 @@ +using System.Text.Json.Serialization; + namespace Geekbot.Bot.Commands.Randomness.Kanye { public class KanyeResponseDto { - public string Id { get; set; } + [JsonPropertyName("quote")] public string Quote { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Utils/Changelog/CommitAuthorDto.cs b/src/Bot/Commands/Utils/Changelog/CommitAuthorDto.cs index 7cabece..19d93eb 100644 --- a/src/Bot/Commands/Utils/Changelog/CommitAuthorDto.cs +++ b/src/Bot/Commands/Utils/Changelog/CommitAuthorDto.cs @@ -1,11 +1,17 @@ using System; +using System.Text.Json.Serialization; namespace Geekbot.Bot.Commands.Utils.Changelog { public class CommitAuthorDto { + [JsonPropertyName("name")] public string Name { get; set; } + + [JsonPropertyName("email")] public string Email { get; set; } + + [JsonPropertyName("date")] public DateTimeOffset Date { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Utils/Changelog/CommitDto.cs b/src/Bot/Commands/Utils/Changelog/CommitDto.cs index a534730..e67d08c 100644 --- a/src/Bot/Commands/Utils/Changelog/CommitDto.cs +++ b/src/Bot/Commands/Utils/Changelog/CommitDto.cs @@ -1,7 +1,10 @@ -namespace Geekbot.Bot.Commands.Utils.Changelog +using System.Text.Json.Serialization; + +namespace Geekbot.Bot.Commands.Utils.Changelog { public class CommitDto { + [JsonPropertyName("commit")] public CommitInfoDto Commit { get; set; } } } \ No newline at end of file diff --git a/src/Bot/Commands/Utils/Changelog/CommitInfoDto.cs b/src/Bot/Commands/Utils/Changelog/CommitInfoDto.cs index d6f806e..592da9e 100644 --- a/src/Bot/Commands/Utils/Changelog/CommitInfoDto.cs +++ b/src/Bot/Commands/Utils/Changelog/CommitInfoDto.cs @@ -1,8 +1,13 @@ -namespace Geekbot.Bot.Commands.Utils.Changelog +using System.Text.Json.Serialization; + +namespace Geekbot.Bot.Commands.Utils.Changelog { public class CommitInfoDto { + [JsonPropertyName("author")] public CommitAuthorDto Author { get; set; } + + [JsonPropertyName("message")] public string Message { get; set; } } } \ No newline at end of file diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index 76e509d..0474388 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -28,7 +28,6 @@ - diff --git a/src/Core/HttpAbstractions.cs b/src/Core/HttpAbstractions.cs index 33ce700..e20fe2d 100644 --- a/src/Core/HttpAbstractions.cs +++ b/src/Core/HttpAbstractions.cs @@ -5,7 +5,6 @@ using System.Text; using System.Text.Json; using System.Text.Json.Serialization; using System.Threading.Tasks; -using Newtonsoft.Json; namespace Geekbot.Core { @@ -39,7 +38,7 @@ namespace Geekbot.Core httpClient.Dispose(); } - return JsonConvert.DeserializeObject(stringResponse); + return JsonSerializer.Deserialize(stringResponse); } public static async Task Post(Uri location, object data, HttpClient httpClient = null, bool disposeClient = true) @@ -48,7 +47,7 @@ namespace Geekbot.Core httpClient.BaseAddress = location; var content = new StringContent( - System.Text.Json.JsonSerializer.Serialize(data, new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }), + JsonSerializer.Serialize(data, new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }), Encoding.UTF8, "application/json" ); @@ -61,7 +60,7 @@ namespace Geekbot.Core httpClient.Dispose(); } - return JsonConvert.DeserializeObject(stringResponse); + return JsonSerializer.Deserialize(stringResponse); } public static async Task Post(Uri location, object data, HttpClient httpClient = null, bool disposeClient = true)