From 9d969f3ab6f450395bec7fb80065e536998d189e Mon Sep 17 00:00:00 2001 From: Hafitz Setya <71178188+breakdowns@users.noreply.github.com> Date: Fri, 14 May 2021 17:34:27 +0700 Subject: [PATCH] v4.7.4 - Remove stickers search, cuz broken - Added SUDO_USER Co-authored-by: jovanzers --- README.md | 10 +++++---- app.json | 4 ++++ bot/__init__.py | 1 + bot/__main__.py | 15 +++++++------- bot/helper/telegram_helper/filters.py | 9 ++++---- bot/modules/stickers.py | 30 --------------------------- config_sample.env | 1 + 7 files changed, 25 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 378db0a..14bc38f 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ This is a Telegram bot writen in Python for mirroring files on the Internet to o ## Additional Features - Mirroring Uptobox.com links to Google Drive (Uptobox account must be premium) +- Sudo support (DWYOR, Sudo User can restart your bot and delete your Drive file) - Get detailed info about replied media - Nyaa.si and Sukebei Torrent search - Speedtest with picture results @@ -56,7 +57,7 @@ For Debian based distros ``` sudo apt install python3 ``` -Install Docker by following the [official docker docs](https://docs.docker.com/engine/install/debian/) +Install Docker by following the [official Docker docs](https://docs.docker.com/engine/install/debian/) - For Arch and it's derivatives: ``` @@ -85,8 +86,9 @@ 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 +- **SUDO_USER**: (Optional field) Multiple Telegram user ID (not username) separate by space. - **AUTHORIZED_CHATS**: Fill user_id and chat_id of you want to authorize. -- **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 +- **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) - **IS_TEAM_DRIVE**: (Optional field) Set to `True` if `GDRIVE_FOLDER_ID` is from a Team Drive else `False` or Leave it empty. - **USE_SERVICE_ACCOUNTS**: (Optional field) (Leave empty if unsure) Whether to use Service Accounts or not. For this to work see [Using service accounts](https://github.com/breakdowns/slam-mirrorbot#generate-service-accounts-what-is-service-account) section below. - **INDEX_URL**: (Optional field) Refer to https://github.com/maple3142/GDIndex/ The URL should not have any trailing '/' @@ -97,7 +99,7 @@ Fill up rest of the fields. Meaning of each fields are discussed below: - **MEGA_PASSWORD**: Your password for your mega.nz account - **BLOCK_MEGA_FOLDER**: (Optional field) If you want to remove mega.nz folder support, set it to `True`. - **BLOCK_MEGA_LINKS**: (Optional field) If you want to remove mega.nz mirror support, set it to `True`. -- **STOP_DUPLICATE_MIRROR**: (Optional field) (Leave empty if unsure) if this field is set to `True`, bot will check file in drive, if it is present in Drive, downloading will be stopped. (Note: File will be checked using filename, not using filehash, so this feature is not perfect yet) +- **STOP_DUPLICATE_MIRROR**: (Optional field) (Leave empty if unsure) if this field is set to `True`, bot will check file in drive, if it is present in Drive, downloading will be stopped. (**Note**: File will be checked using filename, not using filehash, so this feature is not perfect yet) - **ENABLE_FILESIZE_LIMIT**: Set it to `True` if you want to use `MAX_TORRENT_SIZE`. - **MAX_TORRENT_SIZE**: To limit the Torrent mirror size, Fill The amount you want to limit, examples: if you fill `15` it will limit `15gb`. - **HEROKU_API_KEY**: (Only if you deploying on Heroku) Your Heroku API key, get it from https://dashboard.heroku.com/account. @@ -163,7 +165,7 @@ For Service Account to work, you must set **USE_SERVICE_ACCOUNTS=**"True" in con Many thanks to [AutoRClone](https://github.com/xyou365/AutoRclone) for the scripts. **NOTE**: Using Service Accounts is only recommended while uploading to a Team Drive. -## Generate Service Accounts. [What is service account](https://cloud.google.com/iam/docs/service-accounts) +## Generate Service Accounts. [What is Service Account](https://cloud.google.com/iam/docs/service-accounts) Let us create only the Service Accounts that we need. **Warning**: abuse of this feature is not the aim of this project and we do **NOT** recommend that you make a lot of projects, just one project and 100 SAs allow you plenty of use, its also possible that over abuse might get your projects banned by Google. diff --git a/app.json b/app.json index 5c054ac..37d07ef 100644 --- a/app.json +++ b/app.json @@ -38,6 +38,10 @@ "description": "The Telegram User ID of the Owner of the Bot. Get it by using /info in @MissRose_bot.", "required": true }, + "SUDO_USER": { + "description": "Multiple Telegram user ID (not username) separate by space.", + "required": false + }, "AUTO_DELETE_MESSAGE_DURATION": { "description": "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.", "required": true diff --git a/bot/__init__.py b/bot/__init__.py index af9b176..45e6655 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -87,6 +87,7 @@ try: DOWNLOAD_DIR = DOWNLOAD_DIR + '/' DOWNLOAD_STATUS_UPDATE_INTERVAL = int(getConfig('DOWNLOAD_STATUS_UPDATE_INTERVAL')) OWNER_ID = int(getConfig('OWNER_ID')) + SUDO_USER = tuple(filter(lambda x: x, map(int, os.environ.get("SUDO_USER", "").split()))) AUTO_DELETE_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_MESSAGE_DURATION')) TELEGRAM_API = getConfig('TELEGRAM_API') TELEGRAM_HASH = getConfig('TELEGRAM_HASH') diff --git a/bot/__main__.py b/bot/__main__.py index c3ec40b..793097a 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -10,7 +10,7 @@ import pytz import time from telegram import ParseMode, BotCommand, InlineKeyboardMarkup, InlineKeyboardButton from telegram.ext import CommandHandler, run_async -from bot import dispatcher, updater, botStartTime, AUTHORIZED_CHATS, IMAGE_URL +from bot import dispatcher, updater, botStartTime, AUTHORIZED_CHATS, SUDO_USER, IMAGE_URL 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 * @@ -58,9 +58,10 @@ Type /{BotCommands.HelpCommand} to get a list of available commands @run_async def chat_list(update, context): - chatlist ='' - chatlist += '\n'.join(str(id) for id in AUTHORIZED_CHATS) - sendMessage(f'Authorized List:\n{chatlist}\n', context.bot, update) + chat_list = sudo = '' + chat_list += '\n'.join(str(id) for id in AUTHORIZED_CHATS) + sudo += '\n'.join(str(id) for id in SUDO_USER) + sendMessage(f'Authorized Chats\n{chat_list}\nSudo Users\n{sudo}', context.bot, update) @run_async @@ -121,13 +122,13 @@ def bot_help(update, context): /{BotCommands.StatsCommand}: Show Stats of the machine the bot is hosted on -/{BotCommands.AuthorizeCommand}: Authorize a chat or a user to use the bot (Can only be invoked by Owner of the bot) +/{BotCommands.AuthorizeCommand}: Authorize a chat or a user to use the bot (Can only be invoked by Owner & Sudo of the bot) -/{BotCommands.AuthListCommand}: See Authorized list (Can only be invoked by Owner of the bot) +/{BotCommands.AuthListCommand}: See Authorized list & Sudo User (Can only be invoked by Owner & Sudo of the bot) /{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports -/{BotCommands.UsageCommand}: To see Heroku Dyno Stats (Owner only). +/{BotCommands.UsageCommand}: To see Heroku Dyno Stats (Owner & Sudo only). /{BotCommands.SpeedCommand}: Check Internet Speed of the Host diff --git a/bot/helper/telegram_helper/filters.py b/bot/helper/telegram_helper/filters.py index 3cd3c93..28225ab 100644 --- a/bot/helper/telegram_helper/filters.py +++ b/bot/helper/telegram_helper/filters.py @@ -1,19 +1,20 @@ from telegram.ext import BaseFilter from telegram import Message -from bot import AUTHORIZED_CHATS, OWNER_ID, download_dict, download_dict_lock +from bot import AUTHORIZED_CHATS, OWNER_ID, SUDO_USER, download_dict, download_dict_lock class CustomFilters: class _OwnerFilter(BaseFilter): def filter(self, message): - return bool(message.from_user.id == OWNER_ID) + id = message.from_user.id + return bool(message.from_user.id == OWNER_ID or id in SUDO_USER) owner_filter = _OwnerFilter() class _AuthorizedUserFilter(BaseFilter): def filter(self, message): id = message.from_user.id - return bool(id in AUTHORIZED_CHATS or id == OWNER_ID) + return bool(id in AUTHORIZED_CHATS or id == OWNER_ID or id in SUDO_USER) authorized_user = _AuthorizedUserFilter() @@ -26,7 +27,7 @@ class CustomFilters: class _MirrorOwner(BaseFilter): def filter(self, message: Message): user_id = message.from_user.id - if user_id == OWNER_ID: + if user_id in SUDO_USER: return True args = str(message.text).split(' ') if len(args) > 1: diff --git a/bot/modules/stickers.py b/bot/modules/stickers.py index aaf926b..5d66483 100644 --- a/bot/modules/stickers.py +++ b/bot/modules/stickers.py @@ -1,11 +1,7 @@ -import os -import re import math -import requests import urllib.request as urllib from PIL import Image from html import escape -from bs4 import BeautifulSoup as bs from telegram import ParseMode, InlineKeyboardMarkup, InlineKeyboardButton from telegram import TelegramError, Update @@ -14,8 +10,6 @@ from telegram.utils.helpers import mention_html from bot import dispatcher, IMAGE_URL -combot_stickers_url = "https://combot.org/telegram/stickers?q=" - @run_async def stickerid(update: Update, context: CallbackContext): @@ -37,27 +31,6 @@ def stickerid(update: Update, context: CallbackContext): ) -@run_async -def cb_sticker(update: Update, context: CallbackContext): - msg = update.effective_message - split = msg.text.split(' ', 1) - if len(split) == 1: - msg.reply_text('Provide some name to search for pack.') - return - text = requests.get(combot_stickers_url + split[1]).text - soup = bs(text, 'lxml') - results = soup.find_all("a", {'class': "sticker-pack__btn"}) - titles = soup.find_all("div", "sticker-pack__title") - if not results: - msg.reply_text('No results found :(.') - return - reply = f"Stickers for *{split[1]}*:" - for result, title in zip(results, titles): - link = result['href'] - reply += f"\n• [{title.get_text()}]({link})" - msg.reply_text(reply, parse_mode=ParseMode.MARKDOWN) - - def getsticker(update: Update, context: CallbackContext): bot = context.bot msg = update.effective_message @@ -445,7 +418,6 @@ def stickhelp(update, context): • `/getsticker`*:* Reply to a Sticker to me to upload its raw PNG file. • `/kang`*:* Reply to a Sticker to add it to your pack. • `/remove`*:* Replay to a Sticker to remove Sticker from an existing pack. -• `/stickers`*:* Find Stickers for given term on combot Sticker catalogue. ''' update.effective_message.reply_photo(IMAGE_URL, help_string, parse_mode=ParseMode.MARKDOWN) @@ -453,11 +425,9 @@ STICKERID_HANDLER = CommandHandler("stickerid", stickerid) GETSTICKER_HANDLER = CommandHandler("getsticker", getsticker) KANG_HANDLER = CommandHandler("kang", kang) DEL_HANDLER = CommandHandler("remove", delsticker) -STICKERS_HANDLER = CommandHandler("stickers", cb_sticker) STICKHELP_HANDLER = CommandHandler("stickerhelp", stickhelp) -dispatcher.add_handler(STICKERS_HANDLER) dispatcher.add_handler(STICKERID_HANDLER) dispatcher.add_handler(GETSTICKER_HANDLER) dispatcher.add_handler(KANG_HANDLER) diff --git a/config_sample.env b/config_sample.env index 6c0d44e..be90ef4 100644 --- a/config_sample.env +++ b/config_sample.env @@ -13,6 +13,7 @@ TELEGRAM_API = TELEGRAM_HASH = "" # Optional config AUTHORIZED_CHATS = "" +SUDO_USER = USE_SERVICE_ACCOUNTS = "" INDEX_URL = "" UPTOBOX_TOKEN = ""