-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REQUEST] Server Restarting Message before regular restart #40
Comments
I run discord bot with RoR2DS on one VM. |
I completed Server autostop feature for me. By the way, I made autostop function post to discord before autostop. |
async def server_autostop(self):
n = 30
print('AutoStop enabled every ' + str(n) + ' minutes')
while True:
# 秒単位で待つ. n分
# n分ごとにサーバーのプレイ人数をチェックして、0人だったら終了する
await asyncio.sleep(60*n)
is_server_running = await server()
if (not is_server_running) or server_info.player_count == 0:
# stop RoR2DS first
await server_stop()
await asyncio.sleep(10)
if os.path.exists(BepInEx / "LogOutput.log"):
try:
os.remove(BepInEx / "LogOutput.log")
except Exception:
print('Unable to remove log file')
if os.path.exists(BepInEx / "LogOutput.log.offset"):
try:
os.remove(BepInEx / "LogOutput.log.offset")
except Exception:
print('Unable to remove offset! Chat may not work!')
# make POST request to Azure Automation
url = "Azure Automation Webhook(HTTP POST) Here"
data = {}
headers = {
'Content-Type': 'application/json',
}
try:
print("Start autostop function. Requesting Azure API")
request = urllib.request.Request(url, json.dumps(data).encode(), headers)
response = urllib.request.urlopen(request)
responseCode = response.getcode()
body = response.read()
# json = body.decode('utf-8')
print('Server Shutdown is requested because no one playing. ResponseCode: ' + str(responseCode) + "\n body: " + str(body))
except Exception as e:
print("error in requesting Azure API")
print(e)
print(traceback.format_exc())
# Post result to Discord
try:
print("Post to discord before auto server shutdown")
channel = config_object.getint('RoR2', 'channel')
channel = self.bot.get_channel(channel)
chatContent = 'しばらく誰も使っていないため、サーバーにシャットダウンリクエストを送ります。 \nresponseCode: ' + str(responseCode) + '\n responseBody: ' + str(body)
await channel.send(chatContent)
except Exception as e:
print("error in posting to discord before auto server shutdown")
print(e)
print(traceback.format_exc())
elif server_info.player_count > 0:
print('Players currently in server') |
(But this feature looks good when use with autorestart function) |
Thanks for showing the code you used to fix this! I'll look into maybe including this into the main program. Sorry I wasn't able to look into this today for you. Did that resolve your issue/can I close this? |
OK |
Before regular restart, I want Discord message like
'Server is restarting for maintenance. It takes less than 3 minutes'.
(My)Discord Members can understand that The server will come back soon.
The text was updated successfully, but these errors were encountered: