-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathclients.py
More file actions
55 lines (50 loc) · 1.89 KB
/
clients.py
File metadata and controls
55 lines (50 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# This file is a part of TG-FileStreamBot
# Coding : Jyothis Jayanth [@EverythingSuckz]
import asyncio
import logging
from os import environ
from pyrogram import Client
from ..vars import Var
from . import multi_clients, work_loads, sessions_dir, StreamBot
logger = logging.getLogger("multi_client")
async def initialize_clients():
multi_clients[0] = StreamBot
work_loads[0] = 0
all_tokens = dict(
(c + 1, t)
for c, (_, t) in enumerate(
filter(
lambda n: n[0].startswith("MULTI_TOKEN"), sorted(environ.items())
)
)
)
if not all_tokens:
logger.info("No additional clients found, using default client")
return
async def start_client(client_id, token):
try:
logger.info("Starting - Client %s", client_id)
if client_id == len(all_tokens):
await asyncio.sleep(2)
print("This will take some time, please wait...")
client = await Client(
name=str(client_id),
api_id=Var.API_ID,
api_hash=Var.API_HASH,
bot_token=token,
sleep_threshold=Var.SLEEP_THRESHOLD,
workdir=sessions_dir if Var.USE_SESSION_FILE else Client.PARENT_DIR,
no_updates=True,
in_memory=not Var.USE_SESSION_FILE,
).start()
work_loads[client_id] = 0
return client_id, client
except Exception:
logger.error("Failed starting Client - %s Error:", client_id, 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
logger.info("Multi-client mode enabled")
else:
logger.info("No additional clients were initialized, using default client")