Use Owner Attribute instead of manual inline checking
This commit is contained in:
parent
26a0c89cf7
commit
0fe273151c
1 changed files with 11 additions and 35 deletions
|
@ -12,7 +12,7 @@ using StackExchange.Redis;
|
||||||
namespace Geekbot.net.Commands.Admin
|
namespace Geekbot.net.Commands.Admin
|
||||||
{
|
{
|
||||||
[Group("owner")]
|
[Group("owner")]
|
||||||
[RequireUserPermission(GuildPermission.Administrator)]
|
[RequireOwner]
|
||||||
public class Owner : ModuleBase
|
public class Owner : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
|
@ -21,8 +21,7 @@ namespace Geekbot.net.Commands.Admin
|
||||||
private readonly IDatabase _redis;
|
private readonly IDatabase _redis;
|
||||||
private readonly IUserRepository _userRepository;
|
private readonly IUserRepository _userRepository;
|
||||||
|
|
||||||
public Owner(IDatabase redis, DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry,
|
public Owner(IDatabase redis, DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry, IErrorHandler errorHandler)
|
||||||
IErrorHandler errorHandler)
|
|
||||||
{
|
{
|
||||||
_redis = redis;
|
_redis = redis;
|
||||||
_client = client;
|
_client = client;
|
||||||
|
@ -36,14 +35,6 @@ namespace Geekbot.net.Commands.Admin
|
||||||
[Summary("Set the youtube api key")]
|
[Summary("Set the youtube api key")]
|
||||||
public async Task SetYoutubeKey([Summary("API Key")] string 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);
|
_redis.StringSet("youtubeKey", key);
|
||||||
await ReplyAsync("Apikey has been set");
|
await ReplyAsync("Apikey has been set");
|
||||||
}
|
}
|
||||||
|
@ -53,14 +44,6 @@ namespace Geekbot.net.Commands.Admin
|
||||||
[Summary("Set the game that the bot is playing")]
|
[Summary("Set the game that the bot is playing")]
|
||||||
public async Task SetGame([Remainder] [Summary("Game")] string key)
|
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);
|
_redis.StringSet("Game", key);
|
||||||
await _client.SetGameAsync(key);
|
await _client.SetGameAsync(key);
|
||||||
_logger.Information("Geekbot", $"Changed game to {key}");
|
_logger.Information("Geekbot", $"Changed game to {key}");
|
||||||
|
@ -72,22 +55,6 @@ namespace Geekbot.net.Commands.Admin
|
||||||
[Summary("Populate user cache")]
|
[Summary("Populate user cache")]
|
||||||
public async Task PopUserRepoCommand()
|
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 success = 0;
|
||||||
var failed = 0;
|
var failed = 0;
|
||||||
try
|
try
|
||||||
|
@ -114,5 +81,14 @@ namespace Geekbot.net.Commands.Admin
|
||||||
"Couldn't complete User Repository, see console for more info");
|
"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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue