from config import config import subprocess def BuildGameList(): retlist = "List of currently manageable games:\n\n" gamearray = [] for game in config['games']: line = f"**{game['displayname']}**\n- Status: **{CheckSystemdService(game['systemd'])}**\n- Slug: `{game['slug']}`" gamearray.append(line) retlist = retlist + "\n".join(gamearray) return retlist def BuildSingleGameStatus(game): return f"**{game['displayname']}**\n- Status: **{CheckSystemdService(game['systemd'])}**\n- Slug: `{game['slug']}`" 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): stat = subprocess.call(["systemctl", action, "--quiet", service]) return not bool(stat) def BuildHelpList(): return """Bot has the following commands: `help`: Get this help message `info`: List all available games, their status and their slug `start `: Start game with slug __ `stop `: Stop game with slug __ `restart `: Stop game with slug __ `status `: Show status for game with slug __ """