genstr.py 3.2 KB

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