From f50df670d79cf160f5a9b096ad7b91f4cd162a06 Mon Sep 17 00:00:00 2001 From: dev-kittens Date: Sat, 17 Oct 2020 16:43:59 -0500 Subject: [PATCH] Fix log channel clear matching --- PluralKit.Bot/Commands/ServerConfig.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/PluralKit.Bot/Commands/ServerConfig.cs b/PluralKit.Bot/Commands/ServerConfig.cs index 167cc089..2e1cdb88 100644 --- a/PluralKit.Bot/Commands/ServerConfig.cs +++ b/PluralKit.Bot/Commands/ServerConfig.cs @@ -26,20 +26,24 @@ namespace PluralKit.Bot { ctx.CheckGuildContext().CheckAuthorPermission(Permissions.ManageGuild, "Manage Server"); - DiscordChannel channel = null; + if (ctx.MatchClear()) + { + await _db.Execute(conn => _repo.UpsertGuild(conn, ctx.Guild.Id, new GuildPatch {LogChannel = null})); + await ctx.Reply($"{Emojis.Success} Proxy logging channel cleared."); + return; + } + if (!ctx.HasNext()) - throw new PKSyntaxError("You must pass a #channel to set."); + throw new PKSyntaxError("You must pass a #channel to set, or `clear` to clear it."); + + DiscordChannel channel = null; var channelString = ctx.PeekArgument(); channel = await ctx.MatchChannel(); if (channel == null || channel.GuildId != ctx.Guild.Id) throw Errors.ChannelNotFound(channelString); - var patch = new GuildPatch {LogChannel = channel?.Id}; + var patch = new GuildPatch {LogChannel = channel.Id}; await _db.Execute(conn => _repo.UpsertGuild(conn, ctx.Guild.Id, patch)); - - if (channel != null) - await ctx.Reply($"{Emojis.Success} Proxy logging channel set to #{channel.Name}."); - else - await ctx.Reply($"{Emojis.Success} Proxy logging channel cleared."); + await ctx.Reply($"{Emojis.Success} Proxy logging channel set to #{channel.Name}."); } public async Task SetLogEnabled(Context ctx, bool enable)