taglogger.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 (
  24. BOT_ID,
  25. LOG_GROUP_ID,
  26. LOG_MENTIONS,
  27. USERBOT_ID,
  28. USERBOT_NAME,
  29. USERBOT_USERNAME,
  30. app,
  31. app2,
  32. )
  33. from wbb.core.decorators.errors import capture_err
  34. from wbb.utils.filter_groups import taglog_group
  35. __MODULE__ = "Tag Logger"
  36. __HELP__ = """
  37. THIS MODULE IS ONLY FOR SUDOERS
  38. This module logs every action that contains your id, name, username, mention.
  39. """
  40. IS_USERBOT_ONLINE = False
  41. @app2.on_user_status()
  42. async def statusUpdaterFunc(_, update):
  43. if update.id != USERBOT_ID:
  44. return
  45. global IS_USERBOT_ONLINE
  46. if update.status == "online":
  47. IS_USERBOT_ONLINE = True
  48. return
  49. IS_USERBOT_ONLINE = False
  50. async def sendLog(message: Message):
  51. msg = f"""
  52. **User:** {message.from_user.mention if message.from_user else None} [`{message.from_user.id if message.from_user else None}`]
  53. **Text:** {message.text.markdown if message.text else message.caption if message.caption else None}
  54. **Chat:** {message.chat.title} [`{message.chat.id}`]
  55. **Bot:** {message.from_user.is_bot}
  56. """
  57. button = InlineKeyboard(row_width=1)
  58. button.add(InlineKeyboardButton(text="Check Action", url=message.link))
  59. await app.send_message(LOG_GROUP_ID, text=msg, reply_markup=button)
  60. @app2.on_message(
  61. ~filters.me
  62. & ~filters.chat([LOG_GROUP_ID, BOT_ID])
  63. & ~filters.private
  64. & ~filters.edited,
  65. group=taglog_group,
  66. )
  67. @capture_err
  68. async def tagLoggerFunc(_, message: Message):
  69. if not LOG_MENTIONS:
  70. return
  71. if IS_USERBOT_ONLINE:
  72. return
  73. if message.reply_to_message:
  74. reply_message = message.reply_to_message
  75. if reply_message.from_user:
  76. if reply_message.from_user.id == USERBOT_ID:
  77. return await sendLog(message)
  78. if message.text:
  79. text = message.text
  80. elif message.caption:
  81. text = message.caption
  82. else:
  83. return
  84. if (
  85. str(USERBOT_ID) in text
  86. or str(USERBOT_USERNAME) in text
  87. or USERBOT_NAME in text
  88. ):
  89. await sendLog(message)