From e54c04162700af7d3bed19d0326ca009892b06c2 Mon Sep 17 00:00:00 2001 From: Hafitz Setya <71178188+breakdowns@users.noreply.github.com> Date: Tue, 23 Mar 2021 08:59:34 +0700 Subject: [PATCH] Some fixes for vps user (#32) --- README.md | 61 +++++++++++++++++++++++++++++++++++++------------ app.json | 6 ++--- bot/__init__.py | 47 +++++++++++++++---------------------- 3 files changed, 67 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 8a708ba36c0..07a10185181 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,27 @@ [![Slam](https://telegra.ph/file/db03910496f06094f1f7a.jpg)](https://youtu.be/Pk_TthHfLeE) # Slam Mirror Bot -This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive. +This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive. This project is heavily inspired from @out386 's telegram bot which is written in JS. -## Getting Google OAuth API credential file +## How to deploy? +Deploying is pretty much straight forward and is divided into several steps as follows: +## Installing requirements -- Visit the [Google Cloud Console](https://console.developers.google.com/apis/credentials) -- Go to the OAuth Consent tab, fill it, and save. -- Go to the Credentials tab and click Create Credentials -> OAuth Client ID -- Choose Desktop and Create. -- Use the download button to download your credentials. - Clone this repo: ``` git clone https://github.com/breakdowns/slam-mirrorbot mirrorbot/ cd mirrorbot ``` -- Move that file to the root of mirrorbot, and rename it to credentials.json -- Visit [Google API page](https://console.developers.google.com/apis/library) -- Search for Drive and enable it if it is disabled -- Finally, run the script to generate token file (token.pickle) for Google Drive: + +- Install requirements +For Debian based distros ``` -pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib -python3 generate_drive_token.py +sudo apt install python3 +sudo snap install docker +``` +- For Arch and it's derivatives: +``` +sudo pacman -S docker python ``` ## Setting up config file @@ -64,7 +64,38 @@ Note :- Above are the supported url shorteners. Except these only some url short -## Deployment +## Getting Google OAuth API credential file + +- Visit the [Google Cloud Console](https://console.developers.google.com/apis/credentials) +- Go to the OAuth Consent tab, fill it, and save. +- Go to the Credentials tab and click Create Credentials -> OAuth Client ID +- Choose Desktop and Create. +- Use the download button to download your credentials. +- Move that file to the root of mirrorbot, and rename it to credentials.json +- Visit [Google API page](https://console.developers.google.com/apis/library) +- Search for Drive and enable it if it is disabled +- Finally, run the script to generate token file (token.pickle) for Google Drive: +``` +pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib +python3 generate_drive_token.py +``` + +## Deploying + +- Start docker daemon (skip if already running): +``` +sudo dockerd +``` +- Build Docker image: +``` +sudo docker build . -t mirrorbot +``` +- Run the image: +``` +sudo docker run mirrorbot +``` + +## Deploying on Heroku Give Star & Fork this repo, then upload **token.pickle** to your forks @@ -92,7 +123,7 @@ Give Star & Fork this repo, then upload **token.pickle** to your forks - Custom Buttons - Custom Filename (Only for url, telegram files and ytdl. Not for mega links and magnet/torrents) - Speedtest with picture results -- Extracting password protected files and using custom filename see these examples:- +- Extracting password protected files and using custom filename see these examples: > https://telegra.ph/Magneto-Python-Aria---Custom-Filename-Examples-01-20 - Extract these filetypes and uploads to google drive > ZIP, RAR, TAR, 7z, ISO, WIM, CAB, GZIP, BZIP2, diff --git a/app.json b/app.json index 993e4983457..2593199bd1d 100644 --- a/app.json +++ b/app.json @@ -8,7 +8,7 @@ "python" ], "repository": "https://github.com/breakdowns/slam-mirrorbot", - "website": "https://t.me/SlamMirrorSupport", + "website": "https://t.me/SlamMirrorSupportGroup", "success_url": "https://github.com/breakdowns/slam-mirrorbot/blob/master/README.md", "stack": "container", "env": { @@ -26,7 +26,7 @@ }, "DOWNLOAD_DIR": { "description": "The path to the local folder where the downloads should be downloaded to.", - "value": "/home/username/mirror-bot/downloads", + "value": "/home/slam/mirror-bot/downloads", "required": false }, "DOWNLOAD_STATUS_UPDATE_INTERVAL": { @@ -75,7 +75,7 @@ "required": true }, "UPTOBOX_TOKEN": { - "description": "Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account).", + "description": "Uptobox premium token to mirror uptobox links. Get it from https://uptobox.com/my_account.", "required": false }, "MEGA_API_KEY": { diff --git a/bot/__init__.py b/bot/__init__.py index 4ef68c5a8db..ca9c0cb67b9 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -86,40 +86,14 @@ def getConfig(name: str): AUTO_DELETE_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_MESSAGE_DURATION')) TELEGRAM_API = getConfig('TELEGRAM_API') TELEGRAM_HASH = getConfig('TELEGRAM_HASH') - HEROKU_API_KEY = getConfig('HEROKU_API_KEY') - HEROKU_APP_NAME = getConfig('HEROKU_APP_NAME') except KeyError as e: LOGGER.error("One or more env variables missing! Exiting now") exit(1) -try: - UPTOBOX_TOKEN = getConfig('UPTOBOX_TOKEN') -except KeyError: - logging.warning('UPTOBOX_TOKEN not provided!') - UPTOBOX_TOKEN = None -try: - UPTOBOX_TOKEN = getConfig('UPTOBOX_TOKEN') -except KeyError: - logging.warning('UPTOBOX_TOKEN not provided!') - UPTOBOX_TOKEN = None -try: - MEGA_API_KEY = getConfig('MEGA_API_KEY') -except KeyError: - LOGGER.warning('MEGA API KEY not provided!') - MEGA_API_KEY = None -try: - MEGA_EMAIL_ID = getConfig('MEGA_EMAIL_ID') - MEGA_PASSWORD = getConfig('MEGA_PASSWORD') - if len(MEGA_EMAIL_ID) == 0 or len(MEGA_PASSWORD) == 0: - raise KeyError -except KeyError: - LOGGER.warning('MEGA Credentials not provided!') - MEGA_EMAIL_ID = None - MEGA_PASSWORD = None - LOGGER.info("Generating USER_SESSION_STRING") with Client(':memory:', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN) as app: USER_SESSION_STRING = app.export_session_string() + #Generate Telegraph Token sname = ''.join(random.SystemRandom().choices(string.ascii_letters, k=8)) LOGGER.info("Generating Telegraph Token using '" + sname + "' name") @@ -128,10 +102,25 @@ def getConfig(name: str): telegraph_token = telegraph.get_access_token() LOGGER.info("Telegraph Token Generated: '" + telegraph_token + "'") +try: + HEROKU_API_KEY = getConfig('HEROKU_API_KEY') +except KeyError: + LOGGER.warning('HEROKU API KEY not provided!') + HEROKU_API_KEY = None +try: + HEROKU_APP_NAME = getConfig('HEROKU_APP_NAME') +except KeyError: + LOGGER.warning('HEROKU APP NAME not provided!') + HEROKU_APP_NAME = None +try: + UPTOBOX_TOKEN = getConfig('UPTOBOX_TOKEN') +except KeyError: + logging.warning('UPTOBOX_TOKEN not provided!') + UPTOBOX_TOKEN = None try: MEGA_API_KEY = getConfig('MEGA_API_KEY') except KeyError: - logging.warning('MEGA API KEY not provided!') + LOGGER.warning('MEGA API KEY not provided!') MEGA_API_KEY = None try: MEGA_EMAIL_ID = getConfig('MEGA_EMAIL_ID') @@ -139,7 +128,7 @@ def getConfig(name: str): if len(MEGA_EMAIL_ID) == 0 or len(MEGA_PASSWORD) == 0: raise KeyError except KeyError: - logging.warning('MEGA Credentials not provided!') + LOGGER.warning('MEGA Credentials not provided!') MEGA_EMAIL_ID = None MEGA_PASSWORD = None try: