File size: 6,162 Bytes
a8e9b84 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
import platform
from sys import version as pyver
import psutil
from pyrogram import __version__ as pyrover
from pyrogram import filters
from pyrogram.errors import MessageIdInvalid
from pyrogram.types import InputMediaPhoto, Message
from pytgcalls.__version__ import __version__ as pytgver
import config
from DragMusic import app
from DragMusic.core.userbot import assistants
from DragMusic.misc import SUDOERS, mongodb
from DragMusic.plugins import ALL_MODULES
from DragMusic.utils.database import get_served_chats, get_served_users, get_sudoers
from DragMusic.utils.decorators.language import language, languageCB
from DragMusic.utils.inline.stats import back_stats_buttons, stats_buttons
from config import BANNED_USERS, OWNER_ID
@app.on_message(filters.command(["stats", "gstats"]) & ~BANNED_USERS)
@language
async def stats_global(client, message: Message, _):
# Allow sudo users and owner to use it from anywhere
if message.from_user.id not in SUDOERS and message.from_user.id != OWNER_ID:
# Restrict access to only the group with username @dragbackup
if message.chat.username != "dragbackup":
return await message.reply_text(
"Tʜɪs ᴄᴏᴍᴍᴀɴᴅ ᴄᴀɴ ᴏɴʟʏ ʙᴇ ᴜsᴇᴅ ɪɴ ᴛʜᴇ @ᴅʀᴀɢʙᴀᴄᴋᴜᴘ .."
)
upl = stats_buttons(_, True)
await message.reply_photo(
photo=config.STATS_IMG_URL,
caption=_["gstats_2"].format(app.mention),
reply_markup=upl,
)
@app.on_callback_query(filters.regex("stats_back") & ~BANNED_USERS)
@languageCB
async def home_stats(client, CallbackQuery, _):
# Allow sudo users and owner to use it from anywhere
if CallbackQuery.from_user.id not in SUDOERS and CallbackQuery.from_user.id != OWNER_ID:
# Restrict access to only the group with username @dragbackup
if CallbackQuery.message.chat.username != "dragbackup":
return await CallbackQuery.answer("Tʜɪs ᴄᴏᴍᴍᴀɴᴅ ᴄᴀɴ ᴏɴʟʏ ʙᴇ ᴜsᴇᴅ ɪɴ ᴛʜᴇ @ᴅʀᴀɢʙᴀᴄᴋᴜᴘ ɢʀᴏᴜᴘ.", show_alert=True)
upl = stats_buttons(_, True)
await CallbackQuery.edit_message_text(
text=_["gstats_2"].format(app.mention),
reply_markup=upl,
)
@app.on_callback_query(filters.regex("TopOverall") & ~BANNED_USERS)
@languageCB
async def overall_stats(client, CallbackQuery, _):
# Allow sudo users and owner to use it from anywhere
if CallbackQuery.from_user.id not in SUDOERS and CallbackQuery.from_user.id != OWNER_ID:
# Restrict access to only the group with username @dragbackup
if CallbackQuery.message.chat.username != "dragbackup":
return await CallbackQuery.answer("Tʜɪs ᴄᴏᴍᴍᴀɴᴅ ᴄᴀɴ ᴏɴʟʏ ʙᴇ ᴜsᴇᴅ ɪɴ ᴛʜᴇ @ᴅʀᴀɢʙᴀᴄᴋᴜᴘ ɢʀᴏᴜᴘ.", show_alert=True)
await CallbackQuery.answer()
upl = back_stats_buttons(_)
try:
await CallbackQuery.answer()
except:
pass
await CallbackQuery.edit_message_text(_["gstats_1"].format(app.mention))
served_chats = len(await get_served_chats())
served_users = len(await get_served_users())
text = _["gstats_3"].format(
app.mention,
len(assistants),
len(BANNED_USERS),
served_chats,
served_users,
len(ALL_MODULES),
len(SUDOERS),
config.AUTO_LEAVING_ASSISTANT,
config.DURATION_LIMIT_MIN,
)
med = InputMediaPhoto(media=config.STATS_IMG_URL, caption=text)
try:
await CallbackQuery.edit_message_media(media=med, reply_markup=upl)
except MessageIdInvalid:
await CallbackQuery.message.reply_photo(
photo=config.STATS_IMG_URL, caption=text, reply_markup=upl
)
@app.on_callback_query(filters.regex("bot_stats_sudo"))
@languageCB
async def bot_stats(client, CallbackQuery, _):
# Allow sudo users and owner to use it from anywhere
if CallbackQuery.from_user.id not in SUDOERS and CallbackQuery.from_user.id != OWNER_ID:
# Restrict access to only the group with username @dragbackup
if CallbackQuery.message.chat.username != "dragbackup":
return await CallbackQuery.answer("Tʜɪs ᴄᴏᴍᴍᴀɴᴅ ᴄᴀɴ ᴏɴʟʏ ʙᴇ ᴜsᴇᴅ ɪɴ ᴛʜᴇ @ᴅʀᴀɢʙᴀᴄᴋᴜᴘ ɢʀᴏᴜᴘ.", show_alert=True)
upl = back_stats_buttons(_)
try:
await CallbackQuery.answer()
except:
pass
await CallbackQuery.edit_message_text(_["gstats_1"].format(app.mention))
p_core = psutil.cpu_count(logical=False)
t_core = psutil.cpu_count(logical=True)
ram = str(round(psutil.virtual_memory().total / (1024.0**3))) + " ɢʙ"
try:
cpu_freq = psutil.cpu_freq().current
if cpu_freq >= 1000:
cpu_freq = f"{round(cpu_freq / 1000, 2)}ɢʜᴢ"
else:
cpu_freq = f"{round(cpu_freq, 2)}ᴍʜᴢ"
except:
cpu_freq = "ғᴀɪʟᴇᴅ ᴛᴏ ғᴇᴛᴄʜ"
hdd = psutil.disk_usage("/")
total = hdd.total / (1024.0**3)
used = hdd.used / (1024.0**3)
free = hdd.free / (1024.0**3)
call = await mongodb.command("dbstats")
datasize = call["dataSize"] / 1024
storage = call["storageSize"] / 1024
served_chats = len(await get_served_chats())
served_users = len(await get_served_users())
text = _["gstats_5"].format(
app.mention,
len(ALL_MODULES),
platform.system(),
ram,
p_core,
t_core,
cpu_freq,
pyver.split()[0],
pyrover,
pytgver,
str(total)[:4],
str(used)[:4],
str(free)[:4],
served_chats,
served_users,
len(BANNED_USERS),
len(await get_sudoers()),
str(datasize)[:6],
storage,
call["collections"],
call["objects"],
)
med = InputMediaPhoto(media=config.STATS_IMG_URL, caption=text)
try:
await CallbackQuery.edit_message_media(media=med, reply_markup=upl)
except MessageIdInvalid:
await CallbackQuery.message.reply_photo(
photo=config.STATS_IMG_URL, caption=text, reply_markup=upl
)
|