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 <yo@kenharris.xyz>
This commit is contained in:
Hafitz Setya 2021-06-10 14:11:36 +07:00 committed by GitHub
parent 65c71add56
commit 3f5065cc71
Signed by untrusted user: GitHub
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 6 deletions

View File

@ -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:
<details>
<summary><b>Click here for more details</b></summary>
## 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.
```
</details>
# 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:
```

View File

@ -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).",

View File

@ -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

View File

@ -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)

View File

@ -14,6 +14,7 @@ TELEGRAM_HASH = ""
DATABASE_URL = ""
# Optional config
AUTHORIZED_CHATS = ""
IGNORE_PENDING_REQUESTS = ""
USE_SERVICE_ACCOUNTS = ""
INDEX_URL = ""
UPTOBOX_TOKEN = ""