diff --git a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs index b9566aded..1a3c3f7b1 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfCommands.cs @@ -295,6 +295,36 @@ public partial class Administration public partial Task Leave([Leftover] string guildStr) => _service.LeaveGuild(guildStr); + [Cmd] + [OwnerOnly] + public async partial Task DeleteEmptyServers() + { + await ctx.Channel.TriggerTypingAsync(); + + var toLeave = _client.Guilds + .Where(s => s.MemberCount == 1 && s.Users.Count == 1) + .ToList(); + + foreach (var server in toLeave) + { + try + { + await server.DeleteAsync(); + Log.Information("Deleted server {ServerName} [{ServerId}]", + server.Name, + server.Id); + } + catch (Exception ex) + { + Log.Warning(ex, + "Error leaving server {ServerName} [{ServerId}]", + server.Name, + server.Id); + } + } + + await ReplyConfirmLocalizedAsync(strs.deleted_x_servers(toLeave.Count)); + } [Cmd] [OwnerOnly] diff --git a/src/NadekoBot/data/aliases.yml b/src/NadekoBot/data/aliases.yml index 91dffe330..01e49e108 100644 --- a/src/NadekoBot/data/aliases.yml +++ b/src/NadekoBot/data/aliases.yml @@ -1260,4 +1260,6 @@ expredit: exprsimport: - eximport exprsexport: - - exexport \ No newline at end of file + - exexport +deleteemptyservers: + - deleteemptyservers diff --git a/src/NadekoBot/data/strings/commands/commands.en-US.yml b/src/NadekoBot/data/strings/commands/commands.en-US.yml index 221738c36..344c7f54b 100644 --- a/src/NadekoBot/data/strings/commands/commands.en-US.yml +++ b/src/NadekoBot/data/strings/commands/commands.en-US.yml @@ -2140,4 +2140,8 @@ showembed: desc: "Prints the json equivalent of the embed of the message specified by its Id." args: - "820022733172121600" - - "#some-channel 820022733172121600" \ No newline at end of file + - "#some-channel 820022733172121600" +deleteemptyservers: + desc: "Deletes all servers in which the bot is the only member." + args: + - "" \ No newline at end of file diff --git a/src/NadekoBot/data/strings/responses/responses.en-US.json b/src/NadekoBot/data/strings/responses/responses.en-US.json index 6d388a2da..2d0b14ae5 100644 --- a/src/NadekoBot/data/strings/responses/responses.en-US.json +++ b/src/NadekoBot/data/strings/responses/responses.en-US.json @@ -966,5 +966,6 @@ "favorites": "Favorites", "tags": "Tags", "imageonly_enable": "This channel is now image-only.", - "imageonly_disable": "This channel is no longer image-only." + "imageonly_disable": "This channel is no longer image-only.", + "deleted_x_servers": "Deleted {0} servers." }