-
Notifications
You must be signed in to change notification settings - Fork 14
/
client.py
30 lines (23 loc) · 853 Bytes
/
client.py
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
from telethon import TelegramClient
from dotenv import load_dotenv
import os
load_dotenv()
api_id = int(os.getenv('API_ID'))
api_hash = os.getenv('API_HASH')
if not (api_id or api_hash):
raise Exception('You have to pass both API_ID and API_HASH env variables')
proxy = {}
if len(os.getenv('PROXY_URL')) > 2:
p = os.getenv('PROXY_URL')
[schema, urlPort] = p.split("://", 1)
[url, port] = urlPort.rsplit(":", 1)
proxy = {
"proxy_type": schema,
"addr": url,
"port": int(port),
}
print("using proxy for telegram connection: ")
print(proxy)
app = TelegramClient("v2ray-proxy-grabber-telegram", api_id, api_hash, proxy=proxy, auto_reconnect=True, connection_retries=20, retry_delay=5)
PROXY_CHANNELS = os.getenv('PROXY_CHANNELS').lower().split("@")
IS_DEBUG = bool(int(os.getenv('DEBUG_MODE')))