userbotsaske / modules /chat.py
saske560's picture
Upload 15 files
1fefee0 verified
Raw History Blame Contribute Delete
2.3 kB
import html
def setup(registry):
async def say_cmd(ctx):
text = await ctx.require_text("Escribe el texto a enviar con <code>.say mensaje</code>.")
if not text:
return
if ctx.reply:
await ctx.reply.reply_text(text, disable_web_page_preview=True)
else:
await ctx.client.send_message(ctx.message.chat.id, text, disable_web_page_preview=True)
await ctx.maybe_delete_command()
try:
await ctx.message.delete()
except Exception:
pass
async def purge_cmd(ctx):
amount = 5
if ctx.args.strip().isdigit():
amount = max(1, min(100, int(ctx.args.strip())))
deleted = 0
ids = []
async for msg in ctx.client.get_chat_history(ctx.message.chat.id, limit=amount + 25):
is_self = bool(getattr(msg.from_user, "is_self", False)) or bool(msg.outgoing)
if is_self:
ids.append(msg.id)
deleted += 1
if deleted >= amount:
break
if ctx.message.id not in ids:
ids.append(ctx.message.id)
if not ids:
await ctx.respond("⚠️ No encontré mensajes tuyos para borrar.")
return
await ctx.client.delete_messages(ctx.message.chat.id, ids, revoke=True)
async def pin_cmd(ctx):
if not ctx.reply:
await ctx.respond("⚠️ Responde a un mensaje para fijarlo.")
return
await ctx.reply.pin(disable_notification=True)
await ctx.respond("📌 Mensaje fijado correctamente.")
async def unpin_cmd(ctx):
if ctx.reply:
await ctx.reply.unpin()
else:
await ctx.client.unpin_all_chat_messages(ctx.message.chat.id)
await ctx.respond("📍 Hecho.")
registry.add("say", say_cmd, "Envía un texto limpio y borra el comando.", usage=".say hola", aliases=["echo"], category="Chat")
registry.add("purge", purge_cmd, "Borra tus últimos mensajes en el chat.", usage=".purge 10", category="Chat")
registry.add("pin", pin_cmd, "Fija el mensaje respondido.", usage=".pin (reply)", category="Chat")
registry.add("unpin", unpin_cmd, "Desfija el reply o todos si no respondes.", usage=".unpin", category="Chat")