Skip to content

Commit

Permalink
Removed pyro v1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonymousX1025 authored Jan 30, 2023
1 parent 352bf3e commit 5e9b34e
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions StringGenBot/generate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pyrogram.types import Message
from telethon import TelegramClient
from pyrogram import Client, filters
from pyrogram1 import Client as Client1
from asyncio.exceptions import TimeoutError
from telethon.sessions import StringSession
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
Expand All @@ -13,14 +12,6 @@
SessionPasswordNeeded,
PasswordHashInvalid
)
from pyrogram1.errors import (
ApiIdInvalid as ApiIdInvalid1,
PhoneNumberInvalid as PhoneNumberInvalid1,
PhoneCodeInvalid as PhoneCodeInvalid1,
PhoneCodeExpired as PhoneCodeExpired1,
SessionPasswordNeeded as SessionPasswordNeeded1,
PasswordHashInvalid as PasswordHashInvalid1
)
from telethon.errors import (
ApiIdInvalidError,
PhoneNumberInvalidError,
Expand All @@ -37,10 +28,7 @@
ask_ques = "**» ᴩʟᴇᴀsᴇ ᴄʜᴏᴏsᴇ ᴛʜᴇ ᴩʏᴛʜᴏɴ ʟɪʙʀᴀʀʏ ғᴏʀ ᴡʜɪᴄʜ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ sᴛʀɪɴɢ :**"
buttons_ques = [
[
InlineKeyboardButton("ᴩʏʀᴏɢʀᴀᴍ", callback_data="pyrogram1"),
InlineKeyboardButton("ᴩʏʀᴏɢʀᴀᴍ ᴠ2", callback_data="pyrogram"),
],
[
InlineKeyboardButton("ᴩʏʀᴏɢʀᴀᴍ", callback_data="pyrogram"),
InlineKeyboardButton("ᴛᴇʟᴇᴛʜᴏɴ", callback_data="telethon"),
],
[
Expand All @@ -63,13 +51,11 @@ async def main(_, msg):
await msg.reply(ask_ques, reply_markup=InlineKeyboardMarkup(buttons_ques))


async def generate_session(bot: Client, msg: Message, telethon=False, old_pyro: bool = False, is_bot: bool = False):
async def generate_session(bot: Client, msg: Message, telethon=False, is_bot: bool = False):
if telethon:
ty = "ᴛᴇʟᴇᴛʜᴏɴ"
else:
ty = "ᴩʏʀᴏɢʀᴀᴍ"
if not old_pyro:
ty += " ᴠ2"
if is_bot:
ty += " ʙᴏᴛ"
await msg.reply(f"» ᴛʀʏɪɴɢ ᴛᴏ sᴛᴀʀᴛ **{ty}** sᴇssɪᴏɴ ɢᴇɴᴇʀᴀᴛᴏʀ...")
Expand Down Expand Up @@ -108,8 +94,6 @@ async def generate_session(bot: Client, msg: Message, telethon=False, old_pyro:
client = TelegramClient(StringSession(), api_id, api_hash)
elif is_bot:
client = Client(name="bot", api_id=api_id, api_hash=api_hash, bot_token=phone_number, in_memory=True)
elif old_pyro:
client = Client1(":memory:", api_id=api_id, api_hash=api_hash)
else:
client = Client(name="user", api_id=api_id, api_hash=api_hash, in_memory=True)
await client.connect()
Expand All @@ -120,10 +104,10 @@ async def generate_session(bot: Client, msg: Message, telethon=False, old_pyro:
code = await client.send_code_request(phone_number)
else:
code = await client.send_code(phone_number)
except (ApiIdInvalid, ApiIdInvalidError, ApiIdInvalid1):
except (ApiIdInvalid, ApiIdInvalidError):
await msg.reply("» ʏᴏᴜʀ **ᴀᴩɪ_ɪᴅ** ᴀɴᴅ **ᴀᴩɪ_ʜᴀsʜ** ᴄᴏᴍʙɪɴᴀᴛɪᴏɴ ᴅᴏᴇsɴ'ᴛ ᴍᴀᴛᴄʜ ᴡɪᴛʜ ᴛᴇʟᴇɢʀᴀᴍ ᴀᴩᴩs sʏsᴛᴇᴍ. \n\nᴩʟᴇᴀsᴇ sᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ʏᴏᴜʀ sᴇssɪᴏɴ ᴀɢᴀɪɴ.", reply_markup=InlineKeyboardMarkup(gen_button))
return
except (PhoneNumberInvalid, PhoneNumberInvalidError, PhoneNumberInvalid1):
except (PhoneNumberInvalid, PhoneNumberInvalidError):
await msg.reply("» ᴛʜᴇ **ᴩʜᴏɴᴇ_ɴᴜᴍʙᴇʀ** ʏᴏᴜ'ᴠᴇ sᴇɴᴛ ᴅᴏᴇsɴ'ᴛ ʙᴇʟᴏɴɢ ᴛᴏ ᴀɴʏ ᴛᴇʟᴇɢʀᴀᴍ ᴀᴄᴄᴏᴜɴᴛ.\n\nᴩʟᴇᴀsᴇ sᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ʏᴏᴜʀ sᴇssɪᴏɴ ᴀɢᴀɪɴ.", reply_markup=InlineKeyboardMarkup(gen_button))
return
try:
Expand All @@ -142,13 +126,13 @@ async def generate_session(bot: Client, msg: Message, telethon=False, old_pyro:
await client.sign_in(phone_number, phone_code, password=None)
else:
await client.sign_in(phone_number, code.phone_code_hash, phone_code)
except (PhoneCodeInvalid, PhoneCodeInvalidError, PhoneCodeInvalid1):
except (PhoneCodeInvalid, PhoneCodeInvalidError):
await msg.reply("» ᴛʜᴇ ᴏᴛᴩ ʏᴏᴜ'ᴠᴇ sᴇɴᴛ ɪs **ᴡʀᴏɴɢ.**\n\nᴩʟᴇᴀsᴇ sᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ʏᴏᴜʀ sᴇssɪᴏɴ ᴀɢᴀɪɴ.", reply_markup=InlineKeyboardMarkup(gen_button))
return
except (PhoneCodeExpired, PhoneCodeExpiredError, PhoneCodeExpired1):
except (PhoneCodeExpired, PhoneCodeExpiredError):
await msg.reply("» ᴛʜᴇ ᴏᴛᴩ ʏᴏᴜ'ᴠᴇ sᴇɴᴛ ɪs **ᴇxᴩɪʀᴇᴅ.**\n\nᴩʟᴇᴀsᴇ sᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ʏᴏᴜʀ sᴇssɪᴏɴ ᴀɢᴀɪɴ.", reply_markup=InlineKeyboardMarkup(gen_button))
return
except (SessionPasswordNeeded, SessionPasswordNeededError, SessionPasswordNeeded1):
except (SessionPasswordNeeded, SessionPasswordNeededError):
try:
two_step_msg = await bot.ask(user_id, "» ᴩʟᴇᴀsᴇ ᴇɴᴛᴇʀ ʏᴏᴜʀ **ᴛᴡᴏ sᴛᴇᴩ ᴠᴇʀɪғɪᴄᴀᴛɪᴏɴ** ᴩᴀssᴡᴏʀᴅ ᴛᴏ ᴄᴏɴᴛɪɴᴜᴇ.", filters=filters.text, timeout=300)
except TimeoutError:
Expand All @@ -162,7 +146,7 @@ async def generate_session(bot: Client, msg: Message, telethon=False, old_pyro:
await client.check_password(password=password)
if await cancelled(api_id_msg):
return
except (PasswordHashInvalid, PasswordHashInvalidError, PasswordHashInvalid1):
except (PasswordHashInvalid, PasswordHashInvalidError):
await two_step_msg.reply("» ᴛʜᴇ ᴩᴀssᴡᴏʀᴅ ʏᴏᴜ'ᴠᴇ sᴇɴᴛ ɪs ᴡʀᴏɴɢ.\n\nᴩʟᴇᴀsᴇ sᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ʏᴏᴜʀ sᴇssɪᴏɴ ᴀɢᴀɪɴ.", quote=True, reply_markup=InlineKeyboardMarkup(gen_button))
return
else:
Expand Down

0 comments on commit 5e9b34e

Please sign in to comment.