diff --git a/src/NadekoBot/Modules/Searches/Commands/Models/OverwatchApiModel.cs b/src/NadekoBot/Modules/Searches/Commands/Models/OverwatchApiModel.cs new file mode 100644 index 00000000..3c6399f5 --- /dev/null +++ b/src/NadekoBot/Modules/Searches/Commands/Models/OverwatchApiModel.cs @@ -0,0 +1,67 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace NadekoBot.Modules.Searches.Models +{ + public class OverwatchApiModel + { + public OverwatchPlayer Player { get; set; } + + public class OverwatchPlayer + { + public Data data { get; set; } + public class Data + { + public bool Missing { get; set; } = false; + public string username { get; set; } + public int level { get; set; } + public string avatar { get; set; } + public string levelFrame { get; set; } + public string star { get; set; } + [JsonProperty("games")] + public OverwatchGames Games { get; set; } + [JsonProperty("playtime")] + public OverwatchPlaytime Playtime { get; set; } + [JsonProperty("competitive")] + public OverwatchCompetitive Competitive { get; set; } + public class OverwatchGames + { + [JsonProperty("quick")] + public OverwatchQG Quick { get; set; } + [JsonProperty("competitive")] + public OverwatchCOMP Competitive { get; set; } + + public class OverwatchQG + { + public string wins { get; set; } + } + public class OverwatchCOMP + { + public string wins { get; set; } + public int lost { get; set; } + public string played { get; set; } + } + } + public class OverwatchCompetitive + { + public string rank { get; set; } + public string rank_img { get; set; } + } + public class OverwatchPlaytime + { + public string quick { get; set; } + public string competitive { get; set; } + } + } + } + //This is to strip the html from patch notes content + internal static string StripHTML(string input) + { + var re = Regex.Replace(input, "<.*?>", String.Empty); + re = Regex.Replace(re, " ", $@" "); + return re; + } + } +} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs b/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs new file mode 100644 index 00000000..ec3ddfb1 --- /dev/null +++ b/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs @@ -0,0 +1,102 @@ +using Discord; +using Discord.Commands; +using NadekoBot.Attributes; +using NadekoBot.Extensions; +using NadekoBot.Modules.Searches.Models; +using Newtonsoft.Json; +using NLog; +using System; +using System.Linq; +using System.Net.Http; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace NadekoBot.Modules.Searches +{ + public partial class Searches + { + [Group] + public class OverwatchCommands + { + private Logger _log; + public OverwatchCommands() + { + _log = LogManager.GetCurrentClassLogger(); + } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task Overwatch(IUserMessage umsg, string region, [Remainder] string query = null) + { + var channel = (ITextChannel)umsg.Channel; + if (string.IsNullOrWhiteSpace(query)) + return; + var battletag = Regex.Replace(query, "#", "-", RegexOptions.IgnoreCase); + try + { + var model = await GetProfile(region, battletag); + + var rankimg = $"{model.Competitive.rank_img}"; + var rank = $"{model.Competitive.rank}"; + if (string.IsNullOrWhiteSpace(rank)) + { + var embed = new EmbedBuilder() + .WithAuthor(eau => eau.WithName($"{model.username}") + .WithUrl($"https://www.overbuff.com/players/pc/{battletag}") + .WithIconUrl($"{model.avatar}")) + .WithThumbnail(th => th.WithUrl("https://cdn.discordapp.com/attachments/155726317222887425/255653487512256512/YZ4w2ey.png")) + .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("**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 Played**").WithValue($"{model.Games.Competitive.played}").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("**Quick Playtime**").WithValue($"{model.Playtime.quick}").WithIsInline(true)) + .WithColor(NadekoBot.OkColor); + await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); + } + else + { + var embed = new EmbedBuilder() + .WithAuthor(eau => eau.WithName($"{model.username}") + .WithUrl($"https://www.overbuff.com/players/pc/{battletag}") + .WithIconUrl($"{model.avatar}")) + .WithThumbnail(th => th.WithUrl(rankimg)) + .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("**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 Played**").WithValue($"{model.Games.Competitive.played}").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("**Quick Playtime**").WithValue($"{model.Playtime.quick}").WithIsInline(true)) + .WithColor(NadekoBot.OkColor); + await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); + return; + } + } + catch + { + await channel.SendErrorAsync("Found no user! Please check the **Region** and **BattleTag** before trying again."); + } + } + public async Task GetProfile(string region, string battletag) + { + try + { + using (var http = new HttpClient()) + { + var Url = await http.GetStringAsync($"https://api.lootbox.eu/pc/{region.ToLower()}/{battletag}/profile"); + var model = JsonConvert.DeserializeObject(Url); + return model.data; + } + } + catch + { + return null; + } + } + + } + } +} diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 48ea73df..2728e701 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -4648,6 +4648,33 @@ namespace NadekoBot.Resources { return ResourceManager.GetString("osub_usage", resourceCulture); } } + + /// + /// Looks up a localized string similar to overwatch ow. + /// + public static string overwatch_cmd { + get { + return ResourceManager.GetString("overwatch_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Show's basic stats on a player (competitive rank, playtime, level etc) Region codes are: `eu` `us` `cn` `kr`. + /// + public static string overwatch_desc { + get { + return ResourceManager.GetString("overwatch_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}ow us Battletag#1337` or `{0}overwatch eu Battletag#2016`. + /// + public static string overwatch_usage { + get { + return ResourceManager.GetString("overwatch_usage", resourceCulture); + } + } /// /// Looks up a localized string similar to pause p. diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 5648c4f6..3e6df293 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2781,4 +2781,13 @@ `{0}crstats` or `{0}crstats 3` + + overwatch ow + + + Show's basic stats on a player (competitive rank, playtime, level etc) Region codes are: `eu` `us` `cn` `kr` + + + `{0}ow us Battletag#1337` or `{0}overwatch eu Battletag#2016` + \ No newline at end of file