From 62a24b55c2c676cb34d4ea9d884d52f24be1d2ec Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 30 Sep 2016 04:24:56 +0200 Subject: [PATCH] Actually had Leave command done in another place commented out --- .../Modules/Administration/Administration.cs | 12 --- .../Commands/PlayingRotateCommands.cs | 1 - .../Administration/Commands/SelfCommands.cs | 92 ++++++++++--------- 3 files changed, 47 insertions(+), 58 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 8541f8f2..5eca1ac9 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -711,17 +711,5 @@ namespace NadekoBot.Modules.Administration await channel.SendMessageAsync($"Successfuly added a new donator. Total donated amount from this user: {don.Amount} 👑").ConfigureAwait(false); } - - [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] - [RequireContext(ContextType.Guild)] - [OwnerOnly] - public async Task Leave(IUserMessage imsg, [Remainder] IGuild guild) - { - var channel = (ITextChannel)imsg.Channel; - - await guild.LeaveAsync(); - - await channel.SendMessageAsync($"Left guild **{guild.Name}**\nId: `{guild.Id}`."); - } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs index 7bc44758..d482a256 100644 --- a/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs @@ -13,7 +13,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -//todo owner only namespace NadekoBot.Modules.Administration { public partial class Administration diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs index ef6c11a6..19b80c89 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -1,50 +1,52 @@ -//using Discord; -//using Discord.Commands; -//using Discord.WebSocket; -//using NadekoBot.Attributes; -//using System.Linq; -//using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Discord.WebSocket; +using NadekoBot.Attributes; +using System.Linq; +using System.Threading.Tasks; -////todo owner only -//namespace NadekoBot.Modules.Administration -//{ -// public partial class Administration -// { -// [Group] -// class SelfCommands -// { -// private DiscordSocketClient _client; +//todo owner only +namespace NadekoBot.Modules.Administration +{ + public partial class Administration + { + [Group] + class SelfCommands + { + private DiscordSocketClient _client; -// public SelfCommands(DiscordSocketClient client) -// { -// this._client = client; -// } + public SelfCommands(DiscordSocketClient client) + { + this._client = client; + } -// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] -// [RequireContext(ContextType.Guild)] -// public async Task Leave(IUserMessage umsg, [Remainder] string guildStr) -// { -// var channel = (ITextChannel)umsg.Channel; + [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] + [RequireContext(ContextType.Guild)] + [OwnerOnly] + public async Task Leave(IUserMessage umsg, [Remainder] string guildStr) + { + var channel = (ITextChannel)umsg.Channel; -// guildStr = guildStr.ToUpperInvariant(); -// var server = _client.GetGuilds().FirstOrDefault(g => g.Id.ToString() == guildStr) ?? _client.GetGuilds().FirstOrDefault(g => g.Name.ToUpperInvariant() == guildStr); + guildStr = guildStr.Trim().ToUpperInvariant(); + var server = _client.GetGuilds().FirstOrDefault(g => g.Id.ToString().Trim().ToUpperInvariant() == guildStr) ?? + _client.GetGuilds().FirstOrDefault(g => g.Name.Trim().ToUpperInvariant() == guildStr); -// if (server == null) -// { -// await channel.SendMessageAsync("Cannot find that server").ConfigureAwait(false); -// return; -// } -// if (server.OwnerId != _client.GetCurrentUser().Id) -// { -// await server.LeaveAsync().ConfigureAwait(false); -// await channel.SendMessageAsync("Left server " + server.Name).ConfigureAwait(false); -// } -// else -// { -// await server.DeleteAsync().ConfigureAwait(false); -// await channel.SendMessageAsync("Deleted server " + server.Name).ConfigureAwait(false); -// } -// } -// } -// } -//} \ No newline at end of file + if (server == null) + { + await channel.SendMessageAsync("Cannot find that server").ConfigureAwait(false); + return; + } + if (server.OwnerId != _client.GetCurrentUser().Id) + { + await server.LeaveAsync().ConfigureAwait(false); + await channel.SendMessageAsync("Left server " + server.Name).ConfigureAwait(false); + } + else + { + await server.DeleteAsync().ConfigureAwait(false); + await channel.SendMessageAsync("Deleted server " + server.Name).ConfigureAwait(false); + } + } + } + } +} \ No newline at end of file