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 config import config
|
||||||
from lib import *
|
from lib import *
|
||||||
|
|
||||||
|
@ -28,23 +29,35 @@ async def on_message(message):
|
||||||
if message.content == f"{client.user.mention} ping":
|
if message.content == f"{client.user.mention} ping":
|
||||||
await message.channel.send(f"{message.author.mention} ")
|
await message.channel.send(f"{message.author.mention} ")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
#if message.content == f"{client.user.mention} version":
|
||||||
|
# await message.channel.send(f"{message.author.mention} ")
|
||||||
|
# return
|
||||||
|
|
||||||
# Handle @Bot mention
|
# Handle @Bot mention
|
||||||
messagearray = message.content.split()
|
messagearray = message.content.split()
|
||||||
if messagearray[0] == client.user.mention:
|
if messagearray[0] == client.user.mention:
|
||||||
messagearray.pop(0)
|
messagearray.pop(0)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if messagearray[0] == "help":
|
if messagearray[0] == "help":
|
||||||
await message.channel.send(BuildHelpList())
|
await message.channel.send(BuildHelpList())
|
||||||
return
|
return
|
||||||
if messagearray[0] == "list":
|
if messagearray[0] in ["list", "info"]:
|
||||||
await message.channel.send(BuildGameList())
|
await message.channel.send(BuildGameList())
|
||||||
return
|
return
|
||||||
|
|
||||||
if messagearray[0] in ["start", "stop", "restart"] and len(messagearray) >= 2:
|
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:
|
# :white_check_mark: :x:
|
||||||
if success:
|
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")
|
await message.channel.send(f"Sorry {message.author.mention}, that didn't work. Ping @lauralani")
|
||||||
|
|
||||||
if messagearray[0] == "status":
|
if messagearray[0] == "status":
|
||||||
await message.channel.send(BuildSingleGameStatus())
|
await message.channel.send(BuildSingleGameStatus(messagearray[1]))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
11
lib.py
11
lib.py
|
@ -18,11 +18,16 @@ def CheckSystemdService(service : str):
|
||||||
stat = subprocess.call(["systemctl", "is-active", "--quiet", service])
|
stat = subprocess.call(["systemctl", "is-active", "--quiet", service])
|
||||||
return "🟢 UP" if not bool(stat) else "🔴 down"
|
return "🟢 UP" if not bool(stat) else "🔴 down"
|
||||||
|
|
||||||
def HandleSystemdService(service : str, action : str):
|
def HandleSystemdService(game, action : str):
|
||||||
#TODO: Check service constraint !important
|
stat = subprocess.call(["systemctl", action, "--quiet", game['systemd']])
|
||||||
stat = subprocess.call(["systemctl", action, "--quiet", service])
|
|
||||||
return not bool(stat)
|
return not bool(stat)
|
||||||
|
|
||||||
|
def GetGameByGameSlug(slug : str):
|
||||||
|
for game in config['games']:
|
||||||
|
if game['slug'] == slug:
|
||||||
|
return game
|
||||||
|
return False
|
||||||
|
|
||||||
def BuildHelpList():
|
def BuildHelpList():
|
||||||
return """Bot has the following commands:
|
return """Bot has the following commands:
|
||||||
`help`: Get this help message
|
`help`: Get this help message
|
||||||
|
|
Loading…
Reference in a new issue