Merge pull request #896 from samdivaio/dev
Overwatch Stats by sam, fkndean and shotz
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user