Skip to content

Commit

Permalink
updated the script for handeling exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
NovusEdge committed Apr 10, 2021
1 parent 9baccfa commit 8b63f44
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions btb_manager_telegram/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import sys
import time

import colorama

from telegram.ext import ConversationHandler, Updater

from btb_manager_telegram import (
Expand Down Expand Up @@ -106,15 +108,23 @@ def main() -> None:
updater.idle()


def run_on_docker() -> None:
try:
subprocess.run('docker', args=[ 'image', 'inspect', 'BTBMT'], check=True)

except Exception as e:
print(f"{colorama.Fore.RED}[-] E: {e}{colorama.Fore.RESET}")
print(f"{colorama.Fore.YELLOW}[*] Please run the docker_setup.py script "
"before running the bot in a container.{colorama.Fore.RESET}")

return

subprocess.run('docker run', args=['--rm', '-it', 'BTBMT'], shell=True)

if __name__ == "__main__":
on_docker = pre_run_main()
if on_docker:
os.system("docker build --no-cache -t py-container .")
try:
os.system("docker run --rm -it py-container")
except Exception:
pass
os.system("docker rmi -f py-container")
run_on_docker()
sys.exit(-1)

main()

0 comments on commit 8b63f44

Please sign in to comment.