add bulk delete endpoint

- schemas: add BULK_DELETE
This commit is contained in:
Luna 2019-08-27 22:14:38 -03:00
parent c10806e0de
commit 93237e34f8
2 changed files with 43 additions and 1 deletions

View File

@ -27,7 +27,8 @@ from litecord.auth import token_check
from litecord.enums import ChannelType, GUILD_CHANS, MessageType
from litecord.errors import ChannelNotFound, Forbidden
from litecord.schemas import (
validate, CHAN_UPDATE, CHAN_OVERWRITE, SEARCH_CHANNEL, GROUP_DM_UPDATE
validate, CHAN_UPDATE, CHAN_OVERWRITE, SEARCH_CHANNEL, GROUP_DM_UPDATE,
BULK_DELETE,
)
from litecord.blueprints.checks import channel_check, channel_perm_check
@ -664,3 +665,37 @@ async def suppress_embeds(channel_id: int, message_id: int):
)
return '', 204
@bp.route('/<int:channel_id>/messages/bulk-delete', methods=['POST'])
async def bulk_delete(channel_id: int):
user_id = await token_check()
ctype, guild_id = await channel_check(user_id, channel_id)
guild_id = guild_id if ctype in GUILD_CHANS else None
await channel_perm_check(user_id, channel_id, 'manage_messages')
j = validate(await request.get_json(), BULK_DELETE)
message_ids = 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
# that were deleted, ignoring the 2 week+ old ones.
for message_id in message_ids:
# TODO
pass
payload = {
'guild_id': str(guild_id),
'channel_id': str(channel_id),
'ids': 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.dispatcher.dispatch_channel('MESSAGE_DELETE_BULK', payload)
return '', 204

View File

@ -737,3 +737,10 @@ WEBHOOK_MESSAGE_CREATE = {
'schema': {'type': 'dict', 'schema': EMBED_OBJECT}
}
}
BULK_DELETE = {
'messages': {
'type': 'list', 'required': True,
'schema': {'coerce': int}
}
}