From bc2913d001b869acd36e0232244617661558980d Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 18:42:58 +0530 Subject: [PATCH 01/39] Update support.py --- ssnbot/db/support.py | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/ssnbot/db/support.py b/ssnbot/db/support.py index 1978c2b..2c1d32a 100644 --- a/ssnbot/db/support.py +++ b/ssnbot/db/support.py @@ -1,28 +1,38 @@ import asyncio -from pyrogram.errors import FloodWait +from pyrogram.errors import FloodWait, RPCError from pyrogram import enums from ssnbot.db.sql import query_msg, del_user from ssnbot import LOGGER +async def users_info(bot) -> tuple[int, int]: + """ + Function to check user activity and manage the broadcast list. + + Args: + bot: The Pyrogram bot/client instance. + + Returns: + A tuple containing the number of active users and blocked users. + """ + users = 0 # Count of active users + blocked = 0 # Count of blocked users + identity = await query_msg() # Fetch user IDs from the database -async def users_info(bot): - users = 0 - blocked = 0 - identity = await query_msg() for user in identity: user_id = int(user[0]) - name = bool() try: - name = await bot.send_chat_action(user_id, enums.ChatAction.TYPING) + # Attempt to send a "typing" action to the user + await bot.send_chat_action(user_id, enums.ChatAction.TYPING) + users += 1 # If successful, increment active users count except FloodWait as e: - await asyncio.sleep(e.value) - except Exception: - pass - if bool(name): - users += 1 - else: - await del_user(user_id) - LOGGER.info("Deleted user id %s from broadcast list", user_id) - blocked += 1 - return users, blocked + LOGGER.warning("FloodWait triggered for %d seconds", e.value) + await asyncio.sleep(e.value) # Wait for the required time + except RPCError as e: + LOGGER.error("RPCError for user %s: %s", user_id, e) + await del_user(user_id) # Remove the user from the broadcast list + LOGGER.info("Deleted user ID %s from broadcast list", user_id) + blocked += 1 # Increment blocked users count + except Exception as e: + LOGGER.error("Unexpected error for user %s: %s", user_id, e) + return users, blocked # Return the counts of active and blocked users From 8bb66b45d3370bd8205039d0255510c3a44d5433 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 18:48:25 +0530 Subject: [PATCH 02/39] Update sql.py --- ssnbot/db/sql.py | 65 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/ssnbot/db/sql.py b/ssnbot/db/sql.py index f18c666..766d16a 100644 --- a/ssnbot/db/sql.py +++ b/ssnbot/db/sql.py @@ -1,29 +1,32 @@ import threading -from sqlalchemy import create_engine -from sqlalchemy import Column, TEXT, BigInteger +from sqlalchemy import create_engine, Column, TEXT, BigInteger from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.pool import StaticPool from ssnbot import DB_URL - BASE = declarative_base() - class Broadcast(BASE): __tablename__ = "broadcast" user_id = Column(BigInteger, primary_key=True) user_name = Column(TEXT) - def __init__(self, user_id, user_name): + def __init__(self, user_id: int, user_name: str): self.user_id = user_id self.user_name = user_name def start() -> scoped_session: + """ + Initialize the database connection and create tables if they don't exist. + Returns: + scoped_session: Thread-safe session maker. + """ engine = create_engine( - DB_URL, client_encoding="utf8", poolclass=StaticPool) + DB_URL, client_encoding="utf8", poolclass=StaticPool + ) BASE.metadata.bind = engine BASE.metadata.create_all(engine) return scoped_session(sessionmaker(bind=engine, autoflush=False)) @@ -33,7 +36,13 @@ def start() -> scoped_session: INSERTION_LOCK = threading.RLock() -async def add_user(user_id, user_name): +def add_user(user_id: int, user_name: str) -> None: + """ + Add a user to the database if they don't already exist. + Args: + user_id (int): Telegram user ID. + user_name (str): Telegram user name. + """ with INSERTION_LOCK: try: usr = SESSION.query(Broadcast).filter_by(user_id=user_id).one() @@ -43,24 +52,43 @@ async def add_user(user_id, user_name): SESSION.commit() -async def is_user(user_id): +def is_user(user_id: int) -> bool: + """ + Check if a user exists in the database. + Args: + user_id (int): Telegram user ID. + Returns: + bool: True if user exists, False otherwise. + """ with INSERTION_LOCK: try: usr = SESSION.query(Broadcast).filter_by(user_id=user_id).one() - return usr.user_id + return True except NoResultFound: return False -async def query_msg(): - try: - query = SESSION.query(Broadcast.user_id).order_by(Broadcast.user_id) - return query.all() - finally: - SESSION.close() - - -async def del_user(user_id): +def query_msg() -> list: + """ + Retrieve all user IDs from the database. + Returns: + list: List of user IDs. + """ + with INSERTION_LOCK: + try: + query = SESSION.query(Broadcast.user_id).order_by(Broadcast.user_id) + return query.all() + except Exception as e: + print(f"Error querying messages: {e}") + return [] + + +def del_user(user_id: int) -> None: + """ + Delete a user from the database. + Args: + user_id (int): Telegram user ID. + """ with INSERTION_LOCK: try: usr = SESSION.query(Broadcast).filter_by(user_id=user_id).one() @@ -68,4 +96,3 @@ async def del_user(user_id): SESSION.commit() except NoResultFound: pass - \ No newline at end of file From 19d2415272451c3085a3721c2277fb8246821979 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 18:56:20 +0530 Subject: [PATCH 03/39] Update basic.py --- ssnbot/plugins/basic.py | 93 +++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 31 deletions(-) diff --git a/ssnbot/plugins/basic.py b/ssnbot/plugins/basic.py index 3ac539a..c6f2b4e 100644 --- a/ssnbot/plugins/basic.py +++ b/ssnbot/plugins/basic.py @@ -1,47 +1,78 @@ from data import Data from pyrogram import Client, filters -from pyrogram.types import InlineKeyboardMarkup, Message, LinkPreviewOptions -from ssnbot.db.sql import add_user, query_msg +from pyrogram.types import InlineKeyboardMarkup, Message +from ssnbot.db.sql import add_user -def filter(cmd: str): +def command_filter(cmd: str): + """Custom filter for handling bot commands.""" return filters.private & filters.incoming & filters.command(cmd) # Start Message -@Client.on_message(filter("start")) +@Client.on_message(command_filter("start")) async def start(bot: Client, msg: Message): - id = msg.from_user.id - user_name = '@' + msg.from_user.username if msg.from_user.username else None - await add_user(id, user_name) - user = await bot.get_me() - mention = user.mention - await bot.send_message( - msg.chat.id, - Data.START.format(msg.from_user.mention, mention), - reply_markup=InlineKeyboardMarkup(Data.buttons) - ) + """ + Handles the /start command. Greets the user and stores their information in the database. + """ + user_id = msg.from_user.id + username = f"@{msg.from_user.username}" if msg.from_user.username else "Anonymous" + + try: + # Add the user to the database + await add_user(user_id, username) + except Exception as e: + print(f"Error adding user to database: {e}") + + bot_user = await bot.get_me() + mention = bot_user.mention + + try: + await bot.send_message( + msg.chat.id, + Data.START.format(msg.from_user.mention, mention), + reply_markup=InlineKeyboardMarkup(Data.buttons) + ) + except Exception as e: + print(f"Error sending start message: {e}") # Help Message -@Client.on_message(filter("help")) -async def _help(bot: Client, msg: Message): - id = msg.from_user.id - user_name = '@' + msg.from_user.username if msg.from_user.username else None - await add_user(id, user_name) - await bot.send_message( - msg.chat.id, Data.HELP, - reply_markup=InlineKeyboardMarkup(Data.home_buttons) - ) +@Client.on_message(command_filter("help")) +async def help_command(bot: Client, msg: Message): + """ + Handles the /help command. Provides usage instructions to the user. + """ + user_id = msg.from_user.id + username = f"@{msg.from_user.username}" if msg.from_user.username else "Anonymous" + + try: + await add_user(user_id, username) + except Exception as e: + print(f"Error adding user to database: {e}") + + try: + await bot.send_message( + msg.chat.id, + Data.HELP, + reply_markup=InlineKeyboardMarkup(Data.home_buttons) + ) + except Exception as e: + print(f"Error sending help message: {e}") # About Message -@Client.on_message(filter("about")) +@Client.on_message(command_filter("about")) async def about(bot: Client, msg: Message): - await bot.send_message( - msg.chat.id, - Data.ABOUT, - # disable_web_page_preview=True, - link_preview_options=LinkPreviewOptions(is_disabled=True), - reply_markup=InlineKeyboardMarkup(Data.home_buttons), - ) + """ + Handles the /about command. Provides information about the bot. + """ + try: + await bot.send_message( + msg.chat.id, + Data.ABOUT, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup(Data.home_buttons) + ) + except Exception as e: + print(f"Error sending about message: {e}") From dca362fcf83d40360174e8f7ea29e692348fba47 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:00:15 +0530 Subject: [PATCH 04/39] Update broadcast.py --- ssnbot/plugins/broadcast.py | 48 +++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/ssnbot/plugins/broadcast.py b/ssnbot/plugins/broadcast.py index 9ec758d..ed3878b 100644 --- a/ssnbot/plugins/broadcast.py +++ b/ssnbot/plugins/broadcast.py @@ -1,6 +1,6 @@ import asyncio from pyrogram import Client, filters -from pyrogram.errors import FloodWait +from pyrogram.errors import FloodWait, RPCError from pyrogram.types import Message from ssnbot import ADMINS from ssnbot.db.sql import query_msg @@ -9,42 +9,70 @@ @Client.on_message(filters.private & filters.command("stats")) async def get_subscribers_count(bot: Client, message: Message): + """ + Fetch and display subscriber statistics. + Only accessible to admins. + """ user_id = message.from_user.id if user_id not in ADMINS: return + wait_msg = "__Calculating, please wait...__" msg = await message.reply_text(wait_msg) + active, blocked = await users_info(bot) - stats_msg = f"**Stats**\nSubscribers: `{active}`\nBlocked / Deleted: `{blocked}`" + stats_msg = ( + f"**📊 Stats**\n" + f"👤 Active Subscribers: `{active}`\n" + f"🚫 Blocked / Deleted: `{blocked}`" + ) await msg.edit(stats_msg) @Client.on_message(filters.private & filters.command("broadcast")) -async def send_text(bot, message: Message): +async def send_text(bot: Client, message: Message): + """ + Broadcast a message to all users in the database. + Usage: Reply to a message with the /broadcast command. + """ user_id = message.from_user.id if user_id not in ADMINS: return - if "broadcast" in message.text and message.reply_to_message is not None: + if message.reply_to_message: query = await query_msg() + sent, failed = 0, 0 for row in query: chat_id = int(row[0]) try: await bot.copy_message( chat_id=chat_id, from_chat_id=message.chat.id, - message_id=message.reply_to_message_id, - caption=message.reply_to_message.caption, + message_id=message.reply_to_message.message_id, + caption=message.reply_to_message.caption or "", reply_markup=message.reply_to_message.reply_markup, ) + sent += 1 except FloodWait as e: await asyncio.sleep(e.value) - except Exception: - pass + except RPCError as e: + failed += 1 + print(f"Failed to send message to {chat_id}: {e}") + except Exception as e: + failed += 1 + print(f"Unexpected error for {chat_id}: {e}") + + await message.reply_text( + f"**Broadcast Report**\n" + f"✅ Sent: `{sent}`\n" + f"❌ Failed: `{failed}`" + ) else: reply_error = ( - "`Use this command as a reply to any telegram message without any spaces.`" + "❗ **Usage Error:**\n" + "Reply to a message with `/broadcast` to send it to all subscribers." ) - msg = await message.reply_text(reply_error, message.id) + msg = await message.reply_text(reply_error) await asyncio.sleep(8) await msg.delete() + From 6b0727d0bf71758e8ed0ef24a1c181d5d5b18616 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:07:10 +0530 Subject: [PATCH 05/39] Update callbacks.py --- ssnbot/plugins/callbacks.py | 125 ++++++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 41 deletions(-) diff --git a/ssnbot/plugins/callbacks.py b/ssnbot/plugins/callbacks.py index 83279fd..a063128 100644 --- a/ssnbot/plugins/callbacks.py +++ b/ssnbot/plugins/callbacks.py @@ -5,83 +5,126 @@ from ssnbot.plugins.generate import generate_session, ask_ques, buttons_ques from ssnbot import LOGGER +# Default messages to avoid issues if Data variables are undefined +DEFAULT_START = "Welcome, {0}! Use the buttons below to navigate." +DEFAULT_ABOUT = "This bot allows you to generate session strings for your libraries." +DEFAULT_HELP = "Click the buttons below to explore more features or get help." +DEFAULT_ERROR_MESSAGE = ( + "Oops! An error occurred! \n\n**Error** : {} " + "\n\nPlease contact @ElUpdates if this message is unclear or if you need further assistance." +) + @Client.on_callback_query(filters.regex(r"^home$")) async def home(bot, query): - user = bot.me - mention = user.mention - chat_id = query.from_user.id - message_id = query.message.id - await bot.edit_message_text( - chat_id=chat_id, - message_id=message_id, - text=Data.START.format(query.from_user.mention, mention), - reply_markup=InlineKeyboardMarkup(Data.buttons), - ) + """ + Handles the 'home' callback. + Sends the start message with navigation buttons. + """ + try: + user = await bot.get_me() + mention = user.mention + chat_id = query.from_user.id + message_id = query.message.id + await bot.edit_message_text( + chat_id=chat_id, + message_id=message_id, + text=Data.START.format(query.from_user.mention, mention) if Data.START else DEFAULT_START.format(query.from_user.mention), + reply_markup=InlineKeyboardMarkup(Data.buttons), + ) + except Exception as e: + LOGGER.error(traceback.format_exc()) + await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) @Client.on_callback_query(filters.regex(r"^about$")) async def about(bot, query): - chat_id = query.from_user.id - message_id = query.message.id - await bot.edit_message_text( - chat_id=chat_id, - message_id=message_id, - text=Data.ABOUT, - # disable_web_page_preview=True, - link_preview_options=LinkPreviewOptions(is_disabled=True), - reply_markup=InlineKeyboardMarkup(Data.home_buttons), - ) + """ + Handles the 'about' callback. + Sends the about message. + """ + try: + chat_id = query.from_user.id + message_id = query.message.id + await bot.edit_message_text( + chat_id=chat_id, + message_id=message_id, + text=Data.ABOUT if Data.ABOUT else DEFAULT_ABOUT, + link_preview_options=LinkPreviewOptions(is_disabled=True), + reply_markup=InlineKeyboardMarkup(Data.home_buttons), + ) + except Exception as e: + LOGGER.error(traceback.format_exc()) + await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) @Client.on_callback_query(filters.regex(r"^help$")) async def help(bot, query): - chat_id = query.from_user.id - message_id = query.message.id - await bot.edit_message_text( - chat_id=chat_id, - message_id=message_id, - text=Data.HELP, - # disable_web_page_preview=True, - link_preview_options=LinkPreviewOptions(is_disabled=True), - reply_markup=InlineKeyboardMarkup(Data.home_buttons), - ) + """ + Handles the 'help' callback. + Sends the help message with navigation buttons. + """ + try: + chat_id = query.from_user.id + message_id = query.message.id + await bot.edit_message_text( + chat_id=chat_id, + message_id=message_id, + text=Data.HELP if Data.HELP else DEFAULT_HELP, + link_preview_options=LinkPreviewOptions(is_disabled=True), + reply_markup=InlineKeyboardMarkup(Data.home_buttons), + ) + except Exception as e: + LOGGER.error(traceback.format_exc()) + await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) @Client.on_callback_query(filters.regex(r"^generate$")) async def generate(bot, query): - await query.answer("Select your library") - await query.message.reply(ask_ques, reply_markup=InlineKeyboardMarkup(buttons_ques)) + """ + Handles the 'generate' callback. + Prompts the user to choose a library for session generation. + """ + try: + await query.answer("Select your library") + await query.message.reply(ask_ques, reply_markup=InlineKeyboardMarkup(buttons_ques)) + except Exception as e: + LOGGER.error(traceback.format_exc()) + await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) @Client.on_callback_query(filters.regex(r"^pyrogram$")) async def pyro(bot, query): + """ + Handles the 'pyrogram' callback. + Generates a session string for Pyrogram. + """ try: await query.answer( - "Please note that the new type of string sessions may not work in all bots, i.e, only the bots that have been updated to pyrogram v2 will work!", + "Note: New string sessions may not work with older bots. Ensure compatibility with Pyrogram v2.", show_alert=True, ) await generate_session(bot, query.message) except Exception as e: LOGGER.error(traceback.format_exc()) - LOGGER.error(e) - await query.message.reply(ERROR_MESSAGE.format(str(e))) + await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) @Client.on_callback_query(filters.regex(r"^telethon$")) async def tele(bot, query): + """ + Handles the 'telethon' callback. + Generates a session string for Telethon. + """ try: await query.answer() await generate_session(bot, query.message, telethon=True) except Exception as e: LOGGER.error(traceback.format_exc()) - LOGGER.error(e) - await query.message.reply(ERROR_MESSAGE.format(str(e))) + await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) ERROR_MESSAGE = ( - "Oops! An exception occurred! \n\n**Error** : {} " - "\n\nPlease visit @ElUpdates if this message doesn't contain any " - "sensitive information and you if want to report this as " - "this error message is not being logged by us!" + "Oops! An error occurred! \n\n**Error** : {} " + "\n\nPlease contact @ElUpdates if this message is unclear or if you need further assistance." ) From 43c91782fd607e41e2647e30be5a373011c4591d Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:21:28 +0530 Subject: [PATCH 06/39] Update data.py --- data.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/data.py b/data.py index f1ab8aa..9238b19 100644 --- a/data.py +++ b/data.py @@ -2,36 +2,34 @@ class Data: - generate_single_button = [InlineKeyboardButton("🔥 Start Generating Session 🔥", callback_data="generate")] + generate_single_button = InlineKeyboardButton("🔥 Start Generating Session 🔥", callback_data="generate") home_buttons = [ - generate_single_button, + [generate_single_button], [InlineKeyboardButton(text="🏠 Return Home 🏠", callback_data="home")] ] - generate_button = [generate_single_button] - buttons = [ - generate_single_button, + [generate_single_button], [InlineKeyboardButton("✨ Bot Status and More Bots ✨", url="https://t.me/ELUpdates/8")], [ InlineKeyboardButton("How to Use ❔", callback_data="help"), InlineKeyboardButton("🎪 About 🎪", callback_data="about") ], - [InlineKeyboardButton("♥ More Amazing bots ♥", url="https://t.me/ELUpdates")], + [InlineKeyboardButton("♥ More Amazing Bots ♥", url="https://t.me/ELUpdates")], ] START = """ -**Hey {} +**Hey {0}** -Welcome to {} +Welcome to {1} If you don't trust this bot, > Please stop reading this message > Delete this chat Still reading? -You can use me to generate Pyrogram and Telethon string session. Use below buttons to learn more ! +You can use me to generate Pyrogram and Telethon string sessions. Use the buttons below to learn more! By @ELUpdates** """ @@ -39,24 +37,24 @@ class Data: HELP = """ ✨ **Available Commands** ✨ -/about - About The Bot +/about - About the Bot /help - This Message /start - Start the Bot /generate - Generate Session /cancel - Cancel the process -/restart - Cancel the process +/restart - Cancel and Restart the process """ ABOUT = """ **About This Bot** -Telegram Bot to generate Pyrogram and Telethon string session by @ELUpdates +Telegram Bot to generate Pyrogram and Telethon string sessions by @ELUpdates -Source Code : [Click Here](https://github.com/EL-Coders/SessionStringBot) +Source Code: [Click Here](https://github.com/EL-Coders/SessionStringBot) -Framework : [Pyrogram](https://docs.pyrogram.org) +Framework: [Pyrogram](https://docs.pyrogram.org) -Language : [Python](https://www.python.org) +Language: [Python](https://www.python.org) -Developer : @CoderELAlpha +Developer: @CoderELAlpha """ From f5d78e18ce1583c030a86a6018024cf8c64db867 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:25:13 +0530 Subject: [PATCH 07/39] Update requirements.txt --- requirements.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 892f531..217c6f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ -python-dotenv -SQLAlchemy -psycopg2 -Telethon -git+https://github.com/rahulps1000/pyropatch.git@pyrotgfork -pyrotgfork -TgCrypto -uvloop +python-dotenv # For environment variable management +SQLAlchemy # For database ORM +psycopg2-binary # PostgreSQL database adapter +Telethon # Telegram client library +git+https://github.com/rahulps1000/pyropatch.git@pyrotgfork # Custom Pyrogram patch fork +TgCrypto # Cryptographic library for Telegram +uvloop # Fast asyncio event loop + From 94178d4edcad2a081c742adccf3560d9ddb668ae Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:28:12 +0530 Subject: [PATCH 08/39] Update config.ini --- config.ini | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/config.ini b/config.ini index 796fcc7..5aa25cb 100644 --- a/config.ini +++ b/config.ini @@ -2,33 +2,33 @@ keys=root,Logger [handlers] -keys=consoleHandler, file_handler +keys=consoleHandler, fileHandler [formatters] keys=Formatter [logger_root] -level=INFO -handlers=consoleHandler, file_handler +level=DEBUG +handlers=consoleHandler, fileHandler [logger_Logger] -level=INFO -handlers=consoleHandler, file_handler +level=DEBUG +handlers=consoleHandler, fileHandler qualname=Logger -propagate=0 +propagate=1 [handler_consoleHandler] class=StreamHandler -level=INFO +level=DEBUG formatter=Formatter args=(sys.stdout,) -[handler_file_handler] +[handler_fileHandler] class=FileHandler -level=INFO +level=DEBUG formatter=Formatter -args=('logs.txt','w',) +args=('logs/logs.txt', 'a',) [formatter_Formatter] -format= [%(asctime)s][%(name)s][%(module)s][%(lineno)d][%(levelname)s] -> %(message)s -datefmt= %d/%m/%Y %H:%M:%S \ No newline at end of file +format=[%(asctime)s][%(name)s][%(module)s][%(lineno)d][%(levelname)s] -> %(message)s +datefmt=%d/%m/%Y %H:%M:%S From d7928a1dd29022c38579896394665b8ec2f4e4f6 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:31:54 +0530 Subject: [PATCH 09/39] Update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 217c6f2..dbf2abe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ Telethon # Telegram client library git+https://github.com/rahulps1000/pyropatch.git@pyrotgfork # Custom Pyrogram patch fork TgCrypto # Cryptographic library for Telegram uvloop # Fast asyncio event loop +python-3.10.4 From 06d91ab52a5585a785dd19245bafab23462f70ea Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:34:46 +0530 Subject: [PATCH 10/39] Update .gitignore --- .gitignore | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 876a68d..443a2cc 100644 --- a/.gitignore +++ b/.gitignore @@ -32,8 +32,6 @@ share/python-wheels/ MANIFEST # PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec @@ -88,33 +86,18 @@ profile_default/ ipython_config.py # pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version +.python-version # pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. #Pipfile.lock # poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock +poetry.lock # pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide .pdm.toml -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +# PEP 582 __pypackages__/ # Celery stuff @@ -158,26 +141,14 @@ dmypy.json cython_debug/ # PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ ### Python Patch ### -# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration poetry.toml - -# ruff .ruff_cache/ - -# LSP config files pyrightconfig.json -# End of https://www.toptal.com/developers/gitignore/api/python - -# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) - +### Custom Rules ### logs.txt ssnbot.session ssnbot/ssnbot.session-shm From 9a5f8fc3f1b1646aa38cbc5de4b2ec64ca1da3c5 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:51:45 +0530 Subject: [PATCH 11/39] Update data.py --- data.py | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/data.py b/data.py index 9238b19..9ddbbb0 100644 --- a/data.py +++ b/data.py @@ -2,59 +2,59 @@ class Data: - generate_single_button = InlineKeyboardButton("🔥 Start Generating Session 🔥", callback_data="generate") + generate_single_button = InlineKeyboardButton("🔥 ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ", callback_data="generate") home_buttons = [ [generate_single_button], - [InlineKeyboardButton(text="🏠 Return Home 🏠", callback_data="home")] + [InlineKeyboardButton(text="🏠 ʀᴇᴛᴜʀɴ ʜᴏᴍᴇ 🏠", callback_data="home")] ] buttons = [ [generate_single_button], - [InlineKeyboardButton("✨ Bot Status and More Bots ✨", url="https://t.me/ELUpdates/8")], + [InlineKeyboardButton("✨ ʙᴏᴛ ꜱᴛᴀᴛᴜꜱ ᴀɴᴅ ᴍᴏʀᴇ ʙᴏᴛꜱ ✨", url="https://t.me/ELUpdates/8")], [ - InlineKeyboardButton("How to Use ❔", callback_data="help"), - InlineKeyboardButton("🎪 About 🎪", callback_data="about") + InlineKeyboardButton("ʜᴏᴡ ᴛᴏ ᴜꜱᴇ ❔", callback_data="help"), + InlineKeyboardButton("🎪 ᴀʙᴏᴜᴛ 🎪", callback_data="about") ], - [InlineKeyboardButton("♥ More Amazing Bots ♥", url="https://t.me/ELUpdates")], + [InlineKeyboardButton("♥ ᴍᴏʀᴇ ᴀᴍᴀᴢɪɴɢ ʙᴏᴛꜱ ♥", url="https://t.me/ELUpdates")], ] START = """ -**Hey {0}** +**ʜᴇʏ {0}** -Welcome to {1} +ᴡᴇʟᴄᴏᴍᴇ ᴛᴏ {1} -If you don't trust this bot, -> Please stop reading this message -> Delete this chat +ɪꜰ ʏᴏᴜ ᴅᴏɴ'ᴛ ᴛʀᴜꜱᴛ ᴛʜɪꜱ ʙᴏᴛ, +> ᴘʟᴇᴀꜱᴇ ꜱᴛᴏᴘ ʀᴇᴀᴅɪɴɢ ᴛʜɪꜱ ᴍᴇꜱꜱᴀɢᴇ +> ᴅᴇʟᴇᴛᴇ ᴛʜɪꜱ ᴄʜᴀᴛ -Still reading? -You can use me to generate Pyrogram and Telethon string sessions. Use the buttons below to learn more! +ꜱᴛɪʟʟ ʀᴇᴀᴅɪɴɢ? +ʏᴏᴜ ᴄᴀɴ ᴜꜱᴇ ᴍᴇ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ ᴘʏʀᴏɢʀᴀᴍ ᴀɴᴅ ᴛᴇʟᴇᴛʜᴏɴ ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴꜱ. ᴜꜱᴇ ᴛʜᴇ ʙᴜᴛᴛᴏɴꜱ ʙᴇʟᴏᴡ ᴛᴏ ʟᴇᴀʀɴ ᴍᴏʀᴇ! -By @ELUpdates** +ʙʏ @The_Architect04** """ HELP = """ -✨ **Available Commands** ✨ - -/about - About the Bot -/help - This Message -/start - Start the Bot -/generate - Generate Session -/cancel - Cancel the process -/restart - Cancel and Restart the process +✨ **ᴀᴠᴀɪʟᴀʙʟᴇ ᴄᴏᴍᴍᴀɴᴅꜱ** ✨ + +/about - ᴀʙᴏᴜᴛ ᴛʜᴇ ʙᴏᴛ +/help - ᴛʜɪꜱ ᴍᴇꜱꜱᴀɢᴇ +/start - ꜱᴛᴀʀᴛ ᴛʜᴇ ʙᴏᴛ +/generate - ɢᴇɴᴇʀᴀᴛᴇ ꜱᴇꜱꜱɪᴏɴ +/cancel - ᴄᴀɴᴄᴇʟ ᴛʜᴇ ᴘʀᴏᴄᴇꜱꜱ +/restart - ᴄᴀɴᴄᴇʟ ᴀɴᴅ ʀᴇꜱᴛᴀʀᴛ ᴛʜᴇ ᴘʀᴏᴄᴇꜱꜱ """ ABOUT = """ -**About This Bot** +**ᴀʙᴏᴜᴛ ᴛʜɪꜱ ʙᴏᴛ** -Telegram Bot to generate Pyrogram and Telethon string sessions by @ELUpdates +ᴛᴇʟᴇɢʀᴀᴍ ʙᴏᴛ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ ᴘʏʀᴏɢʀᴀᴍ ᴀɴᴅ ᴛᴇʟᴇᴛʜᴏɴ ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴꜱ ʙʏ @The_Architect04 -Source Code: [Click Here](https://github.com/EL-Coders/SessionStringBot) +ꜱᴏᴜʀᴄᴇ ᴄᴏᴅᴇ: [ᴄʟɪᴄᴋ ʜᴇʀᴇ](https://github.com/EL-Coders/SessionStringBot) -Framework: [Pyrogram](https://docs.pyrogram.org) +ꜰʀᴀᴍᴇᴡᴏʀᴋ: [ᴘʏʀᴏɢʀᴀᴍ](https://docs.pyrogram.org) -Language: [Python](https://www.python.org) +ʟᴀɴɢᴜᴀɢᴇ: [ᴘʏᴛʜᴏɴ](https://www.python.org) -Developer: @CoderELAlpha +ᴅᴇᴠᴇʟᴏᴘᴇʀ: @Marwin_ll """ From 1219eac9d1c3fe3f026329d2311e79a1684d2ecc Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:53:13 +0530 Subject: [PATCH 12/39] Update data.py --- data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data.py b/data.py index 9ddbbb0..1195e17 100644 --- a/data.py +++ b/data.py @@ -50,7 +50,7 @@ class Data: ᴛᴇʟᴇɢʀᴀᴍ ʙᴏᴛ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ ᴘʏʀᴏɢʀᴀᴍ ᴀɴᴅ ᴛᴇʟᴇᴛʜᴏɴ ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴꜱ ʙʏ @The_Architect04 -ꜱᴏᴜʀᴄᴇ ᴄᴏᴅᴇ: [ᴄʟɪᴄᴋ ʜᴇʀᴇ](https://github.com/EL-Coders/SessionStringBot) +ꜱᴏᴜʀᴄᴇ ᴄᴏᴅᴇ: [ᴄʟɪᴄᴋ ʜᴇʀᴇ](https://github.com/) ꜰʀᴀᴍᴇᴡᴏʀᴋ: [ᴘʏʀᴏɢʀᴀᴍ](https://docs.pyrogram.org) From 2451f0f1d071df370b621811d2b3b8ccd0ac80a5 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 19:55:09 +0530 Subject: [PATCH 13/39] Rename .env.sample to sample.env --- .env.sample => sample.env | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .env.sample => sample.env (100%) diff --git a/.env.sample b/sample.env similarity index 100% rename from .env.sample rename to sample.env From 919625a439f01e906267bc8ffb1be1c1798df6bd Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 20:04:21 +0530 Subject: [PATCH 14/39] Delete ssnbot/plugins/generate.py --- ssnbot/plugins/generate.py | 297 ------------------------------------- 1 file changed, 297 deletions(-) delete mode 100644 ssnbot/plugins/generate.py diff --git a/ssnbot/plugins/generate.py b/ssnbot/plugins/generate.py deleted file mode 100644 index 4900955..0000000 --- a/ssnbot/plugins/generate.py +++ /dev/null @@ -1,297 +0,0 @@ -import asyncio -from asyncio.exceptions import TimeoutError -from pyrogram import Client, filters -from pyrogram.errors import ( - ApiIdInvalid, - PasswordHashInvalid, - PhoneCodeExpired, - PhoneCodeInvalid, - PhoneNumberInvalid, - SessionPasswordNeeded, - PhoneNumberBanned, - PhonePasswordFlood, - AccessTokenInvalid, -) -from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message -from telethon import TelegramClient -from telethon.errors import ( - ApiIdInvalidError, - PasswordHashInvalidError, - PhoneCodeExpiredError, - PhoneCodeInvalidError, - PhoneNumberInvalidError, - SessionPasswordNeededError, - AccessTokenInvalidError, -) -from telethon.sessions import StringSession - -from data import Data -from ssnbot import LOGGER - -ask_ques = "Please choose the python library you want to generate string session for" -buttons_ques = [ - [ - InlineKeyboardButton("Pyrogram", callback_data="pyrogram"), - InlineKeyboardButton("Telethon", callback_data="telethon"), - ], -] - - -@Client.on_message(filters.private & ~filters.forwarded & filters.command("generate")) -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, -): - if telethon: - ty = "Telethon" - else: - ty = "Pyrogram" - if is_bot: - ty += " Bot" - await msg.reply(f"Starting {ty} Session Generation...") - - user_id = msg.chat.id - try: - api_id_msg = await bot.ask_message( - user_id, "Please send your `API_ID`", filters=filters.text, timeout=360 - ) - except TimeoutError: - await msg.reply_text("Request timed out, please try again with /start") - return - - if await cancelled(api_id_msg): - return - - try: - api_id = int(api_id_msg.text) - except ValueError: - await api_id_msg.reply( - "Not a valid API_ID (which must be an integer). Please start generating session again.", - quote=True, - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return - - try: - api_hash_msg = await bot.ask_message( - user_id, "Please send your `API_HASH`", filters=filters.text, timeout=360 - ) - except TimeoutError: - await msg.reply_text("Request timed out, please try again with /start") - return - if await cancelled(api_hash_msg): - return - - api_hash = api_hash_msg.text - if not is_bot: - t = "Now please send your `PHONE_NUMBER` along with the country code. \nExample : `+19876543210`'" - else: - t = "Now please send your `BOT_TOKEN` \nExample : `12345:abcdefghijklmnopqrstuvwxyz`'" - - try: - phone_number_msg = await bot.ask_message( - user_id, t, filters=filters.text, timeout=360 - ) - except TimeoutError: - await msg.reply_text("Request timed out, please try again with /start") - return - - if await cancelled(phone_number_msg): - return - - phone_number = phone_number_msg.text - await msg.reply("Sending OTP...") - - if telethon and is_bot: - clientt = TelegramClient(StringSession(), api_id, api_hash) - await clientt.start(bot_token=phone_number) - elif telethon: - clientt = TelegramClient(StringSession(), api_id, api_hash) - elif is_bot: - clientt = Client( - name="bot", - api_id=api_id, - api_hash=api_hash, - bot_token=phone_number, - in_memory=True, - ) - else: - clientt = Client( - name="sess_user", api_id=api_id, api_hash=api_hash, in_memory=True - ) - - try: - await clientt.connect() - except Exception as e: - LOGGER.error(e) - - try: - code = None - if not is_bot: - if telethon: - code = await clientt.send_code_request(phone_number) - else: - code = await clientt.send_code(phone_number) - except (ApiIdInvalid, ApiIdInvalidError): - await msg.reply( - "`API_ID` and `API_HASH` combination is invalid. Please start generating session again.", - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return - except (PhoneNumberInvalid, PhoneNumberInvalidError): - await msg.reply( - "`PHONE_NUMBER` is invalid. Please start generating session again.", - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return - except PhoneNumberBanned: - await msg.reply("`PHONE_NUMBER` is banned, please try with another number.") - return - except PhonePasswordFlood: - await msg.reply( - "Unable to send code, you have tried logging in too many times." - ) - return - - try: - phone_code_msg = None - if not is_bot: - phone_code_msg = await bot.ask_message( - user_id, - "Please check for an OTP in official telegram account. If you got it, send OTP here after reading the below format. \nIf OTP is `12345`, **please send it as** `1 2 3 4 5`.", - filters=filters.text, - timeout=360, - ) - if await cancelled(phone_code_msg): - return - except TimeoutError: - await msg.reply( - "Time limit reached of 5 minutes. Please start generating session again by tapping /start.", - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return - - if not is_bot: - phone_code = phone_code_msg.text.replace(" ", "") - try: - if telethon: - await clientt.sign_in(phone_number, phone_code, password=None) - else: - await clientt.sign_in(phone_number, code.phone_code_hash, phone_code) - except (PhoneCodeInvalid, PhoneCodeInvalidError): - await msg.reply( - "OTP is invalid. Please start generating session again.", - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return - except (PhoneCodeExpired, PhoneCodeExpiredError): - await msg.reply( - "OTP is expired. Please start generating session again.", - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return - except ( - SessionPasswordNeeded, - SessionPasswordNeededError, - ): - try: - two_step_msg = await bot.ask_message( - user_id, - "Your account has enabled two-step verification. Please provide the password.", - filters=filters.text, - timeout=300, - ) - except TimeoutError: - await msg.reply( - "Time limit reached of 5 minutes. Please start generating session again by tapping /start.", - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return - try: - password = two_step_msg.text - if telethon: - await clientt.sign_in(password=password) - else: - await clientt.check_password(password=password) - if await cancelled(api_id_msg): - return - except ( - PasswordHashInvalid, - PasswordHashInvalidError, - ): - await two_step_msg.reply( - "Invalid Password Provided. Please start generating session again.", - quote=True, - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return - else: - try: - if telethon: - await clientt.start(bot_token=phone_number) - else: - await clientt.sign_in_bot(phone_number) - except (AccessTokenInvalid, AccessTokenInvalidError): - await msg.reply( - "`BOT_TOKEN` is invalid. Please start generating session again.", - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return - - try: - if telethon: - string_session = clientt.session.save() - else: - string_session = await clientt.export_session_string() - except Exception as e: - LOGGER.error(e) - - text = f"**{ty.upper()} STRING SESSION** \n\n`{string_session}` \n\nGenerated by @SessionStringzBot" - try: - if not is_bot: - await clientt.send_message("me", text) - else: - await bot.send_message(msg.chat.id, text) - except KeyError as e: - LOGGER.error(e) - - try: - await clientt.disconnect() - except Exception as e: - LOGGER.error(e) - - await bot.send_message( - msg.chat.id, - "Successfully generated {} string session. \n\nPlease check your saved messages! \n\nBy @ELUpdates".format( - "telethon" if telethon else "pyrogram" - ), - ) - - -async def cancelled(msg): - if "/cancel" in msg.text: - await msg.reply( - "Cancelled the Process!", - quote=True, - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return True - elif "/restart" in msg.text: - await msg.reply( - "Restarted the Bot!", - quote=True, - reply_markup=InlineKeyboardMarkup(Data.generate_button), - ) - return True - elif msg.text.startswith("/"): # Bot Commands - await msg.reply("Cancelled the generation process!", quote=True) - return True - else: - return False From 9be68b90f3bb519829eebeff3ea0da5ac38ad8ca Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 20:04:46 +0530 Subject: [PATCH 15/39] Add files via upload --- ssnbot/plugins/generate.py | 297 +++++++++++++++++++++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100644 ssnbot/plugins/generate.py diff --git a/ssnbot/plugins/generate.py b/ssnbot/plugins/generate.py new file mode 100644 index 0000000..ae12789 --- /dev/null +++ b/ssnbot/plugins/generate.py @@ -0,0 +1,297 @@ +import asyncio +from asyncio.exceptions import TimeoutError +from pyrogram import Client, filters +from pyrogram.errors import ( + ApiIdInvalid, + PasswordHashInvalid, + PhoneCodeExpired, + PhoneCodeInvalid, + PhoneNumberInvalid, + SessionPasswordNeeded, + PhoneNumberBanned, + PhonePasswordFlood, + AccessTokenInvalid, +) +from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message +from telethon import TelegramClient +from telethon.errors import ( + ApiIdInvalidError, + PasswordHashInvalidError, + PhoneCodeExpiredError, + PhoneCodeInvalidError, + PhoneNumberInvalidError, + SessionPasswordNeededError, + AccessTokenInvalidError, +) +from telethon.sessions import StringSession + +from data import Data +from ssnbot import LOGGER + +ask_ques = "ᴘʟᴇᴀꜱᴇ ᴄʜᴏᴏꜱᴇ ᴛʜᴇ ᴘʏᴛʜᴏɴ ʟɪʙʀᴀʀʏ ʏᴏᴜ ᴡᴀɴᴛ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴ ꜰᴏʀ 🤖" +buttons_ques = [ + [ + InlineKeyboardButton("🍷ᴘʏʀᴏɢʀᴀᴍ🍷", callback_data="pyrogram"), + InlineKeyboardButton("🍧ᴛᴇʟᴇᴛʜᴏɴ🍧", callback_data="telethon"), + ], +] + + +@Client.on_message(filters.private & ~filters.forwarded & filters.command("generate")) +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, +): + if telethon: + ty = "Telethon" + else: + ty = "Pyrogram" + if is_bot: + ty += " Bot" + await msg.reply(f"ꜱᴛᴀʀᴛɪɴɢ {ty} ꜱᴇꜱꜱɪᴏɴ ɢᴇɴᴇʀᴀᴛɪᴏɴ🪺...") + + user_id = msg.chat.id + try: + api_id_msg = await bot.ask_message( + user_id, "Please send your `API_ID`", filters=filters.text, timeout=360 + ) + except TimeoutError: + await msg.reply_text("ʀᴇQᴜᴇꜱᴛ ᴛɪᴍᴇᴅ ᴏᴜᴛ, ᴘʟᴇᴀꜱᴇ ᴛʀʏ ᴀɢᴀɪɴ ᴡɪᴛʜ /start") + return + + if await cancelled(api_id_msg): + return + + try: + api_id = int(api_id_msg.text) + except ValueError: + await api_id_msg.reply( + "Not a valid API_ID (which must be an integer). ᴘʟᴇᴀꜱᴇ ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ᴀɢᴀɪɴ🌱.", + quote=True, + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return + + try: + api_hash_msg = await bot.ask_message( + user_id, "ᴘʟᴇᴀꜱᴇ ꜱᴇɴᴅ ʏᴏᴜʀ `API_HASH`", filters=filters.text, timeout=360 + ) + except TimeoutError: + await msg.reply_text("ʀᴇQᴜᴇꜱᴛ ᴛɪᴍᴇᴅ ᴏᴜᴛ, ᴘʟᴇᴀꜱᴇ ᴛʀʏ ᴀɢᴀɪɴ ᴡɪᴛʜ /start") + return + if await cancelled(api_hash_msg): + return + + api_hash = api_hash_msg.text + if not is_bot: + t = "ɴᴏᴡ ᴘʟᴇᴀꜱᴇ ꜱᴇɴᴅ ʏᴏᴜʀ `PHONE_NUMBER` ᴀʟᴏɴɢ ᴡɪᴛʜ ᴛʜᴇ ᴄᴏᴜɴᴛʀʏ ᴄᴏᴅᴇ⚡ \nᴇxᴀᴍᴘʟᴇ : `+19876543210`'" + else: + t = "ɴᴏᴡ ᴘʟᴇᴀꜱᴇ ꜱᴇɴᴅ ʏᴏᴜʀ `BOT_TOKEN` \nᴇxᴀᴍᴘʟᴇ : `12345:abcdefghijklmnopqrstuvwxyz`'" + + try: + phone_number_msg = await bot.ask_message( + user_id, t, filters=filters.text, timeout=360 + ) + except TimeoutError: + await msg.reply_text("ʀᴇQᴜᴇꜱᴛ ᴛɪᴍᴇᴅ ᴏᴜᴛ, ᴘʟᴇᴀꜱᴇ ᴛʀʏ ᴀɢᴀɪɴ /start") + return + + if await cancelled(phone_number_msg): + return + + phone_number = phone_number_msg.text + await msg.reply("ꜱᴇɴᴅɪɴɢ ᴏᴛᴘ👀...") + + if telethon and is_bot: + clientt = TelegramClient(StringSession(), api_id, api_hash) + await clientt.start(bot_token=phone_number) + elif telethon: + clientt = TelegramClient(StringSession(), api_id, api_hash) + elif is_bot: + clientt = Client( + name="bot", + api_id=api_id, + api_hash=api_hash, + bot_token=phone_number, + in_memory=True, + ) + else: + clientt = Client( + name="sess_user", api_id=api_id, api_hash=api_hash, in_memory=True + ) + + try: + await clientt.connect() + except Exception as e: + LOGGER.error(e) + + try: + code = None + if not is_bot: + if telethon: + code = await clientt.send_code_request(phone_number) + else: + code = await clientt.send_code(phone_number) + except (ApiIdInvalid, ApiIdInvalidError): + await msg.reply( + "`API_ID` and `API_HASH` ᴄᴏᴍʙɪɴᴀᴛɪᴏɴ ɪꜱ ɪɴᴠᴀʟɪᴅ. ᴘʟᴇᴀꜱᴇ ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ᴀɢᴀɪɴ😶.", + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return + except (PhoneNumberInvalid, PhoneNumberInvalidError): + await msg.reply( + "`PHONE_NUMBER` ɪꜱ ɪɴᴠᴀʟɪᴅ. ᴘʟᴇᴀꜱᴇ ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ᴀɢᴀɪɴ💤.", + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return + except PhoneNumberBanned: + await msg.reply("`PHONE_NUMBER` ɪꜱ ʙᴀɴɴᴇᴅ, ᴘʟᴇᴀꜱᴇ ᴛʀʏ ᴡɪᴛʜ ᴀɴᴏᴛʜᴇʀ ɴᴜᴍʙᴇʀ🌪️") + return + except PhonePasswordFlood: + await msg.reply( + "ᴜɴᴀʙʟᴇ ᴛᴏ ꜱᴇɴᴅ ᴄᴏᴅᴇ, ʏᴏᴜ ʜᴀᴠᴇ ᴛʀɪᴇᴅ ʟᴏɢɢɪɴɢ ɪɴ ᴛᴏᴏ ᴍᴀɴʏ ᴛɪᴍᴇꜱ🍩" + ) + return + + try: + phone_code_msg = None + if not is_bot: + phone_code_msg = await bot.ask_message( + user_id, + "ᴘʟᴇᴀꜱᴇ ᴄʜᴇᴄᴋ ꜰᴏʀ ᴀɴ ᴏᴛᴘ ɪɴ ᴏꜰꜰɪᴄɪᴀʟ ᴛᴇʟᴇɢʀᴀᴍ ᴀᴄᴄᴏᴜɴᴛ. ɪꜰ ʏᴏᴜ ɢᴏᴛ ɪᴛ, ꜱᴇɴᴅ ᴏᴛᴘ ʜᴇʀᴇ ᴀꜰᴛᴇʀ ʀᴇᴀᴅɪɴɢ ᴛʜᴇ ʙᴇʟᴏᴡ ꜰᴏʀᴍᴀᴛ🍿 \nɪꜰ ᴏᴛᴘ ɪꜱ `12345`, **ᴘʟᴇᴀꜱᴇ ꜱᴇɴᴅ ɪᴛ ᴀꜱ** `1 2 3 4 5`.", + filters=filters.text, + timeout=360, + ) + if await cancelled(phone_code_msg): + return + except TimeoutError: + await msg.reply( + "ᴛɪᴍᴇ ʟɪᴍɪᴛ ʀᴇᴀᴄʜᴇᴅ ᴏꜰ 5 ᴍɪɴᴜᴛᴇꜱ. ᴘʟᴇᴀꜱᴇ ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ᴀɢᴀɪɴ ʙʏ ᴛᴀᴘᴘɪɴɢ😸 /start.", + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return + + if not is_bot: + phone_code = phone_code_msg.text.replace(" ", "") + try: + if telethon: + await clientt.sign_in(phone_number, phone_code, password=None) + else: + await clientt.sign_in(phone_number, code.phone_code_hash, phone_code) + except (PhoneCodeInvalid, PhoneCodeInvalidError): + await msg.reply( + "ᴏᴛᴘ ɪꜱ ɪɴᴠᴀʟɪᴅ. ᴘʟᴇᴀꜱᴇ ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ᴀɢᴀɪɴ🌴", + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return + except (PhoneCodeExpired, PhoneCodeExpiredError): + await msg.reply( + "ᴏᴛᴘ ɪꜱ ᴇxᴘɪʀᴇᴅ. ᴘʟᴇᴀꜱᴇ ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ᴀɢᴀɪɴ🍬", + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return + except ( + SessionPasswordNeeded, + SessionPasswordNeededError, + ): + try: + two_step_msg = await bot.ask_message( + user_id, + "ʏᴏᴜʀ ᴀᴄᴄᴏᴜɴᴛ ʜᴀꜱ ᴇɴᴀʙʟᴇᴅ ᴛᴡᴏ-ꜱᴛᴇᴘ ᴠᴇʀɪꜰɪᴄᴀᴛɪᴏɴ. ᴘʟᴇᴀꜱᴇ ᴘʀᴏᴠɪᴅᴇ ᴛʜᴇ ᴘᴀꜱꜱᴡᴏʀᴅ🙈", + filters=filters.text, + timeout=300, + ) + except TimeoutError: + await msg.reply( + "ᴛɪᴍᴇ ʟɪᴍɪᴛ ʀᴇᴀᴄʜᴇᴅ ᴏꜰ 5 ᴍɪɴᴜᴛᴇꜱ. ᴘʟᴇᴀꜱᴇ ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ᴀɢᴀɪɴ ʙʏ ᴛᴀᴘᴘɪɴɢ /start.", + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return + try: + password = two_step_msg.text + if telethon: + await clientt.sign_in(password=password) + else: + await clientt.check_password(password=password) + if await cancelled(api_id_msg): + return + except ( + PasswordHashInvalid, + PasswordHashInvalidError, + ): + await two_step_msg.reply( + "ɪɴᴠᴀʟɪᴅ ᴘᴀꜱꜱᴡᴏʀᴅ ᴘʀᴏᴠɪᴅᴇᴅ. ᴘʟᴇᴀꜱᴇ ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ᴀɢᴀɪɴ🫧", + quote=True, + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return + else: + try: + if telethon: + await clientt.start(bot_token=phone_number) + else: + await clientt.sign_in_bot(phone_number) + except (AccessTokenInvalid, AccessTokenInvalidError): + await msg.reply( + "`BOT_TOKEN` ɪꜱ ɪɴᴠᴀʟɪᴅ. ᴘʟᴇᴀꜱᴇ ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ᴀɢᴀɪɴ🙁", + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return + + try: + if telethon: + string_session = clientt.session.save() + else: + string_session = await clientt.export_session_string() + except Exception as e: + LOGGER.error(e) + + text = f"**{ty.upper()} STRING SESSION** \n\n`{string_session}` \n\nɢᴇɴᴇʀᴀᴛᴇᴅ ʙʏ @The_Architect04" + try: + if not is_bot: + await clientt.send_message("me", text) + else: + await bot.send_message(msg.chat.id, text) + except KeyError as e: + LOGGER.error(e) + + try: + await clientt.disconnect() + except Exception as e: + LOGGER.error(e) + + await bot.send_message( + msg.chat.id, + "ꜱᴜᴄᴄᴇꜱꜱꜰᴜʟʟʏ ɢᴇɴᴇʀᴀᴛᴇᴅ {} ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴ. \n\nᴘʟᴇᴀꜱᴇ ᴄʜᴇᴄᴋ ʏᴏᴜʀ ꜱᴀᴠᴇᴅ ᴍᴇꜱꜱᴀɢᴇꜱ🍫 \n\nʙʏ @The_Architect04".format( + "telethon" if telethon else "pyrogram" + ), + ) + + +async def cancelled(msg): + if "/cancel" in msg.text: + await msg.reply( + "Cancelled the Process!", + quote=True, + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return True + elif "/restart" in msg.text: + await msg.reply( + "Restarted the Bot!", + quote=True, + reply_markup=InlineKeyboardMarkup(Data.generate_button), + ) + return True + elif msg.text.startswith("/"): # Bot Commands + await msg.reply("Cancelled the generation process!", quote=True) + return True + else: + return False From 095aa1ba122d70986fce9e9cff6eca01b03c1e64 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 20:12:45 +0530 Subject: [PATCH 16/39] Update data.py --- data.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/data.py b/data.py index 1195e17..4d2fc70 100644 --- a/data.py +++ b/data.py @@ -2,21 +2,21 @@ class Data: - generate_single_button = InlineKeyboardButton("🔥 ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ ", callback_data="generate") + generate_single_button = InlineKeyboardButton("🦋 ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ 🦋", callback_data="generate") home_buttons = [ [generate_single_button], - [InlineKeyboardButton(text="🏠 ʀᴇᴛᴜʀɴ ʜᴏᴍᴇ 🏠", callback_data="home")] + [InlineKeyboardButton(text="🧃 ʀᴇᴛᴜʀɴ ʜᴏᴍᴇ 🧃", callback_data="home")] ] buttons = [ [generate_single_button], - [InlineKeyboardButton("✨ ʙᴏᴛ ꜱᴛᴀᴛᴜꜱ ᴀɴᴅ ᴍᴏʀᴇ ʙᴏᴛꜱ ✨", url="https://t.me/ELUpdates/8")], + [InlineKeyboardButton("🍬 ʙᴏᴛ ꜱᴛᴀᴛᴜꜱ ᴀɴᴅ ᴍᴏʀᴇ ʙᴏᴛꜱ 🍬", url="https://t.me/The_Architect04/13")], [ - InlineKeyboardButton("ʜᴏᴡ ᴛᴏ ᴜꜱᴇ ❔", callback_data="help"), - InlineKeyboardButton("🎪 ᴀʙᴏᴜᴛ 🎪", callback_data="about") + InlineKeyboardButton("👻 ʜᴏᴡ ᴛᴏ ᴜꜱᴇ 👻", callback_data="help"), + InlineKeyboardButton("🌲 ᴀʙᴏᴜᴛ 🌲", callback_data="about") ], - [InlineKeyboardButton("♥ ᴍᴏʀᴇ ᴀᴍᴀᴢɪɴɢ ʙᴏᴛꜱ ♥", url="https://t.me/ELUpdates")], + [InlineKeyboardButton("⚡ ᴍᴏʀᴇ ᴀᴍᴀᴢɪɴɢ ʙᴏᴛꜱ ⚡", url="https://t.me/The_Architect04")], ] START = """ @@ -35,7 +35,7 @@ class Data: """ HELP = """ -✨ **ᴀᴠᴀɪʟᴀʙʟᴇ ᴄᴏᴍᴍᴀɴᴅꜱ** ✨ +🌴 **ᴀᴠᴀɪʟᴀʙʟᴇ ᴄᴏᴍᴍᴀɴᴅꜱ** 🌴 /about - ᴀʙᴏᴜᴛ ᴛʜᴇ ʙᴏᴛ /help - ᴛʜɪꜱ ᴍᴇꜱꜱᴀɢᴇ From 3d0fe5770d5115ad671ae28a51aeadbbc2cfb8f9 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 20:15:56 +0530 Subject: [PATCH 17/39] Update runtime.txt --- runtime.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime.txt b/runtime.txt index 3338e5c..431fc7e 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.10.4 \ No newline at end of file +python-3.11.4 From 3a3946275176e487d1944dc12030a3389bf6849d Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 20:16:20 +0530 Subject: [PATCH 18/39] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index dbf2abe..6a66a09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ Telethon # Telegram client library git+https://github.com/rahulps1000/pyropatch.git@pyrotgfork # Custom Pyrogram patch fork TgCrypto # Cryptographic library for Telegram uvloop # Fast asyncio event loop -python-3.10.4 +python-3.11.4 From 88c47e203f5fe0e17ef8d4218bc4597ab94fc552 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 20:31:30 +0530 Subject: [PATCH 19/39] Update callbacks.py --- ssnbot/plugins/callbacks.py | 125 ++++++++++++------------------------ 1 file changed, 41 insertions(+), 84 deletions(-) diff --git a/ssnbot/plugins/callbacks.py b/ssnbot/plugins/callbacks.py index a063128..6980a93 100644 --- a/ssnbot/plugins/callbacks.py +++ b/ssnbot/plugins/callbacks.py @@ -5,126 +5,83 @@ from ssnbot.plugins.generate import generate_session, ask_ques, buttons_ques from ssnbot import LOGGER -# Default messages to avoid issues if Data variables are undefined -DEFAULT_START = "Welcome, {0}! Use the buttons below to navigate." -DEFAULT_ABOUT = "This bot allows you to generate session strings for your libraries." -DEFAULT_HELP = "Click the buttons below to explore more features or get help." -DEFAULT_ERROR_MESSAGE = ( - "Oops! An error occurred! \n\n**Error** : {} " - "\n\nPlease contact @ElUpdates if this message is unclear or if you need further assistance." -) - @Client.on_callback_query(filters.regex(r"^home$")) async def home(bot, query): - """ - Handles the 'home' callback. - Sends the start message with navigation buttons. - """ - try: - user = await bot.get_me() - mention = user.mention - chat_id = query.from_user.id - message_id = query.message.id - await bot.edit_message_text( - chat_id=chat_id, - message_id=message_id, - text=Data.START.format(query.from_user.mention, mention) if Data.START else DEFAULT_START.format(query.from_user.mention), - reply_markup=InlineKeyboardMarkup(Data.buttons), - ) - except Exception as e: - LOGGER.error(traceback.format_exc()) - await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) + user = bot.me + mention = user.mention + chat_id = query.from_user.id + message_id = query.message.id + await bot.edit_message_text( + chat_id=chat_id, + message_id=message_id, + text=Data.START.format(query.from_user.mention, mention), + reply_markup=InlineKeyboardMarkup(Data.buttons), + ) @Client.on_callback_query(filters.regex(r"^about$")) async def about(bot, query): - """ - Handles the 'about' callback. - Sends the about message. - """ - try: - chat_id = query.from_user.id - message_id = query.message.id - await bot.edit_message_text( - chat_id=chat_id, - message_id=message_id, - text=Data.ABOUT if Data.ABOUT else DEFAULT_ABOUT, - link_preview_options=LinkPreviewOptions(is_disabled=True), - reply_markup=InlineKeyboardMarkup(Data.home_buttons), - ) - except Exception as e: - LOGGER.error(traceback.format_exc()) - await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) + chat_id = query.from_user.id + message_id = query.message.id + await bot.edit_message_text( + chat_id=chat_id, + message_id=message_id, + text=Data.ABOUT, + # disable_web_page_preview=True, + link_preview_options=LinkPreviewOptions(is_disabled=True), + reply_markup=InlineKeyboardMarkup(Data.home_buttons), + ) @Client.on_callback_query(filters.regex(r"^help$")) async def help(bot, query): - """ - Handles the 'help' callback. - Sends the help message with navigation buttons. - """ - try: - chat_id = query.from_user.id - message_id = query.message.id - await bot.edit_message_text( - chat_id=chat_id, - message_id=message_id, - text=Data.HELP if Data.HELP else DEFAULT_HELP, - link_preview_options=LinkPreviewOptions(is_disabled=True), - reply_markup=InlineKeyboardMarkup(Data.home_buttons), - ) - except Exception as e: - LOGGER.error(traceback.format_exc()) - await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) + chat_id = query.from_user.id + message_id = query.message.id + await bot.edit_message_text( + chat_id=chat_id, + message_id=message_id, + text=Data.HELP, + # disable_web_page_preview=True, + link_preview_options=LinkPreviewOptions(is_disabled=True), + reply_markup=InlineKeyboardMarkup(Data.home_buttons), + ) @Client.on_callback_query(filters.regex(r"^generate$")) async def generate(bot, query): - """ - Handles the 'generate' callback. - Prompts the user to choose a library for session generation. - """ - try: - await query.answer("Select your library") - await query.message.reply(ask_ques, reply_markup=InlineKeyboardMarkup(buttons_ques)) - except Exception as e: - LOGGER.error(traceback.format_exc()) - await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) + await query.answer("Select your library") + await query.message.reply(ask_ques, reply_markup=InlineKeyboardMarkup(buttons_ques)) @Client.on_callback_query(filters.regex(r"^pyrogram$")) async def pyro(bot, query): - """ - Handles the 'pyrogram' callback. - Generates a session string for Pyrogram. - """ try: await query.answer( - "Note: New string sessions may not work with older bots. Ensure compatibility with Pyrogram v2.", + "Please note that the new type of string sessions may not work in all bots, i.e, only the bots that have been updated to pyrogram v2 will work!", show_alert=True, ) await generate_session(bot, query.message) except Exception as e: LOGGER.error(traceback.format_exc()) - await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) + LOGGER.error(e) + await query.message.reply(ERROR_MESSAGE.format(str(e))) @Client.on_callback_query(filters.regex(r"^telethon$")) async def tele(bot, query): - """ - Handles the 'telethon' callback. - Generates a session string for Telethon. - """ try: await query.answer() await generate_session(bot, query.message, telethon=True) except Exception as e: LOGGER.error(traceback.format_exc()) - await query.message.reply(DEFAULT_ERROR_MESSAGE.format(str(e))) + LOGGER.error(e) + await query.message.reply(ERROR_MESSAGE.format(str(e))) ERROR_MESSAGE = ( - "Oops! An error occurred! \n\n**Error** : {} " - "\n\nPlease contact @ElUpdates if this message is unclear or if you need further assistance." + "Oops! An exception occurred! \n\n**Error** : {} " + "\n\nPlease visit @The_Architect04 if this message doesn't contain any " + "sensitive information and you if want to report this as " + "this error message is not being logged by us!" ) From 2f5373d94d31f6346b00aafb607b0849838b1b48 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 20:34:58 +0530 Subject: [PATCH 20/39] Update config.ini --- config.ini | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/config.ini b/config.ini index 5aa25cb..4f76541 100644 --- a/config.ini +++ b/config.ini @@ -2,33 +2,33 @@ keys=root,Logger [handlers] -keys=consoleHandler, fileHandler +keys=consoleHandler, file_handler [formatters] keys=Formatter [logger_root] -level=DEBUG -handlers=consoleHandler, fileHandler +level=INFO +handlers=consoleHandler, file_handler [logger_Logger] -level=DEBUG -handlers=consoleHandler, fileHandler +level=INFO +handlers=consoleHandler, file_handler qualname=Logger -propagate=1 +propagate=0 [handler_consoleHandler] class=StreamHandler -level=DEBUG +level=INFO formatter=Formatter args=(sys.stdout,) -[handler_fileHandler] +[handler_file_handler] class=FileHandler -level=DEBUG +level=INFO formatter=Formatter -args=('logs/logs.txt', 'a',) +args=('logs.txt','w',) [formatter_Formatter] -format=[%(asctime)s][%(name)s][%(module)s][%(lineno)d][%(levelname)s] -> %(message)s -datefmt=%d/%m/%Y %H:%M:%S +format= [%(asctime)s][%(name)s][%(module)s][%(lineno)d][%(levelname)s] -> %(message)s +datefmt= %d/%m/%Y %H:%M:%S From 45f4d4c9533a8e97a129c5d88acaa0a852b89bda Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 21:18:49 +0530 Subject: [PATCH 21/39] Update must_join.py --- ssnbot/plugins/must_join.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ssnbot/plugins/must_join.py b/ssnbot/plugins/must_join.py index ca50a3e..5c99fe1 100644 --- a/ssnbot/plugins/must_join.py +++ b/ssnbot/plugins/must_join.py @@ -19,11 +19,11 @@ async def must_join_channel(bot: Client, msg: Message): link = chat_info.invite_link try: await msg.reply( - f"You must join [this channel]({link}) to use me. After joining try again !", + f"ᴛᴏ ᴜᴛɪʟɪᴢᴇ ᴍʏ ꜱᴇʀᴠɪᴄᴇꜱ, ᴘʟᴇᴀꜱᴇ ᴊᴏɪɴ [ᴛʜɪꜱ ᴄʜᴀɴɴᴇʟ]({link}) ꜰɪʀꜱᴛ. ᴛʜᴇɴ ʏᴏᴜ ᴄᴀɴ ᴀᴛᴛᴇᴍᴘᴛ ᴀɢᴀɪɴ 🧑‍💻", # disable_web_page_preview=True, link_preview_options=LinkPreviewOptions(is_disabled=True), reply_markup=InlineKeyboardMarkup([ - [InlineKeyboardButton("✨ Join Channel ✨", url=link)] + [InlineKeyboardButton("❤️‍🩹 ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ ❤️‍🩹", url=link)] ]) ) await msg.stop_propagation() From 43ae7d5fb5e860477e94b019b873fa89c604c675 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 21:19:34 +0530 Subject: [PATCH 22/39] Update must_join.py --- ssnbot/plugins/must_join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ssnbot/plugins/must_join.py b/ssnbot/plugins/must_join.py index 5c99fe1..4e5668f 100644 --- a/ssnbot/plugins/must_join.py +++ b/ssnbot/plugins/must_join.py @@ -19,7 +19,7 @@ async def must_join_channel(bot: Client, msg: Message): link = chat_info.invite_link try: await msg.reply( - f"ᴛᴏ ᴜᴛɪʟɪᴢᴇ ᴍʏ ꜱᴇʀᴠɪᴄᴇꜱ, ᴘʟᴇᴀꜱᴇ ᴊᴏɪɴ [ᴛʜɪꜱ ᴄʜᴀɴɴᴇʟ]({link}) ꜰɪʀꜱᴛ. ᴛʜᴇɴ ʏᴏᴜ ᴄᴀɴ ᴀᴛᴛᴇᴍᴘᴛ ᴀɢᴀɪɴ 🧑‍💻", + f"ᴛᴏ ᴜᴛɪʟɪᴢᴇ ᴍʏ ꜱᴇʀᴠɪᴄᴇꜱ,ᴘʟᴇᴀꜱᴇ ᴊᴏɪɴ [ᴛʜɪꜱ ᴄʜᴀɴɴᴇʟ]({link}) ꜰɪʀꜱᴛ.ᴛʜᴇɴ ʏᴏᴜ ᴄᴀɴ ᴀᴛᴛᴇᴍᴘᴛ ᴀɢᴀɪɴ 🧑‍💻", # disable_web_page_preview=True, link_preview_options=LinkPreviewOptions(is_disabled=True), reply_markup=InlineKeyboardMarkup([ From e66c49c6d644faaff3924bf8c3174088cabb7fe0 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Fri, 27 Dec 2024 21:34:58 +0530 Subject: [PATCH 23/39] Update must_join.py --- ssnbot/plugins/must_join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ssnbot/plugins/must_join.py b/ssnbot/plugins/must_join.py index 4e5668f..5c99fe1 100644 --- a/ssnbot/plugins/must_join.py +++ b/ssnbot/plugins/must_join.py @@ -19,7 +19,7 @@ async def must_join_channel(bot: Client, msg: Message): link = chat_info.invite_link try: await msg.reply( - f"ᴛᴏ ᴜᴛɪʟɪᴢᴇ ᴍʏ ꜱᴇʀᴠɪᴄᴇꜱ,ᴘʟᴇᴀꜱᴇ ᴊᴏɪɴ [ᴛʜɪꜱ ᴄʜᴀɴɴᴇʟ]({link}) ꜰɪʀꜱᴛ.ᴛʜᴇɴ ʏᴏᴜ ᴄᴀɴ ᴀᴛᴛᴇᴍᴘᴛ ᴀɢᴀɪɴ 🧑‍💻", + f"ᴛᴏ ᴜᴛɪʟɪᴢᴇ ᴍʏ ꜱᴇʀᴠɪᴄᴇꜱ, ᴘʟᴇᴀꜱᴇ ᴊᴏɪɴ [ᴛʜɪꜱ ᴄʜᴀɴɴᴇʟ]({link}) ꜰɪʀꜱᴛ. ᴛʜᴇɴ ʏᴏᴜ ᴄᴀɴ ᴀᴛᴛᴇᴍᴘᴛ ᴀɢᴀɪɴ 🧑‍💻", # disable_web_page_preview=True, link_preview_options=LinkPreviewOptions(is_disabled=True), reply_markup=InlineKeyboardMarkup([ From be60a73cd31dde3887ef644eb70375431222948c Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 16:19:04 +0530 Subject: [PATCH 24/39] Update data.py --- data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data.py b/data.py index 4d2fc70..bbad8e7 100644 --- a/data.py +++ b/data.py @@ -15,8 +15,8 @@ class Data: [ InlineKeyboardButton("👻 ʜᴏᴡ ᴛᴏ ᴜꜱᴇ 👻", callback_data="help"), InlineKeyboardButton("🌲 ᴀʙᴏᴜᴛ 🌲", callback_data="about") - ], - [InlineKeyboardButton("⚡ ᴍᴏʀᴇ ᴀᴍᴀᴢɪɴɢ ʙᴏᴛꜱ ⚡", url="https://t.me/The_Architect04")], + ] + ] START = """ From 5445be2dda78eb7eac27bb4307161b097c4a978a Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 16:27:29 +0530 Subject: [PATCH 25/39] Update broadcast.py --- ssnbot/plugins/broadcast.py | 48 ++++++++----------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/ssnbot/plugins/broadcast.py b/ssnbot/plugins/broadcast.py index ed3878b..9ec758d 100644 --- a/ssnbot/plugins/broadcast.py +++ b/ssnbot/plugins/broadcast.py @@ -1,6 +1,6 @@ import asyncio from pyrogram import Client, filters -from pyrogram.errors import FloodWait, RPCError +from pyrogram.errors import FloodWait from pyrogram.types import Message from ssnbot import ADMINS from ssnbot.db.sql import query_msg @@ -9,70 +9,42 @@ @Client.on_message(filters.private & filters.command("stats")) async def get_subscribers_count(bot: Client, message: Message): - """ - Fetch and display subscriber statistics. - Only accessible to admins. - """ user_id = message.from_user.id if user_id not in ADMINS: return - wait_msg = "__Calculating, please wait...__" msg = await message.reply_text(wait_msg) - active, blocked = await users_info(bot) - stats_msg = ( - f"**📊 Stats**\n" - f"👤 Active Subscribers: `{active}`\n" - f"🚫 Blocked / Deleted: `{blocked}`" - ) + stats_msg = f"**Stats**\nSubscribers: `{active}`\nBlocked / Deleted: `{blocked}`" await msg.edit(stats_msg) @Client.on_message(filters.private & filters.command("broadcast")) -async def send_text(bot: Client, message: Message): - """ - Broadcast a message to all users in the database. - Usage: Reply to a message with the /broadcast command. - """ +async def send_text(bot, message: Message): user_id = message.from_user.id if user_id not in ADMINS: return - if message.reply_to_message: + if "broadcast" in message.text and message.reply_to_message is not None: query = await query_msg() - sent, failed = 0, 0 for row in query: chat_id = int(row[0]) try: await bot.copy_message( chat_id=chat_id, from_chat_id=message.chat.id, - message_id=message.reply_to_message.message_id, - caption=message.reply_to_message.caption or "", + message_id=message.reply_to_message_id, + caption=message.reply_to_message.caption, reply_markup=message.reply_to_message.reply_markup, ) - sent += 1 except FloodWait as e: await asyncio.sleep(e.value) - except RPCError as e: - failed += 1 - print(f"Failed to send message to {chat_id}: {e}") - except Exception as e: - failed += 1 - print(f"Unexpected error for {chat_id}: {e}") - - await message.reply_text( - f"**Broadcast Report**\n" - f"✅ Sent: `{sent}`\n" - f"❌ Failed: `{failed}`" - ) + except Exception: + pass else: reply_error = ( - "❗ **Usage Error:**\n" - "Reply to a message with `/broadcast` to send it to all subscribers." + "`Use this command as a reply to any telegram message without any spaces.`" ) - msg = await message.reply_text(reply_error) + msg = await message.reply_text(reply_error, message.id) await asyncio.sleep(8) await msg.delete() - From e18738ed328eb59de8c1fbc9db88555476f21e87 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 16:44:36 +0530 Subject: [PATCH 26/39] Update data.py --- data.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/data.py b/data.py index bbad8e7..1aaab47 100644 --- a/data.py +++ b/data.py @@ -1,6 +1,5 @@ from pyrogram.types import InlineKeyboardButton - class Data: generate_single_button = InlineKeyboardButton("🦋 ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ 🦋", callback_data="generate") @@ -16,8 +15,7 @@ class Data: InlineKeyboardButton("👻 ʜᴏᴡ ᴛᴏ ᴜꜱᴇ 👻", callback_data="help"), InlineKeyboardButton("🌲 ᴀʙᴏᴜᴛ 🌲", callback_data="about") ] - - ] + ] START = """ **ʜᴇʏ {0}** From 7f27bd9cdb13925282fbd5b66f3c5eedc0b50429 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 16:47:08 +0530 Subject: [PATCH 27/39] Delete data.py --- data.py | 58 --------------------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 data.py diff --git a/data.py b/data.py deleted file mode 100644 index 1aaab47..0000000 --- a/data.py +++ /dev/null @@ -1,58 +0,0 @@ -from pyrogram.types import InlineKeyboardButton - -class Data: - generate_single_button = InlineKeyboardButton("🦋 ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ 🦋", callback_data="generate") - - home_buttons = [ - [generate_single_button], - [InlineKeyboardButton(text="🧃 ʀᴇᴛᴜʀɴ ʜᴏᴍᴇ 🧃", callback_data="home")] - ] - - buttons = [ - [generate_single_button], - [InlineKeyboardButton("🍬 ʙᴏᴛ ꜱᴛᴀᴛᴜꜱ ᴀɴᴅ ᴍᴏʀᴇ ʙᴏᴛꜱ 🍬", url="https://t.me/The_Architect04/13")], - [ - InlineKeyboardButton("👻 ʜᴏᴡ ᴛᴏ ᴜꜱᴇ 👻", callback_data="help"), - InlineKeyboardButton("🌲 ᴀʙᴏᴜᴛ 🌲", callback_data="about") - ] - ] - - START = """ -**ʜᴇʏ {0}** - -ᴡᴇʟᴄᴏᴍᴇ ᴛᴏ {1} - -ɪꜰ ʏᴏᴜ ᴅᴏɴ'ᴛ ᴛʀᴜꜱᴛ ᴛʜɪꜱ ʙᴏᴛ, -> ᴘʟᴇᴀꜱᴇ ꜱᴛᴏᴘ ʀᴇᴀᴅɪɴɢ ᴛʜɪꜱ ᴍᴇꜱꜱᴀɢᴇ -> ᴅᴇʟᴇᴛᴇ ᴛʜɪꜱ ᴄʜᴀᴛ - -ꜱᴛɪʟʟ ʀᴇᴀᴅɪɴɢ? -ʏᴏᴜ ᴄᴀɴ ᴜꜱᴇ ᴍᴇ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ ᴘʏʀᴏɢʀᴀᴍ ᴀɴᴅ ᴛᴇʟᴇᴛʜᴏɴ ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴꜱ. ᴜꜱᴇ ᴛʜᴇ ʙᴜᴛᴛᴏɴꜱ ʙᴇʟᴏᴡ ᴛᴏ ʟᴇᴀʀɴ ᴍᴏʀᴇ! - -ʙʏ @The_Architect04** - """ - - HELP = """ -🌴 **ᴀᴠᴀɪʟᴀʙʟᴇ ᴄᴏᴍᴍᴀɴᴅꜱ** 🌴 - -/about - ᴀʙᴏᴜᴛ ᴛʜᴇ ʙᴏᴛ -/help - ᴛʜɪꜱ ᴍᴇꜱꜱᴀɢᴇ -/start - ꜱᴛᴀʀᴛ ᴛʜᴇ ʙᴏᴛ -/generate - ɢᴇɴᴇʀᴀᴛᴇ ꜱᴇꜱꜱɪᴏɴ -/cancel - ᴄᴀɴᴄᴇʟ ᴛʜᴇ ᴘʀᴏᴄᴇꜱꜱ -/restart - ᴄᴀɴᴄᴇʟ ᴀɴᴅ ʀᴇꜱᴛᴀʀᴛ ᴛʜᴇ ᴘʀᴏᴄᴇꜱꜱ -""" - - ABOUT = """ -**ᴀʙᴏᴜᴛ ᴛʜɪꜱ ʙᴏᴛ** - -ᴛᴇʟᴇɢʀᴀᴍ ʙᴏᴛ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ ᴘʏʀᴏɢʀᴀᴍ ᴀɴᴅ ᴛᴇʟᴇᴛʜᴏɴ ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴꜱ ʙʏ @The_Architect04 - -ꜱᴏᴜʀᴄᴇ ᴄᴏᴅᴇ: [ᴄʟɪᴄᴋ ʜᴇʀᴇ](https://github.com/) - -ꜰʀᴀᴍᴇᴡᴏʀᴋ: [ᴘʏʀᴏɢʀᴀᴍ](https://docs.pyrogram.org) - -ʟᴀɴɢᴜᴀɢᴇ: [ᴘʏᴛʜᴏɴ](https://www.python.org) - -ᴅᴇᴠᴇʟᴏᴘᴇʀ: @Marwin_ll - """ From 072cfce4c4c7dacda03938b87cb4b51247985cc5 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 16:47:28 +0530 Subject: [PATCH 28/39] Add files via upload --- data.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 data.py diff --git a/data.py b/data.py new file mode 100644 index 0000000..4d2fc70 --- /dev/null +++ b/data.py @@ -0,0 +1,60 @@ +from pyrogram.types import InlineKeyboardButton + + +class Data: + generate_single_button = InlineKeyboardButton("🦋 ꜱᴛᴀʀᴛ ɢᴇɴᴇʀᴀᴛɪɴɢ ꜱᴇꜱꜱɪᴏɴ 🦋", callback_data="generate") + + home_buttons = [ + [generate_single_button], + [InlineKeyboardButton(text="🧃 ʀᴇᴛᴜʀɴ ʜᴏᴍᴇ 🧃", callback_data="home")] + ] + + buttons = [ + [generate_single_button], + [InlineKeyboardButton("🍬 ʙᴏᴛ ꜱᴛᴀᴛᴜꜱ ᴀɴᴅ ᴍᴏʀᴇ ʙᴏᴛꜱ 🍬", url="https://t.me/The_Architect04/13")], + [ + InlineKeyboardButton("👻 ʜᴏᴡ ᴛᴏ ᴜꜱᴇ 👻", callback_data="help"), + InlineKeyboardButton("🌲 ᴀʙᴏᴜᴛ 🌲", callback_data="about") + ], + [InlineKeyboardButton("⚡ ᴍᴏʀᴇ ᴀᴍᴀᴢɪɴɢ ʙᴏᴛꜱ ⚡", url="https://t.me/The_Architect04")], + ] + + START = """ +**ʜᴇʏ {0}** + +ᴡᴇʟᴄᴏᴍᴇ ᴛᴏ {1} + +ɪꜰ ʏᴏᴜ ᴅᴏɴ'ᴛ ᴛʀᴜꜱᴛ ᴛʜɪꜱ ʙᴏᴛ, +> ᴘʟᴇᴀꜱᴇ ꜱᴛᴏᴘ ʀᴇᴀᴅɪɴɢ ᴛʜɪꜱ ᴍᴇꜱꜱᴀɢᴇ +> ᴅᴇʟᴇᴛᴇ ᴛʜɪꜱ ᴄʜᴀᴛ + +ꜱᴛɪʟʟ ʀᴇᴀᴅɪɴɢ? +ʏᴏᴜ ᴄᴀɴ ᴜꜱᴇ ᴍᴇ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ ᴘʏʀᴏɢʀᴀᴍ ᴀɴᴅ ᴛᴇʟᴇᴛʜᴏɴ ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴꜱ. ᴜꜱᴇ ᴛʜᴇ ʙᴜᴛᴛᴏɴꜱ ʙᴇʟᴏᴡ ᴛᴏ ʟᴇᴀʀɴ ᴍᴏʀᴇ! + +ʙʏ @The_Architect04** + """ + + HELP = """ +🌴 **ᴀᴠᴀɪʟᴀʙʟᴇ ᴄᴏᴍᴍᴀɴᴅꜱ** 🌴 + +/about - ᴀʙᴏᴜᴛ ᴛʜᴇ ʙᴏᴛ +/help - ᴛʜɪꜱ ᴍᴇꜱꜱᴀɢᴇ +/start - ꜱᴛᴀʀᴛ ᴛʜᴇ ʙᴏᴛ +/generate - ɢᴇɴᴇʀᴀᴛᴇ ꜱᴇꜱꜱɪᴏɴ +/cancel - ᴄᴀɴᴄᴇʟ ᴛʜᴇ ᴘʀᴏᴄᴇꜱꜱ +/restart - ᴄᴀɴᴄᴇʟ ᴀɴᴅ ʀᴇꜱᴛᴀʀᴛ ᴛʜᴇ ᴘʀᴏᴄᴇꜱꜱ +""" + + ABOUT = """ +**ᴀʙᴏᴜᴛ ᴛʜɪꜱ ʙᴏᴛ** + +ᴛᴇʟᴇɢʀᴀᴍ ʙᴏᴛ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ ᴘʏʀᴏɢʀᴀᴍ ᴀɴᴅ ᴛᴇʟᴇᴛʜᴏɴ ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴꜱ ʙʏ @The_Architect04 + +ꜱᴏᴜʀᴄᴇ ᴄᴏᴅᴇ: [ᴄʟɪᴄᴋ ʜᴇʀᴇ](https://github.com/) + +ꜰʀᴀᴍᴇᴡᴏʀᴋ: [ᴘʏʀᴏɢʀᴀᴍ](https://docs.pyrogram.org) + +ʟᴀɴɢᴜᴀɢᴇ: [ᴘʏᴛʜᴏɴ](https://www.python.org) + +ᴅᴇᴠᴇʟᴏᴘᴇʀ: @Marwin_ll + """ From c647e0cbf360e975731dcb1761acbd052413e0a5 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 16:57:49 +0530 Subject: [PATCH 29/39] Update __init__.py --- ssnbot/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ssnbot/__init__.py b/ssnbot/__init__.py index 7509aab..37f5c2a 100644 --- a/ssnbot/__init__.py +++ b/ssnbot/__init__.py @@ -13,7 +13,7 @@ API_HASH = os.environ.get("API_HASH", "") BOT_TOKEN = os.environ.get("BOT_TOKEN", "") DB_URL = os.environ.get("DB_URL", "") -OWNER_ID = int(os.environ.get('OWNER_ID', "")) +OWNER_ID = int(os.environ.get('OWNER_ID', "7224419362")) MUST_JOIN = os.environ.get("MUST_JOIN", "") ADMINS = [ int(user) if pattern.search(user) else user @@ -24,4 +24,4 @@ # logging Conf logging.config.fileConfig(fname='config.ini', disable_existing_loggers=False) LOGGER = logging.getLogger(__name__) -logging.getLogger("pyrogram").setLevel(logging.WARNING) \ No newline at end of file +logging.getLogger("pyrogram").setLevel(logging.WARNING) From 85f7cdd79faa7e3d1abac9ca6547107e6ad6ab5c Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 17:07:09 +0530 Subject: [PATCH 30/39] Update __init__.py --- ssnbot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ssnbot/__init__.py b/ssnbot/__init__.py index 37f5c2a..94b3191 100644 --- a/ssnbot/__init__.py +++ b/ssnbot/__init__.py @@ -13,7 +13,7 @@ API_HASH = os.environ.get("API_HASH", "") BOT_TOKEN = os.environ.get("BOT_TOKEN", "") DB_URL = os.environ.get("DB_URL", "") -OWNER_ID = int(os.environ.get('OWNER_ID', "7224419362")) +OWNER_ID = int(os.environ.get('OWNER_ID', "")) MUST_JOIN = os.environ.get("MUST_JOIN", "") ADMINS = [ int(user) if pattern.search(user) else user From a185d874ff9c5b9046c008394fcf3fa1aff30a23 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 17:14:42 +0530 Subject: [PATCH 31/39] Update callbacks.py --- ssnbot/plugins/callbacks.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/ssnbot/plugins/callbacks.py b/ssnbot/plugins/callbacks.py index 6980a93..3f5dae2 100644 --- a/ssnbot/plugins/callbacks.py +++ b/ssnbot/plugins/callbacks.py @@ -1,10 +1,16 @@ import traceback from data import Data from pyrogram import Client, filters -from pyrogram.types import InlineKeyboardMarkup, LinkPreviewOptions +from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, LinkPreviewOptions from ssnbot.plugins.generate import generate_session, ask_ques, buttons_ques from ssnbot import LOGGER +ERROR_MESSAGE = ( + "Oops! An exception occurred! \n\n**Error** : {} " + "\n\nPlease visit @The_Architect04 if this message doesn't contain any " + "sensitive information and you want to report this issue, " + "as this error message is not being logged by us!" +) @Client.on_callback_query(filters.regex(r"^home$")) async def home(bot, query): @@ -16,7 +22,7 @@ async def home(bot, query): chat_id=chat_id, message_id=message_id, text=Data.START.format(query.from_user.mention, mention), - reply_markup=InlineKeyboardMarkup(Data.buttons), + reply_markup=InlineKeyboardMarkup(Data.buttons), # Ensure Data.buttons exists ) @@ -27,10 +33,9 @@ async def about(bot, query): await bot.edit_message_text( chat_id=chat_id, message_id=message_id, - text=Data.ABOUT, - # disable_web_page_preview=True, + text=Data.ABOUT, # Ensure Data.ABOUT exists link_preview_options=LinkPreviewOptions(is_disabled=True), - reply_markup=InlineKeyboardMarkup(Data.home_buttons), + reply_markup=InlineKeyboardMarkup(Data.home_buttons), # Ensure Data.home_buttons exists ) @@ -41,10 +46,9 @@ async def help(bot, query): await bot.edit_message_text( chat_id=chat_id, message_id=message_id, - text=Data.HELP, - # disable_web_page_preview=True, + text=Data.HELP, # Ensure Data.HELP exists link_preview_options=LinkPreviewOptions(is_disabled=True), - reply_markup=InlineKeyboardMarkup(Data.home_buttons), + reply_markup=InlineKeyboardMarkup(Data.home_buttons), # Ensure Data.home_buttons exists ) @@ -61,7 +65,7 @@ async def pyro(bot, query): "Please note that the new type of string sessions may not work in all bots, i.e, only the bots that have been updated to pyrogram v2 will work!", show_alert=True, ) - await generate_session(bot, query.message) + await generate_session(bot, query.message) # Ensure generate_session is correct except Exception as e: LOGGER.error(traceback.format_exc()) LOGGER.error(e) @@ -72,16 +76,8 @@ async def pyro(bot, query): async def tele(bot, query): try: await query.answer() - await generate_session(bot, query.message, telethon=True) + await generate_session(bot, query.message, telethon=True) # Ensure generate_session handles Telethon except Exception as e: LOGGER.error(traceback.format_exc()) LOGGER.error(e) await query.message.reply(ERROR_MESSAGE.format(str(e))) - - -ERROR_MESSAGE = ( - "Oops! An exception occurred! \n\n**Error** : {} " - "\n\nPlease visit @The_Architect04 if this message doesn't contain any " - "sensitive information and you if want to report this as " - "this error message is not being logged by us!" -) From 88825858be95a76ac9a2fb0d514a09c886f505e3 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 17:31:14 +0530 Subject: [PATCH 32/39] Update broadcast.py --- ssnbot/plugins/broadcast.py | 51 ++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/ssnbot/plugins/broadcast.py b/ssnbot/plugins/broadcast.py index 9ec758d..c7b7cce 100644 --- a/ssnbot/plugins/broadcast.py +++ b/ssnbot/plugins/broadcast.py @@ -20,31 +20,40 @@ async def get_subscribers_count(bot: Client, message: Message): @Client.on_message(filters.private & filters.command("broadcast")) -async def send_text(bot, message: Message): +async def send_text(bot: Client, message: Message): user_id = message.from_user.id if user_id not in ADMINS: return - if "broadcast" in message.text and message.reply_to_message is not None: - query = await query_msg() - for row in query: - chat_id = int(row[0]) - try: - await bot.copy_message( - chat_id=chat_id, - from_chat_id=message.chat.id, - message_id=message.reply_to_message_id, - caption=message.reply_to_message.caption, - reply_markup=message.reply_to_message.reply_markup, - ) - except FloodWait as e: - await asyncio.sleep(e.value) - except Exception: - pass + if message.reply_to_message is None: + reply_error = "`Use this command as a reply to any telegram message without any spaces.`" + msg = await message.reply_text(reply_error) + await asyncio.sleep(8) + await msg.delete() + return + + # Check if message text is exactly "broadcast" + if "broadcast" in message.text.lower(): + query = query_msg() # Remove await here if query_msg is not async + if query: # Ensure there are results to send the message to + for row in query: + chat_id = int(row[0]) + try: + await bot.copy_message( + chat_id=chat_id, + from_chat_id=message.chat.id, + message_id=message.reply_to_message_id, + caption=message.reply_to_message.caption, + reply_markup=message.reply_to_message.reply_markup, + ) + except FloodWait as e: + await asyncio.sleep(e.value) + except Exception as e: + logger.error(f"Error sending message to {chat_id}: {e}") + else: + await message.reply_text("No users found in the database.") else: - reply_error = ( - "`Use this command as a reply to any telegram message without any spaces.`" - ) - msg = await message.reply_text(reply_error, message.id) + reply_error = "`Please reply to a message and use the command properly.`" + msg = await message.reply_text(reply_error) await asyncio.sleep(8) await msg.delete() From 9762353151511cb5be38efd397f4d41071149047 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sat, 28 Dec 2024 17:38:56 +0530 Subject: [PATCH 33/39] Update broadcast.py --- ssnbot/plugins/broadcast.py | 51 +++++++++++++++---------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/ssnbot/plugins/broadcast.py b/ssnbot/plugins/broadcast.py index c7b7cce..9ec758d 100644 --- a/ssnbot/plugins/broadcast.py +++ b/ssnbot/plugins/broadcast.py @@ -20,40 +20,31 @@ async def get_subscribers_count(bot: Client, message: Message): @Client.on_message(filters.private & filters.command("broadcast")) -async def send_text(bot: Client, message: Message): +async def send_text(bot, message: Message): user_id = message.from_user.id if user_id not in ADMINS: return - if message.reply_to_message is None: - reply_error = "`Use this command as a reply to any telegram message without any spaces.`" - msg = await message.reply_text(reply_error) - await asyncio.sleep(8) - await msg.delete() - return - - # Check if message text is exactly "broadcast" - if "broadcast" in message.text.lower(): - query = query_msg() # Remove await here if query_msg is not async - if query: # Ensure there are results to send the message to - for row in query: - chat_id = int(row[0]) - try: - await bot.copy_message( - chat_id=chat_id, - from_chat_id=message.chat.id, - message_id=message.reply_to_message_id, - caption=message.reply_to_message.caption, - reply_markup=message.reply_to_message.reply_markup, - ) - except FloodWait as e: - await asyncio.sleep(e.value) - except Exception as e: - logger.error(f"Error sending message to {chat_id}: {e}") - else: - await message.reply_text("No users found in the database.") + if "broadcast" in message.text and message.reply_to_message is not None: + query = await query_msg() + for row in query: + chat_id = int(row[0]) + try: + await bot.copy_message( + chat_id=chat_id, + from_chat_id=message.chat.id, + message_id=message.reply_to_message_id, + caption=message.reply_to_message.caption, + reply_markup=message.reply_to_message.reply_markup, + ) + except FloodWait as e: + await asyncio.sleep(e.value) + except Exception: + pass else: - reply_error = "`Please reply to a message and use the command properly.`" - msg = await message.reply_text(reply_error) + reply_error = ( + "`Use this command as a reply to any telegram message without any spaces.`" + ) + msg = await message.reply_text(reply_error, message.id) await asyncio.sleep(8) await msg.delete() From ef60461e73cb010731ee87b7bfc1e1978e3e2fe7 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sun, 29 Dec 2024 01:25:06 +0530 Subject: [PATCH 34/39] Update data.py --- data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data.py b/data.py index 4d2fc70..ab9cc8f 100644 --- a/data.py +++ b/data.py @@ -11,12 +11,12 @@ class Data: buttons = [ [generate_single_button], - [InlineKeyboardButton("🍬 ʙᴏᴛ ꜱᴛᴀᴛᴜꜱ ᴀɴᴅ ᴍᴏʀᴇ ʙᴏᴛꜱ 🍬", url="https://t.me/The_Architect04/13")], + [ InlineKeyboardButton("👻 ʜᴏᴡ ᴛᴏ ᴜꜱᴇ 👻", callback_data="help"), InlineKeyboardButton("🌲 ᴀʙᴏᴜᴛ 🌲", callback_data="about") ], - [InlineKeyboardButton("⚡ ᴍᴏʀᴇ ᴀᴍᴀᴢɪɴɢ ʙᴏᴛꜱ ⚡", url="https://t.me/The_Architect04")], + ] START = """ From 1bd8a54084a8ddd4119c8ac2347af503db55c0ea Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sun, 29 Dec 2024 01:28:13 +0530 Subject: [PATCH 35/39] Update data.py --- data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data.py b/data.py index ab9cc8f..dc64b02 100644 --- a/data.py +++ b/data.py @@ -46,7 +46,7 @@ class Data: """ ABOUT = """ -**ᴀʙᴏᴜᴛ ᴛʜɪꜱ ʙᴏᴛ** +🍄 **ᴀʙᴏᴜᴛ ᴛʜɪꜱ ʙᴏᴛ** 🍄 ᴛᴇʟᴇɢʀᴀᴍ ʙᴏᴛ ᴛᴏ ɢᴇɴᴇʀᴀᴛᴇ ᴘʏʀᴏɢʀᴀᴍ ᴀɴᴅ ᴛᴇʟᴇᴛʜᴏɴ ꜱᴛʀɪɴɢ ꜱᴇꜱꜱɪᴏɴꜱ ʙʏ @The_Architect04 From 67bb6554f9717abd1d31a7a7fbde95f38cc65218 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sun, 29 Dec 2024 01:39:22 +0530 Subject: [PATCH 36/39] Update broadcast.py --- ssnbot/plugins/broadcast.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ssnbot/plugins/broadcast.py b/ssnbot/plugins/broadcast.py index 9ec758d..2f6a9d2 100644 --- a/ssnbot/plugins/broadcast.py +++ b/ssnbot/plugins/broadcast.py @@ -48,3 +48,4 @@ async def send_text(bot, message: Message): msg = await message.reply_text(reply_error, message.id) await asyncio.sleep(8) await msg.delete() + From b939f742aa49ef193607b13378f855bff61a5663 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sun, 29 Dec 2024 01:45:52 +0530 Subject: [PATCH 37/39] Update support.py --- ssnbot/db/support.py | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/ssnbot/db/support.py b/ssnbot/db/support.py index 2c1d32a..1978c2b 100644 --- a/ssnbot/db/support.py +++ b/ssnbot/db/support.py @@ -1,38 +1,28 @@ import asyncio -from pyrogram.errors import FloodWait, RPCError +from pyrogram.errors import FloodWait from pyrogram import enums from ssnbot.db.sql import query_msg, del_user from ssnbot import LOGGER -async def users_info(bot) -> tuple[int, int]: - """ - Function to check user activity and manage the broadcast list. - - Args: - bot: The Pyrogram bot/client instance. - - Returns: - A tuple containing the number of active users and blocked users. - """ - users = 0 # Count of active users - blocked = 0 # Count of blocked users - identity = await query_msg() # Fetch user IDs from the database +async def users_info(bot): + users = 0 + blocked = 0 + identity = await query_msg() for user in identity: user_id = int(user[0]) + name = bool() try: - # Attempt to send a "typing" action to the user - await bot.send_chat_action(user_id, enums.ChatAction.TYPING) - users += 1 # If successful, increment active users count + name = await bot.send_chat_action(user_id, enums.ChatAction.TYPING) except FloodWait as e: - LOGGER.warning("FloodWait triggered for %d seconds", e.value) - await asyncio.sleep(e.value) # Wait for the required time - except RPCError as e: - LOGGER.error("RPCError for user %s: %s", user_id, e) - await del_user(user_id) # Remove the user from the broadcast list - LOGGER.info("Deleted user ID %s from broadcast list", user_id) - blocked += 1 # Increment blocked users count - except Exception as e: - LOGGER.error("Unexpected error for user %s: %s", user_id, e) + await asyncio.sleep(e.value) + except Exception: + pass + if bool(name): + users += 1 + else: + await del_user(user_id) + LOGGER.info("Deleted user id %s from broadcast list", user_id) + blocked += 1 + return users, blocked - return users, blocked # Return the counts of active and blocked users From 7a912607da512e12aa5f71ff6f4e3882ff888b3c Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sun, 29 Dec 2024 01:47:18 +0530 Subject: [PATCH 38/39] Update sql.py --- ssnbot/db/sql.py | 65 ++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 46 deletions(-) diff --git a/ssnbot/db/sql.py b/ssnbot/db/sql.py index 766d16a..1386c64 100644 --- a/ssnbot/db/sql.py +++ b/ssnbot/db/sql.py @@ -1,32 +1,29 @@ import threading -from sqlalchemy import create_engine, Column, TEXT, BigInteger +from sqlalchemy import create_engine +from sqlalchemy import Column, TEXT, BigInteger from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.pool import StaticPool from ssnbot import DB_URL + BASE = declarative_base() + class Broadcast(BASE): __tablename__ = "broadcast" user_id = Column(BigInteger, primary_key=True) user_name = Column(TEXT) - def __init__(self, user_id: int, user_name: str): + def __init__(self, user_id, user_name): self.user_id = user_id self.user_name = user_name def start() -> scoped_session: - """ - Initialize the database connection and create tables if they don't exist. - Returns: - scoped_session: Thread-safe session maker. - """ engine = create_engine( - DB_URL, client_encoding="utf8", poolclass=StaticPool - ) + DB_URL, client_encoding="utf8", poolclass=StaticPool) BASE.metadata.bind = engine BASE.metadata.create_all(engine) return scoped_session(sessionmaker(bind=engine, autoflush=False)) @@ -36,13 +33,7 @@ def start() -> scoped_session: INSERTION_LOCK = threading.RLock() -def add_user(user_id: int, user_name: str) -> None: - """ - Add a user to the database if they don't already exist. - Args: - user_id (int): Telegram user ID. - user_name (str): Telegram user name. - """ +async def add_user(user_id, user_name): with INSERTION_LOCK: try: usr = SESSION.query(Broadcast).filter_by(user_id=user_id).one() @@ -52,43 +43,24 @@ def add_user(user_id: int, user_name: str) -> None: SESSION.commit() -def is_user(user_id: int) -> bool: - """ - Check if a user exists in the database. - Args: - user_id (int): Telegram user ID. - Returns: - bool: True if user exists, False otherwise. - """ +async def is_user(user_id): with INSERTION_LOCK: try: usr = SESSION.query(Broadcast).filter_by(user_id=user_id).one() - return True + return usr.user_id except NoResultFound: return False -def query_msg() -> list: - """ - Retrieve all user IDs from the database. - Returns: - list: List of user IDs. - """ - with INSERTION_LOCK: - try: - query = SESSION.query(Broadcast.user_id).order_by(Broadcast.user_id) - return query.all() - except Exception as e: - print(f"Error querying messages: {e}") - return [] - - -def del_user(user_id: int) -> None: - """ - Delete a user from the database. - Args: - user_id (int): Telegram user ID. - """ +async def query_msg(): + try: + query = SESSION.query(Broadcast.user_id).order_by(Broadcast.user_id) + return query.all() + finally: + SESSION.close() + + +async def del_user(user_id): with INSERTION_LOCK: try: usr = SESSION.query(Broadcast).filter_by(user_id=user_id).one() @@ -96,3 +68,4 @@ def del_user(user_id: int) -> None: SESSION.commit() except NoResultFound: pass + From cfa33c65ae5e1fef5c152d5403a3882466ff6576 Mon Sep 17 00:00:00 2001 From: THE ARCHITECT Date: Sun, 12 Jan 2025 00:34:01 +0530 Subject: [PATCH 39/39] Update sql.py --- ssnbot/db/sql.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ssnbot/db/sql.py b/ssnbot/db/sql.py index 1386c64..d84ce22 100644 --- a/ssnbot/db/sql.py +++ b/ssnbot/db/sql.py @@ -6,6 +6,21 @@ from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.pool import StaticPool from ssnbot import DB_URL +from sqlalchemy import create_engine + +# Connection URL +connection_url = "postgresql://neondb_owner:ji43CdTZBIPX@ep-broad-lake-a88oaxik.eastus2.azure.neon.tech/neondb?sslmode=require" + +# Create an engine +engine = create_engine(connection_url) + +# Connect to the database and perform a query +with engine.connect() as connection: + result = connection.execute("SELECT table_name FROM information_schema.tables WHERE table_schema='public';") + + print("Tables in the database:") + for row in result: + print(row[0]) BASE = declarative_base()