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(slug: str): game = GetGameByGameSlug(slug) if game: return f"**{game['displayname']}**\n- Status: **{CheckSystemdService(game['systemd'])}**\n- Slug: `{game['slug']}`" else: return False def CheckSystemdService(service : str): stat = subprocess.call(["systemctl", "is-active", "--quiet", service]) return "🟢 UP" if not bool(stat) else "🔴 down" 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 `info`: List all available games, their status and their __ `start `: Start game with slug __ `stop `: Stop game with slug __ `restart `: Stop game with slug __ `status `: Show status for game with slug __"""