mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-09 23:37:54 +00:00
implement server config commands
This commit is contained in:
parent
0f26a69f1b
commit
1627e25268
5 changed files with 350 additions and 215 deletions
|
|
@ -281,6 +281,24 @@ public partial class CommandTree
|
|||
Commands.MessageReproxy(var param, _) => ctx.Execute<ProxiedMessage>(MessageReproxy, m => m.ReproxyMessage(ctx, param.msg.MessageId, param.member)),
|
||||
Commands.Import(var param, _) => ctx.Execute<ImportExport>(Import, m => m.Import(ctx, param.url)),
|
||||
Commands.Export(_, _) => ctx.Execute<ImportExport>(Export, m => m.Export(ctx)),
|
||||
Commands.ServerConfigShow => ctx.Execute<ServerConfig>(null, m => m.ShowConfig(ctx)),
|
||||
Commands.ServerConfigLogChannelShow => ctx.Execute<ServerConfig>(null, m => m.ShowLogChannel(ctx)),
|
||||
Commands.ServerConfigLogChannelSet(var param, _) => ctx.Execute<ServerConfig>(null, m => m.SetLogChannel(ctx, param.channel)),
|
||||
Commands.ServerConfigLogChannelClear => ctx.Execute<ServerConfig>(null, m => m.ClearLogChannel(ctx)),
|
||||
Commands.ServerConfigLogCleanupShow => ctx.Execute<ServerConfig>(null, m => m.ShowLogCleanup(ctx)),
|
||||
Commands.ServerConfigLogCleanupSet(var param, _) => ctx.Execute<ServerConfig>(null, m => m.SetLogCleanup(ctx, param.toggle)),
|
||||
Commands.ServerConfigLogBlacklistShow => ctx.Execute<ServerConfig>(null, m => m.ShowLogBlacklist(ctx)),
|
||||
Commands.ServerConfigLogBlacklistAdd(var param, var flags) => ctx.Execute<ServerConfig>(null, m => m.AddLogBlacklist(ctx, param.channel, flags.all)),
|
||||
Commands.ServerConfigLogBlacklistRemove(var param, var flags) => ctx.Execute<ServerConfig>(null, m => m.RemoveLogBlacklist(ctx, param.channel, flags.all)),
|
||||
Commands.ServerConfigProxyBlacklistShow => ctx.Execute<ServerConfig>(null, m => m.ShowProxyBlacklist(ctx)),
|
||||
Commands.ServerConfigProxyBlacklistAdd(var param, var flags) => ctx.Execute<ServerConfig>(null, m => m.AddProxyBlacklist(ctx, param.channel, flags.all)),
|
||||
Commands.ServerConfigProxyBlacklistRemove(var param, var flags) => ctx.Execute<ServerConfig>(null, m => m.RemoveProxyBlacklist(ctx, param.channel, flags.all)),
|
||||
Commands.ServerConfigInvalidCommandResponseShow => ctx.Execute<ServerConfig>(null, m => m.ShowInvalidCommandResponse(ctx)),
|
||||
Commands.ServerConfigInvalidCommandResponseSet(var param, _) => ctx.Execute<ServerConfig>(null, m => m.SetInvalidCommandResponse(ctx, param.toggle)),
|
||||
Commands.ServerConfigRequireSystemTagShow => ctx.Execute<ServerConfig>(null, m => m.ShowRequireSystemTag(ctx)),
|
||||
Commands.ServerConfigRequireSystemTagSet(var param, _) => ctx.Execute<ServerConfig>(null, m => m.SetRequireSystemTag(ctx, param.toggle)),
|
||||
Commands.ServerConfigSuppressNotificationsShow => ctx.Execute<ServerConfig>(null, m => m.ShowSuppressNotifications(ctx)),
|
||||
Commands.ServerConfigSuppressNotificationsSet(var param, _) => ctx.Execute<ServerConfig>(null, m => m.SetSuppressNotifications(ctx, param.toggle)),
|
||||
Commands.AdminUpdateSystemId(var param, _) => ctx.Execute<Admin>(null, m => m.UpdateSystemId(ctx, param.target, param.new_hid)),
|
||||
Commands.AdminUpdateMemberId(var param, _) => ctx.Execute<Admin>(null, m => m.UpdateMemberId(ctx, param.target, param.new_hid)),
|
||||
Commands.AdminUpdateGroupId(var param, _) => ctx.Execute<Admin>(null, m => m.UpdateGroupId(ctx, param.target, param.new_hid)),
|
||||
|
|
@ -310,32 +328,9 @@ public partial class CommandTree
|
|||
ctx.Reply(
|
||||
$"{Emojis.Error} Parsed command {ctx.Parameters.Callback().AsCode()} not implemented in PluralKit.Bot!"),
|
||||
};
|
||||
// Legacy command routing - these are kept for backwards compatibility until fully migrated to new system
|
||||
if (ctx.Match("commands", "cmd", "c"))
|
||||
return CommandHelpRoot(ctx);
|
||||
if (ctx.Match("serverconfig", "guildconfig", "scfg"))
|
||||
return HandleServerConfigCommand(ctx);
|
||||
if (ctx.Match("log"))
|
||||
if (ctx.Match("channel"))
|
||||
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), true);
|
||||
else if (ctx.Match("disable", "off"))
|
||||
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), true);
|
||||
else
|
||||
return ctx.Reply($"{Emojis.Warn} Message logging commands have moved to `{ctx.DefaultPrefix}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.SetProxyBlacklisted(ctx, true), true);
|
||||
else if (ctx.Match("disable", "off", "remove", "allow"))
|
||||
return ctx.Execute<ServerConfig>(BlacklistRemove, m => m.SetProxyBlacklisted(ctx, false), true);
|
||||
else if (ctx.Match("list", "show"))
|
||||
return ctx.Execute<ServerConfig>(BlacklistShow, m => m.ShowProxyBlacklisted(ctx), true);
|
||||
else
|
||||
return ctx.Reply($"{Emojis.Warn} Blacklist commands have moved to `{ctx.DefaultPrefix}serverconfig`.");
|
||||
if (ctx.Match("invite")) return ctx.Execute<Misc>(Invite, m => m.Invite(ctx));
|
||||
if (ctx.Match("stats", "status")) return ctx.Execute<Misc>(null, m => m.Stats(ctx));
|
||||
}
|
||||
|
|
@ -401,42 +396,4 @@ public partial class CommandTree
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private Task HandleServerConfigCommand(Context ctx)
|
||||
{
|
||||
if (!ctx.HasNext())
|
||||
return ctx.Execute<ServerConfig>(null, m => m.ShowConfig(ctx));
|
||||
|
||||
if (ctx.MatchMultiple(new[] { "log" }, new[] { "cleanup", "clean" }) || ctx.Match("logclean"))
|
||||
return ctx.Execute<ServerConfig>(null, m => m.SetLogCleanup(ctx));
|
||||
if (ctx.MatchMultiple(new[] { "invalid", "unknown" }, new[] { "command" }, new[] { "error", "response" }) || ctx.Match("invalidcommanderror", "unknowncommanderror"))
|
||||
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[] { "suppress" }, new[] { "notifications" }) || ctx.Match("proxysilent"))
|
||||
return ctx.Execute<ServerConfig>(null, m => m.SuppressNotifications(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 `{ctx.DefaultPrefix}commands serverconfig` for the list of possible config settings.");
|
||||
}
|
||||
}
|
||||
|
|
@ -110,34 +110,27 @@ public class ServerConfig
|
|||
);
|
||||
}
|
||||
|
||||
public async Task SetLogChannel(Context ctx)
|
||||
public async Task ShowLogChannel(Context ctx)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
var settings = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("the server log channel"))
|
||||
if (settings.LogChannel == null)
|
||||
{
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogChannel = null });
|
||||
await ctx.Reply($"{Emojis.Success} Proxy logging channel cleared.");
|
||||
await ctx.Reply("This server does not have a log channel set.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ctx.HasNext())
|
||||
{
|
||||
if (settings.LogChannel == null)
|
||||
{
|
||||
await ctx.Reply("This server does not have a log channel set.");
|
||||
return;
|
||||
}
|
||||
await ctx.Reply($"This server's log channel is currently set to <#{settings.LogChannel}>.");
|
||||
}
|
||||
|
||||
await ctx.Reply($"This server's log channel is currently set to <#{settings.LogChannel}>.");
|
||||
return;
|
||||
}
|
||||
public async Task SetLogChannel(Context ctx, Channel channel)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
if (channel.GuildId != ctx.Guild.Id)
|
||||
throw Errors.ChannelNotFound(channel.Id.ToString());
|
||||
|
||||
Channel channel = null;
|
||||
var channelString = ctx.PeekArgument();
|
||||
channel = await ctx.MatchChannel();
|
||||
if (channel == null || channel.GuildId != ctx.Guild.Id) throw Errors.ChannelNotFound(channelString);
|
||||
if (channel.Type != Channel.ChannelType.GuildText && channel.Type != Channel.ChannelType.GuildPublicThread && channel.Type != Channel.ChannelType.GuildPrivateThread)
|
||||
throw new PKError("PluralKit cannot log messages to this type of channel.");
|
||||
|
||||
|
|
@ -151,46 +144,18 @@ 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)
|
||||
public async Task ClearLogChannel(Context ctx)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
var affectedChannels = new List<Channel>();
|
||||
if (ctx.Match("all"))
|
||||
affectedChannels = (await _cache.GetGuildChannels(ctx.Guild.Id))
|
||||
.Where(x => x.Type == Channel.ChannelType.GuildText).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);
|
||||
}
|
||||
if (!await ctx.ConfirmClear("the server log channel"))
|
||||
return;
|
||||
|
||||
ulong? logChannel = null;
|
||||
var config = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||
logChannel = config.LogChannel;
|
||||
|
||||
var blacklist = config.LogBlacklist.ToHashSet();
|
||||
if (enable)
|
||||
blacklist.ExceptWith(affectedChannels.Select(c => c.Id));
|
||||
else
|
||||
blacklist.UnionWith(affectedChannels.Select(c => c.Id));
|
||||
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogBlacklist = blacklist.ToArray() });
|
||||
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} Message logging for the given channels {(enable ? "enabled" : "disabled")}." +
|
||||
(logChannel == null
|
||||
? $"\n{Emojis.Warn} Please note that no logging channel is set, so there is nowhere to log messages to. You can set a logging channel using `{ctx.DefaultPrefix}serverconfig log channel #your-log-channel`."
|
||||
: ""));
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogChannel = null });
|
||||
await ctx.Reply($"{Emojis.Success} Proxy logging channel cleared.");
|
||||
}
|
||||
|
||||
public async Task ShowProxyBlacklisted(Context ctx)
|
||||
public async Task ShowProxyBlacklist(Context ctx)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
|
|
@ -240,14 +205,73 @@ public class ServerConfig
|
|||
});
|
||||
}
|
||||
|
||||
public async Task ShowLogDisabledChannels(Context ctx)
|
||||
public async Task AddProxyBlacklist(Context ctx, Channel? channel, bool all)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
var affectedChannels = new List<Channel>();
|
||||
if (all)
|
||||
{
|
||||
affectedChannels = (await _cache.GetGuildChannels(ctx.Guild.Id))
|
||||
.Where(x => DiscordUtils.IsValidGuildChannel(x)).ToList();
|
||||
}
|
||||
else if (channel != null)
|
||||
{
|
||||
if (channel.GuildId != ctx.Guild.Id)
|
||||
throw Errors.ChannelNotFound(channel.Id.ToString());
|
||||
affectedChannels.Add(channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PKSyntaxError("You must specify a channel or use the --all flag.");
|
||||
}
|
||||
|
||||
var guild = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||
var blacklist = guild.Blacklist.ToHashSet();
|
||||
blacklist.UnionWith(affectedChannels.Select(c => c.Id));
|
||||
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { Blacklist = blacklist.ToArray() });
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} {(all ? "All channels" : "Channel")} added to the proxy blacklist.");
|
||||
}
|
||||
|
||||
public async Task RemoveProxyBlacklist(Context ctx, Channel? channel, bool all)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
var affectedChannels = new List<Channel>();
|
||||
if (all)
|
||||
{
|
||||
affectedChannels = (await _cache.GetGuildChannels(ctx.Guild.Id))
|
||||
.Where(x => DiscordUtils.IsValidGuildChannel(x)).ToList();
|
||||
}
|
||||
else if (channel != null)
|
||||
{
|
||||
if (channel.GuildId != ctx.Guild.Id)
|
||||
throw Errors.ChannelNotFound(channel.Id.ToString());
|
||||
affectedChannels.Add(channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PKSyntaxError("You must specify a channel or use the --all flag.");
|
||||
}
|
||||
|
||||
var guild = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||
var blacklist = guild.Blacklist.ToHashSet();
|
||||
blacklist.ExceptWith(affectedChannels.Select(c => c.Id));
|
||||
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { Blacklist = blacklist.ToArray() });
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} {(all ? "All channels" : "Channel")} removed from the proxy blacklist.");
|
||||
}
|
||||
|
||||
public async Task ShowLogBlacklist(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
|
||||
// todo: GetAllChannels?
|
||||
var channels = (await Task.WhenAll(config.LogBlacklist
|
||||
.Select(id => _cache.TryGetChannel(ctx.Guild.Id, id))))
|
||||
.Where(c => c != null)
|
||||
|
|
@ -291,78 +315,75 @@ public class ServerConfig
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task SetProxyBlacklisted(Context ctx, bool shouldAdd)
|
||||
public async Task AddLogBlacklist(Context ctx, Channel? channel, bool all)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
var affectedChannels = new List<Channel>();
|
||||
if (ctx.Match("all"))
|
||||
if (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 if (channel != null)
|
||||
{
|
||||
if (channel.GuildId != ctx.Guild.Id)
|
||||
throw Errors.ChannelNotFound(channel.Id.ToString());
|
||||
affectedChannels.Add(channel);
|
||||
}
|
||||
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);
|
||||
}
|
||||
{
|
||||
throw new PKSyntaxError("You must specify a channel or use the --all flag.");
|
||||
}
|
||||
|
||||
var guild = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||
|
||||
var blacklist = guild.Blacklist.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 { Blacklist = blacklist.ToArray() });
|
||||
|
||||
await ctx.Reply(
|
||||
$"{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));
|
||||
blacklist.UnionWith(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." +
|
||||
$"{Emojis.Success} {(all ? "All channels" : "Channel")} added to the logging blacklist." +
|
||||
(guild.LogChannel == null
|
||||
? $"\n{Emojis.Warn} Please note that no logging channel is set, so there is nowhere to log messages to. You can set a logging channel using `{ctx.DefaultPrefix}serverconfig log channel #your-log-channel`."
|
||||
: ""));
|
||||
}
|
||||
|
||||
public async Task SetLogCleanup(Context ctx)
|
||||
public async Task RemoveLogBlacklist(Context ctx, Channel? channel, bool all)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
var affectedChannels = new List<Channel>();
|
||||
if (all)
|
||||
{
|
||||
affectedChannels = (await _cache.GetGuildChannels(ctx.Guild.Id))
|
||||
.Where(x => DiscordUtils.IsValidGuildChannel(x)).ToList();
|
||||
}
|
||||
else if (channel != null)
|
||||
{
|
||||
if (channel.GuildId != ctx.Guild.Id)
|
||||
throw Errors.ChannelNotFound(channel.Id.ToString());
|
||||
affectedChannels.Add(channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PKSyntaxError("You must specify a channel or use the --all flag.");
|
||||
}
|
||||
|
||||
var guild = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||
var blacklist = guild.LogBlacklist.ToHashSet();
|
||||
blacklist.ExceptWith(affectedChannels.Select(c => c.Id));
|
||||
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogBlacklist = blacklist.ToArray() });
|
||||
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} {(all ? "All channels" : "Channel")} removed from the logging blacklist." +
|
||||
(guild.LogChannel == null
|
||||
? $"\n{Emojis.Warn} Please note that no logging channel is set, so there is nowhere to log messages to. You can set a logging channel using `{ctx.DefaultPrefix}serverconfig log channel #your-log-channel`."
|
||||
: ""));
|
||||
}
|
||||
|
||||
public async Task ShowLogCleanup(Context ctx)
|
||||
{
|
||||
var botList = string.Join(", ", LoggerCleanService.Bots.Select(b => b.Name).OrderBy(x => x.ToLowerInvariant()));
|
||||
var eb = new EmbedBuilder()
|
||||
|
|
@ -377,74 +398,77 @@ public class ServerConfig
|
|||
}
|
||||
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
bool? newValue = ctx.MatchToggleOrNull();
|
||||
|
||||
if (newValue == null)
|
||||
{
|
||||
if (ctx.GuildConfig!.LogCleanupEnabled)
|
||||
eb.Description(
|
||||
$"Log cleanup is currently **on** for this server. To disable it, type `{ctx.DefaultPrefix}serverconfig logclean off`.");
|
||||
else
|
||||
eb.Description(
|
||||
$"Log cleanup is currently **off** for this server. To enable it, type `{ctx.DefaultPrefix}serverconfig logclean on`.");
|
||||
await ctx.Reply(embed: eb.Build());
|
||||
return;
|
||||
}
|
||||
if (ctx.GuildConfig!.LogCleanupEnabled)
|
||||
eb.Description(
|
||||
$"Log cleanup is currently **on** for this server. To disable it, type `{ctx.DefaultPrefix}serverconfig logclean off`.");
|
||||
else
|
||||
eb.Description(
|
||||
$"Log cleanup is currently **off** for this server. To enable it, type `{ctx.DefaultPrefix}serverconfig logclean on`.");
|
||||
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogCleanupEnabled = newValue.Value });
|
||||
await ctx.Reply(embed: eb.Build());
|
||||
}
|
||||
|
||||
if (newValue.Value)
|
||||
public async Task SetLogCleanup(Context ctx, bool value)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
var botList = string.Join(", ", LoggerCleanService.Bots.Select(b => b.Name).OrderBy(x => x.ToLowerInvariant()));
|
||||
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogCleanupEnabled = value });
|
||||
|
||||
if (value)
|
||||
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
|
||||
await ctx.Reply($"{Emojis.Success} Log cleanup has been **disabled** for this server.");
|
||||
}
|
||||
|
||||
public async Task InvalidCommandResponse(Context ctx)
|
||||
public async Task ShowInvalidCommandResponse(Context ctx)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
if (!ctx.HasNext())
|
||||
{
|
||||
var msg = $"Error responses for unknown/invalid commands are currently **{EnabledDisabled(ctx.GuildConfig!.InvalidCommandResponseEnabled)}**.";
|
||||
await ctx.Reply(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
var newVal = ctx.MatchToggle(false);
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new() { InvalidCommandResponseEnabled = newVal });
|
||||
await ctx.Reply($"Error responses for unknown/invalid commands are now {EnabledDisabled(newVal)}.");
|
||||
var msg = $"Error responses for unknown/invalid commands are currently **{EnabledDisabled(ctx.GuildConfig!.InvalidCommandResponseEnabled)}**.";
|
||||
await ctx.Reply(msg);
|
||||
}
|
||||
|
||||
public async Task RequireSystemTag(Context ctx)
|
||||
public async Task SetInvalidCommandResponse(Context ctx, bool value)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
if (!ctx.HasNext())
|
||||
{
|
||||
var msg = $"System tags are currently **{(ctx.GuildConfig!.RequireSystemTag ? "required" : "not required")}** for PluralKit users in this server.";
|
||||
await ctx.Reply(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
var newVal = ctx.MatchToggle(false);
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new() { RequireSystemTag = newVal });
|
||||
await ctx.Reply($"System tags are now **{(newVal ? "required" : "not required")}** for PluralKit users in this server.");
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new() { InvalidCommandResponseEnabled = value });
|
||||
await ctx.Reply($"Error responses for unknown/invalid commands are now {EnabledDisabled(value)}.");
|
||||
}
|
||||
|
||||
public async Task SuppressNotifications(Context ctx)
|
||||
public async Task ShowRequireSystemTag(Context ctx)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
if (!ctx.HasNext())
|
||||
{
|
||||
var msg = $"Suppressing notifications for proxied messages is currently **{EnabledDisabled(ctx.GuildConfig!.SuppressNotifications)}**.";
|
||||
await ctx.Reply(msg);
|
||||
return;
|
||||
}
|
||||
var msg = $"System tags are currently **{(ctx.GuildConfig!.RequireSystemTag ? "required" : "not required")}** for PluralKit users in this server.";
|
||||
await ctx.Reply(msg);
|
||||
}
|
||||
|
||||
var newVal = ctx.MatchToggle(false);
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new() { SuppressNotifications = newVal });
|
||||
await ctx.Reply($"Suppressing notifications for proxied messages is now {EnabledDisabled(newVal)}.");
|
||||
public async Task SetRequireSystemTag(Context ctx, bool value)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new() { RequireSystemTag = value });
|
||||
await ctx.Reply($"System tags are now **{(value ? "required" : "not required")}** for PluralKit users in this server.");
|
||||
}
|
||||
|
||||
public async Task ShowSuppressNotifications(Context ctx)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
var msg = $"Suppressing notifications for proxied messages is currently **{EnabledDisabled(ctx.GuildConfig!.SuppressNotifications)}**.";
|
||||
await ctx.Reply(msg);
|
||||
}
|
||||
|
||||
public async Task SetSuppressNotifications(Context ctx, bool value)
|
||||
{
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new() { SuppressNotifications = value });
|
||||
await ctx.Reply($"Suppressing notifications for proxied messages is now {EnabledDisabled(value)}.");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue