invites: check maximum invite count

This commit is contained in:
Luna 2019-10-26 11:52:26 -03:00
parent 23034aadbd
commit 27b5836132
1 changed files with 27 additions and 0 deletions

View File

@ -214,6 +214,31 @@ async def use_invite(user_id, invite_code):
pass
async def _check_max_invites(guild_id, channel_id):
"""Check that the maximum invite count (1000) isn't being blown."""
if guild_id is not None:
invite_count = await app.db.fetchval(
"""
SELECT COUNT(*)
FROM invites
WHERE guild_id = $1
""",
guild_id,
)
else:
invite_count = await app.db.fetchval(
"""
SELECT COUNT(*)
FROM invites
WHERE channel_id = $1
""",
channel_id,
)
if invite_count >= 1000:
raise BadRequest(30016)
@bp.route("/channels/<int:channel_id>/invites", methods=["POST"])
async def create_invite(channel_id):
"""Create an invite to a channel."""
@ -241,6 +266,8 @@ async def create_invite(channel_id):
else:
guild_id = None
await _check_max_invites(guild_id, channel_id)
await app.db.execute(
"""
INSERT INTO invites