Merge pull request #896 from samdivaio/dev
Overwatch Stats by sam, fkndean and shotz
This commit is contained in:
commit
92b8466632
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
102
src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs
Normal file
102
src/NadekoBot/Modules/Searches/Commands/OverwatchCommands.cs
Normal file
@ -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<OverwatchApiModel.OverwatchPlayer.Data> 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<OverwatchApiModel.OverwatchPlayer>(Url);
|
||||||
|
return model.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
27
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -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'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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to pause p.
|
/// Looks up a localized string similar to pause p.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2781,4 +2781,13 @@
|
|||||||
<data name="crstats_usage" xml:space="preserve">
|
<data name="crstats_usage" xml:space="preserve">
|
||||||
<value>`{0}crstats` or `{0}crstats 3`</value>
|
<value>`{0}crstats` or `{0}crstats 3`</value>
|
||||||
</data>
|
</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>
|
</root>
|
Loading…
Reference in New Issue
Block a user