2017-10-04 01:35:25 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using Geekbot.net.Lib;
|
|
|
|
|
|
|
|
|
|
namespace Geekbot.net.Commands
|
|
|
|
|
{
|
|
|
|
|
[Group("battletag")]
|
|
|
|
|
public class BattleTag : ModuleBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IErrorHandler _errorHandler;
|
|
|
|
|
private readonly IUserRepository _userRepository;
|
2017-12-29 01:53:50 +01:00
|
|
|
|
|
|
|
|
|
public BattleTag(IErrorHandler errorHandler, IUserRepository userRepository)
|
2017-10-04 01:35:25 +02:00
|
|
|
|
{
|
|
|
|
|
_errorHandler = errorHandler;
|
|
|
|
|
_userRepository = userRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command(RunMode = RunMode.Async)]
|
2017-10-12 16:34:10 +02:00
|
|
|
|
[Remarks(CommandCategories.Games)]
|
2017-10-04 01:35:25 +02:00
|
|
|
|
[Summary("Get your battletag")]
|
|
|
|
|
public async Task BattleTagCmd()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var tag = _userRepository.getUserSetting(Context.User.Id, "BattleTag");
|
|
|
|
|
if (!string.IsNullOrEmpty(tag))
|
|
|
|
|
await ReplyAsync($"Your BattleTag is {tag}");
|
|
|
|
|
else
|
|
|
|
|
await ReplyAsync("You haven't set your BattleTag, set it with `!battletag user#1234`");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler.HandleCommandException(e, Context);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-29 01:53:50 +01:00
|
|
|
|
|
2017-10-04 01:35:25 +02:00
|
|
|
|
[Command(RunMode = RunMode.Async)]
|
2017-10-12 16:34:10 +02:00
|
|
|
|
[Remarks(CommandCategories.Games)]
|
2017-10-04 01:35:25 +02:00
|
|
|
|
[Summary("Save your battletag")]
|
|
|
|
|
public async Task BattleTagCmd([Summary("Battletag")] string tag)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (isValidTag(tag))
|
|
|
|
|
{
|
|
|
|
|
_userRepository.saveUserSetting(Context.User.Id, "BattleTag", tag);
|
|
|
|
|
await ReplyAsync("Saved!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplyAsync("That doesn't seem to be a valid battletag");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler.HandleCommandException(e, Context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-13 23:40:39 +02:00
|
|
|
|
public static bool isValidTag(string tag)
|
2017-10-04 01:35:25 +02:00
|
|
|
|
{
|
|
|
|
|
var splited = tag.Split("#");
|
|
|
|
|
if (splited.Length != 2) return false;
|
2017-12-29 01:53:50 +01:00
|
|
|
|
if (!int.TryParse(splited[1], out var discriminator)) return false;
|
2017-10-04 01:35:25 +02:00
|
|
|
|
if (splited[1].Length == 4 || splited[1].Length == 5) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|