add constraint checks for game
This commit is contained in:
parent
bf6bf954e7
commit
8ea2231379
2 changed files with 24 additions and 6 deletions
19
app.py
19
app.py
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
from config import config
|
||||
from lib import *
|
||||
|
||||
|
@ -28,23 +29,35 @@ async def on_message(message):
|
|||
if message.content == f"{client.user.mention} ping":
|
||||
await message.channel.send(f"{message.author.mention} ")
|
||||
return
|
||||
|
||||
#if message.content == f"{client.user.mention} version":
|
||||
# await message.channel.send(f"{message.author.mention} ")
|
||||
# return
|
||||
|
||||
# Handle @Bot mention
|
||||
messagearray = message.content.split()
|
||||
if messagearray[0] == client.user.mention:
|
||||
messagearray.pop(0)
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
if messagearray[0] == "help":
|
||||
await message.channel.send(BuildHelpList())
|
||||
return
|
||||
if messagearray[0] == "list":
|
||||
if messagearray[0] in ["list", "info"]:
|
||||
await message.channel.send(BuildGameList())
|
||||
return
|
||||
|
||||
if messagearray[0] in ["start", "stop", "restart"] and len(messagearray) >= 2:
|
||||
success = HandleSystemdService(messagearray[1], messagearray[0])
|
||||
game = GetGameByGameSlug(messagearray[1])
|
||||
if not game:
|
||||
await message.add_reaction("❌")
|
||||
await message.channel.send(f"Invalid game: {messagearray[1]}")
|
||||
return
|
||||
success = HandleSystemdService(game, messagearray[0])
|
||||
|
||||
# :white_check_mark: :x:
|
||||
if success:
|
||||
|
@ -54,7 +67,7 @@ async def on_message(message):
|
|||
await message.channel.send(f"Sorry {message.author.mention}, that didn't work. Ping @lauralani")
|
||||
|
||||
if messagearray[0] == "status":
|
||||
await message.channel.send(BuildSingleGameStatus())
|
||||
await message.channel.send(BuildSingleGameStatus(messagearray[1]))
|
||||
return
|
||||
|
||||
|
||||
|
|
11
lib.py
11
lib.py
|
@ -18,11 +18,16 @@ def CheckSystemdService(service : str):
|
|||
stat = subprocess.call(["systemctl", "is-active", "--quiet", service])
|
||||
return "🟢 UP" if not bool(stat) else "🔴 down"
|
||||
|
||||
def HandleSystemdService(service : str, action : str):
|
||||
#TODO: Check service constraint !important
|
||||
stat = subprocess.call(["systemctl", action, "--quiet", service])
|
||||
def HandleSystemdService(game, action : str):
|
||||
stat = subprocess.call(["systemctl", action, "--quiet", game['systemd']])
|
||||
return not bool(stat)
|
||||
|
||||
def GetGameByGameSlug(slug : str):
|
||||
for game in config['games']:
|
||||
if game['slug'] == slug:
|
||||
return game
|
||||
return False
|
||||
|
||||
def BuildHelpList():
|
||||
return """Bot has the following commands:
|
||||
`help`: Get this help message
|
||||
|
|
Loading…
Reference in a new issue