TorrentUplouderBot/bot/func.py

96 lines
2.8 KiB
Python
Raw Normal View History

2023-10-30 22:02:43 +00:00
#!/usr/bin/python3
# -- coding: utf-8 --
2023-10-30 23:37:37 +00:00
import db, os
2023-10-30 22:02:43 +00:00
from db import *
2023-10-31 00:45:12 +00:00
def qbt():
url = os.environ['QURL']
username = os.environ['QUSER']
password = os.environ['QPASS']
commands = [
f"qbt settings set url {url}",
f"qbt settings set username {username}",
f"echo {password} | qbt settings set password --no-warn"
]
for command in commands:
os.system(f"bash -c '{command}'")
2023-10-30 22:02:43 +00:00
def u_auth(id,passwd):
list = []
if db.check('obj',AUTH_FILE):
list = db.read(AUTH_FILE)
if id in list:
2023-10-30 23:59:17 +00:00
return 'Вы уже авторизированны'
2023-10-30 22:02:43 +00:00
else:
if passwd == os.environ['PASS']:
list.append(id)
db.write(list,AUTH_FILE)
2023-10-30 23:59:17 +00:00
return 'Вы успешно авторизировались'
2023-10-30 22:02:43 +00:00
else:
2023-10-30 23:59:17 +00:00
return 'Неверный пароль'
2023-10-30 22:02:43 +00:00
def auth_check(id):
if db.check('obj',AUTH_FILE):
list = db.read(AUTH_FILE)
else:
list = []
if id in list:
return True
def add_dir(id,dir,path):
if auth_check(id):
if os.path.exists(path) == False:
2023-10-30 23:59:17 +00:00
return f"Директории '{path}' не сушествует на сервере"
2023-10-30 22:02:43 +00:00
if db.check('obj',DIR_FILE):
dict = db.read(DIR_FILE)
else:
dict = {}
dict.setdefault(dir,path)
db.write(dict,DIR_FILE)
2023-10-30 23:59:17 +00:00
return f"Папка {dir} успешно добавлена"
2023-10-30 22:02:43 +00:00
else:
2023-10-30 23:59:17 +00:00
return 'Этот бот запривачен, гнида, блять'
2023-10-30 22:02:43 +00:00
def del_dir(id,dir):
if auth_check(id):
if db.check('obj',DIR_FILE):
dict = db.read(DIR_FILE)
else:
dict = {}
if dir in dict:
del dict[dir]
db.write(dict,DIR_FILE)
2023-10-30 23:59:17 +00:00
return f"Папка {dir} успешно удалена"
2023-10-30 22:02:43 +00:00
else:
2023-10-30 23:59:17 +00:00
return f"Папки {dir} не существует"
2023-10-30 22:02:43 +00:00
else:
2023-10-30 23:59:17 +00:00
return 'Этот бот запривачен, гнида, блять'
2023-10-30 22:02:43 +00:00
def magnet(id,link,dir):
if auth_check(id):
2023-10-30 23:03:14 +00:00
dict = db.read(DIR_FILE)
path = dict[dir]
command = f'''qbt torrent add url "{link} -f {path}"'''
os.system(f"bash -c '{command}'")
2023-10-30 23:59:17 +00:00
return 'Torrent добавлен в очередь'
2023-10-30 23:03:14 +00:00
else:
2023-10-30 23:59:17 +00:00
return 'Этот бот запривачен, гнида, блять'
2023-10-30 22:02:43 +00:00
def file(id,file,dir):
if auth_check(id):
2023-10-30 23:37:37 +00:00
dict = db.read(DIR_FILE)
path = dict[dir]
command = f'''qbt torrent add file "{file}" -f {path}'''
os.system(f"bash -c '{command}'")
os.remove(file)
2023-10-30 23:59:17 +00:00
return 'Torrent добавлен в очередь'
2023-10-30 23:37:37 +00:00
else:
2023-10-30 23:59:17 +00:00
return 'Этот бот запривачен, гнида, блять'
2023-10-30 22:02:43 +00:00
def dirlist():
dirs = {}
if db.check('obj',DIR_FILE):
dirs = db.read(DIR_FILE)
return dirs