Super basic overwatch command
This commit is contained in:
parent
9632c5c1b4
commit
60fbe3d3fa
2 changed files with 133 additions and 1 deletions
|
@ -67,7 +67,7 @@ namespace Geekbot.net.Commands
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isValidTag(string tag)
|
public static bool isValidTag(string tag)
|
||||||
{
|
{
|
||||||
var splited = tag.Split("#");
|
var splited = tag.Split("#");
|
||||||
if (splited.Length != 2) return false;
|
if (splited.Length != 2) return false;
|
||||||
|
|
132
Geekbot.net/Commands/Overwatch.cs
Normal file
132
Geekbot.net/Commands/Overwatch.cs
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
|
using Google.Apis.Util;
|
||||||
|
using OverwatchAPI;
|
||||||
|
using OverwatchAPI.Config;
|
||||||
|
using Serilog;
|
||||||
|
using StackExchange.Redis;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Commands
|
||||||
|
{
|
||||||
|
[Group("ow")]
|
||||||
|
public class Overwatch : ModuleBase
|
||||||
|
{
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IUserRepository _userRepository;
|
||||||
|
|
||||||
|
public Overwatch(IErrorHandler errorHandler, ILogger logger, IDatabase redis, IUserRepository userRepository)
|
||||||
|
{
|
||||||
|
_errorHandler = errorHandler;
|
||||||
|
_logger = logger;
|
||||||
|
_userRepository = userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("profile", RunMode = RunMode.Async)]
|
||||||
|
[Summary("Get someones overwatch profile. EU on PC only. Default battletag is your own (if set).")]
|
||||||
|
[Remarks(CommandCategories.Games)]
|
||||||
|
public async Task owProfile()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tag = _userRepository.getUserSetting(Context.User.Id, "BattleTag");
|
||||||
|
if (string.IsNullOrEmpty(tag))
|
||||||
|
{
|
||||||
|
await ReplyAsync("You have no battle Tag saved, use `!battletag`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var profile = await createProfile(tag);
|
||||||
|
if (profile == null)
|
||||||
|
{
|
||||||
|
await ReplyAsync("That player doesn't seem to exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await ReplyAsync("", false, profile.Build());
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("profile", RunMode = RunMode.Async)]
|
||||||
|
[Summary("Get someones overwatch profile. EU on PC only. Default battletag is your own (if set).")]
|
||||||
|
[Remarks(CommandCategories.Games)]
|
||||||
|
public async Task owProfile([Summary("BattleTag")] string tag)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!BattleTag.isValidTag(tag))
|
||||||
|
{
|
||||||
|
await ReplyAsync("That doesn't seem to be a valid battletag...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var profile = await createProfile(tag);
|
||||||
|
if (profile == null)
|
||||||
|
{
|
||||||
|
await ReplyAsync("That player doesn't seem to exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await ReplyAsync("", false, profile.Build());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("profile", RunMode = RunMode.Async)]
|
||||||
|
[Summary("Get someones overwatch profile. EU on PC only.")]
|
||||||
|
[Remarks(CommandCategories.Games)]
|
||||||
|
public async Task owProfile([Summary("@someone")] IUser user)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tag = _userRepository.getUserSetting(user.Id, "BattleTag");
|
||||||
|
if (string.IsNullOrEmpty(tag))
|
||||||
|
{
|
||||||
|
await ReplyAsync("This user didn't set a battletag");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var profile = await createProfile(tag);
|
||||||
|
if (profile == null)
|
||||||
|
{
|
||||||
|
await ReplyAsync("That player doesn't seem to exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await ReplyAsync("", false, profile.Build());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<EmbedBuilder> createProfile(string battletag)
|
||||||
|
{
|
||||||
|
var owConfig = new OverwatchConfig.Builder().WithRegions(Region.Eu).WithPlatforms(Platform.Pc);
|
||||||
|
using (var owClient = new OverwatchClient(owConfig))
|
||||||
|
{
|
||||||
|
var player = await owClient.GetPlayerAsync(battletag);
|
||||||
|
if (player.Username == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.Debug($"[OW] Username = {player.Username}");
|
||||||
|
var eb = new EmbedBuilder();
|
||||||
|
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||||
|
.WithIconUrl(player.ProfilePortraitUrl)
|
||||||
|
.WithName(player.Username));
|
||||||
|
eb.Url = player.ProfileUrl;
|
||||||
|
eb.AddInlineField("Level", player.PlayerLevel);
|
||||||
|
eb.AddInlineField("Current Rank", player.CompetitiveRank > 0 ? player.CompetitiveRank.ToString() : "Unranked");
|
||||||
|
|
||||||
|
return eb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue