forked from tgbot-collection/SearchGram
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit_client.py
35 lines (26 loc) · 940 Bytes
/
init_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
31
32
33
34
35
#!/usr/local/bin/python3
# coding: utf-8
# SearchGram - init_client.py
# 4/5/22 12:19
#
__author__ = "Benny <[email protected]>"
import contextlib
import json
import urllib.request
from pyrogram import Client
from config import APP_HASH, APP_ID, PROXY, IPv6
def get_client(token=None):
if isinstance(PROXY, str):
proxy = json.loads(PROXY)
else:
proxy = PROXY
app_device = dict(app_version=f"SearchGram/{get_revision()}", device_model="Firefox", proxy=proxy)
if token:
return Client("session/bot", APP_ID, APP_HASH, bot_token=token, ipv6=IPv6, **app_device)
else:
return Client("session/client", APP_ID, APP_HASH, ipv6=IPv6, **app_device)
def get_revision():
url = "https://api.github.com/repos/tgbot-collection/SearchGram/commits/master"
with contextlib.suppress(Exception):
return json.loads(urllib.request.urlopen(url).read())["sha"][:7]
return "0.0.0"