updates, fixed .clear

This commit is contained in:
neersighted 2012-02-29 12:11:51 -08:00
parent 4e1ae63ffe
commit 7c0ff1f561
3 changed files with 17 additions and 12 deletions

View file

@ -15,10 +15,11 @@ red = "\033[1;31m"
green = "\033[1;32m" green = "\033[1;32m"
usage = "usage: ./cloudbot {start|stop|restart|status}" usage = "usage: ./cloudbot {start|stop|restart|status}"
quit = nocol + "Goodbye! Thanks for using CloudBot!" quit = "Goodbye! Thanks for using CloudBot!"
pwd = os.getcwd() pwd = os.getcwd()
clearlog = ": >./bot.log && " clearlog1 = ": > ./bot.log && "
clearlog2 = ": > ./bot.log"
command = ":" command = ":"
daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True) daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True)
@ -52,14 +53,14 @@ if daemon:
if backend == "daemon": if backend == "daemon":
start = "daemon -n cloudbot -O " + pwd + \ start = "daemon -n cloudbot -O " + pwd + \
"/bot.log -r python " + pwd + "/bot.py" "/bot.log -r python " + pwd + "/bot.py"
stop = clearlog + "daemon -n cloudbot --stop" stop = clearlog1 + "daemon -n cloudbot --stop"
restart = clearlog + "daemon -n cloudbot --restart" restart = clearlog1 + "daemon -n cloudbot --restart"
pid = "pidof /usr/bin/daemon" pid = "pidof /usr/bin/daemon"
elif backend == "screen": elif backend == "screen":
start = "screen -S cloudbot -dm python" + pwd +\ start = "screen -S cloudbot -dm python" + pwd +\
"/bot.py >>" + pwd + "/bot.log 2>&1" "/bot.py >>" + pwd + "/bot.log 2>&1"
stop = clearlog + "kill `pidof /usr/bin/screen`" stop = clearlog1 + "kill `pidof /usr/bin/screen`"
restart = clearlog + "daemon -n cloudbot --restart" restart = clearlog1 + "daemon -n cloudbot --restart"
pid = "pidof /usr/bin/screen" pid = "pidof /usr/bin/screen"
else: else:
print error5 print error5
@ -67,13 +68,13 @@ elif screen:
if backend == "daemon": if backend == "daemon":
start = "daemon -n cloudbot -O " + pwd + \ start = "daemon -n cloudbot -O " + pwd + \
"/bot.log -r python " + pwd + "/bot.py" "/bot.log -r python " + pwd + "/bot.py"
stop = clearlog + "daemon -n cloudbot --stop" stop = clearlog1 + "daemon -n cloudbot --stop"
restart = stop + " && " + start restart = stop + " && " + start
pid = "pidof /usr/bin/daemon" pid = "pidof /usr/bin/daemon"
elif backend == "screen": elif backend == "screen":
start = "screen -S cloudbot -dm python" + pwd +\ start = "screen -S cloudbot -dm python" + pwd +\
"/bot.py >>" + pwd + "/bot.log 2>&1" "/bot.py >>" + pwd + "/bot.log 2>&1"
stop = clearlog + "kill `pidof /usr/bin/screen`" stop = clearlog1 + "kill `pidof /usr/bin/screen`"
restart = stop + " && " + start restart = stop + " && " + start
pid = "pidof /usr/bin/screen" pid = "pidof /usr/bin/screen"
else: else:
@ -109,6 +110,8 @@ try:
elif (sys.argv[1] == 'status'): elif (sys.argv[1] == 'status'):
command = pid command = pid
print green + "Bot is running! " + nocol print green + "Bot is running! " + nocol
elif (sys.argv[1] == 'clear'):
command = clearlog2
else: else:
print usage print usage
exit exit
@ -141,6 +144,8 @@ try:
print "Bot is not running, cannot restart!" print "Bot is not running, cannot restart!"
elif (sys.argv[1] == 'status'): elif (sys.argv[1] == 'status'):
print red + "Bot is not running!" + nocol print red + "Bot is not running!" + nocol
elif (sys.argv[1] == 'clear'):
command = clearlog2
else: else:
print usage print usage
exit exit

View file

@ -4,8 +4,8 @@ import sys
import os import os
import subprocess import subprocess
if os.path.isfile("./bot.log"): if os.path.isfile("./cloudbot"):
clear = ": >./bot.log" clear = "./cloudbot clear"
else: else:
clear = ":" clear = ":"

View file

@ -37,9 +37,9 @@ def restart(inp, input=None, db=None, notice=None):
sys.exit() sys.exit()
@hook.command @hook.command(autohelp=False)
def clear(inp, input=None, db=None, notice=None): def clear(inp, input=None, db=None, notice=None):
".clear -- Clears the bot's log" ".clear -- Clears the bot's log."
if not input.nick in input.bot.config["admins"]: if not input.nick in input.bot.config["admins"]:
notice("Only bot admins can use this command!") notice("Only bot admins can use this command!")
return return