From e4386e8656d88e99d8c4e99a443e7b33c3d00779 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 27 Aug 2019 22:32:38 -0300 Subject: [PATCH] channels: add bulk delete sql query - schemas: add minlength, maxlength to BULK_DELETE --- litecord/blueprints/channels.py | 9 +++++++-- litecord/schemas.py | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/litecord/blueprints/channels.py b/litecord/blueprints/channels.py index b1de863..a923f90 100644 --- a/litecord/blueprints/channels.py +++ b/litecord/blueprints/channels.py @@ -688,14 +688,19 @@ async def bulk_delete(channel_id: int): payload = { 'guild_id': str(guild_id), 'channel_id': str(channel_id), - 'ids': message_ids + 'ids': list(map(str, message_ids)), } # payload.guild_id is optional in the event, not nullable. if guild_id is None: payload.pop('guild_id') - # TODO delete messages + await app.db.execute(""" + DELETE FROM messages + WHERE + channel_id = $1 + AND ARRAY[message_id] <@ $2::bigint[] + """, channel_id, message_ids) await app.dispatcher.dispatch_channel('MESSAGE_DELETE_BULK', payload) return '', 204 diff --git a/litecord/schemas.py b/litecord/schemas.py index 60eca24..de5aa21 100644 --- a/litecord/schemas.py +++ b/litecord/schemas.py @@ -741,6 +741,7 @@ WEBHOOK_MESSAGE_CREATE = { BULK_DELETE = { 'messages': { 'type': 'list', 'required': True, + 'minlength': 2, 'maxlength': 100, 'schema': {'coerce': int} } }