Port UserRepository and remove OW stuff
This commit is contained in:
parent
d2f31d0730
commit
15034d63a3
20 changed files with 176 additions and 328 deletions
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
|||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.net.Database;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Geekbot.net.Lib.Logger;
|
||||
|
@ -17,17 +18,19 @@ namespace Geekbot.net.Commands.Admin
|
|||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private readonly IDatabase _redis;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public Owner(IDatabase redis, DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry, IErrorHandler errorHandler)
|
||||
public Owner(IDatabase redis, DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry, IErrorHandler errorHandler, DatabaseContext database)
|
||||
{
|
||||
_redis = redis;
|
||||
_client = client;
|
||||
_logger = logger;
|
||||
_userRepository = userRepositry;
|
||||
_errorHandler = errorHandler;
|
||||
_database = database;
|
||||
}
|
||||
|
||||
[Command("youtubekey", RunMode = RunMode.Async)]
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Geekbot.net.Lib.UserRepository;
|
||||
|
||||
namespace Geekbot.net.Commands.Games
|
||||
{
|
||||
[Group("battletag")]
|
||||
public class BattleTag : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public BattleTag(IErrorHandler errorHandler, IUserRepository userRepository)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
[Command(RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Games)]
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
[Command(RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Games)]
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsValidTag(string tag)
|
||||
{
|
||||
var splited = tag.Split("#");
|
||||
if (splited.Length != 2) return false;
|
||||
if (!int.TryParse(splited[1], out var discriminator)) return false;
|
||||
return splited[1].Length == 4 || splited[1].Length == 5;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Geekbot.net.Lib.UserRepository;
|
||||
using OverwatchAPI;
|
||||
using OverwatchAPI.Config;
|
||||
|
||||
namespace Geekbot.net.Commands.Games
|
||||
{
|
||||
[Group("ow")]
|
||||
public class Overwatch : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public Overwatch(IErrorHandler errorHandler, IUserRepository userRepository)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_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().WithPlatforms(Platform.Pc);
|
||||
using (var owClient = new OverwatchClient(owConfig))
|
||||
{
|
||||
var player = await owClient.GetPlayerAsync(battletag);
|
||||
if (player.Username == null) return null;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -81,7 +81,7 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
try
|
||||
{
|
||||
var guildUser = _userRepository.Get((ulong) user.Name);
|
||||
if (guildUser.Username != null)
|
||||
if (guildUser?.Username != null)
|
||||
{
|
||||
highscoreUsers.Add(new RankUserPolyfillDto
|
||||
{
|
||||
|
|
|
@ -18,11 +18,9 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IDatabase _redis;
|
||||
|
||||
public Quote(IDatabase redis, IErrorHandler errorHandler, DatabaseContext database)
|
||||
public Quote(IErrorHandler errorHandler, DatabaseContext database)
|
||||
{
|
||||
_redis = redis;
|
||||
_errorHandler = errorHandler;
|
||||
_database = database;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue