Added .deleteemptyservers command

This commit is contained in:
Kwoth
2022-01-24 02:40:54 +01:00
parent a402f33a4c
commit 02e59bd5a5
4 changed files with 40 additions and 3 deletions

View File

@@ -295,6 +295,36 @@ public partial class Administration
public partial Task Leave([Leftover] string guildStr) public partial Task Leave([Leftover] string guildStr)
=> _service.LeaveGuild(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] [Cmd]
[OwnerOnly] [OwnerOnly]

View File

@@ -1260,4 +1260,6 @@ expredit:
exprsimport: exprsimport:
- eximport - eximport
exprsexport: exprsexport:
- exexport - exexport
deleteemptyservers:
- deleteemptyservers

View File

@@ -2140,4 +2140,8 @@ showembed:
desc: "Prints the json equivalent of the embed of the message specified by its Id." desc: "Prints the json equivalent of the embed of the message specified by its Id."
args: args:
- "820022733172121600" - "820022733172121600"
- "#some-channel 820022733172121600" - "#some-channel 820022733172121600"
deleteemptyservers:
desc: "Deletes all servers in which the bot is the only member."
args:
- ""

View File

@@ -966,5 +966,6 @@
"favorites": "Favorites", "favorites": "Favorites",
"tags": "Tags", "tags": "Tags",
"imageonly_enable": "This channel is now image-only.", "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."
} }