From 9b1f5cbb60075151e1ef5f9fae9cc071730a3194 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 1 Sep 2019 15:30:21 -0300 Subject: [PATCH] channels: use a set for message_ids - channels: check result of db call on bulk delete --- litecord/blueprints/channels.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/litecord/blueprints/channels.py b/litecord/blueprints/channels.py index d53cbeb..11c18a5 100644 --- a/litecord/blueprints/channels.py +++ b/litecord/blueprints/channels.py @@ -678,7 +678,7 @@ async def bulk_delete(channel_id: int): await channel_perm_check(user_id, channel_id, 'manage_messages') j = validate(await request.get_json(), BULK_DELETE) - message_ids = j['messages'] + message_ids = set(j['messages']) # as per discord behavior, if any id here is older than two weeks, # we must error. a cuter behavior would be returning the message ids @@ -700,12 +700,16 @@ async def bulk_delete(channel_id: int): if guild_id is None: payload.pop('guild_id') - await app.db.execute(""" + res = await app.db.execute(""" DELETE FROM messages WHERE channel_id = $1 - AND ARRAY[message_id] <@ $2::bigint[] - """, channel_id, message_ids) + AND ARRAY[id] <@ $2::bigint[] + """, channel_id, list(message_ids)) - await app.dispatcher.dispatch_channel('MESSAGE_DELETE_BULK', payload) + if res == 'DELETE 0': + raise BadRequest('No messages were removed') + + await app.dispatcher.dispatch( + 'channel', channel_id, 'MESSAGE_DELETE_BULK', payload) return '', 204