genstr.py 3.5 KB

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