~ow fix for no rank players
This commit is contained in:
		| @@ -1,102 +1,102 @@ | |||||||
| using Discord; | using Discord; | ||||||
| using Discord.Commands; | using Discord.Commands; | ||||||
| using NadekoBot.Attributes; | using NadekoBot.Attributes; | ||||||
| using NadekoBot.Extensions; | using NadekoBot.Extensions; | ||||||
| using NadekoBot.Modules.Searches.Models; | using NadekoBot.Modules.Searches.Models; | ||||||
| using Newtonsoft.Json; | using Newtonsoft.Json; | ||||||
| using NLog; | using NLog; | ||||||
| using System.Net.Http; | using System.Net.Http; | ||||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
|  |  | ||||||
| namespace NadekoBot.Modules.Searches | namespace NadekoBot.Modules.Searches | ||||||
| { | { | ||||||
|     public partial class Searches |     public partial class Searches | ||||||
|     { |     { | ||||||
|         [Group] |         [Group] | ||||||
|         public class OverwatchCommands : ModuleBase |         public class OverwatchCommands : ModuleBase | ||||||
|         { |         { | ||||||
|             private readonly Logger _log; |             private readonly Logger _log; | ||||||
|             public OverwatchCommands() |             public OverwatchCommands() | ||||||
|             { |             { | ||||||
|                 _log = LogManager.GetCurrentClassLogger(); |                 _log = LogManager.GetCurrentClassLogger(); | ||||||
|             } |             } | ||||||
|             [NadekoCommand, Usage, Description, Aliases] |             [NadekoCommand, Usage, Description, Aliases] | ||||||
|             public async Task Overwatch(string region, [Remainder] string query = null) |             public async Task Overwatch(string region, [Remainder] string query = null) | ||||||
|             { |             { | ||||||
|                 if (string.IsNullOrWhiteSpace(query)) |                 if (string.IsNullOrWhiteSpace(query)) | ||||||
|                     return; |                     return; | ||||||
|                 var battletag = Regex.Replace(query, "#", "-", RegexOptions.IgnoreCase); |                 var battletag = Regex.Replace(query, "#", "-", RegexOptions.IgnoreCase); | ||||||
|  |  | ||||||
|                 await Context.Channel.TriggerTypingAsync().ConfigureAwait(false); |                 await Context.Channel.TriggerTypingAsync().ConfigureAwait(false); | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
|                     await Context.Channel.TriggerTypingAsync().ConfigureAwait(false); |                     await Context.Channel.TriggerTypingAsync().ConfigureAwait(false); | ||||||
|                     var model = await GetProfile(region, battletag); |                     var model = await GetProfile(region, battletag); | ||||||
|                          |                          | ||||||
|                     var rankimg = $"{model.Competitive.rank_img}"; |                     var rankimg = $"{model.Competitive.rank_img}"; | ||||||
|                     var rank = $"{model.Competitive.rank}"; |                     var rank = $"{model.Competitive.rank}"; | ||||||
|                     var competitiveplay = $"{model.Games.Competitive.played}"; |                     var competitiveplay = $"{model.Games.Competitive.played}"; | ||||||
|                     if (string.IsNullOrWhiteSpace(rank)) |                     if (string.IsNullOrWhiteSpace(rank)) | ||||||
|                     { |                     { | ||||||
|                         var embed = new EmbedBuilder() |                         var embed = new EmbedBuilder() | ||||||
|                             .WithAuthor(eau => eau.WithName($"{model.username}") |                             .WithAuthor(eau => eau.WithName($"{model.username}") | ||||||
|                             .WithUrl($"https://www.overbuff.com/players/pc/{battletag}") |                             .WithUrl($"https://www.overbuff.com/players/pc/{battletag}") | ||||||
|                             .WithIconUrl($"{model.avatar}")) |                             .WithIconUrl($"{model.avatar}")) | ||||||
|                             .WithThumbnailUrl("https://cdn.discordapp.com/attachments/155726317222887425/255653487512256512/YZ4w2ey.png") |                             .WithThumbnailUrl("https://cdn.discordapp.com/attachments/155726317222887425/255653487512256512/YZ4w2ey.png") | ||||||
|                             .AddField(fb => fb.WithName("**Level**").WithValue($"{model.level}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Level**").WithValue($"{model.level}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Quick Wins**").WithValue($"{model.Games.Quick.wins}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Quick Wins**").WithValue($"{model.Games.Quick.wins}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Current Competitive Wins**").WithValue($"{model.Games.Competitive.wins}").WithIsInline(true)) |                             //.AddField(fb => fb.WithName("**Current Competitive Wins**").WithValue($"{model.Games.Competitive.wins}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Current Competitive Loses**").WithValue($"{model.Games.Competitive.lost}").WithIsInline(true)) |                             //.AddField(fb => fb.WithName("**Current Competitive Loses**").WithValue($"{model.Games.Competitive.lost}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Current Competitive Played**").WithValue($"{model.Games.Competitive.played}").WithIsInline(true)) |                             //.AddField(fb => fb.WithName("**Current Competitive Played**").WithValue($"{model.Games.Competitive.played}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Competitive Rank**").WithValue("0").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Competitive Rank**").WithValue("0").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Competitive Playtime**").WithValue($"{model.Playtime.competitive}").WithIsInline(true)) |                             //.AddField(fb => fb.WithName("**Competitive Playtime**").WithValue($"{model.Playtime.competitive}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Quick Playtime**").WithValue($"{model.Playtime.quick}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Quick Playtime**").WithValue($"{model.Playtime.quick}").WithIsInline(true)) | ||||||
|                             .WithOkColor(); |                             .WithOkColor(); | ||||||
|                         await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); |                         await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); | ||||||
|                     } |                     } | ||||||
|                     else |                     else | ||||||
|                     { |                     { | ||||||
|                         var embed = new EmbedBuilder() |                         var embed = new EmbedBuilder() | ||||||
|                             .WithAuthor(eau => eau.WithName($"{model.username}") |                             .WithAuthor(eau => eau.WithName($"{model.username}") | ||||||
|                             .WithUrl($"https://www.overbuff.com/players/pc/{battletag}") |                             .WithUrl($"https://www.overbuff.com/players/pc/{battletag}") | ||||||
|                             .WithIconUrl($"{model.avatar}")) |                             .WithIconUrl($"{model.avatar}")) | ||||||
|                             .WithThumbnailUrl(rankimg) |                             .WithThumbnailUrl(rankimg) | ||||||
|                             .AddField(fb => fb.WithName("**Level**").WithValue($"{model.level}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Level**").WithValue($"{model.level}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Quick Wins**").WithValue($"{model.Games.Quick.wins}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Quick Wins**").WithValue($"{model.Games.Quick.wins}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Current Competitive Wins**").WithValue($"{model.Games.Competitive.wins}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Current Competitive Wins**").WithValue($"{model.Games.Competitive.wins}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Current Competitive Loses**").WithValue($"{model.Games.Competitive.lost}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Current Competitive Loses**").WithValue($"{model.Games.Competitive.lost}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Current Competitive Played**").WithValue($"{model.Games.Competitive.played}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Current Competitive Played**").WithValue($"{model.Games.Competitive.played}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Competitive Rank**").WithValue(rank).WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Competitive Rank**").WithValue(rank).WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Competitive Playtime**").WithValue($"{model.Playtime.competitive}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Competitive Playtime**").WithValue($"{model.Playtime.competitive}").WithIsInline(true)) | ||||||
|                             .AddField(fb => fb.WithName("**Quick Playtime**").WithValue($"{model.Playtime.quick}").WithIsInline(true)) |                             .AddField(fb => fb.WithName("**Quick Playtime**").WithValue($"{model.Playtime.quick}").WithIsInline(true)) | ||||||
|                             .WithColor(NadekoBot.OkColor); |                             .WithColor(NadekoBot.OkColor); | ||||||
|                         await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); |                         await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); | ||||||
|                         return; |                         return; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 catch |                 catch | ||||||
|                 { |                 { | ||||||
|                     await Context.Channel.SendErrorAsync("Found no user! Please check the **Region** and **BattleTag** before trying again."); |                     await Context.Channel.SendErrorAsync("Found no user! Please check the **Region** and **BattleTag** before trying again."); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             public async Task<OverwatchApiModel.OverwatchPlayer.Data> GetProfile(string region, string battletag) |             public async Task<OverwatchApiModel.OverwatchPlayer.Data> GetProfile(string region, string battletag) | ||||||
|             { |             { | ||||||
|                 try |                 try | ||||||
|                 { |                 { | ||||||
|                     using (var http = new HttpClient()) |                     using (var http = new HttpClient()) | ||||||
|                     { |                     { | ||||||
|                         var Url = await http.GetStringAsync($"https://api.lootbox.eu/pc/{region.ToLower()}/{battletag}/profile"); |                         var Url = await http.GetStringAsync($"https://api.lootbox.eu/pc/{region.ToLower()}/{battletag}/profile"); | ||||||
|                         var model = JsonConvert.DeserializeObject<OverwatchApiModel.OverwatchPlayer>(Url); |                         var model = JsonConvert.DeserializeObject<OverwatchApiModel.OverwatchPlayer>(Url); | ||||||
|                         return model.data; |                         return model.data; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 catch |                 catch | ||||||
|                 { |                 { | ||||||
|                     return null; |                     return null; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|              |              | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user