log.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from datetime import datetime
  2. import aiofiles
  3. from pyrogram import filters
  4. from pyrogram.types import CallbackQuery, Message
  5. from wbb import SUDOERS, app, log_file
  6. from wbb.core.keyboard import ikb
  7. from wbb.utils.pastebin import paste
  8. callback = "log_paste"
  9. @app.on_message(filters.command("logs") & filters.user(SUDOERS))
  10. async def logs_chat(_, message):
  11. keyboard = ikb([[("📎 Pastebin 📎", callback)]])
  12. time = (datetime.now()).strftime("%d/%m/%Y %H:%M:%S")
  13. caption = f"""
  14. **Time:** `{time}`
  15. **Log Type:** `ERROR`
  16. """
  17. try:
  18. await message.reply_document(
  19. log_file, caption=caption, reply_markup=keyboard
  20. )
  21. except ValueError:
  22. await message.reply_text("**LOGS ARE EMPTY**")
  23. @app.on_callback_query(filters.regex(callback))
  24. async def paste_log_neko(_, cq: CallbackQuery):
  25. if cq.from_user.id not in SUDOERS:
  26. return await cq.answer(
  27. "Stop clicking at whichever thing you come across."
  28. )
  29. async with aiofiles.open(log_file, mode="r") as f:
  30. link = await paste(await f.read())
  31. message: Message = cq.message
  32. return await message.edit_caption(
  33. f"{message.caption.markdown}\n**Paste:** {link}"
  34. )