From db15d302b9280bfd8b9fb789665de980df1a01bc Mon Sep 17 00:00:00 2001 From: appelemac Date: Sun, 5 Jun 2016 19:24:09 +0200 Subject: [PATCH] Leave command --- .../Administration/AdministrationModule.cs | 2 + .../Administration/Commands/SelfCommands.cs | 49 +++++++++++++++++++ NadekoBot/NadekoBot.cs | 2 +- NadekoBot/NadekoBot.csproj | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 NadekoBot/Modules/Administration/Commands/SelfCommands.cs diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index fc612d18..834fe52c 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -30,12 +30,14 @@ namespace NadekoBot.Modules.Administration commands.Add(new InfoCommands(this)); commands.Add(new CustomReactionsCommands(this)); commands.Add(new AutoAssignRole(this)); + commands.Add(new SelfCommands(this)); } public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration; public override void Install(ModuleManager manager) { + manager.CreateCommands("", cgb => { diff --git a/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs new file mode 100644 index 00000000..a09e04c3 --- /dev/null +++ b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -0,0 +1,49 @@ +using NadekoBot.Classes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord.Commands; +using NadekoBot.Modules.Permissions.Classes; + +namespace NadekoBot.Modules.Administration.Commands +{ + class SelfCommands : DiscordCommand + { + public SelfCommands(DiscordModule module) : base(module) + { + } + + internal override void Init(CommandGroupBuilder cgb) + { + cgb.CreateCommand(Module.Prefix + "leave") + .Description("Makes Nadeko leave the server. Either name or id required.\n**Usage**:.leave NSFW") + .Parameter("arg", ParameterType.Required) + .AddCheck(SimpleCheckers.OwnerOnly()) + .Do(async e => + { + var arg = e.GetArg("arg")?.Trim(); + if (string.IsNullOrWhiteSpace(arg)) + return; + var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? + NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault(); + if (server == null) + { + await e.Channel.SendMessage("Cannot find that server").ConfigureAwait(false); + return; + } + var serverId = server.Id; + if (!server.IsOwner) + { + await server.Leave(); + } + else + { + await server.Delete(); + } + await NadekoBot.SendMessageToOwner("Left server " + server.Name); + }); + } + } +} diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index d6e0974d..1c9aea9d 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -252,7 +252,7 @@ namespace NadekoBot public static bool IsOwner(ulong id) => Creds.OwnerIds.Contains(id); - public async Task SendMessageToOwner(string message) + public static async Task SendMessageToOwner(string message) { if (Config.ForwardMessages && OwnerPrivateChannel != null) await OwnerPrivateChannel.SendMessage(message).ConfigureAwait(false); diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 8789a5db..df37a039 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -136,6 +136,7 @@ +