diff --git a/cloudbot b/cloudbot index 8bcfaff..39e1c2d 100755 --- a/cloudbot +++ b/cloudbot @@ -1,11 +1,15 @@ #!/usr/bin/env python # Bot Wrapper by neersighted + + +# Import required modules import sys import os import subprocess import re import json +# Check for config if os.path.isfile("./config"): try: config = json.load(open('config')) @@ -16,16 +20,20 @@ else: config = False command = "python bot.py" +# Colors nocol = "\033[1;m" red = "\033[1;31m" green = "\033[1;32m" -usage = "usage: ./cloudbot {start|stop|restart|status}" -quit = "Goodbye! Thanks for using CloudBot!" - +# Commands pwd = os.getcwd() clearlog = ": > ./bot.log" +start = "echo " + "'" + error1 + "'" +stop = "echo " + "'" + error1 + "'" +restart = "echo " + "'" + error1 + "'" +pid = "echo 'Cannot get pid'" +# Checks daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True) daemon = re.match(r'^/usr/bin/daemon$', daemoncheck) screencheck = subprocess.check_output("locate /usr/bin/screen", shell=True) @@ -42,6 +50,9 @@ try: except (subprocess.CalledProcessError): running = False +# Messages +usage = "usage: ./cloudbot {start|stop|restart|status}" +quit = "Goodbye! Thanks for using CloudBot!" error1 = red + "Neither screen nor daemon is installed! "\ "This program cannot run! {ERROR 1}" + nocol error2 = red + "Could not find bot.py! Are you in the wrong folder? "\ @@ -51,11 +62,7 @@ error4 = red + "Program killed by user! {ERROR 4}" + nocol error5 = red + "Invalid backend in config! {ERROR 5}" + nocol error6 = red + "Author error! We be derpin'! {ERROR 6}" + nocol -start = "echo " + "'" + error1 + "'" -stop = "echo " + "'" + error1 + "'" -restart = "echo " + "'" + error1 + "'" -pid = "echo 'Cannot get pid'" - +# Set commands if daemon: if backend == "daemon": start = "daemon -r -n cloudbot -O " + pwd + \ @@ -93,6 +100,7 @@ elif screen: else: command = command +# Fancy banner print " ______ __ ______ __ __ "\ " _______ .______ ______ .___________." print " / || | / __ \ | | | | "\ @@ -107,6 +115,7 @@ print " \______||_______| \______/ \______/ "\ "|_______/ |______/ \______/ |__| " print "http://git.io/cloudbot "\ " by lukeroge" +# Read arguments/turn interactive try: if running: if (len(sys.argv) > 1): @@ -179,6 +188,7 @@ try: else: print error3 exit +# Pretify errors except (TypeError, ValueError), e: print error3 exit @@ -188,12 +198,15 @@ except (KeyboardInterrupt), e: except (NameError, SyntaxError), e: print error6 exit + +# Check for bot files if os.path.isfile("./bot.py"): command = command else: print error2 exit +# Call command subprocess.call(command, shell=True) print quit exit