From 16f91c3b47a63357a74ddc224f6f3ad0ec64100c Mon Sep 17 00:00:00 2001 From: Dan Hess Date: Thu, 7 May 2020 19:45:37 -0500 Subject: [PATCH] Allow updates to custom permissions --- cogs/admin.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cogs/admin.py b/cogs/admin.py index 1ed014c..2b45cdf 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -528,13 +528,20 @@ WHERE await ctx.send("This command cannot have custom permissions setup!") return - await ctx.bot.db.execute( - "INSERT INTO custom_permissions (guild, command, permission) VALUES ($1, $2, $3)", - ctx.guild.id, - cmd.qualified_name, - perm_value - ) - + try: + await ctx.bot.db.execute( + "INSERT INTO custom_permissions (guild, command, permission) VALUES ($1, $2, $3)", + ctx.guild.id, + cmd.qualified_name, + perm_value + ) + except UniqueViolationError: + await ctx.bot.db.execute( + "UPDATE custom_permissions SET permission = $1 WHERE guild = $2 AND command = $3", + perm_value, + ctx.guild.id, + cmd.qualified_name + ) ctx.bot.cache.update_custom_permission(ctx.guild, cmd, perm_value) await ctx.send("I have just added your custom permissions; "