diff --git a/litecord/blueprints/channels.py b/litecord/blueprints/channels.py index 6711181..b1de863 100644 --- a/litecord/blueprints/channels.py +++ b/litecord/blueprints/channels.py @@ -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('//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 diff --git a/litecord/schemas.py b/litecord/schemas.py index 50e6d09..60eca24 100644 --- a/litecord/schemas.py +++ b/litecord/schemas.py @@ -737,3 +737,10 @@ WEBHOOK_MESSAGE_CREATE = { 'schema': {'type': 'dict', 'schema': EMBED_OBJECT} } } + +BULK_DELETE = { + 'messages': { + 'type': 'list', 'required': True, + 'schema': {'coerce': int} + } +}