mirror of
https://github.com/anasty17/mirror-leech-telegram-bot.git
synced 2025-01-08 12:07:33 +08:00
Minor fixes
Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
parent
a811dee88c
commit
73c1ae483f
@ -29,9 +29,8 @@ In each single file there is a major change from base code, it's almost totaly d
|
||||
- Download from Google Drive
|
||||
- Counting Google Drive files/folders
|
||||
- Search in multiple Drive folder/TeamDrive
|
||||
- Recursive Search (only with `root` or TeamDrive ID, folder ids will be listed with non-recursive method)
|
||||
- Recursive Search (only with `root` or TeamDrive ID, folder ids will be listed with non-recursive method). Based on [Sreeraj](https://github.com/SVR666) searchX-bot.
|
||||
- Use Token.pickle if file not found with Service Account, for all Gdrive functions
|
||||
- List result in html file instead of telegraph or telegram message to avoid limits by [junedkh](https://github.com/junedkh)
|
||||
- Random Service Account for each task
|
||||
### Status
|
||||
- Clone Status
|
||||
@ -72,6 +71,7 @@ In each single file there is a major change from base code, it's almost totaly d
|
||||
- Docker image support for linux `amd64, arm64/v8, arm/v7, s390x`
|
||||
- Edit variables and overwrite the private files while bot running
|
||||
- Update bot at startup and with restart command using `UPSTREAM_REPO`
|
||||
- Improve Telegraph. Based on [Sreeraj](https://github.com/SVR666) loaderX-bot.
|
||||
- Mirror/Leech/Watch/Clone/Count/Del by reply
|
||||
- Mirror/Leech/Clone multi links/files with one command
|
||||
- Custom name for all links except torrents. For files you should add extension except yt-dlp links
|
||||
|
@ -65,12 +65,12 @@ if len(BOT_TOKEN) == 0:
|
||||
|
||||
bot_id = int(BOT_TOKEN.split(':', 1)[0])
|
||||
|
||||
DB_URI = environ.get('DATABASE_URL', '')
|
||||
if len(DB_URI) == 0:
|
||||
DB_URI = ''
|
||||
DATABASE_URL = environ.get('DATABASE_URL', '')
|
||||
if len(DATABASE_URL) == 0:
|
||||
DATABASE_URL = ''
|
||||
|
||||
if DB_URI:
|
||||
conn = MongoClient(DB_URI)
|
||||
if DATABASE_URL:
|
||||
conn = MongoClient(DATABASE_URL)
|
||||
db = conn.mltb
|
||||
if config_dict := db.settings.config.find_one({'_id': bot_id}): #retrun config dict (all env vars)
|
||||
del config_dict['_id']
|
||||
@ -90,6 +90,9 @@ if DB_URI:
|
||||
del qbit_opt['_id']
|
||||
qbit_options = qbit_opt
|
||||
conn.close()
|
||||
BOT_TOKEN = environ.get('BOT_TOKEN', '')
|
||||
bot_id = int(BOT_TOKEN.split(':', 1)[0])
|
||||
DATABASE_URL = environ.get('DATABASE_URL', '')
|
||||
else:
|
||||
config_dict = {}
|
||||
|
||||
@ -120,7 +123,7 @@ DOWNLOAD_DIR = environ.get('DOWNLOAD_DIR', '')
|
||||
if len(DOWNLOAD_DIR) == 0:
|
||||
DOWNLOAD_DIR = '/usr/src/app/downloads/'
|
||||
elif not DOWNLOAD_DIR.endswith("/"):
|
||||
DOWNLOAD_DIR = DOWNLOAD_DIR + '/'
|
||||
DOWNLOAD_DIR = f'{DOWNLOAD_DIR}/'
|
||||
|
||||
AUTHORIZED_CHATS = environ.get('AUTHORIZED_CHATS', '')
|
||||
if len(AUTHORIZED_CHATS) != 0:
|
||||
@ -288,7 +291,10 @@ config_dict = {'AS_DOCUMENT': AS_DOCUMENT,
|
||||
'AUTHORIZED_CHATS': AUTHORIZED_CHATS,
|
||||
'AUTO_DELETE_MESSAGE_DURATION': AUTO_DELETE_MESSAGE_DURATION,
|
||||
'BASE_URL': BASE_URL,
|
||||
'BOT_TOKEN': BOT_TOKEN,
|
||||
'CMD_PERFIX': CMD_PERFIX,
|
||||
'DATABASE_URL': DATABASE_URL,
|
||||
'DOWNLOAD_DIR': DOWNLOAD_DIR,
|
||||
'DUMP_CHAT': DUMP_CHAT,
|
||||
'EQUAL_SPLITS': EQUAL_SPLITS,
|
||||
'EXTENSION_FILTER': EXTENSION_FILTER,
|
||||
@ -302,6 +308,7 @@ config_dict = {'AS_DOCUMENT': AS_DOCUMENT,
|
||||
'MEGA_API_KEY': MEGA_API_KEY,
|
||||
'MEGA_EMAIL_ID': MEGA_EMAIL_ID,
|
||||
'MEGA_PASSWORD': MEGA_PASSWORD,
|
||||
'OWNER_ID': OWNER_ID,
|
||||
'RSS_USER_SESSION_STRING': RSS_USER_SESSION_STRING,
|
||||
'RSS_CHAT_ID': RSS_CHAT_ID,
|
||||
'RSS_COMMAND': RSS_COMMAND,
|
||||
@ -354,6 +361,8 @@ srun(["chmod", "600", ".netrc"])
|
||||
srun(["chmod", "+x", "aria.sh"])
|
||||
srun("./aria.sh", shell=True)
|
||||
if ospath.exists('accounts.zip'):
|
||||
if ospath.exists('accounts'):
|
||||
srun(["rm", "-rf", "accounts"])
|
||||
srun(["unzip", "-q", "-o", "accounts.zip"])
|
||||
srun(["chmod", "-R", "777", "accounts"])
|
||||
osremove('accounts.zip')
|
||||
|
@ -7,7 +7,7 @@ from sys import executable
|
||||
from telegram.ext import CommandHandler
|
||||
|
||||
from bot import bot, dispatcher, updater, botStartTime, IGNORE_PENDING_REQUESTS, LOGGER, Interval, \
|
||||
DB_URI, app, main_loop, QbInterval, INCOMPLETE_TASK_NOTIFIER
|
||||
DATABASE_URL, app, main_loop, QbInterval, INCOMPLETE_TASK_NOTIFIER
|
||||
from .helper.ext_utils.fs_utils import start_cleanup, clean_all, exit_clean_up
|
||||
from .helper.ext_utils.bot_utils import get_readable_file_size, get_readable_time
|
||||
from .helper.ext_utils.db_handler import DbManger
|
||||
@ -138,7 +138,7 @@ def bot_help(update, context):
|
||||
|
||||
def main():
|
||||
start_cleanup()
|
||||
if INCOMPLETE_TASK_NOTIFIER and DB_URI:
|
||||
if INCOMPLETE_TASK_NOTIFIER and DATABASE_URL:
|
||||
if notifier_dict := DbManger().get_incomplete_tasks():
|
||||
for cid, data in notifier_dict.items():
|
||||
if ospath.isfile(".restartmsg"):
|
||||
|
@ -2,7 +2,7 @@ from os import path as ospath, makedirs
|
||||
from pymongo import MongoClient
|
||||
from pymongo.errors import PyMongoError
|
||||
|
||||
from bot import DB_URI, user_data, rss_dict, LOGGER, bot_id, config_dict, aria2_options, qbit_options
|
||||
from bot import DATABASE_URL, user_data, rss_dict, LOGGER, bot_id, config_dict, aria2_options, qbit_options
|
||||
|
||||
class DbManger:
|
||||
def __init__(self):
|
||||
@ -13,7 +13,7 @@ class DbManger:
|
||||
|
||||
def __connect(self):
|
||||
try:
|
||||
self.__conn = MongoClient(DB_URI)
|
||||
self.__conn = MongoClient(DATABASE_URL)
|
||||
self.__db = self.__conn.mltb
|
||||
except PyMongoError as e:
|
||||
LOGGER.error(f"Error in DB connection: {e}")
|
||||
@ -155,6 +155,6 @@ class DbManger:
|
||||
self.__db[name].drop()
|
||||
self.__conn.close()
|
||||
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().db_load()
|
||||
|
||||
|
@ -50,7 +50,7 @@ class TelegraphHelper:
|
||||
except RetryAfterError as st:
|
||||
LOGGER.warning(f'Telegraph Flood control exceeded. I will sleep for {st.retry_after} seconds.')
|
||||
sleep(st.retry_after)
|
||||
return self.edit_page(path, title, content)
|
||||
return self.edit_page(path, title, content)
|
||||
|
||||
def edit_telegraph(self, path, telegraph_content):
|
||||
nxt_page = 1
|
||||
|
@ -1,6 +1,6 @@
|
||||
from telegram.ext import CommandHandler
|
||||
|
||||
from bot import user_data, dispatcher, DB_URI
|
||||
from bot import user_data, dispatcher, DATABASE_URL
|
||||
from bot.helper.telegram_helper.message_utils import sendMessage
|
||||
from bot.helper.telegram_helper.filters import CustomFilters
|
||||
from bot.helper.telegram_helper.bot_commands import BotCommands
|
||||
@ -20,7 +20,7 @@ def authorize(update, context):
|
||||
msg = 'Already Authorized!'
|
||||
else:
|
||||
update_user_ldata(id_, 'is_auth', True)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_user_data(id_)
|
||||
msg = 'Authorized'
|
||||
sendMessage(msg, context.bot, update.message)
|
||||
@ -35,7 +35,7 @@ def unauthorize(update, context):
|
||||
id_ = update.effective_chat.id
|
||||
if id_ not in user_data or user_data[id_].get('is_auth'):
|
||||
update_user_ldata(id_, 'is_auth', False)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_user_data(id_)
|
||||
msg = 'Unauthorized'
|
||||
else:
|
||||
@ -54,7 +54,7 @@ def addSudo(update, context):
|
||||
msg = 'Already Sudo!'
|
||||
else:
|
||||
update_user_ldata(id_, 'is_sudo', True)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_user_data(id_)
|
||||
msg = 'Promoted as Sudo'
|
||||
else:
|
||||
@ -70,7 +70,7 @@ def removeSudo(update, context):
|
||||
id_ = reply_message.from_user.id
|
||||
if id_ and id_ not in user_data or user_data[id_].get('is_sudo'):
|
||||
update_user_ldata(id_, 'is_sudo', False)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_user_data(id_)
|
||||
msg = 'Demoted'
|
||||
else:
|
||||
|
@ -5,7 +5,7 @@ from os import remove, rename, path as ospath, environ
|
||||
from subprocess import run as srun, Popen
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from bot import config_dict, dispatcher, user_data, DB_URI, MAX_SPLIT_SIZE, DRIVES_IDS, DRIVES_NAMES, INDEX_URLS, aria2, GLOBAL_EXTENSION_FILTER, status_reply_dict_lock, Interval, aria2_options, aria2c_global, IS_PREMIUM_USER, download_dict, qbit_options, get_client
|
||||
from bot import config_dict, dispatcher, user_data, DATABASE_URL, MAX_SPLIT_SIZE, DRIVES_IDS, DRIVES_NAMES, INDEX_URLS, aria2, GLOBAL_EXTENSION_FILTER, status_reply_dict_lock, Interval, aria2_options, aria2c_global, IS_PREMIUM_USER, download_dict, qbit_options, get_client
|
||||
from bot.helper.telegram_helper.message_utils import sendFile, sendMarkup, editMessage, update_all_messages
|
||||
from bot.helper.telegram_helper.filters import CustomFilters
|
||||
from bot.helper.telegram_helper.bot_commands import BotCommands
|
||||
@ -18,15 +18,46 @@ START = 0
|
||||
STATE = 'view'
|
||||
handler_dict = {}
|
||||
default_values = {'AUTO_DELETE_MESSAGE_DURATION': 30,
|
||||
'UPSTREAM_BRANCH': 'master',
|
||||
'STATUS_UPDATE_INTERVAL': 10,
|
||||
'DOWNLOAD_DIR': '/usr/src/app/downloads/',
|
||||
'LEECH_SPLIT_SIZE': MAX_SPLIT_SIZE,
|
||||
'RSS_DELAY': 900,
|
||||
'STATUS_UPDATE_INTERVAL': 10,
|
||||
'SEARCH_LIMIT': 0,
|
||||
'RSS_DELAY': 900}
|
||||
'UPSTREAM_BRANCH': 'master'}
|
||||
|
||||
|
||||
def load_config():
|
||||
|
||||
BOT_TOKEN = environ.get('BOT_TOKEN', '')
|
||||
if len(BOT_TOKEN) == 0:
|
||||
BOT_TOKEN = config_dict['BOT_TOKEN']
|
||||
|
||||
TELEGRAM_API = environ.get('TELEGRAM_API', '')
|
||||
if len(TELEGRAM_API) == 0:
|
||||
TELEGRAM_API = config_dict['TELEGRAM_API']
|
||||
else:
|
||||
TELEGRAM_API = int(TELEGRAM_API)
|
||||
|
||||
TELEGRAM_HASH = environ.get('TELEGRAM_HASH', '')
|
||||
if len(TELEGRAM_HASH) == 0:
|
||||
TELEGRAM_API = config_dict['TELEGRAM_API']
|
||||
|
||||
OWNER_ID = environ.get('OWNER_ID', '')
|
||||
if len(OWNER_ID) == 0:
|
||||
OWNER_ID = config_dict['OWNER_ID']
|
||||
else:
|
||||
OWNER_ID = int(OWNER_ID)
|
||||
|
||||
DATABASE_URL = environ.get('DATABASE_URL', '')
|
||||
if len(DATABASE_URL) == 0:
|
||||
DATABASE_URL = ''
|
||||
|
||||
DOWNLOAD_DIR = environ.get('DOWNLOAD_DIR', '')
|
||||
if len(DOWNLOAD_DIR) == 0:
|
||||
DOWNLOAD_DIR = '/usr/src/app/downloads/'
|
||||
elif not DOWNLOAD_DIR.endswith("/"):
|
||||
DOWNLOAD_DIR = f'{DOWNLOAD_DIR}/'
|
||||
|
||||
GDRIVE_ID = environ.get('GDRIVE_ID', '')
|
||||
if len(GDRIVE_ID) == 0:
|
||||
GDRIVE_ID = ''
|
||||
@ -132,10 +163,6 @@ def load_config():
|
||||
|
||||
CMD_PERFIX = environ.get('CMD_PERFIX', '')
|
||||
|
||||
TELEGRAM_HASH = environ.get('TELEGRAM_HASH', '')
|
||||
|
||||
TELEGRAM_API = environ.get('TELEGRAM_API', '')
|
||||
|
||||
USER_SESSION_STRING = environ.get('USER_SESSION_STRING', '')
|
||||
|
||||
RSS_USER_SESSION_STRING = environ.get('RSS_USER_SESSION_STRING', '')
|
||||
@ -154,6 +181,8 @@ def load_config():
|
||||
|
||||
INCOMPLETE_TASK_NOTIFIER = environ.get('INCOMPLETE_TASK_NOTIFIER', '')
|
||||
INCOMPLETE_TASK_NOTIFIER = INCOMPLETE_TASK_NOTIFIER.lower() == 'true'
|
||||
if not INCOMPLETE_TASK_NOTIFIER and DATABASE_URL:
|
||||
DbManger().trunc_table('tasks')
|
||||
|
||||
STOP_DUPLICATE = environ.get('STOP_DUPLICATE', '')
|
||||
STOP_DUPLICATE = STOP_DUPLICATE.lower() == 'true'
|
||||
@ -224,7 +253,10 @@ def load_config():
|
||||
'AUTHORIZED_CHATS': AUTHORIZED_CHATS,
|
||||
'AUTO_DELETE_MESSAGE_DURATION': AUTO_DELETE_MESSAGE_DURATION,
|
||||
'BASE_URL': BASE_URL,
|
||||
'BOT_TOKEN': BOT_TOKEN,
|
||||
'CMD_PERFIX': CMD_PERFIX,
|
||||
'DATABASE_URL': DATABASE_URL,
|
||||
'DOWNLOAD_DIR': DOWNLOAD_DIR,
|
||||
'DUMP_CHAT': DUMP_CHAT,
|
||||
'EQUAL_SPLITS': EQUAL_SPLITS,
|
||||
'EXTENSION_FILTER': EXTENSION_FILTER,
|
||||
@ -238,6 +270,7 @@ def load_config():
|
||||
'MEGA_API_KEY': MEGA_API_KEY,
|
||||
'MEGA_EMAIL_ID': MEGA_EMAIL_ID,
|
||||
'MEGA_PASSWORD': MEGA_PASSWORD,
|
||||
'OWNER_ID': OWNER_ID,
|
||||
'RSS_USER_SESSION_STRING': RSS_USER_SESSION_STRING,
|
||||
'RSS_CHAT_ID': RSS_CHAT_ID,
|
||||
'RSS_COMMAND': RSS_COMMAND,
|
||||
@ -262,7 +295,7 @@ def load_config():
|
||||
'WEB_PINCODE': WEB_PINCODE,
|
||||
'YT_DLP_QUALITY': YT_DLP_QUALITY})
|
||||
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_config(config_dict)
|
||||
|
||||
def get_buttons(key=None, edit_type=None):
|
||||
@ -318,7 +351,7 @@ def get_buttons(key=None, edit_type=None):
|
||||
msg = f'Qbittorrent Options. Page: {int(START/10)}. State: {STATE}'
|
||||
elif edit_type == 'editvar':
|
||||
buttons.sbutton('Back', "botset back var")
|
||||
if key not in ['TELEGRAM_HASH', 'TELEGRAM_API']:
|
||||
if key not in ['TELEGRAM_HASH', 'TELEGRAM_API', 'OWNER_ID', 'BOT_TOKEN']:
|
||||
buttons.sbutton('Default', f"botset resetvar {key}")
|
||||
buttons.sbutton('Close', "botset close")
|
||||
msg = f'Send a valid value for {key}. Timeout: 60 sec'
|
||||
@ -337,7 +370,11 @@ def get_buttons(key=None, edit_type=None):
|
||||
buttons.sbutton('Empty String', f"botset emptyqbit {key}")
|
||||
buttons.sbutton('Close', "botset close")
|
||||
msg = f'Send a valid value for {key}. Timeout: 60 sec'
|
||||
return msg, buttons.build_menu(1)
|
||||
if key is None:
|
||||
button = buttons.build_menu(1)
|
||||
else:
|
||||
button = buttons.build_menu(2)
|
||||
return msg, button
|
||||
|
||||
def update_buttons(message, key=None, edit_type=None):
|
||||
msg, button = get_buttons(key, edit_type)
|
||||
@ -350,6 +387,11 @@ def edit_variable(update, context, omsg, key):
|
||||
value = True
|
||||
elif value.lower() == 'false':
|
||||
value = False
|
||||
if key == 'INCOMPLETE_TASK_NOTIFIER' and DATABASE_URL:
|
||||
DbManger().trunc_table('tasks')
|
||||
elif key == 'DOWNLOAD_DIR':
|
||||
if not value.endswith('/'):
|
||||
value = f'{value}/'
|
||||
elif key == 'STATUS_UPDATE_INTERVAL':
|
||||
value = int(value)
|
||||
if len(download_dict) != 0:
|
||||
@ -393,7 +435,7 @@ def edit_variable(update, context, omsg, key):
|
||||
config_dict[key] = value
|
||||
update_buttons(omsg, 'var')
|
||||
update.message.delete()
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_config({key: value})
|
||||
|
||||
def edit_aria(update, context, omsg, key):
|
||||
@ -414,7 +456,7 @@ def edit_aria(update, context, omsg, key):
|
||||
aria2_options[key] = value
|
||||
update_buttons(omsg, 'aria')
|
||||
update.message.delete()
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_aria2(key, value)
|
||||
|
||||
def edit_qbit(update, context, omsg, key):
|
||||
@ -433,7 +475,7 @@ def edit_qbit(update, context, omsg, key):
|
||||
qbit_options[key] = value
|
||||
update_buttons(omsg, 'qbit')
|
||||
update.message.delete()
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_qbittorrent(key, value)
|
||||
|
||||
def update_private_file(update, context, omsg):
|
||||
@ -487,7 +529,7 @@ def update_private_file(update, context, omsg):
|
||||
else:
|
||||
update.message.delete()
|
||||
update_buttons(omsg)
|
||||
if DB_URI:
|
||||
if DATABASE_URL and file_name != 'config.env':
|
||||
DbManger().update_private_file(file_name)
|
||||
if ospath.exists('accounts.zip'):
|
||||
remove('accounts.zip')
|
||||
@ -548,9 +590,11 @@ def edit_bot_settings(update, context):
|
||||
elif data[2] == 'INDEX_URL':
|
||||
if DRIVES_NAMES and DRIVES_NAMES[0] == 'Main':
|
||||
INDEX_URLS[0] = ''
|
||||
elif data[2] == 'INCOMPLETE_TASK_NOTIFIER' and DATABASE_URL:
|
||||
DbManger().trunc_table('tasks')
|
||||
config_dict[data[2]] = value
|
||||
update_buttons(message, 'var')
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_config({data[2]: value})
|
||||
elif data[1] == 'resetaria':
|
||||
handler_dict[message.chat.id] = False
|
||||
@ -565,7 +609,7 @@ def edit_bot_settings(update, context):
|
||||
downloads = aria2.get_downloads()
|
||||
if downloads:
|
||||
aria2.set_options({data[2]: value}, downloads)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_aria2(data[2], value)
|
||||
elif data[1] == 'emptyaria':
|
||||
query.answer()
|
||||
@ -575,7 +619,7 @@ def edit_bot_settings(update, context):
|
||||
downloads = aria2.get_downloads()
|
||||
if downloads:
|
||||
aria2.set_options({data[2]: ''}, downloads)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_aria2(data[2], '')
|
||||
elif data[1] == 'emptyqbit':
|
||||
query.answer()
|
||||
@ -584,7 +628,7 @@ def edit_bot_settings(update, context):
|
||||
client.app_set_preferences({data[2]: value})
|
||||
qbit_options[data[2]] = ''
|
||||
update_buttons(message, 'qbit')
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_qbittorrent(data[2], '')
|
||||
elif data[1] == 'private':
|
||||
query.answer()
|
||||
@ -603,8 +647,9 @@ def edit_bot_settings(update, context):
|
||||
update_buttons(message)
|
||||
dispatcher.remove_handler(file_handler)
|
||||
elif data[1] == 'editvar' and STATE == 'edit':
|
||||
if data[2] in ['SUDO_USERS', 'RSS_USER_SESSION_STRING', 'IGNORE_PENDING_REQUESTS', 'CMD_PERFIX',
|
||||
'USER_SESSION_STRING', 'TELEGRAM_HASH', 'TELEGRAM_API', 'AUTHORIZED_CHATS', 'RSS_DELAY']:
|
||||
if data[2] in ['SUDO_USERS', 'RSS_USER_SESSION_STRING', 'IGNORE_PENDING_REQUESTS', 'CMD_PERFIX', 'OWNER_ID',
|
||||
'USER_SESSION_STRING', 'TELEGRAM_HASH', 'TELEGRAM_API', 'AUTHORIZED_CHATS', 'RSS_DELAY'
|
||||
'DATABASE_URL', 'BOT_TOKEN', 'DOWNLOAD_DIR']:
|
||||
query.answer(text='Restart required for this edit to take effect!', show_alert=True)
|
||||
else:
|
||||
query.answer()
|
||||
@ -708,7 +753,7 @@ def edit_bot_settings(update, context):
|
||||
update_buttons(message, data[2])
|
||||
elif data[1] == 'push':
|
||||
query.answer()
|
||||
srun([f"git add -f {data[2]} \
|
||||
srun([f"git add -f {data[2].rsplit('.zip', 1)[0]} \
|
||||
&& git commit -sm botsettings -q \
|
||||
&& git push origin {config_dict['UPSTREAM_BRANCH']} -q"], shell=True)
|
||||
query.message.delete()
|
||||
|
@ -5,7 +5,7 @@ from os import path as ospath, remove as osremove, listdir, walk
|
||||
from subprocess import Popen
|
||||
from html import escape
|
||||
|
||||
from bot import Interval, aria2, DOWNLOAD_DIR, download_dict, download_dict_lock, LOGGER, DB_URI, MAX_SPLIT_SIZE, config_dict, status_reply_dict_lock
|
||||
from bot import Interval, aria2, DOWNLOAD_DIR, download_dict, download_dict_lock, LOGGER, DATABASE_URL, MAX_SPLIT_SIZE, config_dict, status_reply_dict_lock
|
||||
from bot.helper.ext_utils.fs_utils import get_base_name, get_path_size, split_file, clean_download, clean_target
|
||||
from bot.helper.ext_utils.exceptions import NotSupportedExtractionArchive
|
||||
from bot.helper.mirror_utils.status_utils.extract_status import ExtractStatus
|
||||
@ -49,7 +49,7 @@ class MirrorLeechListener:
|
||||
pass
|
||||
|
||||
def onDownloadStart(self):
|
||||
if not self.isPrivate and config_dict['INCOMPLETE_TASK_NOTIFIER'] and DB_URI:
|
||||
if not self.isPrivate and config_dict['INCOMPLETE_TASK_NOTIFIER'] and DATABASE_URL:
|
||||
DbManger().add_incomplete_task(self.message.chat.id, self.message.link, self.tag)
|
||||
|
||||
def onDownloadComplete(self):
|
||||
@ -214,7 +214,7 @@ class MirrorLeechListener:
|
||||
drive.upload(up_name)
|
||||
|
||||
def onUploadComplete(self, link: str, size, files, folders, typ, name):
|
||||
if not self.isPrivate and config_dict['INCOMPLETE_TASK_NOTIFIER'] and DB_URI:
|
||||
if not self.isPrivate and config_dict['INCOMPLETE_TASK_NOTIFIER'] and DATABASE_URL:
|
||||
DbManger().rm_complete_task(self.message.link)
|
||||
msg = f"<b>Name: </b><code>{escape(name)}</code>\n\n<b>Size: </b>{size}"
|
||||
if self.isLeech:
|
||||
@ -295,7 +295,7 @@ class MirrorLeechListener:
|
||||
else:
|
||||
update_all_messages()
|
||||
|
||||
if not self.isPrivate and config_dict['INCOMPLETE_TASK_NOTIFIER'] and DB_URI:
|
||||
if not self.isPrivate and config_dict['INCOMPLETE_TASK_NOTIFIER'] and DATABASE_URL:
|
||||
DbManger().rm_complete_task(self.message.link)
|
||||
|
||||
def onUploadError(self, error):
|
||||
@ -315,5 +315,5 @@ class MirrorLeechListener:
|
||||
else:
|
||||
update_all_messages()
|
||||
|
||||
if not self.isPrivate and config_dict['INCOMPLETE_TASK_NOTIFIER'] and DB_URI:
|
||||
if not self.isPrivate and config_dict['INCOMPLETE_TASK_NOTIFIER'] and DATABASE_URL:
|
||||
DbManger().rm_complete_task(self.message.link)
|
||||
|
@ -2,9 +2,8 @@ from feedparser import parse as feedparse
|
||||
from time import sleep
|
||||
from telegram.ext import CommandHandler, CallbackQueryHandler
|
||||
from threading import Lock, Thread
|
||||
from copy import deepcopy
|
||||
|
||||
from bot import dispatcher, job_queue, rss_dict, LOGGER, DB_URI, config_dict, RSS_DELAY, RSS_CHAT_ID
|
||||
from bot import dispatcher, job_queue, rss_dict, LOGGER, DATABASE_URL, config_dict, RSS_DELAY, RSS_CHAT_ID
|
||||
from bot.helper.telegram_helper.message_utils import sendMessage, editMessage, sendMarkup, auto_delete_message, sendRss
|
||||
from bot.helper.telegram_helper.filters import CustomFilters
|
||||
from bot.helper.telegram_helper.bot_commands import BotCommands
|
||||
@ -184,8 +183,7 @@ def rss_monitor(context):
|
||||
if len(rss_dict) == 0:
|
||||
rss_job.enabled = False
|
||||
return
|
||||
rss_saver = deepcopy(rss_dict)
|
||||
for title, data in rss_saver.items():
|
||||
for title, data in list(rss_dict.items()):
|
||||
try:
|
||||
rss_d = feedparse(data['link'])
|
||||
last_link = rss_d.entries[0]['link']
|
||||
@ -222,6 +220,8 @@ def rss_monitor(context):
|
||||
feed_count += 1
|
||||
sleep(5)
|
||||
with rss_dict_lock:
|
||||
if title not in rss_dict:
|
||||
continue
|
||||
rss_dict[title].update({'last_feed': last_link, 'last_title': last_title})
|
||||
DbManger().rss_update(title)
|
||||
LOGGER.info(f"Feed Name: {title}")
|
||||
@ -230,7 +230,7 @@ def rss_monitor(context):
|
||||
LOGGER.error(f"{e} Feed Name: {title} - Feed Link: {data['link']}")
|
||||
continue
|
||||
|
||||
if DB_URI and RSS_CHAT_ID:
|
||||
if DATABASE_URL and RSS_CHAT_ID:
|
||||
rss_list_handler = CommandHandler(BotCommands.RssListCommand, rss_list,
|
||||
filters=CustomFilters.owner_filter | CustomFilters.sudo_user, run_async=True)
|
||||
rss_get_handler = CommandHandler(BotCommands.RssGetCommand, rss_get,
|
||||
|
@ -5,7 +5,7 @@ from time import sleep, time
|
||||
from functools import partial
|
||||
from html import escape
|
||||
|
||||
from bot import user_data, dispatcher, config_dict, DB_URI
|
||||
from bot import user_data, dispatcher, config_dict, DATABASE_URL
|
||||
from bot.helper.telegram_helper.message_utils import sendMessage, sendMarkup, editMessage
|
||||
from bot.helper.telegram_helper.filters import CustomFilters
|
||||
from bot.helper.telegram_helper.bot_commands import BotCommands
|
||||
@ -70,7 +70,7 @@ def set_yt_quality(update, context, omsg):
|
||||
update_user_ldata(user_id, 'yt_ql', value)
|
||||
update.message.delete()
|
||||
update_user_settings(omsg, message.from_user)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_user_data(user_id)
|
||||
|
||||
def set_thumb(update, context, omsg):
|
||||
@ -88,7 +88,7 @@ def set_thumb(update, context, omsg):
|
||||
update_user_ldata(user_id, 'thumb', des_dir)
|
||||
update.message.delete()
|
||||
update_user_settings(omsg, message.from_user)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_thumb(user_id, des_dir)
|
||||
|
||||
def edit_user_settings(update, context):
|
||||
@ -103,13 +103,13 @@ def edit_user_settings(update, context):
|
||||
update_user_ldata(user_id, 'as_doc', True)
|
||||
query.answer(text="Your File Will Deliver As Document!", show_alert=True)
|
||||
update_user_settings(message, query.from_user)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_user_data(user_id)
|
||||
elif data[2] == "med":
|
||||
update_user_ldata(user_id, 'as_doc', False)
|
||||
query.answer(text="Your File Will Deliver As Media!", show_alert=True)
|
||||
update_user_settings(message, query.from_user)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_user_data(user_id)
|
||||
elif data[2] == "dthumb":
|
||||
path = f"Thumbnails/{user_id}.jpg"
|
||||
@ -118,7 +118,7 @@ def edit_user_settings(update, context):
|
||||
osremove(path)
|
||||
update_user_ldata(user_id, 'thumb', '')
|
||||
update_user_settings(message, query.from_user)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_thumb(user_id)
|
||||
else:
|
||||
query.answer(text="Old Settings", show_alert=True)
|
||||
@ -174,7 +174,7 @@ Check all available qualities options <a href="https://github.com/yt-dlp/yt-dlp#
|
||||
query.answer(text="YT-DLP Quality Removed!", show_alert=True)
|
||||
update_user_ldata(user_id, 'yt_ql', '')
|
||||
update_user_settings(message, query.from_user)
|
||||
if DB_URI:
|
||||
if DATABASE_URL:
|
||||
DbManger().update_user_data(user_id)
|
||||
elif data[2] == 'back':
|
||||
query.answer()
|
||||
|
@ -1,17 +1,17 @@
|
||||
# Remove this line before deploying
|
||||
_____REMOVE_THIS_LINE_____=True
|
||||
# REQUIRED CONFIG
|
||||
BOT_TOKEN = "" # Non-editable while bot is running
|
||||
OWNER_ID = "" # Non-editable while bot is running
|
||||
BOT_TOKEN = "" # Require restart after changing it while bot running
|
||||
OWNER_ID = "" # Require restart after changing it while bot running
|
||||
TELEGRAM_API = "" # Require restart after changing it while bot running
|
||||
TELEGRAM_HASH = "" # Require restart after changing it while bot running
|
||||
# OPTIONAL CONFIG
|
||||
GDRIVE_ID = ""
|
||||
IS_TEAM_DRIVE = ""
|
||||
DOWNLOAD_DIR = "/usr/src/app/downloads/" # Non-editable while bot is running
|
||||
DOWNLOAD_DIR = "/usr/src/app/downloads/" # Require restart after changing it while bot running
|
||||
DOWNLOAD_STATUS_UPDATE_INTERVAL = "10"
|
||||
AUTO_DELETE_MESSAGE_DURATION = "30"
|
||||
DATABASE_URL = "" # Non-editable while bot is running
|
||||
DATABASE_URL = "" # Require restart after changing it while bot running
|
||||
AUTHORIZED_CHATS = "" # Require restart after changing it while bot running
|
||||
SUDO_USERS = "" # Require restart after changing it while bot running
|
||||
IGNORE_PENDING_REQUESTS = ""
|
||||
|
10
update.py
10
update.py
@ -29,12 +29,12 @@ if len(BOT_TOKEN) == 0:
|
||||
|
||||
bot_id = int(BOT_TOKEN.split(':', 1)[0])
|
||||
|
||||
DB_URI = environ.get('DATABASE_URL', '')
|
||||
if len(DB_URI) == 0:
|
||||
DB_URI = None
|
||||
DATABASE_URL = environ.get('DATABASE_URL', '')
|
||||
if len(DATABASE_URL) == 0:
|
||||
DATABASE_URL = None
|
||||
|
||||
if DB_URI is not None:
|
||||
conn = MongoClient(DB_URI)
|
||||
if DATABASE_URL is not None:
|
||||
conn = MongoClient(DATABASE_URL)
|
||||
db = conn.mltb
|
||||
if config_dict := db.settings.config.find_one({'_id': bot_id}): #retrun config dict (all env vars)
|
||||
environ['UPSTREAM_REPO'] = config_dict['UPSTREAM_REPO']
|
||||
|
Loading…
Reference in New Issue
Block a user