4
1
Fork 1

Set Russian as main language && bugfix

This commit is contained in:
trueold89 2023-10-31 02:59:17 +03:00
parent 5a4fb2279d
commit ae8005b7e9
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
2 changed files with 35 additions and 34 deletions

43
bot.py
View File

@ -7,21 +7,22 @@ from db import PATH
TOKEN = os.environ["TOKEN"]
bot = telebot.TeleBot(TOKEN)
folder_list = []
dir = None
# Start
@bot.message_handler(commands=['start'])
def welcome(message):
id = message.from_user.id
if func.auth_check(id):
bot.reply_to(message,'Choose download type:',reply_markup=home())
bot.reply_to(message,'Выберите тип загрузки:',reply_markup=home())
else:
bot.reply_to(message,'Log in to use bot /login <passwd>')
bot.reply_to(message,'Этот бот запривачен, гнида, блять')
# Keyboard: Homepage
def home():
keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
file = telebot.types.KeyboardButton('File')
magnet = telebot.types.KeyboardButton('MagnetLink')
file = telebot.types.KeyboardButton('Файл')
magnet = telebot.types.KeyboardButton('Magnet-ссылка')
keyboard.add(file,magnet)
return keyboard
@ -31,7 +32,7 @@ def login(message):
id = message.from_user.id
passwd = message.text.replace('/login ', '')
f = func.u_auth(id,passwd)
if f == 'Success' or f == 'You already logged in':
if f == 'Вы успешно авторизировались' or f == 'Вы уже авторизированны':
bot.reply_to(message,f,reply_markup=home())
else:
bot.reply_to(message,f)
@ -66,7 +67,7 @@ def add(message):
path = txt[2]
f = func.add_dir(id,key,path)
else:
f = 'Invalid args'
f = 'Неверные аргументы'
bot.reply_to(message,f,reply_markup=home())
# Folder del
@ -78,7 +79,7 @@ def rm(message):
bot.reply_to(message,str(f),reply_markup=home())
# Magnet
@bot.message_handler(func=lambda message: message.text == 'MagnetLink')
@bot.message_handler(func=lambda message: message.text == 'Magnet-ссылка')
def magnet(message):
id = message.from_user.id
if func.auth_check(id):
@ -86,14 +87,14 @@ def magnet(message):
type = 'magnet'
f = folder_menu()
if f == None:
bot.reply_to(message,'No folders, use /add <folder_name> <path>')
bot.reply_to(message,'Папок не обнаруженно, воспользуйтесь коммандой /add')
else:
bot.reply_to(message,'Choose dir:',reply_markup=f)
bot.reply_to(message,'Выберите папку:',reply_markup=f)
else:
bot.reply_to(message,'Log in to use bot /login <passwd>')
bot.reply_to(message,'Этот бот запривачен, гнида, блять')
# File
@bot.message_handler(func=lambda message: message.text == 'File')
@bot.message_handler(func=lambda message: message.text == 'Файл')
def file(message):
id = message.from_user.id
if func.auth_check(id):
@ -101,11 +102,11 @@ def file(message):
type = 'file'
f = folder_menu()
if f == None:
bot.reply_to(message,'No folders, use /add <folder_name> <path>')
bot.reply_to(message,'Папок не обнаруженно, воспользуйтесь коммандой /add')
else:
bot.reply_to(message,'Choose dir:',reply_markup=f)
bot.reply_to(message,'Выберите папку:',reply_markup=f)
else:
bot.reply_to(message,'Log in to use bot /login <passwd>')
bot.reply_to(message,'Этот бот запривачен, гнида, блять')
# File download
@bot.message_handler(content_types=['document'])
@ -125,19 +126,19 @@ def download(message):
dir, type, folder_list = None,None,[]
bot.reply_to(message,f)
else:
bot.reply_to(message,'Send .torrent file')
bot.reply_to(message,'Choose download type:',reply_markup=home())
bot.reply_to(message,'Неверное расширение файла')
bot.reply_to(message,'Выберите тип загрузки:',reply_markup=home())
else:
bot.reply_to(message,'Log in to use bot /login <passwd>')
bot.reply_to(message,'Этот бот запривачен, гнида, блять')
# Dir choose
def dirchoose(message):
global dir
dir = message.text
if type == 'magnet':
bot.reply_to(message,'Send magnet link')
bot.reply_to(message,'Отправте Magnet-ссылку')
if type == 'file':
bot.reply_to(message,'Send .torrent file')
bot.reply_to(message,'Отправте .torrent файл')
# Unknown message
@bot.message_handler(func=lambda message: True)
@ -153,8 +154,8 @@ def unknown(message):
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,'Выберите тип загрузки:',reply_markup=home())
else:
bot.reply_to(message,'Log in to use bot /login <passwd>')
bot.reply_to(message,'Этот бот запривачен, гнида, блять')
bot.polling()

26
func.py
View File

@ -9,14 +9,14 @@ def u_auth(id,passwd):
if db.check('obj',AUTH_FILE):
list = db.read(AUTH_FILE)
if id in list:
return 'You already logged in'
return 'Вы уже авторизированны'
else:
if passwd == os.environ['PASS']:
list.append(id)
db.write(list,AUTH_FILE)
return 'Success'
return 'Вы успешно авторизировались'
else:
return 'Wrong password'
return 'Неверный пароль'
def auth_check(id):
if db.check('obj',AUTH_FILE):
@ -29,16 +29,16 @@ def auth_check(id):
def add_dir(id,dir,path):
if auth_check(id):
if os.path.exists(path) == False:
return 'Folder not exist on host'
return f"Директории '{path}' не сушествует на сервере"
if db.check('obj',DIR_FILE):
dict = db.read(DIR_FILE)
else:
dict = {}
dict.setdefault(dir,path)
db.write(dict,DIR_FILE)
return 'Success'
return f"Папка {dir} успешно добавлена"
else:
return 'Log in first'
return 'Этот бот запривачен, гнида, блять'
def del_dir(id,dir):
if auth_check(id):
@ -49,11 +49,11 @@ def del_dir(id,dir):
if dir in dict:
del dict[dir]
db.write(dict,DIR_FILE)
return 'Success'
return f"Папка {dir} успешно удалена"
else:
return 'Dir not exists'
return f"Папки {dir} не существует"
else:
return 'Log in first'
return 'Этот бот запривачен, гнида, блять'
def magnet(id,link,dir):
if auth_check(id):
@ -61,9 +61,9 @@ def magnet(id,link,dir):
path = dict[dir]
command = f'''qbt torrent add url "{link} -f {path}"'''
os.system(f"bash -c '{command}'")
return 'Success'
return 'Torrent добавлен в очередь'
else:
return 'Log in first'
return 'Этот бот запривачен, гнида, блять'
def file(id,file,dir):
if auth_check(id):
@ -72,9 +72,9 @@ def file(id,file,dir):
command = f'''qbt torrent add file "{file}" -f {path}'''
os.system(f"bash -c '{command}'")
os.remove(file)
return 'Success'
return 'Torrent добавлен в очередь'
else:
return 'Log in first'
return 'Этот бот запривачен, гнида, блять'
def dirlist():
dirs = {}