From 7bde2dd7a15842d0f28f3c770032ecdc87b672f4 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 26 Feb 2019 23:48:45 -0300 Subject: [PATCH] add theoretical impl for gdm invites --- litecord/blueprints/invites.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/litecord/blueprints/invites.py b/litecord/blueprints/invites.py index acb860f..dfe912c 100644 --- a/litecord/blueprints/invites.py +++ b/litecord/blueprints/invites.py @@ -103,6 +103,7 @@ async def use_invite(user_id, invite_code): await delete_invite(invite_code) raise InvalidInvite('Too many uses') + # TODO: if group dm invite, guild_id is null. guild_id = inv['guild_id'] await invite_precheck(user_id, guild_id) @@ -151,25 +152,29 @@ async def use_invite(user_id, invite_code): @bp.route('/channels//invites', methods=['POST']) async def create_invite(channel_id): + """Create an invite to a channel.""" user_id = await token_check() - j = validate(await request.get_json(), INVITE) - _ctype, guild_id = await channel_check(user_id, channel_id) + chantype, maybe_guild_id = await channel_check(user_id, channel_id) + chantype = ChannelType(chantype) + + # NOTE: this works on group dms, since it returns ALL_PERMISSIONS on + # non-guild channels. await channel_perm_check(user_id, channel_id, 'create_invites') - chantype = await app.storage.get_chan_type(channel_id) - - # can't create invites for channels that aren't text - # or voice. - - # TODO: once group dms are in, this should change to account. - if chantype not in (ChannelType.GUILD_TEXT.value, - ChannelType.GUILD_VOICE.value): + if chantype not in (ChannelType.GUILD_TEXT, + ChannelType.GUILD_VOICE, + ChannelType.GROUP_DM): raise BadRequest('Invalid channel type') invite_code = gen_inv_code() + if chantype in (ChannelType.GUILD_TEXT, ChannelType.GUILD_VOICE): + guild_id = maybe_guild_id + else: + guild_id = None + await app.db.execute( """ INSERT INTO invites