forked from OrudoCA/qBitDownload-Bot
Add magnet function
This commit is contained in:
parent
affa101f38
commit
500520455b
25
bot.py
25
bot.py
|
@ -20,8 +20,7 @@ def home():
|
||||||
keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
|
keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
|
||||||
file = telebot.types.KeyboardButton('File')
|
file = telebot.types.KeyboardButton('File')
|
||||||
magnet = telebot.types.KeyboardButton('MagnetLink')
|
magnet = telebot.types.KeyboardButton('MagnetLink')
|
||||||
keyboard.add(file)
|
keyboard.add(file,magnet)
|
||||||
keyboard.add(magnet)
|
|
||||||
return keyboard
|
return keyboard
|
||||||
|
|
||||||
# Login
|
# Login
|
||||||
|
@ -43,10 +42,13 @@ def folder_menu():
|
||||||
else:
|
else:
|
||||||
keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
|
keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
|
||||||
i = 0
|
i = 0
|
||||||
|
global folder_list
|
||||||
|
folder_list = []
|
||||||
lst = []
|
lst = []
|
||||||
for folder in folders.keys():
|
for folder in folders.keys():
|
||||||
globals()[f'var_{i}'] = telebot.types.KeyboardButton(f'{folder}')
|
globals()[f'var_{i}'] = telebot.types.KeyboardButton(f'{folder}')
|
||||||
lst.append(f'var_{i}')
|
lst.append(f'var_{i}')
|
||||||
|
folder_list.append(folder)
|
||||||
i += 1
|
i += 1
|
||||||
for var in lst:
|
for var in lst:
|
||||||
keyboard.add(globals()[var])
|
keyboard.add(globals()[var])
|
||||||
|
@ -73,12 +75,13 @@ def rm(message):
|
||||||
f = func.del_dir(id,folder)
|
f = func.del_dir(id,folder)
|
||||||
bot.reply_to(message,str(f),reply_markup=home())
|
bot.reply_to(message,str(f),reply_markup=home())
|
||||||
|
|
||||||
|
|
||||||
# Magnet
|
# Magnet
|
||||||
@bot.message_handler(func=lambda message: message.text == 'MagnetLink')
|
@bot.message_handler(func=lambda message: message.text == 'MagnetLink')
|
||||||
def magnet(message):
|
def magnet(message):
|
||||||
id = message.from_user.id
|
id = message.from_user.id
|
||||||
if func.auth_check(id):
|
if func.auth_check(id):
|
||||||
|
global type
|
||||||
|
type = 'magnet'
|
||||||
f = folder_menu()
|
f = folder_menu()
|
||||||
if f == None:
|
if f == None:
|
||||||
bot.reply_to(message,'No folders, use /add <folder_name> <path>')
|
bot.reply_to(message,'No folders, use /add <folder_name> <path>')
|
||||||
|
@ -87,11 +90,27 @@ def magnet(message):
|
||||||
else:
|
else:
|
||||||
bot.reply_to(message,'Log in to use bot /login <passwd>')
|
bot.reply_to(message,'Log in to use bot /login <passwd>')
|
||||||
|
|
||||||
|
# Dir choose
|
||||||
|
def dirchoose(message):
|
||||||
|
global dir
|
||||||
|
dir = message.text
|
||||||
|
if type == 'magnet':
|
||||||
|
bot.reply_to(message,'Send magnet link')
|
||||||
|
|
||||||
# Unknown message
|
# Unknown message
|
||||||
@bot.message_handler(func=lambda message: True)
|
@bot.message_handler(func=lambda message: True)
|
||||||
def unknown(message):
|
def unknown(message):
|
||||||
|
global type, dir, folder_list
|
||||||
id = message.from_user.id
|
id = message.from_user.id
|
||||||
if func.auth_check(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())
|
bot.reply_to(message,'Choose download type:',reply_markup=home())
|
||||||
else:
|
else:
|
||||||
bot.reply_to(message,'Log in to use bot /login <passwd>')
|
bot.reply_to(message,'Log in to use bot /login <passwd>')
|
||||||
|
|
7
func.py
7
func.py
|
@ -57,8 +57,13 @@ def del_dir(id,dir):
|
||||||
|
|
||||||
def magnet(id,link,dir):
|
def magnet(id,link,dir):
|
||||||
if auth_check(id):
|
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'
|
return 'Success'
|
||||||
|
else:
|
||||||
|
return 'Log in first'
|
||||||
|
|
||||||
def file(id,file,dir):
|
def file(id,file,dir):
|
||||||
if auth_check(id):
|
if auth_check(id):
|
||||||
|
|
Loading…
Reference in New Issue