mirror of https://gitlab.com/litecord/litecord.git
invites: check maximum invite count
This commit is contained in:
parent
23034aadbd
commit
27b5836132
|
|
@ -214,6 +214,31 @@ async def use_invite(user_id, invite_code):
|
||||||
pass
|
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"])
|
@bp.route("/channels/<int:channel_id>/invites", methods=["POST"])
|
||||||
async def create_invite(channel_id):
|
async def create_invite(channel_id):
|
||||||
"""Create an invite to a channel."""
|
"""Create an invite to a channel."""
|
||||||
|
|
@ -241,6 +266,8 @@ async def create_invite(channel_id):
|
||||||
else:
|
else:
|
||||||
guild_id = None
|
guild_id = None
|
||||||
|
|
||||||
|
await _check_max_invites(guild_id, channel_id)
|
||||||
|
|
||||||
await app.db.execute(
|
await app.db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO invites
|
INSERT INTO invites
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue