2023-10-30 22:02:26 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -- coding: utf-8 --
|
|
|
|
|
|
|
|
import func, telebot, os
|
2023-10-30 23:37:37 +00:00
|
|
|
from db import PATH
|
2023-10-31 22:49:17 +00:00
|
|
|
from lang import LANG as msg
|
2023-10-30 22:02:26 +00:00
|
|
|
|
|
|
|
TOKEN = os.environ["TOKEN"]
|
|
|
|
bot = telebot.TeleBot(TOKEN)
|
2023-10-30 23:37:37 +00:00
|
|
|
folder_list = []
|
2023-10-30 23:59:17 +00:00
|
|
|
dir = None
|
2023-10-30 22:02:26 +00:00
|
|
|
|
|
|
|
# Start
|
|
|
|
@bot.message_handler(commands=['start'])
|
|
|
|
def welcome(message):
|
|
|
|
id = message.from_user.id
|
|
|
|
if func.auth_check(id):
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('type')),reply_markup=home())
|
2023-10-30 22:02:26 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('adeny')))
|
2023-10-30 22:02:26 +00:00
|
|
|
|
|
|
|
# Keyboard: Homepage
|
|
|
|
def home():
|
|
|
|
keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
|
2023-10-31 22:49:17 +00:00
|
|
|
file = telebot.types.KeyboardButton(str(msg.get('file')))
|
|
|
|
magnet = telebot.types.KeyboardButton(str(msg.get('magnet')))
|
2023-10-30 23:03:14 +00:00
|
|
|
keyboard.add(file,magnet)
|
2023-10-30 22:02:26 +00:00
|
|
|
return keyboard
|
|
|
|
|
|
|
|
# Login
|
|
|
|
@bot.message_handler(commands=['login'])
|
|
|
|
def login(message):
|
|
|
|
id = message.from_user.id
|
|
|
|
passwd = message.text.replace('/login ', '')
|
2023-10-31 22:49:17 +00:00
|
|
|
f = str(func.u_auth(id,passwd))
|
|
|
|
if f == str(msg.get('sucauth')) or f == str(msg.get('alauth')):
|
2023-10-30 22:02:26 +00:00
|
|
|
bot.reply_to(message,f,reply_markup=home())
|
|
|
|
else:
|
|
|
|
bot.reply_to(message,f)
|
|
|
|
|
|
|
|
# Folders
|
|
|
|
def folder_menu():
|
|
|
|
folders = func.dirlist()
|
|
|
|
if len(folders) == 0:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
|
|
|
|
i = 0
|
2023-10-30 23:03:14 +00:00
|
|
|
global folder_list
|
|
|
|
folder_list = []
|
2023-10-30 22:02:26 +00:00
|
|
|
lst = []
|
|
|
|
for folder in folders.keys():
|
|
|
|
globals()[f'var_{i}'] = telebot.types.KeyboardButton(f'{folder}')
|
|
|
|
lst.append(f'var_{i}')
|
2023-10-30 23:03:14 +00:00
|
|
|
folder_list.append(folder)
|
2023-10-30 22:02:26 +00:00
|
|
|
i += 1
|
|
|
|
for var in lst:
|
|
|
|
keyboard.add(globals()[var])
|
|
|
|
return keyboard
|
|
|
|
|
|
|
|
# Folder add
|
|
|
|
@bot.message_handler(commands=['add'])
|
|
|
|
def add(message):
|
|
|
|
id = message.from_user.id
|
|
|
|
txt = message.text.split(' ', 2)
|
|
|
|
if len(txt) == 3:
|
|
|
|
key = txt[1]
|
|
|
|
path = txt[2]
|
2023-10-31 22:49:17 +00:00
|
|
|
f = str(func.add_dir(id,key,path))
|
2023-10-30 22:02:26 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
f = str(msg.get('aerr'))
|
2023-10-30 22:02:26 +00:00
|
|
|
bot.reply_to(message,f,reply_markup=home())
|
|
|
|
|
|
|
|
# Folder del
|
|
|
|
@bot.message_handler(commands=['del'])
|
|
|
|
def rm(message):
|
|
|
|
id = message.from_user.id
|
|
|
|
folder = message.text.replace('/del ', '')
|
|
|
|
f = func.del_dir(id,folder)
|
|
|
|
bot.reply_to(message,str(f),reply_markup=home())
|
|
|
|
|
|
|
|
# Magnet
|
2023-10-31 22:49:17 +00:00
|
|
|
@bot.message_handler(func=lambda message: message.text == str(msg.get('magnet')))
|
2023-10-30 22:02:26 +00:00
|
|
|
def magnet(message):
|
|
|
|
id = message.from_user.id
|
|
|
|
if func.auth_check(id):
|
2023-10-30 23:03:14 +00:00
|
|
|
global type
|
|
|
|
type = 'magnet'
|
2023-10-30 22:02:26 +00:00
|
|
|
f = folder_menu()
|
|
|
|
if f == None:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('cff')))
|
2023-10-30 22:02:26 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('chf')),reply_markup=f)
|
2023-10-30 22:02:26 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('adeny')))
|
2023-10-30 22:02:26 +00:00
|
|
|
|
2023-10-30 23:37:37 +00:00
|
|
|
# File
|
2023-10-31 22:49:17 +00:00
|
|
|
@bot.message_handler(func=lambda message: message.text == str(msg.get('file')))
|
2023-10-30 23:37:37 +00:00
|
|
|
def file(message):
|
|
|
|
id = message.from_user.id
|
|
|
|
if func.auth_check(id):
|
|
|
|
global type
|
|
|
|
type = 'file'
|
|
|
|
f = folder_menu()
|
|
|
|
if f == None:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('cff')))
|
2023-10-30 23:37:37 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('chf')),reply_markup=f)
|
2023-10-30 23:37:37 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('adeny')))
|
2023-10-30 23:37:37 +00:00
|
|
|
|
|
|
|
# File download
|
|
|
|
@bot.message_handler(content_types=['document'])
|
|
|
|
def download(message):
|
|
|
|
id = message.from_user.id
|
|
|
|
if func.auth_check(id):
|
|
|
|
global type, dir, folder_list
|
|
|
|
if dir != None and type == 'file':
|
|
|
|
if message.document.file_name.lower().endswith('.torrent'):
|
|
|
|
file_info = bot.get_file(message.document.file_id)
|
|
|
|
file_path = file_info.file_path
|
|
|
|
file = bot.download_file(file_path)
|
|
|
|
file_name = os.path.join(PATH, message.document.file_name)
|
|
|
|
with open(file_name, 'wb') as dl:
|
|
|
|
dl.write(file)
|
2023-10-31 22:49:17 +00:00
|
|
|
f = str(func.file(id,file_name,dir))
|
2023-10-30 23:37:37 +00:00
|
|
|
dir, type, folder_list = None,None,[]
|
|
|
|
bot.reply_to(message,f)
|
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('ntorr')))
|
|
|
|
bot.reply_to(message,str(msg.get('type')),reply_markup=home())
|
2023-10-30 23:37:37 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('adeny')))
|
2023-10-30 23:37:37 +00:00
|
|
|
|
2023-10-30 23:03:14 +00:00
|
|
|
# Dir choose
|
|
|
|
def dirchoose(message):
|
|
|
|
global dir
|
|
|
|
dir = message.text
|
|
|
|
if type == 'magnet':
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('sendm')))
|
2023-10-30 23:37:37 +00:00
|
|
|
if type == 'file':
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('sendf')))
|
2023-10-30 23:03:14 +00:00
|
|
|
|
2023-10-30 22:02:26 +00:00
|
|
|
# Unknown message
|
|
|
|
@bot.message_handler(func=lambda message: True)
|
|
|
|
def unknown(message):
|
2023-10-30 23:03:14 +00:00
|
|
|
global type, dir, folder_list
|
2023-10-30 22:02:26 +00:00
|
|
|
id = message.from_user.id
|
|
|
|
if func.auth_check(id):
|
2023-10-30 23:03:14 +00:00
|
|
|
txt = message.text
|
|
|
|
if txt in folder_list:
|
|
|
|
dirchoose(message)
|
|
|
|
return None
|
|
|
|
if dir != None and type == 'magnet':
|
2023-10-31 22:49:17 +00:00
|
|
|
f = str(func.magnet(id,txt,dir))
|
2023-10-30 23:03:14 +00:00
|
|
|
dir, type, folder_list = None,None,[]
|
|
|
|
bot.reply_to(message,f)
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('type')),reply_markup=home())
|
2023-10-30 22:02:26 +00:00
|
|
|
else:
|
2023-10-31 22:49:17 +00:00
|
|
|
bot.reply_to(message,str(msg.get('adeny')))
|
2023-10-30 22:02:26 +00:00
|
|
|
|
2023-10-31 00:45:12 +00:00
|
|
|
func.qbt()
|
2023-10-30 22:02:26 +00:00
|
|
|
bot.polling()
|