-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
36 lines (29 loc) · 1.05 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import asyncio
import os
import subprocess
check = "ps aux | grep bot.py | grep -v 'grep' | awk '{print $2}'"
async def main_bot_loop():
while True:
try:
if os.path.exists("ded.txt"):
os.remove("ded.txt")
break
process = subprocess.Popen(
check, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
stdout, stderr = process.communicate()
if not int.from_bytes(stdout, byteorder="big"):
print("Starting bot.")
if not os.path.exists("logs"):
os.mkdir("logs")
if os.name == "nt":
os.system("nohup python -OO bot.py >> logs/output.log 2>&1 &")
else:
os.system("nohup python3 -OO bot.py >> logs/output.log 2>&1 &")
else:
# Bot is already up
await asyncio.sleep(10)
except Exception as e:
print(e)
if __name__ == "__main__":
asyncio.run(main_bot_loop())