mirror of https://gitlab.com/litecord/litecord.git
admin_api.features: delete vanity invites when guild loses feature
- guilds: make _vanity_inv -> vanity_invite exportable function
This commit is contained in:
parent
6763f2c501
commit
977fa95ff2
|
|
@ -23,6 +23,7 @@ from quart import Blueprint, current_app as app, jsonify, request
|
||||||
from litecord.auth import admin_check
|
from litecord.auth import admin_check
|
||||||
from litecord.errors import BadRequest
|
from litecord.errors import BadRequest
|
||||||
from litecord.schemas import validate, FEATURES
|
from litecord.schemas import validate, FEATURES
|
||||||
|
from litecord.blueprints.guilds import vanity_invite
|
||||||
|
|
||||||
bp = Blueprint('features_admin', __name__)
|
bp = Blueprint('features_admin', __name__)
|
||||||
|
|
||||||
|
|
@ -39,6 +40,19 @@ async def _features(guild_id: int):
|
||||||
|
|
||||||
|
|
||||||
async def _update_features(guild_id: int, features: list):
|
async def _update_features(guild_id: int, features: list):
|
||||||
|
if 'VANITY_URL' not in features:
|
||||||
|
existing_inv = await vanity_invite(guild_id)
|
||||||
|
|
||||||
|
await app.db.execute("""
|
||||||
|
DELETE FROM vanity_invites
|
||||||
|
WHERE guild_id = $1
|
||||||
|
""", guild_id)
|
||||||
|
|
||||||
|
await app.db.execute("""
|
||||||
|
DELETE FROM invites
|
||||||
|
WHERE code = $1
|
||||||
|
""", existing_inv)
|
||||||
|
|
||||||
await app.db.execute("""
|
await app.db.execute("""
|
||||||
UPDATE guilds
|
UPDATE guilds
|
||||||
SET features = $1
|
SET features = $1
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,8 @@ async def ack_guild(guild_id):
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
async def _vanity_inv(guild_id) -> Optional[str]:
|
async def vanity_invite(guild_id: int) -> Optional[str]:
|
||||||
|
"""Get the vanity invite for a guild."""
|
||||||
return await app.db.fetchval("""
|
return await app.db.fetchval("""
|
||||||
SELECT code FROM vanity_invites
|
SELECT code FROM vanity_invites
|
||||||
WHERE guild_id = $1
|
WHERE guild_id = $1
|
||||||
|
|
@ -389,7 +390,7 @@ async def get_vanity_url(guild_id: int):
|
||||||
user_id = await token_check()
|
user_id = await token_check()
|
||||||
await guild_perm_check(user_id, guild_id, 'manage_guild')
|
await guild_perm_check(user_id, guild_id, 'manage_guild')
|
||||||
|
|
||||||
inv_code = await _vanity_inv(guild_id)
|
inv_code = await vanity_invite(guild_id)
|
||||||
|
|
||||||
if inv_code is None:
|
if inv_code is None:
|
||||||
return jsonify({'code': None})
|
return jsonify({'code': None})
|
||||||
|
|
@ -415,7 +416,7 @@ async def change_vanity_url(guild_id: int):
|
||||||
|
|
||||||
# store old vanity in a variable to delete it from
|
# store old vanity in a variable to delete it from
|
||||||
# invites table
|
# invites table
|
||||||
old_vanity = await _vanity_inv(guild_id)
|
old_vanity = await vanity_invite(guild_id)
|
||||||
|
|
||||||
if old_vanity == inv_code:
|
if old_vanity == inv_code:
|
||||||
raise BadRequest('can not change to same invite')
|
raise BadRequest('can not change to same invite')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue