FireBot/core.py

43 lines
987 B
Python
Raw Normal View History

2023-10-23 22:10:07 +00:00
#!/usr/bin/python3
from os import system
from time import sleep
from sys import argv as args
from threading import Thread
def launch(server: str) -> None:
system(f"python3 -u ircbot.py {server}")
2023-10-23 22:10:07 +00:00
threads = {}
servers = [
"ircnow",
"replirc",
2023-10-23 22:23:53 +00:00
# "efnet",
2023-10-23 22:10:07 +00:00
]
def is_dead(thr):
thr.join(timeout=0)
return not thr.is_alive()
def start(server):
t = Thread(target=launch, args=(server,))
t.daemon = True
t.start()
return t
2023-10-23 22:10:07 +00:00
if __name__ == "__main__":
print("[LOG][CORE] Begin initialization")
for server in servers:
threads[server] = start(server)
2023-10-23 22:10:07 +00:00
print("[LOG][CORE] Started all instances. Idling...")
while 1:
sleep(60)
print("[LOG][CORE] Running a checkup on all running instances")
2023-10-23 22:10:07 +00:00
for server in threads:
t = threads[server]
if is_dead(t):
print(f"[LOG][CORE] The thread for {server} died, restarting it...")
threads[server] = start(server)