From 75caf959a3de4e859b7b640990abf4889958c111 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 1 Jul 2022 18:23:46 +0300 Subject: [PATCH] Add psutil --- cogs/mc_server.py | 27 ++++++++++++++++++++++++++- requirements.txt | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cogs/mc_server.py b/cogs/mc_server.py index 76ce132..7176502 100644 --- a/cogs/mc_server.py +++ b/cogs/mc_server.py @@ -3,7 +3,9 @@ from __future__ import annotations from typing import TYPE_CHECKING import discord -from discord.ext import commands +from discord.ext import commands, tasks +import subprocess +import psutil if TYPE_CHECKING: from bot import MinearchyBot @@ -17,6 +19,12 @@ class MinecraftServer( def __init__(self, bot: MinearchyBot) -> None: self.bot = bot + async def cog_load(self) -> None: + self.check_processes_up.start() + + async def cog_unload(self) -> None: + self.check_processes_up.cancel() + @commands.group( invoke_without_command=True, brief="Sends the server IP.", @@ -89,6 +97,23 @@ class MinecraftServer( ) await ctx.reply(view=view) + @tasks.loop(minutes=5) + async def check_processes_up(self) -> None: + pass + # pids = [ + # int(pid) + # for pid in subprocess.Popen( + # ["ps", "aux", "|", "grep", "java"], stdout=subprocess.PIPE + # ) + # .communicate()[0] + # .splitlines() + # ] + # await self.bot.log_webhook.send(f"```\n{pids!r}```") + # + # for pid in pids: + # if not psutil.pid_exists(pid): + # await self.bot.log_webhook.send(f"No such pid: {pid}") + async def setup(bot: MinearchyBot) -> None: await bot.add_cog(MinecraftServer(bot)) diff --git a/requirements.txt b/requirements.txt index e63cbba..82788ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ discord.py @ git+https://github.com/Rapptz/discord.py jishaku==2.5.0 mcstatus +psutil