Add !mmr to get League of Legends MMR numbers
This commit is contained in:
parent
913b4a5f10
commit
9003d6249e
3 changed files with 81 additions and 0 deletions
61
Geekbot.net/Commands/Integrations/LolMmr/LolMmr.cs
Normal file
61
Geekbot.net/Commands/Integrations/LolMmr/LolMmr.cs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Web;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Commands.Integrations.LolMmr
|
||||||
|
{
|
||||||
|
public class LolMmr : ModuleBase
|
||||||
|
{
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
public LolMmr(IErrorHandler errorHandler)
|
||||||
|
{
|
||||||
|
_errorHandler = errorHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("mmr", RunMode = RunMode.Async)]
|
||||||
|
[Summary("Get the League of Legends MMR for a specified summoner")]
|
||||||
|
public async Task GetMmr([Remainder] [Summary("summoner")] string summonerName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LolMmrDto data;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var name = HttpUtility.UrlEncode(summonerName.ToLower());
|
||||||
|
var httpClient = HttpAbstractions.CreateDefaultClient();
|
||||||
|
// setting the user agent in accordance with the whatismymmr.com api rules
|
||||||
|
httpClient.DefaultRequestHeaders.Remove("User-Agent");
|
||||||
|
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Linux:rocks.pizzaandcoffee.geekbot:v0.0.0");
|
||||||
|
data = await HttpAbstractions.Get<LolMmrDto>(new Uri($"https://euw.whatismymmr.com/api/v1/summoner?name={name}"), httpClient);
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
if (e.StatusCode != HttpStatusCode.NotFound) throw e;
|
||||||
|
|
||||||
|
await Context.Channel.SendMessageAsync("Player not found");
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.AppendLine($"**MMR for {summonerName}**");
|
||||||
|
sb.AppendLine($"Normal: {data.Normal.Avg}");
|
||||||
|
sb.AppendLine($"Ranked: {data.Ranked.Avg}");
|
||||||
|
sb.AppendLine($"ARAM: {data.ARAM.Avg}");
|
||||||
|
|
||||||
|
await Context.Channel.SendMessageAsync(sb.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
Geekbot.net/Commands/Integrations/LolMmr/LolMmrDto.cs
Normal file
9
Geekbot.net/Commands/Integrations/LolMmr/LolMmrDto.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Geekbot.net.Commands.Integrations.LolMmr
|
||||||
|
{
|
||||||
|
public class LolMmrDto
|
||||||
|
{
|
||||||
|
public LolMrrInfoDto Ranked { get; set; }
|
||||||
|
public LolMrrInfoDto Normal { get; set; }
|
||||||
|
public LolMrrInfoDto ARAM { get; set; }
|
||||||
|
}
|
||||||
|
}
|
11
Geekbot.net/Commands/Integrations/LolMmr/LolMrrInfoDto.cs
Normal file
11
Geekbot.net/Commands/Integrations/LolMmr/LolMrrInfoDto.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Commands.Integrations.LolMmr
|
||||||
|
{
|
||||||
|
public class LolMrrInfoDto
|
||||||
|
{
|
||||||
|
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public decimal Avg { get; set; } = 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue