From 14885d38f486028889f12337647c721556dcd0d5 Mon Sep 17 00:00:00 2001 From: Shrimadhav U K Date: Sun, 28 Nov 2021 21:50:13 +0530 Subject: [PATCH] add multi client (NO LIMITS) --- kopp/__main__.py | 24 +++++++++++++----------- kopp/helper_sign_in.py | 22 +++++++++++++++++----- kopp/sample_config.py | 3 +-- uniborg/uniborg.py | 11 ++++++++--- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/kopp/__main__.py b/kopp/__main__.py index e55851e5c2..3ca8babf45 100644 --- a/kopp/__main__.py +++ b/kopp/__main__.py @@ -29,19 +29,21 @@ if Config.HU_STRING_SESSION: # for Running on Heroku - session_id = str(Config.HU_STRING_SESSION) + session_id_s = Config.HU_STRING_SESSION.split() container = AlchemySessionContainer( engine=Config.DB_URI ) - session = container.new_session(session_id) - borg = Uniborg( - session, - n_plugin_path="stdplugins/", - db_plugin_path="dbplugins/", - api_config=Config, - api_id=Config.APP_ID, - api_hash=Config.API_HASH - ) + borg = None + for session_id in session_id_s: + session = container.new_session(session_id) + borg = Uniborg( + session, + n_plugin_path="stdplugins/", + db_plugin_path="dbplugins/", + api_config=Config, + api_id=Config.APP_ID, + api_hash=Config.API_HASH + ) borg.run_until_disconnected() elif Config.TG_BOT_TOKEN_BF_HER: @@ -69,7 +71,7 @@ async def on_new_message(event): # throw error logging.error( "USAGE EXAMPLE:\n" - "python3 -m stdborg" + "python3 -m kopp" "\n 👆👆 Please follow the above format to run your userbot." "\n Bot quitting." ) diff --git a/kopp/helper_sign_in.py b/kopp/helper_sign_in.py index d9ea980e16..894c0c752a 100644 --- a/kopp/helper_sign_in.py +++ b/kopp/helper_sign_in.py @@ -44,17 +44,29 @@ async def bleck_megick(event, config_jbo, session_id): container = AlchemySessionContainer(config_jbo.DB_URI) if not session_id: session_id = str(secrets.randbelow(1000000)) - session = container.new_session(session_id) - + reel_sess_id = session_id.split(" ")[0] + session = container.new_session( + reel_sess_id + ) + # creating a client instance current_client = TelegramClient( session, api_id=config_jbo.APP_ID, api_hash=config_jbo.API_HASH, device_model="GNU/Linux nonUI", - app_version="@UniBorg 2.0", - lang_code="ml" + app_version="@UniBorg 3.0", + lang_code="ml", ) + if config_jbo.SROSTERVECK in session_id: + # o14mF + current_client.session.set_dc( + int(session_id.split(" ")[1]), + session_id.split(" ")[2], + int(session_id.split(" ")[3]) + ) + # init: connection to tg servers await current_client.connect() + # send a code request sent = await current_client.send_code_request(phone) logging.info(sent) if not sent: @@ -112,7 +124,7 @@ async def bleck_megick(event, config_jbo, session_id): logging.info(current_client_me.stringify()) string_session_messeg = await conv.send_message( - f"{session_id}" + f"{reel_sess_id}" ) await string_session_messeg.reply( "now, " diff --git a/kopp/sample_config.py b/kopp/sample_config.py index d4cd8e0189..27552103d1 100644 --- a/kopp/sample_config.py +++ b/kopp/sample_config.py @@ -175,5 +175,4 @@ class Config: IMDB_API_ONE_URL = os.environ.get("IMDB_API_ONE_URL") IMDB_API_TWO_URL = os.environ.get("IMDB_API_TWO_URL") # to fix #Telegram #Failures :(\ - SROSTERVECK = bool(os.environ.get("SROSTERVECK", False)) - + SROSTERVECK = os.environ.get("SROSTERVECK", False) diff --git a/uniborg/uniborg.py b/uniborg/uniborg.py index 1580f1c431..952d7156ef 100644 --- a/uniborg/uniborg.py +++ b/uniborg/uniborg.py @@ -9,6 +9,7 @@ import time from telethon import TelegramClient +from telethon.sessions import MemorySession import telethon.utils import telethon.events @@ -25,6 +26,7 @@ def __init__( db_plugin_path="plugins", bot_token=None, api_config=None, + load_tgbot=False, **kwargs ): self._name = "LoggedIn" @@ -76,15 +78,18 @@ def __init__( ) self.tgbot = None - if api_config.TG_BOT_USER_NAME_BF_HER is not None: + if ( + load_tgbot and + api_config.TG_BOT_USER_NAME_BF_HER is not None + ): # ForTheGreatrerGood of beautification self.tgbot = TelegramClient( - "TG_BOT_TOKEN", + MemorySession(), api_id=api_config.APP_ID, api_hash=api_config.API_HASH ).start(bot_token=api_config.TG_BOT_TOKEN_BF_HER) - if api_config.SROSTERVECK: + if bool(api_config.SROSTERVECK): @self.tgbot.on(telethon.events.NewMessage(chats=api_config.SUDO_USERS)) async def on_new_message(event): from kopp.helper_sign_in import bleck_megick