taglogger.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. """
  2. MIT License
  3. Copyright (c) 2021 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. from pykeyboard import InlineKeyboard
  21. from pyrogram import filters
  22. from pyrogram.types import InlineKeyboardButton, Message
  23. from wbb import (BOT_ID, LOG_GROUP_ID, LOG_MENTIONS, USERBOT_ID,
  24. USERBOT_NAME, USERBOT_USERNAME, app, app2)
  25. from wbb.core.decorators.errors import capture_err
  26. from wbb.utils.filter_groups import taglog_group
  27. IS_USERBOT_ONLINE = False
  28. @app2.on_user_status()
  29. async def statusUpdaterFunc(_, update):
  30. if update.id != USERBOT_ID:
  31. return
  32. global IS_USERBOT_ONLINE
  33. if update.status == "online":
  34. IS_USERBOT_ONLINE = True
  35. return
  36. IS_USERBOT_ONLINE = False
  37. async def sendLog(message: Message):
  38. msg = f"""
  39. **User:** {message.from_user.mention if message.from_user else None} [`{message.from_user.id if message.from_user else None}`]
  40. **Text:** {message.text.markdown if message.text else message.caption if message.caption else None}
  41. **Chat:** {message.chat.title} [`{message.chat.id}`]
  42. **Bot:** {message.from_user.is_bot}
  43. """
  44. button = InlineKeyboard(row_width=1)
  45. button.add(
  46. InlineKeyboardButton(text="Check Action", url=message.link)
  47. )
  48. await app.send_message(
  49. LOG_GROUP_ID,
  50. text=msg,
  51. reply_markup=button,
  52. disable_web_page_preview=True,
  53. )
  54. @app2.on_message(
  55. ~filters.me
  56. & ~filters.chat([LOG_GROUP_ID, BOT_ID])
  57. & ~filters.private
  58. & ~filters.edited,
  59. group=taglog_group,
  60. )
  61. @capture_err
  62. async def tagLoggerFunc(_, message: Message):
  63. if not LOG_MENTIONS:
  64. return
  65. if IS_USERBOT_ONLINE:
  66. return
  67. if message.reply_to_message:
  68. reply_message = message.reply_to_message
  69. if reply_message.from_user and (
  70. reply_message.from_user.id == USERBOT_ID
  71. ):
  72. return await sendLog(message)
  73. if message.text:
  74. text = message.text
  75. elif message.caption:
  76. text = message.caption
  77. else:
  78. return
  79. if (
  80. str(USERBOT_ID) in text
  81. or str(USERBOT_USERNAME) in text
  82. or USERBOT_NAME in text
  83. ):
  84. await sendLog(message)