diff --git a/PluralKit.Bot/CommandMeta/CommandHelp.cs b/PluralKit.Bot/CommandMeta/CommandHelp.cs index 08601749..3dc1b908 100644 --- a/PluralKit.Bot/CommandMeta/CommandHelp.cs +++ b/PluralKit.Bot/CommandMeta/CommandHelp.cs @@ -92,6 +92,7 @@ public partial class CommandTree public static Command LogChannelClear = new Command("log channel", "log channel -clear", "Clears the currently set log channel"); public static Command LogEnable = new Command("log enable", "log enable all| [channel 2] [channel 3...]", "Enables message logging in certain channels"); public static Command LogDisable = new Command("log disable", "log disable all| [channel 2] [channel 3...]", "Disables message logging in certain channels"); + public static Command LogShow = new Command("log show", "log show", "Displays the current list of channels where logging is disabled"); public static Command LogClean = new Command("logclean", "logclean [on|off]", "Toggles whether to clean up other bots' log channels"); public static Command BlacklistShow = new Command("blacklist show", "blacklist show", "Displays the current proxy blacklist"); public static Command BlacklistAdd = new Command("blacklist add", "blacklist add all| [channel 2] [channel 3...]", "Adds certain channels to the proxy blacklist"); @@ -142,7 +143,7 @@ public partial class CommandTree AutoproxyOff, AutoproxyFront, AutoproxyLatch, AutoproxyMember }; - public static Command[] LogCommands = { LogChannel, LogChannelClear, LogEnable, LogDisable }; + public static Command[] LogCommands = { LogChannel, LogChannelClear, LogEnable, LogDisable, LogShow }; public static Command[] BlacklistCommands = { BlacklistAdd, BlacklistRemove, BlacklistShow }; } \ No newline at end of file diff --git a/PluralKit.Bot/CommandMeta/CommandTree.cs b/PluralKit.Bot/CommandMeta/CommandTree.cs index 29be7bf0..d29c0751 100644 --- a/PluralKit.Bot/CommandMeta/CommandTree.cs +++ b/PluralKit.Bot/CommandMeta/CommandTree.cs @@ -57,6 +57,8 @@ public partial class CommandTree return ctx.Execute(LogEnable, m => m.SetLogEnabled(ctx, true)); else if (ctx.Match("disable", "off")) return ctx.Execute(LogDisable, m => m.SetLogEnabled(ctx, false)); + else if (ctx.Match("list", "show")) + return ctx.Execute(LogShow, m => m.ShowLogDisabledChannels(ctx)); else if (ctx.Match("commands")) return PrintCommandList(ctx, "message logging", LogCommands); else return PrintCommandExpectedError(ctx, LogCommands); diff --git a/PluralKit.Bot/Commands/ServerConfig.cs b/PluralKit.Bot/Commands/ServerConfig.cs index 5cf8bb46..fc9f2841 100644 --- a/PluralKit.Bot/Commands/ServerConfig.cs +++ b/PluralKit.Bot/Commands/ServerConfig.cs @@ -146,6 +146,57 @@ public class ServerConfig }); } + public async Task ShowLogDisabledChannels(Context ctx) + { + await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server"); + + var config = await ctx.Repository.GetGuild(ctx.Guild.Id); + + // Resolve all channels from the cache and order by position + var channels = (await Task.WhenAll(config.LogBlacklist + .Select(id => _cache.TryGetChannel(id)))) + .Where(c => c != null) + .OrderBy(c => c.Position) + .ToList(); + + if (channels.Count == 0) + { + await ctx.Reply("This server has no channels where logging is disabled."); + return; + } + + await ctx.Paginate(channels.ToAsyncEnumerable(), channels.Count, 25, + $"Channels where logging is disabled for {ctx.Guild.Name}", + null, + async (eb, l) => + { + async Task CategoryName(ulong? id) => + id != null ? (await _cache.GetChannel(id.Value)).Name : "(no category)"; + + ulong? lastCategory = null; + + var fieldValue = new StringBuilder(); + foreach (var channel in l) + { + if (lastCategory != channel!.ParentId && fieldValue.Length > 0) + { + eb.Field(new Embed.Field(await CategoryName(lastCategory), fieldValue.ToString())); + fieldValue.Clear(); + } + else + { + fieldValue.Append("\n"); + } + + fieldValue.Append(channel.Mention()); + lastCategory = channel.ParentId; + } + + eb.Field(new Embed.Field(await CategoryName(lastCategory), fieldValue.ToString())); + }); + } + + public async Task SetBlacklisted(Context ctx, bool shouldAdd) { await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server"); diff --git a/docs/content/command-list.md b/docs/content/command-list.md index d395a190..37e9cd1c 100644 --- a/docs/content/command-list.md +++ b/docs/content/command-list.md @@ -121,6 +121,7 @@ Some arguments indicate the use of specific Discord features. These include: - `pk;log channel -clear` - Clears the currently set log channel. - `pk;log disable <#channel> [#channel...]` - Disables logging messages posted in the given channel(s) (useful for staff channels and such). - `pk;log enable <#channel> [#channel...]` - Re-enables logging messages posted in the given channel(s). +- `pk;log show` - Displays the current list of channels where logging is disabled. - `pk;logclean ` - Enables or disables [log cleanup](/staff/compatibility/#log-cleanup). - `pk;blacklist add <#channel> [#channel...]` - Adds the given channel(s) to the proxy blacklist (proxying will be disabled here) - `pk;blacklist remove <#channel> [#channel...]` - Removes the given channel(s) from the proxy blacklist.