From 0fe273151c61535d54605b6658488f83ef6a117f Mon Sep 17 00:00:00 2001 From: runebaas Date: Sun, 6 May 2018 00:59:06 +0200 Subject: [PATCH] Use Owner Attribute instead of manual inline checking --- Geekbot.net/Commands/Admin/Owner.cs | 46 +++++++---------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/Geekbot.net/Commands/Admin/Owner.cs b/Geekbot.net/Commands/Admin/Owner.cs index 39ccd8c..4d4f0f2 100644 --- a/Geekbot.net/Commands/Admin/Owner.cs +++ b/Geekbot.net/Commands/Admin/Owner.cs @@ -12,7 +12,7 @@ using StackExchange.Redis; namespace Geekbot.net.Commands.Admin { [Group("owner")] - [RequireUserPermission(GuildPermission.Administrator)] + [RequireOwner] public class Owner : ModuleBase { private readonly DiscordSocketClient _client; @@ -21,8 +21,7 @@ namespace Geekbot.net.Commands.Admin 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) { _redis = redis; _client = client; @@ -36,14 +35,6 @@ namespace Geekbot.net.Commands.Admin [Summary("Set the youtube api key")] public async Task SetYoutubeKey([Summary("API Key")] string key) { - var botOwner = Context.Guild.GetUserAsync(ulong.Parse(_redis.StringGet("botOwner"))).Result; - if (!Context.User.Id.ToString().Equals(botOwner.Id.ToString())) - { - await ReplyAsync( - $"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})"); - return; - } - _redis.StringSet("youtubeKey", key); await ReplyAsync("Apikey has been set"); } @@ -53,14 +44,6 @@ namespace Geekbot.net.Commands.Admin [Summary("Set the game that the bot is playing")] public async Task SetGame([Remainder] [Summary("Game")] string key) { - var botOwner = Context.Guild.GetUserAsync(ulong.Parse(_redis.StringGet("botOwner"))).Result; - if (!Context.User.Id.ToString().Equals(botOwner.Id.ToString())) - { - await ReplyAsync( - $"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})"); - return; - } - _redis.StringSet("Game", key); await _client.SetGameAsync(key); _logger.Information("Geekbot", $"Changed game to {key}"); @@ -72,22 +55,6 @@ namespace Geekbot.net.Commands.Admin [Summary("Populate user cache")] public async Task PopUserRepoCommand() { - try - { - var botOwner = Context.Guild.GetUserAsync(ulong.Parse(_redis.StringGet("botOwner"))).Result; - if (!Context.User.Id.ToString().Equals(botOwner.Id.ToString())) - { - await ReplyAsync( - $"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})"); - return; - } - } - catch (Exception) - { - await ReplyAsync("Sorry, only the botowner can do this"); - return; - } - var success = 0; var failed = 0; try @@ -114,5 +81,14 @@ namespace Geekbot.net.Commands.Admin "Couldn't complete User Repository, see console for more info"); } } + + [Command("error", RunMode = RunMode.Async)] + [Remarks(CommandCategories.Admin)] + [Summary("Throw an error un purpose")] + public void PurposefulError() + { + var e = new Exception("Error Generated by !owner error"); + _errorHandler.HandleCommandException(e, Context); + } } } \ No newline at end of file