diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 431fdc74..00000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Deploy to Heroku - -on: workflow_dispatch - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: akhileshns/heroku-deploy@v3.12.12 - with: - heroku_api_key: ${{secrets.HEROKU_API_KEY}} - heroku_email: ${{secrets.HEROKU_EMAIL}} - heroku_app_name: ${{secrets.HEROKU_APP_NAME}} - usedocker: true - docker_heroku_process_type: worker - stack: "container" - region: "eu" - env: - HD_CONFIG_ENV_URL: ${{secrets.CONFIG_ENV_URL}} diff --git a/README.md b/README.md index 7c595b20..098089d7 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ These four files are required to run the bot ## Deployment These two guides are available to deploy the bot -- [Deploying to Heroku](https://github.com/l3v11/SearchX/wiki/Deploying-to-Heroku) (free) -- [Deploying to VPS](https://github.com/l3v11/SearchX/wiki/Deploying-to-VPS) (paid) +- [Deploying to Heroku](https://github.com/l3v11/SearchX/wiki/Deploying-to-Heroku) +- [Deploying to VPS](https://github.com/l3v11/SearchX/wiki/Deploying-to-VPS) ## Commands diff --git a/bot/__init__.py b/bot/__init__.py index 2cf20bbd..6bff3155 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -82,7 +82,7 @@ DATABASE_URL = os.environ.get('DATABASE_URL', '') if len(DATABASE_URL) == 0: - DATABASE_URL = None + DATABASE_URL = '' IS_TEAM_DRIVE = os.environ.get('IS_TEAM_DRIVE', '') IS_TEAM_DRIVE = IS_TEAM_DRIVE.lower() == 'true' @@ -102,13 +102,13 @@ INDEX_URL = os.environ.get('INDEX_URL', '').rstrip("/") if len(INDEX_URL) == 0: - INDEX_URL = None + INDEX_URL = '' ARCHIVE_LIMIT = os.environ.get('ARCHIVE_LIMIT', '') -ARCHIVE_LIMIT = None if len(ARCHIVE_LIMIT) == 0 else float(ARCHIVE_LIMIT) +ARCHIVE_LIMIT = '' if len(ARCHIVE_LIMIT) == 0 else float(ARCHIVE_LIMIT) CLONE_LIMIT = os.environ.get('CLONE_LIMIT', '') -CLONE_LIMIT = None if len(CLONE_LIMIT) == 0 else float(CLONE_LIMIT) +CLONE_LIMIT = '' if len(CLONE_LIMIT) == 0 else float(CLONE_LIMIT) TOKEN_JSON_URL = os.environ.get('TOKEN_JSON_URL', '') if len(TOKEN_JSON_URL) != 0: @@ -152,12 +152,12 @@ APPDRIVE_EMAIL = os.environ.get('APPDRIVE_EMAIL', '') APPDRIVE_PASS = os.environ.get('APPDRIVE_PASS', '') if len(APPDRIVE_EMAIL) == 0 or len(APPDRIVE_PASS) == 0: - APPDRIVE_EMAIL = None - APPDRIVE_PASS = None + APPDRIVE_EMAIL = '' + APPDRIVE_PASS = '' GDTOT_CRYPT = os.environ.get('GDTOT_CRYPT', '') if len(GDTOT_CRYPT) == 0: - GDTOT_CRYPT = None + GDTOT_CRYPT = '' if os.path.exists('drive_list'): with open('drive_list', 'r+') as f: diff --git a/bot/helper/drive_utils/gdriveTools.py b/bot/helper/drive_utils/gdriveTools.py index 50ffb51e..62fbcaf5 100644 --- a/bot/helper/drive_utils/gdriveTools.py +++ b/bot/helper/drive_utils/gdriveTools.py @@ -46,6 +46,7 @@ def __init__(self, name=None, path=None, size=0, listener=None): self.__total_folders = 0 self.__total_files = 0 self.__sa_count = 0 + self.__service_account_index = 0 self.__start_time = 0 self.__total_time = 0 self.__alt_auth = False diff --git a/bot/helper/ext_utils/database.py b/bot/helper/ext_utils/database.py index 6ae866c6..7e761ed6 100644 --- a/bot/helper/ext_utils/database.py +++ b/bot/helper/ext_utils/database.py @@ -1,25 +1,46 @@ from pymongo import MongoClient -from bot import AUTHORIZED_USERS, DATABASE_URL +from bot import LOGGER, AUTHORIZED_USERS, DATABASE_URL class DatabaseHelper: def __init__(self): - self.mongodb = MongoClient(host=DATABASE_URL)["SearchX"] - self.col = self.mongodb["users"] + self.__err = False + self.__client = None + self.__db = None + self.__collection = None + self.__connect() + + def __connect(self): + try: + self.__client = MongoClient(DATABASE_URL) + self.__db = self.client['SearchX'] + self.__collection = self.db['users'] + except PyMongoError as err: + LOGGER.error(err) + self.__err = True def auth_user(self, user_id: int): + if self.__err: + return self.col.insert_one({"user_id": user_id}) return 'Authorization granted' + self.__client.close() def unauth_user(self, user_id: int): + if self.__err: + return self.col.delete_many({"user_id": user_id}) return 'Authorization revoked' + self.__client.close() def load_users(self): + if self.__err: + return users = self.col.find().sort("user_id") for user in users: - AUTHORIZED_USERS.add(user['user_id']) + AUTHORIZED_USERS.add(user["user_id"]) + self.__client.close() if DATABASE_URL is not None: DatabaseHelper().load_users() diff --git a/bot/helper/telegram_helper/message_utils.py b/bot/helper/telegram_helper/message_utils.py index ceff0dae..bad5bd18 100644 --- a/bot/helper/telegram_helper/message_utils.py +++ b/bot/helper/telegram_helper/message_utils.py @@ -2,13 +2,12 @@ from telegram import InlineKeyboardMarkup from telegram.error import RetryAfter -from telegram.message import Message from bot import bot, LOGGER, Interval, STATUS_UPDATE_INTERVAL, \ status_reply_dict, status_reply_dict_lock from bot.helper.ext_utils.bot_utils import SetInterval, get_readable_message -def sendMessage(text: str, bot, message: Message): +def sendMessage(text, bot, message): try: return bot.sendMessage(message.chat_id, reply_to_message_id=message.message_id, @@ -22,7 +21,7 @@ def sendMessage(text: str, bot, message: Message): LOGGER.error(str(err)) return -def sendMarkup(text: str, bot, message: Message, reply_markup: InlineKeyboardMarkup): +def sendMarkup(text, bot, message, reply_markup: InlineKeyboardMarkup): try: return bot.sendMessage(message.chat_id, reply_to_message_id=message.message_id, @@ -36,7 +35,7 @@ def sendMarkup(text: str, bot, message: Message, reply_markup: InlineKeyboardMar LOGGER.error(str(err)) return -def editMessage(text: str, message: Message, reply_markup=None): +def editMessage(text, message, reply_markup=None): try: bot.editMessageText(text=text, message_id=message.message_id, chat_id=message.chat.id, @@ -50,14 +49,14 @@ def editMessage(text: str, message: Message, reply_markup=None): LOGGER.error(str(err)) return str(err) -def deleteMessage(bot, message: Message): +def deleteMessage(bot, message): try: bot.deleteMessage(chat_id=message.chat.id, message_id=message.message_id) - except Exception as err: + except: pass -def sendLogFile(bot, message: Message): +def sendLogFile(bot, message): with open('log.txt', 'rb') as f: bot.sendDocument(document=f, filename=f.name, reply_to_message_id=message.message_id, diff --git a/bot/modules/archive.py b/bot/modules/archive.py index 3624fef6..72db3496 100644 --- a/bot/modules/archive.py +++ b/bot/modules/archive.py @@ -8,7 +8,7 @@ from html import escape from telegram.ext import CommandHandler -from bot import LOGGER, dispatcher, DOWNLOAD_DIR, Interval, INDEX_URL, download_dict, download_dict_lock +from bot import LOGGER, dispatcher, DOWNLOAD_DIR, Interval, INDEX_URL, download_dict, download_dict_lock, status_reply_dict_lock from bot.helper.download_utils.ddl_generator import appdrive, gdtot from bot.helper.download_utils.gd_downloader import add_gd_download from bot.helper.drive_utils.gdriveTools import GoogleDriveHelper @@ -35,8 +35,9 @@ def __init__(self, bot, message, is_compress=False, is_extract=False, pswd=None) def clean(self): try: - Interval[0].cancel() - Interval.clear() + with status_reply_dict_lock: + Interval[0].cancel() + Interval.clear() delete_all_messages() except: pass diff --git a/bot/modules/auth.py b/bot/modules/auth.py index 450a8246..a4755154 100644 --- a/bot/modules/auth.py +++ b/bot/modules/auth.py @@ -10,7 +10,7 @@ def authorize(update, context): user_id = '' reply_message = update.message.reply_to_message if len(context.args) == 1: - user_id = context.args[0] + user_id = int(context.args[0]) elif reply_message: user_id = reply_message.from_user.id if user_id: @@ -38,7 +38,7 @@ def unauthorize(update, context): user_id = '' reply_message = update.message.reply_to_message if len(context.args) == 1: - user_id = context.args[0] + user_id = int(context.args[0]) elif reply_message: user_id = reply_message.from_user.id if user_id: