TorrentUplouderBot/bot/func.py

104 lines
2.8 KiB
Python
Raw Normal View History

2023-10-30 22:02:43 +00:00
#!/usr/bin/python3
# -- coding: utf-8 --
import db, os, log, subprocess
2023-10-30 22:02:43 +00:00
from db import *
2023-10-31 22:49:17 +00:00
from lang import LANG as msg
2023-10-30 22:02:43 +00:00
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",
f"qbt server info "
2023-10-31 00:45:12 +00:00
]
for command in commands:
os.system(f"bash -c '{command}'")
output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
2023-10-31 00:45:12 +00:00
def u_auth(name,id,passwd):
2023-10-30 22:02:43 +00:00
list = []
if db.check('obj',AUTH_FILE):
list = db.read(AUTH_FILE)
if id in list:
2023-10-31 22:49:17 +00:00
return msg.get('alauth')
2023-10-30 22:02:43 +00:00
else:
if passwd == os.environ['PASS']:
list.append(id)
db.write(list,AUTH_FILE)
log.auth(name,id)
2023-10-31 22:49:17 +00:00
return msg.get('sucauth')
2023-10-30 22:02:43 +00:00
else:
2023-10-31 22:49:17 +00:00
return msg.get('wrauth')
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(name,id,dir,path):
2023-10-30 22:02:43 +00:00
if auth_check(id):
if os.path.exists(path) == False:
2023-10-31 22:49:17 +00:00
return str(msg.get('pne')).format(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)
log.add(name,id,dir,path)
2023-10-31 22:49:17 +00:00
return str(msg.get('fsa')).format(dir)
2023-10-30 22:02:43 +00:00
else:
2023-10-31 22:49:17 +00:00
return msg.get('adeny')
2023-10-30 22:02:43 +00:00
def del_dir(name,id,dir):
2023-10-30 22:02:43 +00:00
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)
log.rm(name,id,dir)
2023-10-31 22:49:17 +00:00
return str(msg.get('frm')).format(dir)
2023-10-30 22:02:43 +00:00
else:
2023-10-31 22:49:17 +00:00
return str(msg.get('fne')).format(dir)
2023-10-30 22:02:43 +00:00
else:
2023-10-31 22:49:17 +00:00
return msg.get('adeny')
2023-10-30 22:02:43 +00:00
def magnet(name,id,link,dir):
2023-10-30 22:02:43 +00:00
if auth_check(id):
2023-10-30 23:03:14 +00:00
dict = db.read(DIR_FILE)
path = dict[dir]
2023-10-31 22:49:17 +00:00
command = f'''qbt torrent add url "{link}" -f "{path}"'''
2023-10-30 23:03:14 +00:00
os.system(f"bash -c '{command}'")
log.addmagnet(name,id,link)
2023-10-31 22:49:17 +00:00
return msg.get('add')
2023-10-30 23:03:14 +00:00
else:
2023-10-31 22:49:17 +00:00
return msg.get('adeny')
2023-10-30 22:02:43 +00:00
def file(name,id,file,dir):
2023-10-30 22:02:43 +00:00
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)
log.addfile(name,id,file)
2023-10-31 22:49:17 +00:00
return msg.get('add')
2023-10-30 23:37:37 +00:00
else:
2023-10-31 22:49:17 +00:00
return msg.get('adeny')
2023-10-30 22:02:43 +00:00
def dirlist():
dirs = {}
if db.check('obj',DIR_FILE):
dirs = db.read(DIR_FILE)
return dirs