Skip to content

Commit

Permalink
add multi client (NO LIMITS)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpEcHiDe committed Nov 28, 2021
1 parent f945412 commit 14885d3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
24 changes: 13 additions & 11 deletions kopp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."
)
22 changes: 17 additions & 5 deletions kopp/helper_sign_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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, "
Expand Down
3 changes: 1 addition & 2 deletions kopp/sample_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 8 additions & 3 deletions uniborg/uniborg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time

from telethon import TelegramClient
from telethon.sessions import MemorySession
import telethon.utils
import telethon.events

Expand All @@ -25,6 +26,7 @@ def __init__(
db_plugin_path="plugins",
bot_token=None,
api_config=None,
load_tgbot=False,
**kwargs
):
self._name = "LoggedIn"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 14885d3

Please sign in to comment.