feat: add 'pk;log show' command
This commit is contained in:
parent
c87979ef03
commit
0ee0e75e02
@ -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 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> [channel 2] [channel 3...]", "Enables message logging in certain channels");
|
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 LogDisable = new Command("log disable", "log disable all|<channel> [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 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 BlacklistShow = new Command("blacklist show", "blacklist show", "Displays the current proxy blacklist");
|
||||||
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 BlacklistAdd = new Command("blacklist add", "blacklist add all|<channel> [channel 2] [channel 3...]", "Adds certain channels to the proxy blacklist");
|
||||||
@ -142,7 +143,7 @@ public partial class CommandTree
|
|||||||
AutoproxyOff, AutoproxyFront, AutoproxyLatch, AutoproxyMember
|
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 };
|
public static Command[] BlacklistCommands = { BlacklistAdd, BlacklistRemove, BlacklistShow };
|
||||||
}
|
}
|
@ -57,6 +57,8 @@ public partial class CommandTree
|
|||||||
return ctx.Execute<ServerConfig>(LogEnable, m => m.SetLogEnabled(ctx, true));
|
return ctx.Execute<ServerConfig>(LogEnable, m => m.SetLogEnabled(ctx, true));
|
||||||
else if (ctx.Match("disable", "off"))
|
else if (ctx.Match("disable", "off"))
|
||||||
return ctx.Execute<ServerConfig>(LogDisable, m => m.SetLogEnabled(ctx, false));
|
return ctx.Execute<ServerConfig>(LogDisable, m => m.SetLogEnabled(ctx, false));
|
||||||
|
else if (ctx.Match("list", "show"))
|
||||||
|
return ctx.Execute<ServerConfig>(LogShow, m => m.ShowLogDisabledChannels(ctx));
|
||||||
else if (ctx.Match("commands"))
|
else if (ctx.Match("commands"))
|
||||||
return PrintCommandList(ctx, "message logging", LogCommands);
|
return PrintCommandList(ctx, "message logging", LogCommands);
|
||||||
else return PrintCommandExpectedError(ctx, LogCommands);
|
else return PrintCommandExpectedError(ctx, LogCommands);
|
||||||
|
@ -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<string> 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)
|
public async Task SetBlacklisted(Context ctx, bool shouldAdd)
|
||||||
{
|
{
|
||||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||||
|
@ -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 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 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 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 <on|off>` - Enables or disables [log cleanup](/staff/compatibility/#log-cleanup).
|
- `pk;logclean <on|off>` - 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 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.
|
- `pk;blacklist remove <#channel> [#channel...]` - Removes the given channel(s) from the proxy blacklist.
|
||||||
|
Loading…
Reference in New Issue
Block a user