antiservice.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Written By [MaskedVirus | swatv3nub] for William and Ryūga
  2. # Kang With Proper Credits
  3. from pyrogram import filters
  4. from wbb import app
  5. from wbb.core.decorators.permissions import adminsOnly
  6. from wbb.utils.dbfunctions import (
  7. antiservice_off,
  8. antiservice_on,
  9. is_antiservice_on,
  10. )
  11. __MODULE__ = "服务消息清理"
  12. __HELP__ = """
  13. 自动删除成员加入、退出、置顶等群服务消息。
  14. /antiservice [开启|关闭]
  15. """
  16. @app.on_message(filters.command("antiservice") & ~filters.private)
  17. @adminsOnly("can_change_info")
  18. async def anti_service(_, message):
  19. if len(message.command) != 2:
  20. return await message.reply_text(
  21. "用法:/antiservice [开启|关闭]"
  22. )
  23. status = message.text.split(None, 1)[1].strip()
  24. status = status.lower()
  25. status = {
  26. "开启": "enable",
  27. "打开": "enable",
  28. "关闭": "disable",
  29. }.get(status, status)
  30. chat_id = message.chat.id
  31. if status == "enable":
  32. await antiservice_on(chat_id)
  33. await message.reply_text(
  34. "服务消息自动清理已开启。"
  35. )
  36. elif status == "disable":
  37. await antiservice_off(chat_id)
  38. await message.reply_text(
  39. "服务消息自动清理已关闭。"
  40. )
  41. else:
  42. await message.reply_text(
  43. "参数无效,用法:/antiservice [开启|关闭]"
  44. )
  45. @app.on_message(filters.service, group=11)
  46. async def delete_service(_, message):
  47. chat_id = message.chat.id
  48. try:
  49. if await is_antiservice_on(chat_id):
  50. return await message.delete()
  51. except Exception:
  52. pass