feat(bot): allow 'pk;logclean' in DMs
This commit is contained in:
		@@ -103,6 +103,13 @@ public static class ContextArgumentsExt
 | 
			
		||||
        ctx.Match("r", "raw") || ctx.MatchFlag("r", "raw");
 | 
			
		||||
 | 
			
		||||
    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())
 | 
			
		||||
            return defaultValue.Value;
 | 
			
		||||
@@ -114,8 +121,7 @@ public static class ContextArgumentsExt
 | 
			
		||||
            return true;
 | 
			
		||||
        else if (ctx.Match(noToggles) || ctx.MatchFlag(noToggles))
 | 
			
		||||
            return false;
 | 
			
		||||
        else
 | 
			
		||||
            throw new PKError("You must pass either \"on\" or \"off\" to this command.");
 | 
			
		||||
        else return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static (ulong? messageId, ulong? channelId) MatchMessage(this Context ctx, bool parseRawMessageId)
 | 
			
		||||
 
 | 
			
		||||
@@ -231,27 +231,26 @@ public class ServerConfig
 | 
			
		||||
 | 
			
		||||
    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 eb = new EmbedBuilder()
 | 
			
		||||
            .Title("Log cleanup settings")
 | 
			
		||||
            .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;
 | 
			
		||||
        if (ctx.Match("enable", "on", "yes"))
 | 
			
		||||
        {
 | 
			
		||||
            newValue = true;
 | 
			
		||||
        }
 | 
			
		||||
        else if (ctx.Match("disable", "off", "no"))
 | 
			
		||||
        {
 | 
			
		||||
            newValue = false;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            var eb = new EmbedBuilder()
 | 
			
		||||
                .Title("Log cleanup settings")
 | 
			
		||||
                .Field(new Embed.Field("Supported bots", botList));
 | 
			
		||||
        bool? newValue = ctx.MatchToggleOrNull();
 | 
			
		||||
 | 
			
		||||
        if (newValue == null)
 | 
			
		||||
        {
 | 
			
		||||
            var guildCfg = await ctx.Repository.GetGuild(ctx.Guild.Id);
 | 
			
		||||
            if (guildCfg.LogCleanupEnabled)
 | 
			
		||||
                eb.Description(
 | 
			
		||||
@@ -263,9 +262,9 @@ public class ServerConfig
 | 
			
		||||
            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(
 | 
			
		||||
                $"{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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user