Overwatch

This commit is contained in:
samvaio 2016-12-15 20:33:48 +05:30
parent f09b9cf194
commit b3529d9d28
4 changed files with 325 additions and 0 deletions

View File

@ -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<OverwatchPatchNotes> PatchNotes { get; set; }
[JsonProperty("pagination")]
public OverwatchPagination Pagination { get; set; }
//Player All Heroes Stats
public OverwatchAllHeroes AllHeroes { get; set; }
//achievements
[JsonProperty("achievements")]
public List<OverwatchAchievements> 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, "&#160;", $@" ");
return re;
}
}
}

View File

@ -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.");
}
}
}
}
}

View File

@ -4649,6 +4649,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to overwatch ow.
/// </summary>
public static string overwatch_cmd {
get {
return ResourceManager.GetString("overwatch_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Show&apos;s basic stats on a player (competitive rank, playtime, level etc) Region codes are: `eu` `us` `cn` `kr`.
/// </summary>
public static string overwatch_desc {
get {
return ResourceManager.GetString("overwatch_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}ow us Battletag#1337` or `{0}overwatch eu Battletag#2016`.
/// </summary>
public static string overwatch_usage {
get {
return ResourceManager.GetString("overwatch_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to pause p.
/// </summary>

View File

@ -2781,4 +2781,13 @@
<data name="crstats_usage" xml:space="preserve">
<value>`{0}crstats` or `{0}crstats 3`</value>
</data>
<data name="overwatch_cmd" xml:space="preserve">
<value>overwatch ow</value>
</data>
<data name="overwatch_desc" xml:space="preserve">
<value>Show's basic stats on a player (competitive rank, playtime, level etc) Region codes are: `eu` `us` `cn` `kr`</value>
</data>
<data name="overwatch_usage" xml:space="preserve">
<value>`{0}ow us Battletag#1337` or `{0}overwatch eu Battletag#2016`</value>
</data>
</root>