tools/restart_server.py

26 lines
882 B
Python
Executable File

#!/usr/bin/env python3
import time
import sys
import datetime
from mcrcon import MCRcon
from CONFIG import HOST,PW,PORT
autosave_on=False
with MCRcon(HOST, PW, port=PORT) as mcr:
current_time = datetime.datetime.now().strftime("%H:%M")
resp = mcr.command("say {}: Server will restart in §a10§f minutes".format(current_time))
time.sleep(30)
current_time = datetime.datetime.now().strftime("%H:%M")
resp = mcr.command("say {}: Server will restart in §e5§f minutes".format(current_time))
time.sleep(24)
current_time = datetime.datetime.now().strftime("%H:%M")
resp = mcr.command("say {}: Server will restart in §61§f minute".format(current_time))
time.sleep(5)
for i in range(10):
resp = mcr.command("say Server will restart in §4{}§f seconds".format(10-i))
time.sleep(1)
resp = mcr.command("restart")
sys.exit(0)