From ccda460088b781e80a60627443b28eefd8055883 Mon Sep 17 00:00:00 2001 From: ovin Date: Thu, 26 Aug 2021 15:19:38 +0700 Subject: [PATCH] v4.9.1 - Change docker name - Use qbittorrent config file - Fixing Co-authored-by: anas --- Dockerfile | 3 +- README.md | 12 +- alive.py | 8 - aria.sh | 2 +- bot/__init__.py | 35 +-- bot/__main__.py | 9 +- bot/helper/__init__.py | 24 -- .../download_utils/qbit_downloader.py | 4 +- bot/helper/telegram_helper/bot_commands.py | 1 - bot/modules/config.py | 221 ------------------ bot/modules/reboot.py | 14 ++ bot/modules/updates.py | 99 -------- config_sample.env | 8 +- qBittorrent.conf | 51 ++++ start.sh | 2 +- wserver.py | 2 +- 16 files changed, 103 insertions(+), 392 deletions(-) delete mode 100644 bot/modules/config.py create mode 100644 bot/modules/reboot.py delete mode 100644 bot/modules/updates.py create mode 100644 qBittorrent.conf diff --git a/Dockerfile b/Dockerfile index a2526465..cfbf047c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM vincreator/eunha-sdk-python:latest +FROM vincreator/eunhamirror:latest WORKDIR /usr/src/app RUN chmod 777 /usr/src/app @@ -10,6 +10,7 @@ COPY extract /usr/local/bin COPY pextract /usr/local/bin RUN chmod +x /usr/local/bin/extract && chmod +x /usr/local/bin/pextract COPY . . +COPY qBittorrent.conf ./.config/qBittorrent/qBittorrent.conf COPY .netrc /root/.netrc RUN chmod 600 /usr/src/app/.netrc RUN chmod +x aria.sh diff --git a/README.md b/README.md index fe555814..1998d177 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,10 @@ sudo apt install python3 ``` Install Docker by following the [official Docker docs](https://docs.docker.com/engine/install/debian/) +OR +``` +sudo snap install docker +``` - For Arch and it's derivatives: ``` sudo pacman -S docker python @@ -160,8 +164,6 @@ Fill up rest of the fields. Meaning of each fields are discussed below: - **DOWNLOAD_DIR**: The path to the local folder where the downloads should be downloaded to - **DOWNLOAD_STATUS_UPDATE_INTERVAL**: A short interval of time in seconds after which the Mirror progress message is updated. (I recommend to keep it `5` seconds at least) - **AUTO_DELETE_MESSAGE_DURATION**: Interval of time (in seconds), after which the bot deletes it's message (and command message) which is expected to be viewed instantly. (**Note**: Set to `-1` to never automatically delete messages) -- **UPSTREAM_REPO**: Link for Bot Upstream Repo, if you want default update, fill `https://github.com/vincreator/Eunha-Mirror-bot`. -- **UPSTREAM_BRANCH**: Branch name for Bot Upstream Repo, fill `master`. ### Optional Field - **ACCOUNTS_ZIP_URL**: Only if you want to load your Service Account externally from an Index Link. Archive your Service Account json files to a zip file directly (don't archive the accounts folder. Select all the jsons inside and zip them only instead. Name the zip file with whatever you want, it doesn't matter). Fill this with the direct link of that file. - **TOKEN_PICKLE_URL**: Only if you want to load your **token.pickle** externally from an Index Link. Fill this with the direct link of that file. @@ -188,9 +190,9 @@ Fill up rest of the fields. Meaning of each fields are discussed below: - **HEROKU_APP_NAME**: (Only if you deploying on Heroku) Your Heroku app name. - **IGNORE_PENDING_REQUESTS**: If you want the bot to ignore pending requests after it restarts, set this to `True`. - **STATUS_LIMIT**: Status limit with buttons (**NOTE**: Recommend limit status to `4` tasks max). -- **IS_VPS**: Set it to `True` if you use VPS -- **SERVER_PORT**: Your VPS port -- **BASE_URL_OF_BOT**: Valid BASE URL of where the bot is deploy. Ip/domain of your bot like `http://myip` or if you have chosen other port then `80` then `http://myip:port`. No slash at the end, for Heroku fill `https://yourappname.herokuapp.com`. +- **IS_VPS**: (Only for VPS) Don't set this to `True` even if you are using vps, unless facing error with web server. Also go to start.sh and replace `$PORT` by `80` or any port you want to use. +- **SERVER_PORT**: (Only if IS_VPS is `True`) Base URL Port +- **BASE_URL_OF_BOT**: (Required for Heroku) Valid BASE URL of where the bot is deploy. Ip/domain of your bot like `http://myip` or if you have chosen other port then `80` then `http://myip:port`, for Heroku fill `https://yourappname.herokuapp.com` (**NOTE**: No slash at the end) - **SHORTENER_API**: Fill your Shortener api key if you are using Shortener. - **SHORTENER**: if you want to use Shortener in Gdrive and index link, fill Shortener url here. Examples: ``` diff --git a/alive.py b/alive.py index 4e4f8fd7..7b33aafb 100644 --- a/alive.py +++ b/alive.py @@ -5,14 +5,6 @@ import time import requests import os -import subprocess -from dotenv import load_dotenv - -CONFIG_FILE_URL = os.environ.get('CONFIG_FILE_URL', None) -if CONFIG_FILE_URL is not None: - out = subprocess.run(["wget", "-q", "-O", "config.env", CONFIG_FILE_URL]) - -load_dotenv('config.env') BASE_URL = os.environ.get('BASE_URL_OF_BOT', None) if len(BASE_URL) == 0: diff --git a/aria.sh b/aria.sh index 792c36c4..99e4aa4c 100755 --- a/aria.sh +++ b/aria.sh @@ -1,7 +1,7 @@ tracker_list=$(curl -Ns https://raw.githubusercontent.com/XIU2/TrackersListCollection/master/all.txt https://ngosang.github.io/trackerslist/trackers_all_http.txt https://newtrackon.com/api/all https://raw.githubusercontent.com/DeSireFire/animeTrackerList/master/AT_all.txt https://raw.githubusercontent.com/hezhijie0327/Trackerslist/main/trackerslist_tracker.txt https://raw.githubusercontent.com/hezhijie0327/Trackerslist/main/trackerslist_exclude.txt | awk '$0' | tr '\n\n' ',') aria2c --enable-rpc --check-certificate=false \ --max-connection-per-server=10 --rpc-max-request-size=1024M --bt-max-peers=0 \ - --bt-stop-timeout=1200 --min-split-size=10M --follow-torrent=mem --split=10 \ + --bt-stop-timeout=0 --min-split-size=10M --follow-torrent=mem --split=10 \ --daemon=true --allow-overwrite=true --max-overall-download-limit=0 --bt-tracker="[$tracker_list]"\ --max-overall-upload-limit=1K --max-concurrent-downloads=15 --continue=true \ --peer-id-prefix=-qB4360- --user-agent=qBittorrent/4.3.6 --peer-agent=qBittorrent/4.3.6 \ diff --git a/bot/__init__.py b/bot/__init__.py index bb4f3e89..b670c34c 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -33,8 +33,16 @@ LOGGER = logging.getLogger(__name__) +CONFIG_FILE_URL = os.environ.get('CONFIG_FILE_URL', None) +if CONFIG_FILE_URL is not None: + out = subprocess.run(["wget", "-q", "-O", "config.env", CONFIG_FILE_URL]) + if out.returncode != 0: + logging.error(out) + load_dotenv('config.env') +alive = subprocess.Popen(["python3", "alive.py"]) + Interval = [] @@ -73,7 +81,7 @@ def get_client() -> qba.TorrentsAPIMixIn: qb_client = qba.Client(host="localhost", port=8090, username="admin", password="adminadmin") try: qb_client.auth_log_in() - qb_client.application.set_preferences({"disk_cache":64, "incomplete_files_ext":True, "max_connec":3000, "max_connec_per_torrent":300, "async_io_threads":32, "preallocate_all":True, "upnp":True, "dl_limit":-1, "up_limit":-1, "dht":True, "pex":True, "lsd":True, "encryption":0, "queueing_enabled":True, "max_active_downloads":15, "max_active_torrents":50, "dont_count_slow_torrents":True, "bittorrent_protocol":0, "recheck_completed_torrents":True, "enable_multi_connections_from_same_ip":True, "slow_torrent_dl_rate_threshold":100,"slow_torrent_inactive_timer":600}) + #qb_client.application.set_preferences({"disk_cache":64, "incomplete_files_ext":True, "max_connec":3000, "max_connec_per_torrent":300, "async_io_threads":8, "preallocate_all":True, "upnp":True, "dl_limit":-1, "up_limit":-1, "dht":True, "pex":True, "lsd":True, "encryption":0, "queueing_enabled":True, "max_active_downloads":15, "max_active_torrents":50, "dont_count_slow_torrents":True, "bittorrent_protocol":0, "recheck_completed_torrents":True, "enable_multi_connections_from_same_ip":True, "slow_torrent_dl_rate_threshold":100,"slow_torrent_inactive_timer":600}) return qb_client except qba.LoginFailed as e: LOGGER.error(str(e)) @@ -129,8 +137,6 @@ def get_client() -> qba.TorrentsAPIMixIn: AUTO_DELETE_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_MESSAGE_DURATION')) TELEGRAM_API = getConfig('TELEGRAM_API') TELEGRAM_HASH = getConfig('TELEGRAM_HASH') - UPSTREAM_REPO = getConfig('UPSTREAM_REPO') - UPSTREAM_BRANCH = getConfig('UPSTREAM_BRANCH') except KeyError as e: LOGGER.error("One or more env variables missing! Exiting now") exit(1) @@ -196,13 +202,12 @@ def get_client() -> qba.TorrentsAPIMixIn: MEGA_PASSWORD = None try: HEROKU_API_KEY = getConfig('HEROKU_API_KEY') -except KeyError: - logging.warning('HEROKU API KEY not provided!') - HEROKU_API_KEY = None -try: HEROKU_APP_NAME = getConfig('HEROKU_APP_NAME') + if len(HEROKU_API_KEY) == 0 or len(HEROKU_APP_NAME) == 0: + HEROKU_API_KEY = None + HEROKU_APP_NAME = None except KeyError: - logging.warning('HEROKU APP NAME not provided!') + HEROKU_API_KEY = None HEROKU_APP_NAME = None try: UPTOBOX_TOKEN = getConfig('UPTOBOX_TOKEN') @@ -319,14 +324,14 @@ def get_client() -> qba.TorrentsAPIMixIn: except KeyError: SHORTENER = None SHORTENER_API = None - -IGNORE_PENDING_REQUESTS = False try: - if getConfig("IGNORE_PENDING_REQUESTS").lower() == "true": + IGNORE_PENDING_REQUESTS = getConfig("IGNORE_PENDING_REQUESTS") + if IGNORE_PENDING_REQUESTS.lower() == 'true': IGNORE_PENDING_REQUESTS = True + else: + IGNORE_PENDING_REQUESTS = False except KeyError: - pass - + IGNORE_PENDING_REQUESTS = False try: BASE_URL = getConfig('BASE_URL_OF_BOT') if len(BASE_URL) == 0: @@ -334,7 +339,6 @@ def get_client() -> qba.TorrentsAPIMixIn: except KeyError: logging.warning('BASE_URL_OF_BOT not provided!') BASE_URL = None - try: IS_VPS = getConfig('IS_VPS') if IS_VPS.lower() == 'true': @@ -343,7 +347,6 @@ def get_client() -> qba.TorrentsAPIMixIn: IS_VPS = False except KeyError: IS_VPS = False - try: SERVER_PORT = getConfig('SERVER_PORT') if len(SERVER_PORT) == 0: @@ -351,7 +354,6 @@ def get_client() -> qba.TorrentsAPIMixIn: except KeyError: logging.warning('SERVER_PORT not provided!') SERVER_PORT = None - try: TOKEN_PICKLE_URL = getConfig('TOKEN_PICKLE_URL') if len(TOKEN_PICKLE_URL) == 0: @@ -362,7 +364,6 @@ def get_client() -> qba.TorrentsAPIMixIn: logging.error(out) except KeyError: TOKEN_PICKLE_URL = None - try: ACCOUNTS_ZIP_URL = getConfig('ACCOUNTS_ZIP_URL') if len(ACCOUNTS_ZIP_URL) == 0: diff --git a/bot/__main__.py b/bot/__main__.py index 4cf53d31..3e99f1f3 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -3,7 +3,7 @@ import os from pyrogram import idle -from bot import app +from bot import app, alive from sys import executable from telegram import ParseMode @@ -15,7 +15,7 @@ from .helper.ext_utils.bot_utils import get_readable_file_size, get_readable_time from .helper.telegram_helper.filters import CustomFilters from bot.helper.telegram_helper import button_build -from .modules import authorize, list, cancel_mirror, mirror_status, mirror, clone, watch, shell, eval, torrent_search, delete, speedtest, count, config, updates +from .modules import authorize, list, cancel_mirror, mirror_status, mirror, clone, watch, shell, eval, torrent_search, delete, speedtest, count, reboot def stats(update, context): @@ -68,6 +68,7 @@ def restart(update, context): f.truncate(0) f.write(f"{restart_message.chat.id}\n{restart_message.message_id}\n") fs_utils.clean_all() + alive.terminate() os.execl(executable, executable, "-m", "bot") @@ -130,10 +131,6 @@ def bot_help(update, context): /{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports -/{BotCommands.ConfigMenuCommand}: Get Info Menu about bot config (Owner Only) - -/{BotCommands.UpdateCommand}: Update Bot from Upstream Repo (Owner Only) - /{BotCommands.SpeedCommand}: Check Internet Speed of the Host /{BotCommands.ShellCommand}: Run commands in Shell (Terminal) diff --git a/bot/helper/__init__.py b/bot/helper/__init__.py index 26eb8cff..ff0cf2c5 100644 --- a/bot/helper/__init__.py +++ b/bot/helper/__init__.py @@ -28,27 +28,3 @@ async def heroku_cli(client, message): await func(client, message, heroku_app) return heroku_cli - -# Preparing For Update Bot -# Implement by https://github.com/jusidama18 and Based on this https://github.com/DevsExpo/FridayUserbot/blob/master/plugins/updater.py - -def fetch_heroku_git_url(api_key, app_name): - if not api_key: - return None - if not app_name: - return None - heroku = heroku3.from_key(api_key) - try: - heroku_applications = heroku.apps() - except: - return None - heroku_app = None - for app in heroku_applications: - if app.name == app_name: - heroku_app = app - break - if not heroku_app: - return None - return heroku_app.git_url.replace("https://", "https://api:" + api_key + "@") - -HEROKU_URL = fetch_heroku_git_url(HEROKU_API_KEY, HEROKU_APP_NAME) diff --git a/bot/helper/mirror_utils/download_utils/qbit_downloader.py b/bot/helper/mirror_utils/download_utils/qbit_downloader.py index 94eb29a4..1645e199 100644 --- a/bot/helper/mirror_utils/download_utils/qbit_downloader.py +++ b/bot/helper/mirror_utils/download_utils/qbit_downloader.py @@ -137,7 +137,7 @@ def update(self): tor_info = tor_info[0] if tor_info.state == "metaDL": self.stalled_time = time.time() - if time.time() - self.meta_time >= 600: + if time.time() - self.meta_time >= 999999999: # timeout while downloading metadata self.listener.onDownloadError("Dead Torrent!") self.client.torrents_delete(torrent_hashes=self.ext_hash, delete_files=True) self.client.auth_log_out() @@ -162,7 +162,7 @@ def update(self): self.updater.cancel() return elif tor_info.state == "stalledDL": - if time.time() - self.stalled_time >= 900: + if time.time() - self.stalled_time >= 999999999: # timeout after downloading metadata self.listener.onDownloadError("Dead Torrent!") self.client.torrents_delete(torrent_hashes=self.ext_hash, delete_files=True) self.client.auth_log_out() diff --git a/bot/helper/telegram_helper/bot_commands.py b/bot/helper/telegram_helper/bot_commands.py index c219c149..37695573 100644 --- a/bot/helper/telegram_helper/bot_commands.py +++ b/bot/helper/telegram_helper/bot_commands.py @@ -26,7 +26,6 @@ def __init__(self): self.TarWatchCommand = 'tarwatch' self.DeleteCommand = 'del' self.ShellCommand = 'shell' - self.UpdateCommand = 'update' self.ExecHelpCommand = 'exechelp' self.TsHelpCommand = 'tshelp' diff --git a/bot/modules/config.py b/bot/modules/config.py deleted file mode 100644 index c9265a0b..00000000 --- a/bot/modules/config.py +++ /dev/null @@ -1,221 +0,0 @@ -# Implement By https://github.com/jusidama18 -# Based on this https://github.com/DevsExpo/FridayUserbot/blob/master/plugins/heroku_helpers.py - -from pyrogram import filters, types, emoji -from bot.helper.telegram_helper.bot_commands import BotCommands -from bot import app, OWNER_ID, bot -from bot.helper import check_heroku -from bot import * - -# Add Variable - -@app.on_message(filters.command(['setvar', f'setvar@{bot.username}']) & filters.user(OWNER_ID)) -@check_heroku -async def set_varr(client, message, app_): - msg_ = await message.reply_text("`Please Wait!`") - heroku_var = app_.config() - _var = message.text.split(None, 1)[1] - if not _var: - await msg_.edit("`Here is Usage Syntax: /setvar KEY VALUE`", parse_mode="markdown") - return - if not " " in _var: - await msg_.edit("`Variable VALUE needed !`", parse_mode="markdown") - return - var_ = _var.split(" ", 1) - if len(var_) > 2: - await msg_.edit("`Here is Usage Syntax: /setvar KEY VALUE`", parse_mode="markdown") - return - _varname, _varvalue = var_ - await msg_.edit( - f"`Variable {_varname} Added With Value {_varvalue}!`" \ - f"\nYour Heroku app will restart. Be patient." - ) - heroku_var[_varname] = _varvalue - -# Delete Variable - -@app.on_message(filters.command(['delvar', f'delvar@{bot.username}']) & filters.user(OWNER_ID)) -@check_heroku -async def del_varr(client, message, app_): - msg_ = await message.reply_text("`Please Wait!`", parse_mode="markdown") - heroku_var = app_.config() - _var = message.text.split(None, 1)[1] - if not _var: - await msg_.edit("`Give Var Name As Input!`", parse_mode="markdown") - return - if not _var in heroku_var: - await msg_.edit("`This Var Doesn't Exists!`", parse_mode="markdown") - return - await msg_.edit( - f"`Sucessfully Deleted {_var} Var!`" \ - f"\nYour Heroku app will restart. Be patient.", - parse_mode="markdown") - del heroku_var[_var] - -@app.on_message(filters.command(['reboot', f'reboot@{bot.username}']) & filters.user(OWNER_ID)) -@check_heroku -async def gib_restart(client, message, hap): - msg_ = await message.reply_text("[HEROKU] - Restarting") - hap.restart() - -# CONFIG LIST # - -__header__='📕 **Page** **{}**\n\n' - -@app.on_message(filters.command([BotCommands.ConfigMenuCommand, f'{BotCommands.ConfigMenuCommand}@{bot.username}']) & filters.user(OWNER_ID)) -async def config_menu(_, message): - await message.reply( - f"**Hello {message.from_user.mention}**,\n\n**If you want to add or set Variable in Heroku use** `/setvar`\n\n**If you want to delete Variable in Heroku use `/delvar`**\n\n**WARNING! Very Recommended to do this command in private since it's contain Bot info.**\n\n**Here's This is Eunha-Mirror-bot Current Configs**", - reply_markup=types.InlineKeyboardMarkup( - [[types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), types.InlineKeyboardButton(f"BOT CONFIG", callback_data='docs_1')]] - ) - ) - -@app.on_callback_query(filters.regex('^docs_') & filters.user(OWNER_ID)) -async def config_button(_, query): - data = query.data.split('_')[1] - if data == '1': - return await query.message.edit( - __header__.format(data) - + f"**[ Telegram Config ]**\n\n**BOT_TOKEN:** `{BOT_TOKEN}`\n\n**TELEGRAM_API:** `{TELEGRAM_API}`\n\n**TELEGRAM_HASH:** `{TELEGRAM_HASH}`\n\n**TELEGRAPH_TOKEN:** `{telegraph_token}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_10'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_2') - ] - ] - ) - ) - elif data == '2': - return await query.message.edit( - __header__.format(data) - + f"**[ Drive and Index Config ]**\n\n**GDRIVE_FOLDER_ID:** `{parent_id}`\n\n**IS_TEAM_DRIVE:** `{IS_TEAM_DRIVE}`\n\n**USE_SERVICE_ACCOUNTS:** `{USE_SERVICE_ACCOUNTS}`\n\n**INDEX_URL:** `{INDEX_URL}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_1'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_3') - ] - ] - ) - ) - elif data == '3': - return await query.message.edit( - __header__.format(data) - + f"**[ Mega and Uptobox Config ]**\n\n**MEGA_API_KEY:** `{MEGA_API_KEY}`\n\n**MEGA_EMAIL_ID:** `{MEGA_EMAIL_ID}`\n\n**MEGA_PASSWORD:** `{MEGA_PASSWORD}`\n\n**UPTOBOX_TOKEN:** `{UPTOBOX_TOKEN}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_2'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_4') - ] - ] - ) - ) - elif data == '4': - return await query.message.edit( - __header__.format(data) - + f"**[ Stop and Block Config ]**\n\n**STOP_DUPLICATE:** `{STOP_DUPLICATE}`\n\n**BLOCK_MEGA_FOLDER:** `{BLOCK_MEGA_FOLDER}`\n\n**BLOCK_MEGA_LINKS:** `{BLOCK_MEGA_LINKS}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_3'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_5') - ] - ] - ) - ) - elif data == '5': - return await query.message.edit( - __header__.format(data) - + f"**[ Limit Size Config ]**\n\n**TORRENT_DIRECT_LIMIT:** `{TORRENT_DIRECT_LIMIT}`\n\n**TAR_UNZIP_LIMIT:** `{TAR_UNZIP_LIMIT}`\n\n**CLONE_LIMIT:** `{CLONE_LIMIT}`\n\n**MEGA_LIMIT:** `{MEGA_LIMIT}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_4'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_6') - ] - ] - ) - ) - elif data == '6': - user = sudo = '' - user += '\n'.join(str(id) for id in AUTHORIZED_CHATS) - sudo += '\n'.join(str(id) for id in SUDO_USERS) - return await query.message.edit( - __header__.format(data) - + f"**[ User ID Config ]**\n\n**OWNER_ID:** `{OWNER_ID}`\n\n**AUTHORIZED_CHATS:**\n`{user}`\n\n**SUDO_USERS:**\n`{sudo}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_5'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_7') - ] - ] - ) - ) - elif data == '7': - return await query.message.edit( - __header__.format(data) - + f"**[ Button Config ]**\n\n**BUTTON_FOUR_NAME:** `{BUTTON_FOUR_NAME}`\n\n**BUTTON_FOUR_URL:** `{BUTTON_FOUR_URL}`\n\n**BUTTON_FIVE_NAME:** `{BUTTON_FIVE_NAME}`\n\n**BUTTON_FIVE_URL:** `{BUTTON_FIVE_URL}`\n\n**BUTTON_SIX_NAME:** `{BUTTON_SIX_NAME}`\n\n**BUTTON_SIX_URL:** `{BUTTON_SIX_URL}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_6'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_8') - ] - ] - ) - ) - elif data == '8': - return await query.message.edit( - __header__.format(data) - + f"**[ Heroku Config ]**\n\n**HEROKU_API_KEY:** `{HEROKU_API_KEY}`\n\n**HEROKU_APP_NAME:** `{HEROKU_APP_NAME}`\n\n**[ Shortener Config ]**\n\n**SHORTENER:** `{SHORTENER}`\n\n**SHORTENER_API:** `{SHORTENER_API}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_7'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_9') - ] - ] - ) - ) - elif data == '9': - return await query.message.edit( - __header__.format(data) - + f"**[ Others Config ]**\n\n**VIEW_LINK:** `{VIEW_LINK}`\n\n**STATUS_LIMIT:** `{STATUS_LIMIT}`\n\n**DOWNLOAD_STATUS_UPDATE_INTERVAL:** `{DOWNLOAD_STATUS_UPDATE_INTERVAL}`\n\n**IGNORE_PENDING_REQUESTS:** `{IGNORE_PENDING_REQUESTS}`\n\n**AUTO_DELETE_MESSAGE_DURATION:** `{AUTO_DELETE_MESSAGE_DURATION}`\n\n**DOWNLOAD_DIR:** `{DOWNLOAD_DIR}`\n\n**DATABASE_URL:** `{DB_URI}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_8'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_10') - ] - ] - ) - ) - elif data == '10': - return await query.message.edit( - __header__.format(data) - + f"**[ qBittorrent Config ]**\n\n**IS_VPS:** `{IS_VPS}`\n\n**SERVER_PORT:** `{SERVER_PORT}`\n\n**BASE_URL_OF_BOT:** `{BASE_URL}`\n\n**[ Updater Config ]**\n\n**UPSTREAM_REPO:** `{UPSTREAM_REPO}`\n\n**UPSTREAM_BRANCH:** `{UPSTREAM_BRANCH}`", - reply_markup=types.InlineKeyboardMarkup( - [ - [ - types.InlineKeyboardButton(f"{emoji.LEFT_ARROW}", callback_data='docs_9'), - types.InlineKeyboardButton(f"{emoji.CROSS_MARK}", callback_data='docs_end'), - types.InlineKeyboardButton(f"{emoji.RIGHT_ARROW}", callback_data='docs_1') - ] - ] - ) - ) - elif data == 'end': - return await query.message.delete() diff --git a/bot/modules/reboot.py b/bot/modules/reboot.py new file mode 100644 index 00000000..611f9cd1 --- /dev/null +++ b/bot/modules/reboot.py @@ -0,0 +1,14 @@ +# Implement By https://github.com/jusidama18 +# Based on this https://github.com/DevsExpo/FridayUserbot/blob/master/plugins/heroku_helpers.py + +from pyrogram import filters +from bot import app, OWNER_ID, bot +from bot.helper import check_heroku + +@app.on_message(filters.command(['reboot', f'reboot@{bot.username}']) & filters.user(OWNER_ID)) +@check_heroku +async def gib_restart(client, message, hap): + msg_ = await message.reply_text("[HEROKU] - Restarting") + hap.restart() + + diff --git a/bot/modules/updates.py b/bot/modules/updates.py deleted file mode 100644 index faf46136..00000000 --- a/bot/modules/updates.py +++ /dev/null @@ -1,99 +0,0 @@ -# Implement By https://github.com/jusidama18 -# Based on this https://github.com/DevsExpo/FridayUserbot/blob/master/plugins/updater.py - -import sys -import subprocess -import heroku3 - -from datetime import datetime -from os import environ, execle, path, remove - -from git import Repo -from git.exc import GitCommandError, InvalidGitRepositoryError, NoSuchPathError - -from pyrogram import filters - -from bot import app, OWNER_ID, UPSTREAM_REPO, UPSTREAM_BRANCH, bot -from bot.helper import HEROKU_URL -from bot.helper.telegram_helper.bot_commands import BotCommands - -REPO_ = UPSTREAM_REPO -BRANCH_ = UPSTREAM_BRANCH - -def gen_chlog(repo, diff): - ch_log = '' - d_form = "%d/%m/%y" - for c in repo.iter_commits(diff): - ch_log += f'• [{c.committed_datetime.strftime(d_form)}]: {c.summary} **{c.author}**\n' - return ch_log - -# Update Command - -@app.on_message(filters.command([BotCommands.UpdateCommand, f'{BotCommands.UpdateCommand}@{bot.username}']) & filters.user(OWNER_ID)) -async def update_it(client, message): - msg_ = await message.reply_text("`Updating Please Wait!`") - text = message.text.split(None, 1)[1] - try: - repo = Repo() - except GitCommandError: - return await msg_.edit( - "**Invalid Git Command. Please Report This Bug To [Support Group](https://t.me/SlamMirrorSupport)**" - ) - except InvalidGitRepositoryError: - repo = Repo.init() - if "upstream" in repo.remotes: - origin = repo.remote("upstream") - else: - origin = repo.create_remote("upstream", REPO_) - origin.fetch() - repo.create_head(UPSTREAM_BRANCH, origin.refs.master) - repo.heads.master.set_tracking_branch(origin.refs.master) - repo.heads.master.checkout(True) - if repo.active_branch.name != UPSTREAM_BRANCH: - return await msg_.edit( - f"`Seems Like You Are Using Custom Branch - {repo.active_branch.name}! Please Switch To {UPSTREAM_BRANCH} To Make This Updater Function!`" - ) - try: - repo.create_remote("upstream", REPO_) - except BaseException: - pass - ups_rem = repo.remote("upstream") - ups_rem.fetch(UPSTREAM_BRANCH) - clogs = gen_chlog(repo, f'HEAD..upstream/{UPSTREAM_BRANCH}') - - if not clogs: - await msg_.edit(f"Bot up-to-date with **{UPSTREAM_BRANCH}**", parse_mode="Markdown") - return - - if "now" == text: - await msg_.edit(f"`Bot Updating with` **{UPSTREAM_BRANCH}** `Branch Please Wait...`", parse_mode="Markdown") - if not HEROKU_URL: - try: - ups_rem.pull(UPSTREAM_BRANCH) - except GitCommandError: - repo.git.reset("--hard", "FETCH_HEAD") - await subprocess.run(["pip3","install","--no-cache-dir","-r","requirements.txt"]) - await msg_.edit("`Updated Sucessfully! Give Me Some Time To Restart!`") - with open("./aria.sh", 'rb') as file: - script = file.read() - subprocess.call("./aria.sh", shell=True) - args = [sys.executable, "-m", "bot"] - execle(sys.executable, *args, environ) - else: - await msg_.edit("`Heroku Detected! Pushing, Please wait!`") - ups_rem.fetch(UPSTREAM_BRANCH) - repo.git.reset("--hard", "FETCH_HEAD") - if "heroku" in repo.remotes: - remote = repo.remote("heroku") - remote.set_url(HEROKU_URL) - else: - remote = repo.create_remote("heroku", HEROKU_URL) - try: - remote.push(refspec="HEAD:refs/heads/master", force=True) - except BaseException as error: - await msg_.edit(f"**Updater Error** \nTraceBack : `{error}`") - return repo.__del__() - await msg_.edit(f"`Updated Sucessfully! \n\nCheck your config with` `/{BotCommands.ConfigMenuCommand}`") - else: - await msg_.edit(f"**New Update Available**\n\nFrom [REPO]({REPO_})\nCHANGELOG:\n\n{clogs}\n\nDo `/update now` to Update BOT.", parse_mode="Markdown",disable_web_page_preview=True) - return diff --git a/config_sample.env b/config_sample.env index 2e12a090..3504969e 100644 --- a/config_sample.env +++ b/config_sample.env @@ -11,8 +11,6 @@ AUTO_DELETE_MESSAGE_DURATION = 20 IS_TEAM_DRIVE = "" TELEGRAM_API = TELEGRAM_HASH = "" -UPSTREAM_REPO = "https://github.com/vincreator/Eunha-Mirror-bot" -UPSTREAM_BRANCH = "master" # OPTIONAL CONFIG DATABASE_URL = "" AUTHORIZED_CHATS = "" # Split by space @@ -31,9 +29,9 @@ STOP_DUPLICATE = "" SHORTENER = "" SHORTENER_API = "" # qBittorrent -IS_VPS = "" -SERVER_PORT = "80" # For VPS -BASE_URL_OF_BOT = "" #required for heroku +IS_VPS = "" # Don't set this to true even if VPS, unless facing error with web server +SERVER_PORT = "80" # Only for VPS +BASE_URL_OF_BOT = "" # Required for Heroku # If you want to use Credentials externally from Index Links, fill these vars with the direct links # These are optional, if you don't know, simply leave them, don't fill anything in them. ACCOUNTS_ZIP_URL = "" diff --git a/qBittorrent.conf b/qBittorrent.conf new file mode 100644 index 00000000..e15a0162 --- /dev/null +++ b/qBittorrent.conf @@ -0,0 +1,51 @@ +[AutoRun] +enabled=true +program= + +[LegalNotice] +Accepted=true + +[Network] +Cookies=@Invalid() + +[BitTorrent] +Session\AsyncIOThreadsCount=8 +Session\BTProtocol=Both +Session\MultiConnectionsPerIp=true +Session\SlowTorrentsDownloadRate=100 +Session\SlowTorrentsInactivityTimer=600 +Session\uTPMixedMode=TCP + +[Preferences] +Advanced\AnnounceToAllTrackers=true +Advanced\IgnoreLimitsLAN=true +Advanced\IncludeOverhead=false +Advanced\RecheckOnCompletion=true +Advanced\LtTrackerExchange=true +Advanced\SuperSeeding=false +Bittorrent\MaxConnecs=3000 +Bittorrent\MaxConnecsPerTorrent=300 +Bittorrent\DHT=true +Bittorrent\DHTPort=6881 +Bittorrent\Encryption=0 +Bittorrent\PeX=true +Bittorrent\LSD=true +Bittorrent\sameDHTPortAsBT=true +Bittorrent\uTP=true +Bittorrent\uTP_rate_limited=false +Connection\PortRangeMin=6881 +Connection\UPnP=true +Downloads\DiskWriteCacheSize=64 +Downloads\PreAllocation=true +Downloads\UseIncompleteExtension=true +Queueing\IgnoreSlowTorrents=true +Queueing\MaxActiveDownloads=50 +Queueing\MaxActiveTorrents=100 +Queueing\QueueingEnabled=true +WebUI\CSRFProtection=true +WebUI\ClickjackingProtection=true +WebUI\HTTPS\Enabled=false +WebUI\HostHeaderValidation=true +WebUI\Enabled=true +WebUI\Port=8090 +WebUI\UseUPnP=true diff --git a/start.sh b/start.sh index 3d46f03f..df365ef4 100755 --- a/start.sh +++ b/start.sh @@ -1 +1 @@ -gunicorn wserver:start_server --bind 0.0.0.0:$PORT --worker-class aiohttp.GunicornWebWorker & qbittorrent-nox -d --webui-port=8090 & python3 alive.py & ./aria.sh; python3 -m bot +gunicorn wserver:start_server --bind 0.0.0.0:$PORT --worker-class aiohttp.GunicornWebWorker & qbittorrent-nox -d & ./aria.sh; python3 -m bot diff --git a/wserver.py b/wserver.py index 24bed9e0..fbadf5d5 100644 --- a/wserver.py +++ b/wserver.py @@ -648,7 +648,7 @@ async def re_verfiy(paused, resumed, client, torr): else: break k += 1 - if k >= 4: + if k > 4: return False return True