Skip to content

Commit

Permalink
Some fixes for vps user (breakdowns#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdowns authored Mar 23, 2021
1 parent eee541b commit e54c041
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 47 deletions.
61 changes: 46 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -64,7 +64,38 @@ Note :- Above are the supported url shorteners. Except these only some url short

</details>

## 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

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
47 changes: 18 additions & 29 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -128,18 +102,33 @@ 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')
MEGA_PASSWORD = getConfig('MEGA_PASSWORD')
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:
Expand Down

0 comments on commit e54c041

Please sign in to comment.