~ow fixed

This commit is contained in:
Master Kwoth 2017-05-17 19:43:30 +02:00
parent aebb4398fd
commit 95899f0542
2 changed files with 94 additions and 83 deletions

View File

@ -8,59 +8,55 @@ namespace NadekoBot.Modules.Searches.Models
{
public OverwatchPlayer Player { get; set; }
public class OverwatchResponse
{
public object _request;
public OverwatchPlayer Eu { get; set; }
public OverwatchPlayer Kr { get; set; }
public OverwatchPlayer Us { 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 StatsField Stats { get; set; }
}
public class OverwatchQG
public class StatsField
{
public string wins { get; set; }
public Stats Quickplay { get; set; }
public Stats Competitive { get; set; }
}
public class OverwatchCOMP
public class Stats
{
public string wins { get; set; }
public int lost { get; set; }
public string played { get; set; }
[JsonProperty("overall_stats")]
public OverallStats OverallStats { get; set; }
[JsonProperty("game_stats")]
public GameStats GameStats { get; set; }
}
}
public class OverwatchCompetitive
public class OverallStats
{
public string rank { get; set; }
public string rank_img { get; set; }
public int? comprank;
public int level;
public int prestige;
public string avatar;
public int wins;
public int losses;
public int games;
public string rank_image;
}
public class OverwatchPlaytime
public class GameStats
{
public string quick { get; set; }
public string competitive { get; set; }
[JsonProperty("time_played")]
public float timePlayed;
}
}
}
//This is to strip the html from patch notes content
internal static string StripHTML(string input)
public class Competitive
{
var re = Regex.Replace(input, "<.*?>", String.Empty);
re = Regex.Replace(re, "&#160;", $@" ");
return re;
}
}
}

View File

@ -15,61 +15,67 @@ namespace NadekoBot.Modules.Searches
[Group]
public class OverwatchCommands : NadekoSubmodule
{
public enum Region
{
Eu,
Us,
Kr
}
[NadekoCommand, Usage, Description, Aliases]
public async Task Overwatch(string region, [Remainder] string query = null)
public async Task Overwatch(Region region, [Remainder] string query = null)
{
if (string.IsNullOrWhiteSpace(query))
return;
var battletag = query.Replace("#", "-");
await Context.Channel.TriggerTypingAsync().ConfigureAwait(false);
try
{
await Context.Channel.TriggerTypingAsync().ConfigureAwait(false);
var model = await GetProfile(region, battletag);
var model = (await GetProfile(region, battletag))?.Stats;
var rankimg = model.Competitive.rank_img;
var rank = model.Competitive.rank;
if (string.IsNullOrWhiteSpace(rank))
if (model != null)
{
if (model.Competitive == null)
{
var qp = model.Quickplay;
var embed = new EmbedBuilder()
.WithAuthor(eau => eau.WithName($"{model.username}")
.WithAuthor(eau => eau.WithName(query)
.WithUrl($"https://www.overbuff.com/players/pc/{battletag}")
.WithIconUrl($"{model.avatar}"))
.WithThumbnailUrl("https://cdn.discordapp.com/attachments/155726317222887425/255653487512256512/YZ4w2ey.png")
.AddField(fb => fb.WithName(GetText("level")).WithValue($"{model.level}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("quick_wins")).WithValue($"{model.Games.Quick.wins}").WithIsInline(true))
.WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/255653487512256512/YZ4w2ey.png"))
.WithThumbnailUrl(qp.OverallStats.avatar)
.AddField(fb => fb.WithName(GetText("level")).WithValue(qp.OverallStats.level.ToString()).WithIsInline(true))
.AddField(fb => fb.WithName(GetText("quick_wins")).WithValue(qp.OverallStats.wins.ToString()).WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_rank")).WithValue("0").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("quick_playtime")).WithValue($"{model.Playtime.quick}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("quick_playtime")).WithValue($"{qp.GameStats.timePlayed}hrs").WithIsInline(true))
.WithOkColor();
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
}
else
{
var qp = model.Quickplay;
var compet = model.Competitive;
var embed = new EmbedBuilder()
.WithAuthor(eau => eau.WithName($"{model.username}")
.WithAuthor(eau => eau.WithName(query)
.WithUrl($"https://www.overbuff.com/players/pc/{battletag}")
.WithIconUrl($"{model.avatar}"))
.WithThumbnailUrl(rankimg)
.AddField(fb => fb.WithName(GetText("level")).WithValue($"{model.level}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("quick_wins")).WithValue($"{model.Games.Quick.wins}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_wins")).WithValue($"{model.Games.Competitive.wins}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_loses")).WithValue($"{model.Games.Competitive.lost}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_played")).WithValue($"{model.Games.Competitive.played}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_rank")).WithValue(rank).WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_playtime")).WithValue($"{model.Playtime.competitive}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("quick_playtime")).WithValue($"{model.Playtime.quick}").WithIsInline(true))
.WithIconUrl(compet.OverallStats.rank_image))
.WithThumbnailUrl(compet.OverallStats.avatar)
.AddField(fb => fb.WithName(GetText("level")).WithValue((compet.OverallStats.level + (compet.OverallStats.prestige * 100)).ToString()).WithIsInline(true))
.AddField(fb => fb.WithName(GetText("quick_wins")).WithValue(qp.OverallStats.wins.ToString()).WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_wins")).WithValue(compet.OverallStats.wins.ToString()).WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_loses")).WithValue(compet.OverallStats.losses.ToString()).WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_played")).WithValue(compet.OverallStats.games.ToString()).WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_rank")).WithValue(compet.OverallStats.comprank.ToString()).WithIsInline(true))
.AddField(fb => fb.WithName(GetText("compet_playtime")).WithValue(compet.GameStats.timePlayed + "hrs").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("quick_playtime")).WithValue(qp.GameStats.timePlayed.ToString("F1") + "hrs").WithIsInline(true))
.WithColor(NadekoBot.OkColor);
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
}
}
catch
else
{
await ReplyErrorLocalized("ow_user_not_found").ConfigureAwait(false);
}
}
public async Task<OverwatchApiModel.OverwatchPlayer.Data> GetProfile(string region, string battletag)
public async Task<OverwatchApiModel.OverwatchPlayer> GetProfile(Region region, string battletag)
{
try
{
@ -78,11 +84,20 @@ namespace NadekoBot.Modules.Searches
handler.ServerCertificateCustomValidationCallback = (x, y, z, e) => true;
using (var http = new HttpClient(handler))
{
var url =
await http.GetStringAsync(
$"https://api.lootbox.eu/pc/{region.ToLower()}/{battletag}/profile");
var model = JsonConvert.DeserializeObject<OverwatchApiModel.OverwatchPlayer>(url);
return model.data;
http.AddFakeHeaders();
var url = $"https://owapi.nadekobot.me/api/v3/u/{battletag}/stats";
System.Console.WriteLine(url);
var res = await http.GetStringAsync($"https://owapi.nadekobot.me/api/v3/u/{battletag}/stats");
var model = JsonConvert.DeserializeObject<OverwatchApiModel.OverwatchResponse>(res);
switch (region)
{
case Region.Eu:
return model.Eu;
case Region.Kr:
return model.Kr;
default:
return model.Us;
}
}
}
}