Add stats server

This commit is contained in:
yasir 2023-02-15 12:07:21 +07:00
parent b35acc0a0d
commit 3297e1b339
3 changed files with 31 additions and 6 deletions

View file

@ -18,7 +18,7 @@ def ratelimiter(func: Callable) -> Callable:
@wraps(func) @wraps(func)
async def decorator(client: Client, update: Union[Message, CallbackQuery]): async def decorator(client: Client, update: Union[Message, CallbackQuery]):
userid = update.from_user.id if update.from_user else update.sender_chat.id userid = update.from_user.id or update.sender_chat.id
is_limited = await ratelimit.acquire(userid) is_limited = await ratelimit.acquire(userid)
if is_limited and userid not in warned_users: if is_limited and userid not in warned_users:

View file

@ -4,13 +4,19 @@ import os
import sys import sys
import pickle import pickle
import traceback import traceback
from shutil import disk_usage
from time import time
from inspect import getfullargspec from inspect import getfullargspec
from psutil import cpu_percent
from psutil import disk_usage as disk_usage_percent
from psutil import virtual_memory
from pyrogram import enums, filters from pyrogram import enums, filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from misskaty import app, user from misskaty import app, user, botStartTime, BOT_NAME
from misskaty.helper import http from misskaty.helper import http, get_readable_file_size, get_readable_time
from misskaty.core.message_utils import editPesan, kirimPesan from misskaty.core.message_utils import editPesan, kirimPesan
from misskaty.vars import COMMAND_HANDLER, SUDO from misskaty.vars import COMMAND_HANDLER, SUDO
from utils import LOGGER from utils import LOGGER
@ -71,9 +77,28 @@ async def balas(c, m):
await m.reply(pesan[1], reply_to_message_id=m.reply_to_message.id) await m.reply(pesan[1], reply_to_message_id=m.reply_to_message.id)
@app.on_message(filters.command(["neofetch"], COMMAND_HANDLER) & filters.user(SUDO)) @app.on_message(filters.command(["stats"], COMMAND_HANDLER) & filters.user(SUDO))
async def neofetch(c, m): async def server_stats(c, m):
"""
Give system stats of the server.
"""
currentTime = get_readable_time(time() - botStartTime)
total, used, free = disk_usage(".")
total = get_readable_file_size(total)
used = get_readable_file_size(used)
free = get_readable_file_size(free)
neofetch = (await shell_exec("neofetch --stdout"))[0] neofetch = (await shell_exec("neofetch --stdout"))[0]
caption = f"""
**{BOT_NAME} is Up and Running successfully.**
Bot Uptime: `{currentTime}`
Total Disk Space: `{total}`
Used: `{used}({disk_usage_percent("/").percent}%)`
Free: `{free}`
CPU Usage: `{cpu_percent()}%`
RAM Usage: `{virtual_memory().percent}%`
`{neofetch}`
"""
await m.reply(f"<code>{neofetch}</code>") await m.reply(f"<code>{neofetch}</code>")

View file

@ -27,7 +27,7 @@ async def take_ss(_, m):
msg = await m.reply("Capturing screenshot...") msg = await m.reply("Capturing screenshot...")
try: try:
url = f"https://webss.yasirapi.eu.org/api?url={url}&width=1280&height=720" url = f"https://webss.yasirapi.eu.org/api?url={url}&width=1280&height=720"
await gather(*[m.reply_document(url, file_name=filename), m.reply_photo(url, file_name=filename)]) await gather(*[m.reply_document(url, file_name=filename), m.reply_photo(url)])
await hapusPesan(m) await hapusPesan(m)
os.remove(filename) os.remove(filename)
except Exception as e: except Exception as e: