From 086f4ce9125dcb56372fd48ef87532069a9ad1ff Mon Sep 17 00:00:00 2001 From: esefxdz Date: Sat, 6 Jun 2026 12:19:11 +0300 Subject: [PATCH] sysinfo.py upgraded --- .vscode/PythonImportHelper-v2-Completion.json | 11 ++- cogs/sysinfo.py | 69 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json index 272691e..38a5703 100644 --- a/.vscode/PythonImportHelper-v2-Completion.json +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -92,6 +92,15 @@ "detail": "re", "documentation": {} }, + { + "label": "psutil", + "kind": 6, + "isExtraImport": true, + "importPath": "psutil", + "description": "psutil", + "detail": "psutil", + "documentation": {} + }, { "label": "load_dotenv", "importPath": "dotenv", @@ -168,7 +177,7 @@ "kind": 6, "importPath": "cogs.sysinfo", "description": "cogs.sysinfo", - "peekOfCode": "class SysInfo(commands.Cog):\n def __init__(self, bot):\n self.bot = bot\n def strip_ansi(self, text):\n return re.sub(r'\\x1b\\[[0-9;]*[a-zA-Z]|\\[[0-9]+[A-Z]', '', text)\n @commands.command()\n async def fetch(self, ctx):\n result = subprocess.run(['fastfetch', '--pipe', '--logo', 'none'], capture_output=True, text=True)\n clean = self.strip_ansi(result.stdout)\n await ctx.reply(f'```\\n{clean}\\n```')", + "peekOfCode": "class SysInfo(commands.Cog):\n def __init__(self, bot):\n self.bot = bot\n def strip_ansi(self, text):\n return re.sub(r'\\x1b\\[[0-9;]*[a-zA-Z]|\\[[0-9]+[A-Z]', '', text)\n #this command lists all the sysinfo commands, not an actualy sysinfo command##\n @commands.command()\n async def sysinfo(self, ctx):\n sys_commands = [f'!{cmd.name}' for cmd in self.get_commands()]\n await ctx.reply('\\n'.join(sys_commands))", "detail": "cogs.sysinfo", "documentation": {} }, diff --git a/cogs/sysinfo.py b/cogs/sysinfo.py index 78e103d..f851f98 100644 --- a/cogs/sysinfo.py +++ b/cogs/sysinfo.py @@ -2,6 +2,7 @@ import subprocess import discord from discord.ext import commands import re +import psutil class SysInfo(commands.Cog): def __init__(self, bot): @@ -9,6 +10,13 @@ class SysInfo(commands.Cog): def strip_ansi(self, text): return re.sub(r'\x1b\[[0-9;]*[a-zA-Z]|\[[0-9]+[A-Z]', '', text) + + #this command lists all the sysinfo commands, not an actualy sysinfo command## + @commands.command() + async def sysinfo(self, ctx): + sys_commands = [f'!{cmd.name}' for cmd in self.get_commands()] + await ctx.reply('\n'.join(sys_commands)) + ###################################################################### @commands.command() async def fetch(self, ctx): @@ -16,5 +24,66 @@ class SysInfo(commands.Cog): clean = self.strip_ansi(result.stdout) await ctx.reply(f'```\n{clean}\n```') + @commands.command() + async def uptime(self, ctx): + result = subprocess.run(['uptime', '-p'], capture_output=True, text=True) + await ctx.reply(f'⏱️ {result.stdout.strip()}') + + @commands.command() + async def temps(self, ctx): + result = subprocess.run(['sensors'], capture_output=True, text=True) + await ctx.reply(f'```\n{result.stdout}\n```') + + @commands.command() + async def gpu(self, ctx): + result = subprocess.run(['envycontrol', '--query'], capture_output=True, text=True) + await ctx.reply(f'I am on {result.stdout.strip()} mode esef!') + + @commands.command() + async def top(self, ctx): + result = subprocess.run(['ps', 'aux', '--sort=-%cpu'], capture_output=True, text=True) + lines = result.stdout.splitlines() + top5 = '\n'.join(lines[:6]) # header + 5 processes + await ctx.reply(f'```\n{top5}\n```') + + @commands.command() + async def mem(self, ctx): + mem = psutil.virtual_memory() + await ctx.reply(f'💾 Memory Usage: {mem.percent}% ({mem.used // (1024**2)}MB / {mem.total // (1024**2)}MB)') + + @commands.command() + async def cpu(self, ctx): + cpu_percent = psutil.cpu_percent(interval=1) + await ctx.reply(f'⚡ CPU Usage: {cpu_percent}%') + + @commands.command() + async def load(self, ctx): + load1, load5, load15 = psutil.getloadavg() + await ctx.reply(f'📊 Load Average: {load1:.2f}, {load5:.2f}, {load15:.2f}') + + @commands.command() + async def net(self, ctx): + net = psutil.net_io_counters() + await ctx.reply(f'📡 Network I/O: {net.bytes_sent} sent, {net.bytes_recv} received') + + @commands.command() + async def battery(self, ctx): + battery = psutil.sensors_battery() + if battery: + await ctx.reply(f'Battery: {battery.percent}% {"Charging" if battery.power_plugged else "Not Charging"}') + + @commands.command() + async def processes(self, ctx): + processes = psutil.pids() + await ctx.reply(f'Processes: {len(processes)} running processes ') + + @commands.command() + async def stats(self, ctx): + cpu = psutil.cpu_percent(interval=1) + ram = psutil.virtual_memory().percent + disk = psutil.disk_usage('/').percent + reply = f'CPU: {cpu}% | RAM: {ram}% | Disk: {disk}%' + await ctx.reply(reply) + async def setup(bot): await bot.add_cog(SysInfo(bot)) \ No newline at end of file