-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
152d39a
commit ee25d51
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# (c) adarsh-goel | ||
from pyrogram import Client | ||
import pyromod.listen | ||
from ..vars import Var | ||
from os import getcwd | ||
|
||
StreamBot = Client( | ||
name='Web Streamer', | ||
api_id=Var.API_ID, | ||
api_hash=Var.API_HASH, | ||
bot_token=Var.BOT_TOKEN, | ||
sleep_threshold=Var.SLEEP_THRESHOLD, | ||
workers=Var.WORKERS | ||
) | ||
|
||
multi_clients = {} | ||
work_loads = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# (c) adarsh-goel | ||
|
||
import asyncio | ||
import logging | ||
from ..vars import Var | ||
from pyrogram import Client | ||
from Adarsh.utils.config_parser import TokenParser | ||
from . import multi_clients, work_loads, StreamBot | ||
|
||
|
||
async def initialize_clients(): | ||
multi_clients[0] = StreamBot | ||
work_loads[0] = 0 | ||
all_tokens = TokenParser().parse_from_env() | ||
if not all_tokens: | ||
print("No additional clients found, using default client") | ||
return | ||
|
||
async def start_client(client_id, token): | ||
try: | ||
print(f"Starting - Client {client_id}") | ||
if client_id == len(all_tokens): | ||
await asyncio.sleep(2) | ||
print("This will take some time, please wait...") | ||
client = await Client( | ||
name=":memory:", | ||
api_id=Var.API_ID, | ||
api_hash=Var.API_HASH, | ||
bot_token=token, | ||
sleep_threshold=Var.SLEEP_THRESHOLD, | ||
no_updates=True, | ||
).start() | ||
work_loads[client_id] = 0 | ||
return client_id, client | ||
except Exception: | ||
logging.error(f"Failed starting Client - {client_id} Error:", exc_info=True) | ||
|
||
clients = await asyncio.gather(*[start_client(i, token) for i, token in all_tokens.items()]) | ||
multi_clients.update(dict(clients)) | ||
if len(multi_clients) != 1: | ||
Var.MULTI_CLIENT = True | ||
print("Multi-Client Mode Enabled") | ||
else: | ||
print("No additional clients were initialized, using default client") |