Comments (6)
I run discord bot with RoR2DS on one VM.
So I want to make it clear whether mentenance, some accidents or VM shutdown.
from pyre-bot.
I completed Server autostop feature for me.
I'm setting server waits 30min to autostop.
I notice that the server autostop before autostart.
So this feature is Unnecessary right now. Sorry.ð
By the way, I made autostop function post to discord before autostop.
May be reusable, so I past here.
Code will tell more than my bad english.
from pyre-bot.
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')
from pyre-bot.
(But this feature looks good when use with autorestart function)
from pyre-bot.
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?
from pyre-bot.
OK
from pyre-bot.
Related Issues (20)
- [REQUEST] Log players overall activity on the Risk of Rain 2 server HOT 1
- [BUG] get_run_timer won't be accurate on the last player to leave HOT 1
- [BUG] No exceptions output when exception handling is working
- [REQUEST] Update setup.py to generate blank JSON files HOT 1
- Move user linking and stat tracking from JSON to database HOT 3
- [BUG] Bot not removing log files HOT 2
- [REQUEST] Allow single bot instance to control multiple servers HOT 3
- [BUG] Discord bot does not verify the existence of an item or equipment before passing on give_item or give_equip HOT 1
- [BUG] Stat tracking not working correctly HOT 1
- [BUG] Duplicate chat after reload HOT 3
- [REQUEST] Update setup script HOT 1
- [REQUEST] Add auto-update feature HOT 1
- [BUG] Documentation Out of date
- [REQUEST] Disable stat tracking by default HOT 1
- [REQUEST] Add update command HOT 1
- Roadmap for new branch "cloud" HOT 2
- [BUG] Regex removes chat text between parentheses
- [REQUEST] Command to stop server on lobby, notify admin
- [BUG] '>' prefix appears to be dysfunctional for commands
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
ð Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ððð
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â€ïž Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyre-bot.