From 2bc3817a4ec762d49946eff2e372ffa14bf197c5 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 15 Mar 2019 03:46:12 -0300 Subject: [PATCH] guilds: fix region update vip check --- litecord/blueprints/guilds.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/litecord/blueprints/guilds.py b/litecord/blueprints/guilds.py index bdb8b27..0a98676 100644 --- a/litecord/blueprints/guilds.py +++ b/litecord/blueprints/guilds.py @@ -238,6 +238,21 @@ async def _guild_update_icon(scope: str, guild_id: int, """, new_icon.icon_hash, guild_id) +async def _guild_update_region(guild_id, region): + is_vip = region.vip + can_vip = await app.storage.has_feature(guild_id, 'VIP_REGIONS') + + if is_vip and not can_vip: + raise BadRequest('can not assign guild to vip-only region') + + await app.db.execute(""" + UPDATE guilds + SET region = $1 + WHERE id = $2 + """, region.id, guild_id) + + + @bp.route('/', methods=['PATCH']) async def _update_guild(guild_id): user_id = await token_check() @@ -263,17 +278,10 @@ async def _update_guild(guild_id): """, j['name'], guild_id) if 'region' in j: - is_vip = app.voice.lvsp.region(j['region']).vip - can_vip = await app.storage.has_feature(guild_id, 'VIP_REGIONS') + region = app.voice.lvsp.region(j['region']) - if is_vip and not can_vip: - raise BadRequest('can not assign guild to vip-only region') - - await app.db.execute(""" - UPDATE guilds - SET region = $1 - WHERE id = $2 - """, j['region'], guild_id) + if region is not None: + await _guild_update_region(guild_id, region) if 'icon' in j: await _guild_update_icon(