guilds: add basic vanity urls

- add vanity_invites table
This commit is contained in:
Luna 2019-03-13 04:28:23 -03:00
parent 0dbfb3a210
commit 633cd730c0
3 changed files with 31 additions and 0 deletions

View File

@ -371,3 +371,23 @@ async def ack_guild(guild_id):
await channel_ack(user_id, guild_id, chan_id)
return '', 204
@bp.route('/<int:guild_id>/vanity-url', methods=['GET'])
async def get_vanity_url(guild_id: int):
"""Get the vanity url of a guild."""
user_id = await token_check()
await guild_perm_check(user_id, guild_id, 'manage_guild')
inv_code = await app.db.fetchval("""
SELECT code FROM vanity_invites
WHERE guild_id = $1
""", guild_id)
if inv_code is None:
return jsonify({'code': None})
return jsonify(
await app.storage.get_invite(inv_code)
)

View File

@ -0,0 +1,5 @@
-- vanity url table, the mapping is 1-1 for guilds and vanity urls
CREATE TABLE IF NOT EXISTS vanity_invites (
guild_id bigint REFERENCES guilds (id) PRIMARY KEY,
code text REFERENCES invites (code) ON DELETE CASCADE
);

View File

@ -527,6 +527,12 @@ CREATE TABLE IF NOT EXISTS invites (
revoked bool DEFAULT false
);
-- vanity url table, the mapping is 1-1 for guilds and vanity urls
CREATE TABLE IF NOT EXISTS vanity_invites (
guild_id bigint REFERENCES guilds (id) PRIMARY KEY,
code text REFERENCES invites (code) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS webhooks (
id bigint PRIMARY KEY,