mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(bot): move blacklist/logging settings to serverconfig command
This commit is contained in:
parent
1b6c635571
commit
17f094354d
4 changed files with 118 additions and 39 deletions
|
|
@ -100,15 +100,15 @@ public partial class CommandTree
|
|||
public static Command MessageEdit = new Command("edit", "edit [link] <text>", "Edit a previously proxied message");
|
||||
public static Command MessageReproxy = new Command("reproxy", "reproxy [link] <member>", "Reproxy a previously proxied message using a different member");
|
||||
public static Command ProxyCheck = new Command("debug proxy", "debug proxy [link|reply]", "Checks why your message has not been proxied");
|
||||
public static Command LogChannel = new Command("log channel", "log channel <channel>", "Designates a channel to post proxied messages to");
|
||||
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 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 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 BlacklistRemove = new Command("blacklist remove", "blacklist remove all|<channel> [channel 2] [channel 3...]", "Removes certain channels from the proxy blacklist");
|
||||
public static Command ServerConfigLogClean = new Command("serverconfig logclean", "serverconfig logclean [on|off]", "Toggles whether to clean up other bots' log channels");
|
||||
public static Command LogChannel = new Command("serverconfig log channel", "serverconfig log channel <channel>", "Designates a channel to post proxied messages to");
|
||||
public static Command LogChannelClear = new Command("serverconfig log channel", "serverconfig log channel -clear", "Clears the currently set log channel");
|
||||
public static Command LogEnable = new Command("serverconfig log blacklist remove", "serverconfig log blacklist remove all|<channel> [channel 2] [channel 3...]", "Enables message logging in certain channels");
|
||||
public static Command LogDisable = new Command("serverconfig log blacklist add", "serverconfig log blacklist add all|<channel> [channel 2] [channel 3...]", "Disables message logging in certain channels");
|
||||
public static Command LogShow = new Command("serverconfig log blacklist", "serverconfig log blacklist", "Displays the current list of channels where logging is disabled");
|
||||
public static Command BlacklistShow = new Command("serverconfig proxy blacklist", "serverconfig proxy blacklist", "Displays the current list of channels where message proxying is disabled");
|
||||
public static Command BlacklistAdd = new Command("serverconfig proxy blacklist add", "serverconfig proxy blacklist add all|<channel> [channel 2] [channel 3...]", "Disables message proxying in certain channels");
|
||||
public static Command BlacklistRemove = new Command("serverconfig blacklist remove", "serverconfig blacklist remove all|<channel> [channel 2] [channel 3...]", "Enables message proxying in certain channels");
|
||||
public static Command ServerConfigLogClean = new Command("serverconfig log cleanup", "serverconfig log cleanup [on|off]", "Toggles whether to clean up other bots' log channels");
|
||||
public static Command ServerConfigInvalidCommandResponse = new Command("serverconfig invalid command error", "serverconfig invalid command error [on|off]", "Sets whether to show an error message when an unknown command is sent");
|
||||
public static Command ServerConfigRequireSystemTag = new Command("serverconfig require tag", "serverconfig require tag [on|off]", "Sets whether server users are required to have a system tag on proxied messages");
|
||||
public static Command Invite = new Command("invite", "invite", "Gets a link to invite PluralKit to other servers");
|
||||
|
|
@ -155,7 +155,9 @@ public partial class CommandTree
|
|||
|
||||
public static Command[] ServerConfigCommands =
|
||||
{
|
||||
ServerConfigLogClean, ServerConfigInvalidCommandResponse, ServerConfigRequireSystemTag
|
||||
ServerConfigLogClean, ServerConfigInvalidCommandResponse, ServerConfigRequireSystemTag,
|
||||
LogChannel, LogChannelClear, LogShow, LogDisable, LogEnable,
|
||||
BlacklistShow, BlacklistAdd, BlacklistRemove
|
||||
};
|
||||
|
||||
public static Command[] AutoproxyCommands =
|
||||
|
|
|
|||
|
|
@ -56,28 +56,26 @@ public partial class CommandTree
|
|||
return ctx.Execute<ProxiedMessage>(MessageReproxy, m => m.ReproxyMessage(ctx));
|
||||
if (ctx.Match("log"))
|
||||
if (ctx.Match("channel"))
|
||||
return ctx.Execute<ServerConfig>(LogChannel, m => m.SetLogChannel(ctx));
|
||||
return ctx.Execute<ServerConfig>(LogChannel, m => m.SetLogChannel(ctx), true);
|
||||
else if (ctx.Match("enable", "on"))
|
||||
return ctx.Execute<ServerConfig>(LogEnable, m => m.SetLogEnabled(ctx, true));
|
||||
return ctx.Execute<ServerConfig>(LogEnable, m => m.SetLogEnabled(ctx, true), true);
|
||||
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), true);
|
||||
else if (ctx.Match("list", "show"))
|
||||
return ctx.Execute<ServerConfig>(LogShow, m => m.ShowLogDisabledChannels(ctx));
|
||||
else if (ctx.Match("commands"))
|
||||
return PrintCommandList(ctx, "message logging", LogCommands);
|
||||
else return PrintCommandExpectedError(ctx, LogCommands);
|
||||
return ctx.Execute<ServerConfig>(LogShow, m => m.ShowLogDisabledChannels(ctx), true);
|
||||
else
|
||||
return ctx.Reply($"{Emojis.Warn} Message logging commands have moved to `pk;serverconfig`.");
|
||||
if (ctx.Match("logclean"))
|
||||
return ctx.Execute<ServerConfig>(ServerConfigLogClean, m => m.SetLogCleanup(ctx), true);
|
||||
if (ctx.Match("blacklist", "bl"))
|
||||
if (ctx.Match("enable", "on", "add", "deny"))
|
||||
return ctx.Execute<ServerConfig>(BlacklistAdd, m => m.SetBlacklisted(ctx, true));
|
||||
return ctx.Execute<ServerConfig>(BlacklistAdd, m => m.SetProxyBlacklisted(ctx, true), true);
|
||||
else if (ctx.Match("disable", "off", "remove", "allow"))
|
||||
return ctx.Execute<ServerConfig>(BlacklistRemove, m => m.SetBlacklisted(ctx, false));
|
||||
return ctx.Execute<ServerConfig>(BlacklistRemove, m => m.SetProxyBlacklisted(ctx, false), true);
|
||||
else if (ctx.Match("list", "show"))
|
||||
return ctx.Execute<ServerConfig>(BlacklistShow, m => m.ShowBlacklisted(ctx));
|
||||
else if (ctx.Match("commands"))
|
||||
return PrintCommandList(ctx, "channel blacklisting", BlacklistCommands);
|
||||
else return PrintCommandExpectedError(ctx, BlacklistCommands);
|
||||
return ctx.Execute<ServerConfig>(BlacklistShow, m => m.ShowProxyBlacklisted(ctx), true);
|
||||
else
|
||||
return ctx.Reply($"{Emojis.Warn} Blacklist commands have moved to `pk;serverconfig`.");
|
||||
if (ctx.Match("proxy"))
|
||||
if (ctx.Match("debug"))
|
||||
return ctx.Execute<Checks>(ProxyCheck, m => m.MessageProxyCheck(ctx));
|
||||
|
|
@ -627,6 +625,26 @@ public partial class CommandTree
|
|||
return ctx.Execute<ServerConfig>(null, m => m.InvalidCommandResponse(ctx));
|
||||
if (ctx.MatchMultiple(new[] { "require", "enforce" }, new[] { "tag", "systemtag" }) || ctx.Match("requiretag", "enforcetag"))
|
||||
return ctx.Execute<ServerConfig>(null, m => m.RequireSystemTag(ctx));
|
||||
if (ctx.MatchMultiple(new[] { "log" }, new[] { "channel" }))
|
||||
return ctx.Execute<ServerConfig>(null, m => m.SetLogChannel(ctx));
|
||||
if (ctx.MatchMultiple(new[] { "log" }, new[] { "blacklist" }))
|
||||
{
|
||||
if (ctx.Match("enable", "on", "add", "deny"))
|
||||
return ctx.Execute<ServerConfig>(null, m => m.SetLogBlacklisted(ctx, true));
|
||||
else if (ctx.Match("disable", "off", "remove", "allow"))
|
||||
return ctx.Execute<ServerConfig>(null, m => m.SetLogBlacklisted(ctx, false));
|
||||
else
|
||||
return ctx.Execute<ServerConfig>(null, m => m.ShowLogDisabledChannels(ctx));
|
||||
}
|
||||
if (ctx.MatchMultiple(new[] { "proxy", "proxying" }, new[] { "blacklist" }))
|
||||
{
|
||||
if (ctx.Match("enable", "on", "add", "deny"))
|
||||
return ctx.Execute<ServerConfig>(null, m => m.SetProxyBlacklisted(ctx, true));
|
||||
else if (ctx.Match("disable", "off", "remove", "allow"))
|
||||
return ctx.Execute<ServerConfig>(null, m => m.SetProxyBlacklisted(ctx, false));
|
||||
else
|
||||
return ctx.Execute<ServerConfig>(null, m => m.ShowProxyBlacklisted(ctx));
|
||||
}
|
||||
|
||||
// todo: maybe add the list of configuration keys here?
|
||||
return ctx.Reply($"{Emojis.Error} Could not find a setting with that name. Please see `pk;commands serverconfig` for the list of possible config settings.");
|
||||
|
|
|
|||
|
|
@ -49,6 +49,29 @@ public class ServerConfig
|
|||
"disabled"
|
||||
));
|
||||
|
||||
items.Add(new(
|
||||
"log channel",
|
||||
"Channel to log proxied messages to",
|
||||
ctx.GuildConfig!.LogChannel != null ? $"<#{ctx.GuildConfig.LogChannel}>" : "none",
|
||||
"none"
|
||||
));
|
||||
|
||||
string ChannelListMessage(int count, string cmd) => $"{count} channels, use `pk;scfg {cmd}` to view/update";
|
||||
|
||||
items.Add(new(
|
||||
"log blacklist",
|
||||
"Channels whose proxied messages will not be logged",
|
||||
ChannelListMessage(ctx.GuildConfig!.LogBlacklist.Length, "log blacklist"),
|
||||
ChannelListMessage(0, "log blacklist")
|
||||
));
|
||||
|
||||
items.Add(new(
|
||||
"proxy blacklist",
|
||||
"Channels where message proxying is disabled",
|
||||
ChannelListMessage(ctx.GuildConfig!.Blacklist.Length, "proxy blacklist"),
|
||||
ChannelListMessage(0, "proxy blacklist")
|
||||
));
|
||||
|
||||
await ctx.Paginate<PaginatedConfigItem>(
|
||||
items.ToAsyncEnumerable(),
|
||||
items.Count,
|
||||
|
|
@ -123,6 +146,8 @@ public class ServerConfig
|
|||
await ctx.Reply($"{Emojis.Success} Proxy logging channel set to <#{channel.Id}>.");
|
||||
}
|
||||
|
||||
// legacy behaviour: enable/disable logging for commands
|
||||
// new behaviour is add/remove from log blacklist (see #LogBlacklistNew)
|
||||
public async Task SetLogEnabled(Context ctx, bool enable)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
|
@ -160,7 +185,7 @@ public class ServerConfig
|
|||
: ""));
|
||||
}
|
||||
|
||||
public async Task ShowBlacklisted(Context ctx)
|
||||
public async Task ShowProxyBlacklisted(Context ctx)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
|
|
@ -175,7 +200,7 @@ public class ServerConfig
|
|||
|
||||
if (channels.Count == 0)
|
||||
{
|
||||
await ctx.Reply("This server has no blacklisted channels.");
|
||||
await ctx.Reply("This server has no channels where proxying is disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -262,7 +287,8 @@ public class ServerConfig
|
|||
}
|
||||
|
||||
|
||||
public async Task SetBlacklisted(Context ctx, bool shouldAdd)
|
||||
|
||||
public async Task SetProxyBlacklisted(Context ctx, bool shouldAdd)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
|
|
@ -295,6 +321,39 @@ public class ServerConfig
|
|||
$"{Emojis.Success} Channels {(shouldAdd ? "added to" : "removed from")} the proxy blacklist.");
|
||||
}
|
||||
|
||||
public async Task SetLogBlacklisted(Context ctx, bool shouldAdd)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
var affectedChannels = new List<Channel>();
|
||||
if (ctx.Match("all"))
|
||||
affectedChannels = (await _cache.GetGuildChannels(ctx.Guild.Id))
|
||||
// All the channel types you can proxy in
|
||||
.Where(x => DiscordUtils.IsValidGuildChannel(x)).ToList();
|
||||
else if (!ctx.HasNext()) throw new PKSyntaxError("You must pass one or more #channels.");
|
||||
else
|
||||
while (ctx.HasNext())
|
||||
{
|
||||
var channelString = ctx.PeekArgument();
|
||||
var channel = await ctx.MatchChannel();
|
||||
if (channel == null || channel.GuildId != ctx.Guild.Id) throw Errors.ChannelNotFound(channelString);
|
||||
affectedChannels.Add(channel);
|
||||
}
|
||||
|
||||
var guild = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||
|
||||
var blacklist = guild.LogBlacklist.ToHashSet();
|
||||
if (shouldAdd)
|
||||
blacklist.UnionWith(affectedChannels.Select(c => c.Id));
|
||||
else
|
||||
blacklist.ExceptWith(affectedChannels.Select(c => c.Id));
|
||||
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogBlacklist = blacklist.ToArray() });
|
||||
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} Channels {(shouldAdd ? "added to" : "removed from")} the logging blacklist.");
|
||||
}
|
||||
|
||||
public async Task SetLogCleanup(Context ctx)
|
||||
{
|
||||
var botList = string.Join(", ", LoggerCleanService.Bots.Select(b => b.Name).OrderBy(x => x.ToLowerInvariant()));
|
||||
|
|
|
|||
|
|
@ -153,17 +153,17 @@ You can have a space after `pk;`, e.g. `pk;system` and `pk; system` will do the
|
|||
|
||||
## Server owner commands
|
||||
*(all commands here require Manage Server permission)*
|
||||
- `pk;log channel` - Shows the currently set log channel
|
||||
- `pk;log channel <channel>` - Sets the given channel to log all proxied messages.
|
||||
- `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;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;serverconfig logclean [on|off]` - Enables or disables [log cleanup](/staff/compatibility/#log-cleanup).
|
||||
- `pk;serverconfig log cleanup [on|off]` - Toggles whether to clean up other bots' log channels
|
||||
- `pk;serverconfig invalid command error [on|off]` - Sets whether to show an error message when an unknown command is sent
|
||||
- `pk;serverconfig require tag [on|off]` - Sets whether server users are required to have a system tag on proxied messages
|
||||
- `pk;serverconfig log channel <channel>` - Designates a channel to post proxied messages to
|
||||
- `pk;serverconfig log channel -clear` - Clears the currently set log channel
|
||||
- `pk;serverconfig log blacklist`- Displays the current list of channels where logging is disabled
|
||||
- `pk;serverconfig log blacklist add all|<channel> [channel 2] [channel 3...]` - Disables message logging in certain channels
|
||||
- `pk;serverconfig log blacklist remove all|<channel> [channel 2] [channel 3...]` - Enables message logging in certain channels
|
||||
- `pk;serverconfig proxy blacklist` - Displays the current proxy blacklist
|
||||
- `pk;serverconfig proxy blacklist add all|<channel> [channel 2] [channel 3...]` - Adds certain channels to the proxy blacklist
|
||||
- `pk;serverconfig blacklist remove all|<channel> [channel 2] [channel 3...]` - Removes certain channels from the proxy blacklist
|
||||
|
||||
## Utility
|
||||
- `pk;message <message id|message link|reply>` - Looks up information about a proxied message by its message ID or link.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue