Last active
August 3, 2022 11:21
-
-
Save naytseyd/8dae165c9d3b0ba6850814ad969b0fe9 to your computer and use it in GitHub Desktop.
Seden UserBot Heroku Deploy Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (C) 2020-2022 TeamDerUntergang <https://github.com/TeamDerUntergang> | |
# | |
# This file is part of TeamDerUntergang project, | |
# and licensed under GNU Affero General Public License v3. | |
# See the GNU Affero General Public License for more details. | |
# | |
# All rights reserved. See COPYING, AUTHORS. | |
# | |
from os import name, system | |
from sys import stderr | |
from threading import Thread | |
from time import sleep | |
# Check pip modules | |
try: | |
from git import Repo | |
from git.exc import GitCommandError, InvalidGitRepositoryError, NoSuchPathError | |
except ImportError: | |
import pip | |
pip.main(['install', 'gitpython']) | |
from git import Repo | |
from git.exc import GitCommandError, InvalidGitRepositoryError, NoSuchPathError | |
try: | |
from heroku3 import from_key | |
except ImportError: | |
import pip | |
pip.main(['install', 'heroku3']) | |
from heroku3 import from_key | |
stop_logging = False | |
def cls(): | |
system('cls' if name == 'nt' else 'clear') | |
cls() | |
# Heroku random App Name | |
def random_appname(): | |
from random import choice | |
from string import ascii_lowercase | |
return ''.join(choice(ascii_lowercase) for i in range(28)) | |
def inputx(desc, default=None, retry=False): | |
ret = input(desc) | |
if len(ret.strip()): | |
return ret | |
if retry: | |
return inputx(desc, default=default, retry=retry) | |
return default | |
# Colorized | |
class Logger: | |
@staticmethod | |
def info(message): | |
Logger.msg(message, color=34) | |
@staticmethod | |
def success(message): | |
Logger.msg(message, color=32) | |
@staticmethod | |
def warning(message): | |
Logger.msg(message, color=33) | |
@staticmethod | |
def error(message): | |
Logger.msg(message, color=31) | |
@staticmethod | |
def msg(message, color=0): | |
stderr.write(f'\x1b[1;{color}m{message.strip()}\x1b[0m\n') | |
# App logs | |
def track_deploy(app): | |
try: | |
for line in app.stream_log(lines=1): | |
if stop_logging: | |
break | |
Logger.info(line.decode()) | |
except: | |
sleep(1) | |
return track_deploy(app) | |
Logger.info('Seden Heroku Deploy Script\nTelegram: @SedenUserBot') | |
heroku_apikey = inputx('\nHeroku API Key: ', retry=True) | |
repo_url = 'https://github.com/TeamDerUntergang/Telegram-SedenUserBot' | |
heroku_appname = inputx('Heroku App Name (default: random): ', default=random_appname()) | |
sleep(1) | |
def create_app(heroku_apikey, heroku_appname, repo_url): | |
try: | |
heroku = from_key(heroku_apikey) | |
heroku.apps() | |
except BaseException: | |
return Logger.error('Wrong API Key!') | |
try: | |
app = heroku.create_app( | |
name=heroku_appname, stack_id_or_name='container', region_id_or_name='eu' | |
) | |
except BaseException as e: | |
raise e | |
log_thread = Thread(target=track_deploy, args=(app,)) | |
app.install_addon(plan_id_or_name='heroku-postgresql', config={}) | |
buildpack_urls = [ | |
'https://github.com/heroku/heroku-buildpack-google-chrome', | |
'https://github.com/heroku/heroku-buildpack-chromedriver', | |
] | |
app.update_buildpacks(buildpack_urls) | |
env = app.config() | |
sleep(3) | |
Logger.info('Enter configs! ( https://teamderuntergang.github.io/configs.html )') | |
env['ALIVE_MSG'] = inputx('ALIVE_MSG: ') | |
env['API_HASH'] = inputx('API_HASH: ', retry=True) | |
env['API_ID'] = inputx('API_ID: ', retry=True) | |
env['BOT_PREFIX'] = inputx('BOT_PREFIX: ', '.') | |
env['CHROME_DRIVER'] = '/usr/bin/chromedriver' | |
env['HEROKU_APPNAME'] = heroku_appname | |
env['HEROKU_KEY'] = heroku_apikey | |
env['LOG_ID'] = inputx('LOG_ID: ', 0) | |
env['LOG_VERBOSE'] = inputx('LOG_VERBOSE: ', default=False) | |
env['PM_AUTO_BAN'] = inputx('PM_AUTO_BAN: ', default=False) | |
env['PM_MSG_COUNT'] = inputx('PM_MSG_COUNT: ', default=5) | |
env['PM_UNAPPROVED'] = inputx('PM_UNAPPROVED: ') | |
env['REPO_URL'] = repo_url | |
env['SEDEN_LANG'] = inputx('SEDEN_LANG: ', default='en') | |
env['SESSION'] = inputx('SESSION: ', retry=True) | |
other = inputx( | |
'Do you want to set other configs ? (Not Needed) (y/N): ', retry=True | |
) | |
while other.lower() not in ('y', 'n'): | |
other = inputx( | |
'Do you want to set other configs ? (Not Needed) (y/N): ', retry=True | |
) | |
if other == 'y': | |
env['SPOTIPY_CLIENT_ID'] = inputx('SPOTIPY_CLIENT_ID: ') | |
env['SPOTIPY_CLIENT_SECRET'] = inputx('SPOTIPY_CLIENT_SECRET: ') | |
env['DRIVE_CLIENT'] = inputx('DRIVE_CLIENT: ') | |
env['DRIVE_SECRET'] = inputx('DRIVE_SECRET: ') | |
env['GDRIVE_FOLDER_ID'] = inputx('GDRIVE_FOLDER_ID: ') | |
env['GENIUS_TOKEN'] = inputx('GENIUS_TOKEN: ') | |
env['SPAMWATCH_KEY'] = inputx('SPAMWATCH_KEY: ') | |
env['OCR_APIKEY'] = inputx('OCR_APIKEY: ') | |
env['RBG_APIKEY'] = inputx('RBG_APIKEY: ') | |
env['AUTO_PP'] = inputx('AUTO_PP: ') | |
env['WEATHER'] = inputx('WEATHER: ') | |
elif other == 'n': | |
pass | |
return app, log_thread | |
app, log_thread = create_app(heroku_apikey, heroku_appname, repo_url) | |
log_thread.start() | |
def git_push(repo_url, heroku_apikey, app): | |
repo = None | |
try: | |
repo = Repo() | |
except NoSuchPathError as error: | |
print(error) | |
repo.__del__() | |
except GitCommandError as error: | |
print(error) | |
repo.__del__() | |
except InvalidGitRepositoryError as error: | |
repo = Repo.init() | |
origin = repo.create_remote('upstream', repo_url) | |
origin.fetch() | |
repo.create_head('seden', origin.refs.seden) | |
repo.heads.seden.set_tracking_branch(origin.refs.seden) | |
repo.heads.seden.checkout(True) | |
ac_br = repo.active_branch.name | |
try: | |
repo.create_remote('upstream', repo_url) | |
except BaseException: | |
pass | |
ups_rem = repo.remote('upstream') | |
ups_rem.fetch(ac_br) | |
ups_rem.fetch(ac_br) | |
repo.git.reset('--hard', 'FETCH_HEAD') | |
heroku_git_url = app.git_url.replace('https://', f'https://api:{heroku_apikey}@') | |
if 'heroku' in repo.remotes: | |
remote = repo.remote('heroku') | |
remote.set_url(heroku_git_url) | |
else: | |
remote = repo.create_remote('heroku', heroku_git_url) | |
remote.push(refspec='HEAD:refs/heads/master', force=True) | |
sleep(1) | |
Logger.info('Deploying...') | |
git_push(repo_url, heroku_apikey, app) | |
app.scale_formation_process('seden', 1) | |
sleep(1) | |
cls() | |
Logger.success( | |
f'App deployed succesfully!\nApp URL: https://dashboard.heroku.com/apps/{heroku_appname}' | |
) | |
Logger.warning( | |
'''Your bot is running! | |
You can test it by typing .alive in any chat. | |
You can get the list of modules by typing ".seden" | |
If you need help, you can check out our support group https://t.me/SedenUserBotSupport''' | |
) | |
Logger.info( | |
'For other configs see https://teamderuntergang.github.io/configs.html\n\nSedenUserBot©' | |
) | |
stop_logging = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment