From 3f5065cc71bef71fbad86cfbb98986822b9178f0 Mon Sep 17 00:00:00 2001 From: Hafitz Setya <71178188+breakdowns@users.noreply.github.com> Date: Thu, 10 Jun 2021 14:11:36 +0700 Subject: [PATCH] bot: Add config to handle pending requests when bot restarts Whenever the bot restarts, it immediately starts responding to all the commands that wasn't handled when the bot wasn't on. This obviously can cause issues, so let's add a config to disable this behaviour. Co-authored-by: KenHV --- README.md | 5 +---- app.json | 4 ++++ bot/__init__.py | 7 +++++++ bot/__main__.py | 4 ++-- config_sample.env | 1 + 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5832417..9c28094 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,6 @@ **Slam Mirror Bot** is a _multipurpose_ Telegram Bot writen in Python for mirroring files on the Internet to our beloved Google Drive. # Features supported: -
- Click here for more details - ## Additional Features - Get detailed info about replied media (Only for Telegram file) - Nyaa.si and Sukebei Torrent search @@ -64,7 +61,6 @@ APM, ARJ, CHM, CPIO, CramFS, DEB, DMG, FAT, HFS, LZH, LZMA, LZMA2, MBR, MSI, MSLZ, NSIS, NTFS, RPM, SquashFS, UDF, VHD, XAR, Z. ``` -
# How to deploy? Deploying is pretty much straight forward and is divided into several steps as follows: @@ -156,6 +152,7 @@ Fill up rest of the fields. Meaning of each fields are discussed below: - **UPTOBOX_TOKEN**: Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account). - **HEROKU_API_KEY**: (Only if you deploying on Heroku) Your Heroku API key, get it from https://dashboard.heroku.com/account. - **HEROKU_APP_NAME**: (Only if you deploying on Heroku) Your Heroku app name. +- **IGNORE_PENDING_REQUESTS**: If you want the bot to ignore pending requests after it restarts, set this to `True`. - **SHORTENER_API**: Fill your Shortener api key if you are using Shortener. - **SHORTENER**: if you want to use Shortener in Gdrive and index link, fill Shortener url here. Examples: ``` diff --git a/app.json b/app.json index d0b5751..e14083e 100644 --- a/app.json +++ b/app.json @@ -140,6 +140,10 @@ "description": "Show Image/Logo in /start message, Use telegra.ph or any direct link image.", "value": "https://telegra.ph/file/db03910496f06094f1f7a.jpg", "required": false + }, + "IGNORE_PENDING_REQUESTS": { + "description": "If you want the bot to ignorepending requests after it restarts, set this to True.", + "required": false }, "VIEW_LINK": { "description": "View Link button to open file Index Link in browser instead of direct download link, you can figure out if it's compatible with your Index code or not, open any video from you Index and check if the END of link from browser link bar is ?a=view, if yes make it True it will work (Compatible with Bhadoo Index Code).", diff --git a/bot/__init__.py b/bot/__init__.py index 5f11211..1b16424 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -296,6 +296,13 @@ try: except KeyError: IMAGE_URL = 'https://telegra.ph/file/db03910496f06094f1f7a.jpg' +IGNORE_PENDING_REQUESTS = False +try: + if getConfig("IGNORE_PENDING_REQUESTS").lower() == "true": + IGNORE_PENDING_REQUESTS = True +except KeyError: + pass + updater = tg.Updater(token=BOT_TOKEN, use_context=True) bot = updater.bot dispatcher = updater.dispatcher diff --git a/bot/__main__.py b/bot/__main__.py index c80e1cb..7545a78 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -11,7 +11,7 @@ import time from telegram import ParseMode, BotCommand from telegram.ext import CommandHandler, run_async -from bot import bot, dispatcher, updater, botStartTime, IMAGE_URL +from bot import bot, dispatcher, updater, botStartTime, IMAGE_URL, IGNORE_PENDING_REQUESTS from bot.helper.ext_utils import fs_utils from bot.helper.telegram_helper.bot_commands import BotCommands from bot.helper.telegram_helper.message_utils import * @@ -238,7 +238,7 @@ def main(): dispatcher.add_handler(help_handler) dispatcher.add_handler(stats_handler) dispatcher.add_handler(log_handler) - updater.start_polling() + updater.start_polling(drop_pending_updates=IGNORE_PENDING_REQUESTS) LOGGER.info("Bot Started!") signal.signal(signal.SIGINT, fs_utils.exit_clean_up) diff --git a/config_sample.env b/config_sample.env index ad897ee..f9e2c86 100644 --- a/config_sample.env +++ b/config_sample.env @@ -14,6 +14,7 @@ TELEGRAM_HASH = "" DATABASE_URL = "" # Optional config AUTHORIZED_CHATS = "" +IGNORE_PENDING_REQUESTS = "" USE_SERVICE_ACCOUNTS = "" INDEX_URL = "" UPTOBOX_TOKEN = ""