File size: 1,614 Bytes
19e1d1f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import re
import logging
from pyrogram import Client, filters
from info import DELETE_CHANNELS
from database.ia_filterdb import Media, unpack_new_file_id
logger = logging.getLogger(__name__)
media_filter = filters.document | filters.video | filters.audio
@Client.on_message(filters.chat(DELETE_CHANNELS) & media_filter)
async def deletemultiplemedia(bot, message):
"""Delete Multiple files from database"""
for file_type in ("document", "video", "audio"):
media = getattr(message, file_type, None)
if media is not None:
break
else:
return
file_id, file_ref = unpack_new_file_id(media.file_id)
result = await Media.collection.delete_one({
'_id': file_id,
})
if result.deleted_count:
logger.info('File is successfully deleted from database.')
else:
file_name = re.sub(r"(_|\-|\.|\+)", " ", str(media.file_name))
result = await Media.collection.delete_many({
'file_name': file_name,
'file_size': media.file_size,
'mime_type': media.mime_type
})
if result.deleted_count:
logger.info('File is successfully deleted from database.')
else:
result = await Media.collection.delete_many({
'file_name': media.file_name,
'file_size': media.file_size,
'mime_type': media.mime_type
})
if result.deleted_count:
logger.info('File is successfully deleted from database.')
else:
logger.info('File not found in database.')
|