Add logger bot cleanup support
This commit is contained in:
@@ -56,6 +56,7 @@ namespace PluralKit.Bot
|
||||
public static Command LogChannel = new Command("log channel", "log channel <channel>", "Designates a channel to post proxied messages to");
|
||||
public static Command LogEnable = new Command("log enable", "log enable all|<channel> [channel 2] [channel 3...]", "Enables message logging in certain channels");
|
||||
public static Command LogDisable = new Command("log disable", "log disable all|<channel> [channel 2] [channel 3...]", "Disables message logging in certain channels");
|
||||
public static Command LogClean = new Command("logclean", "logclean [on|off]", "Toggles whether to clean up other bots' log channels");
|
||||
public static Command BlacklistAdd = new Command("blacklist add", "blacklist add all|<channel> [channel 2] [channel 3...]", "Adds certain channels to the proxy blacklist");
|
||||
public static Command BlacklistRemove = new Command("blacklist remove", "blacklist remove all|<channel> [channel 2] [channel 3...]", "Removes certain channels from the proxy blacklist");
|
||||
public static Command Invite = new Command("invite", "invite", "Gets a link to invite PluralKit to other servers");
|
||||
@@ -127,6 +128,8 @@ namespace PluralKit.Bot
|
||||
else if (ctx.Match("disable", "off"))
|
||||
return ctx.Execute<ServerConfig>(LogDisable, m => m.SetLogEnabled(ctx, false));
|
||||
else return PrintCommandExpectedError(ctx, LogCommands);
|
||||
if (ctx.Match("logclean"))
|
||||
return ctx.Execute<ServerConfig>(LogClean, m => m.SetLogCleanup(ctx));
|
||||
if (ctx.Match("blacklist", "bl"))
|
||||
if (ctx.Match("enable", "on", "add", "deny"))
|
||||
return ctx.Execute<ServerConfig>(BlacklistAdd, m => m.SetBlacklisted(ctx, true));
|
||||
|
@@ -11,9 +11,11 @@ namespace PluralKit.Bot
|
||||
public class ServerConfig
|
||||
{
|
||||
private IDataStore _data;
|
||||
public ServerConfig(IDataStore data)
|
||||
private LoggerCleanService _cleanService;
|
||||
public ServerConfig(IDataStore data, LoggerCleanService cleanService)
|
||||
{
|
||||
_data = data;
|
||||
_cleanService = cleanService;
|
||||
}
|
||||
|
||||
public async Task SetLogChannel(Context ctx)
|
||||
@@ -84,5 +86,38 @@ namespace PluralKit.Bot
|
||||
await _data.SaveGuildConfig(guildCfg);
|
||||
await ctx.Reply($"{Emojis.Success} Channels {(onBlacklist ? "added to" : "removed from")} the proxy blacklist.");
|
||||
}
|
||||
|
||||
public async Task SetLogCleanup(Context ctx)
|
||||
{
|
||||
ctx.CheckGuildContext().CheckAuthorPermission(GuildPermission.ManageGuild, "Manage Server");
|
||||
|
||||
var guildCfg = await _data.GetOrCreateGuildConfig(ctx.Guild.Id);
|
||||
var botList = string.Join(", ", _cleanService.Bots.Select(b => b.Name).OrderBy(x => x.ToLowerInvariant()));
|
||||
|
||||
if (ctx.Match("enable", "on", "yes"))
|
||||
{
|
||||
guildCfg.LogCleanupEnabled = true;
|
||||
await _data.SaveGuildConfig(guildCfg);
|
||||
await ctx.Reply($"{Emojis.Success} Log cleanup has been **enabled** for this server. Messages deleted by PluralKit will now be cleaned up from logging channels managed by the following bots:\n- **{botList}**\n\n{Emojis.Note} Make sure PluralKit has the **Manage Messages** permission in the channels in question.\n{Emojis.Note} Also, make sure to blacklist the logging channel itself from the bots in question to prevent conflicts.");
|
||||
}
|
||||
else if (ctx.Match("disable", "off", "no"))
|
||||
{
|
||||
guildCfg.LogCleanupEnabled = false;
|
||||
await _data.SaveGuildConfig(guildCfg);
|
||||
await ctx.Reply($"{Emojis.Success} Log cleanup has been **disabled** for this server.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var eb = new EmbedBuilder()
|
||||
.WithTitle("Log cleanup settings")
|
||||
.AddField("Supported bots", botList);
|
||||
|
||||
if (guildCfg.LogCleanupEnabled)
|
||||
eb.WithDescription("Log cleanup is currently **on** for this server. To disable it, type `pk;logclean off`.");
|
||||
else
|
||||
eb.WithDescription("Log cleanup is currently **off** for this server. To enable it, type `pk;logclean on`.");
|
||||
await ctx.Reply(embed: eb.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user