misc.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import secrets
  2. import string
  3. from pyrogram import filters
  4. from pyrogram.types import Message
  5. from cryptography.fernet import Fernet
  6. from wbb.utils.botinfo import BOT_ID
  7. from wbb import app, FERNET_ENCRYPTION_KEY
  8. from wbb.utils import cust_filter, random_line
  9. __MODULE__ = "Misc"
  10. __HELP__ = '''/commit - Generate Funny Commit Messages
  11. /runs - Idk Test Yourself
  12. /quote - Get Random Linux Quotes
  13. /id - Get Chat_ID or User_ID
  14. /dev - Forward Anything To Developers [SPAM = GBAN]
  15. /random - Generate Random Complex Passwords
  16. /http - Get Cats Reference Photo For Http Error Codes
  17. /encrypt - Encrypt Text [Can Only Be Decrypted By This Bot]
  18. /decrypt - Decrypt Text'''
  19. @app.on_message(cust_filter.command(commands=("commit")) & ~filters.edited)
  20. async def commit(_, message: Message):
  21. await message.reply_text((await random_line('wbb/utils/commit.txt')))
  22. @app.on_message(cust_filter.command(commands=("runs")) & ~filters.edited)
  23. async def runs(_, message: Message):
  24. await message.reply_text((await random_line('wbb/utils/runs.txt')))
  25. @app.on_message(cust_filter.command(commands=("quote")) & ~filters.edited)
  26. async def quote(_, message: Message):
  27. await message.reply_text((await random_line('wbb/utils/quotes.txt')))
  28. @app.on_message(cust_filter.command(commands=("id")) & ~filters.edited)
  29. async def get_id(_, message: Message):
  30. app.set_parse_mode("markdown")
  31. if message.text != '/id':
  32. username = message.text.replace('/id', '')
  33. user_id = (await app.get_users(username)).id
  34. msg = f"{username}'s ID is `{user_id}`"
  35. await message.reply_text(msg)
  36. elif message.text == '/id' and not bool(message.reply_to_message):
  37. chat_id = message.chat.id
  38. msg = f"{message.chat.title}'s ID is `{chat_id}`"
  39. await message.reply_text(msg)
  40. elif message.text == '/id' and bool(message.reply_to_message):
  41. from_user_id = message.reply_to_message.from_user.id
  42. from_user_mention = message.reply_to_message.from_user.mention
  43. msg = f"{from_user_mention}'s ID is `{from_user_id}`"
  44. await message.reply_text(msg)
  45. @app.on_message(cust_filter.command(commands=("dev")) & ~filters.edited)
  46. async def dev(_, message: Message):
  47. app.set_parse_mode("markdown")
  48. if (await app.get_chat_member(
  49. message.chat.id,
  50. BOT_ID)).can_restrict_members:
  51. await message.reply_to_message.forward('WBBSupport')
  52. await app.send_message("WBBSupport",
  53. "Forwarded By: `{}` | {}\n"
  54. "Forwarded From: `{}` | {}"
  55. .format(message.from_user.id,
  56. message.from_user.mention,
  57. message.chat.id,
  58. message.chat.title))
  59. await message.reply_text("Your Message Has Been Forward To Devs,"
  60. + " Any Missuse Of This Feature Will Not"
  61. + " Be Tolerated And You Will Be"
  62. + " Gbanned instantaneously!")
  63. else:
  64. await message.reply_text("To Use This Feature You Have To Make Me"
  65. + " Admin")
  66. # Password
  67. @app.on_message(cust_filter.command(commands=('random')) & ~filters.edited)
  68. async def random(_, message: Message):
  69. app.set_parse_mode('markdown')
  70. if message.text != "/random":
  71. length = message.text.replace('/random', '')
  72. try:
  73. if 1 < int(length) < 1000:
  74. alphabet = string.ascii_letters + string.digits
  75. password = ''.join(secrets.choice(alphabet) for i in
  76. range(int(length)))
  77. await message.reply_text(f"`{password}`")
  78. else:
  79. await message.reply_text('Specify A Length Between 1-1000')
  80. except ValueError:
  81. await message.reply_text("Strings Won't Work!, Pass A"
  82. + " Positive Integer Between 1-1000")
  83. else:
  84. await message.reply_text('"/random" Needs An Argurment.'
  85. ' Ex: `/random 5`')
  86. # http cat search
  87. @app.on_message(cust_filter.command(commands=('http')) & ~filters.edited)
  88. async def http(_, message: Message):
  89. if message.text != "/http":
  90. code = message.text.replace('/http', '')
  91. url = f"https://http.cat/{code}"
  92. final = url.replace(' ', '')
  93. await message.reply_photo(final)
  94. else:
  95. await message.reply_text('"/http" Needs An Argument. Ex: `/http 404`')
  96. # Encrypt
  97. @app.on_message(cust_filter.command(commands=('encrypt')) & ~filters.edited)
  98. async def encrypt(_, message: Message):
  99. app.set_parse_mode('markdown')
  100. if not message.reply_to_message:
  101. await message.reply_text('Reply To A Message To Encrypt It.')
  102. else:
  103. text = message.reply_to_message.text
  104. text_in_bytes = bytes(text, 'utf-8')
  105. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  106. encrypted_text = cipher_suite.encrypt(text_in_bytes)
  107. bytes_in_text = encrypted_text.decode("utf-8")
  108. await message.reply_text(bytes_in_text)
  109. # Decrypt
  110. @app.on_message(cust_filter.command(commands=('decrypt')) & ~filters.edited)
  111. async def decrypt(_, message: Message):
  112. if not message.reply_to_message:
  113. await message.reply_text('Reply To A Message To Decrypt It.')
  114. else:
  115. text = message.reply_to_message.text
  116. text_in_bytes = bytes(text, 'utf-8')
  117. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  118. decoded_text = cipher_suite.decrypt(text_in_bytes)
  119. bytes_in_text = decoded_text.decode("utf-8")
  120. await message.reply_text(bytes_in_text)