forked from OrudoCA/qBitDownload-Bot
Add connection check && some little fixes
This commit is contained in:
parent
d951b22056
commit
e0345df54e
20
bot/bot.py
20
bot/bot.py
|
@ -1,11 +1,11 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -- coding: utf-8 --
|
# -- coding: utf-8 --
|
||||||
|
|
||||||
import func, telebot, os, log
|
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,6 +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():
|
||||||
|
if os.path.exists(PATH) == False:
|
||||||
|
os.mkdir(PATH)
|
||||||
log.start()
|
log.start()
|
||||||
|
try:
|
||||||
|
func.qbt()
|
||||||
|
except:
|
||||||
|
log.errqbt()
|
||||||
|
sys.exit(1)
|
||||||
|
try:
|
||||||
bot.polling()
|
bot.polling()
|
||||||
|
except:
|
||||||
|
log.errtelebot()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -- coding: utf-8 --
|
# -- coding: utf-8 --
|
||||||
|
|
||||||
import db, os, log
|
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 = []
|
||||||
|
|
12
bot/lang.py
12
bot/lang.py
|
@ -27,12 +27,14 @@ RU = {
|
||||||
'adeny': 'Этот бот запривачен, гнида, блять',
|
'adeny': 'Этот бот запривачен, гнида, блять',
|
||||||
# Logs
|
# Logs
|
||||||
'l_create': "Log Файл '{}' создан",
|
'l_create': "Log Файл '{}' создан",
|
||||||
'l_start': 'Бот готов к работе',
|
'l_start': 'Запуск бота...',
|
||||||
'l_auth': "Пользователь '{}' успешно авторизировался",
|
'l_auth': "Пользователь '{}' успешно авторизировался",
|
||||||
'l_add': "Пользователь '{}' добавил папку '{}' по пути '{}'",
|
'l_add': "Пользователь '{}' добавил папку '{}' по пути '{}'",
|
||||||
'l_rm': "Пользователь '{}' удалил папку '{}'",
|
'l_rm': "Пользователь '{}' удалил папку '{}'",
|
||||||
'l_file': "Пользователь '{}' добавил в очередь файл '{}'",
|
'l_file': "Пользователь '{}' добавил в очередь файл '{}'",
|
||||||
'l_magnet': "Пользователь '{}' добавил в очередь ссылку '{}'"
|
'l_magnet': "Пользователь '{}' добавил в очередь ссылку '{}'",
|
||||||
|
'l_errqbt': "Ошибка подключения к qBitTorrent",
|
||||||
|
'l_errtele': "Ошибка подключения к Telegram API, проверьте ваш токен",
|
||||||
}
|
}
|
||||||
|
|
||||||
# English
|
# English
|
||||||
|
@ -57,12 +59,14 @@ ENG = {
|
||||||
'adeny': "You do not have access, first authorize '/login <password>'",
|
'adeny': "You do not have access, first authorize '/login <password>'",
|
||||||
# Logs
|
# Logs
|
||||||
'l_create': "Log File '{}' created",
|
'l_create': "Log File '{}' created",
|
||||||
'l_start': 'Bot is up and running',
|
'l_start': 'Start bot polling...',
|
||||||
'l_auth': "User '{}' successfully authorized",
|
'l_auth': "User '{}' successfully authorized",
|
||||||
'l_add': "User '{}' added a folder '{}' with the path '{}'",
|
'l_add': "User '{}' added a folder '{}' with the path '{}'",
|
||||||
'l_rm': "User '{}' deleted '{}' folder",
|
'l_rm': "User '{}' deleted '{}' folder",
|
||||||
'l_file': "User '{}' added file '{}' to the queue",
|
'l_file': "User '{}' added file '{}' to the queue",
|
||||||
'l_magnet': "User '{}' added the link '{}' 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:
|
||||||
|
|
10
bot/log.py
10
bot/log.py
|
@ -53,3 +53,13 @@ def addmagnet(id,link):
|
||||||
log = DEFAULT + str(msg.get('l_magnet').format(id,link))
|
log = DEFAULT + str(msg.get('l_magnet').format(id,link))
|
||||||
file(log)
|
file(log)
|
||||||
print(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)
|
||||||
|
|
|
@ -12,4 +12,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>"
|
||||||
|
|
Loading…
Reference in New Issue