feat(bot): allow 'pk;logclean' in DMs

This commit is contained in:
spiral 2022-06-21 11:13:24 -04:00
parent cfd9dff6c5
commit b04b6e38d2
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E
2 changed files with 25 additions and 20 deletions

View File

@ -103,6 +103,13 @@ public static class ContextArgumentsExt
ctx.Match("r", "raw") || ctx.MatchFlag("r", "raw"); ctx.Match("r", "raw") || ctx.MatchFlag("r", "raw");
public static bool MatchToggle(this Context ctx, bool? defaultValue = null) public static bool MatchToggle(this Context ctx, bool? defaultValue = null)
{
var value = ctx.MatchToggleOrNull(defaultValue);
if (value == null) throw new PKError("You must pass either \"on\" or \"off\" to this command.");
return value.Value;
}
public static bool? MatchToggleOrNull(this Context ctx, bool? defaultValue = null)
{ {
if (defaultValue != null && ctx.MatchClearInner()) if (defaultValue != null && ctx.MatchClearInner())
return defaultValue.Value; return defaultValue.Value;
@ -114,8 +121,7 @@ public static class ContextArgumentsExt
return true; return true;
else if (ctx.Match(noToggles) || ctx.MatchFlag(noToggles)) else if (ctx.Match(noToggles) || ctx.MatchFlag(noToggles))
return false; return false;
else else return null;
throw new PKError("You must pass either \"on\" or \"off\" to this command.");
} }
public static (ulong? messageId, ulong? channelId) MatchMessage(this Context ctx, bool parseRawMessageId) public static (ulong? messageId, ulong? channelId) MatchMessage(this Context ctx, bool parseRawMessageId)

View File

@ -231,27 +231,26 @@ public class ServerConfig
public async Task SetLogCleanup(Context ctx) public async Task SetLogCleanup(Context ctx)
{ {
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
var botList = string.Join(", ", LoggerCleanService.Bots.Select(b => b.Name).OrderBy(x => x.ToLowerInvariant())); var botList = string.Join(", ", LoggerCleanService.Bots.Select(b => b.Name).OrderBy(x => x.ToLowerInvariant()));
var guild = await ctx.Repository.GetGuild(ctx.Guild.Id);
bool newValue;
if (ctx.Match("enable", "on", "yes"))
{
newValue = true;
}
else if (ctx.Match("disable", "off", "no"))
{
newValue = false;
}
else
{
var eb = new EmbedBuilder() var eb = new EmbedBuilder()
.Title("Log cleanup settings") .Title("Log cleanup settings")
.Field(new Embed.Field("Supported bots", botList)); .Field(new Embed.Field("Supported bots", botList));
if (ctx.Guild == null)
{
eb.Description("Run this command in a server to enable/disable log cleanup.");
await ctx.Reply(embed: eb.Build());
return;
}
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
var guild = await ctx.Repository.GetGuild(ctx.Guild.Id);
bool? newValue = ctx.MatchToggleOrNull();
if (newValue == null)
{
var guildCfg = await ctx.Repository.GetGuild(ctx.Guild.Id); var guildCfg = await ctx.Repository.GetGuild(ctx.Guild.Id);
if (guildCfg.LogCleanupEnabled) if (guildCfg.LogCleanupEnabled)
eb.Description( eb.Description(
@ -263,9 +262,9 @@ public class ServerConfig
return; return;
} }
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogCleanupEnabled = newValue }); await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogCleanupEnabled = newValue.Value });
if (newValue) if (newValue.Value)
await ctx.Reply( 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."); $"{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 else