4
1
Fork 1
---
- logging system added
- Several bug fixes
This commit is contained in:
trueold89 2023-11-02 22:56:13 +00:00
commit cdd1f37f22
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
6 changed files with 119 additions and 10 deletions

View File

@ -53,7 +53,7 @@ docker run \
-e QUSER="<YOUR_QBIT_USERNAME>" \ -e QUSER="<YOUR_QBIT_USERNAME>" \
-e QPASS="<YOUR_QBIT_PASSWORD>" \ -e QPASS="<YOUR_QBIT_PASSWORD>" \
-e LANG="YOUR_LANG" \ -e LANG="YOUR_LANG" \
-d your_image_here -d -it your_image_here
``` ```
##### or ##### or
@ -63,6 +63,7 @@ docker run \
services: services:
qbitdl_bot: qbitdl_bot:
image: <YOUR_IMAGE_HERE> image: <YOUR_IMAGE_HERE>
tty: true
container_name: qbitdl_bot container_name: qbitdl_bot
volumes: volumes:
- /path/to/config:/etc/bot - /path/to/config:/etc/bot

View File

@ -1,11 +1,11 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -- coding: utf-8 -- # -- coding: utf-8 --
import func, telebot, os import func, telebot, os, log, sys
from db import PATH from db import PATH
from lang import LANG as msg from lang import LANG as msg
TOKEN = os.environ["TOKEN"] TOKEN = os.environ.get('TOKEN','None')
bot = telebot.TeleBot(TOKEN) bot = telebot.TeleBot(TOKEN)
folder_list = [] folder_list = []
dir = None dir = None
@ -159,5 +159,20 @@ def unknown(message):
else: else:
bot.reply_to(message,str(msg.get('adeny'))) bot.reply_to(message,str(msg.get('adeny')))
func.qbt() def run():
bot.polling() if os.path.exists(PATH) == False:
os.mkdir(PATH)
log.start()
try:
func.qbt()
except:
log.errqbt()
sys.exit(1)
try:
bot.polling()
except:
log.errtelebot()
sys.exit(1)
if __name__ == "__main__":
run()

View File

@ -1,7 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -- coding: utf-8 -- # -- coding: utf-8 --
import db, os import db, os, log, subprocess
from db import * from db import *
from lang import LANG as msg from lang import LANG as msg
@ -12,10 +12,12 @@ def qbt():
commands = [ commands = [
f"qbt settings set url {url}", f"qbt settings set url {url}",
f"qbt settings set username {username}", f"qbt settings set username {username}",
f"echo {password} | qbt settings set password --no-warn" f"echo {password} | qbt settings set password --no-warn",
f"qbt server info "
] ]
for command in commands: for command in commands:
os.system(f"bash -c '{command}'") os.system(f"bash -c '{command}'")
output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
def u_auth(id,passwd): def u_auth(id,passwd):
list = [] list = []
@ -27,6 +29,7 @@ def u_auth(id,passwd):
if passwd == os.environ['PASS']: if passwd == os.environ['PASS']:
list.append(id) list.append(id)
db.write(list,AUTH_FILE) db.write(list,AUTH_FILE)
log.auth(id)
return msg.get('sucauth') return msg.get('sucauth')
else: else:
return msg.get('wrauth') return msg.get('wrauth')
@ -49,6 +52,7 @@ def add_dir(id,dir,path):
dict = {} dict = {}
dict.setdefault(dir,path) dict.setdefault(dir,path)
db.write(dict,DIR_FILE) db.write(dict,DIR_FILE)
log.add(id,dir,path)
return str(msg.get('fsa')).format(dir) return str(msg.get('fsa')).format(dir)
else: else:
return msg.get('adeny') return msg.get('adeny')
@ -62,6 +66,7 @@ def del_dir(id,dir):
if dir in dict: if dir in dict:
del dict[dir] del dict[dir]
db.write(dict,DIR_FILE) db.write(dict,DIR_FILE)
log.rm(id,dir)
return str(msg.get('frm')).format(dir) return str(msg.get('frm')).format(dir)
else: else:
return str(msg.get('fne')).format(dir) return str(msg.get('fne')).format(dir)
@ -74,6 +79,7 @@ def magnet(id,link,dir):
path = dict[dir] path = dict[dir]
command = f'''qbt torrent add url "{link}" -f "{path}"''' command = f'''qbt torrent add url "{link}" -f "{path}"'''
os.system(f"bash -c '{command}'") os.system(f"bash -c '{command}'")
log.addmagnet(id,link)
return msg.get('add') return msg.get('add')
else: else:
return msg.get('adeny') return msg.get('adeny')
@ -85,6 +91,7 @@ def file(id,file,dir):
command = f'''qbt torrent add file "{file}" -f {path}''' command = f'''qbt torrent add file "{file}" -f {path}'''
os.system(f"bash -c '{command}'") os.system(f"bash -c '{command}'")
os.remove(file) os.remove(file)
log.addfile(id,file)
return msg.get('add') return msg.get('add')
else: else:
return msg.get('adeny') return msg.get('adeny')

View File

@ -24,7 +24,17 @@ RU = {
'ntorr': 'Неверное расширение файла', 'ntorr': 'Неверное расширение файла',
'sendm': 'Отправте Magnet-ссылку', 'sendm': 'Отправте Magnet-ссылку',
'sendf': 'Отправте .torrent файл', 'sendf': 'Отправте .torrent файл',
'adeny': 'Этот бот запривачен, гнида, блять' 'adeny': 'Этот бот запривачен, гнида, блять',
# Logs
'l_create': "Log Файл '{}' создан",
'l_start': 'Запуск бота...',
'l_auth': "Пользователь '{}' успешно авторизировался",
'l_add': "Пользователь '{}' добавил папку '{}' по пути '{}'",
'l_rm': "Пользователь '{}' удалил папку '{}'",
'l_file': "Пользователь '{}' добавил в очередь файл '{}'",
'l_magnet': "Пользователь '{}' добавил в очередь ссылку '{}'",
'l_errqbt': "Ошибка подключения к qBitTorrent",
'l_errtele': "Ошибка подключения к Telegram API, проверьте ваш токен",
} }
# English # English
@ -46,7 +56,17 @@ ENG = {
'ntorr': 'Incorrect file extension', 'ntorr': 'Incorrect file extension',
'sendm': 'Send Magnet link', 'sendm': 'Send Magnet link',
'sendf': 'Send .torrent file', 'sendf': 'Send .torrent file',
'adeny': "You do not have access, first authorize '/login <password>'" 'adeny': "You do not have access, first authorize '/login <password>'",
# Logs
'l_create': "Log File '{}' created",
'l_start': 'Start bot polling...',
'l_auth': "User '{}' successfully authorized",
'l_add': "User '{}' added a folder '{}' with the path '{}'",
'l_rm': "User '{}' deleted '{}' folder",
'l_file': "User '{}' added file '{}' to the queue",
'l_magnet': "User '{}' added the link '{}' to the queue",
'l_errqbt': "Error connecting to qBitTorrent",
'l_errtele': "Error connecting to Telegram API, check your token"
} }
for i in langs: for i in langs:

65
bot/log.py Normal file
View File

@ -0,0 +1,65 @@
#!/usr/bin/python3
# -- coding: utf-8 --
import os, uuid
from datetime import datetime
from lang import LANG as msg
from db import PATH
def dt():
date = datetime.now().date()
time = datetime.now().time()
str = f'{date} | {time.strftime("%H:%M:%S")}'
return str
DEFAULT = f'{dt()} LOG: '
ID = str(uuid.uuid1())[0:7]
FILE = f'{ID}.txt'
def file(log):
if os.path.exists(f'{PATH}logs') == False:
os.mkdir(f'{PATH}logs')
with open(f'{PATH}logs/{FILE}','a') as logfile:
logfile.write(f'{log}\n')
logfile.close()
def start():
log1 = DEFAULT + str(msg.get('l_create').format(FILE))
log2 = DEFAULT + str(msg.get('l_start'))
file(log2)
print(f'{log1}\n{log2}')
def auth(id):
log = DEFAULT + str(msg.get('l_auth').format(id))
file(log)
print(log)
def add(id,folder,path):
log = DEFAULT + str(msg.get('l_add').format(id,folder,path))
file(log)
print(log)
def rm(id,folder):
log = DEFAULT + str(msg.get('l_rm').format(id,folder))
file(log)
print(log)
def addfile(id,filename):
log = DEFAULT + str(msg.get('l_file').format(id,filename[9:]))
file(log)
print(log)
def addmagnet(id,link):
log = DEFAULT + str(msg.get('l_magnet').format(id,link))
file(log)
print(log)
def errqbt():
log = DEFAULT + str(msg.get('l_errqbt'))
file(log)
print(log)
def errtelebot():
log = DEFAULT + str(msg.get('l_errtele'))
file(log)
print(log)

View File

@ -1,6 +1,7 @@
services: services:
qbitdl_bot: qbitdl_bot:
image: <YOUR_IMAGE_HERE> image: <YOUR_IMAGE_HERE>
tty: true
container_name: qbitdl_bot container_name: qbitdl_bot
volumes: volumes:
- /path/to/config:/etc/bot - /path/to/config:/etc/bot
@ -12,4 +13,4 @@ services:
QURL: "<http://<YOUR_QBIT_SERVER_IP_HERE>:<PORT>" QURL: "<http://<YOUR_QBIT_SERVER_IP_HERE>:<PORT>"
QUSER: "<YOUR_QBIT_USERNAME>" QUSER: "<YOUR_QBIT_USERNAME>"
QPASS: "<YOUR_QBIT_PASSWORD>" QPASS: "<YOUR_QBIT_PASSWORD>"
LANG: "RU" LANG: "<YOUR_LANG>"