From 500520455b074a49d9eac7d40e85dda0d667d40c Mon Sep 17 00:00:00 2001 From: trueold89 Date: Tue, 31 Oct 2023 02:03:14 +0300 Subject: [PATCH] Add magnet function --- bot.py | 25 ++++++++++++++++++++++--- func.py | 7 ++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index d593c0e..6f3eda7 100644 --- a/bot.py +++ b/bot.py @@ -20,8 +20,7 @@ def home(): keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True) file = telebot.types.KeyboardButton('File') magnet = telebot.types.KeyboardButton('MagnetLink') - keyboard.add(file) - keyboard.add(magnet) + keyboard.add(file,magnet) return keyboard # Login @@ -43,10 +42,13 @@ def folder_menu(): else: keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True) i = 0 + global folder_list + folder_list = [] lst = [] for folder in folders.keys(): globals()[f'var_{i}'] = telebot.types.KeyboardButton(f'{folder}') lst.append(f'var_{i}') + folder_list.append(folder) i += 1 for var in lst: keyboard.add(globals()[var]) @@ -73,12 +75,13 @@ def rm(message): f = func.del_dir(id,folder) bot.reply_to(message,str(f),reply_markup=home()) - # Magnet @bot.message_handler(func=lambda message: message.text == 'MagnetLink') def magnet(message): id = message.from_user.id if func.auth_check(id): + global type + type = 'magnet' f = folder_menu() if f == None: bot.reply_to(message,'No folders, use /add ') @@ -87,11 +90,27 @@ def magnet(message): else: bot.reply_to(message,'Log in to use bot /login ') +# Dir choose +def dirchoose(message): + global dir + dir = message.text + if type == 'magnet': + bot.reply_to(message,'Send magnet link') + # Unknown message @bot.message_handler(func=lambda message: True) def unknown(message): + global type, dir, folder_list id = message.from_user.id if func.auth_check(id): + txt = message.text + if txt in folder_list: + dirchoose(message) + return None + if dir != None and type == 'magnet': + f = func.magnet(id,txt,dir) + dir, type, folder_list = None,None,[] + bot.reply_to(message,f) bot.reply_to(message,'Choose download type:',reply_markup=home()) else: bot.reply_to(message,'Log in to use bot /login ') diff --git a/func.py b/func.py index d56913f..94eb061 100644 --- a/func.py +++ b/func.py @@ -57,8 +57,13 @@ def del_dir(id,dir): def magnet(id,link,dir): if auth_check(id): - subprocess.run(f"qbt torrent add url {link} -f {dir}", check=True, shell=True) + dict = db.read(DIR_FILE) + path = dict[dir] + command = f'''qbt torrent add url "{link} -f {path}"''' + os.system(f"bash -c '{command}'") return 'Success' + else: + return 'Log in first' def file(id,file,dir): if auth_check(id):