From b3529d9d28f91ac20ee97d92a0ad208ed8969441 Mon Sep 17 00:00:00 2001 From: samvaio Date: Thu, 15 Dec 2016 20:33:48 +0530 Subject: [PATCH] Overwatch --- .../Commands/Models/OverwatchApiModel.cs | 204 ++++++++++++++++++ .../Searches/Commands/OverwatchCommands.cs | 85 ++++++++ .../Resources/CommandStrings.Designer.cs | 27 +++ src/NadekoBot/Resources/CommandStrings.resx | 9 + 4 files changed, 325 insertions(+) create mode 100644 src/NadekoBot/Modules/Searches/Commands/Models/OverwatchApiModel.cs create mode 100644 src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs 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..aa522320 --- /dev/null +++ b/src/NadekoBot/Modules/Searches/Commands/Models/OverwatchApiModel.cs @@ -0,0 +1,204 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace NadekoBot.Modules.Searches.Models +{ + public class OverwatchApiModel + { + + //patch notes + [JsonProperty("patchNotes")] + public List PatchNotes { get; set; } + [JsonProperty("pagination")] + public OverwatchPagination Pagination { get; set; } + + //Player All Heroes Stats + public OverwatchAllHeroes AllHeroes { get; set; } + + //achievements + [JsonProperty("achievements")] + public List Achievements { get; set; } + public float totalNumberOfAchievements { get; set; } + public float numberOfAchievementsCompleted { get; set; } + public string finishedAchievements { get; set; } + + public OverwatchPlayer Player { get; set; } + + + public class OverwatchAllHeroes + { + public string MeleeFinalBlows { get; set; } + public string SoloKills { get; set; } + public string ObjectiveKills { get; set; } + public string FinalBlows { get; set; } + public string DamageDone { get; set; } + public string Eliminations { get; set; } + public string Multikills { get; set; } + public string ReconAssists { get; set; } + public string HealingDone { get; set; } + public string TeleporterPadDestroyed { get; set; } + [JsonProperty("Eliminations-MostinGame")] + public string Eliminations_MostinGame { get; set; } + [JsonProperty("FinalBlows-MostinGame")] + public string FinalBlows_MostinGame { get; set; } + [JsonProperty("DamageDone-MostinGame")] + public string DamageDone_MostinGame { get; set; } + [JsonProperty("HealingDone-MostinGame")] + public string HealingDone_MostinGame { get; set; } + [JsonProperty("DefensiveAssists-MostinGame")] + public string DefensiveAssists_MostinGame { get; set; } + [JsonProperty("OffensiveAssists-MostinGame")] + public string OffensiveAssists_MostinGame { get; set; } + [JsonProperty("ObjectiveKills-MostinGame")] + public string ObjectiveKills_MostinGame { get; set; } + [JsonProperty("ObjectiveTime-MostinGame")] + public string ObjectiveTime_MostinGame { get; set; } + [JsonProperty("Multikill-Best")] + public string Multikill_Best { get; set; } + [JsonProperty("SoloKills-MostinGame")] + public string SoloKills_MostinGame { get; set; } + [JsonProperty("TimeSpentonFire-MostinGame")] + public string TimeSpentonFire_MostinGame { get; set; } + [JsonProperty("MeleeFinalBlows-Average")] + public string MeleeFinalBlows_Average { get; set; } + [JsonProperty("TimeSpentonFire-Average")] + public string TimeSpentonFire_Average { get; set; } + [JsonProperty("SoloKills-Average")] + public string SoloKills_Average { get; set; } + [JsonProperty("ObjectiveTime-Average")] + public string ObjectiveTime_Average { get; set; } + [JsonProperty("ObjectiveKills-Average")] + public string ObjectiveKills_Average { get; set; } + [JsonProperty("HealingDone-Average")] + public string HealingDone_Average { get; set; } + [JsonProperty("FinalBlows-Average")] + public string FinalBlows_Average { get; set; } + [JsonProperty("Deaths-Average")] + public string Deaths_Average { get; set; } + [JsonProperty("DamageDone-Average")] + public string DamageDone_Average { get; set; } + [JsonProperty("Eliminations-Average")] + public string Eliminations_Average { get; set; } + public string Deaths { get; set; } + public string EnvironmentalDeaths { get; set; } + public string Cards { get; set; } + public string Medals { get; set; } + [JsonProperty("Medals-Gold")] + public string Medals_Gold { get; set; } + [JsonProperty("Medals-Silver")] + public string Medals_Silver { get; set; } + [JsonProperty("Medals-Bronze")] + public string Medals_Bronze { get; set; } + public string GamesPlayed { get; set; } + public string GamesWon { get; set; } + public string TimeSpentonFire { get; set; } + public string ObjectiveTime { get; set; } + public string TimePlayed { get; set; } + [JsonProperty("MeleeFinalBlows-MostinGame")] + public string MeleeFinalBlows_MostinGame { get; set; } + public string GamesTied { get; set; } + public string GamesLost { get; set; } + [JsonProperty("ReconAssists-Average")] + public string ReconAssists_Average { get; set; } + public string DefensiveAssists { get; set; } + [JsonProperty("DefensiveAssists-Average")] + public string DefensiveAssists_Average { get; set; } + public string OffensiveAssists { get; set; } + [JsonProperty("OffensiveAssists-Average")] + public string OffensiveAssists_Average { 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; } + } + } + } + + public class OverwatchPatchNotes + { + public bool Missing { get; set; } = false; + public string program { get; set; } + public string locale { get; set; } + public string type { get; set; } + public string patchVersion { get; set; } + public string status { get; set; } + public string detail { get; set; } + public int buildNumber { get; set; } + public object publish { get; set; } + public object created { get; set; } + public bool updated { get; set; } + public string slug { get; set; } + public string version { get; set; } + } + + public class OverwatchPagination + { + public bool Missing { get; set; } = false; + public float totalEntries { get; set; } + public float totalPages { get; set; } + public float pageSize { get; set; } + public float page { get; set; } + } + + public class OverwatchAchievements + { + public bool Missing { get; set; } = false; + public string name { get; set; } + public bool finished { get; set; } + public string image { get; set; } + public string description { get; set; } + public object category { 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..6a8bc9d4 --- /dev/null +++ b/src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs @@ -0,0 +1,85 @@ +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."); + } + } + } + } +} 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