genstr.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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, api_hash="eb06d4abfb49dc3eeb1aeb98ae0f581e")
  30. except Exception as e:
  31. await app.send_message(chat.id ,f"**ERROR:** `{str(e)}`")
  32. return
  33. try:
  34. await temp_client.connect()
  35. except ConnectionError:
  36. await temp_client.disconnect()
  37. await temp_client.connect()
  38. try:
  39. code = await temp_client.send_code(phone)
  40. await asyncio.sleep(2)
  41. except PhoneNumberInvalid:
  42. await message.reply_text("Phone Number is Invalid")
  43. return
  44. try:
  45. otp = await app.ask(
  46. chat.id, ("An OTP is sent to your phone number, "
  47. "Please enter OTP in `1 2 3 4 5` format. __(Space between each numbers!)__"), timeout=300)
  48. except TimeoutError:
  49. await message.reply_text("Time limit reached of 5 min. Process Cancelled.")
  50. return
  51. otp_code = otp.text
  52. try:
  53. await temp_client.sign_in(phone, code.phone_code_hash, phone_code=' '.join(str(otp_code)))
  54. except PhoneCodeInvalid:
  55. await message.reply_text("Invalid OTP.")
  56. return
  57. except PhoneCodeExpired:
  58. await message.reply_text("OTP is Expired.")
  59. return
  60. except SessionPasswordNeeded:
  61. try:
  62. two_step_code = await app.ask(
  63. chat.id,
  64. "Your account have Two-Step Verification.\nPlease enter your Password.",
  65. timeout=300
  66. )
  67. except TimeoutError:
  68. await message.reply_text("Time limit reached of 5 min.")
  69. return
  70. new_code = two_step_code.text
  71. try:
  72. await temp_client.check_password(new_code)
  73. except Exception as e:
  74. await message.reply_text(f"**ERROR:** `{str(e)}`")
  75. return
  76. except Exception as e:
  77. await app.send_message(chat.id ,f"**ERROR:** `{str(e)}`")
  78. return
  79. try:
  80. session_string = await temp_client.export_session_string()
  81. await temp_client.disconnect()
  82. await app.send_message(chat.id, text=f"**HERE IS YOUR STRING SESSION:**\n```{session_string}```")
  83. except Exception as e:
  84. await app.send_message(chat.id ,f"**ERROR:** `{str(e)}`")
  85. return