Implementing auto delete message
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
parent
a432ad8a5d
commit
5d6c0c8ff7
|
|
@ -1,16 +1,16 @@
|
|||
# What is this repo about?
|
||||
This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive.
|
||||
|
||||
## Inspiration
|
||||
# Inspiration
|
||||
This project is heavily inspired from @out386 's telegram bot which is written in JS.
|
||||
|
||||
## Features supported:
|
||||
# Features supported:
|
||||
- Mirroring direct download links to google drive
|
||||
- Download progress
|
||||
- Upload progress
|
||||
- Download/upload speeds and ETAs
|
||||
|
||||
## Upcoming features (TODOs):
|
||||
# Upcoming features (TODOs):
|
||||
- Mega link mirror support
|
||||
- Docker support
|
||||
- More code clean up
|
||||
|
|
@ -54,7 +54,7 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
|
|||
- DOWNLOAD_DIR : The path to the local folder where the downloads should be downloaded to
|
||||
- DOWNLOAD_STATUS_UPDATE_INTERVAL : A short interval of time in seconds after which the Mirror progress message is updated. (I recommend to keep it 5 seconds at least)
|
||||
- OWNER_ID : The Telegram user ID (not username) of the owner of the bot
|
||||
|
||||
- AUTO_DELETE_MESSAGE_DURATION : Interval of time (in seconds), after which the bot deletes it's message (and command message) which is expected to be viewed instantly. Note: Set to -1 to never automatically delete messages
|
||||
## Getting Google OAuth API credential file
|
||||
|
||||
- Visit the Google Cloud Console
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ try:
|
|||
DOWNLOAD_DIR = DOWNLOAD_DIR + '/'
|
||||
DOWNLOAD_STATUS_UPDATE_INTERVAL = int(getConfig('DOWNLOAD_STATUS_UPDATE_INTERVAL'))
|
||||
OWNER_ID = int(getConfig('OWNER_ID'))
|
||||
AUTO_DELETE_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_MESSAGE_DURATION'))
|
||||
except KeyError as e:
|
||||
LOGGER.error("One or more env variables missing! Exiting now")
|
||||
exit(1)
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ BOT_TOKEN =
|
|||
GDRIVE_FOLDER_ID =
|
||||
DOWNLOAD_DIR = /home/username/mirror-bot/downloads
|
||||
DOWNLOAD_STATUS_UPDATE_INTERVAL = 5
|
||||
AUTO_DELETE_MESSAGE_DURATION = 20
|
||||
OWNER_ID =
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
from telegram.message import Message
|
||||
from telegram.update import Update
|
||||
import time
|
||||
from bot import AUTO_DELETE_MESSAGE_DURATION
|
||||
|
||||
|
||||
def sendMessage(text: str, context, update: Update):
|
||||
|
|
@ -17,3 +19,14 @@ def editMessage(text: str, context, message: Message):
|
|||
def deleteMessage(context, message: Message):
|
||||
context.bot.delete_message(chat_id=message.chat.id,
|
||||
message_id=message.message_id)
|
||||
|
||||
|
||||
def auto_delete_message(context, cmd_message: Message, bot_message: Message):
|
||||
if AUTO_DELETE_MESSAGE_DURATION != -1:
|
||||
time.sleep(AUTO_DELETE_MESSAGE_DURATION)
|
||||
try:
|
||||
# Skip if None is passed meaning we don't want to delete bot xor cmd message
|
||||
deleteMessage(context, cmd_message)
|
||||
deleteMessage(context, bot_message)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
from telegram.ext import CommandHandler, run_async
|
||||
from bot.helper.mirror_utils.gdriveTools import GoogleDriveHelper
|
||||
from bot import LOGGER, dispatcher
|
||||
from bot.helper.telegram_helper.message_utils import auto_delete_message, sendMessage
|
||||
import threading
|
||||
|
||||
|
||||
@run_async
|
||||
|
|
@ -11,12 +13,12 @@ def list_drive(update, context):
|
|||
gdrive = GoogleDriveHelper(None)
|
||||
msg = gdrive.drive_list(search)
|
||||
if msg:
|
||||
context.bot.send_message(chat_id=update.message.chat_id, reply_to_message_id=update.message.message_id,
|
||||
text=msg, parse_mode='HTML')
|
||||
reply_message = sendMessage(msg, context, update)
|
||||
|
||||
else:
|
||||
context.bot.send_message(chat_id=update.message.chat_id, reply_to_message_id=update.message.message_id,
|
||||
text="No Results Found.")
|
||||
reply_message = sendMessage('No result found', context, update)
|
||||
|
||||
threading.Thread(target=auto_delete_message, args=(context, update.message, reply_message)).start()
|
||||
|
||||
|
||||
list_handler = CommandHandler('list', list_drive)
|
||||
|
|
|
|||
Loading…
Reference in New Issue