diff --git a/Readme.md b/Readme.md index ddb820d..176c135 100644 --- a/Readme.md +++ b/Readme.md @@ -2,45 +2,44 @@ ![](https://cloud.orudo.ru/apps/files_sharing/publicpreview/pgxm2mKT5KHEHFE?file=/&fileId=23795&x=1920&y=1200&a=true&etag=430e9d84364f13b79e42991fede6609a) -## Telegram бот, предназначенный для удаленного добавление загрузок в очередь на qBitTorrent сервер - +## Telegram bot designed to remotely add downloads to the queue on qBitTorrent server | [**git.orudo.ru**](https://git.orudo.ru/OrudoCA/qBitDownload-Bot) | [**GitHub**](https://github.com/OrudoCA/qBitDownload-Bot) | [**DockerHub**](https://hub.docker.com/r/orudoca/qbitdownload-bot) | | ---------------- | ---------- | ------------- | | [![](https://cloud.orudo.ru/apps/files_sharing/publicpreview/AmggNTQWgR6KkyB?file=/&fileId=23836&x=1920&y=1200&a=true&etag=0ef9694cea6e4d85c05aef9be72b927a)](https://git.orudo.ru/OrudoCA/qBitDownload-Bot) | [![](https://cloud.orudo.ru/apps/files_sharing/publicpreview/ip5qtGcwKHMPMAG?file=/&fileId=23819&x=1920&y=1200&a=true&etag=c540068d990ac47217a31f7450afc0ee)](https://github.com/OrudoCA/qBitDownload-Bot) |[![](https://cloud.orudo.ru/apps/files_sharing/publicpreview/7AEeEAzHYikFd5B?file=/&fileId=23806&x=1920&y=1200&a=true&etag=59894ecdfa7aaa6fb832cc4bf99c418d)](https://hub.docker.com/r/orudoca/qbitdownload-bot) | -### Для работы бота требуется [**qBitTorrent**](https://www.qbittorrent.org/) сервер +### Bot requires [**qBitTorrent**](https://www.qbittorrent.org/) server --- -### Текущие фичи: +### Current features: --- -- **Авторизация по паролю** -- **Добавление загрузок в очередь через .torrent файлы / Magnet-ссылки** -- **Добавление/Удаление директорий для загрузок** +- **Authorization by password** +- **Adding downloads to the queue via .torrent files / Magnet-links** +- **Add/Delete download directories** +- **Multiple language support** --- -### В образе используется ["fedarovich/qbittorrent-cli"](https://github.com/fedarovich/qbittorrent-cli) +### Image uses ["fedarovich/qbittorrent-cli"](https://github.com/fedarovich/qbittorrent-cli) --- [![](https://cloud.orudo.ru/apps/files_sharing/publicpreview/rRcdSnCEaA85tWf?file=/&fileId=23784&x=1920&y=1200&a=true&etag=32928842bc4e76adaba194cdd9ec1351)](https://hub.docker.com/r/orudoca/qbitdownload-bot) -## Развертывание через Docker: -#### 1. Соберите образ или склонируйте образ с [Dockerhub](https://hub.docker.com/r/orudoca/qbitdownload-bot) +## Deploy with Docker +#### 1. Build image or clone it from [Dockerhub](https://hub.docker.com/r/orudoca/qbitdownload-bot) -**Склонировать репозиторий и перейти в его директорию** +**Clone a repository and go to its directory** ```bash git clone https://git.orudo.ru/OrudoCA/qBitDownload-Bot.git && cd qBitDownload-Bot ``` -**Сбор образа** +**Build image** ```bash docker build -t . ``` -#### 2. Развернуть через docker-cli или docker-compose - +#### 2. Deploy via docker-cli or docker-compose **Docker-cli** ```bash docker run \ @@ -56,7 +55,7 @@ docker run \ -d your_image_here ``` -##### или +##### or **docker-compose** ```yml diff --git a/bot/bot.py b/bot/bot.py index 90f32dc..0ef6f87 100755 --- a/bot/bot.py +++ b/bot/bot.py @@ -3,6 +3,7 @@ import func, telebot, os from db import PATH +from lang import LANG as msg TOKEN = os.environ["TOKEN"] bot = telebot.TeleBot(TOKEN) @@ -14,15 +15,15 @@ dir = None def welcome(message): id = message.from_user.id if func.auth_check(id): - bot.reply_to(message,'Выберите тип загрузки:',reply_markup=home()) + bot.reply_to(message,str(msg.get('type')),reply_markup=home()) else: - bot.reply_to(message,'Этот бот запривачен, гнида, блять') + bot.reply_to(message,str(msg.get('adeny'))) # Keyboard: Homepage def home(): keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True) - file = telebot.types.KeyboardButton('Файл') - magnet = telebot.types.KeyboardButton('Magnet-ссылка') + file = telebot.types.KeyboardButton(str(msg.get('file'))) + magnet = telebot.types.KeyboardButton(str(msg.get('magnet'))) keyboard.add(file,magnet) return keyboard @@ -31,8 +32,8 @@ def home(): def login(message): id = message.from_user.id passwd = message.text.replace('/login ', '') - f = func.u_auth(id,passwd) - if f == 'Вы успешно авторизировались' or f == 'Вы уже авторизированны': + f = str(func.u_auth(id,passwd)) + if f == str(msg.get('sucauth')) or f == str(msg.get('alauth')): bot.reply_to(message,f,reply_markup=home()) else: bot.reply_to(message,f) @@ -65,9 +66,9 @@ def add(message): if len(txt) == 3: key = txt[1] path = txt[2] - f = func.add_dir(id,key,path) + f = str(func.add_dir(id,key,path)) else: - f = 'Неверные аргументы' + f = str(msg.get('aerr')) bot.reply_to(message,f,reply_markup=home()) # Folder del @@ -79,7 +80,7 @@ def rm(message): bot.reply_to(message,str(f),reply_markup=home()) # Magnet -@bot.message_handler(func=lambda message: message.text == 'Magnet-ссылка') +@bot.message_handler(func=lambda message: message.text == str(msg.get('magnet'))) def magnet(message): id = message.from_user.id if func.auth_check(id): @@ -87,14 +88,14 @@ def magnet(message): type = 'magnet' f = folder_menu() if f == None: - bot.reply_to(message,'Папок не обнаруженно, воспользуйтесь коммандой /add') + bot.reply_to(message,str(msg.get('cff'))) else: - bot.reply_to(message,'Выберите папку:',reply_markup=f) + bot.reply_to(message,str(msg.get('chf')),reply_markup=f) else: - bot.reply_to(message,'Этот бот запривачен, гнида, блять') + bot.reply_to(message,str(msg.get('adeny'))) # File -@bot.message_handler(func=lambda message: message.text == 'Файл') +@bot.message_handler(func=lambda message: message.text == str(msg.get('file'))) def file(message): id = message.from_user.id if func.auth_check(id): @@ -102,11 +103,11 @@ def file(message): type = 'file' f = folder_menu() if f == None: - bot.reply_to(message,'Папок не обнаруженно, воспользуйтесь коммандой /add') + bot.reply_to(message,str(msg.get('cff'))) else: - bot.reply_to(message,'Выберите папку:',reply_markup=f) + bot.reply_to(message,str(msg.get('chf')),reply_markup=f) else: - bot.reply_to(message,'Этот бот запривачен, гнида, блять') + bot.reply_to(message,str(msg.get('adeny'))) # File download @bot.message_handler(content_types=['document']) @@ -122,23 +123,23 @@ def download(message): file_name = os.path.join(PATH, message.document.file_name) with open(file_name, 'wb') as dl: dl.write(file) - f = func.file(id,file_name,dir) + f = str(func.file(id,file_name,dir)) dir, type, folder_list = None,None,[] bot.reply_to(message,f) else: - bot.reply_to(message,'Неверное расширение файла') - bot.reply_to(message,'Выберите тип загрузки:',reply_markup=home()) + bot.reply_to(message,str(msg.get('ntorr'))) + bot.reply_to(message,str(msg.get('type')),reply_markup=home()) else: - bot.reply_to(message,'Этот бот запривачен, гнида, блять') + bot.reply_to(message,str(msg.get('adeny'))) # Dir choose def dirchoose(message): global dir dir = message.text if type == 'magnet': - bot.reply_to(message,'Отправте Magnet-ссылку') + bot.reply_to(message,str(msg.get('sendm'))) if type == 'file': - bot.reply_to(message,'Отправте .torrent файл') + bot.reply_to(message,str(msg.get('sendf'))) # Unknown message @bot.message_handler(func=lambda message: True) @@ -151,12 +152,12 @@ def unknown(message): dirchoose(message) return None if dir != None and type == 'magnet': - f = func.magnet(id,txt,dir) + f = str(func.magnet(id,txt,dir)) dir, type, folder_list = None,None,[] bot.reply_to(message,f) - bot.reply_to(message,'Выберите тип загрузки:',reply_markup=home()) + bot.reply_to(message,str(msg.get('type')),reply_markup=home()) else: - bot.reply_to(message,'Этот бот запривачен, гнида, блять') + bot.reply_to(message,str(msg.get('adeny'))) func.qbt() bot.polling() diff --git a/bot/func.py b/bot/func.py index 18c5283..de33a22 100644 --- a/bot/func.py +++ b/bot/func.py @@ -3,6 +3,7 @@ import db, os from db import * +from lang import LANG as msg def qbt(): url = os.environ['QURL'] @@ -21,14 +22,14 @@ def u_auth(id,passwd): if db.check('obj',AUTH_FILE): list = db.read(AUTH_FILE) if id in list: - return 'Вы уже авторизированны' + return msg.get('alauth') else: if passwd == os.environ['PASS']: list.append(id) db.write(list,AUTH_FILE) - return 'Вы успешно авторизировались' + return msg.get('sucauth') else: - return 'Неверный пароль' + return msg.get('wrauth') def auth_check(id): if db.check('obj',AUTH_FILE): @@ -41,16 +42,16 @@ def auth_check(id): def add_dir(id,dir,path): if auth_check(id): if os.path.exists(path) == False: - return f"Директории '{path}' не сушествует на сервере" + return str(msg.get('pne')).format(path) if db.check('obj',DIR_FILE): dict = db.read(DIR_FILE) else: dict = {} dict.setdefault(dir,path) db.write(dict,DIR_FILE) - return f"Папка {dir} успешно добавлена" + return str(msg.get('fsa')).format(dir) else: - return 'Этот бот запривачен, гнида, блять' + return msg.get('adeny') def del_dir(id,dir): if auth_check(id): @@ -61,11 +62,11 @@ def del_dir(id,dir): if dir in dict: del dict[dir] db.write(dict,DIR_FILE) - return f"Папка {dir} успешно удалена" + return str(msg.get('frm')).format(dir) else: - return f"Папки {dir} не существует" + return str(msg.get('fne')).format(dir) else: - return 'Этот бот запривачен, гнида, блять' + return msg.get('adeny') def magnet(id,link,dir): if auth_check(id): @@ -73,9 +74,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 'Torrent добавлен в очередь' + return msg.get('add') else: - return 'Этот бот запривачен, гнида, блять' + return msg.get('adeny') def file(id,file,dir): if auth_check(id): @@ -84,9 +85,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 'Torrent добавлен в очередь' + return msg.get('add') else: - return 'Этот бот запривачен, гнида, блять' + return msg.get('adeny') def dirlist(): dirs = {} diff --git a/bot/lang.py b/bot/lang.py new file mode 100644 index 0000000..9db759c --- /dev/null +++ b/bot/lang.py @@ -0,0 +1,54 @@ +#!/usr/bin/python3 +# -- coding: utf-8 -- + +import os + +langs = ['ENG','RU'] + +# Russian +RU = { + 'alauth': 'Вы уже авторизированны', + 'sucauth': 'Вы успешно авторизировались', + 'wrauth': 'Неверный пароль', + 'pne': "Директории '{}' не сушествует на сервере", + 'fsa': "Папка '{}' успешно добавлена", + 'frm': "Папка '{}' успешно удалена", + 'fne': "Папки '{}' не существует", + 'add': 'Torrent добавлен в очередь', + 'type': 'Выберите тип загрузки:', + 'magnet': 'Magnet-ссылка', + 'file': 'Файл', + 'aerr': 'Неверные аргументы', + 'cff': 'Папок не обнаруженно, воспользуйтесь коммандой /add', + 'chf': 'Выберите папку:', + 'ntorr': 'Неверное расширение файла', + 'sendm': 'Отправте Magnet-ссылку', + 'sendf': 'Отправте .torrent файл', + 'adeny': 'Этот бот запривачен, гнида, блять' + } + +# English +ENG = { + 'alauth': 'You are already authorized', + 'sucauth': 'You have successfully logged in', + 'wrauth': 'Wrong password', + 'pne': "The '{}' directory does not exist on the server", + 'fsa': "The '{}' folder has been successfully added", + 'frm': "The '{}' folder has been successfully deleted", + 'fne': "The '{}' folder does not exist", + 'add': 'Torrent has been added to the queue', + 'type': 'Select the download type:', + 'magnet': 'Magnet', + 'file': 'File', + 'aerr': 'Wrong arguments', + 'cff': 'No folders found, use the /add command', + 'chf': 'Select folder:', + 'ntorr': 'Incorrect file extension', + 'sendm': 'Send Magnet link', + 'sendf': 'Send .torrent file', + 'adeny': "You do not have access, first authorize '/login '" + } + +for i in langs: + if i == os.environ.get('LANG','ENG'): + LANG = globals()[i] diff --git a/docker-compose.yml b/docker-compose.yml index 8d5a264..562561b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,3 +12,4 @@ services: QURL: ":" QUSER: "" QPASS: "" + LANG: "RU"