genstr.py 3.2 KB

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