Spaces:
Paused
Paused
File size: 10,893 Bytes
5321464 | 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | """
plugins/extra_admin.py β Comandos administrativos extra.
Comandos:
.join <enlace> β Unirse a un canal/grupo via enlace
.leave [chat_id] β Abandonar un chat (default: chat actual)
.chatinfo [chat_id] β Info detallada del chat
.server β CPU, RAM, disco + speedtest
.clear β Limpia el directorio temp/downloads
.dlmusic <url> β Descarga mΓΊsica de Spotify (requiere spotdl)
.stopdl β Cancela la descarga de mΓΊsica en curso
"""
import asyncio
import os
import shutil
from pathlib import Path
import aiohttp
from pyrogram import filters
from pyrogram.errors import RPCError
from pyrogram.types import Message
from bot import app
from config import Config
P = Config.CMD_PREFIX
# Tarea de descarga activa
_dl_task: asyncio.Task | None = None
async def _tmp(client, chat_id: int, text: str, delay: int = 8):
m = await client.send_message(chat_id, text)
await asyncio.sleep(delay)
await m.delete()
# ββ .join βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@app.on_message(filters.me & filters.command("join", prefixes=P))
async def cmd_join(client, msg: Message):
await msg.delete()
args = msg.text.split(None, 1)
if len(args) < 2:
await _tmp(client, msg.chat.id,
f"β **Uso:** `{P}join <enlace>`\nEj: `{P}join https://t.me/+ABC123`")
return
link = args[1].strip()
status = await client.send_message(msg.chat.id, f"π UniΓ©ndome a `{link}`...")
try:
chat = await client.join_chat(link)
await status.edit(
f"β
**Β‘Unido!**\n\n"
f"π **Nombre:** {chat.title}\n"
f"π **ID:** `{chat.id}`\n"
f"π **Tipo:** `{chat.type}`"
)
except Exception as e:
await status.edit(f"β **Error al unirse:** `{e}`")
await asyncio.sleep(8)
await status.delete()
# ββ .leave ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@app.on_message(filters.me & filters.command("leave", prefixes=P))
async def cmd_leave(client, msg: Message):
await msg.delete()
args = msg.text.split(None, 1)
chat_id = int(args[1].strip()) if len(args) > 1 else msg.chat.id
try:
await client.leave_chat(chat_id)
await _tmp(client, msg.chat.id, f"π **Abandonado el chat** `{chat_id}`.")
except Exception as e:
await _tmp(client, msg.chat.id, f"β `{e}`")
# ββ .chatinfo βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@app.on_message(filters.me & filters.command("chatinfo", prefixes=P))
async def cmd_chatinfo(client, msg: Message):
await msg.delete()
args = msg.text.split(None, 1)
chat_id = int(args[1].strip()) if len(args) > 1 else msg.chat.id
try:
chat = await client.get_chat(chat_id)
members = getattr(chat, "members_count", "?")
desc = getattr(chat, "description", "") or ""
uname = f"@{chat.username}" if getattr(chat, "username", None) else "sin username"
text = (
f"π¬ **InformaciΓ³n del chat**\n\n"
f"π **Nombre:** {chat.title or 'N/A'}\n"
f"π **ID:** `{chat.id}`\n"
f"π **Tipo:** `{chat.type}`\n"
f"π **Username:** {uname}\n"
f"π₯ **Miembros:** `{members}`\n"
)
if desc:
text += f"\nπ **DescripciΓ³n:**\n_{desc[:300]}_"
m = await client.send_message(msg.chat.id, text)
await asyncio.sleep(12)
await m.delete()
except Exception as e:
await _tmp(client, msg.chat.id, f"β `{e}`")
# ββ .server βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@app.on_message(filters.me & filters.command("server", prefixes=P))
async def cmd_server(client, msg: Message):
await msg.delete()
def bar(pct):
filled = round(pct / 100 * 8)
return "β" * filled + "β" * (8 - filled)
# --- Info bΓ‘sica ---
try:
import psutil
cpu = psutil.cpu_percent(interval=0.5)
cores = psutil.cpu_count()
ram = psutil.virtual_memory()
disk = psutil.disk_usage("/")
sysinfo = (
f"**π₯οΈ Servidor**\n\n"
f"βοΈ **CPU:** `{cpu:.1f}%` `{bar(cpu)}` `{cores} nΓΊcleos`\n"
f"π§ **RAM:** `{ram.percent:.1f}%` `{bar(ram.percent)}`\n"
f" β `{ram.used/1024**3:.1f}` / `{ram.total/1024**3:.1f} GB`\n"
f"πΎ **Disco:** `{disk.percent:.1f}%` `{bar(disk.percent)}`\n"
f" β `{disk.used/1024**3:.1f}` / `{disk.total/1024**3:.1f} GB`\n\n"
f"β‘ **Speedtest:** ejecutando..."
)
except ImportError:
import platform
sysinfo = (
f"π Python `{platform.python_version()}` | "
f"π§ `{platform.system()} {platform.release()}`\n\n"
f"β‘ **Speedtest:** ejecutando..."
)
status = await client.send_message(msg.chat.id, sysinfo)
# --- Speedtest ---
try:
import speedtest as st_lib
loop = asyncio.get_event_loop()
def _run_speedtest():
s = st_lib.Speedtest()
s.get_best_server()
down = s.download()
up = s.upload()
srv = s.results.server
return down, up, srv
down, up, srv = await loop.run_in_executor(None, _run_speedtest)
server_name = srv.get("sponsor", "?") if srv else "?"
country = srv.get("country", "?") if srv else "?"
speed_text = (
f"\nπ₯ **Bajada:** `{down/1e6:.1f} Mbps`\n"
f"π€ **Subida:** `{up/1e6:.1f} Mbps`\n"
f"π **Servidor:** `{server_name}` ({country})"
)
await status.edit(sysinfo.replace("β‘ **Speedtest:** ejecutando...", "β‘ **Speedtest:**" + speed_text))
except Exception as e:
await status.edit(sysinfo.replace("ejecutando...", f"error: `{e}`"))
await asyncio.sleep(60)
await status.delete()
# ββ .clear ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@app.on_message(filters.me & filters.command("clear", prefixes=P))
async def cmd_clear(client, msg: Message):
await msg.delete()
count = 0
for d in ("temp", "downloads"):
p = Path(d)
if p.exists():
for f in p.iterdir():
try:
if f.is_file():
f.unlink(); count += 1
elif f.is_dir():
shutil.rmtree(f); count += 1
except Exception:
pass
await _tmp(client, msg.chat.id, f"ποΈ **{count}** archivo(s) eliminados de temp/downloads.")
# ββ .dlmusic ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@app.on_message(filters.me & filters.command("dlmusic", prefixes=P))
async def cmd_dlmusic(client, msg: Message):
global _dl_task
await msg.delete()
args = msg.text.split(None, 1)
if len(args) < 2:
await _tmp(client, msg.chat.id,
f"β **Uso:** `{P}dlmusic <url_spotify>`\n"
"Acepta: canciΓ³n, playlist, Γ‘lbum, artista")
return
url = args[1].strip()
status = await client.send_message(msg.chat.id, f"π΅ **Iniciando descarga de Spotify...**\n`{url}`")
try:
from spotdl import Spotdl
from spotdl.utils.spotify import SpotifyClient
cid = Config.SPOTIFY_CLIENT_ID
cs = Config.SPOTIFY_CLIENT_SECRET
if not cid or not cs:
await status.edit(
"β **SPOTIFY_CLIENT_ID** y **SPOTIFY_CLIENT_SECRET** no configurados.\n"
"Crea tu app en developer.spotify.com/dashboard"
)
return
out_dir = Path("downloads/spotify")
out_dir.mkdir(parents=True, exist_ok=True)
async def _download():
loop = asyncio.get_event_loop()
def _sync():
spot = Spotdl(client_id=cid, client_secret=cs, downloader_settings={"output": str(out_dir)})
songs = spot.search([url])
results = spot.download_songs(songs)
return results
return await loop.run_in_executor(None, _sync)
_dl_task = asyncio.create_task(_download())
await status.edit("β¬οΈ **Descargando...** usa `.stopdl` para cancelar.")
results = await _dl_task
_dl_task = None
sent = 0
for song, path in results:
if path:
await client.send_audio(
msg.chat.id, str(path),
title=getattr(song, "name", None),
performer=", ".join(getattr(song, "artists", [])),
)
sent += 1
await status.edit(f"β
**{sent}** canciΓ³n(es) descargadas y enviadas.")
await asyncio.sleep(6)
await status.delete()
except asyncio.CancelledError:
await status.edit("β **Descarga cancelada.**")
await asyncio.sleep(5)
await status.delete()
except ImportError:
await status.edit(
"β **spotdl** no instalado.\n"
"AΓ±ade `spotdl` a requirements.txt."
)
except Exception as e:
await status.edit(f"β **Error:** `{e}`")
await asyncio.sleep(8)
await status.delete()
# ββ .stopdl βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@app.on_message(filters.me & filters.command("stopdl", prefixes=P))
async def cmd_stopdl(client, msg: Message):
global _dl_task
await msg.delete()
if _dl_task and not _dl_task.done():
_dl_task.cancel()
await _tmp(client, msg.chat.id, "β **Descarga de mΓΊsica cancelada.**")
else:
await _tmp(client, msg.chat.id, "βΉοΈ No hay ninguna descarga activa.")
|