mirror of https://gitlab.com/litecord/litecord.git
storage: move guilds.vanity_invite to Storage.vanity_invite
- storage: add guild.vanity_url_code in get_guild
This commit is contained in:
parent
7901a18332
commit
973df47503
|
|
@ -438,21 +438,13 @@ async def ack_guild(guild_id):
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
async def vanity_invite(guild_id: int) -> Optional[str]:
|
|
||||||
"""Get the vanity invite for a guild."""
|
|
||||||
return await app.db.fetchval("""
|
|
||||||
SELECT code FROM vanity_invites
|
|
||||||
WHERE guild_id = $1
|
|
||||||
""", guild_id)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<int:guild_id>/vanity-url', methods=['GET'])
|
@bp.route('/<int:guild_id>/vanity-url', methods=['GET'])
|
||||||
async def get_vanity_url(guild_id: int):
|
async def get_vanity_url(guild_id: int):
|
||||||
"""Get the vanity url of a guild."""
|
"""Get the vanity url of a guild."""
|
||||||
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_invite(guild_id)
|
inv_code = await app.storage.vanity_invite(guild_id)
|
||||||
|
|
||||||
if inv_code is None:
|
if inv_code is None:
|
||||||
return jsonify({'code': None})
|
return jsonify({'code': None})
|
||||||
|
|
@ -478,7 +470,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_invite(guild_id)
|
old_vanity = await app.storage.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')
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,13 @@ class Storage:
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
""", guild_id)
|
""", guild_id)
|
||||||
|
|
||||||
|
async def vanity_invite(self, guild_id: int) -> Optional[str]:
|
||||||
|
"""Get the vanity invite for a guild."""
|
||||||
|
return await app.db.fetchval("""
|
||||||
|
SELECT code FROM vanity_invites
|
||||||
|
WHERE guild_id = $1
|
||||||
|
""", guild_id)
|
||||||
|
|
||||||
async def get_guild(self, guild_id: int, user_id=None) -> Optional[Dict]:
|
async def get_guild(self, guild_id: int, user_id=None) -> Optional[Dict]:
|
||||||
"""Get gulid payload."""
|
"""Get gulid payload."""
|
||||||
row = await self.db.fetchrow("""
|
row = await self.db.fetchrow("""
|
||||||
|
|
@ -176,6 +183,8 @@ class Storage:
|
||||||
if user_id:
|
if user_id:
|
||||||
drow['owner'] = drow['owner_id'] == str(user_id)
|
drow['owner'] = drow['owner_id'] == str(user_id)
|
||||||
|
|
||||||
|
drow['vanity_url_code'] = await self.vanity_invite(guild_id)
|
||||||
|
|
||||||
return drow
|
return drow
|
||||||
|
|
||||||
async def _member_basic(self, guild_id: int, member_id: int):
|
async def _member_basic(self, guild_id: int, member_id: int):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue