Skip to content

Commit

Permalink
Bot: Upstream REPO
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkhatri137 committed Aug 31, 2022
1 parent 5ae1bbb commit b9c986b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ RUN set -ex \

RUN pip3 install --no-cache-dir --upgrade -r requirements.txt

CMD ["python3", "-m", "bot"]
CMD ["bash", "start"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ This project is heavily inspired from @out386 's telegram bot which is written i
- Count Drive Files.
- Extract password protected files (It's not hack, you have to enter password)
- For extracting password protected files, using custom filename and download
- Update bot at startup and with restart command using `UPSTREAM_REPO`

## Multi Search IDs
To use list from multi TD/folder. Run driveid.py in your terminal and follow it. It will generate **drive_folder** file or u can simply create `drive_folder` file in working directory and fill it, check below format:
Expand Down Expand Up @@ -134,6 +135,9 @@ Fill up rest of the fields. Meaning of each field is discussed below:
**2. Optional Fields**
- `UPSTREAM_REPO`: Your github repository link, if your repo is private add `https://username:{githubtoken}@github.com/{username}/{reponame}` format. Get token from [Github settings](https://github.com/settings/tokens). So you can update your bot from filled repository on each restart.
- **NOTE**: Any change in docker or requirements you need to deploy/build again with updated repo to take effect. DON'T delete .gitignore file.
- `UPSTREAM_BRANCH`: Upstream branch for update. Default is `master`.
- `ACCOUNTS_ZIP_URL`: Only if you want to load your Service Account externally from an Index Link or by any direct download link NOT webpage link. Archive the accounts folder to ZIP file. Fill this with the direct download link of zip file. If index need authentication so add direct download as shown below:
- `https://username:[email protected]/...`
- `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.
Expand Down
3 changes: 3 additions & 0 deletions config_sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ AS_DOCUMENT = ""
CUSTOM_FILENAME = ""
RECURSIVE_SEARCH = "" #T/F And Fill drive_folder File Using Driveid.py Script.
UPTOBOX_TOKEN = ""
# Upstream
UPSTREAM_REPO = ""
UPSTREAM_BRANCH = ""
# View Link button to open file Index Link in browser instead of direct download link
# You can figure out if it's compatible with your Index code or not, open any video from you Index and check if its URL ends with ?a=view, if yes make it True it will work (Compatible with Bhadoo Drive Index)
VIEW_LINK = ""
Expand Down
1 change: 1 addition & 0 deletions start
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 update.py && python3 -m bot
54 changes: 54 additions & 0 deletions update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from logging import FileHandler, error as log_error, info as log_info
import os
import requests
from subprocess import run as srun
from dotenv import load_dotenv

CONFIG_FILE_URL = os.environ.get('CONFIG_FILE_URL')
try:
if len(CONFIG_FILE_URL) == 0:
raise TypeError
try:
res = requests.get(CONFIG_FILE_URL)
if res.status_code == 200:
with open('config.env', 'wb+') as f:
f.write(res.content)
else:
log_error(f"Failed to download config.env {res.status_code}")
except Exception as e:
log_error(f"CONFIG_FILE_URL: {e}")
except:
pass

load_dotenv('config.env', override=True)

UPSTREAM_REPO = os.environ.get('UPSTREAM_REPO')
UPSTREAM_BRANCH = os.environ.get('UPSTREAM_BRANCH')
try:
if len(UPSTREAM_REPO) == 0:
raise TypeError
except:
UPSTREAM_REPO = None
try:
if len(UPSTREAM_BRANCH) == 0:
raise TypeError
except:
UPSTREAM_BRANCH = 'master'

if UPSTREAM_REPO is not None:
if os.path.exists('.git'):
srun(["rm", "-rf", ".git"])

update = srun([f"git init -q \
&& git config --global user.email [email protected] \
&& git config --global user.name mirrorbot137 \
&& git add . \
&& git commit -sm update -q \
&& git remote add origin {UPSTREAM_REPO} \
&& git fetch origin -q \
&& git reset --hard origin/{UPSTREAM_BRANCH} -q"], shell=True)

if update.returncode == 0:
log_info('Successfully updated from UPSTREAM_REPO')
else:
log_error('Something went wrong, Check UPSTREAM_REPO if valid or not!')

0 comments on commit b9c986b

Please sign in to comment.