sysinfo.py upgraded

This commit is contained in:
esef committed 2026-06-06 12:19:11 +03:00
1 parent aa7a2eb855
commit 086f4ce912
2 files changed
+79 -1

No files matched your search

+10 -1
View File
@@ -92,6 +92,15 @@
"detail": "re", "detail": "re",
"documentation": {} "documentation": {}
}, },
{
"label": "psutil",
"kind": 6,
"isExtraImport": true,
"importPath": "psutil",
"description": "psutil",
"detail": "psutil",
"documentation": {}
},
{ {
"label": "load_dotenv", "label": "load_dotenv",
"importPath": "dotenv", "importPath": "dotenv",
@@ -168,7 +177,7 @@
"kind": 6, "kind": 6,
"importPath": "cogs.sysinfo", "importPath": "cogs.sysinfo",
"description": "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", "detail": "cogs.sysinfo",
"documentation": {} "documentation": {}
}, },
+69
View File
@@ -2,6 +2,7 @@ import subprocess
import discord import discord
from discord.ext import commands from discord.ext import commands
import re import re
import psutil
class SysInfo(commands.Cog): class SysInfo(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
@@ -10,11 +11,79 @@ class SysInfo(commands.Cog):
def strip_ansi(self, text): def strip_ansi(self, text):
return re.sub(r'\x1b\[[0-9;]*[a-zA-Z]|\[[0-9]+[A-Z]', '', 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() @commands.command()
async def fetch(self, ctx): async def fetch(self, ctx):
result = subprocess.run(['fastfetch', '--pipe', '--logo', 'none'], capture_output=True, text=True) result = subprocess.run(['fastfetch', '--pipe', '--logo', 'none'], capture_output=True, text=True)
clean = self.strip_ansi(result.stdout) clean = self.strip_ansi(result.stdout)
await ctx.reply(f'```\n{clean}\n```') 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): async def setup(bot):
await bot.add_cog(SysInfo(bot)) await bot.add_cog(SysInfo(bot))