diff --git a/Geekbot.net/Commands/AdminCmd.cs b/Geekbot.net/Commands/Admin.cs similarity index 53% rename from Geekbot.net/Commands/AdminCmd.cs rename to Geekbot.net/Commands/Admin.cs index 213f9cc..376101a 100644 --- a/Geekbot.net/Commands/AdminCmd.cs +++ b/Geekbot.net/Commands/Admin.cs @@ -11,24 +11,20 @@ using StackExchange.Redis; namespace Geekbot.net.Commands { [Group("admin")] - public class AdminCmd : ModuleBase + [RequireUserPermission(GuildPermission.Administrator)] + public class Admin : ModuleBase { private readonly IDatabase _redis; private readonly DiscordSocketClient _client; - private readonly ILogger _logger; - private readonly IUserRepository _userRepository; private readonly IErrorHandler _errorHandler; - public AdminCmd(IDatabase redis, DiscordSocketClient client, ILogger logger, IUserRepository userRepositry, IErrorHandler errorHandler) + public Admin(IDatabase redis, DiscordSocketClient client, IErrorHandler errorHandler) { _redis = redis; _client = client; - _logger = logger; - _userRepository = userRepositry; _errorHandler = errorHandler; } - [RequireUserPermission(GuildPermission.Administrator)] [Command("welcome", RunMode = RunMode.Async)] [Remarks(CommandCategories.Admin)] [Summary("Set a Welcome Message (use '$user' to mention the new joined user).")] @@ -40,86 +36,6 @@ namespace Geekbot.net.Commands formatedMessage); } - [Command("youtubekey", RunMode = RunMode.Async)] - [Remarks(CommandCategories.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"); - } - - [Command("game", RunMode = RunMode.Async)] - [Remarks(CommandCategories.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}"); - await ReplyAsync($"Now Playing {key}"); - } - - [Command("popuserrepo", RunMode = RunMode.Async)] - [Remarks(CommandCategories.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 - { - _logger.Warning("[UserRepository] Populating User Repositry"); - await ReplyAsync("Starting Population of User Repository"); - foreach (var guild in _client.Guilds) - { - _logger.Information($"[UserRepository] Populating users from {guild.Name}"); - foreach (var user in guild.Users) - { - var succeded = await _userRepository.Update(user); - var inc = succeded ? success++ : failed++; - } - } - _logger.Warning("[UserRepository] Finished Updating User Repositry"); - await ReplyAsync($"Successfully Populated User Repository with {success} Users in {_client.Guilds.Count} Guilds (Failed: {failed})"); - } - catch (Exception e) - { - _errorHandler.HandleCommandException(e, Context, "Couldn't complete User Repository, see console for more info"); - } - } - - [RequireUserPermission(GuildPermission.Administrator)] [Command("modchannel", RunMode = RunMode.Async)] [Remarks(CommandCategories.Admin)] [Summary("Set a channel for moderation purposes")] @@ -140,7 +56,6 @@ namespace Geekbot.net.Commands } } - [RequireUserPermission(GuildPermission.Administrator)] [Command("showleave", RunMode = RunMode.Async)] [Remarks(CommandCategories.Admin)] [Summary("Notify modchannel when someone leaves")] @@ -167,7 +82,6 @@ namespace Geekbot.net.Commands } } - [RequireUserPermission(GuildPermission.Administrator)] [Command("showdel", RunMode = RunMode.Async)] [Remarks(CommandCategories.Admin)] [Summary("Notify modchannel when someone deletes a message")] diff --git a/Geekbot.net/Commands/Mod.cs b/Geekbot.net/Commands/Mod.cs new file mode 100644 index 0000000..62eb494 --- /dev/null +++ b/Geekbot.net/Commands/Mod.cs @@ -0,0 +1,47 @@ +using System; +using System.Text; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Geekbot.net.Lib; + +namespace Geekbot.net.Commands +{ + [Group("mod")] + [RequireUserPermission(GuildPermission.KickMembers)] + [RequireUserPermission(GuildPermission.ManageMessages)] + [RequireUserPermission(GuildPermission.ManageRoles)] + public class Mod : ModuleBase + { + private readonly IUserRepository _userRepository; + private readonly IErrorHandler _errorHandler; + + public Mod(IUserRepository userRepositry, IErrorHandler errorHandler) + { + _userRepository = userRepositry; + _errorHandler = errorHandler; + } + + [Command("namehistory", RunMode = RunMode.Async)] + [Remarks(CommandCategories.Admin)] + [Summary("See past usernames of an user")] + public async Task usernameHistory([Summary("@user")] IUser user) + { + try + { + var userRepo = _userRepository.Get(user.Id); + var sb = new StringBuilder(); + sb.AppendLine($":bust_in_silhouette: {user.Username} has been known as:"); + foreach (var name in userRepo.UsedNames) + { + sb.AppendLine($"- `{name}`"); + } + await ReplyAsync(sb.ToString()); + } + catch (Exception e) + { + _errorHandler.HandleCommandException(e, Context, "Modchannel doesn't seem to exist, please set one with `!admin modchannel [channelId]`"); + } + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Commands/Owner.cs b/Geekbot.net/Commands/Owner.cs new file mode 100644 index 0000000..c05700c --- /dev/null +++ b/Geekbot.net/Commands/Owner.cs @@ -0,0 +1,110 @@ +using System; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Discord.WebSocket; +using Geekbot.net.Lib; +using Serilog; +using StackExchange.Redis; + +namespace Geekbot.net.Commands +{ + [Group("owner")] + [RequireUserPermission(GuildPermission.Administrator)] + public class Owner : ModuleBase + { + private readonly IDatabase _redis; + private readonly DiscordSocketClient _client; + private readonly ILogger _logger; + private readonly IUserRepository _userRepository; + private readonly IErrorHandler _errorHandler; + + public Owner(IDatabase redis, DiscordSocketClient client, ILogger logger, IUserRepository userRepositry, IErrorHandler errorHandler) + { + _redis = redis; + _client = client; + _logger = logger; + _userRepository = userRepositry; + _errorHandler = errorHandler; + } + + [Command("youtubekey", RunMode = RunMode.Async)] + [Remarks(CommandCategories.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"); + } + + [Command("game", RunMode = RunMode.Async)] + [Remarks(CommandCategories.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}"); + await ReplyAsync($"Now Playing {key}"); + } + + [Command("popuserrepo", RunMode = RunMode.Async)] + [Remarks(CommandCategories.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 + { + _logger.Warning("[UserRepository] Populating User Repositry"); + await ReplyAsync("Starting Population of User Repository"); + foreach (var guild in _client.Guilds) + { + _logger.Information($"[UserRepository] Populating users from {guild.Name}"); + foreach (var user in guild.Users) + { + var succeded = await _userRepository.Update(user); + var inc = succeded ? success++ : failed++; + } + } + _logger.Warning("[UserRepository] Finished Updating User Repositry"); + await ReplyAsync($"Successfully Populated User Repository with {success} Users in {_client.Guilds.Count} Guilds (Failed: {failed})"); + } + catch (Exception e) + { + _errorHandler.HandleCommandException(e, Context, "Couldn't complete User Repository, see console for more info"); + } + } + } +} \ No newline at end of file