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