genstr.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. from wbb import app
  2. from pyrogram import Client, filters
  3. from asyncio.exceptions import TimeoutError
  4. from wbb.core.decorators.errors import capture_err
  5. from pyrogram.errors import (
  6. SessionPasswordNeeded, PhoneNumberInvalid,
  7. PhoneCodeInvalid, PhoneCodeExpired
  8. )
  9. import asyncio
  10. """
  11. Credits:
  12. This module belongs to https://github.com/AbirHasan2005/TG-String-Session/blob/main/genStr.py
  13. """
  14. __MODULE__ = "GenStr"
  15. __HELP__ = """
  16. This Module Can Be Used To Generate Session String For A Userbot.
  17. Send **/genstr** Command To The Bot In Private And Follow Instructions."""
  18. @app.on_message(filters.command("genstr") & filters.private)
  19. @capture_err
  20. async def genstr(_, message):
  21. chat = message.chat
  22. while True:
  23. number = await app.ask(chat.id, "Send Your Phone Number In International Format.")
  24. if not number.text:
  25. continue
  26. phone = number.text.strip()
  27. if phone.startswith("/"):
  28. continue
  29. confirm = await app.ask(chat.id, f'`Is "{phone}" correct?` \n\nSend: `y`\nSend: `n`')
  30. if confirm.text.startswith("/"):
  31. continue
  32. if "y" in confirm.text.lower():
  33. break
  34. try:
  35. temp_client = Client(":memory:", api_id=6,
  36. api_hash="eb06d4abfb49dc3eeb1aeb98ae0f581e")
  37. except Exception as e:
  38. await app.send_message(chat.id, f"**ERROR:** `{str(e)}`")
  39. return
  40. try:
  41. await temp_client.connect()
  42. except ConnectionError:
  43. await temp_client.disconnect()
  44. await temp_client.connect()
  45. try:
  46. code = await temp_client.send_code(phone)
  47. await asyncio.sleep(2)
  48. except PhoneNumberInvalid:
  49. await message.reply_text("Phone Number is Invalid")
  50. return
  51. try:
  52. otp = await app.ask(
  53. chat.id, ("An OTP is sent to your phone number, "
  54. "Please enter OTP in `1 2 3 4 5` format. __(Space between each numbers!)__"), timeout=300)
  55. except TimeoutError:
  56. await message.reply_text("Time limit reached of 5 min. Process Cancelled.")
  57. return
  58. otp_code = otp.text
  59. try:
  60. await temp_client.sign_in(phone, code.phone_code_hash, phone_code=' '.join(str(otp_code)))
  61. except PhoneCodeInvalid:
  62. await message.reply_text("Invalid OTP.")
  63. return
  64. except PhoneCodeExpired:
  65. await message.reply_text("OTP is Expired.")
  66. return
  67. except SessionPasswordNeeded:
  68. try:
  69. two_step_code = await app.ask(
  70. chat.id,
  71. "Your account have Two-Step Verification.\nPlease enter your Password.",
  72. timeout=300
  73. )
  74. except TimeoutError:
  75. await message.reply_text("Time limit reached of 5 min.")
  76. return
  77. new_code = two_step_code.text
  78. try:
  79. await temp_client.check_password(new_code)
  80. except Exception as e:
  81. await message.reply_text(f"**ERROR:** `{str(e)}`")
  82. return
  83. except Exception as e:
  84. await app.send_message(chat.id, f"**ERROR:** `{str(e)}`")
  85. return
  86. try:
  87. session_string = await temp_client.export_session_string()
  88. await temp_client.disconnect()
  89. await app.send_message(chat.id, text=f"**HERE IS YOUR STRING SESSION:**\n```{session_string}```")
  90. except Exception as e:
  91. await app.send_message(chat.id, f"**ERROR:** `{str(e)}`")
  92. return